zapier-platform-cli 17.3.1 → 17.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/oclif.manifest.json +16 -4
- package/package.json +1 -1
- package/scaffold/resource.template.ts +30 -9
- package/src/generators/index.js +70 -68
- package/src/generators/templates/README.template.md +10 -0
- package/src/generators/templates/authTests/basic.test.ts +42 -0
- package/src/generators/templates/authTests/custom.test.ts +34 -0
- package/src/generators/templates/authTests/digest.test.ts +43 -0
- package/src/generators/templates/authTests/oauth1.test.ts +63 -0
- package/src/generators/templates/authTests/oauth2.test.ts +115 -0
- package/src/generators/templates/authTests/session.test.ts +36 -0
- package/src/generators/templates/index.template.js +2 -5
- package/src/generators/templates/index.template.ts +11 -14
- package/src/generators/templates/tsconfig.template.json +18 -0
- package/src/oclif/commands/init.js +9 -2
- package/src/oclif/commands/invoke.js +4 -0
- package/src/oclif/commands/versions.js +0 -24
- package/src/utils/auth-files-codegen.js +343 -142
- package/src/utils/build.js +52 -53
- package/src/utils/codegen.js +26 -6
- package/src/utils/files.js +12 -2
- package/src/generators/templates/index-esm.template.ts +0 -24
- package/src/generators/templates/typescript/README.md +0 -3
- package/src/generators/templates/typescript/src/authentication.ts +0 -48
- package/src/generators/templates/typescript/src/constants.ts +0 -3
- package/src/generators/templates/typescript/src/creates/movie.ts +0 -43
- package/src/generators/templates/typescript/src/middleware.ts +0 -11
- package/src/generators/templates/typescript/src/test/creates.test.ts +0 -21
- package/src/generators/templates/typescript/src/test/triggers.test.ts +0 -25
- package/src/generators/templates/typescript/src/triggers/movie.ts +0 -29
- package/src/generators/templates/typescript/tsconfig.json +0 -17
|
@@ -9,10 +9,12 @@ const {
|
|
|
9
9
|
exportStatement,
|
|
10
10
|
fatArrowReturnFunctionDeclaration,
|
|
11
11
|
file,
|
|
12
|
+
fileTS,
|
|
12
13
|
functionDeclaration,
|
|
13
14
|
ifStatement,
|
|
14
15
|
interpLiteral,
|
|
15
16
|
obj,
|
|
17
|
+
objTS,
|
|
16
18
|
objProperty,
|
|
17
19
|
RESPONSE_VAR,
|
|
18
20
|
returnStatement,
|
|
@@ -22,9 +24,19 @@ const {
|
|
|
22
24
|
zResponseErr,
|
|
23
25
|
} = require('./codegen');
|
|
24
26
|
|
|
25
|
-
const standardArgs =
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const standardArgs = (language) =>
|
|
28
|
+
language === 'typescript'
|
|
29
|
+
? ['z: ZObject', 'bundle: Bundle']
|
|
30
|
+
: ['z', 'bundle'];
|
|
31
|
+
const standardTypes = ['ZObject', 'Bundle', 'Authentication'];
|
|
32
|
+
const beforeMiddlewareArgs = (language) => [
|
|
33
|
+
'request',
|
|
34
|
+
...standardArgs(language),
|
|
35
|
+
];
|
|
36
|
+
const afterMiddlewareArgs = (language) => [
|
|
37
|
+
RESPONSE_VAR,
|
|
38
|
+
...standardArgs(language),
|
|
39
|
+
];
|
|
28
40
|
|
|
29
41
|
// used for both oauth1 and oauth2
|
|
30
42
|
const getOauthAccessTokenFuncName = 'getAccessToken';
|
|
@@ -34,48 +46,77 @@ const authJsonUrl = (path) =>
|
|
|
34
46
|
`https://auth-json-server.zapier-staging.com/${path}`;
|
|
35
47
|
|
|
36
48
|
const authFileExport = (
|
|
49
|
+
language,
|
|
37
50
|
authType,
|
|
38
51
|
authDescription,
|
|
39
52
|
{
|
|
40
|
-
beforeFuncNames = [],
|
|
41
|
-
afterFuncNames = [],
|
|
42
53
|
extraConfigProps = [],
|
|
43
54
|
connectionLabel = strLiteral('{{json.username}}'),
|
|
44
55
|
test = objProperty('test'),
|
|
45
56
|
authFields = [],
|
|
46
57
|
} = {},
|
|
47
58
|
) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
const configProps = [
|
|
60
|
+
comment(authDescription),
|
|
61
|
+
objProperty('type', strLiteral(authType)),
|
|
62
|
+
...extraConfigProps,
|
|
63
|
+
comment(
|
|
64
|
+
"Define any input app's auth requires here. The user will be prompted to enter this info when they connect their account.",
|
|
65
|
+
),
|
|
66
|
+
objProperty('fields', arr(...authFields)),
|
|
67
|
+
comment(
|
|
68
|
+
"The test method allows Zapier to verify that the credentials a user provides are valid. We'll execute this method whenever a user connects their account for the first time.",
|
|
69
|
+
),
|
|
70
|
+
test,
|
|
71
|
+
comment(
|
|
72
|
+
`This template string can access all the data returned from the auth test. If you return the test object, you'll access the returned data with a label like \`{{json.X}}\`. If you return \`response.data\` from your test, then your label can be \`{{X}}\`. This can also be a function that returns a label. That function has the standard args \`(${standardArgs(
|
|
73
|
+
language,
|
|
74
|
+
).join(
|
|
75
|
+
', ',
|
|
76
|
+
)})\` and data returned from the test can be accessed in \`bundle.inputData.X\`.`,
|
|
77
|
+
),
|
|
78
|
+
objProperty('connectionLabel', connectionLabel),
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const configObj =
|
|
82
|
+
language === 'typescript'
|
|
83
|
+
? objTS('Authentication', ...configProps)
|
|
84
|
+
: obj(...configProps);
|
|
85
|
+
|
|
86
|
+
return exportStatement(configObj, language);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const middlewareFileExport = (
|
|
90
|
+
language,
|
|
91
|
+
{ beforeFuncNames = [], afterFuncNames = [] },
|
|
92
|
+
) => {
|
|
93
|
+
const exportConst = language === 'typescript';
|
|
94
|
+
return language === 'typescript'
|
|
95
|
+
? [
|
|
96
|
+
// for Typescript, export the befores and afters separately as consts
|
|
97
|
+
variableAssignmentDeclaration(
|
|
98
|
+
'befores',
|
|
99
|
+
arr(...beforeFuncNames),
|
|
100
|
+
exportConst,
|
|
101
|
+
),
|
|
102
|
+
variableAssignmentDeclaration(
|
|
103
|
+
'afters',
|
|
104
|
+
arr(...afterFuncNames),
|
|
105
|
+
exportConst,
|
|
106
|
+
),
|
|
107
|
+
]
|
|
108
|
+
: [
|
|
109
|
+
// for Javascript, export the befores and afters together using module.exports
|
|
110
|
+
exportStatement(
|
|
111
|
+
obj(
|
|
112
|
+
objProperty('befores', arr(...beforeFuncNames)),
|
|
113
|
+
objProperty('afters', arr(...afterFuncNames)),
|
|
68
114
|
),
|
|
69
|
-
objProperty('connectionLabel', connectionLabel),
|
|
70
115
|
),
|
|
71
|
-
|
|
72
|
-
objProperty('befores', arr(...beforeFuncNames)),
|
|
73
|
-
objProperty('afters', arr(...afterFuncNames)),
|
|
74
|
-
),
|
|
75
|
-
);
|
|
116
|
+
];
|
|
76
117
|
};
|
|
77
118
|
|
|
78
|
-
const authTestFunc = (testUrl = strLiteral(authJsonUrl('me'))) =>
|
|
119
|
+
const authTestFunc = (language, testUrl = strLiteral(authJsonUrl('me'))) =>
|
|
79
120
|
block(
|
|
80
121
|
comment(
|
|
81
122
|
'You want to make a request to an endpoint that is either specifically designed to test auth, or one that every user will have access to. eg: `/me`.',
|
|
@@ -83,15 +124,21 @@ const authTestFunc = (testUrl = strLiteral(authJsonUrl('me'))) =>
|
|
|
83
124
|
comment(
|
|
84
125
|
'By returning the entire request object, you have access to the request and response data for testing purposes. Your connection label can access any data from the returned response using the `json.` prefix. eg: `{{json.username}}`.',
|
|
85
126
|
),
|
|
86
|
-
fatArrowReturnFunctionDeclaration(
|
|
127
|
+
fatArrowReturnFunctionDeclaration(
|
|
128
|
+
'test',
|
|
129
|
+
standardArgs(language),
|
|
130
|
+
zRequest(testUrl),
|
|
131
|
+
),
|
|
87
132
|
);
|
|
88
133
|
|
|
89
134
|
const handleBadResponsesFunc = (
|
|
90
135
|
funcName,
|
|
136
|
+
language,
|
|
91
137
|
invalidInfo = 'username and/or password',
|
|
92
138
|
) =>
|
|
93
139
|
afterMiddlewareFunc(
|
|
94
140
|
funcName,
|
|
141
|
+
language,
|
|
95
142
|
ifStatement(
|
|
96
143
|
'response.status === 401',
|
|
97
144
|
zResponseErr(strLiteral(`The ${invalidInfo} you supplied is incorrect`)),
|
|
@@ -99,30 +146,52 @@ const handleBadResponsesFunc = (
|
|
|
99
146
|
returnStatement(RESPONSE_VAR),
|
|
100
147
|
);
|
|
101
148
|
|
|
102
|
-
const basicAuthFile = () => {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
authTestFunc(),
|
|
106
|
-
handleBadResponsesFunc(badFuncName),
|
|
149
|
+
const basicAuthFile = (language) => {
|
|
150
|
+
const fileInput = [
|
|
151
|
+
authTestFunc(language),
|
|
107
152
|
authFileExport(
|
|
153
|
+
language,
|
|
108
154
|
'basic',
|
|
109
155
|
'"basic" auth automatically creates "username" and "password" input fields. It also registers default middleware to create the authentication header.',
|
|
110
|
-
{ afterFuncNames: [badFuncName] },
|
|
111
156
|
),
|
|
112
|
-
|
|
157
|
+
];
|
|
158
|
+
return language === 'typescript'
|
|
159
|
+
? fileTS(standardTypes, ...fileInput)
|
|
160
|
+
: file(...fileInput);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const basicMiddlewareFile = (language) => {
|
|
164
|
+
const badFuncName = 'handleBadResponses';
|
|
165
|
+
const fileInput = [
|
|
166
|
+
handleBadResponsesFunc(badFuncName, language),
|
|
167
|
+
...middlewareFileExport(language, {
|
|
168
|
+
beforeFuncNames: [],
|
|
169
|
+
afterFuncNames: [badFuncName],
|
|
170
|
+
}),
|
|
171
|
+
];
|
|
172
|
+
return language === 'typescript'
|
|
173
|
+
? fileTS(standardTypes, ...fileInput)
|
|
174
|
+
: file(...fileInput);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const basicFiles = (language) => {
|
|
178
|
+
return {
|
|
179
|
+
middleware: basicMiddlewareFile(language),
|
|
180
|
+
authentication: basicAuthFile(language),
|
|
181
|
+
};
|
|
113
182
|
};
|
|
114
183
|
|
|
115
184
|
/**
|
|
116
185
|
* boilerplate for a "before" middleware. No need to return the requst at the end
|
|
117
186
|
*/
|
|
118
|
-
const beforeMiddlewareFunc = (funcName, ...statements) =>
|
|
187
|
+
const beforeMiddlewareFunc = (funcName, language, ...statements) =>
|
|
119
188
|
block(
|
|
120
189
|
comment(
|
|
121
190
|
"This function runs before every outbound request. You can have as many as you need. They'll need to each be registered in your index.js file.",
|
|
122
191
|
),
|
|
123
192
|
functionDeclaration(
|
|
124
193
|
funcName,
|
|
125
|
-
{ args: beforeMiddlewareArgs },
|
|
194
|
+
{ args: beforeMiddlewareArgs(language) },
|
|
126
195
|
...statements,
|
|
127
196
|
// auto include the return if it's not here already
|
|
128
197
|
statements[statements.length - 1].includes('return')
|
|
@@ -131,17 +200,22 @@ const beforeMiddlewareFunc = (funcName, ...statements) =>
|
|
|
131
200
|
),
|
|
132
201
|
);
|
|
133
202
|
|
|
134
|
-
const afterMiddlewareFunc = (funcName, ...statements) =>
|
|
203
|
+
const afterMiddlewareFunc = (funcName, language, ...statements) =>
|
|
135
204
|
block(
|
|
136
205
|
comment(
|
|
137
206
|
"This function runs after every outbound request. You can use it to check for errors or modify the response. You can have as many as you need. They'll need to each be registered in your index.js file.",
|
|
138
207
|
),
|
|
139
|
-
functionDeclaration(
|
|
208
|
+
functionDeclaration(
|
|
209
|
+
funcName,
|
|
210
|
+
{ args: afterMiddlewareArgs(language) },
|
|
211
|
+
...statements,
|
|
212
|
+
),
|
|
140
213
|
);
|
|
141
214
|
|
|
142
|
-
const includeBearerFunc = (funcName) =>
|
|
215
|
+
const includeBearerFunc = (funcName, language) =>
|
|
143
216
|
beforeMiddlewareFunc(
|
|
144
217
|
funcName,
|
|
218
|
+
language,
|
|
145
219
|
ifStatement(
|
|
146
220
|
'bundle.authData.access_token',
|
|
147
221
|
assignmentStatement(
|
|
@@ -154,6 +228,7 @@ const includeBearerFunc = (funcName) =>
|
|
|
154
228
|
|
|
155
229
|
const tokenExchangeFunc = (
|
|
156
230
|
funcName,
|
|
231
|
+
language,
|
|
157
232
|
requestUrl,
|
|
158
233
|
bodyProps,
|
|
159
234
|
returnProps,
|
|
@@ -161,7 +236,7 @@ const tokenExchangeFunc = (
|
|
|
161
236
|
) =>
|
|
162
237
|
functionDeclaration(
|
|
163
238
|
funcName,
|
|
164
|
-
{ args: standardArgs, isAsync: true },
|
|
239
|
+
{ args: standardArgs(language), isAsync: true },
|
|
165
240
|
variableAssignmentDeclaration(
|
|
166
241
|
RESPONSE_VAR,
|
|
167
242
|
awaitStatement(
|
|
@@ -183,10 +258,12 @@ const tokenExchangeFunc = (
|
|
|
183
258
|
|
|
184
259
|
const oauth2TokenExchangeFunc = (
|
|
185
260
|
funcName,
|
|
261
|
+
language,
|
|
186
262
|
{ path, grantType, bodyProps = [], returnComments = [] },
|
|
187
263
|
) => {
|
|
188
264
|
return tokenExchangeFunc(
|
|
189
265
|
funcName,
|
|
266
|
+
language,
|
|
190
267
|
authJsonUrl(path),
|
|
191
268
|
[
|
|
192
269
|
objProperty('client_id', 'process.env.CLIENT_ID'),
|
|
@@ -218,8 +295,8 @@ const oauth2TokenExchangeFunc = (
|
|
|
218
295
|
);
|
|
219
296
|
};
|
|
220
297
|
|
|
221
|
-
const getAccessTokenFunc = () => {
|
|
222
|
-
return oauth2TokenExchangeFunc(getOauthAccessTokenFuncName, {
|
|
298
|
+
const getAccessTokenFunc = (language) => {
|
|
299
|
+
return oauth2TokenExchangeFunc(getOauthAccessTokenFuncName, language, {
|
|
223
300
|
path: 'oauth/access-token',
|
|
224
301
|
bodyProps: [
|
|
225
302
|
objProperty('code', 'bundle.inputData.code'),
|
|
@@ -236,11 +313,12 @@ const getAccessTokenFunc = () => {
|
|
|
236
313
|
'If your app does an app refresh, then `refresh_token` should be returned here as well',
|
|
237
314
|
),
|
|
238
315
|
],
|
|
316
|
+
language,
|
|
239
317
|
});
|
|
240
318
|
};
|
|
241
319
|
|
|
242
|
-
const refreshTokenFunc = () => {
|
|
243
|
-
return oauth2TokenExchangeFunc(refreshOath2AccessTokenFuncName, {
|
|
320
|
+
const refreshTokenFunc = (language) => {
|
|
321
|
+
return oauth2TokenExchangeFunc(refreshOath2AccessTokenFuncName, language, {
|
|
244
322
|
path: 'oauth/refresh-token',
|
|
245
323
|
bodyProps: [objProperty('refresh_token', 'bundle.authData.refresh_token')],
|
|
246
324
|
grantType: 'refresh_token',
|
|
@@ -250,22 +328,20 @@ const refreshTokenFunc = () => {
|
|
|
250
328
|
'If the refresh token does change, return it here to update the stored value in Zapier',
|
|
251
329
|
),
|
|
252
330
|
],
|
|
331
|
+
language,
|
|
253
332
|
});
|
|
254
333
|
};
|
|
255
334
|
|
|
256
|
-
const oauth2AuthFile = () => {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
includeBearerFunc(bearerFuncName),
|
|
262
|
-
authTestFunc(),
|
|
335
|
+
const oauth2AuthFile = (language) => {
|
|
336
|
+
const fileInput = [
|
|
337
|
+
getAccessTokenFunc(language),
|
|
338
|
+
refreshTokenFunc(language),
|
|
339
|
+
authTestFunc(language),
|
|
263
340
|
authFileExport(
|
|
341
|
+
language,
|
|
264
342
|
'oauth2',
|
|
265
343
|
'OAuth2 is a web authentication standard. There are a lot of configuration options that will fit most any situation.',
|
|
266
344
|
{
|
|
267
|
-
beforeFuncNames: [bearerFuncName],
|
|
268
|
-
afterFuncNames: [],
|
|
269
345
|
extraConfigProps: [
|
|
270
346
|
objProperty(
|
|
271
347
|
'oauth2Config',
|
|
@@ -306,16 +382,65 @@ const oauth2AuthFile = () => {
|
|
|
306
382
|
],
|
|
307
383
|
},
|
|
308
384
|
),
|
|
309
|
-
|
|
385
|
+
];
|
|
386
|
+
// TODO determine if we need to import AuthenticationOAuth2Config
|
|
387
|
+
return language === 'typescript'
|
|
388
|
+
? fileTS(standardTypes, ...fileInput)
|
|
389
|
+
: file(...fileInput);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const oauth2MiddlewareFile = (language) => {
|
|
393
|
+
const bearerFuncName = 'includeBearerToken';
|
|
394
|
+
const fileInput = [
|
|
395
|
+
includeBearerFunc(bearerFuncName, language),
|
|
396
|
+
...middlewareFileExport(language, {
|
|
397
|
+
beforeFuncNames: [bearerFuncName],
|
|
398
|
+
afterFuncNames: [],
|
|
399
|
+
}),
|
|
400
|
+
];
|
|
401
|
+
return language === 'typescript'
|
|
402
|
+
? fileTS(standardTypes, ...fileInput)
|
|
403
|
+
: file(...fileInput);
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const oauth2Files = (language) => {
|
|
407
|
+
return {
|
|
408
|
+
middleware: oauth2MiddlewareFile(language),
|
|
409
|
+
authentication: oauth2AuthFile(language),
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const customAuthFile = (language) => {
|
|
414
|
+
const fileInput = [
|
|
415
|
+
authTestFunc(language),
|
|
416
|
+
authFileExport(
|
|
417
|
+
language,
|
|
418
|
+
'custom',
|
|
419
|
+
'"custom" is the catch-all auth type. The user supplies some info and Zapier can make authenticated requests with it',
|
|
420
|
+
{
|
|
421
|
+
authFields: [
|
|
422
|
+
obj(
|
|
423
|
+
objProperty('key', strLiteral('apiKey')),
|
|
424
|
+
objProperty('label', strLiteral('API Key')),
|
|
425
|
+
objProperty('required', 'true'),
|
|
426
|
+
),
|
|
427
|
+
],
|
|
428
|
+
},
|
|
429
|
+
),
|
|
430
|
+
];
|
|
431
|
+
return language === 'typescript'
|
|
432
|
+
? fileTS(standardTypes, ...fileInput)
|
|
433
|
+
: file(...fileInput);
|
|
310
434
|
};
|
|
311
|
-
|
|
435
|
+
|
|
436
|
+
const customMiddlewareFile = (language) => {
|
|
312
437
|
const includeApiKeyFuncName = 'includeApiKey';
|
|
313
438
|
const handleResponseFuncName = 'handleBadResponses';
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
handleBadResponsesFunc(handleResponseFuncName, 'API Key'),
|
|
439
|
+
const fileInput = [
|
|
440
|
+
handleBadResponsesFunc(handleResponseFuncName, language, 'API Key'),
|
|
317
441
|
beforeMiddlewareFunc(
|
|
318
442
|
includeApiKeyFuncName,
|
|
443
|
+
language,
|
|
319
444
|
ifStatement(
|
|
320
445
|
'bundle.authData.apiKey',
|
|
321
446
|
comment('Use these lines to include the API key in the querystring'),
|
|
@@ -328,49 +453,71 @@ const customAuthFile = () => {
|
|
|
328
453
|
comment('request.headers.Authorization = bundle.authData.apiKey;'),
|
|
329
454
|
),
|
|
330
455
|
),
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
objProperty('key', strLiteral('apiKey')),
|
|
340
|
-
objProperty('label', strLiteral('API Key')),
|
|
341
|
-
objProperty('required', 'true'),
|
|
342
|
-
),
|
|
343
|
-
],
|
|
344
|
-
},
|
|
345
|
-
),
|
|
346
|
-
);
|
|
456
|
+
...middlewareFileExport(language, {
|
|
457
|
+
beforeFuncNames: [includeApiKeyFuncName],
|
|
458
|
+
afterFuncNames: [handleResponseFuncName],
|
|
459
|
+
}),
|
|
460
|
+
];
|
|
461
|
+
return language === 'typescript'
|
|
462
|
+
? fileTS(standardTypes, ...fileInput)
|
|
463
|
+
: file(...fileInput);
|
|
347
464
|
};
|
|
348
465
|
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
466
|
+
const customFiles = (language) => {
|
|
467
|
+
return {
|
|
468
|
+
middleware: customMiddlewareFile(language),
|
|
469
|
+
authentication: customAuthFile(language),
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
const digestAuthFile = (language) => {
|
|
474
|
+
const fileInput = [
|
|
352
475
|
// special digest auth
|
|
353
476
|
authTestFunc(
|
|
477
|
+
language,
|
|
354
478
|
strLiteral(
|
|
355
479
|
'https://httpbin.zapier-tooling.com/digest-auth/auth/myuser/mypass',
|
|
356
480
|
),
|
|
357
481
|
),
|
|
358
|
-
handleBadResponsesFunc(badFuncName),
|
|
359
482
|
authFileExport(
|
|
483
|
+
language,
|
|
360
484
|
'digest',
|
|
361
485
|
'"digest" auth automatically creates "username" and "password" input fields. It also registers default middleware to create the authentication header.',
|
|
362
|
-
{ afterFuncNames: [badFuncName] },
|
|
363
486
|
),
|
|
364
|
-
|
|
487
|
+
];
|
|
488
|
+
return language === 'typescript'
|
|
489
|
+
? fileTS(standardTypes, ...fileInput)
|
|
490
|
+
: file(...fileInput);
|
|
365
491
|
};
|
|
366
492
|
|
|
367
|
-
const
|
|
493
|
+
const digestMiddlewareFile = (language) => {
|
|
494
|
+
const badFuncName = 'handleBadResponses';
|
|
495
|
+
const fileInput = [
|
|
496
|
+
handleBadResponsesFunc(badFuncName, language),
|
|
497
|
+
...middlewareFileExport(language, {
|
|
498
|
+
beforeFuncNames: [],
|
|
499
|
+
afterFuncNames: [badFuncName],
|
|
500
|
+
}),
|
|
501
|
+
];
|
|
502
|
+
return language === 'typescript'
|
|
503
|
+
? fileTS(standardTypes, ...fileInput)
|
|
504
|
+
: file(...fileInput);
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const digestFiles = (language) => {
|
|
508
|
+
return {
|
|
509
|
+
middleware: digestMiddlewareFile(language),
|
|
510
|
+
authentication: digestAuthFile(language),
|
|
511
|
+
};
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
const sessionAuthFile = (language) => {
|
|
368
515
|
const getSessionKeyName = 'getSessionKey';
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
authTestFunc(),
|
|
516
|
+
const fileInput = [
|
|
517
|
+
authTestFunc(language),
|
|
372
518
|
tokenExchangeFunc(
|
|
373
519
|
getSessionKeyName,
|
|
520
|
+
language,
|
|
374
521
|
'https://httpbin.zapier-tooling.com/post',
|
|
375
522
|
[
|
|
376
523
|
objProperty('username', 'bundle.authData.username'),
|
|
@@ -383,23 +530,11 @@ const sessionAuthFile = () => {
|
|
|
383
530
|
objProperty('sessionKey', 'response.data.sessionKey || "secret"'),
|
|
384
531
|
],
|
|
385
532
|
),
|
|
386
|
-
beforeMiddlewareFunc(
|
|
387
|
-
includeSessionKeyName,
|
|
388
|
-
ifStatement(
|
|
389
|
-
'bundle.authData.sessionKey',
|
|
390
|
-
assignmentStatement('request.headers', 'request.headers || {}'),
|
|
391
|
-
assignmentStatement(
|
|
392
|
-
"request.headers['X-API-Key']",
|
|
393
|
-
'bundle.authData.sessionKey',
|
|
394
|
-
),
|
|
395
|
-
),
|
|
396
|
-
),
|
|
397
533
|
authFileExport(
|
|
534
|
+
language,
|
|
398
535
|
'session',
|
|
399
536
|
'"session" auth exchanges user data for a different session token (that may be periodically refreshed")',
|
|
400
537
|
{
|
|
401
|
-
beforeFuncNames: [includeSessionKeyName],
|
|
402
|
-
afterFuncNames: [],
|
|
403
538
|
authFields: [
|
|
404
539
|
obj(
|
|
405
540
|
objProperty('key', strLiteral('username')),
|
|
@@ -422,13 +557,54 @@ const sessionAuthFile = () => {
|
|
|
422
557
|
],
|
|
423
558
|
},
|
|
424
559
|
),
|
|
425
|
-
|
|
560
|
+
];
|
|
561
|
+
return language === 'typescript'
|
|
562
|
+
? fileTS(standardTypes, ...fileInput)
|
|
563
|
+
: file(...fileInput);
|
|
426
564
|
};
|
|
565
|
+
|
|
566
|
+
const sessionMiddlewareFile = (language) => {
|
|
567
|
+
const includeSessionKeyName = 'includeSessionKeyHeader';
|
|
568
|
+
const fileInput = [
|
|
569
|
+
beforeMiddlewareFunc(
|
|
570
|
+
includeSessionKeyName,
|
|
571
|
+
language,
|
|
572
|
+
ifStatement(
|
|
573
|
+
'bundle.authData.sessionKey',
|
|
574
|
+
assignmentStatement('request.headers', 'request.headers || {}'),
|
|
575
|
+
assignmentStatement(
|
|
576
|
+
"request.headers['X-API-Key']",
|
|
577
|
+
'bundle.authData.sessionKey',
|
|
578
|
+
),
|
|
579
|
+
),
|
|
580
|
+
),
|
|
581
|
+
...middlewareFileExport(language, {
|
|
582
|
+
beforeFuncNames: [includeSessionKeyName],
|
|
583
|
+
afterFuncNames: [],
|
|
584
|
+
}),
|
|
585
|
+
];
|
|
586
|
+
return language === 'typescript'
|
|
587
|
+
? fileTS(standardTypes, ...fileInput)
|
|
588
|
+
: file(...fileInput);
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
const sessionFiles = (language) => {
|
|
592
|
+
return {
|
|
593
|
+
middleware: sessionMiddlewareFile(language),
|
|
594
|
+
authentication: sessionAuthFile(language),
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
|
|
427
598
|
// just different enough from oauth2 that it gets its own function
|
|
428
|
-
const oauth1TokenExchangeFunc = (
|
|
599
|
+
const oauth1TokenExchangeFunc = (
|
|
600
|
+
funcName,
|
|
601
|
+
language,
|
|
602
|
+
url,
|
|
603
|
+
...authProperties
|
|
604
|
+
) => {
|
|
429
605
|
return functionDeclaration(
|
|
430
606
|
funcName,
|
|
431
|
-
{ args: standardArgs, isAsync: true },
|
|
607
|
+
{ args: standardArgs(language), isAsync: true },
|
|
432
608
|
variableAssignmentDeclaration(
|
|
433
609
|
RESPONSE_VAR,
|
|
434
610
|
awaitStatement(
|
|
@@ -449,13 +625,13 @@ const oauth1TokenExchangeFunc = (funcName, url, ...authProperties) => {
|
|
|
449
625
|
returnStatement(`querystring.parse(${RESPONSE_VAR}.content)`),
|
|
450
626
|
);
|
|
451
627
|
};
|
|
452
|
-
|
|
628
|
+
|
|
629
|
+
const oauth1AuthFile = (language) => {
|
|
453
630
|
const requestTokenVarName = 'REQUEST_TOKEN_URL';
|
|
454
631
|
const accessTokenVarName = 'ACCESS_TOKEN_URL';
|
|
455
632
|
const authorizeUrlVarName = 'AUTHORIZE_URL';
|
|
456
633
|
const getRequestTokenFuncName = 'getRequestToken';
|
|
457
|
-
const
|
|
458
|
-
return file(
|
|
634
|
+
const fileInput = [
|
|
459
635
|
variableAssignmentDeclaration('querystring', "require('querystring')"),
|
|
460
636
|
block(
|
|
461
637
|
variableAssignmentDeclaration(
|
|
@@ -473,6 +649,7 @@ const oauth1AuthFile = () => {
|
|
|
473
649
|
),
|
|
474
650
|
oauth1TokenExchangeFunc(
|
|
475
651
|
getRequestTokenFuncName,
|
|
652
|
+
language,
|
|
476
653
|
requestTokenVarName,
|
|
477
654
|
objProperty('oauth_signature_method', strLiteral('HMAC-SHA1')),
|
|
478
655
|
objProperty('oauth_callback', 'bundle.inputData.redirect_uri'),
|
|
@@ -480,37 +657,14 @@ const oauth1AuthFile = () => {
|
|
|
480
657
|
),
|
|
481
658
|
oauth1TokenExchangeFunc(
|
|
482
659
|
getOauthAccessTokenFuncName,
|
|
660
|
+
language,
|
|
483
661
|
accessTokenVarName,
|
|
484
662
|
objProperty('oauth_token', 'bundle.inputData.oauth_token'),
|
|
485
663
|
objProperty('oauth_token_secret', 'bundle.inputData.oauth_token_secret'),
|
|
486
664
|
objProperty('oauth_verifier', 'bundle.inputData.oauth_verifier'),
|
|
487
665
|
),
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
ifStatement(
|
|
491
|
-
'bundle.authData && bundle.authData.oauth_token && bundle.authData.oauth_token_secret',
|
|
492
|
-
comment(
|
|
493
|
-
'Put your OAuth1 credentials in `req.auth`, Zapier will sign the request for you.',
|
|
494
|
-
),
|
|
495
|
-
assignmentStatement(
|
|
496
|
-
'request.auth',
|
|
497
|
-
obj(
|
|
498
|
-
objProperty('oauth_consumer_key', 'process.env.CLIENT_ID'),
|
|
499
|
-
objProperty('oauth_consumer_secret', 'process.env.CLIENT_SECRET'),
|
|
500
|
-
objProperty('oauth_token', 'bundle.authData.oauth_token'),
|
|
501
|
-
objProperty(
|
|
502
|
-
'oauth_token_secret',
|
|
503
|
-
'bundle.authData.oauth_token_secret',
|
|
504
|
-
),
|
|
505
|
-
comment("oauth_version: '1.0', // sometimes required"),
|
|
506
|
-
objProperty('...(request.auth || {})'),
|
|
507
|
-
),
|
|
508
|
-
),
|
|
509
|
-
),
|
|
510
|
-
),
|
|
511
|
-
authTestFunc(strLiteral('https://api.trello.com/1/members/me/')),
|
|
512
|
-
authFileExport('oauth1', 'OAuth1 is an older form of OAuth', {
|
|
513
|
-
beforeFuncNames: [includeAccessTokenFuncName],
|
|
666
|
+
authTestFunc(language, strLiteral('https://api.trello.com/1/members/me/')),
|
|
667
|
+
authFileExport(language, 'oauth1', 'OAuth1 is an older form of OAuth', {
|
|
514
668
|
extraConfigProps: [
|
|
515
669
|
objProperty(
|
|
516
670
|
'oauth1Config',
|
|
@@ -544,14 +698,61 @@ const oauth1AuthFile = () => {
|
|
|
544
698
|
],
|
|
545
699
|
connectionLabel: strLiteral('{{username}}'),
|
|
546
700
|
}),
|
|
547
|
-
|
|
701
|
+
];
|
|
702
|
+
return language === 'typescript'
|
|
703
|
+
? fileTS(standardTypes, ...fileInput)
|
|
704
|
+
: file(...fileInput);
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
const oauth1MiddlewareFile = (language) => {
|
|
708
|
+
const includeAccessTokenFuncName = 'includeAccessToken';
|
|
709
|
+
const fileInput = [
|
|
710
|
+
beforeMiddlewareFunc(
|
|
711
|
+
includeAccessTokenFuncName,
|
|
712
|
+
language,
|
|
713
|
+
ifStatement(
|
|
714
|
+
'bundle.authData && bundle.authData.oauth_token && bundle.authData.oauth_token_secret',
|
|
715
|
+
comment(
|
|
716
|
+
'Put your OAuth1 credentials in `req.auth`, Zapier will sign the request for you.',
|
|
717
|
+
),
|
|
718
|
+
assignmentStatement(
|
|
719
|
+
'request.auth',
|
|
720
|
+
obj(
|
|
721
|
+
objProperty('oauth_consumer_key', 'process.env.CLIENT_ID'),
|
|
722
|
+
objProperty('oauth_consumer_secret', 'process.env.CLIENT_SECRET'),
|
|
723
|
+
objProperty('oauth_token', 'bundle.authData.oauth_token'),
|
|
724
|
+
objProperty(
|
|
725
|
+
'oauth_token_secret',
|
|
726
|
+
'bundle.authData.oauth_token_secret',
|
|
727
|
+
),
|
|
728
|
+
comment("oauth_version: '1.0', // sometimes required"),
|
|
729
|
+
objProperty('...(request.auth || {})'),
|
|
730
|
+
),
|
|
731
|
+
),
|
|
732
|
+
),
|
|
733
|
+
),
|
|
734
|
+
...middlewareFileExport(language, {
|
|
735
|
+
beforeFuncNames: [includeAccessTokenFuncName],
|
|
736
|
+
afterFuncNames: [],
|
|
737
|
+
}),
|
|
738
|
+
];
|
|
739
|
+
return language === 'typescript'
|
|
740
|
+
? fileTS(standardTypes, ...fileInput)
|
|
741
|
+
: file(...fileInput);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
const oauth1Files = (language) => {
|
|
745
|
+
return {
|
|
746
|
+
middleware: oauth1MiddlewareFile(language),
|
|
747
|
+
authentication: oauth1AuthFile(language),
|
|
748
|
+
};
|
|
548
749
|
};
|
|
549
750
|
|
|
550
751
|
module.exports = {
|
|
551
|
-
basic:
|
|
552
|
-
custom:
|
|
553
|
-
digest:
|
|
554
|
-
oauth1:
|
|
555
|
-
oauth2:
|
|
556
|
-
session:
|
|
752
|
+
basic: basicFiles,
|
|
753
|
+
custom: customFiles,
|
|
754
|
+
digest: digestFiles,
|
|
755
|
+
oauth1: oauth1Files,
|
|
756
|
+
oauth2: oauth2Files,
|
|
757
|
+
session: sessionFiles,
|
|
557
758
|
};
|