@zapier/zapier-sdk-cli 0.34.1 → 0.34.3
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 +14 -0
- package/dist/cli.cjs +134 -117
- package/dist/cli.mjs +135 -118
- package/dist/index.cjs +74 -113
- package/dist/index.mjs +75 -114
- package/dist/package.json +1 -1
- package/dist/src/plugins/login/index.d.ts +1 -2
- package/dist/src/plugins/login/index.js +16 -65
- package/dist/src/utils/cli-generator.d.ts +1 -0
- package/dist/src/utils/cli-generator.js +69 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @zapier/zapier-sdk-cli
|
|
2
2
|
|
|
3
|
+
## 0.34.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a6dec83]
|
|
8
|
+
- @zapier/zapier-sdk@0.32.2
|
|
9
|
+
- @zapier/zapier-sdk-mcp@0.9.13
|
|
10
|
+
|
|
11
|
+
## 0.34.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 2860435: Emit telemetry events for all CLI commands
|
|
16
|
+
|
|
3
17
|
## 0.34.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cli.cjs
CHANGED
|
@@ -909,7 +909,95 @@ var SHARED_COMMAND_CLI_OPTIONS = [
|
|
|
909
909
|
}
|
|
910
910
|
];
|
|
911
911
|
|
|
912
|
+
// package.json
|
|
913
|
+
var package_default = {
|
|
914
|
+
version: "0.34.3"};
|
|
915
|
+
|
|
916
|
+
// src/telemetry/builders.ts
|
|
917
|
+
function createCliBaseEvent(context = {}) {
|
|
918
|
+
return {
|
|
919
|
+
event_id: zapierSdk.generateEventId(),
|
|
920
|
+
timestamp_ms: zapierSdk.getCurrentTimestamp(),
|
|
921
|
+
release_id: zapierSdk.getReleaseId(),
|
|
922
|
+
customuser_id: context.customuser_id ?? null,
|
|
923
|
+
account_id: context.account_id ?? null,
|
|
924
|
+
identity_id: context.identity_id ?? null,
|
|
925
|
+
visitor_id: context.visitor_id ?? null,
|
|
926
|
+
correlation_id: context.correlation_id ?? null
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
function buildCliCommandExecutedEvent({
|
|
930
|
+
data,
|
|
931
|
+
context = {},
|
|
932
|
+
cliVersion = package_default.version
|
|
933
|
+
}) {
|
|
934
|
+
const osInfo = zapierSdk.getOsInfo();
|
|
935
|
+
const platformVersions = zapierSdk.getPlatformVersions();
|
|
936
|
+
return {
|
|
937
|
+
...createCliBaseEvent(context),
|
|
938
|
+
system_name: "zapier-sdk-cli",
|
|
939
|
+
session_id: context.session_id ?? null,
|
|
940
|
+
cli_version: data.cli_version ?? cliVersion,
|
|
941
|
+
cli_arguments: data.cli_arguments ?? null,
|
|
942
|
+
cli_primary_command: data.cli_primary_command,
|
|
943
|
+
os_platform: osInfo.platform,
|
|
944
|
+
os_release: osInfo.release,
|
|
945
|
+
os_architecture: osInfo.architecture,
|
|
946
|
+
platform_versions: platformVersions,
|
|
947
|
+
selected_api: context.selected_api ?? null,
|
|
948
|
+
app_id: context.app_id ?? null,
|
|
949
|
+
app_version_id: context.app_version_id ?? null,
|
|
950
|
+
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
951
|
+
success_flag: data.success_flag,
|
|
952
|
+
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
953
|
+
error_message: data.error_message ?? null,
|
|
954
|
+
command_category: data.command_category ?? null,
|
|
955
|
+
requires_auth: null,
|
|
956
|
+
is_ci_environment: zapierSdk.isCi(),
|
|
957
|
+
ci_platform: zapierSdk.getCiPlatform(),
|
|
958
|
+
package_manager: data.package_manager ?? "pnpm",
|
|
959
|
+
// Default based on project setup
|
|
960
|
+
made_network_requests: data.made_network_requests ?? null,
|
|
961
|
+
files_modified_count: data.files_modified_count ?? null,
|
|
962
|
+
files_created_count: data.files_created_count ?? null,
|
|
963
|
+
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
964
|
+
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
965
|
+
subprocess_count: data.subprocess_count ?? null
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
|
|
912
969
|
// src/utils/cli-generator.ts
|
|
970
|
+
var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
971
|
+
var SENSITIVE_FLAGS = [
|
|
972
|
+
"--credentials",
|
|
973
|
+
"--credentials-client-secret",
|
|
974
|
+
"--credentials-client-id",
|
|
975
|
+
"--credentials-base-url",
|
|
976
|
+
"--user",
|
|
977
|
+
"--header",
|
|
978
|
+
"-H",
|
|
979
|
+
"-u"
|
|
980
|
+
];
|
|
981
|
+
function sanitizeCliArguments(args) {
|
|
982
|
+
const sanitized = [];
|
|
983
|
+
let skipNext = false;
|
|
984
|
+
for (const arg of args) {
|
|
985
|
+
if (skipNext) {
|
|
986
|
+
skipNext = false;
|
|
987
|
+
sanitized.push("[REDACTED]");
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
if (SENSITIVE_FLAGS.some((flag) => arg.startsWith(flag + "="))) {
|
|
991
|
+
sanitized.push(arg.split("=")[0] + "=[REDACTED]");
|
|
992
|
+
} else if (SENSITIVE_FLAGS.includes(arg)) {
|
|
993
|
+
sanitized.push(arg);
|
|
994
|
+
skipNext = true;
|
|
995
|
+
} else {
|
|
996
|
+
sanitized.push(arg);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return sanitized;
|
|
1000
|
+
}
|
|
913
1001
|
var CONFIRM_MESSAGES = {
|
|
914
1002
|
"create-secret": {
|
|
915
1003
|
messageBefore: "You are about to create a sensitive secret that will be displayed as plain text.\nOnce created, you cannot retrieve it again.",
|
|
@@ -1164,6 +1252,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1164
1252
|
const parameters = usesInputParameters ? analyzeInputParameters(functionInfo.inputParameters, functionInfo) : analyzeZodSchema(schema, functionInfo);
|
|
1165
1253
|
const description = functionInfo.description || schema?.description || `${cliCommandName} command`;
|
|
1166
1254
|
const handler = async (...args) => {
|
|
1255
|
+
const startTime = Date.now();
|
|
1256
|
+
let success = true;
|
|
1257
|
+
let errorMessage = null;
|
|
1258
|
+
let resolvedParams = {};
|
|
1167
1259
|
try {
|
|
1168
1260
|
const commandObj = args[args.length - 1];
|
|
1169
1261
|
const options = commandObj.opts();
|
|
@@ -1178,7 +1270,6 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1178
1270
|
args.slice(0, -1),
|
|
1179
1271
|
options
|
|
1180
1272
|
);
|
|
1181
|
-
let resolvedParams;
|
|
1182
1273
|
if (schema && !usesInputParameters) {
|
|
1183
1274
|
const resolver = new SchemaParameterResolver();
|
|
1184
1275
|
resolvedParams = await resolver.resolveParameters(
|
|
@@ -1268,6 +1359,8 @@ ${confirmMessageAfter}`));
|
|
|
1268
1359
|
}
|
|
1269
1360
|
}
|
|
1270
1361
|
} catch (error) {
|
|
1362
|
+
success = false;
|
|
1363
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
1271
1364
|
if (error instanceof Error && error.message.includes('"code"')) {
|
|
1272
1365
|
try {
|
|
1273
1366
|
const validationErrors = JSON.parse(error.message);
|
|
@@ -1302,9 +1395,29 @@ ${confirmMessageAfter}`));
|
|
|
1302
1395
|
console.error(chalk6__default.default.red("\u274C Error:"), formattedMessage);
|
|
1303
1396
|
throw new ZapierCliExitError(formattedMessage, 1);
|
|
1304
1397
|
} else {
|
|
1305
|
-
const
|
|
1306
|
-
console.error(chalk6__default.default.red("\u274C Error:"),
|
|
1307
|
-
throw new ZapierCliExitError(
|
|
1398
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
1399
|
+
console.error(chalk6__default.default.red("\u274C Error:"), msg);
|
|
1400
|
+
throw new ZapierCliExitError(msg, 1);
|
|
1401
|
+
}
|
|
1402
|
+
} finally {
|
|
1403
|
+
try {
|
|
1404
|
+
const event = buildCliCommandExecutedEvent({
|
|
1405
|
+
data: {
|
|
1406
|
+
cli_primary_command: cliCommandName,
|
|
1407
|
+
success_flag: success,
|
|
1408
|
+
execution_duration_ms: Date.now() - startTime,
|
|
1409
|
+
exit_code: success ? 0 : 1,
|
|
1410
|
+
error_message: errorMessage,
|
|
1411
|
+
command_category: functionInfo.categories?.[0] ?? null,
|
|
1412
|
+
requires_auth: null,
|
|
1413
|
+
cli_arguments: sanitizeCliArguments(process.argv.slice(2))
|
|
1414
|
+
},
|
|
1415
|
+
context: {
|
|
1416
|
+
selected_api: resolvedParams.appKey ?? null
|
|
1417
|
+
}
|
|
1418
|
+
});
|
|
1419
|
+
sdk2.getContext().eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
1420
|
+
} catch {
|
|
1308
1421
|
}
|
|
1309
1422
|
}
|
|
1310
1423
|
};
|
|
@@ -1863,65 +1976,7 @@ var LoginSchema = zod.z.object({
|
|
|
1863
1976
|
timeout: zod.z.string().optional().describe("Login timeout in seconds (default: 300)")
|
|
1864
1977
|
}).describe("Log in to Zapier to access your account");
|
|
1865
1978
|
|
|
1866
|
-
// package.json
|
|
1867
|
-
var package_default = {
|
|
1868
|
-
version: "0.34.1"};
|
|
1869
|
-
|
|
1870
|
-
// src/telemetry/builders.ts
|
|
1871
|
-
function createCliBaseEvent(context = {}) {
|
|
1872
|
-
return {
|
|
1873
|
-
event_id: zapierSdk.generateEventId(),
|
|
1874
|
-
timestamp_ms: zapierSdk.getCurrentTimestamp(),
|
|
1875
|
-
release_id: zapierSdk.getReleaseId(),
|
|
1876
|
-
customuser_id: context.customuser_id ?? null,
|
|
1877
|
-
account_id: context.account_id ?? null,
|
|
1878
|
-
identity_id: context.identity_id ?? null,
|
|
1879
|
-
visitor_id: context.visitor_id ?? null,
|
|
1880
|
-
correlation_id: context.correlation_id ?? null
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
function buildCliCommandExecutedEvent({
|
|
1884
|
-
data,
|
|
1885
|
-
context = {},
|
|
1886
|
-
cliVersion = package_default.version
|
|
1887
|
-
}) {
|
|
1888
|
-
const osInfo = zapierSdk.getOsInfo();
|
|
1889
|
-
const platformVersions = zapierSdk.getPlatformVersions();
|
|
1890
|
-
return {
|
|
1891
|
-
...createCliBaseEvent(context),
|
|
1892
|
-
system_name: "zapier-sdk-cli",
|
|
1893
|
-
session_id: context.session_id ?? null,
|
|
1894
|
-
cli_version: data.cli_version ?? cliVersion,
|
|
1895
|
-
cli_arguments: data.cli_arguments ?? null,
|
|
1896
|
-
cli_primary_command: data.cli_primary_command,
|
|
1897
|
-
os_platform: osInfo.platform,
|
|
1898
|
-
os_release: osInfo.release,
|
|
1899
|
-
os_architecture: osInfo.architecture,
|
|
1900
|
-
platform_versions: platformVersions,
|
|
1901
|
-
selected_api: context.selected_api ?? null,
|
|
1902
|
-
app_id: context.app_id ?? null,
|
|
1903
|
-
app_version_id: context.app_version_id ?? null,
|
|
1904
|
-
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
1905
|
-
success_flag: data.success_flag,
|
|
1906
|
-
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
1907
|
-
error_message: data.error_message ?? null,
|
|
1908
|
-
command_category: data.command_category ?? null,
|
|
1909
|
-
requires_auth: data.requires_auth ?? null,
|
|
1910
|
-
is_ci_environment: zapierSdk.isCi(),
|
|
1911
|
-
ci_platform: zapierSdk.getCiPlatform(),
|
|
1912
|
-
package_manager: data.package_manager ?? "pnpm",
|
|
1913
|
-
// Default based on project setup
|
|
1914
|
-
made_network_requests: data.made_network_requests ?? null,
|
|
1915
|
-
files_modified_count: data.files_modified_count ?? null,
|
|
1916
|
-
files_created_count: data.files_created_count ?? null,
|
|
1917
|
-
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
1918
|
-
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
1919
|
-
subprocess_count: data.subprocess_count ?? null
|
|
1920
|
-
};
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
1979
|
// src/plugins/login/index.ts
|
|
1924
|
-
var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
1925
1980
|
function toPkceCredentials(credentials2) {
|
|
1926
1981
|
if (credentials2 && zapierSdk.isCredentialsObject(credentials2) && !("clientSecret" in credentials2)) {
|
|
1927
1982
|
return {
|
|
@@ -1933,63 +1988,25 @@ function toPkceCredentials(credentials2) {
|
|
|
1933
1988
|
}
|
|
1934
1989
|
return void 0;
|
|
1935
1990
|
}
|
|
1936
|
-
var loginPlugin = ({
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
try {
|
|
1944
|
-
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
1945
|
-
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
1946
|
-
throw new Error("Timeout must be a positive number");
|
|
1947
|
-
}
|
|
1948
|
-
const resolvedCredentials = await context.resolveCredentials();
|
|
1949
|
-
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
1950
|
-
await login_default({
|
|
1951
|
-
timeoutMs: timeoutSeconds * 1e3,
|
|
1952
|
-
credentials: pkceCredentials
|
|
1953
|
-
});
|
|
1954
|
-
const user = await cliLogin.getLoggedInUser();
|
|
1955
|
-
accountId = user.accountId;
|
|
1956
|
-
customUserId = user.customUserId;
|
|
1957
|
-
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
1958
|
-
success = true;
|
|
1959
|
-
} catch (error) {
|
|
1960
|
-
success = false;
|
|
1961
|
-
errorMessage = error instanceof Error ? error.message : "Login failed";
|
|
1962
|
-
throw error;
|
|
1963
|
-
} finally {
|
|
1964
|
-
const event = buildCliCommandExecutedEvent({
|
|
1965
|
-
data: {
|
|
1966
|
-
cli_primary_command: "login",
|
|
1967
|
-
success_flag: success,
|
|
1968
|
-
execution_duration_ms: Date.now() - startTime,
|
|
1969
|
-
exit_code: success ? 0 : 1,
|
|
1970
|
-
error_message: errorMessage,
|
|
1971
|
-
command_category: "authentication",
|
|
1972
|
-
requires_auth: false,
|
|
1973
|
-
cli_arguments: [
|
|
1974
|
-
"login",
|
|
1975
|
-
options.timeout ? `--timeout=${options.timeout}` : null
|
|
1976
|
-
].filter(Boolean)
|
|
1977
|
-
},
|
|
1978
|
-
context: {
|
|
1979
|
-
session_id: context.session_id,
|
|
1980
|
-
selected_api: context.selected_api,
|
|
1981
|
-
app_id: context.app_id,
|
|
1982
|
-
app_version_id: context.app_version_id,
|
|
1983
|
-
customuser_id: customUserId,
|
|
1984
|
-
account_id: accountId
|
|
1985
|
-
},
|
|
1986
|
-
cliVersion: package_default.version
|
|
1987
|
-
});
|
|
1988
|
-
context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
1991
|
+
var loginPlugin = ({
|
|
1992
|
+
context
|
|
1993
|
+
}) => {
|
|
1994
|
+
const loginFn = async (options) => {
|
|
1995
|
+
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
1996
|
+
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
1997
|
+
throw new Error("Timeout must be a positive number");
|
|
1989
1998
|
}
|
|
1999
|
+
const resolvedCredentials = await context.resolveCredentials();
|
|
2000
|
+
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
2001
|
+
await login_default({
|
|
2002
|
+
timeoutMs: timeoutSeconds * 1e3,
|
|
2003
|
+
credentials: pkceCredentials
|
|
2004
|
+
});
|
|
2005
|
+
const user = await cliLogin.getLoggedInUser();
|
|
2006
|
+
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
1990
2007
|
};
|
|
1991
2008
|
return {
|
|
1992
|
-
login:
|
|
2009
|
+
login: loginFn,
|
|
1993
2010
|
context: {
|
|
1994
2011
|
meta: {
|
|
1995
2012
|
login: {
|
|
@@ -4143,7 +4160,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
4143
4160
|
// package.json with { type: 'json' }
|
|
4144
4161
|
var package_default2 = {
|
|
4145
4162
|
name: "@zapier/zapier-sdk-cli",
|
|
4146
|
-
version: "0.34.
|
|
4163
|
+
version: "0.34.3"};
|
|
4147
4164
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
4148
4165
|
var CACHE_RESET_INTERVAL_MS = (() => {
|
|
4149
4166
|
const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, injectCliLogin, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase, formatErrorMessage, isCredentialsObject, getOsInfo, getPlatformVersions, getCiPlatform, isCi,
|
|
4
|
+
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, injectCliLogin, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase, formatErrorMessage, isCredentialsObject, isPositional, getOsInfo, getPlatformVersions, getCiPlatform, isCi, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import chalk6 from 'chalk';
|
|
7
7
|
import util from 'util';
|
|
@@ -872,7 +872,95 @@ var SHARED_COMMAND_CLI_OPTIONS = [
|
|
|
872
872
|
}
|
|
873
873
|
];
|
|
874
874
|
|
|
875
|
+
// package.json
|
|
876
|
+
var package_default = {
|
|
877
|
+
version: "0.34.3"};
|
|
878
|
+
|
|
879
|
+
// src/telemetry/builders.ts
|
|
880
|
+
function createCliBaseEvent(context = {}) {
|
|
881
|
+
return {
|
|
882
|
+
event_id: generateEventId(),
|
|
883
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
884
|
+
release_id: getReleaseId(),
|
|
885
|
+
customuser_id: context.customuser_id ?? null,
|
|
886
|
+
account_id: context.account_id ?? null,
|
|
887
|
+
identity_id: context.identity_id ?? null,
|
|
888
|
+
visitor_id: context.visitor_id ?? null,
|
|
889
|
+
correlation_id: context.correlation_id ?? null
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function buildCliCommandExecutedEvent({
|
|
893
|
+
data,
|
|
894
|
+
context = {},
|
|
895
|
+
cliVersion = package_default.version
|
|
896
|
+
}) {
|
|
897
|
+
const osInfo = getOsInfo();
|
|
898
|
+
const platformVersions = getPlatformVersions();
|
|
899
|
+
return {
|
|
900
|
+
...createCliBaseEvent(context),
|
|
901
|
+
system_name: "zapier-sdk-cli",
|
|
902
|
+
session_id: context.session_id ?? null,
|
|
903
|
+
cli_version: data.cli_version ?? cliVersion,
|
|
904
|
+
cli_arguments: data.cli_arguments ?? null,
|
|
905
|
+
cli_primary_command: data.cli_primary_command,
|
|
906
|
+
os_platform: osInfo.platform,
|
|
907
|
+
os_release: osInfo.release,
|
|
908
|
+
os_architecture: osInfo.architecture,
|
|
909
|
+
platform_versions: platformVersions,
|
|
910
|
+
selected_api: context.selected_api ?? null,
|
|
911
|
+
app_id: context.app_id ?? null,
|
|
912
|
+
app_version_id: context.app_version_id ?? null,
|
|
913
|
+
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
914
|
+
success_flag: data.success_flag,
|
|
915
|
+
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
916
|
+
error_message: data.error_message ?? null,
|
|
917
|
+
command_category: data.command_category ?? null,
|
|
918
|
+
requires_auth: null,
|
|
919
|
+
is_ci_environment: isCi(),
|
|
920
|
+
ci_platform: getCiPlatform(),
|
|
921
|
+
package_manager: data.package_manager ?? "pnpm",
|
|
922
|
+
// Default based on project setup
|
|
923
|
+
made_network_requests: data.made_network_requests ?? null,
|
|
924
|
+
files_modified_count: data.files_modified_count ?? null,
|
|
925
|
+
files_created_count: data.files_created_count ?? null,
|
|
926
|
+
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
927
|
+
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
928
|
+
subprocess_count: data.subprocess_count ?? null
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
|
|
875
932
|
// src/utils/cli-generator.ts
|
|
933
|
+
var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
934
|
+
var SENSITIVE_FLAGS = [
|
|
935
|
+
"--credentials",
|
|
936
|
+
"--credentials-client-secret",
|
|
937
|
+
"--credentials-client-id",
|
|
938
|
+
"--credentials-base-url",
|
|
939
|
+
"--user",
|
|
940
|
+
"--header",
|
|
941
|
+
"-H",
|
|
942
|
+
"-u"
|
|
943
|
+
];
|
|
944
|
+
function sanitizeCliArguments(args) {
|
|
945
|
+
const sanitized = [];
|
|
946
|
+
let skipNext = false;
|
|
947
|
+
for (const arg of args) {
|
|
948
|
+
if (skipNext) {
|
|
949
|
+
skipNext = false;
|
|
950
|
+
sanitized.push("[REDACTED]");
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
if (SENSITIVE_FLAGS.some((flag) => arg.startsWith(flag + "="))) {
|
|
954
|
+
sanitized.push(arg.split("=")[0] + "=[REDACTED]");
|
|
955
|
+
} else if (SENSITIVE_FLAGS.includes(arg)) {
|
|
956
|
+
sanitized.push(arg);
|
|
957
|
+
skipNext = true;
|
|
958
|
+
} else {
|
|
959
|
+
sanitized.push(arg);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return sanitized;
|
|
963
|
+
}
|
|
876
964
|
var CONFIRM_MESSAGES = {
|
|
877
965
|
"create-secret": {
|
|
878
966
|
messageBefore: "You are about to create a sensitive secret that will be displayed as plain text.\nOnce created, you cannot retrieve it again.",
|
|
@@ -1127,6 +1215,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1127
1215
|
const parameters = usesInputParameters ? analyzeInputParameters(functionInfo.inputParameters, functionInfo) : analyzeZodSchema(schema, functionInfo);
|
|
1128
1216
|
const description = functionInfo.description || schema?.description || `${cliCommandName} command`;
|
|
1129
1217
|
const handler = async (...args) => {
|
|
1218
|
+
const startTime = Date.now();
|
|
1219
|
+
let success = true;
|
|
1220
|
+
let errorMessage = null;
|
|
1221
|
+
let resolvedParams = {};
|
|
1130
1222
|
try {
|
|
1131
1223
|
const commandObj = args[args.length - 1];
|
|
1132
1224
|
const options = commandObj.opts();
|
|
@@ -1141,7 +1233,6 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1141
1233
|
args.slice(0, -1),
|
|
1142
1234
|
options
|
|
1143
1235
|
);
|
|
1144
|
-
let resolvedParams;
|
|
1145
1236
|
if (schema && !usesInputParameters) {
|
|
1146
1237
|
const resolver = new SchemaParameterResolver();
|
|
1147
1238
|
resolvedParams = await resolver.resolveParameters(
|
|
@@ -1231,6 +1322,8 @@ ${confirmMessageAfter}`));
|
|
|
1231
1322
|
}
|
|
1232
1323
|
}
|
|
1233
1324
|
} catch (error) {
|
|
1325
|
+
success = false;
|
|
1326
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
1234
1327
|
if (error instanceof Error && error.message.includes('"code"')) {
|
|
1235
1328
|
try {
|
|
1236
1329
|
const validationErrors = JSON.parse(error.message);
|
|
@@ -1265,9 +1358,29 @@ ${confirmMessageAfter}`));
|
|
|
1265
1358
|
console.error(chalk6.red("\u274C Error:"), formattedMessage);
|
|
1266
1359
|
throw new ZapierCliExitError(formattedMessage, 1);
|
|
1267
1360
|
} else {
|
|
1268
|
-
const
|
|
1269
|
-
console.error(chalk6.red("\u274C Error:"),
|
|
1270
|
-
throw new ZapierCliExitError(
|
|
1361
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
1362
|
+
console.error(chalk6.red("\u274C Error:"), msg);
|
|
1363
|
+
throw new ZapierCliExitError(msg, 1);
|
|
1364
|
+
}
|
|
1365
|
+
} finally {
|
|
1366
|
+
try {
|
|
1367
|
+
const event = buildCliCommandExecutedEvent({
|
|
1368
|
+
data: {
|
|
1369
|
+
cli_primary_command: cliCommandName,
|
|
1370
|
+
success_flag: success,
|
|
1371
|
+
execution_duration_ms: Date.now() - startTime,
|
|
1372
|
+
exit_code: success ? 0 : 1,
|
|
1373
|
+
error_message: errorMessage,
|
|
1374
|
+
command_category: functionInfo.categories?.[0] ?? null,
|
|
1375
|
+
requires_auth: null,
|
|
1376
|
+
cli_arguments: sanitizeCliArguments(process.argv.slice(2))
|
|
1377
|
+
},
|
|
1378
|
+
context: {
|
|
1379
|
+
selected_api: resolvedParams.appKey ?? null
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
sdk2.getContext().eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
1383
|
+
} catch {
|
|
1271
1384
|
}
|
|
1272
1385
|
}
|
|
1273
1386
|
};
|
|
@@ -1826,65 +1939,7 @@ var LoginSchema = z.object({
|
|
|
1826
1939
|
timeout: z.string().optional().describe("Login timeout in seconds (default: 300)")
|
|
1827
1940
|
}).describe("Log in to Zapier to access your account");
|
|
1828
1941
|
|
|
1829
|
-
// package.json
|
|
1830
|
-
var package_default = {
|
|
1831
|
-
version: "0.34.1"};
|
|
1832
|
-
|
|
1833
|
-
// src/telemetry/builders.ts
|
|
1834
|
-
function createCliBaseEvent(context = {}) {
|
|
1835
|
-
return {
|
|
1836
|
-
event_id: generateEventId(),
|
|
1837
|
-
timestamp_ms: getCurrentTimestamp(),
|
|
1838
|
-
release_id: getReleaseId(),
|
|
1839
|
-
customuser_id: context.customuser_id ?? null,
|
|
1840
|
-
account_id: context.account_id ?? null,
|
|
1841
|
-
identity_id: context.identity_id ?? null,
|
|
1842
|
-
visitor_id: context.visitor_id ?? null,
|
|
1843
|
-
correlation_id: context.correlation_id ?? null
|
|
1844
|
-
};
|
|
1845
|
-
}
|
|
1846
|
-
function buildCliCommandExecutedEvent({
|
|
1847
|
-
data,
|
|
1848
|
-
context = {},
|
|
1849
|
-
cliVersion = package_default.version
|
|
1850
|
-
}) {
|
|
1851
|
-
const osInfo = getOsInfo();
|
|
1852
|
-
const platformVersions = getPlatformVersions();
|
|
1853
|
-
return {
|
|
1854
|
-
...createCliBaseEvent(context),
|
|
1855
|
-
system_name: "zapier-sdk-cli",
|
|
1856
|
-
session_id: context.session_id ?? null,
|
|
1857
|
-
cli_version: data.cli_version ?? cliVersion,
|
|
1858
|
-
cli_arguments: data.cli_arguments ?? null,
|
|
1859
|
-
cli_primary_command: data.cli_primary_command,
|
|
1860
|
-
os_platform: osInfo.platform,
|
|
1861
|
-
os_release: osInfo.release,
|
|
1862
|
-
os_architecture: osInfo.architecture,
|
|
1863
|
-
platform_versions: platformVersions,
|
|
1864
|
-
selected_api: context.selected_api ?? null,
|
|
1865
|
-
app_id: context.app_id ?? null,
|
|
1866
|
-
app_version_id: context.app_version_id ?? null,
|
|
1867
|
-
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
1868
|
-
success_flag: data.success_flag,
|
|
1869
|
-
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
1870
|
-
error_message: data.error_message ?? null,
|
|
1871
|
-
command_category: data.command_category ?? null,
|
|
1872
|
-
requires_auth: data.requires_auth ?? null,
|
|
1873
|
-
is_ci_environment: isCi(),
|
|
1874
|
-
ci_platform: getCiPlatform(),
|
|
1875
|
-
package_manager: data.package_manager ?? "pnpm",
|
|
1876
|
-
// Default based on project setup
|
|
1877
|
-
made_network_requests: data.made_network_requests ?? null,
|
|
1878
|
-
files_modified_count: data.files_modified_count ?? null,
|
|
1879
|
-
files_created_count: data.files_created_count ?? null,
|
|
1880
|
-
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
1881
|
-
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
1882
|
-
subprocess_count: data.subprocess_count ?? null
|
|
1883
|
-
};
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
1942
|
// src/plugins/login/index.ts
|
|
1887
|
-
var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
1888
1943
|
function toPkceCredentials(credentials2) {
|
|
1889
1944
|
if (credentials2 && isCredentialsObject(credentials2) && !("clientSecret" in credentials2)) {
|
|
1890
1945
|
return {
|
|
@@ -1896,63 +1951,25 @@ function toPkceCredentials(credentials2) {
|
|
|
1896
1951
|
}
|
|
1897
1952
|
return void 0;
|
|
1898
1953
|
}
|
|
1899
|
-
var loginPlugin = ({
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
try {
|
|
1907
|
-
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
1908
|
-
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
1909
|
-
throw new Error("Timeout must be a positive number");
|
|
1910
|
-
}
|
|
1911
|
-
const resolvedCredentials = await context.resolveCredentials();
|
|
1912
|
-
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
1913
|
-
await login_default({
|
|
1914
|
-
timeoutMs: timeoutSeconds * 1e3,
|
|
1915
|
-
credentials: pkceCredentials
|
|
1916
|
-
});
|
|
1917
|
-
const user = await getLoggedInUser();
|
|
1918
|
-
accountId = user.accountId;
|
|
1919
|
-
customUserId = user.customUserId;
|
|
1920
|
-
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
1921
|
-
success = true;
|
|
1922
|
-
} catch (error) {
|
|
1923
|
-
success = false;
|
|
1924
|
-
errorMessage = error instanceof Error ? error.message : "Login failed";
|
|
1925
|
-
throw error;
|
|
1926
|
-
} finally {
|
|
1927
|
-
const event = buildCliCommandExecutedEvent({
|
|
1928
|
-
data: {
|
|
1929
|
-
cli_primary_command: "login",
|
|
1930
|
-
success_flag: success,
|
|
1931
|
-
execution_duration_ms: Date.now() - startTime,
|
|
1932
|
-
exit_code: success ? 0 : 1,
|
|
1933
|
-
error_message: errorMessage,
|
|
1934
|
-
command_category: "authentication",
|
|
1935
|
-
requires_auth: false,
|
|
1936
|
-
cli_arguments: [
|
|
1937
|
-
"login",
|
|
1938
|
-
options.timeout ? `--timeout=${options.timeout}` : null
|
|
1939
|
-
].filter(Boolean)
|
|
1940
|
-
},
|
|
1941
|
-
context: {
|
|
1942
|
-
session_id: context.session_id,
|
|
1943
|
-
selected_api: context.selected_api,
|
|
1944
|
-
app_id: context.app_id,
|
|
1945
|
-
app_version_id: context.app_version_id,
|
|
1946
|
-
customuser_id: customUserId,
|
|
1947
|
-
account_id: accountId
|
|
1948
|
-
},
|
|
1949
|
-
cliVersion: package_default.version
|
|
1950
|
-
});
|
|
1951
|
-
context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
1954
|
+
var loginPlugin = ({
|
|
1955
|
+
context
|
|
1956
|
+
}) => {
|
|
1957
|
+
const loginFn = async (options) => {
|
|
1958
|
+
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
1959
|
+
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
1960
|
+
throw new Error("Timeout must be a positive number");
|
|
1952
1961
|
}
|
|
1962
|
+
const resolvedCredentials = await context.resolveCredentials();
|
|
1963
|
+
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
1964
|
+
await login_default({
|
|
1965
|
+
timeoutMs: timeoutSeconds * 1e3,
|
|
1966
|
+
credentials: pkceCredentials
|
|
1967
|
+
});
|
|
1968
|
+
const user = await getLoggedInUser();
|
|
1969
|
+
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
1953
1970
|
};
|
|
1954
1971
|
return {
|
|
1955
|
-
login:
|
|
1972
|
+
login: loginFn,
|
|
1956
1973
|
context: {
|
|
1957
1974
|
meta: {
|
|
1958
1975
|
login: {
|
|
@@ -4106,7 +4123,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
4106
4123
|
// package.json with { type: 'json' }
|
|
4107
4124
|
var package_default2 = {
|
|
4108
4125
|
name: "@zapier/zapier-sdk-cli",
|
|
4109
|
-
version: "0.34.
|
|
4126
|
+
version: "0.34.3"};
|
|
4110
4127
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
4111
4128
|
var CACHE_RESET_INTERVAL_MS = (() => {
|
|
4112
4129
|
const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;
|