@zapier/zapier-sdk-cli 0.13.9 → 0.13.11
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/CHANGELOG.md +16 -0
- package/dist/cli.cjs +121 -104
- package/dist/cli.mjs +124 -107
- package/dist/index.cjs +99 -100
- package/dist/index.d.mts +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.mjs +102 -103
- package/dist/package.json +1 -1
- package/dist/src/cli.js +23 -3
- package/dist/src/plugins/add/index.js +0 -8
- package/dist/src/plugins/buildManifest/index.js +12 -12
- package/dist/src/plugins/buildManifest/schemas.d.ts +0 -4
- package/dist/src/plugins/generateAppTypes/index.js +47 -59
- package/dist/src/plugins/generateAppTypes/schemas.d.ts +0 -4
- package/dist/src/plugins/login/index.js +17 -5
- package/dist/src/utils/auth/login.d.ts +7 -1
- package/dist/src/utils/auth/login.js +10 -7
- package/dist/src/utils/constants.d.ts +1 -1
- package/dist/src/utils/constants.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/cli.test.ts +10 -0
- package/src/cli.ts +35 -3
- package/src/plugins/add/index.ts +0 -9
- package/src/plugins/buildManifest/index.test.ts +96 -53
- package/src/plugins/buildManifest/index.ts +17 -14
- package/src/plugins/buildManifest/schemas.ts +0 -4
- package/src/plugins/generateAppTypes/index.test.ts +679 -0
- package/src/plugins/generateAppTypes/index.ts +53 -61
- package/src/plugins/generateAppTypes/schemas.ts +0 -4
- package/src/plugins/login/index.ts +33 -14
- package/src/utils/auth/login.ts +27 -8
- package/src/utils/constants.ts +1 -2
package/dist/index.cjs
CHANGED
|
@@ -107,28 +107,28 @@ var client_default = api;
|
|
|
107
107
|
|
|
108
108
|
// src/utils/getCallablePromise.ts
|
|
109
109
|
var getCallablePromise = () => {
|
|
110
|
-
let
|
|
110
|
+
let resolve4 = () => {
|
|
111
111
|
};
|
|
112
112
|
let reject = () => {
|
|
113
113
|
};
|
|
114
114
|
const promise = new Promise((_resolve, _reject) => {
|
|
115
|
-
|
|
115
|
+
resolve4 = _resolve;
|
|
116
116
|
reject = _reject;
|
|
117
117
|
});
|
|
118
118
|
return {
|
|
119
119
|
promise,
|
|
120
|
-
resolve:
|
|
120
|
+
resolve: resolve4,
|
|
121
121
|
reject
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
124
|
var getCallablePromise_default = getCallablePromise;
|
|
125
125
|
var findAvailablePort = () => {
|
|
126
|
-
return new Promise((
|
|
126
|
+
return new Promise((resolve4, reject) => {
|
|
127
127
|
let portIndex = 0;
|
|
128
128
|
const tryPort = (port) => {
|
|
129
129
|
const server = express__default.default().listen(port, () => {
|
|
130
130
|
server.close();
|
|
131
|
-
|
|
131
|
+
resolve4(port);
|
|
132
132
|
});
|
|
133
133
|
server.on("error", (err) => {
|
|
134
134
|
if (err.code === "EADDRINUSE") {
|
|
@@ -161,7 +161,15 @@ var generateRandomString = () => {
|
|
|
161
161
|
(dec) => ("0" + dec.toString(16)).substring(-2)
|
|
162
162
|
).join("");
|
|
163
163
|
};
|
|
164
|
-
var login = async (
|
|
164
|
+
var login = async ({
|
|
165
|
+
timeoutMs = LOGIN_TIMEOUT_MS,
|
|
166
|
+
baseUrl,
|
|
167
|
+
authBaseUrl,
|
|
168
|
+
authClientId
|
|
169
|
+
}) => {
|
|
170
|
+
const authOptions = { baseUrl, authBaseUrl };
|
|
171
|
+
const tokenUrl = zapierSdkCliLogin.getAuthTokenUrl(authOptions);
|
|
172
|
+
const authorizeUrl = zapierSdkCliLogin.getAuthAuthorizeUrl(authOptions);
|
|
165
173
|
zapierSdkCliLogin.logout();
|
|
166
174
|
const availablePort = await findAvailablePort();
|
|
167
175
|
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
@@ -187,9 +195,9 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
|
|
|
187
195
|
process.on("SIGINT", cleanup);
|
|
188
196
|
process.on("SIGTERM", cleanup);
|
|
189
197
|
const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge__default.default();
|
|
190
|
-
const authUrl = `${
|
|
198
|
+
const authUrl = `${authorizeUrl}?${new URLSearchParams({
|
|
191
199
|
response_type: "code",
|
|
192
|
-
client_id: zapierSdkCliLogin.
|
|
200
|
+
client_id: authClientId || zapierSdkCliLogin.ZAPIER_AUTH_CLIENT_ID,
|
|
193
201
|
redirect_uri: redirectUri,
|
|
194
202
|
scope: "internal offline_access",
|
|
195
203
|
state: generateRandomString(),
|
|
@@ -218,26 +226,26 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
|
|
|
218
226
|
} finally {
|
|
219
227
|
process.off("SIGINT", cleanup);
|
|
220
228
|
process.off("SIGTERM", cleanup);
|
|
221
|
-
await new Promise((
|
|
229
|
+
await new Promise((resolve4) => {
|
|
222
230
|
const timeout = setTimeout(() => {
|
|
223
231
|
log_default.info("Server close timed out, forcing connection shutdown...");
|
|
224
232
|
connections.forEach((conn) => conn.destroy());
|
|
225
|
-
|
|
233
|
+
resolve4();
|
|
226
234
|
}, 1e3);
|
|
227
235
|
server.close(() => {
|
|
228
236
|
clearTimeout(timeout);
|
|
229
|
-
|
|
237
|
+
resolve4();
|
|
230
238
|
});
|
|
231
239
|
});
|
|
232
240
|
}
|
|
233
241
|
log_default.info("Exchanging authorization code for tokens...");
|
|
234
242
|
const { data } = await client_default.post(
|
|
235
|
-
|
|
243
|
+
tokenUrl,
|
|
236
244
|
{
|
|
237
245
|
grant_type: "authorization_code",
|
|
238
246
|
code: await promisedCode,
|
|
239
247
|
redirect_uri: redirectUri,
|
|
240
|
-
client_id: zapierSdkCliLogin.
|
|
248
|
+
client_id: authClientId || zapierSdkCliLogin.ZAPIER_AUTH_CLIENT_ID,
|
|
241
249
|
code_verifier: codeVerifier
|
|
242
250
|
},
|
|
243
251
|
{
|
|
@@ -258,7 +266,7 @@ var LoginSchema = zod.z.object({
|
|
|
258
266
|
|
|
259
267
|
// package.json
|
|
260
268
|
var package_default = {
|
|
261
|
-
version: "0.13.
|
|
269
|
+
version: "0.13.11"};
|
|
262
270
|
|
|
263
271
|
// src/telemetry/builders.ts
|
|
264
272
|
function createCliBaseEvent(context = {}) {
|
|
@@ -316,23 +324,35 @@ function buildCliCommandExecutedEvent({
|
|
|
316
324
|
|
|
317
325
|
// src/plugins/login/index.ts
|
|
318
326
|
var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
319
|
-
var loginWithSdk = zapierSdk.createFunction(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
327
|
+
var loginWithSdk = zapierSdk.createFunction(
|
|
328
|
+
async (options) => {
|
|
329
|
+
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
330
|
+
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
331
|
+
throw new Error("Timeout must be a positive number");
|
|
332
|
+
}
|
|
333
|
+
await login_default({
|
|
334
|
+
timeoutMs: timeoutSeconds * 1e3,
|
|
335
|
+
baseUrl: options.baseUrl,
|
|
336
|
+
authBaseUrl: options.authBaseUrl,
|
|
337
|
+
authClientId: options.authClientId
|
|
338
|
+
});
|
|
339
|
+
const user = await zapierSdkCliLogin.getLoggedInUser();
|
|
340
|
+
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
341
|
+
setTimeout(() => process.exit(0), 100);
|
|
323
342
|
}
|
|
324
|
-
|
|
325
|
-
const user = await zapierSdkCliLogin.getLoggedInUser();
|
|
326
|
-
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
327
|
-
setTimeout(() => process.exit(0), 100);
|
|
328
|
-
}, LoginSchema);
|
|
343
|
+
);
|
|
329
344
|
var loginPlugin = ({ context }) => {
|
|
330
345
|
const loginWithTelemetry = async (options) => {
|
|
331
346
|
const startTime = Date.now();
|
|
332
347
|
let success = false;
|
|
333
348
|
let errorMessage = null;
|
|
334
349
|
try {
|
|
335
|
-
await loginWithSdk(
|
|
350
|
+
await loginWithSdk({
|
|
351
|
+
...options,
|
|
352
|
+
baseUrl: context.options?.baseUrl,
|
|
353
|
+
authBaseUrl: context.options?.authBaseUrl,
|
|
354
|
+
authClientId: context.options?.authClientId
|
|
355
|
+
});
|
|
336
356
|
success = true;
|
|
337
357
|
} catch (error) {
|
|
338
358
|
success = false;
|
|
@@ -649,14 +669,6 @@ var addPlugin = ({ sdk }) => {
|
|
|
649
669
|
if (successfulApps.length > 0) {
|
|
650
670
|
console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
|
|
651
671
|
}
|
|
652
|
-
const allErrors = [...manifestResult.errors, ...typesResult.errors];
|
|
653
|
-
if (allErrors.length > 0) {
|
|
654
|
-
console.warn(`
|
|
655
|
-
\u26A0\uFE0F ${allErrors.length} error(s) occurred:`);
|
|
656
|
-
allErrors.forEach(({ appKey, error }) => {
|
|
657
|
-
console.warn(` - ${appKey}: ${error}`);
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
672
|
}, AddSchema);
|
|
661
673
|
return {
|
|
662
674
|
add,
|
|
@@ -1276,17 +1288,12 @@ var generateAppTypesPlugin = ({ sdk }) => {
|
|
|
1276
1288
|
appKeys,
|
|
1277
1289
|
authenticationIds,
|
|
1278
1290
|
skipWrite = false,
|
|
1279
|
-
typesOutputDirectory,
|
|
1291
|
+
typesOutputDirectory = await detectTypesOutputDirectory(),
|
|
1280
1292
|
onProgress
|
|
1281
1293
|
} = options;
|
|
1282
|
-
|
|
1283
|
-
throw new Error(
|
|
1284
|
-
"typesOutputDirectory is required when skipWrite is false"
|
|
1285
|
-
);
|
|
1286
|
-
}
|
|
1294
|
+
const resolvedTypesOutput = path.resolve(typesOutputDirectory);
|
|
1287
1295
|
const result = {
|
|
1288
|
-
typeDefinitions: {}
|
|
1289
|
-
errors: []
|
|
1296
|
+
typeDefinitions: {}
|
|
1290
1297
|
};
|
|
1291
1298
|
onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
|
|
1292
1299
|
const appsIterator = sdk.listApps({ appKeys }).items();
|
|
@@ -1314,8 +1321,8 @@ var generateAppTypesPlugin = ({ sdk }) => {
|
|
|
1314
1321
|
count: authentications.length
|
|
1315
1322
|
});
|
|
1316
1323
|
}
|
|
1317
|
-
if (!skipWrite &&
|
|
1318
|
-
await promises.mkdir(
|
|
1324
|
+
if (!skipWrite && resolvedTypesOutput) {
|
|
1325
|
+
await promises.mkdir(resolvedTypesOutput, { recursive: true });
|
|
1319
1326
|
}
|
|
1320
1327
|
if (!skipWrite) {
|
|
1321
1328
|
result.writtenFiles = {};
|
|
@@ -1328,17 +1335,18 @@ var generateAppTypesPlugin = ({ sdk }) => {
|
|
|
1328
1335
|
});
|
|
1329
1336
|
try {
|
|
1330
1337
|
if (!app.version) {
|
|
1331
|
-
const
|
|
1332
|
-
result.errors.push({
|
|
1333
|
-
appKey: app.key,
|
|
1334
|
-
error
|
|
1335
|
-
});
|
|
1338
|
+
const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
|
|
1336
1339
|
onProgress?.({
|
|
1337
1340
|
type: "app_processing_error",
|
|
1338
1341
|
appKey: app.key,
|
|
1339
|
-
error
|
|
1342
|
+
error: errorMessage
|
|
1343
|
+
});
|
|
1344
|
+
throw new zapierSdk.ZapierValidationError(errorMessage, {
|
|
1345
|
+
details: {
|
|
1346
|
+
appKey: app.key,
|
|
1347
|
+
implementationId: app.implementation_id
|
|
1348
|
+
}
|
|
1340
1349
|
});
|
|
1341
|
-
continue;
|
|
1342
1350
|
}
|
|
1343
1351
|
let authenticationId;
|
|
1344
1352
|
if (authentications.length > 0) {
|
|
@@ -1361,56 +1369,47 @@ var generateAppTypesPlugin = ({ sdk }) => {
|
|
|
1361
1369
|
}
|
|
1362
1370
|
}
|
|
1363
1371
|
const manifestKey = getManifestKey(app);
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
+
const generator = new AstTypeGenerator();
|
|
1373
|
+
const typeDefinitionString = await generator.generateTypes({
|
|
1374
|
+
app,
|
|
1375
|
+
authenticationId,
|
|
1376
|
+
sdk
|
|
1377
|
+
});
|
|
1378
|
+
result.typeDefinitions[manifestKey] = typeDefinitionString;
|
|
1379
|
+
onProgress?.({
|
|
1380
|
+
type: "type_generated",
|
|
1381
|
+
manifestKey,
|
|
1382
|
+
sizeBytes: typeDefinitionString.length
|
|
1383
|
+
});
|
|
1384
|
+
if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
|
|
1385
|
+
const filePath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
|
|
1386
|
+
await promises.writeFile(filePath, typeDefinitionString, "utf8");
|
|
1387
|
+
result.writtenFiles[manifestKey] = filePath;
|
|
1372
1388
|
onProgress?.({
|
|
1373
|
-
type: "
|
|
1389
|
+
type: "file_written",
|
|
1374
1390
|
manifestKey,
|
|
1375
|
-
|
|
1376
|
-
});
|
|
1377
|
-
if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
|
|
1378
|
-
const filePath = path.join(typesOutputDirectory, `${manifestKey}.d.ts`);
|
|
1379
|
-
await promises.writeFile(filePath, typeDefinitionString, "utf8");
|
|
1380
|
-
result.writtenFiles[manifestKey] = filePath;
|
|
1381
|
-
onProgress?.({
|
|
1382
|
-
type: "file_written",
|
|
1383
|
-
manifestKey,
|
|
1384
|
-
filePath
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
onProgress?.({
|
|
1388
|
-
type: "app_processing_complete",
|
|
1389
|
-
appKey: app.key
|
|
1390
|
-
});
|
|
1391
|
-
} catch (error) {
|
|
1392
|
-
const errorMessage = `Failed to generate types: ${error}`;
|
|
1393
|
-
result.errors.push({
|
|
1394
|
-
appKey: app.key,
|
|
1395
|
-
error: errorMessage
|
|
1396
|
-
});
|
|
1397
|
-
onProgress?.({
|
|
1398
|
-
type: "app_processing_error",
|
|
1399
|
-
appKey: app.key,
|
|
1400
|
-
error: errorMessage
|
|
1391
|
+
filePath
|
|
1401
1392
|
});
|
|
1402
1393
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
appKey: app.key,
|
|
1407
|
-
error: errorMessage
|
|
1394
|
+
onProgress?.({
|
|
1395
|
+
type: "app_processing_complete",
|
|
1396
|
+
appKey: app.key
|
|
1408
1397
|
});
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
|
|
1409
1400
|
onProgress?.({
|
|
1410
1401
|
type: "app_processing_error",
|
|
1411
1402
|
appKey: app.key,
|
|
1412
1403
|
error: errorMessage
|
|
1413
1404
|
});
|
|
1405
|
+
if (error instanceof zapierSdk.ZapierValidationError) {
|
|
1406
|
+
throw error;
|
|
1407
|
+
} else {
|
|
1408
|
+
throw new zapierSdk.ZapierUnknownError(errorMessage, {
|
|
1409
|
+
cause: error
|
|
1410
|
+
// Works for both Error and non-Error
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1414
1413
|
}
|
|
1415
1414
|
}
|
|
1416
1415
|
return result;
|
|
@@ -1445,9 +1444,6 @@ var BuildManifestSchema = zod.z.object({
|
|
|
1445
1444
|
var buildManifestPlugin = ({ sdk, context }) => {
|
|
1446
1445
|
const buildManifest = zapierSdk.createFunction(async function buildManifest2(options) {
|
|
1447
1446
|
const { appKeys, skipWrite = false, configPath, onProgress } = options;
|
|
1448
|
-
const result = {
|
|
1449
|
-
errors: []
|
|
1450
|
-
};
|
|
1451
1447
|
onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
|
|
1452
1448
|
const appsIterator = sdk.listApps({ appKeys }).items();
|
|
1453
1449
|
const apps = [];
|
|
@@ -1457,7 +1453,7 @@ var buildManifestPlugin = ({ sdk, context }) => {
|
|
|
1457
1453
|
}
|
|
1458
1454
|
onProgress?.({ type: "apps_lookup_complete", count: apps.length });
|
|
1459
1455
|
if (apps.length === 0) {
|
|
1460
|
-
return
|
|
1456
|
+
return {};
|
|
1461
1457
|
}
|
|
1462
1458
|
let updatedManifest;
|
|
1463
1459
|
for (const app of apps) {
|
|
@@ -1490,20 +1486,23 @@ var buildManifestPlugin = ({ sdk, context }) => {
|
|
|
1490
1486
|
});
|
|
1491
1487
|
onProgress?.({ type: "app_processing_complete", appKey: app.key });
|
|
1492
1488
|
} catch (error) {
|
|
1493
|
-
const errorMessage = `Failed to process app: ${error}`;
|
|
1494
|
-
result.errors.push({
|
|
1495
|
-
appKey: app.key,
|
|
1496
|
-
error: errorMessage
|
|
1497
|
-
});
|
|
1489
|
+
const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
|
|
1498
1490
|
onProgress?.({
|
|
1499
1491
|
type: "app_processing_error",
|
|
1500
1492
|
appKey: app.key,
|
|
1501
1493
|
error: errorMessage
|
|
1502
1494
|
});
|
|
1495
|
+
if (error instanceof zapierSdk.ZapierValidationError) {
|
|
1496
|
+
throw error;
|
|
1497
|
+
} else {
|
|
1498
|
+
throw new zapierSdk.ZapierUnknownError(errorMessage, {
|
|
1499
|
+
cause: error
|
|
1500
|
+
// Works for both Error and non-Error
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
1503
|
}
|
|
1504
1504
|
}
|
|
1505
|
-
|
|
1506
|
-
return result;
|
|
1505
|
+
return { manifest: updatedManifest };
|
|
1507
1506
|
}, BuildManifestSchema);
|
|
1508
1507
|
return {
|
|
1509
1508
|
buildManifest,
|
package/dist/index.d.mts
CHANGED
|
@@ -50,10 +50,6 @@ type ManifestBuildProgressEvent = {
|
|
|
50
50
|
};
|
|
51
51
|
interface BuildManifestResult {
|
|
52
52
|
manifest?: Manifest;
|
|
53
|
-
errors: Array<{
|
|
54
|
-
appKey: string;
|
|
55
|
-
error: string;
|
|
56
|
-
}>;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
interface BuildManifestPluginProvides {
|
|
@@ -132,10 +128,6 @@ type AppTypesProgressEvent = {
|
|
|
132
128
|
interface GenerateAppTypesResult {
|
|
133
129
|
typeDefinitions: Record<string, string>;
|
|
134
130
|
writtenFiles?: Record<string, string>;
|
|
135
|
-
errors: Array<{
|
|
136
|
-
appKey: string;
|
|
137
|
-
error: string;
|
|
138
|
-
}>;
|
|
139
131
|
}
|
|
140
132
|
|
|
141
133
|
interface GenerateAppTypesPluginProvides {
|
package/dist/index.d.ts
CHANGED
|
@@ -50,10 +50,6 @@ type ManifestBuildProgressEvent = {
|
|
|
50
50
|
};
|
|
51
51
|
interface BuildManifestResult {
|
|
52
52
|
manifest?: Manifest;
|
|
53
|
-
errors: Array<{
|
|
54
|
-
appKey: string;
|
|
55
|
-
error: string;
|
|
56
|
-
}>;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
interface BuildManifestPluginProvides {
|
|
@@ -132,10 +128,6 @@ type AppTypesProgressEvent = {
|
|
|
132
128
|
interface GenerateAppTypesResult {
|
|
133
129
|
typeDefinitions: Record<string, string>;
|
|
134
130
|
writtenFiles?: Record<string, string>;
|
|
135
|
-
errors: Array<{
|
|
136
|
-
appKey: string;
|
|
137
|
-
error: string;
|
|
138
|
-
}>;
|
|
139
131
|
}
|
|
140
132
|
|
|
141
133
|
interface GenerateAppTypesPluginProvides {
|