shop-cli 0.1.1 → 0.1.2
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/dist/cli/approvalRequired.d.ts +30 -0
- package/dist/cli/approvalRequired.js +87 -0
- package/dist/cli/errors.d.ts +4 -1
- package/dist/cli/errors.js +3 -1
- package/dist/cli/router.js +3 -0
- package/dist/cli/verbs/graphql.js +2 -0
- package/dist/cli.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { OutputFormat } from './output';
|
|
2
|
+
type ApprovalRequiredAction = Record<string, unknown> & {
|
|
3
|
+
type?: unknown;
|
|
4
|
+
status?: unknown;
|
|
5
|
+
id?: unknown;
|
|
6
|
+
executed?: unknown;
|
|
7
|
+
contentType?: unknown;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type ApprovalRequiredInfo = {
|
|
11
|
+
code: 'APPROVAL_REQUIRED' | 'ACTION_REQUIRED';
|
|
12
|
+
action: ApprovalRequiredAction;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Generic GraphQL proxy contract for deferred execution.
|
|
16
|
+
*
|
|
17
|
+
* When a proxy requires human approval before executing an operation, it may return a
|
|
18
|
+
* standard GraphQL response with an `errors[]` entry that includes:
|
|
19
|
+
* - `error.extensions.code === "APPROVAL_REQUIRED"` (also accepts "ACTION_REQUIRED")
|
|
20
|
+
* - `error.extensions.action` describing the approval workflow
|
|
21
|
+
*
|
|
22
|
+
* In this case, the operation has NOT executed yet. shop-cli surfaces a purpose-built
|
|
23
|
+
* error payload and exits with code 3.
|
|
24
|
+
*/
|
|
25
|
+
export declare const findApprovalRequired: (errors: unknown[] | undefined | null) => ApprovalRequiredInfo | undefined;
|
|
26
|
+
export declare const maybeThrowApprovalRequired: ({ format, errors, }: {
|
|
27
|
+
format: OutputFormat;
|
|
28
|
+
errors: unknown[] | undefined | null;
|
|
29
|
+
}) => void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var approvalRequired_exports = {};
|
|
20
|
+
__export(approvalRequired_exports, {
|
|
21
|
+
findApprovalRequired: () => findApprovalRequired,
|
|
22
|
+
maybeThrowApprovalRequired: () => maybeThrowApprovalRequired
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(approvalRequired_exports);
|
|
25
|
+
var import_output = require("./output");
|
|
26
|
+
var import_errors = require("./errors");
|
|
27
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28
|
+
const findApprovalRequired = (errors) => {
|
|
29
|
+
if (!Array.isArray(errors)) return void 0;
|
|
30
|
+
for (const err of errors) {
|
|
31
|
+
if (!isPlainObject(err)) continue;
|
|
32
|
+
const extensions = err.extensions;
|
|
33
|
+
if (!isPlainObject(extensions)) continue;
|
|
34
|
+
const code = extensions.code;
|
|
35
|
+
if (code !== "APPROVAL_REQUIRED" && code !== "ACTION_REQUIRED") continue;
|
|
36
|
+
const action = extensions.action;
|
|
37
|
+
if (!isPlainObject(action)) continue;
|
|
38
|
+
if (action.type !== "approval") continue;
|
|
39
|
+
if (action.status !== "pending") continue;
|
|
40
|
+
if (action.executed !== false) continue;
|
|
41
|
+
if (typeof action.id !== "string" || !action.id.trim()) continue;
|
|
42
|
+
if (typeof action.body !== "string" || !action.body.trim()) continue;
|
|
43
|
+
return { code, action };
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
};
|
|
47
|
+
const writeHumanApprovalMessage = ({ action }) => {
|
|
48
|
+
const id = String(action.id);
|
|
49
|
+
const body = typeof action.body === "string" ? action.body.trim() : "";
|
|
50
|
+
const lines = [
|
|
51
|
+
"Approval required: this operation was NOT executed yet.",
|
|
52
|
+
`Approval id: ${id}`,
|
|
53
|
+
"Execution will happen after approval is granted (out-of-band)."
|
|
54
|
+
];
|
|
55
|
+
if (body) {
|
|
56
|
+
lines.push("", body);
|
|
57
|
+
}
|
|
58
|
+
process.stderr.write(lines.join("\n").trimEnd() + "\n");
|
|
59
|
+
};
|
|
60
|
+
const maybeThrowApprovalRequired = ({
|
|
61
|
+
format,
|
|
62
|
+
errors
|
|
63
|
+
}) => {
|
|
64
|
+
const approval = findApprovalRequired(errors);
|
|
65
|
+
if (!approval) return;
|
|
66
|
+
if (format === "json" || format === "jsonl") {
|
|
67
|
+
(0, import_output.printJsonError)(
|
|
68
|
+
{
|
|
69
|
+
ok: false,
|
|
70
|
+
error: {
|
|
71
|
+
code: approval.code,
|
|
72
|
+
action: approval.action
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
format === "json"
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
writeHumanApprovalMessage(approval);
|
|
79
|
+
}
|
|
80
|
+
throw new import_errors.CliError("", 3, { silent: true });
|
|
81
|
+
};
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
findApprovalRequired,
|
|
85
|
+
maybeThrowApprovalRequired
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=approvalRequired.js.map
|
package/dist/cli/errors.d.ts
CHANGED
package/dist/cli/errors.js
CHANGED
|
@@ -23,9 +23,11 @@ __export(errors_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(errors_exports);
|
|
24
24
|
class CliError extends Error {
|
|
25
25
|
exitCode;
|
|
26
|
-
|
|
26
|
+
silent;
|
|
27
|
+
constructor(message, exitCode = 1, { silent = false } = {}) {
|
|
27
28
|
super(message);
|
|
28
29
|
this.exitCode = exitCode;
|
|
30
|
+
this.silent = silent;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cli/router.js
CHANGED
|
@@ -29,6 +29,7 @@ var import_admin_2026_04 = require("../generated/admin-2026-04");
|
|
|
29
29
|
var import_admin_2026_042 = require("../generated/admin-2026-04");
|
|
30
30
|
var import_errors = require("./errors");
|
|
31
31
|
var import_output = require("./output");
|
|
32
|
+
var import_approvalRequired = require("./approvalRequired");
|
|
32
33
|
var import_introspection = require("./introspection");
|
|
33
34
|
var import_format = require("./introspection/format");
|
|
34
35
|
var import_resources = require("./introspection/resources");
|
|
@@ -442,6 +443,7 @@ const runQuery = async (ctx, request) => {
|
|
|
442
443
|
return await ctx.client.query(request);
|
|
443
444
|
} catch (err) {
|
|
444
445
|
if (err instanceof import_admin_2026_042.GenqlError) {
|
|
446
|
+
(0, import_approvalRequired.maybeThrowApprovalRequired)({ format: ctx.format, errors: err.errors });
|
|
445
447
|
if (ctx.warnMissingAccessToken && hasNotAuthorizedError(err)) {
|
|
446
448
|
console.error("SHOPIFY_ACCESS_TOKEN not set");
|
|
447
449
|
}
|
|
@@ -461,6 +463,7 @@ const runMutation = async (ctx, request) => {
|
|
|
461
463
|
return await ctx.client.mutation(request);
|
|
462
464
|
} catch (err) {
|
|
463
465
|
if (err instanceof import_admin_2026_042.GenqlError) {
|
|
466
|
+
(0, import_approvalRequired.maybeThrowApprovalRequired)({ format: ctx.format, errors: err.errors });
|
|
464
467
|
if (ctx.warnMissingAccessToken && hasNotAuthorizedError(err)) {
|
|
465
468
|
console.error("SHOPIFY_ACCESS_TOKEN not set");
|
|
466
469
|
}
|
|
@@ -26,6 +26,7 @@ var import_node_fs = require("node:fs");
|
|
|
26
26
|
var import_errors = require("../errors");
|
|
27
27
|
var import_output = require("../output");
|
|
28
28
|
var import_router = require("../router");
|
|
29
|
+
var import_approvalRequired = require("../approvalRequired");
|
|
29
30
|
var import_adminClient = require("../../adminClient");
|
|
30
31
|
var import_graphqlValidator = require("../../graphqlValidator");
|
|
31
32
|
const printHelp = () => {
|
|
@@ -272,6 +273,7 @@ const runGraphQL = async ({
|
|
|
272
273
|
throw new import_errors.CliError(`GraphQL request failed: ${err.message}`, 1);
|
|
273
274
|
}
|
|
274
275
|
if (response.errors && response.errors.length > 0) {
|
|
276
|
+
(0, import_approvalRequired.maybeThrowApprovalRequired)({ format: ctx.format, errors: response.errors });
|
|
275
277
|
(0, import_output.printJsonError)({ errors: response.errors, data: response.data }, ctx.format !== "raw");
|
|
276
278
|
throw new import_errors.CliError("GraphQL request returned errors", 1);
|
|
277
279
|
}
|
package/dist/cli.js
CHANGED
|
@@ -224,12 +224,12 @@ Missing <verb> for "${resource}"`, 2);
|
|
|
224
224
|
See help:
|
|
225
225
|
${command} ${resource} ${verb} --help`;
|
|
226
226
|
}
|
|
227
|
-
throw new import_errors.CliError(message, err.exitCode);
|
|
227
|
+
throw new import_errors.CliError(message, err.exitCode, { silent: err.silent });
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
230
|
main().catch((err) => {
|
|
231
231
|
if (err instanceof import_errors.CliError) {
|
|
232
|
-
console.error(err.message);
|
|
232
|
+
if (!err.silent) console.error(err.message);
|
|
233
233
|
process.exit(err.exitCode);
|
|
234
234
|
}
|
|
235
235
|
console.error(err);
|