@adobe/aio-commerce-lib-app 1.6.0 → 1.8.0-beta-20260714082406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/dist/cjs/actions/app-config/index.cjs +205 -0
- package/dist/cjs/actions/{app-config.d.cts → app-config/index.d.cts} +10 -7
- package/dist/cjs/actions/association/index.cjs +85 -0
- package/dist/cjs/actions/association/index.d.cts +28 -0
- package/dist/cjs/actions/{config.cjs → config/index.cjs} +70 -53
- package/dist/{es/actions/config.d.mts → cjs/actions/config/index.d.cts} +10 -7
- package/dist/cjs/actions/{installation.cjs → installation/index.cjs} +106 -72
- package/dist/{es/actions/installation.d.mts → cjs/actions/installation/index.d.cts} +10 -8
- package/dist/cjs/actions/{scope-tree.cjs → scope-tree/index.cjs} +60 -22
- package/dist/cjs/actions/{scope-tree.d.cts → scope-tree/index.d.cts} +1 -1
- package/dist/cjs/app-D3P-Z6uY.d.cts +1679 -0
- package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
- package/dist/cjs/commands/index.cjs +517 -309
- package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
- package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
- package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
- package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
- package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
- package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
- package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
- package/dist/cjs/config/index.browser.cjs +18 -0
- package/dist/cjs/config/index.browser.d.cts +16 -0
- package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
- package/dist/cjs/config/index.node.d.cts +1603 -0
- package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
- package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
- package/dist/cjs/environment-B7EnozSg.cjs +135 -0
- package/dist/cjs/index-BXm8UbK7.d.cts +16 -0
- package/dist/cjs/{index-Dw2NvVOY.d.cts → index-CzReNwbF.d.cts} +177 -3
- package/dist/cjs/index.cjs +250 -0
- package/dist/cjs/index.d.cts +217 -0
- package/dist/cjs/{config-FNMclIFO.cjs → index.node-Dz4lV4qe.cjs} +119 -35
- package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
- package/dist/cjs/management/index.cjs +1 -1
- package/dist/cjs/management/index.d.cts +1 -2
- package/dist/cjs/{management-Cvsz4VMf.cjs → management-B9ItB80R.cjs} +432 -591
- package/dist/cjs/openapi-CwytYdWl.cjs +2948 -0
- package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
- package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
- package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
- package/dist/cjs/{validate-DydOAZha.cjs → validate-BfxhZ5Wv.cjs} +63 -31
- package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
- package/dist/es/actions/{app-config.d.mts → app-config/index.d.mts} +10 -7
- package/dist/es/actions/app-config/index.mjs +202 -0
- package/dist/es/actions/association/index.d.mts +28 -0
- package/dist/es/actions/association/index.mjs +82 -0
- package/dist/{cjs/actions/config.d.cts → es/actions/config/index.d.mts} +10 -7
- package/dist/es/actions/{config.mjs → config/index.mjs} +67 -50
- package/dist/{cjs/actions/installation.d.cts → es/actions/installation/index.d.mts} +10 -8
- package/dist/es/actions/{installation.mjs → installation/index.mjs} +104 -71
- package/dist/es/actions/{scope-tree.d.mts → scope-tree/index.d.mts} +1 -1
- package/dist/es/actions/{scope-tree.mjs → scope-tree/index.mjs} +58 -20
- package/dist/es/app-D3P-Z6uY.d.mts +1679 -0
- package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
- package/dist/es/commands/index.mjs +550 -340
- package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
- package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
- package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
- package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
- package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
- package/dist/es/commands/templates/app-management/association.js.template +6 -0
- package/dist/es/commands/templates/app-management/installation.js.template +1 -13
- package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
- package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
- package/dist/es/config/index.browser.d.mts +16 -0
- package/dist/es/config/index.browser.mjs +17 -0
- package/dist/es/config/index.node.d.mts +1604 -0
- package/dist/es/config/index.node.mjs +20 -0
- package/dist/es/define-EoYRZbpe.d.mts +34 -0
- package/dist/es/define-Z_Glf1-_.mjs +35 -0
- package/dist/es/environment-C84BPRJZ.mjs +104 -0
- package/dist/es/index-B0XqHwY5.d.mts +16 -0
- package/dist/es/{index-Bo0tQsVq.d.mts → index-D52xglhZ.d.mts} +177 -3
- package/dist/es/index.d.mts +217 -0
- package/dist/es/index.mjs +242 -0
- package/dist/es/{config-CcE0EBG7.mjs → index.node-CDH5gwJE.mjs} +94 -30
- package/dist/es/management/index.d.mts +1 -2
- package/dist/es/management/index.mjs +1 -1
- package/dist/es/{management-BZ4Y6lVp.mjs → management-B89ApQVY.mjs} +402 -562
- package/dist/es/openapi-CXonvevE.mjs +2900 -0
- package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
- package/dist/es/utils-_gj8L6eN.mjs +289 -0
- package/dist/es/{validate-Du3LhCre.mjs → validate-9cRZWGrA.mjs} +49 -29
- package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
- package/package.json +52 -22
- package/dist/cjs/actions/app-config.cjs +0 -54
- package/dist/cjs/actions/registration.cjs +0 -40
- package/dist/cjs/actions/registration.d.cts +0 -32
- package/dist/cjs/admin-ui-sdk-DZZJCrdT.d.cts +0 -665
- package/dist/cjs/app-CakwxQvs.d.cts +0 -673
- package/dist/cjs/config/index.d.cts +0 -1975
- package/dist/cjs/step-CKVE0aJi.d.cts +0 -187
- package/dist/es/actions/app-config.mjs +0 -53
- package/dist/es/actions/registration.d.mts +0 -32
- package/dist/es/actions/registration.mjs +0 -39
- package/dist/es/admin-ui-sdk-hu6iWr0A.d.mts +0 -667
- package/dist/es/app-CakwxQvs.d.mts +0 -673
- package/dist/es/config/index.d.mts +0 -1975
- package/dist/es/config/index.mjs +0 -19
- package/dist/es/step-D64mMPrt.d.mts +0 -187
- /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { t as
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
15
|
+
import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
|
|
16
|
+
import { t as validateCommerceAppConfig } from "../../validate-9cRZWGrA.mjs";
|
|
17
|
+
import { a as runValidation, c as isFailedState, i as runUninstallation, l as isInProgressState, n as createInitialUninstallationState, r as runInstallation, s as isCompletedState, t as createInitialInstallationState, u as isSucceededState } from "../../management-B89ApQVY.mjs";
|
|
18
|
+
import { n as logger, t as HttpActionRouter } from "../../router-B_h0cvjc.mjs";
|
|
19
|
+
import { init } from "@adobe/aio-lib-state";
|
|
20
20
|
import * as v from "valibot";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { init as init$1 } from "@adobe/aio-lib-
|
|
21
|
+
import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
|
|
22
|
+
import { accepted, badRequest, conflict, internalServerError, noContent, ok } from "@adobe/aio-commerce-lib-core/responses";
|
|
23
|
+
import { init as init$1 } from "@adobe/aio-lib-files";
|
|
24
24
|
import openwhisk from "openwhisk";
|
|
25
25
|
|
|
26
26
|
//#region ../../packages-private/common-utils/source/storage/files-store.ts
|
|
@@ -52,12 +52,15 @@ const DEFAULT_DIR_PREFIX = "store";
|
|
|
52
52
|
*/
|
|
53
53
|
async function createFilesStore(options = {}) {
|
|
54
54
|
const { dirPrefix = DEFAULT_DIR_PREFIX } = options;
|
|
55
|
-
|
|
55
|
+
const files = await init$1();
|
|
56
|
+
return new FilesStore(files, dirPrefix);
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* Key-value store implementation using @adobe/aio-lib-files.
|
|
59
60
|
*/
|
|
60
61
|
var FilesStore = class {
|
|
62
|
+
files;
|
|
63
|
+
dirPrefix;
|
|
61
64
|
constructor(files, dirPrefix) {
|
|
62
65
|
this.files = files;
|
|
63
66
|
this.dirPrefix = dirPrefix;
|
|
@@ -122,12 +125,16 @@ const DEFAULT_KEY_PREFIX = "store";
|
|
|
122
125
|
*/
|
|
123
126
|
async function createStateStore(options = {}) {
|
|
124
127
|
const { keyPrefix = DEFAULT_KEY_PREFIX, ttlSeconds = DEFAULT_TTL_SECONDS } = options;
|
|
125
|
-
|
|
128
|
+
const state = await init();
|
|
129
|
+
return new StateStore(state, keyPrefix, ttlSeconds);
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
132
|
* Key-value store implementation using @adobe/aio-lib-state.
|
|
129
133
|
*/
|
|
130
134
|
var StateStore = class {
|
|
135
|
+
state;
|
|
136
|
+
keyPrefix;
|
|
137
|
+
ttlSeconds;
|
|
131
138
|
constructor(state, keyPrefix, ttlSeconds) {
|
|
132
139
|
this.state = state;
|
|
133
140
|
this.keyPrefix = keyPrefix;
|
|
@@ -217,6 +224,9 @@ async function createCombinedStore(options = {}) {
|
|
|
217
224
|
* Uses lib-state for cache and lib-files for persistence.
|
|
218
225
|
*/
|
|
219
226
|
var CombinedStore = class {
|
|
227
|
+
cache;
|
|
228
|
+
persistent;
|
|
229
|
+
shouldPersist;
|
|
220
230
|
constructor(cache, persistent, shouldPersist) {
|
|
221
231
|
this.cache = cache;
|
|
222
232
|
this.persistent = persistent;
|
|
@@ -237,7 +247,7 @@ var CombinedStore = class {
|
|
|
237
247
|
if (!this.shouldPersist || this.shouldPersist(data)) await this.persistent.put(key, data);
|
|
238
248
|
}
|
|
239
249
|
async delete(key) {
|
|
240
|
-
const [cacheDeleted, persistentDeleted] = await Promise.all([this.cache.delete
|
|
250
|
+
const [cacheDeleted, persistentDeleted] = await Promise.all([this.cache.delete(key), this.persistent.delete(key)]);
|
|
241
251
|
return cacheDeleted || persistentDeleted;
|
|
242
252
|
}
|
|
243
253
|
};
|
|
@@ -257,16 +267,19 @@ const AppDataSchema = v.object({
|
|
|
257
267
|
});
|
|
258
268
|
|
|
259
269
|
//#endregion
|
|
260
|
-
//#region source/actions/installation.ts
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const InstallationRequestBodySchema = object({
|
|
270
|
+
//#region source/actions/installation/schema.ts
|
|
271
|
+
/** Request body for POST / and POST /validation (shared shape) */
|
|
272
|
+
const InstallationRequestBodySchema = v.object({
|
|
264
273
|
appData: AppDataSchema,
|
|
265
|
-
commerceBaseUrl: string(),
|
|
266
|
-
commerceEnv:
|
|
267
|
-
|
|
268
|
-
|
|
274
|
+
commerceBaseUrl: v.string(),
|
|
275
|
+
commerceEnv: CommerceEnvSchema,
|
|
276
|
+
ioEventsEnv: v.string(),
|
|
277
|
+
ioEventsUrl: v.string()
|
|
269
278
|
});
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region source/actions/installation/router.ts
|
|
282
|
+
const DEFAULT_ACTION_NAME = "app-management/installation";
|
|
270
283
|
/** Creates a workflow state store with the given prefix. */
|
|
271
284
|
function createWorkflowStore(prefix) {
|
|
272
285
|
return createCombinedStore({
|
|
@@ -296,11 +309,11 @@ function getStorageKey() {
|
|
|
296
309
|
function buildWorkflowParams(body, rawParams) {
|
|
297
310
|
return {
|
|
298
311
|
...rawParams,
|
|
299
|
-
appData: body.appData,
|
|
300
|
-
AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
|
|
301
|
-
AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
|
|
302
312
|
AIO_COMMERCE_API_BASE_URL: body.commerceBaseUrl,
|
|
303
|
-
AIO_COMMERCE_API_FLAVOR: body.commerceEnv
|
|
313
|
+
AIO_COMMERCE_API_FLAVOR: body.commerceEnv,
|
|
314
|
+
AIO_COMMERCE_AUTH_IMS_ENVIRONMENT: body.ioEventsEnv,
|
|
315
|
+
AIO_EVENTS_API_BASE_URL: body.ioEventsUrl,
|
|
316
|
+
appData: body.appData
|
|
304
317
|
};
|
|
305
318
|
}
|
|
306
319
|
/**
|
|
@@ -310,9 +323,9 @@ function buildWorkflowParams(body, rawParams) {
|
|
|
310
323
|
function buildInstallationContext(params, appConfig, logFn) {
|
|
311
324
|
return {
|
|
312
325
|
appData: params.appData,
|
|
313
|
-
params,
|
|
326
|
+
customScripts: params.customScriptsLoader?.(appConfig, logFn) ?? {},
|
|
314
327
|
logger: logFn,
|
|
315
|
-
|
|
328
|
+
params
|
|
316
329
|
};
|
|
317
330
|
}
|
|
318
331
|
/**
|
|
@@ -337,26 +350,26 @@ function createInstallationHooks(store, logFn) {
|
|
|
337
350
|
await store.put(getStorageKey(), data);
|
|
338
351
|
};
|
|
339
352
|
return {
|
|
340
|
-
onInstallationStart: (state) => logAndSave("Installation started", state),
|
|
341
353
|
onInstallationFailure: (state) => logAndSave("Installation failed", state),
|
|
354
|
+
onInstallationStart: (state) => logAndSave("Installation started", state),
|
|
342
355
|
onInstallationSuccess: (state) => logAndSave(state.status === "succeeded" && state.metadata?.isRetry ? "Installation succeeded on retry" : "Installation succeeded", state),
|
|
356
|
+
onStepFailure: (event, state) => logAndSave(`Step failed: ${event.stepName} — ${event.error.message ?? `(key: ${event.error.key})`}`, state),
|
|
343
357
|
onStepStart: (event, state) => logAndSave(`Step started: ${event.stepName}`, state),
|
|
344
|
-
onStepSuccess: (event, state) => logAndSave(`Step succeeded: ${event.stepName}`, state)
|
|
345
|
-
onStepFailure: (event, state) => logAndSave(`Step failed: ${event.stepName} — ${event.error.message ?? `(key: ${event.error.key})`}`, state)
|
|
358
|
+
onStepSuccess: (event, state) => logAndSave(`Step succeeded: ${event.stepName}`, state)
|
|
346
359
|
};
|
|
347
360
|
}
|
|
348
361
|
/**
|
|
349
362
|
* Installation action router.
|
|
350
363
|
*
|
|
351
364
|
* Routes:
|
|
352
|
-
* - GET /
|
|
353
|
-
* - POST /
|
|
354
|
-
* - POST /
|
|
355
|
-
* - POST /
|
|
356
|
-
* - POST /
|
|
357
|
-
* - GET /
|
|
358
|
-
* - POST /
|
|
359
|
-
* - DELETE /
|
|
365
|
+
* - GET / Get current installation status
|
|
366
|
+
* - POST / Start installation (creates plan, invokes execution async)
|
|
367
|
+
* - POST /execution Execute installation (internal, called async)
|
|
368
|
+
* - POST /validation Pre-installation validation
|
|
369
|
+
* - POST /uninstallation Start uninstallation (creates plan, invokes execution async)
|
|
370
|
+
* - GET /uninstallation Get current uninstallation status
|
|
371
|
+
* - POST /uninstallation/execution Execute uninstallation (internal, called async)
|
|
372
|
+
* - DELETE /uninstallation Clear uninstallation state only (no offboarding)
|
|
360
373
|
*/
|
|
361
374
|
const router = new HttpActionRouter().use(logger({ name: () => "installation" }));
|
|
362
375
|
/**
|
|
@@ -398,7 +411,7 @@ router.post("/", {
|
|
|
398
411
|
logger.debug("Previous installation failed, allowing retry");
|
|
399
412
|
}
|
|
400
413
|
const rawAppConfig = rawParams.appConfig;
|
|
401
|
-
if (!rawAppConfig) return internalServerError("
|
|
414
|
+
if (!rawAppConfig) return internalServerError("The app config is missing. Does the action receive it as a parameter?");
|
|
402
415
|
const appConfig = validateCommerceAppConfig(rawAppConfig);
|
|
403
416
|
const initialState = createInitialInstallationState({ config: appConfig });
|
|
404
417
|
logger.debug(`Created initial state: ${initialState.id}`);
|
|
@@ -406,27 +419,28 @@ router.post("/", {
|
|
|
406
419
|
const ow = openwhisk();
|
|
407
420
|
const mergedParams = buildWorkflowParams(req.body, rawParams);
|
|
408
421
|
const activation = await ow.actions.invoke({
|
|
409
|
-
name: DEFAULT_ACTION_NAME,
|
|
410
422
|
blocking: false,
|
|
411
|
-
|
|
423
|
+
name: DEFAULT_ACTION_NAME,
|
|
412
424
|
params: {
|
|
413
425
|
...mergedParams,
|
|
414
|
-
|
|
415
|
-
appConfig,
|
|
426
|
+
__ow_method: "post",
|
|
416
427
|
__ow_path: "/execution",
|
|
417
|
-
|
|
418
|
-
|
|
428
|
+
appConfig,
|
|
429
|
+
initialState
|
|
430
|
+
},
|
|
431
|
+
result: false
|
|
419
432
|
});
|
|
420
433
|
logger.debug(`Async execution started: ${activation.activationId}`);
|
|
421
434
|
return accepted({ body: {
|
|
422
|
-
message: "Installation started",
|
|
423
435
|
activationId: activation.activationId,
|
|
436
|
+
message: "Installation started",
|
|
424
437
|
...initialState
|
|
425
438
|
} });
|
|
426
439
|
}
|
|
427
440
|
});
|
|
428
441
|
/**
|
|
429
|
-
* POST /installation/execution - Execute installation
|
|
442
|
+
* POST /installation/execution - Execute installation
|
|
443
|
+
* @internal - Do not add to OpenAPI Spec.
|
|
430
444
|
*
|
|
431
445
|
* This endpoint is called asynchronously by POST /installation.
|
|
432
446
|
* It runs the actual installation workflow and saves state.
|
|
@@ -442,16 +456,16 @@ router.post("/execution", { handler: async (_req, { logger, rawParams }) => {
|
|
|
442
456
|
const installationContext = buildInstallationContext(params, appConfig, logger);
|
|
443
457
|
logger.debug(`Executing installation ${initialState.id} for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${AIO_COMMERCE_API_BASE_URL}")`);
|
|
444
458
|
const result = await runInstallation({
|
|
445
|
-
installationContext,
|
|
446
459
|
config: appConfig,
|
|
460
|
+
hooks,
|
|
447
461
|
initialState,
|
|
448
|
-
|
|
462
|
+
installationContext
|
|
449
463
|
});
|
|
450
464
|
await store.put(getStorageKey(), result);
|
|
451
465
|
logger.debug(`Installation completed: ${result.status}`);
|
|
452
466
|
if (isFailedState(result)) return internalServerError({ body: {
|
|
453
|
-
message: "Installation failed",
|
|
454
467
|
error: result.error,
|
|
468
|
+
message: "Installation failed",
|
|
455
469
|
state: result
|
|
456
470
|
} });
|
|
457
471
|
return ok({ body: result });
|
|
@@ -473,16 +487,16 @@ router.post("/validation", {
|
|
|
473
487
|
handler: async (req, { logger, rawParams }) => {
|
|
474
488
|
logger.debug("Running pre-installation validation...");
|
|
475
489
|
const rawAppConfig = rawParams.appConfig;
|
|
476
|
-
if (!rawAppConfig) return internalServerError("
|
|
490
|
+
if (!rawAppConfig) return internalServerError("The app config is missing. Does the action receive it as a parameter?");
|
|
477
491
|
const appConfig = validateCommerceAppConfig(rawAppConfig);
|
|
478
492
|
const { appData, ...params } = buildWorkflowParams(req.body, rawParams);
|
|
479
493
|
const result = await runValidation({
|
|
494
|
+
config: appConfig,
|
|
480
495
|
validationContext: {
|
|
481
496
|
appData,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
config: appConfig
|
|
497
|
+
logger,
|
|
498
|
+
params
|
|
499
|
+
}
|
|
486
500
|
});
|
|
487
501
|
logger.debug(`Validation complete — valid: ${result.valid}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}`);
|
|
488
502
|
return ok({ body: result });
|
|
@@ -512,41 +526,43 @@ router.post("/uninstallation", {
|
|
|
512
526
|
handler: async (req, { logger, rawParams }) => {
|
|
513
527
|
const { appData, commerceBaseUrl } = req.body;
|
|
514
528
|
logger.debug(`Starting uninstallation for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${commerceBaseUrl}")`);
|
|
515
|
-
const rawAppConfig = rawParams.appConfig;
|
|
516
|
-
if (!rawAppConfig) return internalServerError("Could not find or parse the app.commerce.manifest.json file, is it present and valid?");
|
|
517
|
-
const appConfig = validateCommerceAppConfig(rawAppConfig);
|
|
518
529
|
const store = await createUninstallationStore();
|
|
519
530
|
const existingState = await store.get(getStorageKey());
|
|
520
531
|
if (existingState && isInProgressState(existingState)) {
|
|
521
532
|
logger.debug(`Uninstallation already in progress: ${existingState.status}`);
|
|
522
533
|
return conflict("Uninstallation is already in progress. Wait for it to complete.");
|
|
523
534
|
}
|
|
524
|
-
const
|
|
535
|
+
const installAppConfig = (await getInstallationSnapshot())?.config;
|
|
536
|
+
const uninstallConfig = installAppConfig ?? rawParams.appConfig;
|
|
537
|
+
if (!uninstallConfig) return internalServerError("Cannot determine what to uninstall: no recorded installation snapshot and no app config was provided.");
|
|
538
|
+
logger.debug(installAppConfig ? "Sourcing uninstallation from recorded install snapshot" : "No recorded install config found; falling back to request config");
|
|
539
|
+
const initialState = createInitialUninstallationState({ config: validateCommerceAppConfig(uninstallConfig) });
|
|
525
540
|
logger.debug(`Created initial uninstall state: ${initialState.id}`);
|
|
526
541
|
await store.put(getStorageKey(), initialState);
|
|
527
542
|
const workflowParams = buildWorkflowParams(req.body, rawParams);
|
|
528
543
|
const activation = await openwhisk().actions.invoke({
|
|
529
|
-
name: DEFAULT_ACTION_NAME,
|
|
530
544
|
blocking: false,
|
|
531
|
-
|
|
545
|
+
name: DEFAULT_ACTION_NAME,
|
|
532
546
|
params: {
|
|
533
547
|
...workflowParams,
|
|
534
|
-
|
|
535
|
-
appConfig,
|
|
548
|
+
__ow_method: "post",
|
|
536
549
|
__ow_path: "/uninstallation/execution",
|
|
537
|
-
|
|
538
|
-
|
|
550
|
+
appConfig: uninstallConfig,
|
|
551
|
+
initialState
|
|
552
|
+
},
|
|
553
|
+
result: false
|
|
539
554
|
});
|
|
540
555
|
logger.debug(`Async uninstallation started: ${activation.activationId}`);
|
|
541
556
|
return accepted({ body: {
|
|
542
|
-
message: "Uninstallation started",
|
|
543
557
|
activationId: activation.activationId,
|
|
558
|
+
message: "Uninstallation started",
|
|
544
559
|
...initialState
|
|
545
560
|
} });
|
|
546
561
|
}
|
|
547
562
|
});
|
|
548
563
|
/**
|
|
549
|
-
* POST /uninstallation/execution - Execute uninstallation
|
|
564
|
+
* POST /uninstallation/execution - Execute uninstallation
|
|
565
|
+
* @internal - Do not add to OpenAPI Spec.
|
|
550
566
|
*
|
|
551
567
|
* Flow:
|
|
552
568
|
* 1. Build InstallationContext from params
|
|
@@ -566,10 +582,10 @@ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawPa
|
|
|
566
582
|
const installationContext = buildInstallationContext(params, appConfig, logger);
|
|
567
583
|
logger.debug(`Executing uninstallation ${initialState.id} for app "${appData.projectName}" (workspace: "${appData.workspaceName}", commerce: "${AIO_COMMERCE_API_BASE_URL}")`);
|
|
568
584
|
const result = await runUninstallation({
|
|
569
|
-
installationContext,
|
|
570
585
|
config: appConfig,
|
|
586
|
+
hooks,
|
|
571
587
|
initialState,
|
|
572
|
-
|
|
588
|
+
installationContext
|
|
573
589
|
});
|
|
574
590
|
await store.put(getStorageKey(), result);
|
|
575
591
|
logger.debug(`Uninstallation completed: ${result.status}`);
|
|
@@ -578,8 +594,8 @@ router.post("/uninstallation/execution", { handler: async (_req, { logger, rawPa
|
|
|
578
594
|
logger.debug("Cleared installation state after successful uninstallation");
|
|
579
595
|
}
|
|
580
596
|
if (isFailedState(result)) return internalServerError({ body: {
|
|
581
|
-
message: "Uninstallation failed",
|
|
582
597
|
error: result.error,
|
|
598
|
+
message: "Uninstallation failed",
|
|
583
599
|
state: result
|
|
584
600
|
} });
|
|
585
601
|
return ok({ body: result });
|
|
@@ -595,9 +611,26 @@ router.delete("/uninstallation", { handler: async (_req, { logger }) => {
|
|
|
595
611
|
logger.debug("Uninstallation state cleared");
|
|
596
612
|
return noContent();
|
|
597
613
|
} });
|
|
598
|
-
/**
|
|
599
|
-
|
|
600
|
-
|
|
614
|
+
/**
|
|
615
|
+
* Returns the completed installation snapshot that recorded its config, or null
|
|
616
|
+
* when none is authoritative (no install, an in-progress install, or a legacy
|
|
617
|
+
* record persisted before the config was recorded).
|
|
618
|
+
*/
|
|
619
|
+
async function getInstallationSnapshot() {
|
|
620
|
+
const installSnapshot = await (await createInstallationStore()).get(getStorageKey());
|
|
621
|
+
return installSnapshot && isCompletedState(installSnapshot) && installSnapshot.config ? installSnapshot : null;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region source/actions/installation/index.ts
|
|
626
|
+
/**
|
|
627
|
+
* Factory to create the route handler for the `installation` action.
|
|
628
|
+
* @param args - The arguments required to create the runtime action.
|
|
629
|
+
*/
|
|
630
|
+
const installationRuntimeAction = (args) => async (params) => {
|
|
631
|
+
const handler = router.handler();
|
|
632
|
+
const { appConfig, customScriptsLoader } = args;
|
|
633
|
+
return await handler({
|
|
601
634
|
...params,
|
|
602
635
|
appConfig,
|
|
603
636
|
customScriptsLoader
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
//#region source/actions/scope-tree.d.ts
|
|
15
|
+
//#region source/actions/scope-tree/index.d.ts
|
|
16
16
|
/** The handler method for the `scope-tree` action. */
|
|
17
17
|
declare const scopeTreeRuntimeAction: (args: import("@adobe/aio-commerce-lib-core/params").RuntimeActionParams) => Promise<import("@adobe/aio-commerce-lib-core/responses").ActionResponse>;
|
|
18
18
|
//#endregion
|
|
@@ -12,36 +12,74 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { t as
|
|
15
|
+
import { r as nonEmptyStringValueSchema } from "../../schemas-hRovglBF.mjs";
|
|
16
|
+
import { t as inspect } from "../../logging-DbJHXSKh.mjs";
|
|
17
|
+
import { n as logger, t as HttpActionRouter } from "../../router-B_h0cvjc.mjs";
|
|
18
|
+
import { resolveCommerceHttpClientParams } from "@adobe/aio-commerce-lib-api";
|
|
18
19
|
import { getScopeTree, setCustomScopeTree, syncCommerceScopes, unsyncCommerceScopes } from "@adobe/aio-commerce-lib-config";
|
|
19
|
-
import { internalServerError, nonAuthoritativeInformation, ok } from "@adobe/aio-commerce-lib-core/responses";
|
|
20
20
|
import * as v from "valibot";
|
|
21
|
-
import {
|
|
21
|
+
import { CommerceEnvSchema } from "@adobe/aio-commerce-lib-core/commerce";
|
|
22
|
+
import { badRequest, internalServerError, nonAuthoritativeInformation, ok } from "@adobe/aio-commerce-lib-core/responses";
|
|
23
|
+
|
|
24
|
+
//#region source/actions/scope-tree/schema.ts
|
|
25
|
+
const CustomScopeInputSchema = v.object({
|
|
26
|
+
children: v.optional(v.array(v.lazy(() => CustomScopeInputSchema))),
|
|
27
|
+
code: v.string(),
|
|
28
|
+
id: v.optional(v.string()),
|
|
29
|
+
is_editable: v.boolean(),
|
|
30
|
+
is_final: v.boolean(),
|
|
31
|
+
label: v.string(),
|
|
32
|
+
level: v.optional(v.string())
|
|
33
|
+
});
|
|
34
|
+
/** Request body for PUT / */
|
|
35
|
+
const SetCustomScopeTreeBodySchema = v.object({ scopes: v.array(CustomScopeInputSchema) });
|
|
36
|
+
/** Request body for POST /commerce */
|
|
37
|
+
const SyncCommerceScopesBodySchema = v.object({
|
|
38
|
+
commerceBaseUrl: nonEmptyStringValueSchema("commerceBaseUrl"),
|
|
39
|
+
commerceEnv: v.optional(CommerceEnvSchema)
|
|
40
|
+
});
|
|
22
41
|
|
|
23
|
-
//#
|
|
24
|
-
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region source/actions/scope-tree/router.ts
|
|
44
|
+
/**
|
|
45
|
+
* Scope Tree action router.
|
|
46
|
+
*
|
|
47
|
+
* Routes:
|
|
48
|
+
* - GET / Retrieve the scope tree.
|
|
49
|
+
* - PUT / Set custom scope tree.
|
|
50
|
+
* - POST /commerce Sync commerce scopes
|
|
51
|
+
* - DELETE /commerce Unsync commerce scopes
|
|
52
|
+
*/
|
|
53
|
+
const router = new HttpActionRouter().use(logger({ name: () => "scope-tree" }));
|
|
25
54
|
/** GET / - Get scope tree */
|
|
26
55
|
router.get("/", { handler: async (_req, ctx) => {
|
|
27
56
|
const { logger } = ctx;
|
|
28
57
|
const result = await getScopeTree();
|
|
29
58
|
logger.debug(`Successfully retrieved scope tree (cached: ${result.isCachedData}): ${inspect(result.scopeTree)}`);
|
|
30
59
|
if (result.isCachedData) return nonAuthoritativeInformation({
|
|
31
|
-
|
|
32
|
-
|
|
60
|
+
body: { scopes: result.scopeTree },
|
|
61
|
+
headers: { "x-cache": "hit" }
|
|
33
62
|
});
|
|
34
63
|
return ok({ body: { scopes: result.scopeTree } });
|
|
35
64
|
} });
|
|
36
|
-
/**
|
|
65
|
+
/** PUT / - Set custom scope tree */
|
|
37
66
|
router.put("/", {
|
|
38
|
-
body:
|
|
67
|
+
body: SetCustomScopeTreeBodySchema,
|
|
39
68
|
handler: async (req, ctx) => {
|
|
40
69
|
const { logger } = ctx;
|
|
41
70
|
logger.debug(`Setting custom scope tree with ${req.body.scopes?.length || 0} scopes`);
|
|
42
71
|
const request = { scopes: req.body.scopes };
|
|
72
|
+
let result;
|
|
43
73
|
logger.debug(`Setting custom scope tree: ${inspect(request)}`);
|
|
44
|
-
|
|
74
|
+
try {
|
|
75
|
+
result = await setCustomScopeTree(request);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
if (err instanceof Error && "isValidationError" in err) {
|
|
78
|
+
logger.debug(`Custom scope tree validation failed: ${err.message}`);
|
|
79
|
+
return badRequest({ body: { message: err.message } });
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
45
83
|
logger.debug(`Successfully set custom scope tree: ${inspect(result)}`);
|
|
46
84
|
return ok({
|
|
47
85
|
body: { result },
|
|
@@ -51,10 +89,7 @@ router.put("/", {
|
|
|
51
89
|
});
|
|
52
90
|
/** POST /commerce - Sync commerce scopes */
|
|
53
91
|
router.post("/commerce", {
|
|
54
|
-
body:
|
|
55
|
-
commerceBaseUrl: nonEmptyStringValueSchema("commerceBaseUrl"),
|
|
56
|
-
commerceEnv: v.optional(nonEmptyStringValueSchema("commerceEnv"))
|
|
57
|
-
}),
|
|
92
|
+
body: SyncCommerceScopesBodySchema,
|
|
58
93
|
handler: async (req, ctx) => {
|
|
59
94
|
const { logger } = ctx;
|
|
60
95
|
logger.debug("Syncing commerce scopes...");
|
|
@@ -67,18 +102,18 @@ router.post("/commerce", {
|
|
|
67
102
|
if (result.error) {
|
|
68
103
|
logger.error(`Error syncing commerce scopes: ${inspect(result.error)}`);
|
|
69
104
|
return internalServerError({ body: {
|
|
70
|
-
|
|
71
|
-
|
|
105
|
+
error: result.error,
|
|
106
|
+
message: "An internal server error occurred"
|
|
72
107
|
} });
|
|
73
108
|
}
|
|
74
109
|
if (!result.synced) {
|
|
75
110
|
logger.debug(`Commerce scopes not synced (cached): ${inspect(result.scopeTree)}`);
|
|
76
111
|
return nonAuthoritativeInformation({
|
|
77
|
-
headers: { "x-cache": "hit" },
|
|
78
112
|
body: {
|
|
79
113
|
scopes: result.scopeTree,
|
|
80
114
|
synced: false
|
|
81
|
-
}
|
|
115
|
+
},
|
|
116
|
+
headers: { "x-cache": "hit" }
|
|
82
117
|
});
|
|
83
118
|
}
|
|
84
119
|
logger.debug(`Successfully synced commerce scopes: ${inspect(result.scopeTree)}`);
|
|
@@ -102,6 +137,9 @@ router.delete("/commerce", { handler: async (_req, ctx) => {
|
|
|
102
137
|
logger.debug(message);
|
|
103
138
|
return ok(message);
|
|
104
139
|
} });
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region source/actions/scope-tree/index.ts
|
|
105
143
|
/** The handler method for the `scope-tree` action. */
|
|
106
144
|
const scopeTreeRuntimeAction = router.handler();
|
|
107
145
|
|