@adobe/aio-commerce-lib-app 1.7.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/cjs/actions/app-config/index.cjs +41 -38
  3. package/dist/cjs/actions/app-config/index.d.cts +1 -1
  4. package/dist/cjs/actions/association/index.cjs +85 -0
  5. package/dist/cjs/actions/{registration → association}/index.d.cts +9 -13
  6. package/dist/cjs/actions/config/index.cjs +21 -32
  7. package/dist/cjs/actions/installation/index.cjs +72 -51
  8. package/dist/cjs/actions/installation/index.d.cts +2 -2
  9. package/dist/cjs/actions/scope-tree/index.cjs +18 -17
  10. package/dist/{es/app-DrYHK-z1.d.mts → cjs/app-D3P-Z6uY.d.cts} +1085 -1035
  11. package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
  12. package/dist/cjs/commands/index.cjs +512 -298
  13. package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
  14. package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
  15. package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
  16. package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  17. package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  18. package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  19. package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  20. package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
  21. package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
  22. package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
  23. package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
  24. package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
  25. package/dist/cjs/config/index.browser.cjs +18 -0
  26. package/dist/cjs/config/index.browser.d.cts +16 -0
  27. package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
  28. package/dist/cjs/config/{index.d.cts → index.node.d.cts} +954 -386
  29. package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
  30. package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
  31. package/dist/cjs/environment-B7EnozSg.cjs +135 -0
  32. package/dist/cjs/{index-B5gJ-q4U.d.cts → index-CzReNwbF.d.cts} +17 -12
  33. package/dist/cjs/index.cjs +250 -0
  34. package/dist/cjs/index.d.cts +217 -0
  35. package/dist/cjs/{config-D-s0GSep.cjs → index.node-Dz4lV4qe.cjs} +119 -35
  36. package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
  37. package/dist/cjs/management/index.cjs +1 -1
  38. package/dist/cjs/management/index.d.cts +1 -1
  39. package/dist/cjs/{management-Dehz9qSJ.cjs → management-B9ItB80R.cjs} +385 -582
  40. package/dist/cjs/{openapi-Cux6K4ZD.cjs → openapi-CwytYdWl.cjs} +476 -600
  41. package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
  42. package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
  43. package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
  44. package/dist/cjs/{validate-oAOpyFyb.cjs → validate-BfxhZ5Wv.cjs} +20 -20
  45. package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
  46. package/dist/es/actions/app-config/index.d.mts +1 -1
  47. package/dist/es/actions/app-config/index.mjs +39 -36
  48. package/dist/es/actions/{registration → association}/index.d.mts +9 -13
  49. package/dist/es/actions/association/index.mjs +82 -0
  50. package/dist/es/actions/config/index.mjs +17 -28
  51. package/dist/es/actions/installation/index.d.mts +2 -2
  52. package/dist/es/actions/installation/index.mjs +69 -48
  53. package/dist/es/actions/scope-tree/index.mjs +14 -13
  54. package/dist/{cjs/app-DrYHK-z1.d.cts → es/app-D3P-Z6uY.d.mts} +1085 -1035
  55. package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
  56. package/dist/es/commands/index.mjs +544 -328
  57. package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
  58. package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
  59. package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
  60. package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
  61. package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
  62. package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
  63. package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
  64. package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
  65. package/dist/es/commands/templates/app-management/association.js.template +6 -0
  66. package/dist/es/commands/templates/app-management/installation.js.template +1 -13
  67. package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
  68. package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
  69. package/dist/es/config/index.browser.d.mts +16 -0
  70. package/dist/es/config/index.browser.mjs +17 -0
  71. package/dist/es/config/{index.d.mts → index.node.d.mts} +954 -386
  72. package/dist/es/config/{index.mjs → index.node.mjs} +5 -4
  73. package/dist/es/define-EoYRZbpe.d.mts +34 -0
  74. package/dist/es/define-Z_Glf1-_.mjs +35 -0
  75. package/dist/es/environment-C84BPRJZ.mjs +104 -0
  76. package/dist/es/{index-DLMbTtKS.d.mts → index-D52xglhZ.d.mts} +17 -12
  77. package/dist/es/index.d.mts +217 -0
  78. package/dist/es/index.mjs +242 -0
  79. package/dist/es/{config-3I4eLyyR.mjs → index.node-CDH5gwJE.mjs} +94 -30
  80. package/dist/es/management/index.d.mts +1 -1
  81. package/dist/es/management/index.mjs +1 -1
  82. package/dist/es/{management-BUX-w2Ji.mjs → management-B89ApQVY.mjs} +353 -550
  83. package/dist/es/{openapi-B6uP0SRn.mjs → openapi-CXonvevE.mjs} +476 -600
  84. package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
  85. package/dist/es/utils-_gj8L6eN.mjs +289 -0
  86. package/dist/es/{validate-Dfajrp99.mjs → validate-9cRZWGrA.mjs} +17 -17
  87. package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
  88. package/package.json +40 -17
  89. package/dist/cjs/actions/registration/index.cjs +0 -50
  90. package/dist/cjs/admin-ui-sdk-EU915zlR.d.cts +0 -664
  91. package/dist/es/actions/registration/index.mjs +0 -49
  92. package/dist/es/admin-ui-sdk-BwnD0xjK.d.mts +0 -664
  93. /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { n as CommerceAppConfig } from "./app-D3P-Z6uY.cjs";
16
+
17
+ //#region source/config/lib/define.d.ts
18
+ /**
19
+ * Helper to type-safely define the app config.
20
+ * @param config - The app config to define.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { defineConfig } from "@adobe/aio-commerce-lib-app";
25
+ *
26
+ * // In app.commerce.config.js
27
+ * export default defineConfig({
28
+ * // You get autocompletion and type-safety for the config object.
29
+ * businessConfig: { ... }
30
+ * });
31
+ */
32
+ declare function defineConfig<const T extends CommerceAppConfig>(config: T): T;
33
+ //#endregion
34
+ export { defineConfig as t };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ //#region source/config/lib/define.ts
17
+ /**
18
+ * Helper to type-safely define the app config.
19
+ * @param config - The app config to define.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { defineConfig } from "@adobe/aio-commerce-lib-app";
24
+ *
25
+ * // In app.commerce.config.js
26
+ * export default defineConfig({
27
+ * // You get autocompletion and type-safety for the config object.
28
+ * businessConfig: { ... }
29
+ * });
30
+ */
31
+ function defineConfig(config) {
32
+ return config;
33
+ }
34
+
35
+ //#endregion
36
+ Object.defineProperty(exports, 'defineConfig', {
37
+ enumerable: true,
38
+ get: function () {
39
+ return defineConfig;
40
+ }
41
+ });
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ const require_rolldown_runtime = require('./rolldown-runtime-Cozy-1ZF.cjs');
16
+ let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
17
+ let valibot = require("valibot");
18
+ valibot = require_rolldown_runtime.__toESM(valibot, 1);
19
+ let _adobe_aio_commerce_lib_core_commerce = require("@adobe/aio-commerce-lib-core/commerce");
20
+
21
+ //#region ../../packages-private/common-utils/source/valibot/utils.ts
22
+ /**
23
+ * Parses the input using the provided schema and throws a {@link CommerceSdkValidationError} error if the input is invalid.
24
+ * @param schema - The schema to use for parsing.
25
+ * @param input - The input to parse.
26
+ * @param message - Optional custom error message for the validation error.
27
+ */
28
+ function parseOrThrow(schema, input, message) {
29
+ const result = valibot.safeParse(schema, input);
30
+ if (!result.success) throw new _adobe_aio_commerce_lib_core_error.CommerceSdkValidationError(message ?? "Invalid input", { issues: result.issues });
31
+ return result.output;
32
+ }
33
+
34
+ //#endregion
35
+ //#region source/config/lib/environment.ts
36
+ /**
37
+ * Returns true when an item applies to the given Commerce environment: either it
38
+ * declares no `env` (applies to all environments) or its `env` list includes the
39
+ * environment. This is the single keep-rule shared by install-time filtering and
40
+ * the environment-filtered `app-config` display path.
41
+ *
42
+ * @param item - The webhook or event entry, which may carry an optional `env` array.
43
+ * @param env - The target Commerce environment (e.g. `"paas"` or `"saas"`).
44
+ */
45
+ function appliesToEnv(item, env) {
46
+ return item.env === void 0 || item.env.includes(env);
47
+ }
48
+ /**
49
+ * Reads and validates the target Commerce environment from the install workflow params,
50
+ * where the router maps the request's `commerceEnv` onto `AIO_COMMERCE_API_FLAVOR`.
51
+ * Throws if the value is absent or not a recognised Commerce environment.
52
+ *
53
+ * @param params - The runtime action params available to install steps.
54
+ */
55
+ function getInstallCommerceEnv(params) {
56
+ return parseOrThrow(_adobe_aio_commerce_lib_core_commerce.CommerceEnvSchema, params.AIO_COMMERCE_API_FLAVOR, "Missing or unknown commerce environment");
57
+ }
58
+ /**
59
+ * Filters a provider list to the given environment: each provider keeps only its
60
+ * applicable events, and providers left with no events are dropped entirely.
61
+ */
62
+ function filterProvidersByEnv(providers, env) {
63
+ return providers.map((provider) => ({
64
+ ...provider,
65
+ events: provider.events.filter((event) => appliesToEnv(event, env))
66
+ })).filter((provider) => provider.events.length > 0);
67
+ }
68
+ /**
69
+ * Returns a copy of a validated app config scoped to the given Commerce environment:
70
+ * business-config fields and webhooks not applicable to the environment are removed,
71
+ * each event provider keeps only its applicable events, and providers left with no
72
+ * events are dropped. Uses the same `appliesToEnv` keep-rule as the `config` action,
73
+ * so the `app-config` action renders the same scoped set that the rest of the SDK
74
+ * (install and `config`) applies.
75
+ *
76
+ * @param config - The validated app config.
77
+ * @param env - The target Commerce environment (e.g. `"paas"` or `"saas"`).
78
+ */
79
+ function filterAppConfigByEnv(config, env) {
80
+ const filtered = { ...config };
81
+ if (filtered.businessConfig && Array.isArray(filtered.businessConfig.schema)) filtered.businessConfig = {
82
+ ...filtered.businessConfig,
83
+ schema: filtered.businessConfig.schema.filter((field) => appliesToEnv(field, env))
84
+ };
85
+ if (Array.isArray(filtered.webhooks)) filtered.webhooks = filtered.webhooks.filter((webhook) => appliesToEnv(webhook, env));
86
+ if (filtered.eventing) filtered.eventing = {
87
+ ...filtered.eventing,
88
+ ...filtered.eventing.commerce && { commerce: filterProvidersByEnv(filtered.eventing.commerce, env) },
89
+ ...filtered.eventing.external && { external: filterProvidersByEnv(filtered.eventing.external, env) }
90
+ };
91
+ return filtered;
92
+ }
93
+ /**
94
+ * Filters a business configuration schema to the fields applicable to the
95
+ * given Commerce environment. Fields without an `env` property apply to all
96
+ * environments and are always included.
97
+ *
98
+ * @param schema - The business configuration schema to filter.
99
+ * @param env - The Commerce environment to filter by.
100
+ */
101
+ function filterSchemaByEnv(schema, env) {
102
+ return schema.filter((field) => appliesToEnv(field, env));
103
+ }
104
+
105
+ //#endregion
106
+ Object.defineProperty(exports, 'appliesToEnv', {
107
+ enumerable: true,
108
+ get: function () {
109
+ return appliesToEnv;
110
+ }
111
+ });
112
+ Object.defineProperty(exports, 'filterAppConfigByEnv', {
113
+ enumerable: true,
114
+ get: function () {
115
+ return filterAppConfigByEnv;
116
+ }
117
+ });
118
+ Object.defineProperty(exports, 'filterSchemaByEnv', {
119
+ enumerable: true,
120
+ get: function () {
121
+ return filterSchemaByEnv;
122
+ }
123
+ });
124
+ Object.defineProperty(exports, 'getInstallCommerceEnv', {
125
+ enumerable: true,
126
+ get: function () {
127
+ return getInstallCommerceEnv;
128
+ }
129
+ });
130
+ Object.defineProperty(exports, 'parseOrThrow', {
131
+ enumerable: true,
132
+ get: function () {
133
+ return parseOrThrow;
134
+ }
135
+ });
@@ -12,7 +12,7 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import { r as CommerceAppConfigOutputModel } from "./app-DrYHK-z1.cjs";
15
+ import { r as CommerceAppConfigOutputModel } from "./app-D3P-Z6uY.cjs";
16
16
  import { RuntimeActionParams } from "@adobe/aio-commerce-lib-core/params";
17
17
  import AioLogger from "@adobe/aio-lib-core-logging";
18
18
  import * as v from "valibot";
@@ -115,7 +115,7 @@ type BranchStep<TName extends string = string, TConfig extends CommerceAppConfig
115
115
  /** A step in the installation tree (discriminated union by `type`). */
116
116
  type Step<TName extends string = string, TConfig extends CommerceAppConfigOutputModel = CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> = LeafStep<TName, TConfig, TStepCtx, TOutput> | BranchStep<TName, TConfig, TStepCtx>;
117
117
  /** Loosely-typed step for use in non type-safe contexts. */
118
- interface AnyStep {
118
+ type AnyStep = {
119
119
  children?: AnyStep[];
120
120
  context?: (context: InstallationContext) => any;
121
121
  install?: (config: any, context: any) => unknown | Promise<unknown>;
@@ -125,7 +125,7 @@ interface AnyStep {
125
125
  uninstall?: (config: any, context: any) => void | Promise<void>;
126
126
  validate?: (config: any, context: any) => ValidationIssue[] | Promise<ValidationIssue[]>;
127
127
  when?: (config: CommerceAppConfigOutputModel) => boolean;
128
- }
128
+ };
129
129
  /** Check if a step is a leaf step. */
130
130
  declare function isLeafStep(step: AnyStep): step is LeafStep;
131
131
  /** Check if a step is a branch step. */
@@ -150,13 +150,13 @@ type BranchStepOptions<TName extends string, TConfig extends CommerceAppConfigOu
150
150
  * ```
151
151
  */
152
152
  declare function defineLeafStep<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown>(options: LeafStepOptions<TName, TConfig, TStepCtx, TOutput>): {
153
- type: "leaf";
154
- name: TName;
155
- meta: StepMeta;
156
- when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
157
153
  install: (config: TConfig, context: ExecutionContext<TStepCtx>) => TOutput | Promise<TOutput>;
154
+ meta: StepMeta;
155
+ name: TName;
156
+ type: "leaf";
158
157
  uninstall: ((config: TConfig, context: ExecutionContext<TStepCtx>) => void | Promise<void>) | undefined;
159
158
  validate: ((config: TConfig, context: ValidationExecutionContext<TStepCtx>) => ValidationIssue[] | Promise<ValidationIssue[]>) | undefined;
159
+ when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
160
160
  };
161
161
  /**
162
162
  * Define a branch step (container with children, no runner).
@@ -173,13 +173,13 @@ declare function defineLeafStep<TName extends string, TConfig extends CommerceAp
173
173
  * ```
174
174
  */
175
175
  declare function defineBranchStep<TName extends string, TConfig extends CommerceAppConfigOutputModel, TStepCtx extends Record<string, unknown> = Record<string, unknown>, const TChildren extends AnyStep[] = AnyStep[]>(options: BranchStepOptions<TName, TConfig, TStepCtx, TChildren>): {
176
- type: "branch";
177
- name: TName;
178
- meta: StepMeta;
179
- when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
180
- context: StepContextFactory<TStepCtx> | undefined;
181
176
  children: TChildren;
177
+ context: StepContextFactory<TStepCtx> | undefined;
178
+ meta: StepMeta;
179
+ name: TName;
180
+ type: "branch";
182
181
  validate: ((config: TConfig, context: ValidationExecutionContext<TStepCtx>) => ValidationIssue[] | Promise<ValidationIssue[]>) | undefined;
182
+ when: ((config: CommerceAppConfigOutputModel) => config is TConfig) | undefined;
183
183
  };
184
184
  /** Infer the output type from a leaf step. */
185
185
  type InferStepOutput<TStep> = TStep extends LeafStep<infer _TName, infer _TConfig, infer _TStepCtx, infer TOutput> ? Awaited<TOutput> : never;
@@ -214,6 +214,11 @@ type InstallationStateBase = {
214
214
  /** Unique installation identifier. */id: string; /** Root step status. */
215
215
  step: StepStatus; /** Results from executed leaf steps, keyed by path. */
216
216
  data: InstallationData | null;
217
+ /**
218
+ * The validated app configuration that drove this workflow. May be
219
+ * undefined on states persisted before this field was introduced.
220
+ */
221
+ config?: CommerceAppConfigOutputModel;
217
222
  };
218
223
  /** Installation state when in progress. */
219
224
  type InProgressInstallationState = InstallationStateBase & {
@@ -0,0 +1,250 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
+ const require_association_repository = require('./association-repository-BAs3-VkW.cjs');
17
+ const require_utils = require('./utils-DSCmZ_iJ.cjs');
18
+ let _adobe_aio_commerce_lib_api = require("@adobe/aio-commerce-lib-api");
19
+ let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
20
+ let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
21
+
22
+ //#region source/errors/app-not-associated-error.ts
23
+ const DEFAULT_MESSAGE = "App is not associated with a Commerce instance. Re-associate the app to resolve this error.";
24
+ /**
25
+ * Thrown when a runtime action calls `getCommerceInstance` or `getCommerceClient`
26
+ * but the app has no stored association data — for example, when the app has
27
+ * never been associated, has been unassociated, or was associated by an older
28
+ * SDK that did not store this data.
29
+ *
30
+ * Re-associating the app resolves the error.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { getCommerceClient, AppNotAssociatedError } from "@adobe/aio-commerce-lib-app";
35
+ * import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth";
36
+ *
37
+ * try {
38
+ * const client = await getCommerceClient(resolveImsAuthParams(params));
39
+ * // ... use client
40
+ * } catch (error) {
41
+ * if (error instanceof AppNotAssociatedError) {
42
+ * // handle the unassociated case (e.g. return a 400 response)
43
+ * }
44
+ * throw error;
45
+ * }
46
+ * ```
47
+ */
48
+ var AppNotAssociatedError = class extends _adobe_aio_commerce_lib_core_error.CommerceSdkErrorBase {
49
+ constructor(message = DEFAULT_MESSAGE, options) {
50
+ super(message, options);
51
+ }
52
+ };
53
+
54
+ //#endregion
55
+ //#region source/access/commerce-instance.ts
56
+ /**
57
+ * Returns the Commerce instance this app is currently associated with.
58
+ *
59
+ * @throws {AppNotAssociatedError} If the app is not associated, was
60
+ * unassociated, or was associated by an older SDK that did not store this
61
+ * data. Re-associating the app resolves the error.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { getCommerceInstance } from "@adobe/aio-commerce-lib-app";
66
+ *
67
+ * export async function main() {
68
+ * const instance = await getCommerceInstance();
69
+ *
70
+ * // instance.baseUrl — e.g. "https://my-store.example.com"
71
+ * // instance.env — "saas" | "paas"
72
+ * }
73
+ * ```
74
+ */
75
+ async function getCommerceInstance() {
76
+ const instance = await require_association_repository.getAssociationData();
77
+ if (instance === null) throw new AppNotAssociatedError();
78
+ return instance;
79
+ }
80
+ /**
81
+ * Returns an initialised `AdobeCommerceHttpClient` for the Commerce instance
82
+ * this app is currently associated with.
83
+ *
84
+ * The base URL and flavor come from the stored association data
85
+ * ({@link getCommerceInstance}); the caller supplies the resolved IMS auth.
86
+ *
87
+ * @param auth - Resolved IMS auth params or an IMS auth provider.
88
+ * @param fetchOptions - Optional global fetch options forwarded to the
89
+ * underlying `AdobeCommerceHttpClient` (e.g. `headers`, `timeout`, `retry`).
90
+ * @throws {AppNotAssociatedError} If the app is not associated, was
91
+ * unassociated, or was associated by an older SDK that did not store this
92
+ * data. Re-associating the app resolves the error.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { getCommerceClient } from "@adobe/aio-commerce-lib-app";
97
+ * import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth";
98
+ *
99
+ * export async function main(params) {
100
+ * const client = await getCommerceClient(resolveImsAuthParams(params));
101
+ * const products = await client.get("products").json();
102
+ * }
103
+ * ```
104
+ */
105
+ async function getCommerceClient(auth, fetchOptions) {
106
+ const instance = await getCommerceInstance();
107
+ return new _adobe_aio_commerce_lib_api.AdobeCommerceHttpClient({
108
+ auth,
109
+ config: {
110
+ baseUrl: instance.baseUrl,
111
+ flavor: instance.env
112
+ },
113
+ fetchOptions
114
+ });
115
+ }
116
+
117
+ //#endregion
118
+ //#region source/errors/publish-event-errors.ts
119
+ /**
120
+ * Base error thrown by {@link publishEvent} when event resolution or publishing fails.
121
+ * Catch this to handle all publish-event failures in a single clause.
122
+ */
123
+ var PublishEventError = class extends _adobe_aio_commerce_lib_core_error.CommerceSdkErrorBase {};
124
+ /**
125
+ * Thrown when {@link publishEvent} cannot find the eventing installation data in system storage.
126
+ *
127
+ * This typically means the app installation has not run yet, or ran with an older SDK version
128
+ * that did not write event provider metadata to storage. Re-running the installation resolves it.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * try {
133
+ * await publishEvent({ client, provider: "order-events", event: "order.created", payload });
134
+ * } catch (error) {
135
+ * if (error instanceof EventsDataNotInitializedError) {
136
+ * // Prompt re-installation
137
+ * }
138
+ * }
139
+ * ```
140
+ */
141
+ var EventsDataNotInitializedError = class extends PublishEventError {
142
+ constructor() {
143
+ super("No eventing installation data found. Re-run the app installation to initialize event provider metadata.");
144
+ }
145
+ };
146
+ /**
147
+ * Thrown when the provider key passed to {@link publishEvent} does not match any provider
148
+ * declared in the app's eventing configuration.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * try {
153
+ * await publishEvent({ client, provider: "order-events", event: "order.created", payload });
154
+ * } catch (error) {
155
+ * if (error instanceof ProviderNotFoundError) {
156
+ * // "order-events" was not found — check app.commerce.config.ts
157
+ * }
158
+ * }
159
+ * ```
160
+ */
161
+ var ProviderNotFoundError = class extends PublishEventError {
162
+ constructor(providerKey) {
163
+ super(`No event provider with key '${providerKey}' found in the app eventing configuration.`);
164
+ }
165
+ };
166
+ /**
167
+ * Thrown when the event name passed to {@link publishEvent} does not match any event
168
+ * declared under the given provider in the app's eventing configuration.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * try {
173
+ * await publishEvent({ client, provider: "order-events", event: "order.created", payload });
174
+ * } catch (error) {
175
+ * if (error instanceof EventNotFoundError) {
176
+ * // "order.created" was not found under "order-events" — check app.commerce.config.ts
177
+ * }
178
+ * }
179
+ * ```
180
+ */
181
+ var EventNotFoundError = class extends PublishEventError {
182
+ constructor(eventName, providerKey) {
183
+ super(`No event named '${eventName}' found under provider '${providerKey}'.`);
184
+ }
185
+ };
186
+
187
+ //#endregion
188
+ //#region source/access/events.ts
189
+ /**
190
+ * Publishes an event declared in the app's eventing configuration.
191
+ *
192
+ * Resolves the provider key and event name to their respective I/O Events IDs from
193
+ * data written to system storage at installation time, then delegates the HTTP call
194
+ * to the given client. No management API round-trip is needed at runtime.
195
+ *
196
+ * @param params.client - An {@link AdobeIoEventsApiClient} configured with the correct IMS auth.
197
+ * @param params.provider - The `key` of an event provider declared in `app.commerce.config.ts`.
198
+ * @param params.event - The `name` of an event within that provider.
199
+ * @param params.payload - The event payload. Must be a JSON object.
200
+ *
201
+ * @throws {EventsDataNotInitializedError} If no eventing installation data is found in system storage.
202
+ * @throws {ProviderNotFoundError} If the provider key is not found in the stored data.
203
+ * @throws {EventNotFoundError} If the event name is not found under the given provider.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { publishEvent } from "@adobe/aio-commerce-lib-app";
208
+ * import { createAdobeIoEventsApiClient } from "@adobe/aio-commerce-lib-events";
209
+ * import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth";
210
+ *
211
+ * export async function main(params) {
212
+ * const client = createAdobeIoEventsApiClient({
213
+ * auth: resolveImsAuthParams(params),
214
+ * config: { ingressBaseUrl: params.AIO_EVENTS_INGRESS_BASE_URL },
215
+ * });
216
+ *
217
+ * await publishEvent({
218
+ * client,
219
+ * provider: "order-events",
220
+ * event: "order.created",
221
+ * payload: { orderId: "100000123", total: 149.99 },
222
+ * });
223
+ * }
224
+ * ```
225
+ */
226
+ async function publishEvent(params) {
227
+ const { client, provider: providerKey, event: eventName, payload } = params;
228
+ const data = await (0, _adobe_aio_commerce_lib_config.getSystemConfigByKey)(require_utils.EVENTS_STORAGE_KEY);
229
+ if (!data) throw new EventsDataNotInitializedError();
230
+ const providerEntry = data.providers[providerKey];
231
+ if (!providerEntry) throw new ProviderNotFoundError(providerKey);
232
+ const eventEntry = providerEntry.events[eventName];
233
+ if (!eventEntry) throw new EventNotFoundError(eventName, providerKey);
234
+ await client.publishEvent({
235
+ eventCode: eventEntry.code,
236
+ isPhiData: eventEntry.isPhiData,
237
+ payload,
238
+ providerId: providerEntry.id
239
+ });
240
+ }
241
+
242
+ //#endregion
243
+ exports.AppNotAssociatedError = AppNotAssociatedError;
244
+ exports.EventNotFoundError = EventNotFoundError;
245
+ exports.EventsDataNotInitializedError = EventsDataNotInitializedError;
246
+ exports.ProviderNotFoundError = ProviderNotFoundError;
247
+ exports.PublishEventError = PublishEventError;
248
+ exports.getCommerceClient = getCommerceClient;
249
+ exports.getCommerceInstance = getCommerceInstance;
250
+ exports.publishEvent = publishEvent;