@zapier/zapier-sdk-cli 0.68.0 → 0.70.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/CHANGELOG.md +28 -0
- package/README.md +26 -7
- package/dist/cli.cjs +1719 -293
- package/dist/cli.mjs +1721 -297
- package/dist/experimental.cjs +1793 -30
- package/dist/experimental.d.mts +1 -1
- package/dist/experimental.d.ts +1 -1
- package/dist/experimental.mjs +1791 -33
- package/dist/{extensions-CU5Oy_Wv.d.mts → extensions-DSCQgX9d.d.mts} +177 -2
- package/dist/{extensions-CU5Oy_Wv.d.ts → extensions-DSCQgX9d.d.ts} +177 -2
- package/dist/index.cjs +1804 -33
- package/dist/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.mjs +1800 -35
- package/package.json +6 -4
- package/templates/setup/zapier-slack-test.mjs +38 -0
- package/templates/setup/zapier-slack-test.ts +38 -0
package/dist/experimental.mjs
CHANGED
|
@@ -2,16 +2,16 @@ import * as jwt from 'jsonwebtoken';
|
|
|
2
2
|
import { deletePassword, getKeyring, setPassword, getPassword } from 'cross-keychain';
|
|
3
3
|
import Conf from 'conf';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
|
-
import { promises, createWriteStream, existsSync, readdirSync, rmSync, mkdirSync, writeFileSync, copyFileSync
|
|
5
|
+
import { promises, createWriteStream, existsSync, readdirSync, readFileSync, rmSync, mkdirSync, writeFileSync, copyFileSync } from 'fs';
|
|
6
6
|
import crypto, { createHash } from 'crypto';
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { resolve, join, dirname, basename, relative, extname } from 'path';
|
|
9
9
|
import * as lockfile from 'proper-lockfile';
|
|
10
|
-
import { defineMethod, apiPluginRef, resolveCredentialsPluginRef, eventEmissionPluginRef, sdkOptionsPluginRef, declareOptionalProperty, OutputPropertySchema, ZapierBundleError, isZapierBundleError, DEFAULT_CONFIG_PATH, declareMethod, ZapierValidationError, isZapierValidationError, ZapierUnknownError, manifestPluginRef, defineResolver, isPermanentHttpError, isZapierAuthenticationError, ZapierApiError, defineMethodOverride, zapierCoreOptions, injectCliLogin, definePlugin, omitExports, zapierSdkPlugin, invalidateCachedToken, batch, toSnakeCase, ZapierError, isZapierReleaseTriggerMessageSignal, getOrCreateApiClient, isCredentialsObject, ZapierAbortDrainSignal, ZapierReleaseTriggerMessageSignal, buildApplicationLifecycleEvent, AuthMechanism, ZapierAuthenticationError, DEPRECATION_NOTICE_EVENT } from '@zapier/zapier-sdk';
|
|
10
|
+
import { defineMethod, apiPluginRef, resolveCredentialsPluginRef, eventEmissionPluginRef, sdkOptionsPluginRef, declareOptionalProperty, OutputPropertySchema, ZapierBundleError, isZapierBundleError, DEFAULT_CONFIG_PATH, declareMethod, ZapierValidationError, isZapierValidationError, ZapierUnknownError, manifestPluginRef, defineResolver, isPermanentHttpError, isZapierAuthenticationError, ZapierApiError, defineMethodOverride, zapierCoreOptions, injectCliLogin, definePlugin, omitExports, zapierSdkPlugin, invalidateCachedToken, batch, toSnakeCase, ZapierError, isZapierReleaseTriggerMessageSignal, getOrCreateApiClient, isCredentialsObject, createSdk, getRegistryPlugin, createController, ZapierAbortDrainSignal, ZapierReleaseTriggerMessageSignal, buildApplicationLifecycleEvent, AuthMechanism, isCoreCancelledSignal, ZapierAuthenticationError, DEPRECATION_NOTICE_EVENT } from '@zapier/zapier-sdk';
|
|
11
11
|
import { z } from 'zod';
|
|
12
|
-
import { triggerInboxResolver, DrainTriggerInboxSchema, WatchTriggerInboxSchema, injectCliLogin as injectCliLogin$1, definePlugin as definePlugin$1, omitExports as omitExports$1, zapierExperimentalSdkPlugin, createSdk, CORE_OPTIONS_ID, SDK_OPTIONS_ID, addPlugin } from '@zapier/zapier-sdk/experimental';
|
|
12
|
+
import { triggerInboxResolver, DrainTriggerInboxSchema, WatchTriggerInboxSchema, injectCliLogin as injectCliLogin$1, definePlugin as definePlugin$1, omitExports as omitExports$1, zapierExperimentalSdkPlugin, createSdk as createSdk$1, CORE_OPTIONS_ID, SDK_OPTIONS_ID, addPlugin } from '@zapier/zapier-sdk/experimental';
|
|
13
13
|
import { hostname } from 'os';
|
|
14
|
-
import
|
|
14
|
+
import inquirer3 from 'inquirer';
|
|
15
15
|
import express from 'express';
|
|
16
16
|
import { createInterface } from 'readline/promises';
|
|
17
17
|
import open from 'open';
|
|
@@ -26,7 +26,12 @@ import 'is-installed-globally';
|
|
|
26
26
|
import { execSync, spawn } from 'child_process';
|
|
27
27
|
import Handlebars from 'handlebars';
|
|
28
28
|
import { fileURLToPath } from 'url';
|
|
29
|
-
import '
|
|
29
|
+
import { makeTheme, createPrompt, useState, usePrefix, useMemo, useEffect, useKeypress, isEnterKey, isTabKey, isUpKey, isDownKey, usePagination, Separator } from '@inquirer/core';
|
|
30
|
+
import packageJsonLib, { VersionNotFoundError } from 'package-json';
|
|
31
|
+
import semver from 'semver';
|
|
32
|
+
import crossSpawn from 'cross-spawn';
|
|
33
|
+
import wrapAnsi from 'wrap-ansi';
|
|
34
|
+
import Table from 'cli-table3';
|
|
30
35
|
|
|
31
36
|
var __defProp = Object.defineProperty;
|
|
32
37
|
var __export = (target, all) => {
|
|
@@ -1960,7 +1965,7 @@ async function promptCredentialsName({
|
|
|
1960
1965
|
email,
|
|
1961
1966
|
promptMessage
|
|
1962
1967
|
}) {
|
|
1963
|
-
const { credentialName } = await
|
|
1968
|
+
const { credentialName } = await inquirer3.prompt([
|
|
1964
1969
|
{
|
|
1965
1970
|
type: "input",
|
|
1966
1971
|
name: "credentialName",
|
|
@@ -2023,7 +2028,7 @@ async function promptConfirm({
|
|
|
2023
2028
|
message,
|
|
2024
2029
|
defaultValue
|
|
2025
2030
|
}) {
|
|
2026
|
-
const { confirmed } = await
|
|
2031
|
+
const { confirmed } = await inquirer3.prompt([
|
|
2027
2032
|
{ type: "confirm", name: "confirmed", message, default: defaultValue }
|
|
2028
2033
|
]);
|
|
2029
2034
|
return confirmed;
|
|
@@ -4099,26 +4104,57 @@ var InitSchema = z.object({
|
|
|
4099
4104
|
}).describe(
|
|
4100
4105
|
"Create a new Zapier SDK project in a new directory with starter files"
|
|
4101
4106
|
);
|
|
4107
|
+
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
4108
|
+
var LOCKFILES = [
|
|
4109
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
4110
|
+
["yarn.lock", "yarn"],
|
|
4111
|
+
["bun.lock", "bun"],
|
|
4112
|
+
["bun.lockb", "bun"],
|
|
4113
|
+
["package-lock.json", "npm"]
|
|
4114
|
+
];
|
|
4115
|
+
function readDeclaredPackageManager(cwd) {
|
|
4116
|
+
try {
|
|
4117
|
+
const manifest = JSON.parse(
|
|
4118
|
+
readFileSync(join(cwd, "package.json"), "utf8")
|
|
4119
|
+
);
|
|
4120
|
+
if (typeof manifest !== "object" || manifest === null || !("packageManager" in manifest) || typeof manifest.packageManager !== "string") {
|
|
4121
|
+
return void 0;
|
|
4122
|
+
}
|
|
4123
|
+
const [name] = manifest.packageManager.split("@", 1);
|
|
4124
|
+
return PACKAGE_MANAGERS.find((packageManager) => packageManager === name);
|
|
4125
|
+
} catch {
|
|
4126
|
+
return void 0;
|
|
4127
|
+
}
|
|
4128
|
+
}
|
|
4102
4129
|
function detectPackageManager(cwd = process.cwd()) {
|
|
4103
|
-
const
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
if (
|
|
4118
|
-
return { name, source: "
|
|
4130
|
+
const lockfileManagers = new Set(
|
|
4131
|
+
LOCKFILES.filter(([file]) => existsSync(join(cwd, file))).map(
|
|
4132
|
+
([, packageManager]) => packageManager
|
|
4133
|
+
)
|
|
4134
|
+
);
|
|
4135
|
+
if (lockfileManagers.size === 1) {
|
|
4136
|
+
return { name: [...lockfileManagers][0], source: "lockfile" };
|
|
4137
|
+
}
|
|
4138
|
+
const declaredPackageManager = readDeclaredPackageManager(cwd);
|
|
4139
|
+
if (declaredPackageManager) {
|
|
4140
|
+
return { name: declaredPackageManager, source: "package-json" };
|
|
4141
|
+
}
|
|
4142
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
4143
|
+
if (userAgent) {
|
|
4144
|
+
if (userAgent.includes("yarn")) {
|
|
4145
|
+
return { name: "yarn", source: "runtime" };
|
|
4146
|
+
}
|
|
4147
|
+
if (userAgent.includes("pnpm")) {
|
|
4148
|
+
return { name: "pnpm", source: "runtime" };
|
|
4149
|
+
}
|
|
4150
|
+
if (userAgent.includes("bun")) {
|
|
4151
|
+
return { name: "bun", source: "runtime" };
|
|
4152
|
+
}
|
|
4153
|
+
if (userAgent.includes("npm")) {
|
|
4154
|
+
return { name: "npm", source: "runtime" };
|
|
4119
4155
|
}
|
|
4120
4156
|
}
|
|
4121
|
-
return { name: "
|
|
4157
|
+
return { name: "npm", source: "fallback" };
|
|
4122
4158
|
}
|
|
4123
4159
|
function getDirentParentPath(entry) {
|
|
4124
4160
|
const e = entry;
|
|
@@ -4166,7 +4202,7 @@ async function promptYesNo({
|
|
|
4166
4202
|
nonInteractive
|
|
4167
4203
|
}) {
|
|
4168
4204
|
if (nonInteractive) return defaultValue;
|
|
4169
|
-
const { answer } = await
|
|
4205
|
+
const { answer } = await inquirer3.prompt([
|
|
4170
4206
|
{ type: "confirm", name: "answer", message, default: defaultValue }
|
|
4171
4207
|
]);
|
|
4172
4208
|
return answer;
|
|
@@ -4516,17 +4552,16 @@ var initPlugin = defineMethod({
|
|
|
4516
4552
|
const cwd = process.cwd();
|
|
4517
4553
|
const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
|
|
4518
4554
|
const displayHooks = createConsoleDisplayHooks();
|
|
4519
|
-
const
|
|
4520
|
-
if (
|
|
4555
|
+
const packageManager = detectPackageManager(cwd);
|
|
4556
|
+
if (packageManager.source === "fallback") {
|
|
4521
4557
|
displayHooks.onWarn(
|
|
4522
4558
|
"Could not detect package manager, defaulting to npm."
|
|
4523
4559
|
);
|
|
4524
4560
|
}
|
|
4525
|
-
const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
|
|
4526
4561
|
const steps = getInitSteps({
|
|
4527
4562
|
projectDir,
|
|
4528
4563
|
projectName,
|
|
4529
|
-
packageManager,
|
|
4564
|
+
packageManager: packageManager.name,
|
|
4530
4565
|
displayHooks
|
|
4531
4566
|
});
|
|
4532
4567
|
const completedSetupStepIds = [];
|
|
@@ -4554,8 +4589,1729 @@ var initPlugin = defineMethod({
|
|
|
4554
4589
|
projectName,
|
|
4555
4590
|
steps,
|
|
4556
4591
|
completedSetupStepIds,
|
|
4557
|
-
packageManager
|
|
4592
|
+
packageManager: packageManager.name
|
|
4593
|
+
});
|
|
4594
|
+
}
|
|
4595
|
+
});
|
|
4596
|
+
function isSelectable(item) {
|
|
4597
|
+
return !Separator.isSeparator(item) && !item.disabled;
|
|
4598
|
+
}
|
|
4599
|
+
function normalizeChoices(choices) {
|
|
4600
|
+
return choices.map((choice) => {
|
|
4601
|
+
if (Separator.isSeparator(choice)) return choice;
|
|
4602
|
+
const name = choice.name ?? String(choice.value);
|
|
4603
|
+
return {
|
|
4604
|
+
value: choice.value,
|
|
4605
|
+
name,
|
|
4606
|
+
short: choice.short ?? name,
|
|
4607
|
+
disabled: choice.disabled ?? false
|
|
4608
|
+
};
|
|
4609
|
+
});
|
|
4610
|
+
}
|
|
4611
|
+
var theme = makeTheme({
|
|
4612
|
+
icon: { cursor: "\u276F" },
|
|
4613
|
+
style: {
|
|
4614
|
+
disabled: (text) => chalk3.dim(`- ${text}`),
|
|
4615
|
+
searchTerm: (text) => chalk3.cyan(text),
|
|
4616
|
+
keysHelpTip: (keys) => keys.map(([key, action]) => `${chalk3.bold(key)} ${chalk3.dim(action)}`).join(chalk3.dim(" \u2022 "))
|
|
4617
|
+
}
|
|
4618
|
+
});
|
|
4619
|
+
var searchSelect = createPrompt(
|
|
4620
|
+
(config2, done) => {
|
|
4621
|
+
const { pageSize = 7 } = config2;
|
|
4622
|
+
const [status, setStatus] = useState(
|
|
4623
|
+
"loading"
|
|
4624
|
+
);
|
|
4625
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
4626
|
+
const [searchResults, setSearchResults] = useState([]);
|
|
4627
|
+
const [searchError, setSearchError] = useState();
|
|
4628
|
+
const prefix = usePrefix({ status, theme });
|
|
4629
|
+
const bounds = useMemo(() => {
|
|
4630
|
+
const first = searchResults.findIndex(isSelectable);
|
|
4631
|
+
let last = -1;
|
|
4632
|
+
for (let i = searchResults.length - 1; i >= 0; i--) {
|
|
4633
|
+
if (isSelectable(searchResults[i])) {
|
|
4634
|
+
last = i;
|
|
4635
|
+
break;
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
return { first, last };
|
|
4639
|
+
}, [searchResults]);
|
|
4640
|
+
const defaultActive = useMemo(() => {
|
|
4641
|
+
const requested = config2.initialActive;
|
|
4642
|
+
if (searchTerm === "" && requested !== void 0 && requested >= 0 && requested < searchResults.length && isSelectable(searchResults[requested])) {
|
|
4643
|
+
return requested;
|
|
4644
|
+
}
|
|
4645
|
+
return bounds.first;
|
|
4646
|
+
}, [searchResults, searchTerm, bounds.first]);
|
|
4647
|
+
const [active = defaultActive, setActive] = useState();
|
|
4648
|
+
useEffect(() => {
|
|
4649
|
+
const controller = new AbortController();
|
|
4650
|
+
setStatus("loading");
|
|
4651
|
+
setSearchError(void 0);
|
|
4652
|
+
const fetchResults = async () => {
|
|
4653
|
+
try {
|
|
4654
|
+
const results = await config2.source(searchTerm || void 0);
|
|
4655
|
+
if (!controller.signal.aborted) {
|
|
4656
|
+
setActive(void 0);
|
|
4657
|
+
setSearchError(void 0);
|
|
4658
|
+
setSearchResults(normalizeChoices(results));
|
|
4659
|
+
setStatus("idle");
|
|
4660
|
+
}
|
|
4661
|
+
} catch (error2) {
|
|
4662
|
+
if (!controller.signal.aborted && error2 instanceof Error) {
|
|
4663
|
+
setSearchError(error2.message);
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
};
|
|
4667
|
+
void fetchResults();
|
|
4668
|
+
return () => {
|
|
4669
|
+
controller.abort();
|
|
4670
|
+
};
|
|
4671
|
+
}, [searchTerm]);
|
|
4672
|
+
const selectedChoice = searchResults[active];
|
|
4673
|
+
useKeypress((key, rl) => {
|
|
4674
|
+
if (isEnterKey(key)) {
|
|
4675
|
+
if (selectedChoice && isSelectable(selectedChoice)) {
|
|
4676
|
+
setStatus("done");
|
|
4677
|
+
done(selectedChoice.value);
|
|
4678
|
+
} else {
|
|
4679
|
+
rl.write(searchTerm);
|
|
4680
|
+
}
|
|
4681
|
+
} else if (isTabKey(key) && selectedChoice && isSelectable(selectedChoice)) {
|
|
4682
|
+
rl.clearLine(0);
|
|
4683
|
+
rl.write(selectedChoice.name);
|
|
4684
|
+
setSearchTerm(selectedChoice.name);
|
|
4685
|
+
} else if (status !== "loading" && (isUpKey(key) || isDownKey(key))) {
|
|
4686
|
+
rl.clearLine(0);
|
|
4687
|
+
if (isUpKey(key) && active !== bounds.first || isDownKey(key) && active !== bounds.last) {
|
|
4688
|
+
const offset = isUpKey(key) ? -1 : 1;
|
|
4689
|
+
let next = active;
|
|
4690
|
+
do {
|
|
4691
|
+
next = (next + offset + searchResults.length) % searchResults.length;
|
|
4692
|
+
} while (!isSelectable(searchResults[next]));
|
|
4693
|
+
setActive(next);
|
|
4694
|
+
}
|
|
4695
|
+
} else {
|
|
4696
|
+
setSearchTerm(rl.line);
|
|
4697
|
+
}
|
|
4698
|
+
});
|
|
4699
|
+
const page = usePagination({
|
|
4700
|
+
items: searchResults,
|
|
4701
|
+
active,
|
|
4702
|
+
renderItem({ item, isActive }) {
|
|
4703
|
+
if (Separator.isSeparator(item)) {
|
|
4704
|
+
return ` ${item.separator}`;
|
|
4705
|
+
}
|
|
4706
|
+
if (item.disabled) {
|
|
4707
|
+
const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
|
|
4708
|
+
return theme.style.disabled(`${item.name} ${disabledLabel}`);
|
|
4709
|
+
}
|
|
4710
|
+
const color = isActive ? theme.style.highlight : (x) => x;
|
|
4711
|
+
const cursor = isActive ? theme.icon.cursor : ` `;
|
|
4712
|
+
return color(`${cursor} ${item.name}`);
|
|
4713
|
+
},
|
|
4714
|
+
pageSize,
|
|
4715
|
+
loop: false
|
|
4716
|
+
});
|
|
4717
|
+
const message = theme.style.message(config2.message, status);
|
|
4718
|
+
if (status === "done" && selectedChoice && isSelectable(selectedChoice)) {
|
|
4719
|
+
return [prefix, message, theme.style.answer(selectedChoice.short)].filter(Boolean).join(" ").trimEnd();
|
|
4720
|
+
}
|
|
4721
|
+
const searchStr = theme.style.searchTerm(searchTerm);
|
|
4722
|
+
const helpTip = theme.style.keysHelpTip([
|
|
4723
|
+
["\u2191\u2193", "navigate"],
|
|
4724
|
+
["\u23CE", "select"]
|
|
4725
|
+
]);
|
|
4726
|
+
let error;
|
|
4727
|
+
if (searchError) {
|
|
4728
|
+
error = theme.style.error(searchError);
|
|
4729
|
+
} else if (searchResults.length === 0 && searchTerm !== "" && status === "idle") {
|
|
4730
|
+
error = theme.style.error("No results found");
|
|
4731
|
+
}
|
|
4732
|
+
const header = [prefix, message, searchStr].filter(Boolean).join(" ").trimEnd();
|
|
4733
|
+
const body = [error ?? page, " ", helpTip].filter(Boolean).join("\n").trimEnd();
|
|
4734
|
+
return [header, body];
|
|
4735
|
+
}
|
|
4736
|
+
);
|
|
4737
|
+
|
|
4738
|
+
// src/utils/controller-answer.ts
|
|
4739
|
+
function offers(question, action) {
|
|
4740
|
+
return question.actions.some((a) => a.action === action);
|
|
4741
|
+
}
|
|
4742
|
+
function isActionRow(value) {
|
|
4743
|
+
return typeof value === "object" && value !== null && "action" in value;
|
|
4744
|
+
}
|
|
4745
|
+
async function promptText({
|
|
4746
|
+
message,
|
|
4747
|
+
password
|
|
4748
|
+
}) {
|
|
4749
|
+
const { value } = await inquirer3.prompt([
|
|
4750
|
+
{
|
|
4751
|
+
type: password ? "password" : "input",
|
|
4752
|
+
name: "value",
|
|
4753
|
+
message,
|
|
4754
|
+
theme: HIGH_CONTRAST_PROMPT_THEME
|
|
4755
|
+
}
|
|
4756
|
+
]);
|
|
4757
|
+
return value;
|
|
4758
|
+
}
|
|
4759
|
+
var display = (c) => c.hint ? `${c.label} ${chalk3.dim(`(${c.hint})`)}` : c.label;
|
|
4760
|
+
var HIGH_CONTRAST_PROMPT_THEME = {
|
|
4761
|
+
style: {
|
|
4762
|
+
answer: (text) => chalk3.inverse.bold(` ${text} `)
|
|
4763
|
+
}
|
|
4764
|
+
};
|
|
4765
|
+
function buildSelectRows(question, term) {
|
|
4766
|
+
const row = (name, action) => ({
|
|
4767
|
+
name,
|
|
4768
|
+
value: { action }
|
|
4769
|
+
});
|
|
4770
|
+
const t = term.trim().toLowerCase();
|
|
4771
|
+
const matched = t ? question.choices.filter(
|
|
4772
|
+
(c) => `${c.label} ${c.hint ?? ""}`.toLowerCase().includes(t)
|
|
4773
|
+
) : question.choices;
|
|
4774
|
+
const matchRows = matched.map((c) => ({
|
|
4775
|
+
name: display(c),
|
|
4776
|
+
value: c.value
|
|
4777
|
+
}));
|
|
4778
|
+
const skipRow = offers(question, "skip") ? [row(chalk3.dim("Skip (optional)"), "skip")] : [];
|
|
4779
|
+
const customRow = offers(question, "custom") ? [row(chalk3.dim("Enter a value manually\u2026"), "custom")] : [];
|
|
4780
|
+
const committed = !!t || question.search !== void 0;
|
|
4781
|
+
let rows;
|
|
4782
|
+
if (!committed) {
|
|
4783
|
+
rows = [...skipRow, ...customRow, ...matchRows];
|
|
4784
|
+
} else if (matchRows.length > 0) {
|
|
4785
|
+
rows = [...matchRows, ...skipRow, ...customRow];
|
|
4786
|
+
} else {
|
|
4787
|
+
rows = [...customRow, ...skipRow];
|
|
4788
|
+
}
|
|
4789
|
+
if (offers(question, "search"))
|
|
4790
|
+
rows.push(row(chalk3.cyan("Search again\u2026"), "search"));
|
|
4791
|
+
if (offers(question, "next_page"))
|
|
4792
|
+
rows.push(row(chalk3.dim("Load more\u2026"), "next_page"));
|
|
4793
|
+
if (offers(question, "retry")) rows.push(row(chalk3.yellow("Retry"), "retry"));
|
|
4794
|
+
if (offers(question, "cancel")) rows.push(row(chalk3.dim("Cancel"), "cancel"));
|
|
4795
|
+
for (const note of question.notes ?? [])
|
|
4796
|
+
rows.push({ name: chalk3.dim(note), value: note, disabled: true });
|
|
4797
|
+
return rows;
|
|
4798
|
+
}
|
|
4799
|
+
function foldPage(acc, question, field) {
|
|
4800
|
+
const page = question.page;
|
|
4801
|
+
if (!page) {
|
|
4802
|
+
return {
|
|
4803
|
+
key: field,
|
|
4804
|
+
pageIndex: 0,
|
|
4805
|
+
choices: question.choices,
|
|
4806
|
+
newStart: 0,
|
|
4807
|
+
checked: []
|
|
4808
|
+
};
|
|
4809
|
+
}
|
|
4810
|
+
const key = `${field}#${page.generation}`;
|
|
4811
|
+
if (acc?.key === key && page.index === acc.pageIndex + 1) {
|
|
4812
|
+
return {
|
|
4813
|
+
key,
|
|
4814
|
+
pageIndex: page.index,
|
|
4815
|
+
choices: [...acc.choices, ...question.choices],
|
|
4816
|
+
newStart: acc.choices.length,
|
|
4817
|
+
checked: acc.checked
|
|
4818
|
+
};
|
|
4819
|
+
}
|
|
4820
|
+
if (acc?.key === key && page.index === acc.pageIndex) {
|
|
4821
|
+
return { ...acc, newStart: 0 };
|
|
4822
|
+
}
|
|
4823
|
+
return {
|
|
4824
|
+
key,
|
|
4825
|
+
pageIndex: page.index,
|
|
4826
|
+
choices: question.choices,
|
|
4827
|
+
newStart: 0,
|
|
4828
|
+
checked: []
|
|
4829
|
+
};
|
|
4830
|
+
}
|
|
4831
|
+
async function answerSelect(question, field, box, failed, mode) {
|
|
4832
|
+
const acc = failed ? void 0 : box.acc = foldPage(box.acc, question, field);
|
|
4833
|
+
const view = acc ? { ...question, choices: acc.choices } : question;
|
|
4834
|
+
const isClosedListPrompt = mode === "closed-list" && !failed && !view.multiple;
|
|
4835
|
+
const booleanValues = view.choices.map(({ value: value2 }) => value2);
|
|
4836
|
+
if (isClosedListPrompt && booleanValues.length === 2 && booleanValues.includes("true") && booleanValues.includes("false")) {
|
|
4837
|
+
const { value: value2 } = await inquirer3.prompt([
|
|
4838
|
+
{
|
|
4839
|
+
type: "confirm",
|
|
4840
|
+
name: "value",
|
|
4841
|
+
message: view.message,
|
|
4842
|
+
default: booleanValues[0] === "true",
|
|
4843
|
+
theme: HIGH_CONTRAST_PROMPT_THEME
|
|
4844
|
+
}
|
|
4845
|
+
]);
|
|
4846
|
+
return { type: "choose", value: String(value2) };
|
|
4847
|
+
}
|
|
4848
|
+
if (isClosedListPrompt && view.choices.length > 0 && !offers(view, "search") && !offers(view, "next_page") && !offers(view, "retry")) {
|
|
4849
|
+
const choices = view.choices.map((choice) => ({
|
|
4850
|
+
name: display(choice),
|
|
4851
|
+
value: choice.value
|
|
4852
|
+
}));
|
|
4853
|
+
const { value: value2 } = await inquirer3.prompt([
|
|
4854
|
+
{
|
|
4855
|
+
type: "list",
|
|
4856
|
+
name: "value",
|
|
4857
|
+
message: view.message,
|
|
4858
|
+
choices,
|
|
4859
|
+
theme: HIGH_CONTRAST_PROMPT_THEME
|
|
4860
|
+
}
|
|
4861
|
+
]);
|
|
4862
|
+
return { type: "choose", value: value2 };
|
|
4863
|
+
}
|
|
4864
|
+
if (question.multiple && acc) {
|
|
4865
|
+
if (acc.newStart > 0 && process.stdout.isTTY) {
|
|
4866
|
+
process.stdout.write("\x1B[1A\x1B[2K");
|
|
4867
|
+
}
|
|
4868
|
+
const choices = [
|
|
4869
|
+
...acc.choices.map((c) => ({
|
|
4870
|
+
name: display(c),
|
|
4871
|
+
value: c.value,
|
|
4872
|
+
checked: acc.checked.includes(c.value)
|
|
4873
|
+
})),
|
|
4874
|
+
...offers(question, "next_page") ? [
|
|
4875
|
+
{
|
|
4876
|
+
name: chalk3.dim("Load more\u2026"),
|
|
4877
|
+
value: { action: "next_page" }
|
|
4878
|
+
}
|
|
4879
|
+
] : [],
|
|
4880
|
+
...(question.notes ?? []).map((note) => ({
|
|
4881
|
+
name: chalk3.dim(note),
|
|
4882
|
+
value: note,
|
|
4883
|
+
disabled: true
|
|
4884
|
+
}))
|
|
4885
|
+
];
|
|
4886
|
+
const { values } = await inquirer3.prompt([
|
|
4887
|
+
{
|
|
4888
|
+
type: "checkbox",
|
|
4889
|
+
name: "values",
|
|
4890
|
+
message: question.message,
|
|
4891
|
+
choices,
|
|
4892
|
+
theme: HIGH_CONTRAST_PROMPT_THEME
|
|
4893
|
+
}
|
|
4894
|
+
]);
|
|
4895
|
+
const selected = values;
|
|
4896
|
+
const picked = selected.filter((v) => !isActionRow(v));
|
|
4897
|
+
if (selected.some(isActionRow)) {
|
|
4898
|
+
box.acc = { ...acc, checked: picked };
|
|
4899
|
+
return { type: "next_page" };
|
|
4900
|
+
}
|
|
4901
|
+
if (picked.length === 0 && offers(question, "skip")) {
|
|
4902
|
+
return { type: "skip" };
|
|
4903
|
+
}
|
|
4904
|
+
return { type: "choose", value: picked };
|
|
4905
|
+
}
|
|
4906
|
+
if (offers(question, "search") && question.search === void 0) {
|
|
4907
|
+
const optional = offers(question, "skip");
|
|
4908
|
+
const parts = [
|
|
4909
|
+
...optional ? ["optional"] : [],
|
|
4910
|
+
...question.placeholder ? [question.placeholder] : []
|
|
4911
|
+
];
|
|
4912
|
+
const hint = parts.length ? ` (${parts.join(", ")})` : "";
|
|
4913
|
+
while (true) {
|
|
4914
|
+
const term = (await promptText({
|
|
4915
|
+
message: `Enter or search ${field}${hint}:`,
|
|
4916
|
+
password: false
|
|
4917
|
+
})).trim();
|
|
4918
|
+
if (term) return { type: "search", term };
|
|
4919
|
+
if (optional) return { type: "skip" };
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
const newStart = acc?.newStart ?? 0;
|
|
4923
|
+
const firstFreshValue = newStart > 0 ? view.choices[newStart]?.value : void 0;
|
|
4924
|
+
const initialActive = firstFreshValue !== void 0 ? buildSelectRows(view, "").findIndex((r) => r.value === firstFreshValue) : -1;
|
|
4925
|
+
const value = await searchSelect(
|
|
4926
|
+
{
|
|
4927
|
+
message: view.message,
|
|
4928
|
+
source: (term) => buildSelectRows(view, term ?? ""),
|
|
4929
|
+
...initialActive >= 0 ? { initialActive } : {}
|
|
4930
|
+
},
|
|
4931
|
+
{ clearPromptOnDone: true }
|
|
4932
|
+
);
|
|
4933
|
+
if (!isActionRow(value)) {
|
|
4934
|
+
const picked = view.choices.find((c) => c.value === value);
|
|
4935
|
+
printAnswered(view.message, picked?.label ?? String(value));
|
|
4936
|
+
return { type: "choose", value };
|
|
4937
|
+
}
|
|
4938
|
+
switch (value.action) {
|
|
4939
|
+
case "search": {
|
|
4940
|
+
const term = await promptText({
|
|
4941
|
+
message: `Search ${field}:`,
|
|
4942
|
+
password: false
|
|
4943
|
+
});
|
|
4944
|
+
return { type: "search", term };
|
|
4945
|
+
}
|
|
4946
|
+
case "custom": {
|
|
4947
|
+
const custom = await promptText({
|
|
4948
|
+
message: `Enter ${field}:`,
|
|
4949
|
+
password: false
|
|
4950
|
+
});
|
|
4951
|
+
return { type: "custom", value: custom };
|
|
4952
|
+
}
|
|
4953
|
+
case "next_page":
|
|
4954
|
+
return { type: "next_page" };
|
|
4955
|
+
case "retry":
|
|
4956
|
+
return { type: "retry" };
|
|
4957
|
+
case "skip":
|
|
4958
|
+
printAnswered(view.message, chalk3.dim("(skipped)"));
|
|
4959
|
+
return { type: "skip" };
|
|
4960
|
+
case "cancel":
|
|
4961
|
+
return { type: "cancel" };
|
|
4962
|
+
}
|
|
4963
|
+
}
|
|
4964
|
+
function printAnswered(message, label) {
|
|
4965
|
+
console.log(`${chalk3.green("\u2714")} ${message} ${chalk3.cyan(label)}`);
|
|
4966
|
+
}
|
|
4967
|
+
async function answerInput(question) {
|
|
4968
|
+
const message = question.placeholder ? question.message.replace(/:?\s*$/, ` (${question.placeholder}):`) : question.message;
|
|
4969
|
+
const value = await promptText({
|
|
4970
|
+
message,
|
|
4971
|
+
password: question.inputType === "password"
|
|
4972
|
+
});
|
|
4973
|
+
if (value === "" && offers(question, "skip")) {
|
|
4974
|
+
return { type: "skip" };
|
|
4975
|
+
}
|
|
4976
|
+
return { type: "custom", value };
|
|
4977
|
+
}
|
|
4978
|
+
async function answerCollection(question) {
|
|
4979
|
+
if (!offers(question, "done")) {
|
|
4980
|
+
return { type: "add" };
|
|
4981
|
+
}
|
|
4982
|
+
if (question.description) console.log(question.description);
|
|
4983
|
+
const { again } = await inquirer3.prompt([
|
|
4984
|
+
{
|
|
4985
|
+
type: "confirm",
|
|
4986
|
+
name: "again",
|
|
4987
|
+
message: question.message,
|
|
4988
|
+
default: false,
|
|
4989
|
+
theme: HIGH_CONTRAST_PROMPT_THEME
|
|
4990
|
+
}
|
|
4991
|
+
]);
|
|
4992
|
+
return again ? { type: "add" } : { type: "done" };
|
|
4993
|
+
}
|
|
4994
|
+
function createCliAnswer({
|
|
4995
|
+
mode = "search"
|
|
4996
|
+
} = {}) {
|
|
4997
|
+
const box = {};
|
|
4998
|
+
return async ({ result }) => {
|
|
4999
|
+
try {
|
|
5000
|
+
if (result.error !== void 0) {
|
|
5001
|
+
const message = typeof result.error === "string" ? result.error : result.error.message;
|
|
5002
|
+
console.log(chalk3.yellow(`! ${message}`));
|
|
5003
|
+
}
|
|
5004
|
+
const question = result.question;
|
|
5005
|
+
const field = question.path.length ? question.path.join(".") : "value";
|
|
5006
|
+
switch (question.type) {
|
|
5007
|
+
case "select":
|
|
5008
|
+
return await answerSelect(
|
|
5009
|
+
question,
|
|
5010
|
+
field,
|
|
5011
|
+
box,
|
|
5012
|
+
result.status === "failed",
|
|
5013
|
+
mode
|
|
5014
|
+
);
|
|
5015
|
+
case "input":
|
|
5016
|
+
return await answerInput(question);
|
|
5017
|
+
case "collection":
|
|
5018
|
+
return await answerCollection(question);
|
|
5019
|
+
}
|
|
5020
|
+
} catch (error) {
|
|
5021
|
+
if (error instanceof Error && error.name === "ExitPromptError") {
|
|
5022
|
+
return { type: "cancel" };
|
|
5023
|
+
}
|
|
5024
|
+
throw error;
|
|
5025
|
+
}
|
|
5026
|
+
};
|
|
5027
|
+
}
|
|
5028
|
+
var ONE_DAY_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
5029
|
+
var CACHE_RESET_INTERVAL_MILLISECONDS = (() => {
|
|
5030
|
+
const {
|
|
5031
|
+
ZAPIER_SDK_UPDATE_CHECK_INTERVAL_SECONDS,
|
|
5032
|
+
ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS
|
|
5033
|
+
} = process.env;
|
|
5034
|
+
let intervalMs;
|
|
5035
|
+
if (ZAPIER_SDK_UPDATE_CHECK_INTERVAL_SECONDS !== void 0) {
|
|
5036
|
+
const seconds = parseInt(ZAPIER_SDK_UPDATE_CHECK_INTERVAL_SECONDS);
|
|
5037
|
+
intervalMs = isNaN(seconds) ? NaN : seconds * 1e3;
|
|
5038
|
+
} else if (ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS !== void 0) {
|
|
5039
|
+
intervalMs = parseInt(ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS);
|
|
5040
|
+
} else {
|
|
5041
|
+
intervalMs = ONE_DAY_MILLISECONDS;
|
|
5042
|
+
}
|
|
5043
|
+
if (isNaN(intervalMs) || intervalMs < 0) {
|
|
5044
|
+
return -1;
|
|
5045
|
+
}
|
|
5046
|
+
return intervalMs;
|
|
5047
|
+
})();
|
|
5048
|
+
function getVersionCache() {
|
|
5049
|
+
try {
|
|
5050
|
+
const cache = getConfig().get("version_cache");
|
|
5051
|
+
const now = Date.now();
|
|
5052
|
+
if (!cache || !cache.last_reset_timestamp || now - cache.last_reset_timestamp >= CACHE_RESET_INTERVAL_MILLISECONDS) {
|
|
5053
|
+
const newCache = {
|
|
5054
|
+
last_reset_timestamp: now,
|
|
5055
|
+
packages: {}
|
|
5056
|
+
};
|
|
5057
|
+
getConfig().set("version_cache", newCache);
|
|
5058
|
+
return newCache;
|
|
5059
|
+
}
|
|
5060
|
+
return cache;
|
|
5061
|
+
} catch (error) {
|
|
5062
|
+
log_default.debug(`Failed to read version cache: ${error}`);
|
|
5063
|
+
return {
|
|
5064
|
+
last_reset_timestamp: Date.now(),
|
|
5065
|
+
packages: {}
|
|
5066
|
+
};
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
function setCachedPackageInfo(packageName, version, info) {
|
|
5070
|
+
try {
|
|
5071
|
+
const cache = getVersionCache();
|
|
5072
|
+
if (!cache.packages[packageName]) {
|
|
5073
|
+
cache.packages[packageName] = {};
|
|
5074
|
+
}
|
|
5075
|
+
cache.packages[packageName][version] = info;
|
|
5076
|
+
getConfig().set("version_cache", cache);
|
|
5077
|
+
} catch (error) {
|
|
5078
|
+
log_default.debug(`Failed to cache package info: ${error}`);
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
function getCachedPackageInfo(packageName, version) {
|
|
5082
|
+
try {
|
|
5083
|
+
const cache = getVersionCache();
|
|
5084
|
+
return cache.packages[packageName]?.[version];
|
|
5085
|
+
} catch (error) {
|
|
5086
|
+
log_default.debug(`Failed to get cached package info: ${error}`);
|
|
5087
|
+
return void 0;
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
async function fetchCachedPackageInfo(packageName, version) {
|
|
5091
|
+
const cacheKey = version || "latest";
|
|
5092
|
+
let cachedInfo = getCachedPackageInfo(packageName, cacheKey);
|
|
5093
|
+
if (cachedInfo) {
|
|
5094
|
+
return cachedInfo;
|
|
5095
|
+
}
|
|
5096
|
+
const packageInfo = await packageJsonLib(packageName, {
|
|
5097
|
+
version,
|
|
5098
|
+
fullMetadata: true
|
|
5099
|
+
});
|
|
5100
|
+
const info = {
|
|
5101
|
+
version: packageInfo.version,
|
|
5102
|
+
deprecated: packageInfo.deprecated,
|
|
5103
|
+
fetched_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
5104
|
+
};
|
|
5105
|
+
setCachedPackageInfo(packageName, cacheKey, info);
|
|
5106
|
+
return info;
|
|
5107
|
+
}
|
|
5108
|
+
async function checkForUpdates({
|
|
5109
|
+
packageName,
|
|
5110
|
+
currentVersion
|
|
5111
|
+
}) {
|
|
5112
|
+
try {
|
|
5113
|
+
const latestPackageInfo = await fetchCachedPackageInfo(packageName);
|
|
5114
|
+
const latestVersion = latestPackageInfo.version;
|
|
5115
|
+
const hasUpdate = semver.gt(latestVersion, currentVersion);
|
|
5116
|
+
let currentPackageInfo;
|
|
5117
|
+
try {
|
|
5118
|
+
currentPackageInfo = await fetchCachedPackageInfo(
|
|
5119
|
+
packageName,
|
|
5120
|
+
currentVersion
|
|
5121
|
+
);
|
|
5122
|
+
} catch (error) {
|
|
5123
|
+
if (!(error instanceof VersionNotFoundError)) {
|
|
5124
|
+
log_default.debug(`Failed to check deprecation for current version: ${error}`);
|
|
5125
|
+
}
|
|
5126
|
+
currentPackageInfo = latestPackageInfo;
|
|
5127
|
+
}
|
|
5128
|
+
const isDeprecated = Boolean(currentPackageInfo.deprecated);
|
|
5129
|
+
const deprecationMessage = isDeprecated ? String(currentPackageInfo.deprecated) : void 0;
|
|
5130
|
+
return {
|
|
5131
|
+
hasUpdate,
|
|
5132
|
+
latestVersion,
|
|
5133
|
+
currentVersion,
|
|
5134
|
+
isDeprecated,
|
|
5135
|
+
deprecationMessage
|
|
5136
|
+
};
|
|
5137
|
+
} catch (error) {
|
|
5138
|
+
log_default.debug(`Failed to check for updates: ${error}`);
|
|
5139
|
+
return {
|
|
5140
|
+
hasUpdate: false,
|
|
5141
|
+
currentVersion,
|
|
5142
|
+
isDeprecated: false
|
|
5143
|
+
};
|
|
5144
|
+
}
|
|
5145
|
+
}
|
|
5146
|
+
var BRAILLE_BLANK = "\u2800";
|
|
5147
|
+
var LIGHTNING_INTERVAL_MILLISECONDS = 140;
|
|
5148
|
+
var boltRows = [
|
|
5149
|
+
"\u2800\u2800\u2880\u28FE\u2800\u2800\u2800\u2800",
|
|
5150
|
+
"\u2800\u2800\u28E0\u28FF\u28FF\u2800\u2800\u2800",
|
|
5151
|
+
"\u2800\u28FC\u28FF\u28FF\u28FF\u28C0\u28C0\u2840",
|
|
5152
|
+
"\u2808\u2809\u2809\u28FF\u28FF\u28FF\u285F\u2800",
|
|
5153
|
+
"\u2800\u2800\u2800\u28FF\u28FF\u280B\u2800\u2800",
|
|
5154
|
+
"\u2800\u2800\u2800\u287F\u2801\u2800\u2800\u2800"
|
|
5155
|
+
];
|
|
5156
|
+
var boltFillOrder = boltRows.flatMap(
|
|
5157
|
+
(row, rowIndex) => [...row].flatMap(
|
|
5158
|
+
(cell, columnIndex) => cell === BRAILLE_BLANK ? [] : rowIndex * row.length + columnIndex
|
|
5159
|
+
)
|
|
5160
|
+
);
|
|
5161
|
+
var fillStages = [
|
|
5162
|
+
...Array.from({ length: boltFillOrder.length + 1 }, (_, index) => index),
|
|
5163
|
+
boltFillOrder.length,
|
|
5164
|
+
0
|
|
5165
|
+
];
|
|
5166
|
+
var boltFillRanks = new Map(
|
|
5167
|
+
boltFillOrder.map((cellIndex, fillIndex) => [cellIndex, fillIndex])
|
|
5168
|
+
);
|
|
5169
|
+
var STATUS_ROW_INDEX = Math.floor(boltRows.length / 2);
|
|
5170
|
+
function formatPhase({ label, detail }) {
|
|
5171
|
+
return detail ? `${chalk3.bold(label)} ${chalk3.dim(detail)}` : chalk3.bold(label);
|
|
5172
|
+
}
|
|
5173
|
+
function formatLoaderFrame({
|
|
5174
|
+
phase,
|
|
5175
|
+
fillStage
|
|
5176
|
+
}) {
|
|
5177
|
+
return boltRows.map((row, rowIndex) => {
|
|
5178
|
+
const bolt = [...row].map((cell, columnIndex) => {
|
|
5179
|
+
if (cell === BRAILLE_BLANK) return cell;
|
|
5180
|
+
const cellIndex = rowIndex * row.length + columnIndex;
|
|
5181
|
+
const fillRank = boltFillRanks.get(cellIndex);
|
|
5182
|
+
const isFilled = fillRank !== void 0 && fillRank < fillStage;
|
|
5183
|
+
return isFilled ? chalk3.bold.yellow(cell) : chalk3.dim.yellow(cell);
|
|
5184
|
+
}).join("");
|
|
5185
|
+
const status = rowIndex === STATUS_ROW_INDEX ? ` ${formatPhase(phase)}` : "";
|
|
5186
|
+
return `${bolt}${status}`;
|
|
5187
|
+
}).join("\n");
|
|
5188
|
+
}
|
|
5189
|
+
async function runWithSetupLoader({
|
|
5190
|
+
promise,
|
|
5191
|
+
...phase
|
|
5192
|
+
}) {
|
|
5193
|
+
const startedAt = Date.now();
|
|
5194
|
+
let fillFrameIndex = 0;
|
|
5195
|
+
const loader = ora({
|
|
5196
|
+
isEnabled: process.stderr.isTTY === true,
|
|
5197
|
+
spinner: { interval: 80, frames: [""] },
|
|
5198
|
+
text: formatLoaderFrame({
|
|
5199
|
+
phase,
|
|
5200
|
+
fillStage: fillStages[fillFrameIndex]
|
|
5201
|
+
})
|
|
5202
|
+
}).start();
|
|
5203
|
+
const animationTimer = setInterval(() => {
|
|
5204
|
+
fillFrameIndex = (fillFrameIndex + 1) % fillStages.length;
|
|
5205
|
+
loader.text = formatLoaderFrame({
|
|
5206
|
+
phase,
|
|
5207
|
+
fillStage: fillStages[fillFrameIndex]
|
|
5208
|
+
});
|
|
5209
|
+
}, LIGHTNING_INTERVAL_MILLISECONDS);
|
|
5210
|
+
animationTimer.unref?.();
|
|
5211
|
+
try {
|
|
5212
|
+
const result = await promise;
|
|
5213
|
+
clearInterval(animationTimer);
|
|
5214
|
+
const elapsedSeconds = ((Date.now() - startedAt) / 1e3).toFixed(1);
|
|
5215
|
+
loader.succeed(`${formatPhase(phase)} ${chalk3.dim(`${elapsedSeconds}s`)}`);
|
|
5216
|
+
return result;
|
|
5217
|
+
} catch (error) {
|
|
5218
|
+
clearInterval(animationTimer);
|
|
5219
|
+
const elapsedSeconds = ((Date.now() - startedAt) / 1e3).toFixed(1);
|
|
5220
|
+
loader.fail(`${formatPhase(phase)} ${chalk3.dim(`${elapsedSeconds}s`)}`);
|
|
5221
|
+
throw error;
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
function isRecord(value) {
|
|
5225
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5226
|
+
}
|
|
5227
|
+
function readPackageJson({
|
|
5228
|
+
directory
|
|
5229
|
+
}) {
|
|
5230
|
+
try {
|
|
5231
|
+
const manifest = JSON.parse(
|
|
5232
|
+
readFileSync(join(directory, "package.json"), "utf8")
|
|
5233
|
+
);
|
|
5234
|
+
return isRecord(manifest) ? manifest : void 0;
|
|
5235
|
+
} catch {
|
|
5236
|
+
return void 0;
|
|
5237
|
+
}
|
|
5238
|
+
}
|
|
5239
|
+
var SetupOptionSchema = z.object({
|
|
5240
|
+
label: z.string(),
|
|
5241
|
+
value: z.string()
|
|
5242
|
+
});
|
|
5243
|
+
var SetupOptionsSchema = z.array(SetupOptionSchema).min(1);
|
|
5244
|
+
var SetupDecisionSchema = z.object({
|
|
5245
|
+
message: z.string(),
|
|
5246
|
+
options: SetupOptionsSchema,
|
|
5247
|
+
answer: z.string()
|
|
5248
|
+
});
|
|
5249
|
+
var SetupInputSchema = z.object({
|
|
5250
|
+
message: z.string(),
|
|
5251
|
+
answer: z.string()
|
|
5252
|
+
});
|
|
5253
|
+
var setupDecisionResolver = defineResolver({
|
|
5254
|
+
requireParameters: ["message", "options"],
|
|
5255
|
+
listItems: ({ input }) => ({ data: input.options }),
|
|
5256
|
+
prompt: ({ items, input }) => ({
|
|
5257
|
+
type: "list",
|
|
5258
|
+
message: input.message,
|
|
5259
|
+
choices: items
|
|
5260
|
+
}),
|
|
5261
|
+
validate: ({ input, value }) => {
|
|
5262
|
+
if (typeof value !== "string") return "Choose an available option.";
|
|
5263
|
+
return input.options.some((option) => option.value === value) || "Choose one of the available options.";
|
|
5264
|
+
}
|
|
5265
|
+
});
|
|
5266
|
+
var setupInputResolver = defineResolver({
|
|
5267
|
+
type: "static",
|
|
5268
|
+
inputType: "text",
|
|
5269
|
+
requireParameters: ["message"]
|
|
5270
|
+
});
|
|
5271
|
+
var resolveSetupDecisionPlugin = defineMethod({
|
|
5272
|
+
name: "resolveSetupDecision",
|
|
5273
|
+
description: "Resolve one setup wizard decision.",
|
|
5274
|
+
inputSchema: SetupDecisionSchema,
|
|
5275
|
+
resolvers: { answer: setupDecisionResolver },
|
|
5276
|
+
run: ({ input }) => input
|
|
5277
|
+
});
|
|
5278
|
+
var resolveSetupInputPlugin = defineMethod({
|
|
5279
|
+
name: "resolveSetupInput",
|
|
5280
|
+
description: "Resolve one setup wizard text input.",
|
|
5281
|
+
inputSchema: SetupInputSchema,
|
|
5282
|
+
resolvers: { answer: setupInputResolver },
|
|
5283
|
+
run: ({ input }) => input
|
|
5284
|
+
});
|
|
5285
|
+
function createSetupController() {
|
|
5286
|
+
const setupResolutionSdk = createSdk(
|
|
5287
|
+
definePlugin({
|
|
5288
|
+
name: "setup-resolution",
|
|
5289
|
+
exports: [
|
|
5290
|
+
resolveSetupDecisionPlugin,
|
|
5291
|
+
resolveSetupInputPlugin,
|
|
5292
|
+
getRegistryPlugin
|
|
5293
|
+
]
|
|
5294
|
+
})
|
|
5295
|
+
);
|
|
5296
|
+
return createController(setupResolutionSdk);
|
|
5297
|
+
}
|
|
5298
|
+
async function resolveWithCancellation({
|
|
5299
|
+
run
|
|
5300
|
+
}) {
|
|
5301
|
+
try {
|
|
5302
|
+
return await run();
|
|
5303
|
+
} catch (error) {
|
|
5304
|
+
if (isCoreCancelledSignal(error)) {
|
|
5305
|
+
throw new ZapierCliUserCancellationError();
|
|
5306
|
+
}
|
|
5307
|
+
throw error;
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
async function resolveSetupDecision({
|
|
5311
|
+
answer,
|
|
5312
|
+
controller,
|
|
5313
|
+
message,
|
|
5314
|
+
options
|
|
5315
|
+
}) {
|
|
5316
|
+
const parsedOptions = SetupOptionsSchema.parse(options);
|
|
5317
|
+
const resolved = await resolveWithCancellation({
|
|
5318
|
+
run: () => controller.resolve({
|
|
5319
|
+
method: "resolveSetupDecision",
|
|
5320
|
+
input: { message, options: parsedOptions },
|
|
5321
|
+
answer,
|
|
5322
|
+
interactive: true
|
|
5323
|
+
})
|
|
5324
|
+
});
|
|
5325
|
+
return SetupDecisionSchema.parse(resolved).answer;
|
|
5326
|
+
}
|
|
5327
|
+
async function resolveSetupConfirm({
|
|
5328
|
+
answer,
|
|
5329
|
+
controller,
|
|
5330
|
+
defaultValue,
|
|
5331
|
+
message
|
|
5332
|
+
}) {
|
|
5333
|
+
const values = defaultValue ? [true, false] : [false, true];
|
|
5334
|
+
const resolved = await resolveSetupDecision({
|
|
5335
|
+
answer,
|
|
5336
|
+
controller,
|
|
5337
|
+
message,
|
|
5338
|
+
options: values.map((value) => ({
|
|
5339
|
+
label: value ? "Yes" : "No",
|
|
5340
|
+
value: String(value)
|
|
5341
|
+
}))
|
|
5342
|
+
});
|
|
5343
|
+
return resolved === "true";
|
|
5344
|
+
}
|
|
5345
|
+
async function resolveSetupInput({
|
|
5346
|
+
answer,
|
|
5347
|
+
controller,
|
|
5348
|
+
message
|
|
5349
|
+
}) {
|
|
5350
|
+
const resolved = await resolveWithCancellation({
|
|
5351
|
+
run: () => controller.resolve({
|
|
5352
|
+
method: "resolveSetupInput",
|
|
5353
|
+
input: { message },
|
|
5354
|
+
answer: ({ result, state }) => answer({
|
|
5355
|
+
state,
|
|
5356
|
+
result: {
|
|
5357
|
+
...result,
|
|
5358
|
+
question: { ...result.question, message }
|
|
5359
|
+
}
|
|
5360
|
+
}),
|
|
5361
|
+
interactive: true
|
|
5362
|
+
})
|
|
5363
|
+
});
|
|
5364
|
+
return SetupInputSchema.parse(resolved).answer.trim();
|
|
5365
|
+
}
|
|
5366
|
+
async function resolveSetupSelect({
|
|
5367
|
+
answer,
|
|
5368
|
+
controller,
|
|
5369
|
+
choices,
|
|
5370
|
+
message
|
|
5371
|
+
}) {
|
|
5372
|
+
const resolved = await resolveSetupDecision({
|
|
5373
|
+
answer,
|
|
5374
|
+
controller,
|
|
5375
|
+
message,
|
|
5376
|
+
options: choices
|
|
5377
|
+
});
|
|
5378
|
+
const selected = choices.find(({ value }) => value === resolved);
|
|
5379
|
+
if (!selected) {
|
|
5380
|
+
throw new Error("Resolved setup selection is not an available choice.");
|
|
5381
|
+
}
|
|
5382
|
+
return selected.value;
|
|
5383
|
+
}
|
|
5384
|
+
|
|
5385
|
+
// src/plugins/setup/dependencies.ts
|
|
5386
|
+
var REQUIRED_PACKAGES = [
|
|
5387
|
+
{ name: "@zapier/zapier-sdk", dev: false, checkForUpdates: true },
|
|
5388
|
+
{ name: "@zapier/zapier-sdk-cli", dev: true, checkForUpdates: true },
|
|
5389
|
+
{
|
|
5390
|
+
name: "@types/node",
|
|
5391
|
+
dev: true,
|
|
5392
|
+
checkForUpdates: false,
|
|
5393
|
+
typescriptOnly: true
|
|
5394
|
+
},
|
|
5395
|
+
{
|
|
5396
|
+
name: "typescript",
|
|
5397
|
+
dev: true,
|
|
5398
|
+
checkForUpdates: false,
|
|
5399
|
+
typescriptOnly: true
|
|
5400
|
+
},
|
|
5401
|
+
{ name: "tsx", dev: true, checkForUpdates: false, typescriptOnly: true }
|
|
5402
|
+
];
|
|
5403
|
+
function getInstallCommand({
|
|
5404
|
+
packageManager,
|
|
5405
|
+
packages,
|
|
5406
|
+
dev = false
|
|
5407
|
+
}) {
|
|
5408
|
+
const verb = packageManager === "npm" ? "install" : "add";
|
|
5409
|
+
const devFlag = packageManager === "bun" ? "-d" : "-D";
|
|
5410
|
+
return {
|
|
5411
|
+
command: packageManager,
|
|
5412
|
+
args: [verb, ...dev ? [devFlag] : [], ...packages]
|
|
5413
|
+
};
|
|
5414
|
+
}
|
|
5415
|
+
async function executeInstall(context, command) {
|
|
5416
|
+
try {
|
|
5417
|
+
await context.runCommand({ ...command, cwd: context.cwd });
|
|
5418
|
+
} catch (error) {
|
|
5419
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5420
|
+
if (message.includes("EPERM") && message.includes(".npm/_cacache")) {
|
|
5421
|
+
console.error(
|
|
5422
|
+
"This EPERM usually means the command sandbox blocked npm cache writes; it does not usually mean your file permissions are broken."
|
|
5423
|
+
);
|
|
5424
|
+
}
|
|
5425
|
+
throw error;
|
|
5426
|
+
}
|
|
5427
|
+
}
|
|
5428
|
+
function getDeclaredPackageNames(cwd) {
|
|
5429
|
+
const manifest = readPackageJson({ directory: cwd });
|
|
5430
|
+
if (!manifest) return /* @__PURE__ */ new Set();
|
|
5431
|
+
const names = /* @__PURE__ */ new Set();
|
|
5432
|
+
for (const section of ["dependencies", "devDependencies"]) {
|
|
5433
|
+
const dependencies = manifest[section];
|
|
5434
|
+
if (!isRecord(dependencies)) continue;
|
|
5435
|
+
for (const name of Object.keys(dependencies)) names.add(name);
|
|
5436
|
+
}
|
|
5437
|
+
return names;
|
|
5438
|
+
}
|
|
5439
|
+
function getInstalledPackageVersion({
|
|
5440
|
+
cwd,
|
|
5441
|
+
packageName
|
|
5442
|
+
}) {
|
|
5443
|
+
let directory = cwd;
|
|
5444
|
+
while (true) {
|
|
5445
|
+
const manifest = readPackageJson({
|
|
5446
|
+
directory: join(directory, "node_modules", ...packageName.split("/"))
|
|
5447
|
+
});
|
|
5448
|
+
if (manifest?.name === packageName && typeof manifest.version === "string") {
|
|
5449
|
+
return manifest.version;
|
|
5450
|
+
}
|
|
5451
|
+
const parent = dirname(directory);
|
|
5452
|
+
if (parent === directory) return void 0;
|
|
5453
|
+
directory = parent;
|
|
5454
|
+
}
|
|
5455
|
+
}
|
|
5456
|
+
async function installPackages({
|
|
5457
|
+
context,
|
|
5458
|
+
packages
|
|
5459
|
+
}) {
|
|
5460
|
+
const runtimePackages = packages.filter(({ dependency }) => !dependency.dev).map(({ dependency }) => dependency.name);
|
|
5461
|
+
if (runtimePackages.length > 0) {
|
|
5462
|
+
await executeInstall(
|
|
5463
|
+
context,
|
|
5464
|
+
getInstallCommand({
|
|
5465
|
+
packageManager: context.packageManager,
|
|
5466
|
+
packages: runtimePackages
|
|
5467
|
+
})
|
|
5468
|
+
);
|
|
5469
|
+
}
|
|
5470
|
+
const developmentPackages = packages.filter(({ dependency }) => dependency.dev).map(({ dependency }) => dependency.name);
|
|
5471
|
+
if (developmentPackages.length > 0) {
|
|
5472
|
+
await executeInstall(
|
|
5473
|
+
context,
|
|
5474
|
+
getInstallCommand({
|
|
5475
|
+
packageManager: context.packageManager,
|
|
5476
|
+
packages: developmentPackages,
|
|
5477
|
+
dev: true
|
|
5478
|
+
})
|
|
5479
|
+
);
|
|
5480
|
+
}
|
|
5481
|
+
}
|
|
5482
|
+
async function offerMissingPackageInstall({
|
|
5483
|
+
context,
|
|
5484
|
+
packages
|
|
5485
|
+
}) {
|
|
5486
|
+
if (packages.length === 0) return;
|
|
5487
|
+
const shouldInstall = await resolveSetupConfirm({
|
|
5488
|
+
answer: context.createAnswer(),
|
|
5489
|
+
controller: context.setupController,
|
|
5490
|
+
message: `These packages are required to continue. Install them now: ${packages.map(({ dependency }) => dependency.name).join(", ")}?`,
|
|
5491
|
+
defaultValue: true
|
|
5492
|
+
});
|
|
5493
|
+
if (!shouldInstall) {
|
|
5494
|
+
console.log(
|
|
5495
|
+
"The Zapier SDK packages are required to continue. Setup cancelled without installing dependencies."
|
|
5496
|
+
);
|
|
5497
|
+
throw new ZapierCliUserCancellationError(
|
|
5498
|
+
"Required Zapier SDK packages were not installed"
|
|
5499
|
+
);
|
|
5500
|
+
}
|
|
5501
|
+
await installPackages({ context, packages });
|
|
5502
|
+
}
|
|
5503
|
+
async function offerPackageUpdate({
|
|
5504
|
+
context,
|
|
5505
|
+
packageState
|
|
5506
|
+
}) {
|
|
5507
|
+
const { currentVersion, dependency } = packageState;
|
|
5508
|
+
if (!currentVersion || !dependency.checkForUpdates) return;
|
|
5509
|
+
const update = await runWithSetupLoader({
|
|
5510
|
+
promise: context.checkForUpdates({
|
|
5511
|
+
packageName: dependency.name,
|
|
5512
|
+
currentVersion
|
|
5513
|
+
}),
|
|
5514
|
+
label: "Checking for updates",
|
|
5515
|
+
detail: dependency.name
|
|
5516
|
+
});
|
|
5517
|
+
if (!update.hasUpdate || !update.latestVersion) return;
|
|
5518
|
+
const shouldUpdate = await resolveSetupConfirm({
|
|
5519
|
+
answer: context.createAnswer(),
|
|
5520
|
+
controller: context.setupController,
|
|
5521
|
+
message: `Update ${dependency.name} from ${currentVersion} to ${update.latestVersion}?`,
|
|
5522
|
+
defaultValue: true
|
|
5523
|
+
});
|
|
5524
|
+
if (!shouldUpdate) return;
|
|
5525
|
+
await executeInstall(
|
|
5526
|
+
context,
|
|
5527
|
+
getInstallCommand({
|
|
5528
|
+
packageManager: context.packageManager,
|
|
5529
|
+
packages: [`${dependency.name}@${update.latestVersion}`],
|
|
5530
|
+
dev: dependency.dev
|
|
5531
|
+
})
|
|
5532
|
+
);
|
|
5533
|
+
}
|
|
5534
|
+
async function prepareDependencies(context) {
|
|
5535
|
+
const declaredPackageNames = getDeclaredPackageNames(context.cwd);
|
|
5536
|
+
const requiredPackages = REQUIRED_PACKAGES.filter(
|
|
5537
|
+
({ typescriptOnly }) => !typescriptOnly || context.projectLanguage === "typescript"
|
|
5538
|
+
);
|
|
5539
|
+
const packages = requiredPackages.map((dependency) => ({
|
|
5540
|
+
dependency,
|
|
5541
|
+
currentVersion: declaredPackageNames.has(dependency.name) ? getInstalledPackageVersion({
|
|
5542
|
+
cwd: context.cwd,
|
|
5543
|
+
packageName: dependency.name
|
|
5544
|
+
}) : void 0
|
|
5545
|
+
}));
|
|
5546
|
+
await offerMissingPackageInstall({
|
|
5547
|
+
context,
|
|
5548
|
+
packages: packages.filter(
|
|
5549
|
+
({ dependency }) => !declaredPackageNames.has(dependency.name)
|
|
5550
|
+
)
|
|
5551
|
+
});
|
|
5552
|
+
for (const packageState of packages) {
|
|
5553
|
+
await offerPackageUpdate({ context, packageState });
|
|
5554
|
+
}
|
|
5555
|
+
}
|
|
5556
|
+
|
|
5557
|
+
// src/plugins/setup/package-commands.ts
|
|
5558
|
+
function createLocalPackageCommand({
|
|
5559
|
+
packageManager,
|
|
5560
|
+
binary,
|
|
5561
|
+
args = []
|
|
5562
|
+
}) {
|
|
5563
|
+
const runner = {
|
|
5564
|
+
npm: { command: "npx", args: ["--no-install"] },
|
|
5565
|
+
pnpm: { command: "pnpm", args: ["exec"] },
|
|
5566
|
+
yarn: { command: "yarn", args: ["exec"] },
|
|
5567
|
+
bun: { command: "bunx", args: ["--no-install"] }
|
|
5568
|
+
};
|
|
5569
|
+
return {
|
|
5570
|
+
command: runner[packageManager].command,
|
|
5571
|
+
args: [...runner[packageManager].args, binary, ...args]
|
|
5572
|
+
};
|
|
5573
|
+
}
|
|
5574
|
+
function createPackageRunnerCommand({
|
|
5575
|
+
packageManager,
|
|
5576
|
+
packageName,
|
|
5577
|
+
args = []
|
|
5578
|
+
}) {
|
|
5579
|
+
const runner = {
|
|
5580
|
+
npm: { command: "npx", args: ["--yes"] },
|
|
5581
|
+
pnpm: { command: "pnpm", args: ["dlx"] },
|
|
5582
|
+
yarn: { command: "yarn", args: ["dlx"] },
|
|
5583
|
+
bun: { command: "bunx", args: [] }
|
|
5584
|
+
};
|
|
5585
|
+
return {
|
|
5586
|
+
command: runner[packageManager].command,
|
|
5587
|
+
args: [...runner[packageManager].args, packageName, ...args]
|
|
5588
|
+
};
|
|
5589
|
+
}
|
|
5590
|
+
function formatPackageCommand({
|
|
5591
|
+
command,
|
|
5592
|
+
args
|
|
5593
|
+
}) {
|
|
5594
|
+
return [command, ...args].join(" ");
|
|
5595
|
+
}
|
|
5596
|
+
|
|
5597
|
+
// src/plugins/setup/project.ts
|
|
5598
|
+
var COMMAND_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
|
|
5599
|
+
var PROJECT_INIT_COMMANDS = {
|
|
5600
|
+
npm: { command: "npm", args: ["init", "-y"] },
|
|
5601
|
+
pnpm: { command: "pnpm", args: ["init"] },
|
|
5602
|
+
yarn: { command: "yarn", args: ["init", "-y"] },
|
|
5603
|
+
bun: { command: "bun", args: ["init", "-y"] }
|
|
5604
|
+
};
|
|
5605
|
+
var CapturedCommandError = class extends Error {
|
|
5606
|
+
constructor(error, stdout, stderr) {
|
|
5607
|
+
super(error.message);
|
|
5608
|
+
this.stdout = stdout;
|
|
5609
|
+
this.stderr = stderr;
|
|
5610
|
+
}
|
|
5611
|
+
};
|
|
5612
|
+
function commandError({
|
|
5613
|
+
command,
|
|
5614
|
+
code,
|
|
5615
|
+
signal
|
|
5616
|
+
}) {
|
|
5617
|
+
return new Error(
|
|
5618
|
+
signal ? `${command} was terminated by ${signal}` : `${command} exited with code ${code ?? "unknown"}`
|
|
5619
|
+
);
|
|
5620
|
+
}
|
|
5621
|
+
function executeCapturedCommand({
|
|
5622
|
+
command,
|
|
5623
|
+
args,
|
|
5624
|
+
cwd,
|
|
5625
|
+
input
|
|
5626
|
+
}) {
|
|
5627
|
+
return new Promise((resolve4, reject) => {
|
|
5628
|
+
const child = crossSpawn(command, args, {
|
|
5629
|
+
cwd,
|
|
5630
|
+
shell: false,
|
|
5631
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
5632
|
+
});
|
|
5633
|
+
let stdout = "";
|
|
5634
|
+
let stderr = "";
|
|
5635
|
+
const append = ({
|
|
5636
|
+
chunk,
|
|
5637
|
+
stream
|
|
5638
|
+
}) => {
|
|
5639
|
+
if (stream === "stdout") stdout += chunk.toString();
|
|
5640
|
+
else stderr += chunk.toString();
|
|
5641
|
+
if (Buffer.byteLength(stdout) + Buffer.byteLength(stderr) > COMMAND_MAX_BUFFER_BYTES) {
|
|
5642
|
+
child.kill();
|
|
5643
|
+
reject(new Error("Command output exceeded the capture limit."));
|
|
5644
|
+
}
|
|
5645
|
+
};
|
|
5646
|
+
child.stdout?.on(
|
|
5647
|
+
"data",
|
|
5648
|
+
(chunk) => append({ chunk, stream: "stdout" })
|
|
5649
|
+
);
|
|
5650
|
+
child.stderr?.on(
|
|
5651
|
+
"data",
|
|
5652
|
+
(chunk) => append({ chunk, stream: "stderr" })
|
|
5653
|
+
);
|
|
5654
|
+
child.once("error", reject);
|
|
5655
|
+
child.once("close", (code, signal) => {
|
|
5656
|
+
if (code === 0) {
|
|
5657
|
+
resolve4(stdout.trim());
|
|
5658
|
+
return;
|
|
5659
|
+
}
|
|
5660
|
+
reject(
|
|
5661
|
+
new CapturedCommandError(
|
|
5662
|
+
commandError({ command, code, signal }),
|
|
5663
|
+
stdout,
|
|
5664
|
+
stderr
|
|
5665
|
+
)
|
|
5666
|
+
);
|
|
5667
|
+
});
|
|
5668
|
+
child.stdin?.end(input);
|
|
5669
|
+
});
|
|
5670
|
+
}
|
|
5671
|
+
function executeStreamingCommand({
|
|
5672
|
+
command,
|
|
5673
|
+
args,
|
|
5674
|
+
cwd,
|
|
5675
|
+
input
|
|
5676
|
+
}) {
|
|
5677
|
+
return new Promise((resolve4, reject) => {
|
|
5678
|
+
const child = crossSpawn(command, args, {
|
|
5679
|
+
cwd,
|
|
5680
|
+
shell: false,
|
|
5681
|
+
stdio: [input === void 0 ? "inherit" : "pipe", "inherit", "inherit"]
|
|
5682
|
+
});
|
|
5683
|
+
child.once("error", reject);
|
|
5684
|
+
child.once("close", (code, signal) => {
|
|
5685
|
+
if (code === 0) {
|
|
5686
|
+
resolve4("");
|
|
5687
|
+
return;
|
|
5688
|
+
}
|
|
5689
|
+
reject(commandError({ command, code, signal }));
|
|
5690
|
+
});
|
|
5691
|
+
if (input !== void 0) child.stdin?.end(input);
|
|
5692
|
+
});
|
|
5693
|
+
}
|
|
5694
|
+
async function runCommand({
|
|
5695
|
+
command,
|
|
5696
|
+
args = [],
|
|
5697
|
+
cwd,
|
|
5698
|
+
capture = true,
|
|
5699
|
+
input
|
|
5700
|
+
}) {
|
|
5701
|
+
const commandLabel = `$ ${command} ${args.join(" ")}`.trim();
|
|
5702
|
+
const execute = capture ? executeCapturedCommand({ command, args, cwd, input }) : executeStreamingCommand({ command, args, cwd, input });
|
|
5703
|
+
try {
|
|
5704
|
+
if (capture) {
|
|
5705
|
+
return await runWithSetupLoader({
|
|
5706
|
+
promise: execute,
|
|
5707
|
+
label: "Running command",
|
|
5708
|
+
detail: commandLabel
|
|
5709
|
+
});
|
|
5710
|
+
}
|
|
5711
|
+
console.log(chalk3.dim(commandLabel));
|
|
5712
|
+
return await execute;
|
|
5713
|
+
} catch (error) {
|
|
5714
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5715
|
+
if (error instanceof CapturedCommandError) {
|
|
5716
|
+
if (error.stdout) process.stdout.write(error.stdout);
|
|
5717
|
+
if (error.stderr) process.stderr.write(error.stderr);
|
|
5718
|
+
if (!error.stdout && !error.stderr) console.error(message);
|
|
5719
|
+
} else {
|
|
5720
|
+
console.error(message);
|
|
5721
|
+
}
|
|
5722
|
+
throw new ZapierCliExitError(message);
|
|
5723
|
+
}
|
|
5724
|
+
}
|
|
5725
|
+
async function chooseDirectory(context) {
|
|
5726
|
+
const useCurrentDirectory = await resolveSetupConfirm({
|
|
5727
|
+
answer: context.createAnswer(),
|
|
5728
|
+
controller: context.setupController,
|
|
5729
|
+
message: `Set up the Zapier SDK in ${context.cwd}?`,
|
|
5730
|
+
defaultValue: true
|
|
5731
|
+
});
|
|
5732
|
+
if (useCurrentDirectory) return;
|
|
5733
|
+
const setupCommand = formatPackageCommand(
|
|
5734
|
+
createLocalPackageCommand({
|
|
5735
|
+
packageManager: context.packageManager,
|
|
5736
|
+
binary: "zapier-sdk",
|
|
5737
|
+
args: ["setup"]
|
|
5738
|
+
})
|
|
5739
|
+
);
|
|
5740
|
+
console.log(
|
|
5741
|
+
`Setup cancelled. Navigate to the intended directory and run \`${setupCommand}\` again.`
|
|
5742
|
+
);
|
|
5743
|
+
throw new ZapierCliUserCancellationError("Setup cancelled by user");
|
|
5744
|
+
}
|
|
5745
|
+
async function ensureSupportedNode(context) {
|
|
5746
|
+
let version;
|
|
5747
|
+
try {
|
|
5748
|
+
version = await context.runCommand({
|
|
5749
|
+
command: "node",
|
|
5750
|
+
args: ["-v"],
|
|
5751
|
+
cwd: context.cwd,
|
|
5752
|
+
capture: true
|
|
5753
|
+
});
|
|
5754
|
+
} catch {
|
|
5755
|
+
console.error(
|
|
5756
|
+
"Node.js 20 or higher is required. Install it from https://nodejs.org, then run setup again."
|
|
5757
|
+
);
|
|
5758
|
+
throw new ZapierCliExitError(
|
|
5759
|
+
"Setup could not continue without Node.js 20 or higher."
|
|
5760
|
+
);
|
|
5761
|
+
}
|
|
5762
|
+
const major = Number(version.replace(/^v/, "").split(".")[0]);
|
|
5763
|
+
if (!Number.isFinite(major) || major < 20) {
|
|
5764
|
+
console.error(
|
|
5765
|
+
`Node.js 20 or higher is required; found ${version}. Upgrade Node.js, then run setup again.`
|
|
5766
|
+
);
|
|
5767
|
+
throw new ZapierCliExitError(
|
|
5768
|
+
"Setup could not continue without Node.js 20 or higher."
|
|
5769
|
+
);
|
|
5770
|
+
}
|
|
5771
|
+
console.log(`Node.js ${version} is ready.`);
|
|
5772
|
+
}
|
|
5773
|
+
function detectProjectLanguage({
|
|
5774
|
+
cwd,
|
|
5775
|
+
hasExistingProject
|
|
5776
|
+
}) {
|
|
5777
|
+
if (!hasExistingProject || existsSync(join(cwd, "tsconfig.json"))) {
|
|
5778
|
+
return "typescript";
|
|
5779
|
+
}
|
|
5780
|
+
const manifest = readPackageJson({ directory: cwd });
|
|
5781
|
+
const hasTypeScript = [
|
|
5782
|
+
manifest?.dependencies,
|
|
5783
|
+
manifest?.devDependencies
|
|
5784
|
+
].some(
|
|
5785
|
+
(dependencies) => isRecord(dependencies) && "typescript" in dependencies
|
|
5786
|
+
);
|
|
5787
|
+
return hasTypeScript ? "typescript" : "javascript";
|
|
5788
|
+
}
|
|
5789
|
+
async function prepareProject(context) {
|
|
5790
|
+
context.packageManager = detectPackageManager(context.cwd).name;
|
|
5791
|
+
console.log(`Using ${context.packageManager} for dependency installs.`);
|
|
5792
|
+
const hasExistingProject = existsSync(join(context.cwd, "package.json"));
|
|
5793
|
+
context.projectLanguage = detectProjectLanguage({
|
|
5794
|
+
cwd: context.cwd,
|
|
5795
|
+
hasExistingProject
|
|
5796
|
+
});
|
|
5797
|
+
if (hasExistingProject) {
|
|
5798
|
+
console.log("Found package.json; using this project as-is.");
|
|
5799
|
+
} else {
|
|
5800
|
+
await context.runCommand({
|
|
5801
|
+
...PROJECT_INIT_COMMANDS[context.packageManager],
|
|
5802
|
+
cwd: context.cwd
|
|
5803
|
+
});
|
|
5804
|
+
}
|
|
5805
|
+
await prepareDependencies(context);
|
|
5806
|
+
}
|
|
5807
|
+
|
|
5808
|
+
// src/plugins/setup/context.ts
|
|
5809
|
+
function createWizardContext({
|
|
5810
|
+
imports
|
|
5811
|
+
}) {
|
|
5812
|
+
return {
|
|
5813
|
+
cwd: process.cwd(),
|
|
5814
|
+
imports,
|
|
5815
|
+
createAnswer: () => createCliAnswer({ mode: "closed-list" }),
|
|
5816
|
+
setupController: createSetupController(),
|
|
5817
|
+
checkForUpdates,
|
|
5818
|
+
openUrl: async (url) => {
|
|
5819
|
+
await open(url);
|
|
5820
|
+
},
|
|
5821
|
+
runCommand,
|
|
5822
|
+
packageManager: detectPackageManager(process.cwd()).name,
|
|
5823
|
+
projectLanguage: "typescript"
|
|
5824
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
var SetupSchema = z.object({}).describe("Set up the Zapier SDK in an existing or new project");
|
|
5827
|
+
function printAuthCommand({
|
|
5828
|
+
context,
|
|
5829
|
+
flow,
|
|
5830
|
+
headless
|
|
5831
|
+
}) {
|
|
5832
|
+
const command = createLocalPackageCommand({
|
|
5833
|
+
packageManager: context.packageManager,
|
|
5834
|
+
binary: "zapier-sdk",
|
|
5835
|
+
args: [flow, ...headless ? ["--headless"] : []]
|
|
5836
|
+
});
|
|
5837
|
+
console.log(`$ ${formatPackageCommand(command)}`);
|
|
5838
|
+
if (headless) {
|
|
5839
|
+
console.log(
|
|
5840
|
+
"Open the printed URL in another browser, then paste the final OAuth callback URL when prompted."
|
|
5841
|
+
);
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5844
|
+
function isCredentialWriteError(error) {
|
|
5845
|
+
const code = typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : "";
|
|
5846
|
+
if (/^(eacces|eperm)$/i.test(code)) return true;
|
|
5847
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5848
|
+
return /permission|sandbox|eacces|eperm/i.test(message);
|
|
5849
|
+
}
|
|
5850
|
+
async function authenticate(context) {
|
|
5851
|
+
const activeProfile = await runWithSetupLoader({
|
|
5852
|
+
promise: context.imports.getProfile({}).then(({ data }) => data).catch((error) => {
|
|
5853
|
+
if (isZapierAuthenticationError(error)) return void 0;
|
|
5854
|
+
throw error;
|
|
5855
|
+
}),
|
|
5856
|
+
label: "Checking Zapier authentication"
|
|
5857
|
+
});
|
|
5858
|
+
if (activeProfile) {
|
|
5859
|
+
const shouldLogout = await resolveSetupConfirm({
|
|
5860
|
+
answer: context.createAnswer(),
|
|
5861
|
+
controller: context.setupController,
|
|
5862
|
+
message: `You are already logged in as "${activeProfile.email}".
|
|
5863
|
+
Logging out will delete these credentials and may interrupt other Zapier SDK or CLI sessions using them.
|
|
5864
|
+
Log out and use a different account?`,
|
|
5865
|
+
defaultValue: false
|
|
5866
|
+
});
|
|
5867
|
+
if (!shouldLogout) {
|
|
5868
|
+
context.accountEmail = activeProfile.email;
|
|
5869
|
+
console.log(`Continuing as ${activeProfile.email}.`);
|
|
5870
|
+
return;
|
|
5871
|
+
}
|
|
5872
|
+
const logoutCommand = createLocalPackageCommand({
|
|
5873
|
+
packageManager: context.packageManager,
|
|
5874
|
+
binary: "zapier-sdk",
|
|
5875
|
+
args: ["logout"]
|
|
4558
5876
|
});
|
|
5877
|
+
console.log(`$ ${formatPackageCommand(logoutCommand)}`);
|
|
5878
|
+
await context.imports.logout({});
|
|
5879
|
+
}
|
|
5880
|
+
const flow = await resolveSetupSelect({
|
|
5881
|
+
answer: context.createAnswer(),
|
|
5882
|
+
controller: context.setupController,
|
|
5883
|
+
message: "Zapier account:",
|
|
5884
|
+
choices: [
|
|
5885
|
+
{ label: "Log in to an existing account", value: "login" },
|
|
5886
|
+
{ label: "Create a new Zapier account", value: "signup" }
|
|
5887
|
+
]
|
|
5888
|
+
});
|
|
5889
|
+
const environment = await resolveSetupSelect({
|
|
5890
|
+
answer: context.createAnswer(),
|
|
5891
|
+
controller: context.setupController,
|
|
5892
|
+
message: "Environment:",
|
|
5893
|
+
choices: [
|
|
5894
|
+
{ label: "Local machine with a browser", value: "local" },
|
|
5895
|
+
{ label: "Remote or headless", value: "headless" }
|
|
5896
|
+
]
|
|
5897
|
+
});
|
|
5898
|
+
const headless = environment === "headless";
|
|
5899
|
+
const runAuth = flow === "login" ? context.imports.login : context.imports.signup;
|
|
5900
|
+
printAuthCommand({ context, flow, headless });
|
|
5901
|
+
try {
|
|
5902
|
+
await runAuth({ headless });
|
|
5903
|
+
} catch (error) {
|
|
5904
|
+
if (isCredentialWriteError(error)) {
|
|
5905
|
+
console.error(
|
|
5906
|
+
"Authentication could not write credentials. A permissions or sandbox restriction may be blocking disk access."
|
|
5907
|
+
);
|
|
5908
|
+
}
|
|
5909
|
+
throw error;
|
|
5910
|
+
}
|
|
5911
|
+
const { data: profile } = await runWithSetupLoader({
|
|
5912
|
+
promise: context.imports.getProfile({}),
|
|
5913
|
+
label: "Confirming Zapier account"
|
|
5914
|
+
});
|
|
5915
|
+
context.accountEmail = profile.email;
|
|
5916
|
+
console.log(`Authenticated as ${profile.email}.`);
|
|
5917
|
+
}
|
|
5918
|
+
var agentLabels = {
|
|
5919
|
+
claude: "Claude Code",
|
|
5920
|
+
codex: "Codex",
|
|
5921
|
+
cursor: "Cursor",
|
|
5922
|
+
"vscode-copilot": "VS Code Copilot"
|
|
5923
|
+
};
|
|
5924
|
+
function buildAgentPrompt({ context }) {
|
|
5925
|
+
const listConnectionsCommand = formatPackageCommand(
|
|
5926
|
+
createLocalPackageCommand({
|
|
5927
|
+
packageManager: context.packageManager,
|
|
5928
|
+
binary: "zapier-sdk",
|
|
5929
|
+
args: ["list-connections", "--owner", "me", "--json"]
|
|
5930
|
+
})
|
|
5931
|
+
);
|
|
5932
|
+
const listActionsCommand = formatPackageCommand(
|
|
5933
|
+
createLocalPackageCommand({
|
|
5934
|
+
packageManager: context.packageManager,
|
|
5935
|
+
binary: "zapier-sdk",
|
|
5936
|
+
args: ["list-actions", "APP_KEY"]
|
|
5937
|
+
})
|
|
5938
|
+
);
|
|
5939
|
+
return `Start by running this command to discover my active connected apps outside of your sandbox:
|
|
5940
|
+
|
|
5941
|
+
${listConnectionsCommand}
|
|
5942
|
+
|
|
5943
|
+
Using the connected apps returned by that command:
|
|
5944
|
+
|
|
5945
|
+
- Pick 1-3 apps and show commands I can use to explore their actions, such as: ${listActionsCommand}
|
|
5946
|
+
- Do not run those list-actions commands.
|
|
5947
|
+
- Suggest 3 specific ideas based on my connected apps. Each idea should read from one app, optionally process data, and write to another.
|
|
5948
|
+
- Do not suggest event-driven workflows.
|
|
5949
|
+
- Keep each idea to one sentence. Example: "pull in-progress Jira issues and DM yourself a summary on Slack".
|
|
5950
|
+
|
|
5951
|
+
Do not inspect files or modify the project. If fewer than two distinct apps are listed, explain that cross-app ideas require another active connection instead of inventing apps.`;
|
|
5952
|
+
}
|
|
5953
|
+
function printAgentPrompt({
|
|
5954
|
+
context,
|
|
5955
|
+
message
|
|
5956
|
+
}) {
|
|
5957
|
+
console.log();
|
|
5958
|
+
console.log(chalk3.bgYellow.black.bold(message));
|
|
5959
|
+
console.log();
|
|
5960
|
+
console.log(buildAgentPrompt({ context }));
|
|
5961
|
+
}
|
|
5962
|
+
async function openAgentHandoff(context) {
|
|
5963
|
+
const agent = await resolveSetupSelect({
|
|
5964
|
+
answer: context.createAnswer(),
|
|
5965
|
+
controller: context.setupController,
|
|
5966
|
+
message: "Want to open your agent and have it give you suggestions to start?",
|
|
5967
|
+
choices: [
|
|
5968
|
+
{ label: "No", value: "none" },
|
|
5969
|
+
{ label: "Claude Code", value: "claude" },
|
|
5970
|
+
{ label: "Cursor", value: "cursor" },
|
|
5971
|
+
{ label: "Codex", value: "codex" },
|
|
5972
|
+
{ label: "VS Code Copilot", value: "vscode-copilot" },
|
|
5973
|
+
{ label: "Other", value: "other" }
|
|
5974
|
+
]
|
|
5975
|
+
});
|
|
5976
|
+
if (agent === "none") return;
|
|
5977
|
+
if (agent === "other") {
|
|
5978
|
+
printAgentPrompt({
|
|
5979
|
+
context,
|
|
5980
|
+
message: "Paste this prompt into your AI agent:"
|
|
5981
|
+
});
|
|
5982
|
+
return;
|
|
5983
|
+
}
|
|
5984
|
+
const prompt = buildAgentPrompt({ context });
|
|
5985
|
+
const encodedPrompt = encodeURIComponent(prompt);
|
|
5986
|
+
const encodedPath = encodeURIComponent(context.cwd);
|
|
5987
|
+
try {
|
|
5988
|
+
switch (agent) {
|
|
5989
|
+
case "claude":
|
|
5990
|
+
await context.openUrl(
|
|
5991
|
+
`claude://code/new?q=${encodedPrompt}&folder=${encodedPath}`
|
|
5992
|
+
);
|
|
5993
|
+
break;
|
|
5994
|
+
case "codex":
|
|
5995
|
+
await context.openUrl(
|
|
5996
|
+
`codex://threads/new?prompt=${encodedPrompt}&path=${encodedPath}`
|
|
5997
|
+
);
|
|
5998
|
+
break;
|
|
5999
|
+
case "cursor":
|
|
6000
|
+
await context.runCommand({
|
|
6001
|
+
command: "cursor",
|
|
6002
|
+
args: ["."],
|
|
6003
|
+
cwd: context.cwd,
|
|
6004
|
+
capture: true
|
|
6005
|
+
});
|
|
6006
|
+
console.log(`Cursor opened in ${context.cwd}.`);
|
|
6007
|
+
break;
|
|
6008
|
+
case "vscode-copilot":
|
|
6009
|
+
await context.runCommand({
|
|
6010
|
+
command: "code",
|
|
6011
|
+
args: ["chat", "--mode", "agent", "-"],
|
|
6012
|
+
cwd: context.cwd,
|
|
6013
|
+
input: prompt
|
|
6014
|
+
});
|
|
6015
|
+
break;
|
|
6016
|
+
default: {
|
|
6017
|
+
const unsupportedAgent = agent;
|
|
6018
|
+
throw new Error(`Unsupported agent: ${unsupportedAgent}`);
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
} catch {
|
|
6022
|
+
console.warn(
|
|
6023
|
+
`Could not open ${agentLabels[agent]}. Open it manually to continue.`
|
|
6024
|
+
);
|
|
6025
|
+
}
|
|
6026
|
+
printAgentPrompt({
|
|
6027
|
+
context,
|
|
6028
|
+
message: "If it didn't load correctly, paste this prompt into your agent:"
|
|
6029
|
+
});
|
|
6030
|
+
}
|
|
6031
|
+
var CONNECTIONS_URL = "https://zapier.com/app/assets/connections";
|
|
6032
|
+
var CONNECTION_DISPLAY_LIMIT = 10;
|
|
6033
|
+
async function ensureConnectionsAvailable(context) {
|
|
6034
|
+
const page = await runWithSetupLoader({
|
|
6035
|
+
promise: context.imports.listConnections({
|
|
6036
|
+
owner: "me",
|
|
6037
|
+
maxItems: CONNECTION_DISPLAY_LIMIT
|
|
6038
|
+
}),
|
|
6039
|
+
label: "Loading app connections"
|
|
6040
|
+
});
|
|
6041
|
+
if (page.data.length === 0) {
|
|
6042
|
+
console.log(
|
|
6043
|
+
`No active connections found. Connect or reconnect an app at ${CONNECTIONS_URL}, then come back and run setup again.`
|
|
6044
|
+
);
|
|
6045
|
+
throw new ZapierCliExitError(
|
|
6046
|
+
"Setup stopped before completion because no active connections are available."
|
|
6047
|
+
);
|
|
6048
|
+
}
|
|
6049
|
+
const table = new Table({
|
|
6050
|
+
head: ["App", "Connection"],
|
|
6051
|
+
style: { compact: true }
|
|
6052
|
+
});
|
|
6053
|
+
table.push(
|
|
6054
|
+
...page.data.map((connection) => [
|
|
6055
|
+
connection.slug || connection.app_key,
|
|
6056
|
+
connection.title
|
|
6057
|
+
])
|
|
6058
|
+
);
|
|
6059
|
+
console.log(
|
|
6060
|
+
`Active Zapier connections (showing up to ${CONNECTION_DISPLAY_LIMIT}):`
|
|
6061
|
+
);
|
|
6062
|
+
console.log(table.toString());
|
|
6063
|
+
}
|
|
6064
|
+
var CONNECTION_PLACEHOLDER = "__ZAPIER_SDK_SLACK_CONNECTION__";
|
|
6065
|
+
var EMAIL_PLACEHOLDER = "__ZAPIER_SDK_ACCOUNT_EMAIL__";
|
|
6066
|
+
var APP_PLACEHOLDER = "__ZAPIER_SDK_SLACK_APP__";
|
|
6067
|
+
var SLACK_SLUG = "slack";
|
|
6068
|
+
function getSlackTestPath(context) {
|
|
6069
|
+
const extension = context.projectLanguage === "typescript" ? "ts" : "mjs";
|
|
6070
|
+
return join("src", "sdk-demo", `zapier-slack-test.${extension}`);
|
|
6071
|
+
}
|
|
6072
|
+
function getSlackTestTemplatePath(context) {
|
|
6073
|
+
const extension = context.projectLanguage === "typescript" ? "ts" : "mjs";
|
|
6074
|
+
return join(TEMPLATES_DIR, "setup", `zapier-slack-test.${extension}`);
|
|
6075
|
+
}
|
|
6076
|
+
async function findSlackConnection(context) {
|
|
6077
|
+
const page = await runWithSetupLoader({
|
|
6078
|
+
promise: context.imports.listConnections({
|
|
6079
|
+
owner: "me",
|
|
6080
|
+
app: SLACK_SLUG,
|
|
6081
|
+
maxItems: 1
|
|
6082
|
+
}),
|
|
6083
|
+
label: "Looking for a Slack connection"
|
|
6084
|
+
});
|
|
6085
|
+
return page.data.find(({ slug }) => slug === SLACK_SLUG);
|
|
6086
|
+
}
|
|
6087
|
+
function toTemplateString(value) {
|
|
6088
|
+
return JSON.stringify(value).slice(1, -1);
|
|
6089
|
+
}
|
|
6090
|
+
function renderSlackTest({
|
|
6091
|
+
context,
|
|
6092
|
+
app,
|
|
6093
|
+
connection,
|
|
6094
|
+
email
|
|
6095
|
+
}) {
|
|
6096
|
+
return readFileSync(getSlackTestTemplatePath(context), "utf8").replace(APP_PLACEHOLDER, () => toTemplateString(app)).replace(CONNECTION_PLACEHOLDER, () => toTemplateString(connection)).replace(EMAIL_PLACEHOLDER, () => toTemplateString(email));
|
|
6097
|
+
}
|
|
6098
|
+
function writeSlackTest({
|
|
6099
|
+
context,
|
|
6100
|
+
app,
|
|
6101
|
+
connection,
|
|
6102
|
+
email
|
|
6103
|
+
}) {
|
|
6104
|
+
const slackTestPath = getSlackTestPath(context);
|
|
6105
|
+
const path2 = join(context.cwd, slackTestPath);
|
|
6106
|
+
if (!existsSync(dirname(path2))) mkdirSync(dirname(path2), { recursive: true });
|
|
6107
|
+
writeFileSync(path2, renderSlackTest({ context, app, connection, email }));
|
|
6108
|
+
console.log(`Created ${slackTestPath}.`);
|
|
6109
|
+
}
|
|
6110
|
+
async function executeSlackTest(context) {
|
|
6111
|
+
const slackTestPath = getSlackTestPath(context);
|
|
6112
|
+
if (context.projectLanguage === "javascript") {
|
|
6113
|
+
await context.runCommand({
|
|
6114
|
+
command: "node",
|
|
6115
|
+
args: [slackTestPath],
|
|
6116
|
+
cwd: context.cwd,
|
|
6117
|
+
capture: false
|
|
6118
|
+
});
|
|
6119
|
+
return;
|
|
6120
|
+
}
|
|
6121
|
+
const command = context.packageManager === "bun" ? { command: "bun", args: [] } : createLocalPackageCommand({
|
|
6122
|
+
packageManager: context.packageManager,
|
|
6123
|
+
binary: "tsx"
|
|
6124
|
+
});
|
|
6125
|
+
const args = [...command.args, slackTestPath];
|
|
6126
|
+
await context.runCommand({
|
|
6127
|
+
command: command.command,
|
|
6128
|
+
args,
|
|
6129
|
+
cwd: context.cwd,
|
|
6130
|
+
capture: false
|
|
6131
|
+
});
|
|
6132
|
+
}
|
|
6133
|
+
async function trySlackTest(context) {
|
|
6134
|
+
try {
|
|
6135
|
+
await executeSlackTest(context);
|
|
6136
|
+
return true;
|
|
6137
|
+
} catch (error) {
|
|
6138
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6139
|
+
console.warn(`Slack demo failed: ${message}. Setup will continue.`);
|
|
6140
|
+
return false;
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
async function offerSlackTest(context) {
|
|
6144
|
+
if (!context.accountEmail) {
|
|
6145
|
+
console.log("No account email found; skipping the Slack demo.");
|
|
6146
|
+
return;
|
|
6147
|
+
}
|
|
6148
|
+
const slackConnection = await findSlackConnection(context);
|
|
6149
|
+
if (!slackConnection) {
|
|
6150
|
+
console.log("No active Slack connection found; skipping the Slack demo.");
|
|
6151
|
+
return;
|
|
6152
|
+
}
|
|
6153
|
+
const slackTestPath = getSlackTestPath(context);
|
|
6154
|
+
const shouldRun = await resolveSetupConfirm({
|
|
6155
|
+
answer: context.createAnswer(),
|
|
6156
|
+
controller: context.setupController,
|
|
6157
|
+
message: `Run the Slack self-DM test using ${context.accountEmail}?`,
|
|
6158
|
+
defaultValue: true
|
|
6159
|
+
});
|
|
6160
|
+
if (!shouldRun) return;
|
|
6161
|
+
const path2 = join(context.cwd, slackTestPath);
|
|
6162
|
+
if (existsSync(path2)) {
|
|
6163
|
+
const shouldOverwrite = await resolveSetupConfirm({
|
|
6164
|
+
answer: context.createAnswer(),
|
|
6165
|
+
controller: context.setupController,
|
|
6166
|
+
message: `${slackTestPath} already exists. Is it okay to overwrite it?`,
|
|
6167
|
+
defaultValue: false
|
|
6168
|
+
});
|
|
6169
|
+
if (!shouldOverwrite) {
|
|
6170
|
+
console.log("Keeping the existing Slack test file.");
|
|
6171
|
+
const shouldRunExisting = await resolveSetupConfirm({
|
|
6172
|
+
answer: context.createAnswer(),
|
|
6173
|
+
controller: context.setupController,
|
|
6174
|
+
message: `Run the existing ${slackTestPath}?`,
|
|
6175
|
+
defaultValue: false
|
|
6176
|
+
});
|
|
6177
|
+
if (shouldRunExisting) await trySlackTest(context);
|
|
6178
|
+
return;
|
|
6179
|
+
}
|
|
6180
|
+
}
|
|
6181
|
+
let email = context.accountEmail;
|
|
6182
|
+
writeSlackTest({
|
|
6183
|
+
context,
|
|
6184
|
+
app: SLACK_SLUG,
|
|
6185
|
+
connection: slackConnection.id,
|
|
6186
|
+
email
|
|
6187
|
+
});
|
|
6188
|
+
if (await trySlackTest(context)) return;
|
|
6189
|
+
email = await resolveSetupInput({
|
|
6190
|
+
answer: context.createAnswer(),
|
|
6191
|
+
controller: context.setupController,
|
|
6192
|
+
message: "Slack email for one retry after the failed test:"
|
|
6193
|
+
});
|
|
6194
|
+
if (!email) {
|
|
6195
|
+
console.log("Skipping the Slack test.");
|
|
6196
|
+
return;
|
|
6197
|
+
}
|
|
6198
|
+
writeSlackTest({
|
|
6199
|
+
context,
|
|
6200
|
+
app: SLACK_SLUG,
|
|
6201
|
+
connection: slackConnection.id,
|
|
6202
|
+
email
|
|
6203
|
+
});
|
|
6204
|
+
await trySlackTest(context);
|
|
6205
|
+
}
|
|
6206
|
+
|
|
6207
|
+
// src/plugins/setup/skill.ts
|
|
6208
|
+
async function installOptionalSkill(context) {
|
|
6209
|
+
const shouldInstall = await resolveSetupConfirm({
|
|
6210
|
+
answer: context.createAnswer(),
|
|
6211
|
+
controller: context.setupController,
|
|
6212
|
+
message: "Install the optional Zapier SDK skill for extra agent context? This is not required for SDK setup.",
|
|
6213
|
+
defaultValue: true
|
|
6214
|
+
});
|
|
6215
|
+
if (!shouldInstall) {
|
|
6216
|
+
console.log("Skipping the optional Zapier SDK skill.");
|
|
6217
|
+
return;
|
|
6218
|
+
}
|
|
6219
|
+
const command = createPackageRunnerCommand({
|
|
6220
|
+
packageManager: context.packageManager,
|
|
6221
|
+
packageName: "skills",
|
|
6222
|
+
args: ["add", "zapier/sdk", "-y"]
|
|
6223
|
+
});
|
|
6224
|
+
try {
|
|
6225
|
+
await context.runCommand({
|
|
6226
|
+
...command,
|
|
6227
|
+
cwd: context.cwd,
|
|
6228
|
+
capture: true
|
|
6229
|
+
});
|
|
6230
|
+
} catch {
|
|
6231
|
+
console.warn(
|
|
6232
|
+
`Could not install the optional Zapier SDK skill. To install it manually, run: ${formatPackageCommand(command)}`
|
|
6233
|
+
);
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
|
|
6237
|
+
// src/plugins/setup/wizard.ts
|
|
6238
|
+
var PHASE_COUNT = 6;
|
|
6239
|
+
var MINIMUM_MESSAGE_WIDTH = 20;
|
|
6240
|
+
var MAXIMUM_MESSAGE_WIDTH = 88;
|
|
6241
|
+
function showPhase({ number, title }) {
|
|
6242
|
+
console.log();
|
|
6243
|
+
console.log(chalk3.bgCyan.black.bold(` ${number}/${PHASE_COUNT} ${title} `));
|
|
6244
|
+
}
|
|
6245
|
+
function printWrapped(text) {
|
|
6246
|
+
const width = Math.max(
|
|
6247
|
+
MINIMUM_MESSAGE_WIDTH,
|
|
6248
|
+
Math.min(
|
|
6249
|
+
process.stdout.columns ?? MAXIMUM_MESSAGE_WIDTH,
|
|
6250
|
+
MAXIMUM_MESSAGE_WIDTH
|
|
6251
|
+
)
|
|
6252
|
+
);
|
|
6253
|
+
console.log(wrapAnsi(text, width));
|
|
6254
|
+
}
|
|
6255
|
+
function showReadyMessage() {
|
|
6256
|
+
console.log();
|
|
6257
|
+
console.log(chalk3.bgGreen.black.bold(" \u2713 Zapier SDK setup complete "));
|
|
6258
|
+
console.log();
|
|
6259
|
+
printWrapped(
|
|
6260
|
+
"Use active Zapier connections to access 9,000+ app connectors without managing each app's OAuth, token refresh, or retries."
|
|
6261
|
+
);
|
|
6262
|
+
console.log();
|
|
6263
|
+
printWrapped(
|
|
6264
|
+
"To learn more about the Zapier SDK, visit https://docs.zapier.com/sdk"
|
|
6265
|
+
);
|
|
6266
|
+
console.log();
|
|
6267
|
+
}
|
|
6268
|
+
async function runWizard(context) {
|
|
6269
|
+
console.log(chalk3.bold("Zapier SDK setup"));
|
|
6270
|
+
showPhase({ number: 1, title: "Project directory" });
|
|
6271
|
+
await chooseDirectory(context);
|
|
6272
|
+
showPhase({ number: 2, title: "Node.js" });
|
|
6273
|
+
await ensureSupportedNode(context);
|
|
6274
|
+
showPhase({ number: 3, title: "Dependencies" });
|
|
6275
|
+
await prepareProject(context);
|
|
6276
|
+
await installOptionalSkill(context);
|
|
6277
|
+
showPhase({ number: 4, title: "Zapier account" });
|
|
6278
|
+
await authenticate(context);
|
|
6279
|
+
showPhase({ number: 5, title: "App connections" });
|
|
6280
|
+
await ensureConnectionsAvailable(context);
|
|
6281
|
+
showPhase({ number: 6, title: "Slack demo" });
|
|
6282
|
+
await offerSlackTest(context);
|
|
6283
|
+
showReadyMessage();
|
|
6284
|
+
console.log(chalk3.bgCyan.black.bold(" Next steps "));
|
|
6285
|
+
await openAgentHandoff(context);
|
|
6286
|
+
}
|
|
6287
|
+
|
|
6288
|
+
// src/plugins/setup/index.ts
|
|
6289
|
+
var getProfileRef = declareMethod({ id: "getProfile" });
|
|
6290
|
+
var listConnectionsRef2 = declareMethod({ id: "listConnections" });
|
|
6291
|
+
var loginRef = declareMethod({ id: "login" });
|
|
6292
|
+
var logoutRef = declareMethod({ id: "logout" });
|
|
6293
|
+
var signupRef = declareMethod({ id: "signup" });
|
|
6294
|
+
var setupImports = [
|
|
6295
|
+
getProfileRef,
|
|
6296
|
+
listConnectionsRef2,
|
|
6297
|
+
loginRef,
|
|
6298
|
+
logoutRef,
|
|
6299
|
+
signupRef
|
|
6300
|
+
];
|
|
6301
|
+
var setupPlugin = defineMethod({
|
|
6302
|
+
name: "setup",
|
|
6303
|
+
imports: setupImports,
|
|
6304
|
+
categories: ["utility"],
|
|
6305
|
+
supportsJsonOutput: false,
|
|
6306
|
+
inputSchema: SetupSchema,
|
|
6307
|
+
output: "raw",
|
|
6308
|
+
run: async ({ imports }) => {
|
|
6309
|
+
if (process.stdin.isTTY !== true || process.stdout.isTTY !== true) {
|
|
6310
|
+
throw new ZapierCliExitError(
|
|
6311
|
+
"`zapier-sdk setup` requires an interactive terminal."
|
|
6312
|
+
);
|
|
6313
|
+
}
|
|
6314
|
+
await runWizard(createWizardContext({ imports }));
|
|
4559
6315
|
}
|
|
4560
6316
|
});
|
|
4561
6317
|
|
|
@@ -4597,7 +6353,7 @@ ${chalk3.bold(`Message #${messageNumber}`)} ${chalk3.dim(message.id)} ${chalk3.d
|
|
|
4597
6353
|
while (true) {
|
|
4598
6354
|
let action;
|
|
4599
6355
|
try {
|
|
4600
|
-
const answer = await
|
|
6356
|
+
const answer = await inquirer3.prompt([
|
|
4601
6357
|
{
|
|
4602
6358
|
type: "list",
|
|
4603
6359
|
name: "action",
|
|
@@ -5064,7 +6820,7 @@ function collectDeprecationNoticeAndForward(event, onEvent) {
|
|
|
5064
6820
|
// package.json with { type: 'json' }
|
|
5065
6821
|
var package_default = {
|
|
5066
6822
|
name: "@zapier/zapier-sdk-cli",
|
|
5067
|
-
version: "0.
|
|
6823
|
+
version: "0.70.0"};
|
|
5068
6824
|
|
|
5069
6825
|
// src/sdk.ts
|
|
5070
6826
|
var warnedDeprecatedMethods = /* @__PURE__ */ new Set();
|
|
@@ -5104,6 +6860,7 @@ definePlugin({
|
|
|
5104
6860
|
mcpPlugin,
|
|
5105
6861
|
getLoginConfigPathPlugin,
|
|
5106
6862
|
initPlugin,
|
|
6863
|
+
setupPlugin,
|
|
5107
6864
|
bundleCodePlugin,
|
|
5108
6865
|
feedbackPlugin,
|
|
5109
6866
|
curlPlugin,
|
|
@@ -5142,6 +6899,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
5142
6899
|
mcpPlugin,
|
|
5143
6900
|
getLoginConfigPathPlugin,
|
|
5144
6901
|
initPlugin,
|
|
6902
|
+
setupPlugin,
|
|
5145
6903
|
bundleCodePlugin,
|
|
5146
6904
|
feedbackPlugin,
|
|
5147
6905
|
curlPlugin,
|
|
@@ -5150,7 +6908,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
5150
6908
|
generateAppTypesPlugin
|
|
5151
6909
|
]
|
|
5152
6910
|
});
|
|
5153
|
-
const sdk = createSdk(cliExperimentalSdkPlugin, {
|
|
6911
|
+
const sdk = createSdk$1(cliExperimentalSdkPlugin, {
|
|
5154
6912
|
configuration: {
|
|
5155
6913
|
[SDK_OPTIONS_ID]: stackOptions,
|
|
5156
6914
|
[CORE_OPTIONS_ID]: cliCoreOptions,
|