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