@01.software/cli 0.17.4 → 0.18.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/dist/index.js +1329 -229
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import {
|
|
4
|
+
import { realpathSync } from "fs";
|
|
5
|
+
import { createRequire as createRequire2 } from "module";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
5
7
|
import { Command } from "commander";
|
|
6
8
|
|
|
7
9
|
// src/lib/client.ts
|
|
@@ -11,6 +13,373 @@ import {
|
|
|
11
13
|
TenantIntrospectionApi
|
|
12
14
|
} from "@01.software/sdk/server";
|
|
13
15
|
|
|
16
|
+
// ../../internal/http-contracts/src/index.ts
|
|
17
|
+
var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
|
|
18
|
+
var operation = (collection, method, path2, errorFamily) => Object.freeze({
|
|
19
|
+
[operationBrand]: true,
|
|
20
|
+
collection,
|
|
21
|
+
method,
|
|
22
|
+
path: path2,
|
|
23
|
+
...errorFamily && { errorFamily }
|
|
24
|
+
});
|
|
25
|
+
var strictCommerceOperation = (collection, method, path2) => operation(collection, method, path2, "commerce");
|
|
26
|
+
var selectiveCommerceOperation = (collection, method, path2, typedCommerceErrorReasons) => Object.freeze({
|
|
27
|
+
...operation(collection, method, path2),
|
|
28
|
+
typedCommerceErrorReasons: Object.freeze([...typedCommerceErrorReasons])
|
|
29
|
+
});
|
|
30
|
+
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
31
|
+
products: {
|
|
32
|
+
detail: operation("products", "get", "/detail"),
|
|
33
|
+
detailCatalog: operation("products", "get", "/detail/catalog"),
|
|
34
|
+
listingGroups: operation("products", "get", "/listing-groups"),
|
|
35
|
+
listingGroupsCatalog: operation(
|
|
36
|
+
"products",
|
|
37
|
+
"get",
|
|
38
|
+
"/listing-groups/catalog"
|
|
39
|
+
),
|
|
40
|
+
listingGroupsQuery: operation("products", "post", "/listing-groups/query"),
|
|
41
|
+
listingGroupsQueryGet: operation(
|
|
42
|
+
"products",
|
|
43
|
+
"get",
|
|
44
|
+
"/listing-groups/query"
|
|
45
|
+
),
|
|
46
|
+
listingGroupsQueryCatalog: operation(
|
|
47
|
+
"products",
|
|
48
|
+
"get",
|
|
49
|
+
"/listing-groups/query/catalog"
|
|
50
|
+
),
|
|
51
|
+
stockCheck: operation("products", "post", "/stock-check"),
|
|
52
|
+
stockSnapshot: operation("products", "get", "/stock"),
|
|
53
|
+
upsert: operation("products", "post", "/upsert")
|
|
54
|
+
},
|
|
55
|
+
orders: {
|
|
56
|
+
create: operation("orders", "post", "/create"),
|
|
57
|
+
update: operation("orders", "post", "/update"),
|
|
58
|
+
confirmPayment: operation("orders", "post", "/confirm-payment"),
|
|
59
|
+
byPayment: operation("orders", "get", "/by-payment"),
|
|
60
|
+
cancel: operation("orders", "post", "/cancel"),
|
|
61
|
+
resolveCancelRefund: selectiveCommerceOperation(
|
|
62
|
+
"orders",
|
|
63
|
+
"post",
|
|
64
|
+
"/resolve-cancel-refund",
|
|
65
|
+
["managed_refund_attestation_forbidden"]
|
|
66
|
+
),
|
|
67
|
+
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
68
|
+
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
69
|
+
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
70
|
+
},
|
|
71
|
+
checkouts: {
|
|
72
|
+
detail: strictCommerceOperation("checkouts", "post", "/detail"),
|
|
73
|
+
query: strictCommerceOperation("checkouts", "post", "/query")
|
|
74
|
+
},
|
|
75
|
+
transactions: {
|
|
76
|
+
update: operation("transactions", "post", "/update")
|
|
77
|
+
},
|
|
78
|
+
returns: {
|
|
79
|
+
create: operation("returns", "post", "/create"),
|
|
80
|
+
update: operation("returns", "post", "/update"),
|
|
81
|
+
returnRefund: operation("returns", "post", "/return-refund")
|
|
82
|
+
},
|
|
83
|
+
fulfillmentOrders: {
|
|
84
|
+
prepare: operation(
|
|
85
|
+
"fulfillment-orders",
|
|
86
|
+
"post",
|
|
87
|
+
"/prepare-fulfillment-order"
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
fulfillments: {
|
|
91
|
+
bulkImport: operation("fulfillments", "post", "/bulk-import")
|
|
92
|
+
},
|
|
93
|
+
carts: {
|
|
94
|
+
create: strictCommerceOperation("carts", "post", "/create"),
|
|
95
|
+
retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
|
|
96
|
+
mine: strictCommerceOperation("carts", "post", "/mine"),
|
|
97
|
+
merge: strictCommerceOperation("carts", "post", "/merge"),
|
|
98
|
+
addItem: strictCommerceOperation("carts", "post", "/add-item"),
|
|
99
|
+
updateItem: strictCommerceOperation("carts", "post", "/update-item"),
|
|
100
|
+
removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
|
|
101
|
+
updateDiscountCodes: strictCommerceOperation(
|
|
102
|
+
"carts",
|
|
103
|
+
"post",
|
|
104
|
+
"/update-discount-codes"
|
|
105
|
+
),
|
|
106
|
+
updateAttributes: strictCommerceOperation(
|
|
107
|
+
"carts",
|
|
108
|
+
"post",
|
|
109
|
+
"/update-attributes"
|
|
110
|
+
),
|
|
111
|
+
clear: strictCommerceOperation("carts", "post", "/clear")
|
|
112
|
+
},
|
|
113
|
+
paymentSessions: {
|
|
114
|
+
create: strictCommerceOperation("payment-sessions", "post", "/create"),
|
|
115
|
+
retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
|
|
116
|
+
cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
|
|
117
|
+
server: {
|
|
118
|
+
create: strictCommerceOperation(
|
|
119
|
+
"payment-sessions",
|
|
120
|
+
"post",
|
|
121
|
+
"/server/create"
|
|
122
|
+
),
|
|
123
|
+
retrieve: strictCommerceOperation(
|
|
124
|
+
"payment-sessions",
|
|
125
|
+
"post",
|
|
126
|
+
"/server/retrieve"
|
|
127
|
+
),
|
|
128
|
+
cancel: strictCommerceOperation(
|
|
129
|
+
"payment-sessions",
|
|
130
|
+
"post",
|
|
131
|
+
"/server/cancel"
|
|
132
|
+
),
|
|
133
|
+
confirm: strictCommerceOperation(
|
|
134
|
+
"payment-sessions",
|
|
135
|
+
"post",
|
|
136
|
+
"/server/confirm"
|
|
137
|
+
),
|
|
138
|
+
findPortOne: strictCommerceOperation(
|
|
139
|
+
"payment-sessions",
|
|
140
|
+
"post",
|
|
141
|
+
"/server/portone/find"
|
|
142
|
+
),
|
|
143
|
+
reconcilePortOne: strictCommerceOperation(
|
|
144
|
+
"payment-sessions",
|
|
145
|
+
"post",
|
|
146
|
+
"/server/portone/reconcile"
|
|
147
|
+
)
|
|
148
|
+
},
|
|
149
|
+
custom: {
|
|
150
|
+
create: operation("orders", "post", "/custom-payment-sessions"),
|
|
151
|
+
retrieve: operation(
|
|
152
|
+
"orders",
|
|
153
|
+
"post",
|
|
154
|
+
"/custom-payment-sessions/retrieve"
|
|
155
|
+
),
|
|
156
|
+
confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
shippingPolicies: {
|
|
160
|
+
calculate: operation("shipping-policies", "post", "/calculate")
|
|
161
|
+
},
|
|
162
|
+
discounts: {
|
|
163
|
+
validate: operation("discounts", "post", "/validate")
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var portOneStandardActionCapabilityOperations = /* @__PURE__ */ new Set([
|
|
167
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create,
|
|
168
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve,
|
|
169
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create,
|
|
170
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
171
|
+
]);
|
|
172
|
+
var MEMBERSHIP_ENDPOINT_OPERATIONS = {
|
|
173
|
+
subscribe: operation(null, "post", "/memberships/subscribe"),
|
|
174
|
+
cancel: operation(null, "post", "/memberships/:id/cancel"),
|
|
175
|
+
me: operation(null, "get", "/memberships/me")
|
|
176
|
+
};
|
|
177
|
+
var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
|
|
178
|
+
show: operation("tenants", "get", "/embedded-admin-app"),
|
|
179
|
+
configure: operation("tenants", "patch", "/embedded-admin-app"),
|
|
180
|
+
disable: operation("tenants", "delete", "/embedded-admin-app")
|
|
181
|
+
};
|
|
182
|
+
var EVENTS_ENDPOINT_OPERATIONS = {
|
|
183
|
+
events: {
|
|
184
|
+
convertSchedule: operation("events", "post", "/:id/schedule")
|
|
185
|
+
},
|
|
186
|
+
occurrences: {
|
|
187
|
+
range: operation("event-occurrences", "get", "/range"),
|
|
188
|
+
admissionAvailability: operation(
|
|
189
|
+
"event-occurrences",
|
|
190
|
+
"get",
|
|
191
|
+
"/admission-availability"
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var COMMUNITY_ENDPOINT_OPERATIONS = {
|
|
196
|
+
posts: {
|
|
197
|
+
detail: operation("posts", "get", "/detail")
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
function resolveOperationTemplate(descriptor) {
|
|
201
|
+
return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
|
|
202
|
+
}
|
|
203
|
+
function resolveOperationPath(descriptor, options) {
|
|
204
|
+
const path2 = resolveOperationTemplate(descriptor).replace(
|
|
205
|
+
/:([A-Za-z][A-Za-z0-9_]*)/g,
|
|
206
|
+
(_, key) => {
|
|
207
|
+
const value = options?.pathParams?.[key];
|
|
208
|
+
if (value === void 0) {
|
|
209
|
+
throw new TypeError(`Missing path parameter: ${key}`);
|
|
210
|
+
}
|
|
211
|
+
return encodeURIComponent(value);
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
const unresolved = path2.match(/:([A-Za-z][A-Za-z0-9_]*)/);
|
|
215
|
+
if (unresolved) {
|
|
216
|
+
throw new TypeError(`Missing path parameter: ${unresolved[1]}`);
|
|
217
|
+
}
|
|
218
|
+
const query = options?.query?.toString().replace(/^\?/, "");
|
|
219
|
+
return query ? `${path2}?${query}` : path2;
|
|
220
|
+
}
|
|
221
|
+
function resolveOperationMethod(descriptor) {
|
|
222
|
+
return descriptor.method.toUpperCase();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/lib/embedded-admin-management.ts
|
|
226
|
+
import {
|
|
227
|
+
normalizeEmbeddedAdminBindingConfiguration
|
|
228
|
+
} from "@01.software/sdk/embedded-admin";
|
|
229
|
+
var REQUEST_TIMEOUT_MS = 3e4;
|
|
230
|
+
var EmbeddedAdminManagementError = class extends Error {
|
|
231
|
+
constructor(message, status, options = {}) {
|
|
232
|
+
super(message);
|
|
233
|
+
this.name = "EmbeddedAdminManagementError";
|
|
234
|
+
this.status = status;
|
|
235
|
+
this.reason = options.reason;
|
|
236
|
+
this.requestId = options.requestId;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
function resolveApiUrl(explicit) {
|
|
240
|
+
const buildDefault = true ? "https://api.01.software" : "https://api.01.software";
|
|
241
|
+
return (explicit ?? process.env.SOFTWARE_API_URL ?? process.env.NEXT_PUBLIC_SOFTWARE_API_URL ?? buildDefault).replace(/\/$/, "");
|
|
242
|
+
}
|
|
243
|
+
function inferConsoleOrigin(apiUrl) {
|
|
244
|
+
const url = new URL(apiUrl);
|
|
245
|
+
if (url.hostname === "api.01.software") {
|
|
246
|
+
return {
|
|
247
|
+
allowLoopbackConsoleHttp: false,
|
|
248
|
+
consoleOrigin: "https://console.01.software"
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (url.hostname === "api.stg.01.software") {
|
|
252
|
+
return {
|
|
253
|
+
allowLoopbackConsoleHttp: false,
|
|
254
|
+
consoleOrigin: "https://console.stg.01.software"
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
258
|
+
return {
|
|
259
|
+
allowLoopbackConsoleHttp: loopback && url.protocol === "http:",
|
|
260
|
+
...loopback ? { consoleOrigin: url.origin } : {}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function parseBindingState(value) {
|
|
264
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
265
|
+
throw new Error("Embedded admin binding response is invalid.");
|
|
266
|
+
}
|
|
267
|
+
const input = value;
|
|
268
|
+
if (typeof input.tenantId !== "string" || input.tenantId.length === 0 || typeof input.tenantName !== "string" || input.status !== "unconfigured" && input.status !== "disabled" && input.status !== "enabled" && input.status !== "invalid") {
|
|
269
|
+
throw new Error("Embedded admin binding response is invalid.");
|
|
270
|
+
}
|
|
271
|
+
if (input.status === "unconfigured" || input.status === "invalid") {
|
|
272
|
+
if (input.binding !== null) {
|
|
273
|
+
throw new Error("Embedded admin binding response is invalid.");
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
binding: null,
|
|
277
|
+
status: input.status,
|
|
278
|
+
tenantId: input.tenantId,
|
|
279
|
+
tenantName: input.tenantName
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const binding = normalizeEmbeddedAdminBindingConfiguration(input.binding);
|
|
283
|
+
if (binding.enabled !== (input.status === "enabled")) {
|
|
284
|
+
throw new Error("Embedded admin binding response is invalid.");
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
binding,
|
|
288
|
+
status: input.status,
|
|
289
|
+
tenantId: input.tenantId,
|
|
290
|
+
tenantName: input.tenantName
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
var EmbeddedAdminManagementClient = class {
|
|
294
|
+
constructor(options) {
|
|
295
|
+
this.apiUrl = resolveApiUrl(options.apiUrl);
|
|
296
|
+
this.fetchImplementation = options.fetch ?? globalThis.fetch;
|
|
297
|
+
this.publishableKey = options.publishableKey;
|
|
298
|
+
this.secretKey = options.secretKey;
|
|
299
|
+
}
|
|
300
|
+
validateConfiguration(input) {
|
|
301
|
+
this.validateManagementAccess();
|
|
302
|
+
const console2 = inferConsoleOrigin(this.apiUrl);
|
|
303
|
+
return normalizeEmbeddedAdminBindingConfiguration(
|
|
304
|
+
{ ...input, enabled: true, path: input.path ?? "/" },
|
|
305
|
+
console2
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
show() {
|
|
309
|
+
this.validateManagementAccess();
|
|
310
|
+
return this.request(EMBEDDED_ADMIN_ENDPOINT_OPERATIONS.show);
|
|
311
|
+
}
|
|
312
|
+
configure(input) {
|
|
313
|
+
const binding = this.validateConfiguration(input);
|
|
314
|
+
return this.request(EMBEDDED_ADMIN_ENDPOINT_OPERATIONS.configure, {
|
|
315
|
+
label: binding.label,
|
|
316
|
+
origin: binding.origin,
|
|
317
|
+
path: binding.path
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
disable() {
|
|
321
|
+
this.validateManagementAccess();
|
|
322
|
+
return this.request(EMBEDDED_ADMIN_ENDPOINT_OPERATIONS.disable);
|
|
323
|
+
}
|
|
324
|
+
validateManagementAccess() {
|
|
325
|
+
if (!this.secretKey.startsWith("pat01_")) {
|
|
326
|
+
const error = new Error(
|
|
327
|
+
"Embedded admin binding management requires a user PAT (pat01_...)."
|
|
328
|
+
);
|
|
329
|
+
error.name = "ConfigError";
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
async request(operation2, body) {
|
|
334
|
+
const controller = new AbortController();
|
|
335
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
336
|
+
let response;
|
|
337
|
+
try {
|
|
338
|
+
response = await this.fetchImplementation(
|
|
339
|
+
new URL(resolveOperationPath(operation2), `${this.apiUrl}/`),
|
|
340
|
+
{
|
|
341
|
+
method: resolveOperationMethod(operation2),
|
|
342
|
+
headers: {
|
|
343
|
+
Accept: "application/json",
|
|
344
|
+
Authorization: `Bearer ${this.secretKey}`,
|
|
345
|
+
"Content-Type": "application/json",
|
|
346
|
+
"X-Publishable-Key": this.publishableKey
|
|
347
|
+
},
|
|
348
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
349
|
+
signal: controller.signal
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
} catch (cause) {
|
|
353
|
+
const error = new Error(
|
|
354
|
+
"Embedded admin binding request failed."
|
|
355
|
+
);
|
|
356
|
+
error.cause = cause;
|
|
357
|
+
error.name = "NetworkError";
|
|
358
|
+
throw error;
|
|
359
|
+
} finally {
|
|
360
|
+
clearTimeout(timer);
|
|
361
|
+
}
|
|
362
|
+
let payload;
|
|
363
|
+
try {
|
|
364
|
+
payload = await response.json();
|
|
365
|
+
} catch {
|
|
366
|
+
payload = null;
|
|
367
|
+
}
|
|
368
|
+
if (!response.ok) {
|
|
369
|
+
const record = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
370
|
+
throw new EmbeddedAdminManagementError(
|
|
371
|
+
typeof record.error === "string" ? record.error : `Embedded admin binding request failed (${response.status}).`,
|
|
372
|
+
response.status,
|
|
373
|
+
{
|
|
374
|
+
...typeof record.reason === "string" ? { reason: record.reason } : {},
|
|
375
|
+
...response.headers.get("x-request-id") ? { requestId: response.headers.get("x-request-id") } : {}
|
|
376
|
+
}
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
return parseBindingState(payload);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
14
383
|
// src/lib/credentials.ts
|
|
15
384
|
import {
|
|
16
385
|
chmodSync,
|
|
@@ -573,7 +942,10 @@ function adminErrorExitCode(err) {
|
|
|
573
942
|
}
|
|
574
943
|
|
|
575
944
|
// src/lib/i18n.ts
|
|
576
|
-
|
|
945
|
+
function withDoctorActionTranslations(translations) {
|
|
946
|
+
return translations;
|
|
947
|
+
}
|
|
948
|
+
var CLI_I18N_KO = withDoctorActionTranslations({
|
|
577
949
|
// CLI-surface microcopy
|
|
578
950
|
AuthenticationRequired: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4",
|
|
579
951
|
RunLoginToAuthenticate: "`01 login` \uBA85\uB839\uC73C\uB85C \uBE0C\uB77C\uC6B0\uC800 \uC778\uC99D\uC744 \uC9C4\uD589\uD558\uAC70\uB098,",
|
|
@@ -587,6 +959,26 @@ var CLI_I18N_KO = {
|
|
|
587
959
|
Empty: "(\uC5C6\uC74C)",
|
|
588
960
|
Total: "\uCD1D {{n}}\uAC1C",
|
|
589
961
|
PageOf: "{{page}} / {{total}} \uD398\uC774\uC9C0",
|
|
962
|
+
// Redacted app-integration doctor remediation keys. These are stable
|
|
963
|
+
// machine references; the human CLI renders this locale-specific copy.
|
|
964
|
+
DoctorProjectPackageJsonReady: "package.json\uC744 \uC77D\uC744 \uC218 \uC788\uC2B5\uB2C8\uB2E4.",
|
|
965
|
+
DoctorProjectPackageJsonBlocked: "package.json\uC774 \uC788\uB294 \uC571 \uB514\uB809\uD130\uB9AC\uC5D0\uC11C \uC2E4\uD589\uD558\uC138\uC694.",
|
|
966
|
+
DoctorNodeEngineReady: "\uD604\uC7AC Node.js\uAC00 \uC120\uC5B8\uB41C engine\uC744 \uCDA9\uC871\uD569\uB2C8\uB2E4.",
|
|
967
|
+
DoctorNodeEngineAttention: "package.json\uC758 Node.js engine\uACFC \uD604\uC7AC \uBC84\uC804\uC744 \uD655\uC778\uD558\uC138\uC694.",
|
|
968
|
+
DoctorNodeEngineNotDeclared: "package.json\uC5D0 \uC9C0\uC6D0\uD558\uB294 Node.js engine \uBC94\uC704\uB97C \uC120\uC5B8\uD558\uC138\uC694.",
|
|
969
|
+
DoctorSdkDeclarationReady: "@01.software/sdk\uAC00 package.json\uC5D0 \uC120\uC5B8\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4.",
|
|
970
|
+
DoctorSdkDeclarationBlocked: "package.json\uC5D0 @01.software/sdk\uB97C \uCD94\uAC00\uD558\uC138\uC694.",
|
|
971
|
+
DoctorSdkInstallationReady: "@01.software/sdk\uC758 server export\uB97C \uD655\uC778\uD588\uC2B5\uB2C8\uB2E4.",
|
|
972
|
+
DoctorSdkInstallationAttention: "\uC571\uC744 \uC2E4\uD589\uD558\uAE30 \uC804\uC5D0 \uC120\uC5B8\uB41C \uC758\uC874\uC131\uC744 \uC124\uCE58\uD558\uC138\uC694.",
|
|
973
|
+
DoctorEnvCredentialsReady: "\uC571 \uC790\uACA9\uC99D\uBA85 \uD615\uC2DD\uACFC API \uB300\uC0C1\uC774 \uC62C\uBC14\uB985\uB2C8\uB2E4.",
|
|
974
|
+
DoctorEnvCredentialsBlocked: "\uD558\uB098\uC758 pk01_/sk01_ \uC571 \uC30D\uC744 \uC0AC\uC6A9\uD558\uACE0 \uACF5\uAC1C \uD658\uACBD \uBCC0\uC218\uB098 PAT\uC5D0 secret\uC744 \uB123\uC9C0 \uB9C8\uC138\uC694.",
|
|
975
|
+
DoctorEnvFileInvalid: "\uC77C\uBC18 \uD30C\uC77C\uC778 \uC571 \uD658\uACBD \uD30C\uC77C\uC744 \uC9C0\uC815\uD558\uACE0 symlink\xB7\uD2B9\uC218 \uD30C\uC77C\uC744 \uC81C\uAC70\uD558\uC138\uC694.",
|
|
976
|
+
DoctorOriginInputInvalid: "\uC808\uB300 http(s) origin URL\uC744 \uC9C0\uC815\uD558\uC138\uC694.",
|
|
977
|
+
DoctorTenantContextReady: "\uC571 \uC790\uACA9\uC99D\uBA85\uC73C\uB85C \uD14C\uB10C\uD2B8 \uCEE8\uD14D\uC2A4\uD2B8\uC5D0 \uC5F0\uACB0\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.",
|
|
978
|
+
DoctorTenantContextBlocked: "\uC571 \uC790\uACA9\uC99D\uBA85, \uD14C\uB10C\uD2B8 \uC811\uADFC \uAD8C\uD55C \uBC0F API \uC5F0\uACB0\uC744 \uD655\uC778\uD558\uC138\uC694.",
|
|
979
|
+
DoctorOriginCorsReady: "API CORS \uC815\uCC45\uC5D0\uC11C origin\uC774 \uD5C8\uC6A9\uB429\uB2C8\uB2E4.",
|
|
980
|
+
DoctorOriginCorsBlocked: "\uC774 origin\uC744 \uD14C\uB10C\uD2B8 CORS \uC815\uCC45\uC5D0 \uCD94\uAC00\uD558\uC138\uC694.",
|
|
981
|
+
DoctorOriginCorsAttention: "API URL \uBC0F CORS \uC815\uCC45\uC744 \uD655\uC778\uD558\uC138\uC694.",
|
|
590
982
|
// AdminError code translations (mirrors apps/console admin.ts).
|
|
591
983
|
tenant_mismatch: "\uAD8C\uD55C\uC774 \uC5C6\uB294 \uD14C\uB10C\uD2B8",
|
|
592
984
|
account_suspended: "\uACC4\uC815\uC774 \uC815\uC9C0\uB418\uC5C8\uC2B5\uB2C8\uB2E4",
|
|
@@ -605,7 +997,7 @@ var CLI_I18N_KO = {
|
|
|
605
997
|
not_found: "\uB9AC\uC18C\uC2A4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",
|
|
606
998
|
invalid_argument: "\uC778\uC790\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
|
|
607
999
|
unknown: "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"
|
|
608
|
-
};
|
|
1000
|
+
});
|
|
609
1001
|
var CLI_I18N_EN = {
|
|
610
1002
|
AuthenticationRequired: "Authentication required",
|
|
611
1003
|
RunLoginToAuthenticate: "Run `01 login` to authenticate via browser, or",
|
|
@@ -619,6 +1011,24 @@ var CLI_I18N_EN = {
|
|
|
619
1011
|
Empty: "(empty)",
|
|
620
1012
|
Total: "{{n}} total",
|
|
621
1013
|
PageOf: "page {{page}}/{{total}}",
|
|
1014
|
+
DoctorProjectPackageJsonReady: "package.json is readable.",
|
|
1015
|
+
DoctorProjectPackageJsonBlocked: "Run this command in an app directory with package.json.",
|
|
1016
|
+
DoctorNodeEngineReady: "Current Node.js satisfies the declared engine.",
|
|
1017
|
+
DoctorNodeEngineAttention: "Check the package.json Node.js engine and current version.",
|
|
1018
|
+
DoctorNodeEngineNotDeclared: "Declare a supported Node.js engine range in package.json.",
|
|
1019
|
+
DoctorSdkDeclarationReady: "@01.software/sdk is declared in package.json.",
|
|
1020
|
+
DoctorSdkDeclarationBlocked: "Add @01.software/sdk to package.json.",
|
|
1021
|
+
DoctorSdkInstallationReady: "@01.software/sdk server export is installed and resolvable.",
|
|
1022
|
+
DoctorSdkInstallationAttention: "Install declared dependencies before running the app.",
|
|
1023
|
+
DoctorEnvCredentialsReady: "App credentials and the API target are structurally valid.",
|
|
1024
|
+
DoctorEnvCredentialsBlocked: "Use one pk01_/sk01_ app pair; never put a secret in a public env variable or use a PAT.",
|
|
1025
|
+
DoctorEnvFileInvalid: "Use a regular app env file and remove symlinks or special files.",
|
|
1026
|
+
DoctorOriginInputInvalid: "Use an absolute http(s) origin URL.",
|
|
1027
|
+
DoctorTenantContextReady: "Tenant context is reachable with the app credential pair.",
|
|
1028
|
+
DoctorTenantContextBlocked: "Check app credentials, tenant access, and API reachability.",
|
|
1029
|
+
DoctorOriginCorsReady: "Origin is allowed by the API CORS policy.",
|
|
1030
|
+
DoctorOriginCorsBlocked: "Add this origin to the tenant CORS policy.",
|
|
1031
|
+
DoctorOriginCorsAttention: "Check the API URL and CORS policy.",
|
|
622
1032
|
tenant_mismatch: "Tenant access denied",
|
|
623
1033
|
account_suspended: "Your account has been suspended",
|
|
624
1034
|
feature_disabled: "This feature is disabled",
|
|
@@ -749,7 +1159,7 @@ function printError(error, options = {}) {
|
|
|
749
1159
|
const rawMessage = rawErr && typeof rawErr.message === "string" ? rawErr.message : "";
|
|
750
1160
|
const stringErr = typeof error === "string" ? error : "";
|
|
751
1161
|
const detailMessage = rawErr && rawErr.detail && typeof rawErr.detail === "object" && typeof rawErr.detail.message === "string" ? String(rawErr.detail.message) : "";
|
|
752
|
-
const headline = rawMessage || stringErr || detailMessage || localized || adminError.code;
|
|
1162
|
+
const headline = (options.headlineKey ? t(options.headlineKey) : null) || rawMessage || stringErr || detailMessage || localized || adminError.code;
|
|
753
1163
|
console.error(pc.red(`Error: ${headline}`));
|
|
754
1164
|
if (rawErr && typeof rawErr.code === "string" && rawErr.code !== adminError.code) {
|
|
755
1165
|
console.error(pc.dim(`Code: ${rawErr.code}`));
|
|
@@ -830,6 +1240,7 @@ function resolveClientOrThrow(apiKeyFlag) {
|
|
|
830
1240
|
),
|
|
831
1241
|
commerce: new ServerCommerceClient(serverOptions),
|
|
832
1242
|
tenant: new TenantIntrospectionApi(serverOptions),
|
|
1243
|
+
embeddedAdmin: new EmbeddedAdminManagementClient(serverOptions),
|
|
833
1244
|
publishableKey,
|
|
834
1245
|
secretKey
|
|
835
1246
|
};
|
|
@@ -929,15 +1340,15 @@ function readFileAsBlob(filePath) {
|
|
|
929
1340
|
const buffer = readFileSync2(filePath);
|
|
930
1341
|
return { blob: new Blob([buffer]), filename: basename(filePath) };
|
|
931
1342
|
}
|
|
932
|
-
function registerCrudCommands(
|
|
933
|
-
|
|
1343
|
+
function registerCrudCommands(program, getClient, getFormat) {
|
|
1344
|
+
program.command("query <collection>").description("Query documents from a collection").option("--where <json>", "Filter conditions (JSON)").option("--limit <n>", "Max results", (v) => parseInt(v, 10)).option("--page <n>", "Page number", (v) => parseInt(v, 10)).option("--sort <field>", "Sort field (prefix with - for descending)").option(
|
|
934
1345
|
"--depth <n>",
|
|
935
1346
|
"Relationship depth (0 = no population)",
|
|
936
1347
|
(v) => parseInt(v, 10)
|
|
937
1348
|
).option("--select <fields>", "Comma-separated fields to select").action(async (collection, opts) => {
|
|
938
1349
|
try {
|
|
939
1350
|
const col = validateCollection(collection);
|
|
940
|
-
const client =
|
|
1351
|
+
const client = getClient();
|
|
941
1352
|
const options = {};
|
|
942
1353
|
if (opts.where) options.where = parseJson(opts.where, "where");
|
|
943
1354
|
if (opts.limit) options.limit = opts.limit;
|
|
@@ -946,29 +1357,29 @@ function registerCrudCommands(program2, getClient2, getFormat2) {
|
|
|
946
1357
|
if (opts.depth != null) options.depth = opts.depth;
|
|
947
1358
|
if (opts.select) options.select = parseSelect(opts.select);
|
|
948
1359
|
const result = await client.collections.from(col).find(options);
|
|
949
|
-
printResult(result,
|
|
1360
|
+
printResult(result, getFormat());
|
|
950
1361
|
} catch (e) {
|
|
951
1362
|
exitWithError(e);
|
|
952
1363
|
}
|
|
953
1364
|
});
|
|
954
|
-
|
|
1365
|
+
program.command("get <collection> <id>").description("Get a document by ID").option(
|
|
955
1366
|
"--depth <n>",
|
|
956
1367
|
"Relationship depth (0 = no population)",
|
|
957
1368
|
(v) => parseInt(v, 10)
|
|
958
1369
|
).option("--select <fields>", "Comma-separated fields to select").action(async (collection, id, opts) => {
|
|
959
1370
|
try {
|
|
960
1371
|
const col = validateCollection(collection);
|
|
961
|
-
const client =
|
|
1372
|
+
const client = getClient();
|
|
962
1373
|
const options = {};
|
|
963
1374
|
if (opts.depth != null) options.depth = opts.depth;
|
|
964
1375
|
if (opts.select) options.select = parseSelect(opts.select);
|
|
965
1376
|
const result = await client.collections.from(col).findById(id, options);
|
|
966
|
-
printResult(result,
|
|
1377
|
+
printResult(result, getFormat());
|
|
967
1378
|
} catch (e) {
|
|
968
1379
|
exitWithError(e);
|
|
969
1380
|
}
|
|
970
1381
|
});
|
|
971
|
-
|
|
1382
|
+
program.command("create <collection>").description("Create a new document").requiredOption("--data <json>", "Document data (JSON)").option("--file <path>", "File to upload (for upload collections)").option("--dry-run", "Validate inputs without executing").action(async (collection, opts) => {
|
|
972
1383
|
try {
|
|
973
1384
|
const col = validateCollection(collection);
|
|
974
1385
|
const data = parseJson(opts.data, "data");
|
|
@@ -981,23 +1392,23 @@ function registerCrudCommands(program2, getClient2, getFormat2) {
|
|
|
981
1392
|
collection: col,
|
|
982
1393
|
data
|
|
983
1394
|
},
|
|
984
|
-
|
|
1395
|
+
getFormat()
|
|
985
1396
|
);
|
|
986
1397
|
return;
|
|
987
1398
|
}
|
|
988
|
-
const client =
|
|
1399
|
+
const client = getClient();
|
|
989
1400
|
let fileOpts;
|
|
990
1401
|
if (opts.file) {
|
|
991
1402
|
const { blob, filename } = readFileAsBlob(opts.file);
|
|
992
1403
|
fileOpts = { file: blob, filename };
|
|
993
1404
|
}
|
|
994
1405
|
const result = await client.collections.from(col).create(data, fileOpts);
|
|
995
|
-
printResult(result,
|
|
1406
|
+
printResult(result, getFormat());
|
|
996
1407
|
} catch (e) {
|
|
997
1408
|
exitWithError(e);
|
|
998
1409
|
}
|
|
999
1410
|
});
|
|
1000
|
-
|
|
1411
|
+
program.command("update <collection> <id>").description("Update a document by ID").requiredOption("--data <json>", "Document data (JSON)").option("--file <path>", "File to upload (for upload collections)").option("--dry-run", "Validate inputs without executing").action(async (collection, id, opts) => {
|
|
1001
1412
|
try {
|
|
1002
1413
|
const col = validateCollection(collection);
|
|
1003
1414
|
const data = parseJson(opts.data, "data");
|
|
@@ -1011,23 +1422,23 @@ function registerCrudCommands(program2, getClient2, getFormat2) {
|
|
|
1011
1422
|
id,
|
|
1012
1423
|
data
|
|
1013
1424
|
},
|
|
1014
|
-
|
|
1425
|
+
getFormat()
|
|
1015
1426
|
);
|
|
1016
1427
|
return;
|
|
1017
1428
|
}
|
|
1018
|
-
const client =
|
|
1429
|
+
const client = getClient();
|
|
1019
1430
|
let fileOpts;
|
|
1020
1431
|
if (opts.file) {
|
|
1021
1432
|
const { blob, filename } = readFileAsBlob(opts.file);
|
|
1022
1433
|
fileOpts = { file: blob, filename };
|
|
1023
1434
|
}
|
|
1024
1435
|
const result = await client.collections.from(col).update(id, data, fileOpts);
|
|
1025
|
-
printResult(result,
|
|
1436
|
+
printResult(result, getFormat());
|
|
1026
1437
|
} catch (e) {
|
|
1027
1438
|
exitWithError(e);
|
|
1028
1439
|
}
|
|
1029
1440
|
});
|
|
1030
|
-
|
|
1441
|
+
program.command("delete <collection> <id>").description("Delete a document by ID").option("--dry-run", "Validate inputs without executing").action(async (collection, id, opts) => {
|
|
1031
1442
|
try {
|
|
1032
1443
|
const col = validateCollection(collection);
|
|
1033
1444
|
if (opts.dryRun) {
|
|
@@ -1039,18 +1450,18 @@ function registerCrudCommands(program2, getClient2, getFormat2) {
|
|
|
1039
1450
|
collection: col,
|
|
1040
1451
|
id
|
|
1041
1452
|
},
|
|
1042
|
-
|
|
1453
|
+
getFormat()
|
|
1043
1454
|
);
|
|
1044
1455
|
return;
|
|
1045
1456
|
}
|
|
1046
|
-
const client =
|
|
1457
|
+
const client = getClient();
|
|
1047
1458
|
const result = await client.collections.from(col).remove(id);
|
|
1048
|
-
printResult(result,
|
|
1459
|
+
printResult(result, getFormat());
|
|
1049
1460
|
} catch (e) {
|
|
1050
1461
|
exitWithError(e);
|
|
1051
1462
|
}
|
|
1052
1463
|
});
|
|
1053
|
-
|
|
1464
|
+
program.command("update-many <collection>").description("Update multiple documents matching a filter").requiredOption("--where <json>", "Filter conditions (JSON)").requiredOption("--data <json>", "Update data (JSON)").option("--dry-run", "Validate inputs without executing").action(async (collection, opts) => {
|
|
1054
1465
|
try {
|
|
1055
1466
|
const col = validateCollection(collection);
|
|
1056
1467
|
const where = parseJson(opts.where, "where");
|
|
@@ -1065,18 +1476,18 @@ function registerCrudCommands(program2, getClient2, getFormat2) {
|
|
|
1065
1476
|
where,
|
|
1066
1477
|
data
|
|
1067
1478
|
},
|
|
1068
|
-
|
|
1479
|
+
getFormat()
|
|
1069
1480
|
);
|
|
1070
1481
|
return;
|
|
1071
1482
|
}
|
|
1072
|
-
const client =
|
|
1483
|
+
const client = getClient();
|
|
1073
1484
|
const result = await client.collections.from(col).updateMany(where, data);
|
|
1074
|
-
printResult(result,
|
|
1485
|
+
printResult(result, getFormat());
|
|
1075
1486
|
} catch (e) {
|
|
1076
1487
|
exitWithError(e);
|
|
1077
1488
|
}
|
|
1078
1489
|
});
|
|
1079
|
-
|
|
1490
|
+
program.command("delete-many <collection>").description("Delete multiple documents matching a filter").requiredOption("--where <json>", "Filter conditions (JSON)").option("--dry-run", "Validate inputs without executing").action(async (collection, opts) => {
|
|
1080
1491
|
try {
|
|
1081
1492
|
const col = validateCollection(collection);
|
|
1082
1493
|
const where = parseJson(opts.where, "where");
|
|
@@ -1089,13 +1500,13 @@ function registerCrudCommands(program2, getClient2, getFormat2) {
|
|
|
1089
1500
|
collection: col,
|
|
1090
1501
|
where
|
|
1091
1502
|
},
|
|
1092
|
-
|
|
1503
|
+
getFormat()
|
|
1093
1504
|
);
|
|
1094
1505
|
return;
|
|
1095
1506
|
}
|
|
1096
|
-
const client =
|
|
1507
|
+
const client = getClient();
|
|
1097
1508
|
const result = await client.collections.from(col).removeMany(where);
|
|
1098
|
-
printResult(result,
|
|
1509
|
+
printResult(result, getFormat());
|
|
1099
1510
|
} catch (e) {
|
|
1100
1511
|
exitWithError(e);
|
|
1101
1512
|
}
|
|
@@ -1991,6 +2402,17 @@ var confirmTossPaymentSessionBodySchema = z5.object({
|
|
|
1991
2402
|
var confirmTossPaymentSessionParamsSchema = confirmTossPaymentSessionBodySchema.extend({
|
|
1992
2403
|
idempotencyKey: commerceIdempotencyKeySchema
|
|
1993
2404
|
});
|
|
2405
|
+
var portOneProviderIdentitySchema = z5.string().min(1).max(512).refine((value) => /\S/u.test(value), "Provider identity must not be blank");
|
|
2406
|
+
var portOnePaymentSelectorSchema = z5.object({
|
|
2407
|
+
provider: z5.literal("portone"),
|
|
2408
|
+
providerAccountKey: portOneProviderIdentitySchema,
|
|
2409
|
+
environment: z5.enum(["test", "live"]),
|
|
2410
|
+
providerPaymentId: portOneProviderIdentitySchema
|
|
2411
|
+
}).strict();
|
|
2412
|
+
var reconcilePortOnePaymentBodySchema = portOnePaymentSelectorSchema;
|
|
2413
|
+
var reconcilePortOnePaymentParamsSchema = reconcilePortOnePaymentBodySchema.extend({
|
|
2414
|
+
idempotencyKey: commerceIdempotencyKeySchema
|
|
2415
|
+
});
|
|
1994
2416
|
var PAYMENT_PROVIDER_STATUSES = [
|
|
1995
2417
|
"requires_payment_method",
|
|
1996
2418
|
"requires_action",
|
|
@@ -2059,6 +2481,15 @@ var confirmCustomPaymentSessionResponseSchema = z5.object({
|
|
|
2059
2481
|
status: z5.literal("paid"),
|
|
2060
2482
|
alreadyConfirmed: z5.boolean().optional()
|
|
2061
2483
|
}).strict();
|
|
2484
|
+
var PORTONE_RECONCILIATION_DISPOSITIONS = [
|
|
2485
|
+
"applied",
|
|
2486
|
+
"observed",
|
|
2487
|
+
"recovered_after_ambiguous_result",
|
|
2488
|
+
"requires_attention"
|
|
2489
|
+
];
|
|
2490
|
+
var portOneReconciliationDispositionSchema = z5.enum(
|
|
2491
|
+
PORTONE_RECONCILIATION_DISPOSITIONS
|
|
2492
|
+
);
|
|
2062
2493
|
var tossPaymentNextActionSchema = z5.object({
|
|
2063
2494
|
type: z5.literal("toss_widget"),
|
|
2064
2495
|
clientKey: z5.string().min(1).max(255),
|
|
@@ -2077,7 +2508,8 @@ var portOnePaymentNextActionSchema = z5.object({
|
|
|
2077
2508
|
return url.username === "" && url.password === "";
|
|
2078
2509
|
}, "checkoutUrl must not contain embedded credentials")
|
|
2079
2510
|
}).strict();
|
|
2080
|
-
var
|
|
2511
|
+
var PORTONE_STANDARD_ACTION_RETRY_POLICY = "same_action_only";
|
|
2512
|
+
var portOneSdkPaymentRequestSchema = z5.object({
|
|
2081
2513
|
type: z5.literal("portone_sdk"),
|
|
2082
2514
|
version: z5.literal("v2"),
|
|
2083
2515
|
storeId: z5.string().min(1).max(255),
|
|
@@ -2093,7 +2525,21 @@ var portOneSdkPaymentNextActionSchema = z5.object({
|
|
|
2093
2525
|
return (url.protocol === "https:" || loopback) && !url.username && !url.password;
|
|
2094
2526
|
}, "redirectUrl must be HTTPS (or development loopback) without embedded credentials")
|
|
2095
2527
|
}).strict();
|
|
2096
|
-
var
|
|
2528
|
+
var portOneSdkPaymentCapabilityNextActionSchema = portOneSdkPaymentRequestSchema.extend({
|
|
2529
|
+
cancelable: z5.literal(false),
|
|
2530
|
+
retryPolicy: z5.literal(PORTONE_STANDARD_ACTION_RETRY_POLICY)
|
|
2531
|
+
}).strict();
|
|
2532
|
+
var portOneSdkPaymentNextActionSchema = z5.union([
|
|
2533
|
+
portOneSdkPaymentCapabilityNextActionSchema,
|
|
2534
|
+
portOneSdkPaymentRequestSchema
|
|
2535
|
+
]).transform(
|
|
2536
|
+
(action) => "cancelable" in action ? action : {
|
|
2537
|
+
...action,
|
|
2538
|
+
cancelable: false,
|
|
2539
|
+
retryPolicy: PORTONE_STANDARD_ACTION_RETRY_POLICY
|
|
2540
|
+
}
|
|
2541
|
+
);
|
|
2542
|
+
var paymentNextActionSchema = z5.union([
|
|
2097
2543
|
tossPaymentNextActionSchema,
|
|
2098
2544
|
portOnePaymentNextActionSchema,
|
|
2099
2545
|
portOneSdkPaymentNextActionSchema
|
|
@@ -2315,6 +2761,47 @@ var publicPaymentSessionVariants = [
|
|
|
2315
2761
|
)
|
|
2316
2762
|
];
|
|
2317
2763
|
var publicPaymentSessionSchema = z5.union(publicPaymentSessionVariants);
|
|
2764
|
+
var portOneReconciliationSummarySchema = z5.union([
|
|
2765
|
+
noReconciliationSchema,
|
|
2766
|
+
z5.object({
|
|
2767
|
+
status: z5.literal("required"),
|
|
2768
|
+
reasons: z5.array(paymentReconciliationReasonSchema).min(1).readonly()
|
|
2769
|
+
}).strict()
|
|
2770
|
+
]);
|
|
2771
|
+
var portOnePaymentCurrentStateSchema = z5.object({
|
|
2772
|
+
paymentSession: z5.object({
|
|
2773
|
+
id: commerceResourceIdSchema,
|
|
2774
|
+
provider: z5.literal("portone"),
|
|
2775
|
+
providerStatus: paymentProviderStatusSchema,
|
|
2776
|
+
finalizationStatus: z5.enum(["not_ready", "pending", "committed"]),
|
|
2777
|
+
sessionRole: paymentSessionRoleSchema,
|
|
2778
|
+
reconciliation: portOneReconciliationSummarySchema
|
|
2779
|
+
}).strict(),
|
|
2780
|
+
checkout: z5.object({ id: commerceResourceIdSchema }).strict(),
|
|
2781
|
+
order: orderReferenceSchema.nullable(),
|
|
2782
|
+
money: moneySchema
|
|
2783
|
+
}).strict();
|
|
2784
|
+
var findPortOnePaymentResultSchema = z5.discriminatedUnion("found", [
|
|
2785
|
+
z5.object({ found: z5.literal(false) }).strict(),
|
|
2786
|
+
z5.object({
|
|
2787
|
+
found: z5.literal(true),
|
|
2788
|
+
current: portOnePaymentCurrentStateSchema
|
|
2789
|
+
}).strict()
|
|
2790
|
+
]);
|
|
2791
|
+
var reconcilePortOnePaymentResultSchema = z5.discriminatedUnion(
|
|
2792
|
+
"found",
|
|
2793
|
+
[
|
|
2794
|
+
z5.object({
|
|
2795
|
+
found: z5.literal(false),
|
|
2796
|
+
disposition: z5.literal("requires_attention")
|
|
2797
|
+
}).strict(),
|
|
2798
|
+
z5.object({
|
|
2799
|
+
found: z5.literal(true),
|
|
2800
|
+
disposition: portOneReconciliationDispositionSchema,
|
|
2801
|
+
current: portOnePaymentCurrentStateSchema
|
|
2802
|
+
}).strict()
|
|
2803
|
+
]
|
|
2804
|
+
);
|
|
2318
2805
|
var CreatePaymentSessionParamsSchema = createPaymentSessionParamsSchema;
|
|
2319
2806
|
var CancelServerPaymentSessionParamsSchema = cancelServerPaymentSessionParamsSchema;
|
|
2320
2807
|
var ConfirmTossPaymentSessionParamsSchema = confirmTossPaymentSessionParamsSchema;
|
|
@@ -2564,40 +3051,62 @@ var returnCancellationReasonCodeSchema = z7.enum(
|
|
|
2564
3051
|
RETURN_CANCELLATION_REASON_CODES
|
|
2565
3052
|
);
|
|
2566
3053
|
var restockActionSchema = z7.enum(["return_to_stock", "discard"]);
|
|
3054
|
+
var returnRefundMoneySchema = z7.number().int("amount must be an integer minor-unit value").safe("amount must be a safe integer").nonnegative("amount must be non-negative");
|
|
3055
|
+
var positiveReturnRefundMoneySchema = z7.number().int("amount must be an integer minor-unit value").safe("amount must be a safe integer").positive("amount must be positive");
|
|
3056
|
+
function trimmedReturnRefundScalarString(maxScalars, emptyMessage, maximumMessage) {
|
|
3057
|
+
return z7.string().trim().min(1, emptyMessage).refine((value) => Array.from(value).length <= maxScalars, maximumMessage);
|
|
3058
|
+
}
|
|
2567
3059
|
var returnWithRefundItemSchema = z7.object({
|
|
2568
|
-
orderItem: z7.union([z7.string().min(1), z7.number()]).transform(String),
|
|
2569
|
-
quantity: z7.number().int().positive("quantity must be a positive integer"),
|
|
3060
|
+
orderItem: z7.union([z7.string().trim().min(1), z7.number().int().safe().positive()]).transform(String),
|
|
3061
|
+
quantity: z7.number().int("quantity must be an integer").safe("quantity must be a safe integer").positive("quantity must be a positive integer"),
|
|
2570
3062
|
restockAction: restockActionSchema.default("return_to_stock"),
|
|
2571
|
-
restockingFee:
|
|
3063
|
+
restockingFee: returnRefundMoneySchema.optional().describe("Restocking fee charged for this line (ADR 0005 \xA7Gap 1)")
|
|
2572
3064
|
}).strict();
|
|
2573
3065
|
var returnWithRefundSchema = z7.object({
|
|
2574
|
-
orderNumber: z7.string().min(1, "orderNumber is required").describe("Order number (required)"),
|
|
3066
|
+
orderNumber: z7.string().trim().min(1, "orderNumber is required").describe("Order number (required)"),
|
|
2575
3067
|
reason: returnReasonSchema.optional().describe("Return reason (optional)"),
|
|
2576
|
-
reasonDetail:
|
|
3068
|
+
reasonDetail: trimmedReturnRefundScalarString(
|
|
3069
|
+
2e3,
|
|
3070
|
+
"reasonDetail must not be empty",
|
|
3071
|
+
"reasonDetail must be 2000 Unicode code points or fewer"
|
|
3072
|
+
).optional().describe("Detailed reason text (optional)"),
|
|
2577
3073
|
returnItems: z7.array(returnWithRefundItemSchema).min(1, "At least one return item is required").max(100, "Too many return items").describe("Array of products to return (required)"),
|
|
2578
|
-
refundAmount:
|
|
2579
|
-
|
|
3074
|
+
refundAmount: positiveReturnRefundMoneySchema.describe(
|
|
3075
|
+
"Refund amount (required, min 1)"
|
|
3076
|
+
),
|
|
3077
|
+
returnShippingFee: returnRefundMoneySchema.optional().describe(
|
|
2580
3078
|
"Return shipping fee charged to the customer (ADR 0005 \xA7Gap 1)"
|
|
2581
3079
|
),
|
|
2582
|
-
initialShippingRefundAmount:
|
|
2583
|
-
initialShippingRefundOverrideNote:
|
|
3080
|
+
initialShippingRefundAmount: returnRefundMoneySchema.optional().describe("Initial order shipping amount refunded to the customer"),
|
|
3081
|
+
initialShippingRefundOverrideNote: trimmedReturnRefundScalarString(
|
|
3082
|
+
2e3,
|
|
3083
|
+
"initialShippingRefundOverrideNote must not be empty",
|
|
3084
|
+
"initialShippingRefundOverrideNote must be 2000 Unicode code points or fewer"
|
|
3085
|
+
).optional().describe(
|
|
2584
3086
|
"Operator audit note required when overriding policy suggestion"
|
|
2585
3087
|
),
|
|
2586
|
-
pgPaymentId: z7.string().min(1, "pgPaymentId is required").describe("PG payment ID for refund (required)"),
|
|
2587
|
-
paymentKey: z7.string().min(1).optional().describe("Provider payment key for verified refund"),
|
|
2588
|
-
refundReceiptUrl:
|
|
3088
|
+
pgPaymentId: z7.string().trim().min(1, "pgPaymentId is required").describe("PG payment ID for refund (required)"),
|
|
3089
|
+
paymentKey: z7.string().trim().min(1).optional().describe("Provider payment key for verified refund"),
|
|
3090
|
+
refundReceiptUrl: trimmedReturnRefundScalarString(
|
|
3091
|
+
2048,
|
|
3092
|
+
"refundReceiptUrl must not be empty",
|
|
3093
|
+
"refundReceiptUrl must be 2048 Unicode code points or fewer"
|
|
3094
|
+
).optional().describe("Refund receipt URL (optional)")
|
|
2589
3095
|
}).strict();
|
|
2590
3096
|
var createReturnSchema = z7.object({
|
|
2591
3097
|
orderNumber: z7.string().min(1, "orderNumber is required").describe("Order number (required)"),
|
|
2592
3098
|
reason: returnReasonSchema.optional().describe("Return reason (optional)"),
|
|
2593
|
-
reasonDetail: z7.string().optional().describe("Detailed reason text (optional)"),
|
|
3099
|
+
reasonDetail: z7.string().max(2e3, "reasonDetail must be 2000 characters or fewer").optional().describe("Detailed reason text (optional)"),
|
|
2594
3100
|
returnItems: z7.array(returnWithRefundItemSchema).min(1, "At least one return item is required").max(100, "Too many return items").describe("Array of products to return (required)"),
|
|
2595
|
-
refundAmount:
|
|
3101
|
+
refundAmount: returnRefundMoneySchema.describe(
|
|
2596
3102
|
"Line refund amount before initial shipping refund (required, min 0)"
|
|
2597
3103
|
),
|
|
2598
|
-
returnShippingFee:
|
|
2599
|
-
initialShippingRefundAmount:
|
|
2600
|
-
initialShippingRefundOverrideNote: z7.string().min(1).
|
|
3104
|
+
returnShippingFee: returnRefundMoneySchema.optional().describe("Return shipping fee charged to the customer"),
|
|
3105
|
+
initialShippingRefundAmount: returnRefundMoneySchema.optional().describe("Initial order shipping amount refunded to the customer"),
|
|
3106
|
+
initialShippingRefundOverrideNote: z7.string().min(1).max(
|
|
3107
|
+
2e3,
|
|
3108
|
+
"initialShippingRefundOverrideNote must be 2000 characters or fewer"
|
|
3109
|
+
).optional().describe(
|
|
2601
3110
|
"Operator audit note required when overriding policy suggestion"
|
|
2602
3111
|
)
|
|
2603
3112
|
}).strict();
|
|
@@ -2773,8 +3282,8 @@ var fulfillmentItemsSchema = z8.array(
|
|
|
2773
3282
|
quantity: z8.number().int().positive("quantity must be a positive integer")
|
|
2774
3283
|
}).strict()
|
|
2775
3284
|
).min(1, "At least one fulfillment item is required").max(100, "Maximum 100 items per fulfillment");
|
|
2776
|
-
function registerOrderCommands(
|
|
2777
|
-
const order =
|
|
3285
|
+
function registerOrderCommands(program, getClient, getFormat) {
|
|
3286
|
+
const order = program.command("order").description("Order management");
|
|
2778
3287
|
order.command("update <orderNumber>").description("Confirm a delivered order purchase").requiredOption("--status <status>", "New status (confirmed only)").option("--dry-run", "Validate inputs without executing").action(async (orderNumber, opts) => {
|
|
2779
3288
|
try {
|
|
2780
3289
|
const status = parseWithSchema(opts.status, "status", orderStatusSchema);
|
|
@@ -2782,13 +3291,13 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
2782
3291
|
if (opts.dryRun) {
|
|
2783
3292
|
printResult(
|
|
2784
3293
|
{ dryRun: true, valid: true, action: "order update", data },
|
|
2785
|
-
|
|
3294
|
+
getFormat()
|
|
2786
3295
|
);
|
|
2787
3296
|
return;
|
|
2788
3297
|
}
|
|
2789
|
-
const client =
|
|
3298
|
+
const client = getClient();
|
|
2790
3299
|
const result = await client.commerce.orders.update(data);
|
|
2791
|
-
printResult(result,
|
|
3300
|
+
printResult(result, getFormat());
|
|
2792
3301
|
} catch (e) {
|
|
2793
3302
|
exitWithError(e);
|
|
2794
3303
|
}
|
|
@@ -2810,13 +3319,13 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
2810
3319
|
if (opts.dryRun) {
|
|
2811
3320
|
printResult(
|
|
2812
3321
|
{ dryRun: true, valid: true, action: "order cancel", data },
|
|
2813
|
-
|
|
3322
|
+
getFormat()
|
|
2814
3323
|
);
|
|
2815
3324
|
return;
|
|
2816
3325
|
}
|
|
2817
|
-
const client =
|
|
3326
|
+
const client = getClient();
|
|
2818
3327
|
const result = await client.commerce.orders.cancelOrder(data);
|
|
2819
|
-
printResult(result,
|
|
3328
|
+
printResult(result, getFormat());
|
|
2820
3329
|
} catch (e) {
|
|
2821
3330
|
exitWithError(e);
|
|
2822
3331
|
}
|
|
@@ -2827,13 +3336,13 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
2827
3336
|
if (opts.dryRun) {
|
|
2828
3337
|
printResult(
|
|
2829
3338
|
{ dryRun: true, valid: true, action: "order prepare", data },
|
|
2830
|
-
|
|
3339
|
+
getFormat()
|
|
2831
3340
|
);
|
|
2832
3341
|
return;
|
|
2833
3342
|
}
|
|
2834
|
-
const client =
|
|
3343
|
+
const client = getClient();
|
|
2835
3344
|
const result = await client.commerce.orders.prepareFulfillmentOrder(data);
|
|
2836
|
-
printResult(result,
|
|
3345
|
+
printResult(result, getFormat());
|
|
2837
3346
|
} catch (e) {
|
|
2838
3347
|
exitWithError(e);
|
|
2839
3348
|
}
|
|
@@ -2854,18 +3363,18 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
2854
3363
|
if (opts.dryRun) {
|
|
2855
3364
|
printResult(
|
|
2856
3365
|
{ dryRun: true, valid: true, action: "order fulfill", data },
|
|
2857
|
-
|
|
3366
|
+
getFormat()
|
|
2858
3367
|
);
|
|
2859
3368
|
return;
|
|
2860
3369
|
}
|
|
2861
|
-
const client =
|
|
3370
|
+
const client = getClient();
|
|
2862
3371
|
const result = await client.commerce.orders.createFulfillment({
|
|
2863
3372
|
...data,
|
|
2864
3373
|
...items ? {
|
|
2865
3374
|
items
|
|
2866
3375
|
} : {}
|
|
2867
3376
|
});
|
|
2868
|
-
printResult(result,
|
|
3377
|
+
printResult(result, getFormat());
|
|
2869
3378
|
} catch (e) {
|
|
2870
3379
|
exitWithError(e);
|
|
2871
3380
|
}
|
|
@@ -2890,13 +3399,13 @@ function registerOrderCommands(program2, getClient2, getFormat2) {
|
|
|
2890
3399
|
action: "order update-fulfillment",
|
|
2891
3400
|
data
|
|
2892
3401
|
},
|
|
2893
|
-
|
|
3402
|
+
getFormat()
|
|
2894
3403
|
);
|
|
2895
3404
|
return;
|
|
2896
3405
|
}
|
|
2897
|
-
const client =
|
|
3406
|
+
const client = getClient();
|
|
2898
3407
|
const result = await client.commerce.orders.updateFulfillment(data);
|
|
2899
|
-
printResult(result,
|
|
3408
|
+
printResult(result, getFormat());
|
|
2900
3409
|
} catch (e) {
|
|
2901
3410
|
exitWithError(e);
|
|
2902
3411
|
}
|
|
@@ -2911,8 +3420,8 @@ var returnStatusSchema = z9.enum([
|
|
|
2911
3420
|
"rejected",
|
|
2912
3421
|
"completed"
|
|
2913
3422
|
]);
|
|
2914
|
-
function registerReturnCommands(
|
|
2915
|
-
const ret =
|
|
3423
|
+
function registerReturnCommands(program, getClient, getFormat) {
|
|
3424
|
+
const ret = program.command("return").description("Return management");
|
|
2916
3425
|
ret.command("create <orderNumber>").description("Create a return request").requiredOption("--products <json>", "Return products array (JSON)").requiredOption("--refund-amount <n>", "Refund amount", parseFloat).option(
|
|
2917
3426
|
"--return-shipping-fee <n>",
|
|
2918
3427
|
"Return shipping fee charged to the customer",
|
|
@@ -2946,16 +3455,16 @@ function registerReturnCommands(program2, getClient2, getFormat2) {
|
|
|
2946
3455
|
if (opts.dryRun) {
|
|
2947
3456
|
printResult(
|
|
2948
3457
|
{ dryRun: true, valid: true, action: "return create", data },
|
|
2949
|
-
|
|
3458
|
+
getFormat()
|
|
2950
3459
|
);
|
|
2951
3460
|
return;
|
|
2952
3461
|
}
|
|
2953
|
-
const client =
|
|
3462
|
+
const client = getClient();
|
|
2954
3463
|
const result = await client.commerce.orders.createReturn({
|
|
2955
3464
|
...data,
|
|
2956
3465
|
returnItems: data.returnItems
|
|
2957
3466
|
});
|
|
2958
|
-
printResult(result,
|
|
3467
|
+
printResult(result, getFormat());
|
|
2959
3468
|
} catch (e) {
|
|
2960
3469
|
exitWithError(e);
|
|
2961
3470
|
}
|
|
@@ -2974,13 +3483,13 @@ function registerReturnCommands(program2, getClient2, getFormat2) {
|
|
|
2974
3483
|
if (opts.dryRun) {
|
|
2975
3484
|
printResult(
|
|
2976
3485
|
{ dryRun: true, valid: true, action: "return update", data },
|
|
2977
|
-
|
|
3486
|
+
getFormat()
|
|
2978
3487
|
);
|
|
2979
3488
|
return;
|
|
2980
3489
|
}
|
|
2981
|
-
const client =
|
|
3490
|
+
const client = getClient();
|
|
2982
3491
|
const result = await client.commerce.orders.updateReturn(data);
|
|
2983
|
-
printResult(result,
|
|
3492
|
+
printResult(result, getFormat());
|
|
2984
3493
|
} catch (e) {
|
|
2985
3494
|
exitWithError(e);
|
|
2986
3495
|
}
|
|
@@ -3018,16 +3527,16 @@ function registerReturnCommands(program2, getClient2, getFormat2) {
|
|
|
3018
3527
|
if (opts.dryRun) {
|
|
3019
3528
|
printResult(
|
|
3020
3529
|
{ dryRun: true, valid: true, action: "return refund", data },
|
|
3021
|
-
|
|
3530
|
+
getFormat()
|
|
3022
3531
|
);
|
|
3023
3532
|
return;
|
|
3024
3533
|
}
|
|
3025
|
-
const client =
|
|
3534
|
+
const client = getClient();
|
|
3026
3535
|
const result = await client.commerce.orders.returnWithRefund({
|
|
3027
3536
|
...data,
|
|
3028
3537
|
returnItems: data.returnItems
|
|
3029
3538
|
});
|
|
3030
|
-
printResult(result,
|
|
3539
|
+
printResult(result, getFormat());
|
|
3031
3540
|
} catch (e) {
|
|
3032
3541
|
exitWithError(e);
|
|
3033
3542
|
}
|
|
@@ -3112,8 +3621,8 @@ function sensitiveDryRunResult(action) {
|
|
|
3112
3621
|
}
|
|
3113
3622
|
|
|
3114
3623
|
// src/commands/cart.ts
|
|
3115
|
-
function registerCartCommands(
|
|
3116
|
-
const cart =
|
|
3624
|
+
function registerCartCommands(program, getClient, getFormat) {
|
|
3625
|
+
const cart = program.command("cart").description("Cart management");
|
|
3117
3626
|
cart.command("create").description("Create a cart and print its cartToken capability").option("--data-stdin", "Read market and attributes JSON from stdin").option("--data-file <path>", "Read market and attributes JSON from file").option("--dry-run", "Validate inputs without executing").action(async (opts) => {
|
|
3118
3627
|
try {
|
|
3119
3628
|
const input = opts.dataStdin || opts.dataFile ? await readSensitiveJsonObject(opts) : {};
|
|
@@ -3123,10 +3632,10 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3123
3632
|
createCartParamsSchema
|
|
3124
3633
|
);
|
|
3125
3634
|
if (opts.dryRun) {
|
|
3126
|
-
printResult(sensitiveDryRunResult("cart create"),
|
|
3635
|
+
printResult(sensitiveDryRunResult("cart create"), getFormat());
|
|
3127
3636
|
return;
|
|
3128
3637
|
}
|
|
3129
|
-
printResult(await
|
|
3638
|
+
printResult(await getClient().commerce.carts.create(data), getFormat());
|
|
3130
3639
|
} catch (error) {
|
|
3131
3640
|
exitWithError(error);
|
|
3132
3641
|
}
|
|
@@ -3139,8 +3648,8 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3139
3648
|
retrieveCartParamsSchema
|
|
3140
3649
|
);
|
|
3141
3650
|
printResult(
|
|
3142
|
-
await
|
|
3143
|
-
|
|
3651
|
+
await getClient().commerce.carts.retrieve(data),
|
|
3652
|
+
getFormat()
|
|
3144
3653
|
);
|
|
3145
3654
|
} catch (error) {
|
|
3146
3655
|
exitWithError(error);
|
|
@@ -3154,10 +3663,10 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3154
3663
|
addItemParamsSchema
|
|
3155
3664
|
);
|
|
3156
3665
|
if (opts.dryRun) {
|
|
3157
|
-
printResult(sensitiveDryRunResult("cart add"),
|
|
3666
|
+
printResult(sensitiveDryRunResult("cart add"), getFormat());
|
|
3158
3667
|
return;
|
|
3159
3668
|
}
|
|
3160
|
-
printResult(await
|
|
3669
|
+
printResult(await getClient().commerce.carts.addItem(data), getFormat());
|
|
3161
3670
|
} catch (error) {
|
|
3162
3671
|
exitWithError(error);
|
|
3163
3672
|
}
|
|
@@ -3170,12 +3679,12 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3170
3679
|
updateItemParamsSchema
|
|
3171
3680
|
);
|
|
3172
3681
|
if (opts.dryRun) {
|
|
3173
|
-
printResult(sensitiveDryRunResult("cart update"),
|
|
3682
|
+
printResult(sensitiveDryRunResult("cart update"), getFormat());
|
|
3174
3683
|
return;
|
|
3175
3684
|
}
|
|
3176
3685
|
printResult(
|
|
3177
|
-
await
|
|
3178
|
-
|
|
3686
|
+
await getClient().commerce.carts.updateItem(data),
|
|
3687
|
+
getFormat()
|
|
3179
3688
|
);
|
|
3180
3689
|
} catch (error) {
|
|
3181
3690
|
exitWithError(error);
|
|
@@ -3189,12 +3698,12 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3189
3698
|
removeItemParamsSchema
|
|
3190
3699
|
);
|
|
3191
3700
|
if (opts.dryRun) {
|
|
3192
|
-
printResult(sensitiveDryRunResult("cart remove"),
|
|
3701
|
+
printResult(sensitiveDryRunResult("cart remove"), getFormat());
|
|
3193
3702
|
return;
|
|
3194
3703
|
}
|
|
3195
3704
|
printResult(
|
|
3196
|
-
await
|
|
3197
|
-
|
|
3705
|
+
await getClient().commerce.carts.removeItem(data),
|
|
3706
|
+
getFormat()
|
|
3198
3707
|
);
|
|
3199
3708
|
} catch (error) {
|
|
3200
3709
|
exitWithError(error);
|
|
@@ -3208,10 +3717,10 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3208
3717
|
clearCartParamsSchema
|
|
3209
3718
|
);
|
|
3210
3719
|
if (opts.dryRun) {
|
|
3211
|
-
printResult(sensitiveDryRunResult("cart clear"),
|
|
3720
|
+
printResult(sensitiveDryRunResult("cart clear"), getFormat());
|
|
3212
3721
|
return;
|
|
3213
3722
|
}
|
|
3214
|
-
printResult(await
|
|
3723
|
+
printResult(await getClient().commerce.carts.clear(data), getFormat());
|
|
3215
3724
|
} catch (error) {
|
|
3216
3725
|
exitWithError(error);
|
|
3217
3726
|
}
|
|
@@ -3224,12 +3733,12 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3224
3733
|
updateDiscountCodesParamsSchema
|
|
3225
3734
|
);
|
|
3226
3735
|
if (opts.dryRun) {
|
|
3227
|
-
printResult(sensitiveDryRunResult("cart discounts"),
|
|
3736
|
+
printResult(sensitiveDryRunResult("cart discounts"), getFormat());
|
|
3228
3737
|
return;
|
|
3229
3738
|
}
|
|
3230
3739
|
printResult(
|
|
3231
|
-
await
|
|
3232
|
-
|
|
3740
|
+
await getClient().commerce.carts.updateDiscountCodes(data),
|
|
3741
|
+
getFormat()
|
|
3233
3742
|
);
|
|
3234
3743
|
} catch (error) {
|
|
3235
3744
|
exitWithError(error);
|
|
@@ -3246,12 +3755,12 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3246
3755
|
updateCartAttributesParamsSchema
|
|
3247
3756
|
);
|
|
3248
3757
|
if (opts.dryRun) {
|
|
3249
|
-
printResult(sensitiveDryRunResult("cart attributes"),
|
|
3758
|
+
printResult(sensitiveDryRunResult("cart attributes"), getFormat());
|
|
3250
3759
|
return;
|
|
3251
3760
|
}
|
|
3252
3761
|
printResult(
|
|
3253
|
-
await
|
|
3254
|
-
|
|
3762
|
+
await getClient().commerce.carts.updateAttributes(data),
|
|
3763
|
+
getFormat()
|
|
3255
3764
|
);
|
|
3256
3765
|
} catch (error) {
|
|
3257
3766
|
exitWithError(error);
|
|
@@ -3260,17 +3769,17 @@ function registerCartCommands(program2, getClient2, getFormat2) {
|
|
|
3260
3769
|
}
|
|
3261
3770
|
|
|
3262
3771
|
// src/commands/stock.ts
|
|
3263
|
-
function registerStockCommands(
|
|
3264
|
-
const stock =
|
|
3772
|
+
function registerStockCommands(program, getClient, getFormat) {
|
|
3773
|
+
const stock = program.command("stock").description("Stock management");
|
|
3265
3774
|
stock.command("check").description("Check stock availability").requiredOption(
|
|
3266
3775
|
"--items <json>",
|
|
3267
3776
|
"Items to check (JSON array of { optionId, quantity })"
|
|
3268
3777
|
).action(async (opts) => {
|
|
3269
3778
|
try {
|
|
3270
|
-
const client =
|
|
3779
|
+
const client = getClient();
|
|
3271
3780
|
const items = parseJsonArray(opts.items, "items");
|
|
3272
3781
|
const result = await client.commerce.product.stockCheck({ items });
|
|
3273
|
-
printResult(result,
|
|
3782
|
+
printResult(result, getFormat());
|
|
3274
3783
|
} catch (e) {
|
|
3275
3784
|
exitWithError(e);
|
|
3276
3785
|
}
|
|
@@ -3282,8 +3791,8 @@ function paymentProvider(value) {
|
|
|
3282
3791
|
if (value === "toss" || value === "portone") return value;
|
|
3283
3792
|
throw new Error("payment provider must be toss or portone");
|
|
3284
3793
|
}
|
|
3285
|
-
function registerCommerceSessionCommands(
|
|
3286
|
-
const checkout =
|
|
3794
|
+
function registerCommerceSessionCommands(program, getClient, getFormat) {
|
|
3795
|
+
const checkout = program.command("checkout").description("Checkout management");
|
|
3287
3796
|
checkout.command("create").description("Create a Checkout from a server-authoritative Cart").option("--data-stdin", "Read capability and customer JSON from stdin").option("--data-file <path>", "Read capability and customer JSON from file").option("--dry-run", "Validate inputs without executing").action(async (opts) => {
|
|
3288
3797
|
try {
|
|
3289
3798
|
const data = parseWithSchema(
|
|
@@ -3292,12 +3801,12 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3292
3801
|
CreateServerCheckoutParamsSchema
|
|
3293
3802
|
);
|
|
3294
3803
|
if (opts.dryRun) {
|
|
3295
|
-
printResult(sensitiveDryRunResult("checkout create"),
|
|
3804
|
+
printResult(sensitiveDryRunResult("checkout create"), getFormat());
|
|
3296
3805
|
return;
|
|
3297
3806
|
}
|
|
3298
3807
|
printResult(
|
|
3299
|
-
await
|
|
3300
|
-
|
|
3808
|
+
await getClient().commerce.checkouts.create(data),
|
|
3809
|
+
getFormat()
|
|
3301
3810
|
);
|
|
3302
3811
|
} catch (error) {
|
|
3303
3812
|
exitWithError(error);
|
|
@@ -3306,8 +3815,8 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3306
3815
|
checkout.command("retrieve <checkoutId>").description("Retrieve a Checkout by ID with server credentials").action(async (checkoutId) => {
|
|
3307
3816
|
try {
|
|
3308
3817
|
printResult(
|
|
3309
|
-
await
|
|
3310
|
-
|
|
3818
|
+
await getClient().commerce.checkouts.retrieve({ checkoutId }),
|
|
3819
|
+
getFormat()
|
|
3311
3820
|
);
|
|
3312
3821
|
} catch (error) {
|
|
3313
3822
|
exitWithError(error);
|
|
@@ -3321,14 +3830,14 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3321
3830
|
CanonicalCheckoutQuerySchema
|
|
3322
3831
|
);
|
|
3323
3832
|
printResult(
|
|
3324
|
-
await
|
|
3325
|
-
|
|
3833
|
+
await getClient().commerce.checkouts.query(data),
|
|
3834
|
+
getFormat()
|
|
3326
3835
|
);
|
|
3327
3836
|
} catch (error) {
|
|
3328
3837
|
exitWithError(error);
|
|
3329
3838
|
}
|
|
3330
3839
|
});
|
|
3331
|
-
const sessions =
|
|
3840
|
+
const sessions = program.command("payment-session").description("PaymentSession management");
|
|
3332
3841
|
sessions.command("create").description("Create a canonical provider-configured PaymentSession").option("--data-stdin", "Read canonical create parameters from stdin").option("--data-file <path>", "Read canonical create parameters from file").option("--dry-run", "Validate inputs without executing").action(async (opts) => {
|
|
3333
3842
|
try {
|
|
3334
3843
|
const data = parseWithSchema(
|
|
@@ -3339,13 +3848,13 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3339
3848
|
if (opts.dryRun) {
|
|
3340
3849
|
printResult(
|
|
3341
3850
|
sensitiveDryRunResult("payment-session create"),
|
|
3342
|
-
|
|
3851
|
+
getFormat()
|
|
3343
3852
|
);
|
|
3344
3853
|
return;
|
|
3345
3854
|
}
|
|
3346
|
-
const paymentSessions =
|
|
3855
|
+
const paymentSessions = getClient().commerce.paymentSessions;
|
|
3347
3856
|
const result = data.provider === "portone" ? await paymentSessions.createPortOne(data) : await paymentSessions.create(data);
|
|
3348
|
-
printResult(result,
|
|
3857
|
+
printResult(result, getFormat());
|
|
3349
3858
|
} catch (error) {
|
|
3350
3859
|
exitWithError(error);
|
|
3351
3860
|
}
|
|
@@ -3357,10 +3866,10 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3357
3866
|
).action(async (paymentSessionId, opts) => {
|
|
3358
3867
|
try {
|
|
3359
3868
|
const provider = paymentProvider(opts.provider);
|
|
3360
|
-
const paymentSessions =
|
|
3869
|
+
const paymentSessions = getClient().commerce.paymentSessions;
|
|
3361
3870
|
printResult(
|
|
3362
3871
|
provider === "portone" ? await paymentSessions.retrievePortOne({ paymentSessionId }) : await paymentSessions.retrieve({ paymentSessionId }),
|
|
3363
|
-
|
|
3872
|
+
getFormat()
|
|
3364
3873
|
);
|
|
3365
3874
|
} catch (error) {
|
|
3366
3875
|
exitWithError(error);
|
|
@@ -3384,14 +3893,14 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3384
3893
|
if (opts.dryRun) {
|
|
3385
3894
|
printResult(
|
|
3386
3895
|
sensitiveDryRunResult("payment-session cancel"),
|
|
3387
|
-
|
|
3896
|
+
getFormat()
|
|
3388
3897
|
);
|
|
3389
3898
|
return;
|
|
3390
3899
|
}
|
|
3391
|
-
const paymentSessions =
|
|
3900
|
+
const paymentSessions = getClient().commerce.paymentSessions;
|
|
3392
3901
|
printResult(
|
|
3393
3902
|
provider === "portone" ? await paymentSessions.cancelPortOne(data) : await paymentSessions.cancel(data),
|
|
3394
|
-
|
|
3903
|
+
getFormat()
|
|
3395
3904
|
);
|
|
3396
3905
|
} catch (error) {
|
|
3397
3906
|
exitWithError(error);
|
|
@@ -3407,13 +3916,13 @@ function registerCommerceSessionCommands(program2, getClient2, getFormat2) {
|
|
|
3407
3916
|
if (opts.dryRun) {
|
|
3408
3917
|
printResult(
|
|
3409
3918
|
sensitiveDryRunResult("payment-session confirm-toss"),
|
|
3410
|
-
|
|
3919
|
+
getFormat()
|
|
3411
3920
|
);
|
|
3412
3921
|
return;
|
|
3413
3922
|
}
|
|
3414
3923
|
printResult(
|
|
3415
|
-
await
|
|
3416
|
-
|
|
3924
|
+
await getClient().commerce.paymentSessions.confirm(data),
|
|
3925
|
+
getFormat()
|
|
3417
3926
|
);
|
|
3418
3927
|
} catch (error) {
|
|
3419
3928
|
exitWithError(error);
|
|
@@ -3469,14 +3978,14 @@ function productDetailParamsFromOptions(options) {
|
|
|
3469
3978
|
}
|
|
3470
3979
|
|
|
3471
3980
|
// src/commands/product.ts
|
|
3472
|
-
function registerProductCommands(
|
|
3473
|
-
const product =
|
|
3981
|
+
function registerProductCommands(program, getClient, getFormat) {
|
|
3982
|
+
const product = program.command("product").description("Product management");
|
|
3474
3983
|
product.command("detail").description("Get shaped product detail by slug or ID").option("--slug <slug>", "Product slug").option("--id <id>", "Product ID").option("--market <market>", "Market slug").option("--locale <locale>", "Locale: ko, en, or all").option("--fallback-locale <locale>", "Fallback locale: ko, en, or none").action(async (opts) => {
|
|
3475
3984
|
try {
|
|
3476
3985
|
const params = productDetailParamsFromOptions(opts);
|
|
3477
|
-
const client =
|
|
3986
|
+
const client = getClient();
|
|
3478
3987
|
const result = await client.commerce.product.detail(params);
|
|
3479
|
-
printResult(result,
|
|
3988
|
+
printResult(result, getFormat());
|
|
3480
3989
|
} catch (e) {
|
|
3481
3990
|
exitWithError(e);
|
|
3482
3991
|
}
|
|
@@ -3491,15 +4000,15 @@ function registerProductCommands(program2, getClient2, getFormat2) {
|
|
|
3491
4000
|
if (opts.dryRun) {
|
|
3492
4001
|
printResult(
|
|
3493
4002
|
{ dryRun: true, valid: true, action: "product upsert", data },
|
|
3494
|
-
|
|
4003
|
+
getFormat()
|
|
3495
4004
|
);
|
|
3496
4005
|
return;
|
|
3497
4006
|
}
|
|
3498
|
-
const client =
|
|
4007
|
+
const client = getClient();
|
|
3499
4008
|
const result = await client.commerce.product.upsert(
|
|
3500
4009
|
data
|
|
3501
4010
|
);
|
|
3502
|
-
printResult(result,
|
|
4011
|
+
printResult(result, getFormat());
|
|
3503
4012
|
} catch (e) {
|
|
3504
4013
|
exitWithError(e);
|
|
3505
4014
|
}
|
|
@@ -3507,20 +4016,20 @@ function registerProductCommands(program2, getClient2, getFormat2) {
|
|
|
3507
4016
|
}
|
|
3508
4017
|
|
|
3509
4018
|
// src/commands/discount.ts
|
|
3510
|
-
function registerDiscountCommands(
|
|
3511
|
-
const discount =
|
|
4019
|
+
function registerDiscountCommands(program, getClient, getFormat) {
|
|
4020
|
+
const discount = program.command("discount").description("Discount management");
|
|
3512
4021
|
discount.command("validate").description("Validate a discount code against an order amount").requiredOption("--code <code>", "Discount code").requiredOption(
|
|
3513
4022
|
"--order-amount <n>",
|
|
3514
4023
|
"Order amount",
|
|
3515
4024
|
(v) => parseInt(v, 10)
|
|
3516
4025
|
).action(async (opts) => {
|
|
3517
4026
|
try {
|
|
3518
|
-
const client =
|
|
4027
|
+
const client = getClient();
|
|
3519
4028
|
const result = await client.commerce.discounts.validate({
|
|
3520
4029
|
code: opts.code,
|
|
3521
4030
|
orderAmount: opts.orderAmount
|
|
3522
4031
|
});
|
|
3523
|
-
printResult(result,
|
|
4032
|
+
printResult(result, getFormat());
|
|
3524
4033
|
} catch (e) {
|
|
3525
4034
|
exitWithError(e);
|
|
3526
4035
|
}
|
|
@@ -3528,15 +4037,15 @@ function registerDiscountCommands(program2, getClient2, getFormat2) {
|
|
|
3528
4037
|
}
|
|
3529
4038
|
|
|
3530
4039
|
// src/commands/shipping.ts
|
|
3531
|
-
function registerShippingCommands(
|
|
3532
|
-
const shipping =
|
|
4040
|
+
function registerShippingCommands(program, getClient, getFormat) {
|
|
4041
|
+
const shipping = program.command("shipping").description("Shipping calculation");
|
|
3533
4042
|
shipping.command("calculate").description("Calculate shipping for an order amount").requiredOption(
|
|
3534
4043
|
"--order-amount <n>",
|
|
3535
4044
|
"Order amount",
|
|
3536
4045
|
(v) => parseInt(v, 10)
|
|
3537
4046
|
).option("--shipping-policy-id <id>", "Shipping policy ID").option("--country-code <code>", "Destination country code").option("--region-code <code>", "Destination region code").option("--postal-code <code>", "Destination postal code").action(async (opts) => {
|
|
3538
4047
|
try {
|
|
3539
|
-
const client =
|
|
4048
|
+
const client = getClient();
|
|
3540
4049
|
const result = await client.commerce.shipping.calculate({
|
|
3541
4050
|
orderAmount: opts.orderAmount,
|
|
3542
4051
|
...opts.shippingPolicyId ? { shippingPolicyId: opts.shippingPolicyId } : {},
|
|
@@ -3544,7 +4053,7 @@ function registerShippingCommands(program2, getClient2, getFormat2) {
|
|
|
3544
4053
|
...opts.regionCode ? { regionCode: opts.regionCode } : {},
|
|
3545
4054
|
...opts.postalCode ? { postalCode: opts.postalCode } : {}
|
|
3546
4055
|
});
|
|
3547
|
-
printResult(result,
|
|
4056
|
+
printResult(result, getFormat());
|
|
3548
4057
|
} catch (e) {
|
|
3549
4058
|
exitWithError(e);
|
|
3550
4059
|
}
|
|
@@ -3560,6 +4069,8 @@ import { URL as URL2 } from "url";
|
|
|
3560
4069
|
import pc2 from "picocolors";
|
|
3561
4070
|
var WEB_URL = process.env.SOFTWARE_WEB_URL || "https://01.software";
|
|
3562
4071
|
var TIMEOUT_MS = 3 * 60 * 1e3;
|
|
4072
|
+
var EXCHANGE_TIMEOUT_MS = 3e4;
|
|
4073
|
+
var MAX_EXCHANGE_RESPONSE_BYTES = 1024 * 1024;
|
|
3563
4074
|
function escapeHtml(s) {
|
|
3564
4075
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
3565
4076
|
}
|
|
@@ -3602,16 +4113,72 @@ var ERROR_HTML = (msg) => `<!DOCTYPE html>
|
|
|
3602
4113
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>CLI Login Error</title>
|
|
3603
4114
|
<style>${PAGE_STYLE}</style>
|
|
3604
4115
|
</head><body><div class="card"><div class="icon err">!</div><h1>Authentication failed</h1><p>${escapeHtml(msg)}</p></div></body></html>`;
|
|
3605
|
-
async function
|
|
4116
|
+
async function readBoundedResponseBody(response, signal) {
|
|
4117
|
+
const contentLength = response.headers.get("content-length");
|
|
4118
|
+
if (contentLength !== null && /^\d+$/.test(contentLength) && Number(contentLength) > MAX_EXCHANGE_RESPONSE_BYTES) {
|
|
4119
|
+
void response.body?.cancel().catch(() => void 0);
|
|
4120
|
+
throw new Error("response body exceeded 1 MiB");
|
|
4121
|
+
}
|
|
4122
|
+
const reader = response.body?.getReader();
|
|
4123
|
+
if (!reader) return "";
|
|
4124
|
+
const decoder = new TextDecoder();
|
|
4125
|
+
let body = "";
|
|
4126
|
+
let totalBytes = 0;
|
|
4127
|
+
let completed = false;
|
|
4128
|
+
let rejectAbort;
|
|
4129
|
+
const aborted = new Promise((_, reject) => {
|
|
4130
|
+
rejectAbort = reject;
|
|
4131
|
+
});
|
|
4132
|
+
const onAbort = () => rejectAbort(new Error("request timed out"));
|
|
4133
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4134
|
+
if (signal.aborted) onAbort();
|
|
4135
|
+
try {
|
|
4136
|
+
while (true) {
|
|
4137
|
+
const { done, value } = await Promise.race([reader.read(), aborted]);
|
|
4138
|
+
if (done) {
|
|
4139
|
+
completed = true;
|
|
4140
|
+
return body + decoder.decode();
|
|
4141
|
+
}
|
|
4142
|
+
totalBytes += value.byteLength;
|
|
4143
|
+
if (totalBytes > MAX_EXCHANGE_RESPONSE_BYTES) {
|
|
4144
|
+
throw new Error("response body exceeded 1 MiB");
|
|
4145
|
+
}
|
|
4146
|
+
body += decoder.decode(value, { stream: true });
|
|
4147
|
+
}
|
|
4148
|
+
} finally {
|
|
4149
|
+
signal.removeEventListener("abort", onAbort);
|
|
4150
|
+
if (!completed) void reader.cancel().catch(() => void 0);
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
async function exchangeCode(code, options = {}) {
|
|
3606
4154
|
const url = `${WEB_URL}/api/cli/exchange`;
|
|
4155
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
4156
|
+
const timeoutMs = options.timeoutMs ?? EXCHANGE_TIMEOUT_MS;
|
|
4157
|
+
const controller = new AbortController();
|
|
4158
|
+
let timeoutId;
|
|
4159
|
+
let rejectTimeout;
|
|
4160
|
+
const timedOut = new Promise((_, reject) => {
|
|
4161
|
+
rejectTimeout = reject;
|
|
4162
|
+
});
|
|
3607
4163
|
try {
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
4164
|
+
timeoutId = setTimeout(() => {
|
|
4165
|
+
controller.abort();
|
|
4166
|
+
rejectTimeout(new Error("request timed out"));
|
|
4167
|
+
}, timeoutMs);
|
|
4168
|
+
const res = await Promise.race([
|
|
4169
|
+
fetchImpl(url, {
|
|
4170
|
+
method: "POST",
|
|
4171
|
+
headers: { "Content-Type": "application/json" },
|
|
4172
|
+
body: JSON.stringify({ code }),
|
|
4173
|
+
signal: controller.signal
|
|
4174
|
+
}),
|
|
4175
|
+
timedOut
|
|
4176
|
+
]);
|
|
4177
|
+
const body = await Promise.race([
|
|
4178
|
+
readBoundedResponseBody(res, controller.signal),
|
|
4179
|
+
timedOut
|
|
4180
|
+
]);
|
|
3613
4181
|
if (!res.ok) {
|
|
3614
|
-
const body = await res.text().catch(() => "");
|
|
3615
4182
|
console.error(
|
|
3616
4183
|
pc2.red(
|
|
3617
4184
|
`Exchange failed: HTTP ${res.status} from ${url}${body ? ` \u2014 ${body.slice(0, 200)}` : ""}`
|
|
@@ -3619,7 +4186,13 @@ async function exchangeCode(code) {
|
|
|
3619
4186
|
);
|
|
3620
4187
|
return null;
|
|
3621
4188
|
}
|
|
3622
|
-
|
|
4189
|
+
let data;
|
|
4190
|
+
try {
|
|
4191
|
+
data = JSON.parse(body);
|
|
4192
|
+
} catch {
|
|
4193
|
+
console.error(pc2.red(`Exchange failed: malformed response from ${url}`));
|
|
4194
|
+
return null;
|
|
4195
|
+
}
|
|
3623
4196
|
if (typeof data.publishableKey !== "string" || typeof data.secretKey !== "string" || typeof data.tenantName !== "string" || typeof data.tenantId !== "string") {
|
|
3624
4197
|
console.error(pc2.red(`Exchange failed: malformed response from ${url}`));
|
|
3625
4198
|
return null;
|
|
@@ -3640,10 +4213,12 @@ async function exchangeCode(code) {
|
|
|
3640
4213
|
)
|
|
3641
4214
|
);
|
|
3642
4215
|
return null;
|
|
4216
|
+
} finally {
|
|
4217
|
+
clearTimeout(timeoutId);
|
|
3643
4218
|
}
|
|
3644
4219
|
}
|
|
3645
4220
|
function startAuthServer(options) {
|
|
3646
|
-
return new Promise((
|
|
4221
|
+
return new Promise((resolve3, reject) => {
|
|
3647
4222
|
const server = createServer((req, res) => {
|
|
3648
4223
|
if (!req.url) {
|
|
3649
4224
|
res.writeHead(400).end();
|
|
@@ -3656,7 +4231,10 @@ function startAuthServer(options) {
|
|
|
3656
4231
|
}
|
|
3657
4232
|
const error = url.searchParams.get("error");
|
|
3658
4233
|
if (error) {
|
|
3659
|
-
res.writeHead(200, {
|
|
4234
|
+
res.writeHead(200, {
|
|
4235
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
4236
|
+
Connection: "close"
|
|
4237
|
+
}).end(ERROR_HTML(error));
|
|
3660
4238
|
console.error(pc2.red(`Login failed: ${error}`));
|
|
3661
4239
|
cleanup(2);
|
|
3662
4240
|
return;
|
|
@@ -3664,19 +4242,32 @@ function startAuthServer(options) {
|
|
|
3664
4242
|
const code = url.searchParams.get("code");
|
|
3665
4243
|
const receivedState = url.searchParams.get("state");
|
|
3666
4244
|
if (!code || !receivedState) {
|
|
3667
|
-
res.writeHead(400, {
|
|
4245
|
+
res.writeHead(400, {
|
|
4246
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
4247
|
+
Connection: "close"
|
|
4248
|
+
}).end(ERROR_HTML('Missing code or state. Start over with "01 login".'));
|
|
3668
4249
|
cleanup(2);
|
|
3669
4250
|
return;
|
|
3670
4251
|
}
|
|
3671
4252
|
if (receivedState !== options.state) {
|
|
3672
|
-
res.writeHead(403, {
|
|
4253
|
+
res.writeHead(403, {
|
|
4254
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
4255
|
+
Connection: "close"
|
|
4256
|
+
}).end(ERROR_HTML('State mismatch. Start over with "01 login".'));
|
|
3673
4257
|
console.error(pc2.red("Login failed: state mismatch."));
|
|
3674
4258
|
cleanup(2);
|
|
3675
4259
|
return;
|
|
3676
4260
|
}
|
|
3677
4261
|
exchangeCode(code).then((creds) => {
|
|
3678
4262
|
if (!creds) {
|
|
3679
|
-
res.writeHead(400, {
|
|
4263
|
+
res.writeHead(400, {
|
|
4264
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
4265
|
+
Connection: "close"
|
|
4266
|
+
}).end(
|
|
4267
|
+
ERROR_HTML(
|
|
4268
|
+
'Invalid or expired code. Start over with "01 login".'
|
|
4269
|
+
)
|
|
4270
|
+
);
|
|
3680
4271
|
console.error(pc2.red("Login failed: code exchange failed."));
|
|
3681
4272
|
cleanup(2);
|
|
3682
4273
|
return;
|
|
@@ -3693,7 +4284,10 @@ function startAuthServer(options) {
|
|
|
3693
4284
|
console.log(pc2.green(`
|
|
3694
4285
|
Logged in successfully!`));
|
|
3695
4286
|
console.log(pc2.dim(`Tenant: ${creds.tenantName}`));
|
|
3696
|
-
res.writeHead(200, {
|
|
4287
|
+
res.writeHead(200, {
|
|
4288
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
4289
|
+
Connection: "close"
|
|
4290
|
+
}).end(SUCCESS_HTML);
|
|
3697
4291
|
cleanup(0);
|
|
3698
4292
|
});
|
|
3699
4293
|
});
|
|
@@ -3718,15 +4312,15 @@ Logged in successfully!`));
|
|
|
3718
4312
|
);
|
|
3719
4313
|
cleanup(4);
|
|
3720
4314
|
}, TIMEOUT_MS);
|
|
3721
|
-
|
|
4315
|
+
resolve3({ port: addr.port, cleanup });
|
|
3722
4316
|
});
|
|
3723
4317
|
server.on("error", (err) => {
|
|
3724
4318
|
reject(err);
|
|
3725
4319
|
});
|
|
3726
4320
|
});
|
|
3727
4321
|
}
|
|
3728
|
-
function registerAuthCommands(
|
|
3729
|
-
|
|
4322
|
+
function registerAuthCommands(program) {
|
|
4323
|
+
program.command("login").description("Login via browser and store credentials").action(async () => {
|
|
3730
4324
|
const state = randomBytes2(32).toString("hex");
|
|
3731
4325
|
try {
|
|
3732
4326
|
const { port } = await startAuthServer({
|
|
@@ -3751,7 +4345,7 @@ ${loginUrl}`));
|
|
|
3751
4345
|
process.exit(4);
|
|
3752
4346
|
}
|
|
3753
4347
|
});
|
|
3754
|
-
|
|
4348
|
+
program.command("logout").description("Remove stored credentials").action(() => {
|
|
3755
4349
|
const deleted = deleteCredentials();
|
|
3756
4350
|
if (deleted) {
|
|
3757
4351
|
console.log(pc2.green("Logged out. Credentials removed."));
|
|
@@ -3759,7 +4353,7 @@ ${loginUrl}`));
|
|
|
3759
4353
|
console.log(pc2.dim("No stored credentials found."));
|
|
3760
4354
|
}
|
|
3761
4355
|
});
|
|
3762
|
-
|
|
4356
|
+
program.command("whoami").description("Show current authentication status").action(() => {
|
|
3763
4357
|
const localCreds = loadLocalCredentials();
|
|
3764
4358
|
const globalCreds = loadCredentials();
|
|
3765
4359
|
const creds = localCreds || globalCreds;
|
|
@@ -3777,7 +4371,7 @@ ${loginUrl}`));
|
|
|
3777
4371
|
`File: ${pc2.dim(isLocal ? getLocalCredentialsPath() : getCredentialsPath())}`
|
|
3778
4372
|
);
|
|
3779
4373
|
});
|
|
3780
|
-
const tenant =
|
|
4374
|
+
const tenant = program.command("tenant").description("Manage tenant switching");
|
|
3781
4375
|
tenant.command("list").description("Show cached tenant list").action(() => {
|
|
3782
4376
|
const tenants = loadTenantList();
|
|
3783
4377
|
if (!tenants || tenants.length === 0) {
|
|
@@ -3858,17 +4452,17 @@ ${loginUrl}`));
|
|
|
3858
4452
|
|
|
3859
4453
|
// src/commands/schema.ts
|
|
3860
4454
|
import { SERVER_COLLECTIONS as SERVER_COLLECTIONS2 } from "@01.software/sdk";
|
|
3861
|
-
function registerSchemaCommands(
|
|
3862
|
-
const schema =
|
|
4455
|
+
function registerSchemaCommands(program, getClient, getFormat) {
|
|
4456
|
+
const schema = program.command("schema").description("Collection schema introspection");
|
|
3863
4457
|
schema.command("list").description("List available collections").action(() => {
|
|
3864
|
-
printResult(SERVER_COLLECTIONS2,
|
|
4458
|
+
printResult(SERVER_COLLECTIONS2, getFormat());
|
|
3865
4459
|
});
|
|
3866
4460
|
schema.command("show <collection>").description("Show collection field schema").action(async (collection) => {
|
|
3867
4461
|
try {
|
|
3868
4462
|
const col = validateCollection(collection);
|
|
3869
|
-
const client =
|
|
4463
|
+
const client = getClient();
|
|
3870
4464
|
const result = await client.tenant.collectionSchema(col);
|
|
3871
|
-
printResult(result,
|
|
4465
|
+
printResult(result, getFormat());
|
|
3872
4466
|
} catch (e) {
|
|
3873
4467
|
exitWithError(e);
|
|
3874
4468
|
}
|
|
@@ -3887,8 +4481,8 @@ function flattenProgress(progress) {
|
|
|
3887
4481
|
}))
|
|
3888
4482
|
);
|
|
3889
4483
|
}
|
|
3890
|
-
function registerFeatureCommands(
|
|
3891
|
-
const feature =
|
|
4484
|
+
function registerFeatureCommands(program, getClient, getFormat) {
|
|
4485
|
+
const feature = program.command("feature").description("Feature implementation progress checks");
|
|
3892
4486
|
feature.command("check <feature>").description("Check tenant implementation progress for a feature").option("--evidence", "Include sanitized evidence counts and surface flags").action(async (featureName, options) => {
|
|
3893
4487
|
try {
|
|
3894
4488
|
const input = parseWithSchema(
|
|
@@ -3899,11 +4493,11 @@ function registerFeatureCommands(program2, getClient2, getFormat2) {
|
|
|
3899
4493
|
"feature",
|
|
3900
4494
|
tenantFeatureProgressInputSchema
|
|
3901
4495
|
);
|
|
3902
|
-
const client =
|
|
4496
|
+
const client = getClient();
|
|
3903
4497
|
const result = tenantFeatureProgressResponseSchema.parse(
|
|
3904
4498
|
await client.tenant.featureProgress(input)
|
|
3905
4499
|
);
|
|
3906
|
-
const format =
|
|
4500
|
+
const format = getFormat();
|
|
3907
4501
|
printResult(
|
|
3908
4502
|
format === "table" ? flattenProgress(result) : result,
|
|
3909
4503
|
format
|
|
@@ -4160,18 +4754,18 @@ function assertAgentPlanCapabilityMatrix(matrix) {
|
|
|
4160
4754
|
);
|
|
4161
4755
|
}
|
|
4162
4756
|
const seen = /* @__PURE__ */ new Set();
|
|
4163
|
-
for (const
|
|
4164
|
-
if (!AGENT_PLAN_OPERATIONS.has(
|
|
4757
|
+
for (const operation2 of operations) {
|
|
4758
|
+
if (!AGENT_PLAN_OPERATIONS.has(operation2)) {
|
|
4165
4759
|
throw new Error(
|
|
4166
|
-
`Agent plan capability operation "${
|
|
4760
|
+
`Agent plan capability operation "${operation2}" is invalid for "${collection}".`
|
|
4167
4761
|
);
|
|
4168
4762
|
}
|
|
4169
|
-
if (seen.has(
|
|
4763
|
+
if (seen.has(operation2)) {
|
|
4170
4764
|
throw new Error(
|
|
4171
|
-
`Agent plan capability operation "${
|
|
4765
|
+
`Agent plan capability operation "${operation2}" is duplicated for "${collection}".`
|
|
4172
4766
|
);
|
|
4173
4767
|
}
|
|
4174
|
-
seen.add(
|
|
4768
|
+
seen.add(operation2);
|
|
4175
4769
|
}
|
|
4176
4770
|
}
|
|
4177
4771
|
}
|
|
@@ -4185,19 +4779,19 @@ function isAgentPlanCollection(collection) {
|
|
|
4185
4779
|
function getAgentPlanOperations(collection) {
|
|
4186
4780
|
return isAgentPlanCollection(collection) ? AGENT_PLAN_CAPABILITIES[collection] : [];
|
|
4187
4781
|
}
|
|
4188
|
-
function isAgentPlanCapability(collection,
|
|
4782
|
+
function isAgentPlanCapability(collection, operation2) {
|
|
4189
4783
|
if (!isAgentPlanCollection(collection)) return false;
|
|
4190
4784
|
return AGENT_PLAN_CAPABILITIES[collection].includes(
|
|
4191
|
-
|
|
4785
|
+
operation2
|
|
4192
4786
|
);
|
|
4193
4787
|
}
|
|
4194
|
-
function assertAgentPlanCapability(collection,
|
|
4195
|
-
if (isAgentPlanCapability(collection,
|
|
4788
|
+
function assertAgentPlanCapability(collection, operation2) {
|
|
4789
|
+
if (isAgentPlanCapability(collection, operation2)) {
|
|
4196
4790
|
return collection;
|
|
4197
4791
|
}
|
|
4198
4792
|
throw agentPlanError(
|
|
4199
4793
|
"UNSUPPORTED_OPERATION",
|
|
4200
|
-
`Operation "${
|
|
4794
|
+
`Operation "${operation2}" is not supported for collection "${collection}" in agent plan mutations.`
|
|
4201
4795
|
);
|
|
4202
4796
|
}
|
|
4203
4797
|
|
|
@@ -4296,11 +4890,11 @@ function parseStoredAgentPlan(raw, planId) {
|
|
|
4296
4890
|
throw agentPlanError("PLAN_MISMATCH", "Stored plan has unsupported collection.");
|
|
4297
4891
|
}
|
|
4298
4892
|
const collection = record.collection;
|
|
4299
|
-
const
|
|
4300
|
-
if (
|
|
4893
|
+
const operation2 = record.operation;
|
|
4894
|
+
if (operation2 !== "create" && operation2 !== "update" && operation2 !== "delete") {
|
|
4301
4895
|
throw agentPlanError("PLAN_MISMATCH", "Stored plan has invalid operation.");
|
|
4302
4896
|
}
|
|
4303
|
-
if (!isAgentPlanCapability(collection,
|
|
4897
|
+
if (!isAgentPlanCapability(collection, operation2)) {
|
|
4304
4898
|
throw agentPlanError(
|
|
4305
4899
|
"PLAN_MISMATCH",
|
|
4306
4900
|
"Stored plan has unsupported collection operation."
|
|
@@ -4318,7 +4912,7 @@ function parseStoredAgentPlan(raw, planId) {
|
|
|
4318
4912
|
return {
|
|
4319
4913
|
planId,
|
|
4320
4914
|
planHash: record.planHash,
|
|
4321
|
-
operation,
|
|
4915
|
+
operation: operation2,
|
|
4322
4916
|
collection,
|
|
4323
4917
|
documentId,
|
|
4324
4918
|
payload,
|
|
@@ -4444,8 +5038,8 @@ function readDocumentUpdatedAt(doc) {
|
|
|
4444
5038
|
const updatedAt = doc.updatedAt;
|
|
4445
5039
|
return typeof updatedAt === "string" && updatedAt.length > 0 ? updatedAt : void 0;
|
|
4446
5040
|
}
|
|
4447
|
-
function assertPlanBaseUpdatedAt(
|
|
4448
|
-
if (
|
|
5041
|
+
function assertPlanBaseUpdatedAt(operation2, baseUpdatedAt) {
|
|
5042
|
+
if (operation2 === "create") {
|
|
4449
5043
|
return;
|
|
4450
5044
|
}
|
|
4451
5045
|
if (!baseUpdatedAt) {
|
|
@@ -4711,7 +5305,7 @@ async function runPlanAction(input) {
|
|
|
4711
5305
|
input.outputOptions
|
|
4712
5306
|
);
|
|
4713
5307
|
}
|
|
4714
|
-
function registerAgentPlanCommands(agent,
|
|
5308
|
+
function registerAgentPlanCommands(agent, getClient) {
|
|
4715
5309
|
const plan = configureAgentParser(
|
|
4716
5310
|
agent.command("plan").description("Plan a mutation without executing")
|
|
4717
5311
|
);
|
|
@@ -4730,7 +5324,7 @@ function registerAgentPlanCommands(agent, getClient2) {
|
|
|
4730
5324
|
dataStdin: opts.dataStdin,
|
|
4731
5325
|
dataFile: opts.dataFile,
|
|
4732
5326
|
outputOptions,
|
|
4733
|
-
getClient
|
|
5327
|
+
getClient
|
|
4734
5328
|
});
|
|
4735
5329
|
} catch (error) {
|
|
4736
5330
|
exitWithAgentError(error, outputOptions);
|
|
@@ -4754,7 +5348,7 @@ function registerAgentPlanCommands(agent, getClient2) {
|
|
|
4754
5348
|
dataStdin: opts.dataStdin,
|
|
4755
5349
|
dataFile: opts.dataFile,
|
|
4756
5350
|
outputOptions,
|
|
4757
|
-
getClient
|
|
5351
|
+
getClient
|
|
4758
5352
|
});
|
|
4759
5353
|
} catch (error) {
|
|
4760
5354
|
exitWithAgentError(error, outputOptions);
|
|
@@ -4776,7 +5370,7 @@ function registerAgentPlanCommands(agent, getClient2) {
|
|
|
4776
5370
|
collection,
|
|
4777
5371
|
documentId: id,
|
|
4778
5372
|
outputOptions,
|
|
4779
|
-
getClient
|
|
5373
|
+
getClient
|
|
4780
5374
|
});
|
|
4781
5375
|
} catch (error) {
|
|
4782
5376
|
exitWithAgentError(error, outputOptions);
|
|
@@ -4800,7 +5394,7 @@ function registerAgentPlanCommands(agent, getClient2) {
|
|
|
4800
5394
|
"Plan token does not match --hash."
|
|
4801
5395
|
);
|
|
4802
5396
|
}
|
|
4803
|
-
const client =
|
|
5397
|
+
const client = getClient();
|
|
4804
5398
|
const authFingerprint = buildAuthContextFingerprint({
|
|
4805
5399
|
publishableKey: client.publishableKey,
|
|
4806
5400
|
secretKey: client.secretKey
|
|
@@ -4915,7 +5509,7 @@ function buildAgentManifest() {
|
|
|
4915
5509
|
...AGENT_READ_OPERATIONS,
|
|
4916
5510
|
...collection === "products" ? AGENT_PRODUCT_OPERATIONS : [],
|
|
4917
5511
|
...getAgentPlanOperations(collection).map(
|
|
4918
|
-
(
|
|
5512
|
+
(operation2) => `plan:${operation2}`
|
|
4919
5513
|
)
|
|
4920
5514
|
];
|
|
4921
5515
|
collections[collection] = {
|
|
@@ -4927,7 +5521,8 @@ function buildAgentManifest() {
|
|
|
4927
5521
|
version: AGENT_PROTOCOL_VERSION,
|
|
4928
5522
|
discovery: {
|
|
4929
5523
|
context: { counts: true },
|
|
4930
|
-
schema: { mode: "effective" }
|
|
5524
|
+
schema: { mode: "effective" },
|
|
5525
|
+
doctor: { appIntegration: true }
|
|
4931
5526
|
},
|
|
4932
5527
|
collections
|
|
4933
5528
|
};
|
|
@@ -4940,9 +5535,9 @@ function validateAgentCollection(collection) {
|
|
|
4940
5535
|
throw invalidInput3(message, "collection", collection);
|
|
4941
5536
|
}
|
|
4942
5537
|
}
|
|
4943
|
-
function registerAgentCommands(
|
|
5538
|
+
function registerAgentCommands(program, getClient) {
|
|
4944
5539
|
const agent = configureAgentParser2(
|
|
4945
|
-
|
|
5540
|
+
program.command("agent").description("Machine-stable CLI namespace for coding agents").option("--pretty", "Print 2-space indented success JSON").option(
|
|
4946
5541
|
"--output-file <path>",
|
|
4947
5542
|
"Write success JSON to a secure file and print a receipt"
|
|
4948
5543
|
).addHelpText(
|
|
@@ -4972,7 +5567,7 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
4972
5567
|
const outputOptions = resolveAgentPrintOptions(command);
|
|
4973
5568
|
try {
|
|
4974
5569
|
validateAgentOutputTarget(outputOptions);
|
|
4975
|
-
const client =
|
|
5570
|
+
const client = getClient();
|
|
4976
5571
|
const result = opts.counts ? await client.tenant.context({ includeCounts: true }) : await client.tenant.context();
|
|
4977
5572
|
printAgentSuccess(result, outputOptions);
|
|
4978
5573
|
} catch (error) {
|
|
@@ -4989,7 +5584,7 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
4989
5584
|
try {
|
|
4990
5585
|
validateAgentOutputTarget(outputOptions);
|
|
4991
5586
|
const col = validateAgentCollection(collection);
|
|
4992
|
-
const client =
|
|
5587
|
+
const client = getClient();
|
|
4993
5588
|
const result = await client.tenant.collectionSchema(col);
|
|
4994
5589
|
printAgentSuccess(result, outputOptions);
|
|
4995
5590
|
} catch (error) {
|
|
@@ -5016,7 +5611,7 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
5016
5611
|
if (page != null) options.page = page;
|
|
5017
5612
|
if (opts.sort) options.sort = opts.sort;
|
|
5018
5613
|
if (opts.select) options.select = parseSelect(opts.select);
|
|
5019
|
-
const client =
|
|
5614
|
+
const client = getClient();
|
|
5020
5615
|
const result = await client.collections.from(col).find(options);
|
|
5021
5616
|
printAgentSuccess(result, outputOptions);
|
|
5022
5617
|
} catch (error) {
|
|
@@ -5040,7 +5635,7 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
5040
5635
|
}
|
|
5041
5636
|
const options = {};
|
|
5042
5637
|
if (opts.select) options.select = parseSelect(opts.select);
|
|
5043
|
-
const client =
|
|
5638
|
+
const client = getClient();
|
|
5044
5639
|
const result = await client.collections.from(col).findById(id, options);
|
|
5045
5640
|
printAgentSuccess(result, outputOptions);
|
|
5046
5641
|
} catch (error) {
|
|
@@ -5062,7 +5657,7 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
5062
5657
|
try {
|
|
5063
5658
|
validateAgentOutputTarget(outputOptions);
|
|
5064
5659
|
const params = productDetailParamsFromOptions(opts);
|
|
5065
|
-
const client =
|
|
5660
|
+
const client = getClient();
|
|
5066
5661
|
const result = await client.commerce.product.detail(params);
|
|
5067
5662
|
printAgentSuccess(result, outputOptions);
|
|
5068
5663
|
} catch (error) {
|
|
@@ -5071,37 +5666,542 @@ function registerAgentCommands(program2, getClient2) {
|
|
|
5071
5666
|
}
|
|
5072
5667
|
)
|
|
5073
5668
|
);
|
|
5074
|
-
registerAgentPlanCommands(agent,
|
|
5669
|
+
registerAgentPlanCommands(agent, getClient);
|
|
5670
|
+
return agent;
|
|
5671
|
+
}
|
|
5672
|
+
|
|
5673
|
+
// src/commands/embedded-app.ts
|
|
5674
|
+
function registerEmbeddedAppCommands(program, getClient, getFormat) {
|
|
5675
|
+
const embeddedApp = program.command("embedded-app").description("Manage the active tenant embedded admin app binding");
|
|
5676
|
+
embeddedApp.command("show").description("Show the active tenant embedded app binding").action(async () => {
|
|
5677
|
+
try {
|
|
5678
|
+
const result = await getClient().embeddedAdmin.show();
|
|
5679
|
+
printResult(result, getFormat());
|
|
5680
|
+
} catch (error) {
|
|
5681
|
+
exitWithError(error);
|
|
5682
|
+
}
|
|
5683
|
+
});
|
|
5684
|
+
embeddedApp.command("configure").description("Configure and enable the active tenant embedded app").requiredOption("--label <label>", "Display label shown in Console").requiredOption("--origin <origin>", "Exact HTTPS app origin").option("--path <path>", "Relative app path", "/").option("--dry-run", "Validate inputs without executing").action(
|
|
5685
|
+
async (options) => {
|
|
5686
|
+
try {
|
|
5687
|
+
const client = getClient();
|
|
5688
|
+
const input = {
|
|
5689
|
+
label: options.label,
|
|
5690
|
+
origin: options.origin,
|
|
5691
|
+
path: options.path
|
|
5692
|
+
};
|
|
5693
|
+
const binding = client.embeddedAdmin.validateConfiguration(input);
|
|
5694
|
+
if (options.dryRun) {
|
|
5695
|
+
printResult(
|
|
5696
|
+
{
|
|
5697
|
+
action: "embedded app configure",
|
|
5698
|
+
binding,
|
|
5699
|
+
dryRun: true,
|
|
5700
|
+
valid: true
|
|
5701
|
+
},
|
|
5702
|
+
getFormat()
|
|
5703
|
+
);
|
|
5704
|
+
return;
|
|
5705
|
+
}
|
|
5706
|
+
const result = await client.embeddedAdmin.configure(input);
|
|
5707
|
+
printResult(result, getFormat());
|
|
5708
|
+
} catch (error) {
|
|
5709
|
+
exitWithError(error);
|
|
5710
|
+
}
|
|
5711
|
+
}
|
|
5712
|
+
);
|
|
5713
|
+
embeddedApp.command("disable").description("Disable the active tenant embedded app binding").option("--dry-run", "Validate without executing").action(async (options) => {
|
|
5714
|
+
try {
|
|
5715
|
+
const client = getClient();
|
|
5716
|
+
client.embeddedAdmin.validateManagementAccess();
|
|
5717
|
+
if (options.dryRun) {
|
|
5718
|
+
printResult(
|
|
5719
|
+
{
|
|
5720
|
+
action: "embedded app disable",
|
|
5721
|
+
dryRun: true,
|
|
5722
|
+
valid: true
|
|
5723
|
+
},
|
|
5724
|
+
getFormat()
|
|
5725
|
+
);
|
|
5726
|
+
return;
|
|
5727
|
+
}
|
|
5728
|
+
const result = await client.embeddedAdmin.disable();
|
|
5729
|
+
printResult(result, getFormat());
|
|
5730
|
+
} catch (error) {
|
|
5731
|
+
exitWithError(error);
|
|
5732
|
+
}
|
|
5733
|
+
});
|
|
5734
|
+
}
|
|
5735
|
+
|
|
5736
|
+
// src/lib/doctor.ts
|
|
5737
|
+
import { existsSync as existsSync2, lstatSync as lstatSync2, readFileSync as readFileSync4 } from "fs";
|
|
5738
|
+
import { createRequire } from "module";
|
|
5739
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
5740
|
+
import { satisfies, validRange } from "semver";
|
|
5741
|
+
import {
|
|
5742
|
+
TenantIntrospectionApi as TenantIntrospectionApi2,
|
|
5743
|
+
TENANT_CONTEXT_PATH
|
|
5744
|
+
} from "@01.software/sdk/server";
|
|
5745
|
+
var PUBLIC_ENV_PREFIXES = [
|
|
5746
|
+
"NEXT_PUBLIC_",
|
|
5747
|
+
"VITE_",
|
|
5748
|
+
"REACT_APP_",
|
|
5749
|
+
"PUBLIC_"
|
|
5750
|
+
];
|
|
5751
|
+
var APP_ENV_PREFIXES = ["", ...PUBLIC_ENV_PREFIXES];
|
|
5752
|
+
var envKey = (prefix, suffix) => `${prefix}${suffix}`;
|
|
5753
|
+
var PUBLISHABLE_KEYS = APP_ENV_PREFIXES.map(
|
|
5754
|
+
(prefix) => envKey(prefix, "SOFTWARE_PUBLISHABLE_KEY")
|
|
5755
|
+
);
|
|
5756
|
+
var SECRET_KEYS = APP_ENV_PREFIXES.map(
|
|
5757
|
+
(prefix) => envKey(prefix, "SOFTWARE_SECRET_KEY")
|
|
5758
|
+
);
|
|
5759
|
+
var SDK_API_URL_KEYS = [
|
|
5760
|
+
"SOFTWARE_API_URL",
|
|
5761
|
+
"NEXT_PUBLIC_SOFTWARE_API_URL"
|
|
5762
|
+
];
|
|
5763
|
+
var DoctorInputError = class extends Error {
|
|
5764
|
+
constructor(field = "envFile") {
|
|
5765
|
+
const message = field === "origin" ? "--origin must be an absolute http(s) URL." : "--app-env-file must name a readable regular environment file.";
|
|
5766
|
+
super(message);
|
|
5767
|
+
Object.assign(this, {
|
|
5768
|
+
type: "validation",
|
|
5769
|
+
code: "invalid_argument",
|
|
5770
|
+
field,
|
|
5771
|
+
detail: {
|
|
5772
|
+
message,
|
|
5773
|
+
field
|
|
5774
|
+
}
|
|
5775
|
+
});
|
|
5776
|
+
this.field = field;
|
|
5777
|
+
}
|
|
5778
|
+
};
|
|
5779
|
+
function doctorInputMessageKey(error) {
|
|
5780
|
+
if (!(error instanceof DoctorInputError)) return void 0;
|
|
5781
|
+
return error.field === "origin" ? "DoctorOriginInputInvalid" : "DoctorEnvFileInvalid";
|
|
5782
|
+
}
|
|
5783
|
+
function statusFromChecks(checks) {
|
|
5784
|
+
if (checks.some((check2) => check2.status === "blocked")) return "blocked";
|
|
5785
|
+
if (checks.some((check2) => check2.status === "attention")) return "attention";
|
|
5786
|
+
return "ready";
|
|
5787
|
+
}
|
|
5788
|
+
function compositeExitCode(checks) {
|
|
5789
|
+
const codes = checks.map((check2) => check2.exitCode).filter((code) => typeof code === "number");
|
|
5790
|
+
for (const preferred of [3, 2, 6, 4, 5, 1]) {
|
|
5791
|
+
if (codes.includes(preferred)) return preferred;
|
|
5792
|
+
}
|
|
5793
|
+
return 0;
|
|
5794
|
+
}
|
|
5795
|
+
function check(id, status, action, exitCode) {
|
|
5796
|
+
return { id, status, action, ...exitCode !== void 0 && { exitCode } };
|
|
5797
|
+
}
|
|
5798
|
+
function readPackage(cwd) {
|
|
5799
|
+
const path2 = join3(cwd, "package.json");
|
|
5800
|
+
if (!existsSync2(path2)) return null;
|
|
5801
|
+
try {
|
|
5802
|
+
const value = JSON.parse(readFileSync4(path2, "utf8"));
|
|
5803
|
+
return value && typeof value === "object" ? value : null;
|
|
5804
|
+
} catch {
|
|
5805
|
+
return null;
|
|
5806
|
+
}
|
|
5807
|
+
}
|
|
5808
|
+
function nodeEngineCheck(engine, nodeVersion = process.versions.node) {
|
|
5809
|
+
if (engine === void 0)
|
|
5810
|
+
return check("node.engine", "attention", "DoctorNodeEngineNotDeclared");
|
|
5811
|
+
if (typeof engine !== "string")
|
|
5812
|
+
return check("node.engine", "attention", "DoctorNodeEngineAttention");
|
|
5813
|
+
const range = validRange(engine);
|
|
5814
|
+
if (!range)
|
|
5815
|
+
return check("node.engine", "attention", "DoctorNodeEngineAttention");
|
|
5816
|
+
return satisfies(nodeVersion, range) ? check("node.engine", "ready", "DoctorNodeEngineReady") : check("node.engine", "attention", "DoctorNodeEngineAttention");
|
|
5817
|
+
}
|
|
5818
|
+
function parseEnv(content, file) {
|
|
5819
|
+
const declarations = [];
|
|
5820
|
+
for (const line of content.split(/\r?\n/)) {
|
|
5821
|
+
const match = line.match(
|
|
5822
|
+
/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/
|
|
5823
|
+
);
|
|
5824
|
+
if (!match) continue;
|
|
5825
|
+
let value = match[2] ?? "";
|
|
5826
|
+
if (value.length >= 2 && (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'"))) {
|
|
5827
|
+
value = value.slice(1, -1);
|
|
5828
|
+
} else {
|
|
5829
|
+
value = value.replace(/\s+#.*$/, "");
|
|
5830
|
+
}
|
|
5831
|
+
declarations.push({ key: match[1], value: value.trim(), file });
|
|
5832
|
+
}
|
|
5833
|
+
return declarations;
|
|
5834
|
+
}
|
|
5835
|
+
function readEnvFile(file) {
|
|
5836
|
+
try {
|
|
5837
|
+
if (!lstatSync2(file).isFile()) return null;
|
|
5838
|
+
return parseEnv(readFileSync4(file, "utf8"), file);
|
|
5839
|
+
} catch {
|
|
5840
|
+
return null;
|
|
5841
|
+
}
|
|
5842
|
+
}
|
|
5843
|
+
function existsIncludingSymlink(file) {
|
|
5844
|
+
try {
|
|
5845
|
+
lstatSync2(file);
|
|
5846
|
+
return true;
|
|
5847
|
+
} catch {
|
|
5848
|
+
return false;
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
function resolveEnv(declarations) {
|
|
5852
|
+
const values = /* @__PURE__ */ new Map();
|
|
5853
|
+
const ambiguousKeys = /* @__PURE__ */ new Set();
|
|
5854
|
+
const declaredInFile = /* @__PURE__ */ new Set();
|
|
5855
|
+
for (const declaration of declarations) {
|
|
5856
|
+
const identity = `${declaration.file}\0${declaration.key}`;
|
|
5857
|
+
if (declaredInFile.has(identity)) ambiguousKeys.add(declaration.key);
|
|
5858
|
+
declaredInFile.add(identity);
|
|
5859
|
+
values.set(declaration.key, declaration);
|
|
5860
|
+
}
|
|
5861
|
+
return { values, ambiguousKeys, invalid: false };
|
|
5862
|
+
}
|
|
5863
|
+
function envFilesForPackage(pkg) {
|
|
5864
|
+
const deps = {
|
|
5865
|
+
...pkg?.dependencies ?? {},
|
|
5866
|
+
...pkg?.devDependencies ?? {}
|
|
5867
|
+
};
|
|
5868
|
+
if ("next" in deps || "react-scripts" in deps) {
|
|
5869
|
+
return [".env", ".env.development", ".env.local", ".env.development.local"];
|
|
5870
|
+
}
|
|
5871
|
+
if ("vite" in deps) {
|
|
5872
|
+
return [".env", ".env.local", ".env.development", ".env.development.local"];
|
|
5873
|
+
}
|
|
5874
|
+
return [".env", ".env.local"];
|
|
5875
|
+
}
|
|
5876
|
+
function readDoctorEnv(cwd, pkg, explicit) {
|
|
5877
|
+
if (explicit !== void 0) {
|
|
5878
|
+
const file = resolve2(cwd, explicit);
|
|
5879
|
+
const declarations2 = readEnvFile(file);
|
|
5880
|
+
if (!declarations2) throw new DoctorInputError();
|
|
5881
|
+
return resolveEnv(declarations2);
|
|
5882
|
+
}
|
|
5883
|
+
const declarations = [];
|
|
5884
|
+
let found = false;
|
|
5885
|
+
for (const name of envFilesForPackage(pkg)) {
|
|
5886
|
+
const file = join3(cwd, name);
|
|
5887
|
+
if (!existsIncludingSymlink(file)) continue;
|
|
5888
|
+
found = true;
|
|
5889
|
+
const parsed = readEnvFile(file);
|
|
5890
|
+
if (!parsed)
|
|
5891
|
+
return { values: /* @__PURE__ */ new Map(), ambiguousKeys: /* @__PURE__ */ new Set(), invalid: true };
|
|
5892
|
+
declarations.push(...parsed);
|
|
5893
|
+
}
|
|
5894
|
+
return found ? resolveEnv(declarations) : null;
|
|
5895
|
+
}
|
|
5896
|
+
function normalizeOrigin(origin) {
|
|
5897
|
+
try {
|
|
5898
|
+
const value = new URL(origin);
|
|
5899
|
+
if (value.protocol !== "http:" && value.protocol !== "https:" || value.username || value.password || value.origin === "null") {
|
|
5900
|
+
throw new TypeError("invalid origin");
|
|
5901
|
+
}
|
|
5902
|
+
return value.origin;
|
|
5903
|
+
} catch {
|
|
5904
|
+
throw new DoctorInputError("origin");
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
function resolveDoctorApiUrl(env) {
|
|
5908
|
+
const buildDefault = true ? "https://api.01.software" : "https://api.01.software";
|
|
5909
|
+
const configured = SDK_API_URL_KEYS.map(
|
|
5910
|
+
(key) => env.values.get(key)?.value
|
|
5911
|
+
).find((value2) => Boolean(value2));
|
|
5912
|
+
const value = configured ?? buildDefault;
|
|
5913
|
+
try {
|
|
5914
|
+
return new URL(value).toString().replace(/\/$/, "");
|
|
5915
|
+
} catch {
|
|
5916
|
+
return null;
|
|
5917
|
+
}
|
|
5918
|
+
}
|
|
5919
|
+
function inspectAppCredentials(declarations) {
|
|
5920
|
+
if (!declarations || declarations.invalid) {
|
|
5921
|
+
return {
|
|
5922
|
+
credential: { ok: false },
|
|
5923
|
+
check: check(
|
|
5924
|
+
"env.app-credentials",
|
|
5925
|
+
"blocked",
|
|
5926
|
+
declarations?.invalid ? "DoctorEnvFileInvalid" : "DoctorEnvCredentialsBlocked",
|
|
5927
|
+
3
|
|
5928
|
+
)
|
|
5929
|
+
};
|
|
5930
|
+
}
|
|
5931
|
+
const publicSecret = SECRET_KEYS.slice(1).some(
|
|
5932
|
+
(key) => declarations.values.has(key)
|
|
5933
|
+
);
|
|
5934
|
+
const publishable = PUBLISHABLE_KEYS.map(
|
|
5935
|
+
(key) => declarations.values.get(key)
|
|
5936
|
+
).filter((value) => value !== void 0);
|
|
5937
|
+
const secret = declarations.values.get("SOFTWARE_SECRET_KEY");
|
|
5938
|
+
const ambiguous = [
|
|
5939
|
+
...PUBLISHABLE_KEYS,
|
|
5940
|
+
...SECRET_KEYS,
|
|
5941
|
+
...SDK_API_URL_KEYS
|
|
5942
|
+
].some((key) => declarations.ambiguousKeys.has(key));
|
|
5943
|
+
const publishableKey = publishable[0]?.value ?? "";
|
|
5944
|
+
const secretKey = secret?.value ?? "";
|
|
5945
|
+
const apiUrl = resolveDoctorApiUrl(declarations);
|
|
5946
|
+
if (publicSecret || ambiguous || publishable.length !== 1 || !secret || !publishableKey || !secretKey || !publishableKey.startsWith("pk01_") || !/^sk01_[a-f0-9]{40}$/.test(secretKey) || !apiUrl) {
|
|
5947
|
+
return {
|
|
5948
|
+
credential: { ok: false },
|
|
5949
|
+
check: check(
|
|
5950
|
+
"env.app-credentials",
|
|
5951
|
+
"blocked",
|
|
5952
|
+
"DoctorEnvCredentialsBlocked",
|
|
5953
|
+
3
|
|
5954
|
+
)
|
|
5955
|
+
};
|
|
5956
|
+
}
|
|
5957
|
+
return {
|
|
5958
|
+
credential: { ok: true, publishableKey, secretKey, apiUrl },
|
|
5959
|
+
check: check("env.app-credentials", "ready", "DoctorEnvCredentialsReady")
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
async function defaultOriginProbe(input) {
|
|
5963
|
+
try {
|
|
5964
|
+
const response = await fetch(new URL(TENANT_CONTEXT_PATH, input.apiUrl), {
|
|
5965
|
+
method: "OPTIONS",
|
|
5966
|
+
signal: AbortSignal.timeout(1e4),
|
|
5967
|
+
credentials: "omit",
|
|
5968
|
+
headers: {
|
|
5969
|
+
Origin: input.origin,
|
|
5970
|
+
"X-Publishable-Key": input.publishableKey,
|
|
5971
|
+
"Access-Control-Request-Method": "GET",
|
|
5972
|
+
"Access-Control-Request-Headers": "x-publishable-key"
|
|
5973
|
+
}
|
|
5974
|
+
});
|
|
5975
|
+
if (response.status === 403) return "denied";
|
|
5976
|
+
if (!response.ok || response.status === 408 || response.status === 429 || response.status === 404 || response.status >= 500) {
|
|
5977
|
+
return "indeterminate";
|
|
5978
|
+
}
|
|
5979
|
+
const allowedOrigin = response.headers.get("access-control-allow-origin");
|
|
5980
|
+
const allowsCredentials = response.headers.get("access-control-allow-credentials")?.toLowerCase() === "true";
|
|
5981
|
+
if (allowedOrigin === input.origin) return "allowed";
|
|
5982
|
+
if (allowedOrigin === "*" && !allowsCredentials) return "allowed";
|
|
5983
|
+
return "denied";
|
|
5984
|
+
} catch {
|
|
5985
|
+
return "indeterminate";
|
|
5986
|
+
}
|
|
5987
|
+
}
|
|
5988
|
+
async function runDoctor(options = {}) {
|
|
5989
|
+
const cwd = options.cwd ?? process.cwd();
|
|
5990
|
+
const origin = options.origin === void 0 ? void 0 : normalizeOrigin(options.origin);
|
|
5991
|
+
const checks = [];
|
|
5992
|
+
const pkg = readPackage(cwd);
|
|
5993
|
+
checks.push(
|
|
5994
|
+
pkg ? check("project.package-json", "ready", "DoctorProjectPackageJsonReady") : check(
|
|
5995
|
+
"project.package-json",
|
|
5996
|
+
"blocked",
|
|
5997
|
+
"DoctorProjectPackageJsonBlocked",
|
|
5998
|
+
3
|
|
5999
|
+
)
|
|
6000
|
+
);
|
|
6001
|
+
const engine = pkg?.engines?.node;
|
|
6002
|
+
checks.push(nodeEngineCheck(engine));
|
|
6003
|
+
const deps = {
|
|
6004
|
+
...pkg?.dependencies ?? {},
|
|
6005
|
+
...pkg?.devDependencies ?? {}
|
|
6006
|
+
};
|
|
6007
|
+
checks.push(
|
|
6008
|
+
"@01.software/sdk" in deps ? check("sdk.declaration", "ready", "DoctorSdkDeclarationReady") : check("sdk.declaration", "blocked", "DoctorSdkDeclarationBlocked", 3)
|
|
6009
|
+
);
|
|
6010
|
+
let sdkInstalled = false;
|
|
6011
|
+
try {
|
|
6012
|
+
createRequire(join3(cwd, "package.json")).resolve("@01.software/sdk/server");
|
|
6013
|
+
sdkInstalled = true;
|
|
6014
|
+
} catch {
|
|
6015
|
+
}
|
|
6016
|
+
checks.push(
|
|
6017
|
+
sdkInstalled ? check("sdk.installation", "ready", "DoctorSdkInstallationReady") : check(
|
|
6018
|
+
"sdk.installation",
|
|
6019
|
+
"attention",
|
|
6020
|
+
"DoctorSdkInstallationAttention"
|
|
6021
|
+
)
|
|
6022
|
+
);
|
|
6023
|
+
const inspected = inspectAppCredentials(
|
|
6024
|
+
readDoctorEnv(cwd, pkg, options.envFile)
|
|
6025
|
+
);
|
|
6026
|
+
checks.push(inspected.check);
|
|
6027
|
+
if (inspected.credential.ok) {
|
|
6028
|
+
const { publishableKey, secretKey, apiUrl } = inspected.credential;
|
|
6029
|
+
try {
|
|
6030
|
+
if (options.tenantContext) {
|
|
6031
|
+
await options.tenantContext({ publishableKey, secretKey, apiUrl });
|
|
6032
|
+
} else {
|
|
6033
|
+
await new TenantIntrospectionApi2({
|
|
6034
|
+
publishableKey,
|
|
6035
|
+
secretKey,
|
|
6036
|
+
apiUrl
|
|
6037
|
+
}).context();
|
|
6038
|
+
}
|
|
6039
|
+
checks.push(check("tenant.context", "ready", "DoctorTenantContextReady"));
|
|
6040
|
+
} catch (error) {
|
|
6041
|
+
checks.push(
|
|
6042
|
+
check(
|
|
6043
|
+
"tenant.context",
|
|
6044
|
+
"blocked",
|
|
6045
|
+
"DoctorTenantContextBlocked",
|
|
6046
|
+
getExitCode(error)
|
|
6047
|
+
)
|
|
6048
|
+
);
|
|
6049
|
+
}
|
|
6050
|
+
if (origin) {
|
|
6051
|
+
const outcome = await (options.originProbe ?? defaultOriginProbe)({
|
|
6052
|
+
origin,
|
|
6053
|
+
apiUrl,
|
|
6054
|
+
publishableKey
|
|
6055
|
+
});
|
|
6056
|
+
checks.push(
|
|
6057
|
+
outcome === "allowed" ? check("origin.cors", "ready", "DoctorOriginCorsReady") : outcome === "denied" ? check("origin.cors", "blocked", "DoctorOriginCorsBlocked", 2) : check("origin.cors", "attention", "DoctorOriginCorsAttention")
|
|
6058
|
+
);
|
|
6059
|
+
}
|
|
6060
|
+
} else {
|
|
6061
|
+
checks.push(
|
|
6062
|
+
check("tenant.context", "blocked", "DoctorTenantContextBlocked", 3)
|
|
6063
|
+
);
|
|
6064
|
+
if (origin)
|
|
6065
|
+
checks.push(
|
|
6066
|
+
check("origin.cors", "attention", "DoctorOriginCorsAttention")
|
|
6067
|
+
);
|
|
6068
|
+
}
|
|
6069
|
+
return {
|
|
6070
|
+
version: 1,
|
|
6071
|
+
status: statusFromChecks(checks),
|
|
6072
|
+
exitCode: compositeExitCode(checks),
|
|
6073
|
+
checks
|
|
6074
|
+
};
|
|
6075
|
+
}
|
|
6076
|
+
function actionText(key, locale) {
|
|
6077
|
+
const table = locale === "ko" ? CLI_I18N_KO : CLI_I18N_EN;
|
|
6078
|
+
return table[key];
|
|
6079
|
+
}
|
|
6080
|
+
function doctorHumanLines(result, locale) {
|
|
6081
|
+
const copy = locale === "ko" ? {
|
|
6082
|
+
status: "\uC0C1\uD0DC",
|
|
6083
|
+
ready: "\uC900\uBE44\uB428",
|
|
6084
|
+
attention: "\uD655\uC778 \uD544\uC694",
|
|
6085
|
+
blocked: "\uCC28\uB2E8\uB428"
|
|
6086
|
+
} : {
|
|
6087
|
+
status: "Status",
|
|
6088
|
+
ready: "ready",
|
|
6089
|
+
attention: "attention",
|
|
6090
|
+
blocked: "blocked"
|
|
6091
|
+
};
|
|
6092
|
+
return [
|
|
6093
|
+
`${copy.status}: ${copy[result.status]}`,
|
|
6094
|
+
...result.checks.map(
|
|
6095
|
+
(item) => `[${copy[item.status]}] ${item.id}: ${actionText(item.action, locale)}`
|
|
6096
|
+
)
|
|
6097
|
+
];
|
|
6098
|
+
}
|
|
6099
|
+
|
|
6100
|
+
// src/commands/doctor.ts
|
|
6101
|
+
function selectedHumanFormat(command) {
|
|
6102
|
+
const options = command.optsWithGlobals();
|
|
6103
|
+
return options.format ?? process.env.OUTPUT_FORMAT;
|
|
6104
|
+
}
|
|
6105
|
+
function registerDoctorCommands(program, agent) {
|
|
6106
|
+
program.command("doctor").description("Check local app integration without exposing credentials").option("--app-env-file <path>", "Read one explicit app environment file").option("--origin <origin>", "Optionally probe one browser origin for CORS").action(async (options, command) => {
|
|
6107
|
+
const format = selectedHumanFormat(command);
|
|
6108
|
+
try {
|
|
6109
|
+
const result = await runDoctor({
|
|
6110
|
+
envFile: options.appEnvFile,
|
|
6111
|
+
origin: options.origin
|
|
6112
|
+
});
|
|
6113
|
+
if (format === "json") {
|
|
6114
|
+
printJson(result);
|
|
6115
|
+
} else if (format === "ndjson") {
|
|
6116
|
+
printResult(result, "ndjson");
|
|
6117
|
+
} else {
|
|
6118
|
+
for (const line of doctorHumanLines(result, detectLocale()))
|
|
6119
|
+
console.log(line);
|
|
6120
|
+
}
|
|
6121
|
+
process.exitCode = result.exitCode;
|
|
6122
|
+
} catch (error) {
|
|
6123
|
+
printError(error, {
|
|
6124
|
+
format: format ?? "table",
|
|
6125
|
+
headlineKey: doctorInputMessageKey(error)
|
|
6126
|
+
});
|
|
6127
|
+
process.exitCode = getExitCode(error);
|
|
6128
|
+
}
|
|
6129
|
+
});
|
|
6130
|
+
configureAgentParser2(
|
|
6131
|
+
agent.command("doctor").description("Check local app integration with stable JSON output").option("--app-env-file <path>", "Read one explicit app environment file").option(
|
|
6132
|
+
"--origin <origin>",
|
|
6133
|
+
"Optionally probe one browser origin for CORS"
|
|
6134
|
+
).option("--pretty", "Print 2-space indented success JSON").option(
|
|
6135
|
+
"--output-file <path>",
|
|
6136
|
+
"Write success JSON to a secure file and print a receipt"
|
|
6137
|
+
).action(async (options, command) => {
|
|
6138
|
+
const output = resolveAgentPrintOptions(command);
|
|
6139
|
+
try {
|
|
6140
|
+
validateAgentOutputTarget(output);
|
|
6141
|
+
const result = await runDoctor({
|
|
6142
|
+
envFile: options.appEnvFile,
|
|
6143
|
+
origin: options.origin
|
|
6144
|
+
});
|
|
6145
|
+
printAgentSuccess(result, output);
|
|
6146
|
+
process.exitCode = 0;
|
|
6147
|
+
} catch (error) {
|
|
6148
|
+
const envelope = printAgentError(error, output);
|
|
6149
|
+
process.exitCode = agentErrorExitCode(envelope.error.code);
|
|
6150
|
+
}
|
|
6151
|
+
})
|
|
6152
|
+
);
|
|
5075
6153
|
}
|
|
5076
6154
|
|
|
5077
6155
|
// src/index.ts
|
|
5078
|
-
var require2 =
|
|
6156
|
+
var require2 = createRequire2(import.meta.url);
|
|
5079
6157
|
var { version } = require2("../package.json");
|
|
5080
|
-
|
|
5081
|
-
program
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
registerCrudCommands(program, getClient, getFormat);
|
|
5095
|
-
registerOrderCommands(program, getClient, getFormat);
|
|
5096
|
-
registerReturnCommands(program, getClient, getFormat);
|
|
5097
|
-
registerCartCommands(program, getClient, getFormat);
|
|
5098
|
-
registerStockCommands(program, getClient, getFormat);
|
|
5099
|
-
registerCommerceSessionCommands(program, getClient, getFormat);
|
|
5100
|
-
registerProductCommands(program, getClient, getFormat);
|
|
5101
|
-
registerDiscountCommands(program, getClient, getFormat);
|
|
5102
|
-
registerShippingCommands(program, getClient, getFormat);
|
|
5103
|
-
registerSchemaCommands(program, getClient, getFormat);
|
|
5104
|
-
registerFeatureCommands(program, getClient, getFormat);
|
|
5105
|
-
|
|
5106
|
-
program
|
|
6158
|
+
function createCliProgram() {
|
|
6159
|
+
const program = new Command();
|
|
6160
|
+
program.name("01").description("CLI for the 01.software platform").version(version).option("--api-key <key>", "API key (sk01_... or pat01_... token)").option("--format <format>", "Output format: json, table, or ndjson").option("--lang <locale>", "Force locale (ko or en)");
|
|
6161
|
+
const getFormat = () => program.opts().format ?? process.env.OUTPUT_FORMAT ?? "json";
|
|
6162
|
+
program.hook("preAction", () => {
|
|
6163
|
+
const lang = program.opts().lang;
|
|
6164
|
+
if (lang === "ko" || lang === "en") setLocale(lang);
|
|
6165
|
+
const format = program.opts().format;
|
|
6166
|
+
if (format) process.env.OUTPUT_FORMAT = format;
|
|
6167
|
+
});
|
|
6168
|
+
const getClient = () => resolveClient(program.opts().apiKey);
|
|
6169
|
+
const getAgentClient = () => resolveClientOrThrow(program.opts().apiKey);
|
|
6170
|
+
const agent = registerAgentCommands(program, getAgentClient);
|
|
6171
|
+
registerDoctorCommands(program, agent);
|
|
6172
|
+
registerCrudCommands(program, getClient, getFormat);
|
|
6173
|
+
registerOrderCommands(program, getClient, getFormat);
|
|
6174
|
+
registerReturnCommands(program, getClient, getFormat);
|
|
6175
|
+
registerCartCommands(program, getClient, getFormat);
|
|
6176
|
+
registerStockCommands(program, getClient, getFormat);
|
|
6177
|
+
registerCommerceSessionCommands(program, getClient, getFormat);
|
|
6178
|
+
registerProductCommands(program, getClient, getFormat);
|
|
6179
|
+
registerDiscountCommands(program, getClient, getFormat);
|
|
6180
|
+
registerShippingCommands(program, getClient, getFormat);
|
|
6181
|
+
registerSchemaCommands(program, getClient, getFormat);
|
|
6182
|
+
registerFeatureCommands(program, getClient, getFormat);
|
|
6183
|
+
registerEmbeddedAppCommands(program, getClient, getFormat);
|
|
6184
|
+
registerAuthCommands(program);
|
|
6185
|
+
return program;
|
|
6186
|
+
}
|
|
6187
|
+
function isDirectExecution() {
|
|
6188
|
+
if (process.argv[1] === void 0) return false;
|
|
6189
|
+
try {
|
|
6190
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
6191
|
+
} catch {
|
|
6192
|
+
return false;
|
|
6193
|
+
}
|
|
6194
|
+
}
|
|
6195
|
+
if (isDirectExecution()) {
|
|
6196
|
+
const program = createCliProgram();
|
|
6197
|
+
process.on("unhandledRejection", (err) => {
|
|
6198
|
+
exitWithError(err, {
|
|
6199
|
+
format: program.opts().format ?? process.env.OUTPUT_FORMAT ?? "json"
|
|
6200
|
+
});
|
|
6201
|
+
});
|
|
6202
|
+
program.parse();
|
|
6203
|
+
}
|
|
6204
|
+
export {
|
|
6205
|
+
createCliProgram
|
|
6206
|
+
};
|
|
5107
6207
|
//# sourceMappingURL=index.js.map
|