@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
|
@@ -0,0 +1,242 @@
|
|
|
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 getAssociationData } from "./association-repository-BbQv9WCl.mjs";
|
|
16
|
+
import { n as EVENTS_STORAGE_KEY } from "./utils-_gj8L6eN.mjs";
|
|
17
|
+
import { AdobeCommerceHttpClient } from "@adobe/aio-commerce-lib-api";
|
|
18
|
+
import { CommerceSdkErrorBase } from "@adobe/aio-commerce-lib-core/error";
|
|
19
|
+
import { getSystemConfigByKey } from "@adobe/aio-commerce-lib-config";
|
|
20
|
+
|
|
21
|
+
//#region source/errors/app-not-associated-error.ts
|
|
22
|
+
const DEFAULT_MESSAGE = "App is not associated with a Commerce instance. Re-associate the app to resolve this error.";
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when a runtime action calls `getCommerceInstance` or `getCommerceClient`
|
|
25
|
+
* but the app has no stored association data — for example, when the app has
|
|
26
|
+
* never been associated, has been unassociated, or was associated by an older
|
|
27
|
+
* SDK that did not store this data.
|
|
28
|
+
*
|
|
29
|
+
* Re-associating the app resolves the error.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { getCommerceClient, AppNotAssociatedError } from "@adobe/aio-commerce-lib-app";
|
|
34
|
+
* import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth";
|
|
35
|
+
*
|
|
36
|
+
* try {
|
|
37
|
+
* const client = await getCommerceClient(resolveImsAuthParams(params));
|
|
38
|
+
* // ... use client
|
|
39
|
+
* } catch (error) {
|
|
40
|
+
* if (error instanceof AppNotAssociatedError) {
|
|
41
|
+
* // handle the unassociated case (e.g. return a 400 response)
|
|
42
|
+
* }
|
|
43
|
+
* throw error;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
var AppNotAssociatedError = class extends CommerceSdkErrorBase {
|
|
48
|
+
constructor(message = DEFAULT_MESSAGE, options) {
|
|
49
|
+
super(message, options);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region source/access/commerce-instance.ts
|
|
55
|
+
/**
|
|
56
|
+
* Returns the Commerce instance this app is currently associated with.
|
|
57
|
+
*
|
|
58
|
+
* @throws {AppNotAssociatedError} If the app is not associated, was
|
|
59
|
+
* unassociated, or was associated by an older SDK that did not store this
|
|
60
|
+
* data. Re-associating the app resolves the error.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { getCommerceInstance } from "@adobe/aio-commerce-lib-app";
|
|
65
|
+
*
|
|
66
|
+
* export async function main() {
|
|
67
|
+
* const instance = await getCommerceInstance();
|
|
68
|
+
*
|
|
69
|
+
* // instance.baseUrl — e.g. "https://my-store.example.com"
|
|
70
|
+
* // instance.env — "saas" | "paas"
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async function getCommerceInstance() {
|
|
75
|
+
const instance = await getAssociationData();
|
|
76
|
+
if (instance === null) throw new AppNotAssociatedError();
|
|
77
|
+
return instance;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns an initialised `AdobeCommerceHttpClient` for the Commerce instance
|
|
81
|
+
* this app is currently associated with.
|
|
82
|
+
*
|
|
83
|
+
* The base URL and flavor come from the stored association data
|
|
84
|
+
* ({@link getCommerceInstance}); the caller supplies the resolved IMS auth.
|
|
85
|
+
*
|
|
86
|
+
* @param auth - Resolved IMS auth params or an IMS auth provider.
|
|
87
|
+
* @param fetchOptions - Optional global fetch options forwarded to the
|
|
88
|
+
* underlying `AdobeCommerceHttpClient` (e.g. `headers`, `timeout`, `retry`).
|
|
89
|
+
* @throws {AppNotAssociatedError} If the app is not associated, was
|
|
90
|
+
* unassociated, or was associated by an older SDK that did not store this
|
|
91
|
+
* data. Re-associating the app resolves the error.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { getCommerceClient } from "@adobe/aio-commerce-lib-app";
|
|
96
|
+
* import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth";
|
|
97
|
+
*
|
|
98
|
+
* export async function main(params) {
|
|
99
|
+
* const client = await getCommerceClient(resolveImsAuthParams(params));
|
|
100
|
+
* const products = await client.get("products").json();
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
async function getCommerceClient(auth, fetchOptions) {
|
|
105
|
+
const instance = await getCommerceInstance();
|
|
106
|
+
return new AdobeCommerceHttpClient({
|
|
107
|
+
auth,
|
|
108
|
+
config: {
|
|
109
|
+
baseUrl: instance.baseUrl,
|
|
110
|
+
flavor: instance.env
|
|
111
|
+
},
|
|
112
|
+
fetchOptions
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region source/errors/publish-event-errors.ts
|
|
118
|
+
/**
|
|
119
|
+
* Base error thrown by {@link publishEvent} when event resolution or publishing fails.
|
|
120
|
+
* Catch this to handle all publish-event failures in a single clause.
|
|
121
|
+
*/
|
|
122
|
+
var PublishEventError = class extends CommerceSdkErrorBase {};
|
|
123
|
+
/**
|
|
124
|
+
* Thrown when {@link publishEvent} cannot find the eventing installation data in system storage.
|
|
125
|
+
*
|
|
126
|
+
* This typically means the app installation has not run yet, or ran with an older SDK version
|
|
127
|
+
* that did not write event provider metadata to storage. Re-running the installation resolves it.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* try {
|
|
132
|
+
* await publishEvent({ client, provider: "order-events", event: "order.created", payload });
|
|
133
|
+
* } catch (error) {
|
|
134
|
+
* if (error instanceof EventsDataNotInitializedError) {
|
|
135
|
+
* // Prompt re-installation
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
var EventsDataNotInitializedError = class extends PublishEventError {
|
|
141
|
+
constructor() {
|
|
142
|
+
super("No eventing installation data found. Re-run the app installation to initialize event provider metadata.");
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Thrown when the provider key passed to {@link publishEvent} does not match any provider
|
|
147
|
+
* declared in the app's eventing configuration.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* try {
|
|
152
|
+
* await publishEvent({ client, provider: "order-events", event: "order.created", payload });
|
|
153
|
+
* } catch (error) {
|
|
154
|
+
* if (error instanceof ProviderNotFoundError) {
|
|
155
|
+
* // "order-events" was not found — check app.commerce.config.ts
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
var ProviderNotFoundError = class extends PublishEventError {
|
|
161
|
+
constructor(providerKey) {
|
|
162
|
+
super(`No event provider with key '${providerKey}' found in the app eventing configuration.`);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Thrown when the event name passed to {@link publishEvent} does not match any event
|
|
167
|
+
* declared under the given provider in the app's eventing configuration.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* try {
|
|
172
|
+
* await publishEvent({ client, provider: "order-events", event: "order.created", payload });
|
|
173
|
+
* } catch (error) {
|
|
174
|
+
* if (error instanceof EventNotFoundError) {
|
|
175
|
+
* // "order.created" was not found under "order-events" — check app.commerce.config.ts
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
var EventNotFoundError = class extends PublishEventError {
|
|
181
|
+
constructor(eventName, providerKey) {
|
|
182
|
+
super(`No event named '${eventName}' found under provider '${providerKey}'.`);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region source/access/events.ts
|
|
188
|
+
/**
|
|
189
|
+
* Publishes an event declared in the app's eventing configuration.
|
|
190
|
+
*
|
|
191
|
+
* Resolves the provider key and event name to their respective I/O Events IDs from
|
|
192
|
+
* data written to system storage at installation time, then delegates the HTTP call
|
|
193
|
+
* to the given client. No management API round-trip is needed at runtime.
|
|
194
|
+
*
|
|
195
|
+
* @param params.client - An {@link AdobeIoEventsApiClient} configured with the correct IMS auth.
|
|
196
|
+
* @param params.provider - The `key` of an event provider declared in `app.commerce.config.ts`.
|
|
197
|
+
* @param params.event - The `name` of an event within that provider.
|
|
198
|
+
* @param params.payload - The event payload. Must be a JSON object.
|
|
199
|
+
*
|
|
200
|
+
* @throws {EventsDataNotInitializedError} If no eventing installation data is found in system storage.
|
|
201
|
+
* @throws {ProviderNotFoundError} If the provider key is not found in the stored data.
|
|
202
|
+
* @throws {EventNotFoundError} If the event name is not found under the given provider.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* import { publishEvent } from "@adobe/aio-commerce-lib-app";
|
|
207
|
+
* import { createAdobeIoEventsApiClient } from "@adobe/aio-commerce-lib-events";
|
|
208
|
+
* import { resolveImsAuthParams } from "@adobe/aio-commerce-lib-auth";
|
|
209
|
+
*
|
|
210
|
+
* export async function main(params) {
|
|
211
|
+
* const client = createAdobeIoEventsApiClient({
|
|
212
|
+
* auth: resolveImsAuthParams(params),
|
|
213
|
+
* config: { ingressBaseUrl: params.AIO_EVENTS_INGRESS_BASE_URL },
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* await publishEvent({
|
|
217
|
+
* client,
|
|
218
|
+
* provider: "order-events",
|
|
219
|
+
* event: "order.created",
|
|
220
|
+
* payload: { orderId: "100000123", total: 149.99 },
|
|
221
|
+
* });
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
async function publishEvent(params) {
|
|
226
|
+
const { client, provider: providerKey, event: eventName, payload } = params;
|
|
227
|
+
const data = await getSystemConfigByKey(EVENTS_STORAGE_KEY);
|
|
228
|
+
if (!data) throw new EventsDataNotInitializedError();
|
|
229
|
+
const providerEntry = data.providers[providerKey];
|
|
230
|
+
if (!providerEntry) throw new ProviderNotFoundError(providerKey);
|
|
231
|
+
const eventEntry = providerEntry.events[eventName];
|
|
232
|
+
if (!eventEntry) throw new EventNotFoundError(eventName, providerKey);
|
|
233
|
+
await client.publishEvent({
|
|
234
|
+
eventCode: eventEntry.code,
|
|
235
|
+
isPhiData: eventEntry.isPhiData,
|
|
236
|
+
payload,
|
|
237
|
+
providerId: providerEntry.id
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//#endregion
|
|
242
|
+
export { AppNotAssociatedError, EventNotFoundError, EventsDataNotInitializedError, ProviderNotFoundError, PublishEventError, getCommerceClient, getCommerceInstance, publishEvent };
|
|
@@ -12,34 +12,17 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { t as validateCommerceAppConfig } from "./validate-Du3LhCre.mjs";
|
|
16
15
|
import { t as stringifyError } from "./error-_RMwtrUA.mjs";
|
|
16
|
+
import { t as validateCommerceAppConfig } from "./validate-9cRZWGrA.mjs";
|
|
17
17
|
import { dirname, join, parse } from "path";
|
|
18
18
|
import { existsSync } from "fs";
|
|
19
19
|
import { access, mkdir, readFile } from "fs/promises";
|
|
20
|
+
import NpmPackageJson from "@npmcli/package-json";
|
|
21
|
+
import { getPackageInfo } from "local-pkg";
|
|
20
22
|
import { resolveCommand } from "package-manager-detector";
|
|
21
23
|
import { detect, getUserAgent } from "package-manager-detector/detect";
|
|
24
|
+
import { satisfies, validRange } from "semver";
|
|
22
25
|
|
|
23
|
-
//#region source/config/lib/define.ts
|
|
24
|
-
/**
|
|
25
|
-
* Helper to type-safely define the app config.
|
|
26
|
-
* @param config - The app config to define.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* import { defineConfig } from "@adobe/aio-commerce-lib-app";
|
|
31
|
-
*
|
|
32
|
-
* // In app.commerce.config.js
|
|
33
|
-
* export default defineConfig({
|
|
34
|
-
* // You get autocompletion and type-safety for the config object.
|
|
35
|
-
* businessConfig: { ... }
|
|
36
|
-
* });
|
|
37
|
-
*/
|
|
38
|
-
function defineConfig(config) {
|
|
39
|
-
return config;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
26
|
//#region ../../packages-private/scripting-utils/source/project.ts
|
|
44
27
|
/**
|
|
45
28
|
* This module exports shared project utilities for the AIO Commerce SDK.
|
|
@@ -57,7 +40,7 @@ async function findUp(name, options = {}) {
|
|
|
57
40
|
const { root } = parse(cwd);
|
|
58
41
|
const stopAt = options.stopAt || root;
|
|
59
42
|
let currentDir = cwd;
|
|
60
|
-
|
|
43
|
+
for (;;) {
|
|
61
44
|
for (const fileName of names) {
|
|
62
45
|
const filePath = join(currentDir, fileName);
|
|
63
46
|
try {
|
|
@@ -88,6 +71,72 @@ async function readPackageJson(cwd = process.cwd()) {
|
|
|
88
71
|
return JSON.parse(await readFile(packageJsonPath, "utf-8"));
|
|
89
72
|
}
|
|
90
73
|
/**
|
|
74
|
+
* Load the nearest package.json file with npmcli's package.json helper.
|
|
75
|
+
* @param cwd The current working directory
|
|
76
|
+
*/
|
|
77
|
+
async function loadPackageJson(cwd = process.cwd()) {
|
|
78
|
+
const packageJsonPath = await findNearestPackageJson(cwd);
|
|
79
|
+
if (!packageJsonPath) return null;
|
|
80
|
+
return NpmPackageJson.load(dirname(packageJsonPath));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert package.json dependencies into a dependency map that can be written back.
|
|
84
|
+
* @param dependencies - Dependency map read from package.json.
|
|
85
|
+
*/
|
|
86
|
+
function toWritablePackageJsonDependencies(dependencies) {
|
|
87
|
+
return Object.fromEntries(Object.entries(dependencies).filter((entry) => Boolean(entry[1])));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the installed package version from a project root.
|
|
91
|
+
* @param packageName - Package name to resolve.
|
|
92
|
+
* @param cwd - Project directory to resolve from.
|
|
93
|
+
*/
|
|
94
|
+
async function getInstalledPackageVersion(packageName, cwd = process.cwd()) {
|
|
95
|
+
return (await getPackageInfo(packageName, { paths: [cwd] }))?.version ?? null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Resolve which dependencies are missing or installed with incompatible versions.
|
|
99
|
+
*
|
|
100
|
+
* Installed package versions are compared with `semver.satisfies`. Declared
|
|
101
|
+
* package.json ranges are not used as compatibility proof because they can
|
|
102
|
+
* differ from what is actually installed.
|
|
103
|
+
*
|
|
104
|
+
* @param requiredDependencies - Dependencies that should exist.
|
|
105
|
+
* @param cwd - Project directory to resolve installed packages from.
|
|
106
|
+
*/
|
|
107
|
+
async function getPackageDependencyInstallPlan(requiredDependencies, cwd = process.cwd()) {
|
|
108
|
+
const plan = {
|
|
109
|
+
incompatible: [],
|
|
110
|
+
missing: []
|
|
111
|
+
};
|
|
112
|
+
const installedVersions = await Promise.all(requiredDependencies.map((dependency) => getInstalledPackageVersion(dependency.name, cwd)));
|
|
113
|
+
requiredDependencies.forEach((dependency, index) => {
|
|
114
|
+
const installedVersion = installedVersions[index];
|
|
115
|
+
if (installedVersion === null) {
|
|
116
|
+
plan.missing.push(dependency);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (validRange(dependency.version) === null) return;
|
|
120
|
+
if (!satisfies(installedVersion, dependency.version, { includePrerelease: true })) plan.incompatible.push({
|
|
121
|
+
...dependency,
|
|
122
|
+
installedVersion
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return plan;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Merge required dependencies into a package.json dependency map when they are missing.
|
|
129
|
+
*
|
|
130
|
+
* @param dependencies - Dependency map to update.
|
|
131
|
+
* @param requiredDependencies - Dependencies that should exist.
|
|
132
|
+
* @param dependencyMaps - Package dependency maps to compare against.
|
|
133
|
+
*/
|
|
134
|
+
function mergePackageJsonDependencies(dependencies, requiredDependencies, dependencyMaps = [dependencies]) {
|
|
135
|
+
const nextDependencies = toWritablePackageJsonDependencies(dependencies);
|
|
136
|
+
for (const { name, version } of requiredDependencies) if (!dependencyMaps.some((dependencyMap) => name in dependencyMap)) nextDependencies[name] = version;
|
|
137
|
+
return nextDependencies;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
91
140
|
* Check if the current working directory is an ESM project.
|
|
92
141
|
* @param cwd The current working directory
|
|
93
142
|
*/
|
|
@@ -120,6 +169,12 @@ const VALID_PACKAGE_MANAGERS = [
|
|
|
120
169
|
"yarn",
|
|
121
170
|
"bun"
|
|
122
171
|
];
|
|
172
|
+
const DEV_DEPENDENCY_INSTALL_FLAGS = {
|
|
173
|
+
bun: "--dev",
|
|
174
|
+
npm: "--save-dev",
|
|
175
|
+
pnpm: "--save-dev",
|
|
176
|
+
yarn: "--dev"
|
|
177
|
+
};
|
|
123
178
|
/**
|
|
124
179
|
* Type guard asserting that a value is a supported `PackageManager`.
|
|
125
180
|
* @param value - The value to check
|
|
@@ -153,16 +208,25 @@ function getExecCommand(packageManager) {
|
|
|
153
208
|
* manager (e.g. `pnpm add foo bar`, `npm i foo bar`).
|
|
154
209
|
* @param packageManager - The detected package manager
|
|
155
210
|
* @param packages - Package specifiers to install (e.g. `["foo@^1.0"]`)
|
|
211
|
+
* @param options - Install command options.
|
|
156
212
|
*/
|
|
157
|
-
function getInstallCommand(packageManager, packages) {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
args: ["install", ...
|
|
213
|
+
function getInstallCommand(packageManager, packages, options = {}) {
|
|
214
|
+
const installArgs = options.dev ? [DEV_DEPENDENCY_INSTALL_FLAGS[packageManager], ...packages] : packages;
|
|
215
|
+
const resolved = resolveCommand(packageManager, "add", installArgs);
|
|
216
|
+
return {
|
|
217
|
+
args: resolved?.args.filter(Boolean) ?? ["install", ...installArgs],
|
|
218
|
+
command: resolved?.command ?? "npm"
|
|
162
219
|
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get the command that installs a project's declared dependencies.
|
|
223
|
+
* @param packageManager - The detected package manager
|
|
224
|
+
*/
|
|
225
|
+
function getProjectInstallCommand(packageManager) {
|
|
226
|
+
const resolved = resolveCommand(packageManager, "install", []);
|
|
163
227
|
return {
|
|
164
|
-
args: resolved
|
|
165
|
-
command: resolved
|
|
228
|
+
args: resolved?.args.filter(Boolean) ?? ["install"],
|
|
229
|
+
command: resolved?.command ?? "npm"
|
|
166
230
|
};
|
|
167
231
|
}
|
|
168
232
|
|
|
@@ -242,4 +306,4 @@ async function parseCommerceAppConfig(cwd = process.cwd()) {
|
|
|
242
306
|
}
|
|
243
307
|
|
|
244
308
|
//#endregion
|
|
245
|
-
export { getExecCommand as a,
|
|
309
|
+
export { getExecCommand as a, getProjectInstallCommand as c, loadPackageJson as d, makeOutputDirFor as f, detectPackageManager as i, getProjectRootDirectory as l, readPackageJson as m, readCommerceAppConfig as n, getInstallCommand as o, mergePackageJsonDependencies as p, resolveCommerceAppConfig as r, getPackageDependencyInstallPlan as s, parseCommerceAppConfig as t, isESM as u };
|
|
@@ -12,6 +12,5 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { _ as
|
|
16
|
-
import { A as ExecutionStatus, B as isCompletedState, C as executeUninstallWorkflow, D as StepFailedEvent, E as StepEvent, F as InstallationRetryMetadata, H as isInProgressState, I as InstallationState, L as InstallationStatus, M as InProgressInstallationState, N as InstallationData, O as StepStartedEvent, P as InstallationError, R as StepStatus, S as createRetryState, T as InstallationHooks, U as isSucceededState, V as isFailedState, _ as ValidationSummary, a as RunValidationOptions, b as ExecuteWorkflowOptions, c as runInstallation, d as CustomInstallationStepDefinition, f as CustomInstallationStepHandler, g as ValidationResult, h as ValidateStepTreeOptions, i as RunUninstallationOptions, j as FailedInstallationState, k as StepSucceededEvent, l as runUninstallation, m as StepValidationResult, n as CreateInitialUninstallationStateOptions, o as createInitialInstallationState, p as defineCustomInstallationStep, r as RunInstallationOptions, s as createInitialUninstallationState, t as CreateInitialInstallationStateOptions, u as runValidation, v as validateStepTree, w as executeWorkflow, x as createInitialState, y as CreateInitialStateOptions, z as SucceededInstallationState } from "../index-Bo0tQsVq.mjs";
|
|
15
|
+
import { $ as StepContextFactory, A as ExecutionStatus, B as isCompletedState, C as executeUninstallWorkflow, D as StepFailedEvent, E as StepEvent, F as InstallationRetryMetadata, G as BranchStep, H as isInProgressState, I as InstallationState, J as InferStepOutput, K as BranchStepOptions, L as InstallationStatus, M as InProgressInstallationState, N as InstallationData, O as StepStartedEvent, P as InstallationError, Q as Step, R as StepStatus, S as createRetryState, T as InstallationHooks, U as isSucceededState, V as isFailedState, W as AnyStep, X as LeafStep, Y as InstallationContext, Z as LeafStepOptions, _ as ValidationSummary, a as RunValidationOptions, at as ValidationIssueSeverity, b as ExecuteWorkflowOptions, c as runInstallation, ct as isBranchStep, d as CustomInstallationStepDefinition, et as StepMeta, f as CustomInstallationStepHandler, g as ValidationResult, h as ValidateStepTreeOptions, i as RunUninstallationOptions, it as ValidationIssue, j as FailedInstallationState, k as StepSucceededEvent, l as runUninstallation, lt as isLeafStep, m as StepValidationResult, n as CreateInitialUninstallationStateOptions, nt as ValidationContext, o as createInitialInstallationState, ot as defineBranchStep, p as defineCustomInstallationStep, q as ExecutionContext, r as RunInstallationOptions, rt as ValidationExecutionContext, s as createInitialUninstallationState, st as defineLeafStep, t as CreateInitialInstallationStateOptions, tt as StepMetaInfo, u as runValidation, v as validateStepTree, w as executeWorkflow, x as createInitialState, y as CreateInitialStateOptions, z as SucceededInstallationState } from "../index-D52xglhZ.mjs";
|
|
17
16
|
export { type AnyStep, type BranchStep, type BranchStepOptions, type CreateInitialInstallationStateOptions, type CreateInitialStateOptions, type CreateInitialUninstallationStateOptions, type CustomInstallationStepDefinition, type CustomInstallationStepHandler, type ExecuteWorkflowOptions, type ExecutionContext, type ExecutionStatus, type FailedInstallationState, type InProgressInstallationState, type InferStepOutput, type InstallationContext, type InstallationData, type InstallationError, type InstallationHooks, type InstallationRetryMetadata, type InstallationState, type InstallationStatus, type LeafStep, type LeafStepOptions, type RunInstallationOptions, type RunUninstallationOptions, type RunValidationOptions, type Step, type StepContextFactory, type StepEvent, type StepFailedEvent, type StepMeta, type StepMetaInfo, type StepStartedEvent, type StepStatus, type StepSucceededEvent, type StepValidationResult, type SucceededInstallationState, type ValidateStepTreeOptions, type ValidationContext, type ValidationExecutionContext, type ValidationIssue, type ValidationIssueSeverity, type ValidationResult, type ValidationSummary, createInitialInstallationState, type createInitialState, createInitialUninstallationState, type createRetryState, type defineBranchStep, defineCustomInstallationStep, type defineLeafStep, type executeUninstallWorkflow, type executeWorkflow, type isBranchStep, isCompletedState, isFailedState, isInProgressState, type isLeafStep, isSucceededState, runInstallation, runUninstallation, runValidation, type validateStepTree };
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { a as runValidation, c as isFailedState, i as runUninstallation, l as isInProgressState, n as createInitialUninstallationState, o as defineCustomInstallationStep, r as runInstallation, s as isCompletedState, t as createInitialInstallationState, u as isSucceededState } from "../management-
|
|
15
|
+
import { a as runValidation, c as isFailedState, i as runUninstallation, l as isInProgressState, n as createInitialUninstallationState, o as defineCustomInstallationStep, r as runInstallation, s as isCompletedState, t as createInitialInstallationState, u as isSucceededState } from "../management-B89ApQVY.mjs";
|
|
16
16
|
|
|
17
17
|
export { createInitialInstallationState, createInitialUninstallationState, defineCustomInstallationStep, isCompletedState, isFailedState, isInProgressState, isSucceededState, runInstallation, runUninstallation, runValidation };
|