zapier-platform-cli 17.3.1 → 17.4.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.ts +11 -14
- package/src/generators/templates/tsconfig.template.json +18 -0
- package/src/oclif/commands/init.js +9 -2
- package/src/oclif/commands/versions.js +0 -24
- package/src/utils/auth-files-codegen.js +141 -69
- package/src/utils/build.js +49 -53
- package/src/utils/codegen.js +24 -4
- 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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import zapier from 'zapier-platform-core';
|
|
3
|
+
|
|
4
|
+
import App from '../index.js';
|
|
5
|
+
const appTester = zapier.createAppTester(App);
|
|
6
|
+
|
|
7
|
+
describe('session auth app', () => {
|
|
8
|
+
it('has an exchange for username/password', async () => {
|
|
9
|
+
const bundle = {
|
|
10
|
+
authData: {
|
|
11
|
+
username: 'bryan',
|
|
12
|
+
password: 'hunter2',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const newAuthData = await appTester(
|
|
17
|
+
App.authentication.sessionConfig.perform,
|
|
18
|
+
bundle
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(newAuthData.sessionKey).toBe('secret');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('has auth details added to every request', async () => {
|
|
25
|
+
const bundle = {
|
|
26
|
+
authData: {
|
|
27
|
+
sessionKey: 'secret',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const response = await appTester(App.authentication.test, bundle);
|
|
32
|
+
|
|
33
|
+
expect(response.status).toBe(200);
|
|
34
|
+
expect(response.request.headers['X-API-Key']).toBe('secret');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import zapier, { defineApp } from 'zapier-platform-core';
|
|
2
2
|
|
|
3
|
-
import packageJson from '../package.json';
|
|
3
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import authentication from './authentication';
|
|
8
|
-
import { addBearerHeader } from './middleware';
|
|
5
|
+
import authenticationModule from './authentication.js';
|
|
6
|
+
const { config: authentication, befores, afters } = authenticationModule;
|
|
9
7
|
|
|
10
8
|
export default defineApp({
|
|
11
9
|
version: packageJson.version,
|
|
12
|
-
platformVersion,
|
|
10
|
+
platformVersion: zapier.version,
|
|
13
11
|
|
|
14
12
|
authentication,
|
|
15
|
-
beforeRequest: [
|
|
13
|
+
beforeRequest: [...befores],
|
|
14
|
+
afterResponse: [...afters],
|
|
16
15
|
|
|
17
|
-
triggers
|
|
18
|
-
|
|
19
|
-
},
|
|
16
|
+
// Add your triggers here for them to show up!
|
|
17
|
+
triggers: {},
|
|
20
18
|
|
|
21
|
-
creates
|
|
22
|
-
|
|
23
|
-
},
|
|
19
|
+
// Add your creates here for them to show up!
|
|
20
|
+
creates: {},
|
|
24
21
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"resolveJsonModule": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"noUncheckedIndexedAccess": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"noImplicitAny": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"rootDir": "./src",
|
|
14
|
+
"strict": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["./src/**/*.ts"],
|
|
17
|
+
"exclude": ["./**/*.test.ts"]
|
|
18
|
+
}
|
|
@@ -10,12 +10,12 @@ const { TEMPLATE_CHOICES, ProjectGenerator } = require('../../generators');
|
|
|
10
10
|
class InitCommand extends BaseCommand {
|
|
11
11
|
async perform() {
|
|
12
12
|
const { path } = this.args;
|
|
13
|
-
const { template, module } = this.flags;
|
|
13
|
+
const { template, module, language } = this.flags;
|
|
14
14
|
|
|
15
15
|
const env = yeoman.createEnv();
|
|
16
16
|
env.registerStub(ProjectGenerator, 'zapier:integration');
|
|
17
17
|
|
|
18
|
-
await env.run('zapier:integration', { path, template, module });
|
|
18
|
+
await env.run('zapier:integration', { path, template, module, language });
|
|
19
19
|
|
|
20
20
|
this.log();
|
|
21
21
|
this.log(`A new integration has been created in directory "${path}".`);
|
|
@@ -36,6 +36,12 @@ InitCommand.flags = buildFlags({
|
|
|
36
36
|
'Choose module type: CommonJS or ES Modules. Only enabled for Typescript and Minimal templates.',
|
|
37
37
|
options: ['commonjs', 'esm'],
|
|
38
38
|
}),
|
|
39
|
+
language: Flags.string({
|
|
40
|
+
char: 'l',
|
|
41
|
+
description:
|
|
42
|
+
'Choose the language to use for your new integration. Defaults to JavaScript.',
|
|
43
|
+
options: ['javascript', 'typescript'],
|
|
44
|
+
}),
|
|
39
45
|
},
|
|
40
46
|
});
|
|
41
47
|
InitCommand.args = {
|
|
@@ -49,6 +55,7 @@ InitCommand.examples = [
|
|
|
49
55
|
'zapier init myapp',
|
|
50
56
|
'zapier init ./path/myapp --template oauth2',
|
|
51
57
|
'zapier init ./path/myapp --template minimal --module esm',
|
|
58
|
+
'zapier init ./path/myapp --template oauth2 --language typescript',
|
|
52
59
|
];
|
|
53
60
|
InitCommand.description = `Initialize a new Zapier integration with a project template.
|
|
54
61
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const colors = require('colors/safe');
|
|
2
1
|
const { Flags } = require('@oclif/core');
|
|
3
2
|
const BaseCommand = require('../ZapierBaseCommand');
|
|
4
3
|
const { buildFlags } = require('../buildFlags');
|
|
@@ -34,29 +33,6 @@ class VersionCommand extends BaseCommand {
|
|
|
34
33
|
'No versions to show. Try adding one with the `zapier push` command',
|
|
35
34
|
});
|
|
36
35
|
|
|
37
|
-
this.logTable({
|
|
38
|
-
headers: [],
|
|
39
|
-
rows: [
|
|
40
|
-
{
|
|
41
|
-
version: `- ${colors.bold('Errors')}`,
|
|
42
|
-
platform_version:
|
|
43
|
-
'Issues that will prevent your integration from functioning properly. They block you from pushing.',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
version: `- ${colors.bold('Publishing Tasks')}`,
|
|
47
|
-
platform_version:
|
|
48
|
-
'To-dos that must be addressed before your integration can be included in the App Directory. They block you from promoting and publishing.',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
version: `- ${colors.bold('Warnings')}`,
|
|
52
|
-
platform_version:
|
|
53
|
-
"Issues and recommendations that need human reviews by Zapier before publishing your integration. They don't block.",
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
hasBorder: false,
|
|
57
|
-
style: { head: [], 'padding-left': 0, 'padding-right': 0 },
|
|
58
|
-
});
|
|
59
|
-
|
|
60
36
|
if (versions.map((v) => v.user_count).filter((c) => c === null).length) {
|
|
61
37
|
this.warn(
|
|
62
38
|
'Some user counts are still being calculated - run this command again in ~10 seconds (or longer if your integration has lots of users).',
|
|
@@ -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,6 +46,7 @@ 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
|
{
|
|
@@ -45,37 +58,44 @@ const authFileExport = (
|
|
|
45
58
|
authFields = [],
|
|
46
59
|
} = {},
|
|
47
60
|
) => {
|
|
61
|
+
const configProps = [
|
|
62
|
+
comment(authDescription),
|
|
63
|
+
objProperty('type', strLiteral(authType)),
|
|
64
|
+
...extraConfigProps,
|
|
65
|
+
comment(
|
|
66
|
+
"Define any input app's auth requires here. The user will be prompted to enter this info when they connect their account.",
|
|
67
|
+
),
|
|
68
|
+
objProperty('fields', arr(...authFields)),
|
|
69
|
+
comment(
|
|
70
|
+
"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.",
|
|
71
|
+
),
|
|
72
|
+
test,
|
|
73
|
+
comment(
|
|
74
|
+
`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(
|
|
75
|
+
language,
|
|
76
|
+
).join(
|
|
77
|
+
', ',
|
|
78
|
+
)})\` and data returned from the test can be accessed in \`bundle.inputData.X\`.`,
|
|
79
|
+
),
|
|
80
|
+
objProperty('connectionLabel', connectionLabel),
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const configObj =
|
|
84
|
+
language === 'typescript'
|
|
85
|
+
? objTS('Authentication', ...configProps)
|
|
86
|
+
: obj(...configProps);
|
|
87
|
+
|
|
48
88
|
return exportStatement(
|
|
49
89
|
obj(
|
|
50
|
-
objProperty(
|
|
51
|
-
'config',
|
|
52
|
-
obj(
|
|
53
|
-
comment(authDescription),
|
|
54
|
-
objProperty('type', strLiteral(authType)),
|
|
55
|
-
...extraConfigProps,
|
|
56
|
-
comment(
|
|
57
|
-
"Define any input app's auth requires here. The user will be prompted to enter this info when they connect their account.",
|
|
58
|
-
),
|
|
59
|
-
objProperty('fields', arr(...authFields)),
|
|
60
|
-
comment(
|
|
61
|
-
"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.",
|
|
62
|
-
),
|
|
63
|
-
test,
|
|
64
|
-
comment(
|
|
65
|
-
`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.join(
|
|
66
|
-
', ',
|
|
67
|
-
)})\` and data returned from the test can be accessed in \`bundle.inputData.X\`.`,
|
|
68
|
-
),
|
|
69
|
-
objProperty('connectionLabel', connectionLabel),
|
|
70
|
-
),
|
|
71
|
-
),
|
|
90
|
+
objProperty('config', configObj),
|
|
72
91
|
objProperty('befores', arr(...beforeFuncNames)),
|
|
73
92
|
objProperty('afters', arr(...afterFuncNames)),
|
|
74
93
|
),
|
|
94
|
+
language,
|
|
75
95
|
);
|
|
76
96
|
};
|
|
77
97
|
|
|
78
|
-
const authTestFunc = (testUrl = strLiteral(authJsonUrl('me'))) =>
|
|
98
|
+
const authTestFunc = (language, testUrl = strLiteral(authJsonUrl('me'))) =>
|
|
79
99
|
block(
|
|
80
100
|
comment(
|
|
81
101
|
'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 +103,21 @@ const authTestFunc = (testUrl = strLiteral(authJsonUrl('me'))) =>
|
|
|
83
103
|
comment(
|
|
84
104
|
'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
105
|
),
|
|
86
|
-
fatArrowReturnFunctionDeclaration(
|
|
106
|
+
fatArrowReturnFunctionDeclaration(
|
|
107
|
+
'test',
|
|
108
|
+
standardArgs(language),
|
|
109
|
+
zRequest(testUrl),
|
|
110
|
+
),
|
|
87
111
|
);
|
|
88
112
|
|
|
89
113
|
const handleBadResponsesFunc = (
|
|
90
114
|
funcName,
|
|
115
|
+
language,
|
|
91
116
|
invalidInfo = 'username and/or password',
|
|
92
117
|
) =>
|
|
93
118
|
afterMiddlewareFunc(
|
|
94
119
|
funcName,
|
|
120
|
+
language,
|
|
95
121
|
ifStatement(
|
|
96
122
|
'response.status === 401',
|
|
97
123
|
zResponseErr(strLiteral(`The ${invalidInfo} you supplied is incorrect`)),
|
|
@@ -99,30 +125,34 @@ const handleBadResponsesFunc = (
|
|
|
99
125
|
returnStatement(RESPONSE_VAR),
|
|
100
126
|
);
|
|
101
127
|
|
|
102
|
-
const basicAuthFile = () => {
|
|
128
|
+
const basicAuthFile = (language) => {
|
|
103
129
|
const badFuncName = 'handleBadResponses';
|
|
104
|
-
|
|
105
|
-
authTestFunc(),
|
|
106
|
-
handleBadResponsesFunc(badFuncName),
|
|
130
|
+
const fileInput = [
|
|
131
|
+
authTestFunc(language),
|
|
132
|
+
handleBadResponsesFunc(badFuncName, language),
|
|
107
133
|
authFileExport(
|
|
134
|
+
language,
|
|
108
135
|
'basic',
|
|
109
136
|
'"basic" auth automatically creates "username" and "password" input fields. It also registers default middleware to create the authentication header.',
|
|
110
137
|
{ afterFuncNames: [badFuncName] },
|
|
111
138
|
),
|
|
112
|
-
|
|
139
|
+
];
|
|
140
|
+
return language === 'typescript'
|
|
141
|
+
? fileTS(standardTypes, ...fileInput)
|
|
142
|
+
: file(...fileInput);
|
|
113
143
|
};
|
|
114
144
|
|
|
115
145
|
/**
|
|
116
146
|
* boilerplate for a "before" middleware. No need to return the requst at the end
|
|
117
147
|
*/
|
|
118
|
-
const beforeMiddlewareFunc = (funcName, ...statements) =>
|
|
148
|
+
const beforeMiddlewareFunc = (funcName, language, ...statements) =>
|
|
119
149
|
block(
|
|
120
150
|
comment(
|
|
121
151
|
"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
152
|
),
|
|
123
153
|
functionDeclaration(
|
|
124
154
|
funcName,
|
|
125
|
-
{ args: beforeMiddlewareArgs },
|
|
155
|
+
{ args: beforeMiddlewareArgs(language) },
|
|
126
156
|
...statements,
|
|
127
157
|
// auto include the return if it's not here already
|
|
128
158
|
statements[statements.length - 1].includes('return')
|
|
@@ -131,17 +161,22 @@ const beforeMiddlewareFunc = (funcName, ...statements) =>
|
|
|
131
161
|
),
|
|
132
162
|
);
|
|
133
163
|
|
|
134
|
-
const afterMiddlewareFunc = (funcName, ...statements) =>
|
|
164
|
+
const afterMiddlewareFunc = (funcName, language, ...statements) =>
|
|
135
165
|
block(
|
|
136
166
|
comment(
|
|
137
167
|
"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
168
|
),
|
|
139
|
-
functionDeclaration(
|
|
169
|
+
functionDeclaration(
|
|
170
|
+
funcName,
|
|
171
|
+
{ args: afterMiddlewareArgs(language) },
|
|
172
|
+
...statements,
|
|
173
|
+
),
|
|
140
174
|
);
|
|
141
175
|
|
|
142
|
-
const includeBearerFunc = (funcName) =>
|
|
176
|
+
const includeBearerFunc = (funcName, language) =>
|
|
143
177
|
beforeMiddlewareFunc(
|
|
144
178
|
funcName,
|
|
179
|
+
language,
|
|
145
180
|
ifStatement(
|
|
146
181
|
'bundle.authData.access_token',
|
|
147
182
|
assignmentStatement(
|
|
@@ -154,6 +189,7 @@ const includeBearerFunc = (funcName) =>
|
|
|
154
189
|
|
|
155
190
|
const tokenExchangeFunc = (
|
|
156
191
|
funcName,
|
|
192
|
+
language,
|
|
157
193
|
requestUrl,
|
|
158
194
|
bodyProps,
|
|
159
195
|
returnProps,
|
|
@@ -161,7 +197,7 @@ const tokenExchangeFunc = (
|
|
|
161
197
|
) =>
|
|
162
198
|
functionDeclaration(
|
|
163
199
|
funcName,
|
|
164
|
-
{ args: standardArgs, isAsync: true },
|
|
200
|
+
{ args: standardArgs(language), isAsync: true },
|
|
165
201
|
variableAssignmentDeclaration(
|
|
166
202
|
RESPONSE_VAR,
|
|
167
203
|
awaitStatement(
|
|
@@ -183,10 +219,12 @@ const tokenExchangeFunc = (
|
|
|
183
219
|
|
|
184
220
|
const oauth2TokenExchangeFunc = (
|
|
185
221
|
funcName,
|
|
222
|
+
language,
|
|
186
223
|
{ path, grantType, bodyProps = [], returnComments = [] },
|
|
187
224
|
) => {
|
|
188
225
|
return tokenExchangeFunc(
|
|
189
226
|
funcName,
|
|
227
|
+
language,
|
|
190
228
|
authJsonUrl(path),
|
|
191
229
|
[
|
|
192
230
|
objProperty('client_id', 'process.env.CLIENT_ID'),
|
|
@@ -218,8 +256,8 @@ const oauth2TokenExchangeFunc = (
|
|
|
218
256
|
);
|
|
219
257
|
};
|
|
220
258
|
|
|
221
|
-
const getAccessTokenFunc = () => {
|
|
222
|
-
return oauth2TokenExchangeFunc(getOauthAccessTokenFuncName, {
|
|
259
|
+
const getAccessTokenFunc = (language) => {
|
|
260
|
+
return oauth2TokenExchangeFunc(getOauthAccessTokenFuncName, language, {
|
|
223
261
|
path: 'oauth/access-token',
|
|
224
262
|
bodyProps: [
|
|
225
263
|
objProperty('code', 'bundle.inputData.code'),
|
|
@@ -239,8 +277,8 @@ const getAccessTokenFunc = () => {
|
|
|
239
277
|
});
|
|
240
278
|
};
|
|
241
279
|
|
|
242
|
-
const refreshTokenFunc = () => {
|
|
243
|
-
return oauth2TokenExchangeFunc(refreshOath2AccessTokenFuncName, {
|
|
280
|
+
const refreshTokenFunc = (language) => {
|
|
281
|
+
return oauth2TokenExchangeFunc(refreshOath2AccessTokenFuncName, language, {
|
|
244
282
|
path: 'oauth/refresh-token',
|
|
245
283
|
bodyProps: [objProperty('refresh_token', 'bundle.authData.refresh_token')],
|
|
246
284
|
grantType: 'refresh_token',
|
|
@@ -253,14 +291,15 @@ const refreshTokenFunc = () => {
|
|
|
253
291
|
});
|
|
254
292
|
};
|
|
255
293
|
|
|
256
|
-
const oauth2AuthFile = () => {
|
|
294
|
+
const oauth2AuthFile = (language) => {
|
|
257
295
|
const bearerFuncName = 'includeBearerToken';
|
|
258
|
-
|
|
259
|
-
getAccessTokenFunc(),
|
|
260
|
-
refreshTokenFunc(),
|
|
261
|
-
includeBearerFunc(bearerFuncName),
|
|
262
|
-
authTestFunc(),
|
|
296
|
+
const fileInput = [
|
|
297
|
+
getAccessTokenFunc(language),
|
|
298
|
+
refreshTokenFunc(language),
|
|
299
|
+
includeBearerFunc(bearerFuncName, language),
|
|
300
|
+
authTestFunc(language),
|
|
263
301
|
authFileExport(
|
|
302
|
+
language,
|
|
264
303
|
'oauth2',
|
|
265
304
|
'OAuth2 is a web authentication standard. There are a lot of configuration options that will fit most any situation.',
|
|
266
305
|
{
|
|
@@ -306,16 +345,21 @@ const oauth2AuthFile = () => {
|
|
|
306
345
|
],
|
|
307
346
|
},
|
|
308
347
|
),
|
|
309
|
-
|
|
348
|
+
];
|
|
349
|
+
// TODO determine if we need to import AuthenticationOAuth2Config
|
|
350
|
+
return language === 'typescript'
|
|
351
|
+
? fileTS(standardTypes, ...fileInput)
|
|
352
|
+
: file(...fileInput);
|
|
310
353
|
};
|
|
311
|
-
const customAuthFile = () => {
|
|
354
|
+
const customAuthFile = (language) => {
|
|
312
355
|
const includeApiKeyFuncName = 'includeApiKey';
|
|
313
356
|
const handleResponseFuncName = 'handleBadResponses';
|
|
314
|
-
|
|
315
|
-
authTestFunc(),
|
|
316
|
-
handleBadResponsesFunc(handleResponseFuncName, 'API Key'),
|
|
357
|
+
const fileInput = [
|
|
358
|
+
authTestFunc(language),
|
|
359
|
+
handleBadResponsesFunc(handleResponseFuncName, language, 'API Key'),
|
|
317
360
|
beforeMiddlewareFunc(
|
|
318
361
|
includeApiKeyFuncName,
|
|
362
|
+
language,
|
|
319
363
|
ifStatement(
|
|
320
364
|
'bundle.authData.apiKey',
|
|
321
365
|
comment('Use these lines to include the API key in the querystring'),
|
|
@@ -329,6 +373,7 @@ const customAuthFile = () => {
|
|
|
329
373
|
),
|
|
330
374
|
),
|
|
331
375
|
authFileExport(
|
|
376
|
+
language,
|
|
332
377
|
'custom',
|
|
333
378
|
'"custom" is the catch-all auth type. The user supplies some info and Zapier can make authenticated requests with it',
|
|
334
379
|
{
|
|
@@ -343,34 +388,43 @@ const customAuthFile = () => {
|
|
|
343
388
|
],
|
|
344
389
|
},
|
|
345
390
|
),
|
|
346
|
-
|
|
391
|
+
];
|
|
392
|
+
return language === 'typescript'
|
|
393
|
+
? fileTS(standardTypes, ...fileInput)
|
|
394
|
+
: file(...fileInput);
|
|
347
395
|
};
|
|
348
396
|
|
|
349
|
-
const digestAuthFile = () => {
|
|
397
|
+
const digestAuthFile = (language) => {
|
|
350
398
|
const badFuncName = 'handleBadResponses';
|
|
351
|
-
|
|
399
|
+
const fileInput = [
|
|
352
400
|
// special digest auth
|
|
353
401
|
authTestFunc(
|
|
402
|
+
language,
|
|
354
403
|
strLiteral(
|
|
355
404
|
'https://httpbin.zapier-tooling.com/digest-auth/auth/myuser/mypass',
|
|
356
405
|
),
|
|
357
406
|
),
|
|
358
|
-
handleBadResponsesFunc(badFuncName),
|
|
407
|
+
handleBadResponsesFunc(badFuncName, language),
|
|
359
408
|
authFileExport(
|
|
409
|
+
language,
|
|
360
410
|
'digest',
|
|
361
411
|
'"digest" auth automatically creates "username" and "password" input fields. It also registers default middleware to create the authentication header.',
|
|
362
412
|
{ afterFuncNames: [badFuncName] },
|
|
363
413
|
),
|
|
364
|
-
|
|
414
|
+
];
|
|
415
|
+
return language === 'typescript'
|
|
416
|
+
? fileTS(standardTypes, ...fileInput)
|
|
417
|
+
: file(...fileInput);
|
|
365
418
|
};
|
|
366
419
|
|
|
367
|
-
const sessionAuthFile = () => {
|
|
420
|
+
const sessionAuthFile = (language) => {
|
|
368
421
|
const getSessionKeyName = 'getSessionKey';
|
|
369
422
|
const includeSessionKeyName = 'includeSessionKeyHeader';
|
|
370
|
-
|
|
371
|
-
authTestFunc(),
|
|
423
|
+
const fileInput = [
|
|
424
|
+
authTestFunc(language),
|
|
372
425
|
tokenExchangeFunc(
|
|
373
426
|
getSessionKeyName,
|
|
427
|
+
language,
|
|
374
428
|
'https://httpbin.zapier-tooling.com/post',
|
|
375
429
|
[
|
|
376
430
|
objProperty('username', 'bundle.authData.username'),
|
|
@@ -385,6 +439,7 @@ const sessionAuthFile = () => {
|
|
|
385
439
|
),
|
|
386
440
|
beforeMiddlewareFunc(
|
|
387
441
|
includeSessionKeyName,
|
|
442
|
+
language,
|
|
388
443
|
ifStatement(
|
|
389
444
|
'bundle.authData.sessionKey',
|
|
390
445
|
assignmentStatement('request.headers', 'request.headers || {}'),
|
|
@@ -395,6 +450,7 @@ const sessionAuthFile = () => {
|
|
|
395
450
|
),
|
|
396
451
|
),
|
|
397
452
|
authFileExport(
|
|
453
|
+
language,
|
|
398
454
|
'session',
|
|
399
455
|
'"session" auth exchanges user data for a different session token (that may be periodically refreshed")',
|
|
400
456
|
{
|
|
@@ -422,13 +478,22 @@ const sessionAuthFile = () => {
|
|
|
422
478
|
],
|
|
423
479
|
},
|
|
424
480
|
),
|
|
425
|
-
|
|
481
|
+
];
|
|
482
|
+
return language === 'typescript'
|
|
483
|
+
? fileTS(standardTypes, ...fileInput)
|
|
484
|
+
: file(...fileInput);
|
|
426
485
|
};
|
|
486
|
+
|
|
427
487
|
// just different enough from oauth2 that it gets its own function
|
|
428
|
-
const oauth1TokenExchangeFunc = (
|
|
488
|
+
const oauth1TokenExchangeFunc = (
|
|
489
|
+
funcName,
|
|
490
|
+
language,
|
|
491
|
+
url,
|
|
492
|
+
...authProperties
|
|
493
|
+
) => {
|
|
429
494
|
return functionDeclaration(
|
|
430
495
|
funcName,
|
|
431
|
-
{ args: standardArgs, isAsync: true },
|
|
496
|
+
{ args: standardArgs(language), isAsync: true },
|
|
432
497
|
variableAssignmentDeclaration(
|
|
433
498
|
RESPONSE_VAR,
|
|
434
499
|
awaitStatement(
|
|
@@ -449,13 +514,14 @@ const oauth1TokenExchangeFunc = (funcName, url, ...authProperties) => {
|
|
|
449
514
|
returnStatement(`querystring.parse(${RESPONSE_VAR}.content)`),
|
|
450
515
|
);
|
|
451
516
|
};
|
|
452
|
-
|
|
517
|
+
|
|
518
|
+
const oauth1AuthFile = (language) => {
|
|
453
519
|
const requestTokenVarName = 'REQUEST_TOKEN_URL';
|
|
454
520
|
const accessTokenVarName = 'ACCESS_TOKEN_URL';
|
|
455
521
|
const authorizeUrlVarName = 'AUTHORIZE_URL';
|
|
456
522
|
const getRequestTokenFuncName = 'getRequestToken';
|
|
457
523
|
const includeAccessTokenFuncName = 'includeAccessToken';
|
|
458
|
-
|
|
524
|
+
const fileInput = [
|
|
459
525
|
variableAssignmentDeclaration('querystring', "require('querystring')"),
|
|
460
526
|
block(
|
|
461
527
|
variableAssignmentDeclaration(
|
|
@@ -473,6 +539,7 @@ const oauth1AuthFile = () => {
|
|
|
473
539
|
),
|
|
474
540
|
oauth1TokenExchangeFunc(
|
|
475
541
|
getRequestTokenFuncName,
|
|
542
|
+
language,
|
|
476
543
|
requestTokenVarName,
|
|
477
544
|
objProperty('oauth_signature_method', strLiteral('HMAC-SHA1')),
|
|
478
545
|
objProperty('oauth_callback', 'bundle.inputData.redirect_uri'),
|
|
@@ -480,6 +547,7 @@ const oauth1AuthFile = () => {
|
|
|
480
547
|
),
|
|
481
548
|
oauth1TokenExchangeFunc(
|
|
482
549
|
getOauthAccessTokenFuncName,
|
|
550
|
+
language,
|
|
483
551
|
accessTokenVarName,
|
|
484
552
|
objProperty('oauth_token', 'bundle.inputData.oauth_token'),
|
|
485
553
|
objProperty('oauth_token_secret', 'bundle.inputData.oauth_token_secret'),
|
|
@@ -487,6 +555,7 @@ const oauth1AuthFile = () => {
|
|
|
487
555
|
),
|
|
488
556
|
beforeMiddlewareFunc(
|
|
489
557
|
includeAccessTokenFuncName,
|
|
558
|
+
language,
|
|
490
559
|
ifStatement(
|
|
491
560
|
'bundle.authData && bundle.authData.oauth_token && bundle.authData.oauth_token_secret',
|
|
492
561
|
comment(
|
|
@@ -508,8 +577,8 @@ const oauth1AuthFile = () => {
|
|
|
508
577
|
),
|
|
509
578
|
),
|
|
510
579
|
),
|
|
511
|
-
authTestFunc(strLiteral('https://api.trello.com/1/members/me/')),
|
|
512
|
-
authFileExport('oauth1', 'OAuth1 is an older form of OAuth', {
|
|
580
|
+
authTestFunc(language, strLiteral('https://api.trello.com/1/members/me/')),
|
|
581
|
+
authFileExport(language, 'oauth1', 'OAuth1 is an older form of OAuth', {
|
|
513
582
|
beforeFuncNames: [includeAccessTokenFuncName],
|
|
514
583
|
extraConfigProps: [
|
|
515
584
|
objProperty(
|
|
@@ -544,7 +613,10 @@ const oauth1AuthFile = () => {
|
|
|
544
613
|
],
|
|
545
614
|
connectionLabel: strLiteral('{{username}}'),
|
|
546
615
|
}),
|
|
547
|
-
|
|
616
|
+
];
|
|
617
|
+
return language === 'typescript'
|
|
618
|
+
? fileTS(standardTypes, ...fileInput)
|
|
619
|
+
: file(...fileInput);
|
|
548
620
|
};
|
|
549
621
|
|
|
550
622
|
module.exports = {
|