forked from zapier/zapier-platform-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
176 lines (155 loc) · 4.46 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Type definitions for zapier-platform-core
// Project: Zapier's Platform Core
// Definitions by: David Brownman <https://davidbrownman.com>
/// <reference types="node" />
import { Agent } from 'http';
// The EXPORTED OBJECT
export const version: string;
export const tools: { env: { inject: (filename?: string) => void } };
// see: https://github.com/zapier/zapier-platform-cli/issues/339#issue-336888249
export const createAppTester: (
appRaw: object,
options?: { customStoreKey?: string }
) => <T extends any, B extends Bundle>(
func: (z: ZObject, bundle: B) => Promise<T>,
bundle?: Partial<B> // partial so we don't have to make a full bundle in tests
) => T extends Promise<T> ? T : Promise<T>;
// internal only
// export const integrationTestHandler: () => any;
// export const createAppHandler: (appRaw: object) => any
type HttpMethod =
| 'GET'
| 'POST'
| 'PUT'
| 'PATCH'
| 'DELETE'
| 'OPTIONS'
| 'HEAD';
export interface Bundle<InputData = { [x: string]: any }> {
authData: { [x: string]: string };
inputData: InputData;
inputDataRaw: { [x: string]: string };
meta: {
isFillingDynamicDropdown: boolean;
isLoadingSample: boolean;
isPopulatingDedupe: boolean;
isTestingAuth: boolean;
limit: number;
page: number;
zap?: { id: string };
};
rawRequest?: Partial<{
method: HttpMethod;
querystring: string;
headers: { [x: string]: string };
content: string;
}>;
cleanedRequest?: Partial<{
method: HttpMethod;
querystring: { [x: string]: string };
headers: { [x: string]: string };
content: { [x: string]: string };
}> | any;
subscribeData?: { id: string };
targetUrl?: string;
}
declare class HaltedError extends Error {}
declare class ExpiredAuthError extends Error {}
declare class RefreshAuthError extends Error {}
// copied http stuff from external typings
export interface HttpRequestOptions {
agent?: Agent;
body?: string | Buffer | ReadableStream | object;
compress?: boolean;
follow?: number;
form?: object;
headers?: { [name: string]: string };
json?: object | any[];
method?: HttpMethod;
params?: object;
raw?: boolean;
redirect?: 'manual' | 'error' | 'follow';
removeMissingValuesFrom?: {
params?: boolean;
body?: boolean;
};
size?: number;
timeout?: number;
url?: string;
}
interface BaseHttpResponse {
status: number;
headers: { [key: string]: string };
getHeader(key: string): string | undefined;
throwForStatus(): void;
request: HttpRequestOptions;
}
export interface HttpResponse extends BaseHttpResponse {
content: string;
json?: object;
}
export interface RawHttpResponse extends BaseHttpResponse {
content: Buffer;
json: Promise<object | undefined>;
body: ReadableStream;
}
export interface ZObject {
request: {
// most specific overloads go first
(url: string, options: HttpRequestOptions & { raw: true }): Promise<
RawHttpResponse
>;
(options: HttpRequestOptions & { raw: true; url: string }): Promise<
RawHttpResponse
>;
(url: string, options?: HttpRequestOptions): Promise<HttpResponse>;
(options: HttpRequestOptions & { url: string }): Promise<HttpResponse>;
};
console: Console;
dehydrate: <T>(
func: (z: this, bundle: Bundle<T>) => any,
inputData: object
) => string;
cursor: {
get: () => Promise<string>;
set: (cursor: string) => Promise<null>;
};
generateCallbackUrl: () => string;
/**
* turns a file or request into a file into a publicly accessible url
*/
stashFile: {
(
input: string | Buffer | ReadableStream,
knownLength?: number,
filename?: string,
contentType?: string
): string;
(input: Promise<string>): string;
};
JSON: {
/**
* Acts a lot like regular `JSON.parse`, but throws a nice error for improper json input
*/
parse: (text: string) => any;
stringify: typeof JSON.stringify;
};
/**
* Easily hash data using node's crypto package
* @param algorithm probably 'sha256', see [this](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options) for more options
* @param data the data you want to hash
* @param encoding defaults to 'hex'
* @param input_encoding defaults to 'binary'
*/
hash: (
algorithm: string,
data: string,
encoding?: string,
input_encoding?: string
) => string;
errors: {
HaltedError: typeof HaltedError;
ExpiredAuthError: typeof ExpiredAuthError;
RefreshAuthError: typeof RefreshAuthError;
};
}