zapier-platform-cli 18.5.1 → 18.6.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/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { customLogger } = require('../logger');
|
|
2
|
+
const { localAppCommand } = require('../../../../utils/local');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Renders the auth template with real credentials from context.authData.
|
|
6
|
+
* @param {Object} context - The execution context with authData
|
|
7
|
+
* @returns {Promise<*>} The rendered auth template result
|
|
8
|
+
*/
|
|
9
|
+
const renderAuth = async (context) => {
|
|
10
|
+
try {
|
|
11
|
+
const result = await localAppCommand({
|
|
12
|
+
command: 'renderAuthTemplate',
|
|
13
|
+
bundle: {
|
|
14
|
+
authData: context.authData,
|
|
15
|
+
},
|
|
16
|
+
customLogger,
|
|
17
|
+
calledFromCliInvoke: true,
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err.message && err.message.includes('Unexpected command')) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'`auth render` requires latest version of zapier-platform-core. ' +
|
|
24
|
+
'Upgrade zapier-platform-core in your dependencies.',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
module.exports = { renderAuth };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { customLogger } = require('../logger');
|
|
2
|
+
const { localAppCommand } = require('../../../../utils/local');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gets the auth template for the current app. No credentials needed.
|
|
6
|
+
* Returns a template with {{bundle.authData.X}} placeholders.
|
|
7
|
+
* @param {Object} context - The execution context
|
|
8
|
+
* @returns {Promise<*>} The auth template result
|
|
9
|
+
*/
|
|
10
|
+
const templateAuth = async (context) => {
|
|
11
|
+
try {
|
|
12
|
+
const result = await localAppCommand({
|
|
13
|
+
command: 'getAuthTemplate',
|
|
14
|
+
bundle: {},
|
|
15
|
+
customLogger,
|
|
16
|
+
calledFromCliInvoke: true,
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (err.message && err.message.includes('Unexpected command')) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'`auth template` requires latest version of zapier-platform-core. ' +
|
|
23
|
+
'Upgrade zapier-platform-core in your dependencies.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports = { templateAuth };
|
|
@@ -17,6 +17,8 @@ const {
|
|
|
17
17
|
appendEnv,
|
|
18
18
|
} = require('./env');
|
|
19
19
|
const { startAuth, testAuth, getAuthLabel, refreshAuth } = require('./auth');
|
|
20
|
+
const { templateAuth } = require('./auth/template');
|
|
21
|
+
const { renderAuth } = require('./auth/render');
|
|
20
22
|
const { invokeAction } = require('./action');
|
|
21
23
|
const { promptForAuthentication } = require('./prompts');
|
|
22
24
|
|
|
@@ -119,7 +121,14 @@ class InvokeCommand extends BaseCommand {
|
|
|
119
121
|
throw new Error('You must specify ACTIONKEY in non-interactive mode.');
|
|
120
122
|
}
|
|
121
123
|
if (context.actionType === 'auth') {
|
|
122
|
-
const actionKeys = [
|
|
124
|
+
const actionKeys = [
|
|
125
|
+
'label',
|
|
126
|
+
'refresh',
|
|
127
|
+
'render',
|
|
128
|
+
'start',
|
|
129
|
+
'template',
|
|
130
|
+
'test',
|
|
131
|
+
];
|
|
123
132
|
context.actionKey = await this.promptWithList(
|
|
124
133
|
'Which auth operation would you like to invoke?',
|
|
125
134
|
actionKeys,
|
|
@@ -176,6 +185,18 @@ class InvokeCommand extends BaseCommand {
|
|
|
176
185
|
}
|
|
177
186
|
}
|
|
178
187
|
|
|
188
|
+
// Reject unsupported flags early for template/render commands
|
|
189
|
+
if (
|
|
190
|
+
context.actionType === 'auth' &&
|
|
191
|
+
(context.actionKey === 'template' || context.actionKey === 'render') &&
|
|
192
|
+
(context.remote || context.authId)
|
|
193
|
+
) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`The \`--remote\` and \`--authentication-id\` flags are not applicable to \`auth ${context.actionKey}\`. ` +
|
|
196
|
+
'This command runs locally using auth data from the .env file.',
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
179
200
|
if (context.authId && !context.remote) {
|
|
180
201
|
// Fill authData with curlies if we're in relay mode
|
|
181
202
|
const authFields = context.appDefinition.authentication.fields || [];
|
|
@@ -191,6 +212,31 @@ class InvokeCommand extends BaseCommand {
|
|
|
191
212
|
// gives the developer an option to override the values in bundle.authData.
|
|
192
213
|
context.authData = { ...context.authData, ...loadAuthDataFromEnv() };
|
|
193
214
|
|
|
215
|
+
// `auth render` accepts a positional JSON-encoded authData arg whose
|
|
216
|
+
// values take precedence over .env. Useful for one-off rendering
|
|
217
|
+
// without touching the .env file.
|
|
218
|
+
if (this.args.authData) {
|
|
219
|
+
if (context.actionType !== 'auth' || context.actionKey !== 'render') {
|
|
220
|
+
throw new Error(
|
|
221
|
+
'The authData positional argument is only supported by `auth render`.',
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
let parsed;
|
|
225
|
+
try {
|
|
226
|
+
parsed = JSON.parse(this.args.authData);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
throw new Error(`Failed to parse authData as JSON: ${err.message}`);
|
|
229
|
+
}
|
|
230
|
+
if (
|
|
231
|
+
parsed === null ||
|
|
232
|
+
typeof parsed !== 'object' ||
|
|
233
|
+
Array.isArray(parsed)
|
|
234
|
+
) {
|
|
235
|
+
throw new Error('authData must be a JSON object.');
|
|
236
|
+
}
|
|
237
|
+
context.authData = { ...context.authData, ...parsed };
|
|
238
|
+
}
|
|
239
|
+
|
|
194
240
|
if (context.actionType === 'auth') {
|
|
195
241
|
switch (context.actionKey) {
|
|
196
242
|
case 'start': {
|
|
@@ -253,10 +299,20 @@ class InvokeCommand extends BaseCommand {
|
|
|
253
299
|
}
|
|
254
300
|
return;
|
|
255
301
|
}
|
|
302
|
+
case 'template': {
|
|
303
|
+
const output = await templateAuth(context);
|
|
304
|
+
console.log(JSON.stringify(output, null, 2));
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
case 'render': {
|
|
308
|
+
const output = await renderAuth(context);
|
|
309
|
+
console.log(JSON.stringify(output, null, 2));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
256
312
|
default:
|
|
257
313
|
throw new Error(
|
|
258
314
|
`Unknown auth operation "${context.actionKey}". ` +
|
|
259
|
-
'The options are "label", "refresh", "start", and "test". \n',
|
|
315
|
+
'The options are "label", "refresh", "render", "start", "template", and "test". \n',
|
|
260
316
|
);
|
|
261
317
|
}
|
|
262
318
|
} else {
|
|
@@ -377,6 +433,13 @@ InvokeCommand.args = {
|
|
|
377
433
|
description:
|
|
378
434
|
'The trigger/action key you want to invoke. If ACTIONTYPE is "auth", this can be "label", "refresh", "start", or "test".',
|
|
379
435
|
}),
|
|
436
|
+
authData: Args.string({
|
|
437
|
+
description:
|
|
438
|
+
'Only used by `auth render`. JSON-encoded object with auth field values (e.g. `\'{"access_token":"a_token"}\'`). Values here take precedence over the .env file.',
|
|
439
|
+
// Don't auto-fill from piped stdin — that breaks `--inputData @-` usage
|
|
440
|
+
// for non-auth actions, which pipes into stdin for inputData.
|
|
441
|
+
ignoreStdin: true,
|
|
442
|
+
}),
|
|
380
443
|
};
|
|
381
444
|
|
|
382
445
|
InvokeCommand.examples = [
|
|
@@ -394,6 +457,7 @@ InvokeCommand.examples = [
|
|
|
394
457
|
'zapier-platform invoke trigger new_recipe --remote',
|
|
395
458
|
'zapier-platform invoke trigger new_recipe -r -a 12345',
|
|
396
459
|
'zapier-platform invoke -r -v 2.0.0 -a -',
|
|
460
|
+
`zapier-platform invoke auth render '{"access_token":"a_token"}'`,
|
|
397
461
|
];
|
|
398
462
|
InvokeCommand.description = `Invoke an authentication method, a trigger, or a create/search action locally or remotely.
|
|
399
463
|
|