@salesforce/storefront-next-runtime 0.3.1 → 0.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/dist/DesignComponent.js +37 -12
- package/dist/DesignComponent.js.map +1 -1
- package/dist/DesignContext.js +47 -2
- package/dist/DesignContext.js.map +1 -1
- package/dist/DesignFrame.js +1 -1
- package/dist/DesignRegion.js +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/custom-global-preferences.d.ts +20 -0
- package/dist/custom-global-preferences.d.ts.map +1 -0
- package/dist/custom-global-preferences.js +28 -0
- package/dist/custom-global-preferences.js.map +1 -0
- package/dist/custom-site-preferences.d.ts +20 -0
- package/dist/custom-site-preferences.d.ts.map +1 -0
- package/dist/custom-site-preferences.js +28 -0
- package/dist/custom-site-preferences.js.map +1 -0
- package/dist/data-store-custom-global-preferences.d.ts +2 -0
- package/dist/data-store-custom-global-preferences.js +6 -0
- package/dist/data-store-custom-site-preferences.d.ts +2 -0
- package/dist/data-store-custom-site-preferences.js +6 -0
- package/dist/data-store-gcp-preferences.d.ts +2 -0
- package/dist/data-store-gcp-preferences.js +6 -0
- package/dist/data-store.d.ts +97 -0
- package/dist/data-store.d.ts.map +1 -0
- package/dist/data-store.js +42 -0
- package/dist/data-store.js.map +1 -0
- package/dist/design-data.d.ts +82 -88
- package/dist/design-data.d.ts.map +1 -1
- package/dist/design-data.js +95 -57
- package/dist/design-data.js.map +1 -1
- package/dist/design-messaging.d.ts +2 -2
- package/dist/design-react-core.d.ts +2 -2
- package/dist/events.d.ts +34 -6
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +6 -6
- package/dist/events.js.map +1 -1
- package/dist/gcp-preferences.d.ts +52 -0
- package/dist/gcp-preferences.d.ts.map +1 -0
- package/dist/gcp-preferences.js +61 -0
- package/dist/gcp-preferences.js.map +1 -0
- package/dist/i18n-client.d.ts +38 -0
- package/dist/i18n-client.d.ts.map +1 -0
- package/dist/i18n-client.js +72 -0
- package/dist/i18n-client.js.map +1 -0
- package/dist/i18n.d.ts +63 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +98 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +60 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/messaging-api.js +3 -1
- package/dist/messaging-api.js.map +1 -1
- package/dist/scapi.d.ts +247 -2
- package/dist/scapi.d.ts.map +1 -1
- package/dist/scapi.js +1 -1
- package/dist/scapi.js.map +1 -1
- package/dist/site-context.d.ts +93 -17
- package/dist/site-context.d.ts.map +1 -1
- package/dist/site-context.js +2 -417
- package/dist/site-context2.js +513 -0
- package/dist/site-context2.js.map +1 -0
- package/dist/types2.d.ts +210 -0
- package/dist/types2.d.ts.map +1 -1
- package/dist/utils.js +179 -0
- package/dist/utils.js.map +1 -0
- package/package.json +63 -4
- package/dist/site-context.js.map +0 -1
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","names":["defaultInterpolation: InterpolationOptions","cached: ReturnType<typeof createI18nextMiddleware> | null","getLocale"],"sources":["../src/i18n/context.ts","../src/i18n/defaults.ts","../src/i18n/middleware.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport i18next, { type i18n } from 'i18next';\nimport { createContext, type RouterContextProvider } from 'react-router';\n\ntype I18nContextValue = {\n getLocale: () => string;\n getI18nextInstance: () => i18n;\n};\n\n// Internal context key — not exported. Use getTranslation() / getLocale() to read,\n// and mockI18nContext() in tests to write.\nexport const i18nextContext = createContext<I18nContextValue | null>(null);\n\n/**\n * Gets the i18next instance and translation function for non-component code.\n * Use `useTranslation` hook for React components. Mirrors the `getConfig`/`useConfig` pattern.\n */\nexport function getTranslation(context?: Readonly<RouterContextProvider>) {\n if (context && typeof window === 'undefined') {\n const i18nextData = context.get(i18nextContext);\n if (!i18nextData) {\n throw new Error('i18next data not found in context. Ensure i18next middleware runs before loaders.');\n }\n\n const i18nextInstance = i18nextData.getI18nextInstance();\n return {\n i18next: i18nextInstance,\n t: i18nextInstance.t,\n };\n }\n\n return {\n i18next,\n t: i18next.t,\n };\n}\n\n/**\n * Gets the active locale string from server context.\n * Returns undefined on the client (locale is on the document element or URL).\n */\nexport function getLocale(context: Readonly<RouterContextProvider>): string | undefined {\n return context.get(i18nextContext)?.getLocale();\n}\n\n/**\n * Sets up a mock i18n context on a RouterContextProvider for use in tests.\n * Replaces the need to import the internal i18nextContext key directly.\n */\nexport function mockI18nContext(\n contextProvider: RouterContextProvider,\n options: { locale?: string; instance?: i18n } = {}\n): void {\n const { locale = 'en-GB', instance = i18next } = options;\n contextProvider.set(i18nextContext, {\n getLocale: () => locale,\n getI18nextInstance: () => instance,\n });\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { InterpolationOptions } from 'i18next';\n\n/** Shared i18next interpolation config. Disables HTML escaping (React handles that) and adds `{{ value, number }}` formatting via `toLocaleString`. */\nexport const defaultInterpolation: InterpolationOptions = {\n escapeValue: false,\n format: (value, format) => {\n if (format === 'number' && typeof value === 'number') {\n return value.toLocaleString();\n }\n return value;\n },\n};\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { initReactI18next } from 'react-i18next';\nimport { createI18nextMiddleware } from 'remix-i18next/middleware';\nimport { type MiddlewareFunction } from 'react-router';\nimport { requestToLocaleMap } from '../site-context/index.js';\nimport { defaultInterpolation } from './defaults.js';\nimport { i18nextContext } from './context.js';\nimport type { I18nMiddlewareConfig } from './types.js';\n\n/**\n * Creates a server-side i18next middleware from the provided config.\n * Lazy-initializes on first request so supported languages can come from runtime config.\n */\nexport function createI18nMiddleware(config: I18nMiddlewareConfig): MiddlewareFunction<Response> {\n const { resources, supportedLanguages, fallbackLanguage, interpolation, plugins = [] } = config;\n\n let cached: ReturnType<typeof createI18nextMiddleware> | null = null;\n\n return async (args, next) => {\n if (!cached) {\n cached = createI18nextMiddleware({\n detection: {\n order: ['custom'],\n // eslint-disable-next-line @typescript-eslint/require-await\n findLocale: async (request: Request) => {\n const localeId = requestToLocaleMap.get(request);\n return localeId ?? null;\n },\n fallbackLanguage,\n supportedLanguages,\n },\n i18next: {\n resources,\n interpolation: { ...defaultInterpolation, ...interpolation },\n },\n plugins: [initReactI18next, ...plugins],\n });\n }\n\n const [originalMiddleware, getLocale, getInstance] = cached;\n\n args.context.set(i18nextContext, {\n getLocale: () => getLocale(args.context),\n getI18nextInstance: () => getInstance(args.context),\n });\n\n return originalMiddleware(args, next);\n };\n}\n"],"mappings":";;;;;;;;AAyBA,MAAa,iBAAiB,cAAuC,KAAK;;;;;AAM1E,SAAgB,eAAe,SAA2C;AACtE,KAAI,WAAW,OAAO,WAAW,aAA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package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ interface HostToClientConfiguration {
|
|
|
54
54
|
* The locale to use on the client.
|
|
55
55
|
*/
|
|
56
56
|
locale?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The regions by id that are available in the component tree.
|
|
59
|
+
*/
|
|
60
|
+
regions: Record<string, RegionInfo>;
|
|
57
61
|
}
|
|
58
62
|
/**
|
|
59
63
|
* The default keys that are forwarded from the host to the client.
|
|
@@ -72,6 +76,19 @@ interface ComponentInfo {
|
|
|
72
76
|
* The component type.
|
|
73
77
|
*/
|
|
74
78
|
type: string;
|
|
79
|
+
/**
|
|
80
|
+
* The custom name for the component.
|
|
81
|
+
*/
|
|
82
|
+
name?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Information about a region in the component tree.
|
|
86
|
+
*/
|
|
87
|
+
interface RegionInfo {
|
|
88
|
+
/**
|
|
89
|
+
* The custom name for the region.
|
|
90
|
+
*/
|
|
91
|
+
name: string;
|
|
75
92
|
}
|
|
76
93
|
/**
|
|
77
94
|
* Information about a component type.
|
|
@@ -211,6 +228,31 @@ interface ClientAcknowledgedEvent extends WithBaseEvent, HostToClientConfigurati
|
|
|
211
228
|
interface ClientConfigurationChangedEvent extends WithBaseEvent, HostToClientConfiguration {
|
|
212
229
|
eventType: 'ClientConfigurationChanged';
|
|
213
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Emits when a component is updated in the editor.
|
|
233
|
+
*
|
|
234
|
+
* @target client
|
|
235
|
+
* @group Events
|
|
236
|
+
*/
|
|
237
|
+
interface ComponentUpdatedEvent extends WithBaseEvent {
|
|
238
|
+
eventType: 'ComponentUpdated';
|
|
239
|
+
/**
|
|
240
|
+
* The unique identifier of the component
|
|
241
|
+
*/
|
|
242
|
+
componentId: string;
|
|
243
|
+
/**
|
|
244
|
+
* The type of change that occurred
|
|
245
|
+
*/
|
|
246
|
+
changeType: 'name' | 'visibility';
|
|
247
|
+
/**
|
|
248
|
+
* The new value after the change
|
|
249
|
+
*/
|
|
250
|
+
newValue: unknown;
|
|
251
|
+
/**
|
|
252
|
+
* The old value before the change (optional)
|
|
253
|
+
*/
|
|
254
|
+
oldValue?: unknown;
|
|
255
|
+
}
|
|
214
256
|
/**
|
|
215
257
|
* Emits when dragging from the host enters the client window.
|
|
216
258
|
* @target client
|
|
@@ -538,6 +580,7 @@ interface ClientEventNameMapping extends IsomorphicEventNameMapping {
|
|
|
538
580
|
HostKeyPressed: HostKeyPressedEvent;
|
|
539
581
|
ClientAcknowledged: ClientAcknowledgedEvent;
|
|
540
582
|
ClientConfigurationChanged: ClientConfigurationChangedEvent;
|
|
583
|
+
ComponentUpdated: ComponentUpdatedEvent;
|
|
541
584
|
ClientWindowDragEntered: ClientWindowDragEnteredEvent;
|
|
542
585
|
ClientWindowDragMoved: ClientWindowDragMovedEvent;
|
|
543
586
|
ClientWindowDragExited: ClientWindowDragExitedEvent;
|
|
@@ -1136,6 +1179,22 @@ interface HostApi extends IsomorphicApi {
|
|
|
1136
1179
|
* ```
|
|
1137
1180
|
*/
|
|
1138
1181
|
setClientConfiguration(event: EventPayload<ClientConfigurationChangedEvent>): void;
|
|
1182
|
+
/**
|
|
1183
|
+
* Notifies the client that a component has been updated.
|
|
1184
|
+
*
|
|
1185
|
+
* @param event - The component update event containing the component ID, change type, and new value
|
|
1186
|
+
* @stability development
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```typescript
|
|
1190
|
+
* api.notifyComponentUpdated({
|
|
1191
|
+
* componentId: 'comp-123',
|
|
1192
|
+
* changeType: 'name',
|
|
1193
|
+
* newValue: 'New Component Name'
|
|
1194
|
+
* });
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
1197
|
+
notifyComponentUpdated(event: EventPayload<ComponentUpdatedEvent>): void;
|
|
1139
1198
|
}
|
|
1140
1199
|
//#endregion
|
|
1141
1200
|
//#region src/design/messaging-api/client.d.ts
|
|
@@ -1167,5 +1226,5 @@ declare function createHostApi({
|
|
|
1167
1226
|
logger
|
|
1168
1227
|
}: HostConfiguration): HostApi;
|
|
1169
1228
|
//#endregion
|
|
1170
|
-
export { ClientWindowDragExitedEvent as A, ComponentMovedToRegionEvent as B, ClientConfigurationChangedEvent as C, ClientReady as D, ClientPageChangedEvent as E, ComponentDragStartedEvent as F,
|
|
1229
|
+
export { WindowScrollChangedEvent as $, ClientWindowDragExitedEvent as A, ComponentMovedToRegionEvent as B, ClientConfigurationChangedEvent as C, ClientReady as D, ClientPageChangedEvent as E, ComponentDragStartedEvent as F, DefaultForwardedKeys as G, ComponentSelectedEvent as H, ComponentFocusedEvent as I, HostKeyPressedEvent as J, ErrorEvent as K, ComponentHoveredInEvent as L, ComponentAddedToRegionEvent as M, ComponentDeletedEvent as N, ClientWindowDragDroppedEvent as O, ComponentDeselectedEvent as P, RegionInfo as Q, ComponentHoveredOutEvent as R, ClientAcknowledgedEvent as S, ClientInitializedEvent as T, ComponentType as U, ComponentPropertiesChangedEvent as V, ComponentUpdatedEvent as W, MediaChangedEvent as X, HostToClientConfiguration as Y, PageSettingsChangedEvent as Z, IsomorphicEventNameMapping as _, ClientEventNameMapping as a, WithEventType as b, EventHandler as c, HostApi as d, HostConfiguration as f, IsomorphicConfiguration as g, IsomorphicApi as h, ClientConfiguration as i, ClientWindowDragMovedEvent as j, ClientWindowDragEnteredEvent as k, EventPayload as l, HostMessage as m, createClientApi as n, ClientMessage as o, HostEventNameMapping as p, HostDisconnected as q, ClientApi as r, ConfigFactory as s, createHostApi as t, EventTypeName as u, MessageEmitter as v, ClientDisconnectedEvent as w, WithMeta as x, Source as y, ComponentInfo as z };
|
|
1171
1230
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/design/messaging-api/domain-types.ts","../src/design/messaging-api/api-types.ts","../src/design/messaging-api/client.ts","../src/design/messaging-api/host.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/design/messaging-api/domain-types.ts","../src/design/messaging-api/api-types.ts","../src/design/messaging-api/client.ts","../src/design/messaging-api/host.ts"],"sourcesContent":[],"mappings":";;;;AA0FA,UAlEU,aAAA,CAkEE;EAKK,SAAA,EAAA,MAAa;AAkB9B;AAUA;AA8DA;AAiBA;AAeA;AAkBA,UA3MU,eAAA,CA2MO;EAiBA;AAUjB;AASA;EAUiB,WAAA,EAAA,MAAA;AAyBjB;AAQA,UAnRU,iBAAA,CAmRO;EAAmC;;;EAAkD,aAAA,EAAA,MAAA;AAQtG;AAQA;AAQA;;;UAhSU,gBAAA,CAuSM;EANJ;;;AAaZ;EAWiB,CAAA,EAAA,MAAA;EAA0C;;;;EAS1C,CAAA,EAAA,MAAA;;AAAqE,UArTrE,yBAAA,CAqTqE;EAGxE;;;EAQG,UAAA,EA5TD,MA4TC,CAAA,MAAkB,EA5TJ,aA4TY,CAAA;EAa1B;AAiBjB;AAqCA;EAQiB,cAAA,EAnYG,MAmYH,CAAA,MAAyB,EAnYP,aAmYe,CAAA;EAQjC;AAQjB;AAQA;EAiBiB,MAAA,EAxaL,MAwaK,CAAA,MAAA,EAAA,MAAA,CAA2B;EAAgB;;;EAChD,MAAA,CAAA,EAAA,MAAA;EAAa;AA2CzB;AAYA;WAxda,eAAe;;;ACjE5B;AAQA;AA0BA;AAMiB,KDgCL,oBAAA,GChC+B,SAAA,GAAA,WAAA,GAAA,WAAA,GAAA,YAAA,GAAA,QAAA;;;;AAIpB,UDiCN,aAAA,CCjCM;EACE;;;EAGG,EAAA,EAAA,MAAA;EACH;;;EAQR,IAAA,EAAA,MAAA;EACM;;;EAGA,IAAA,CAAA,EAAA,MAAA;;;AAOvB;;AAEyB,UDyBR,UAAA,CCzBQ;EACL;;;EAGE,IAAA,EAAA,MAAA;;;;;AAKU,UD0Bf,aAAA,CC1Be;EACT;;;EAZmD,EAAA,EAAA,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6CAE1B,SAAS,WAAW;;;;;;;;;;;;;;;mCAgB9B,aAAa;;;;;;;;;;;;;;;;;;;;;;yBAuBvB,aAAa;;;;;;;;;;;;;;;;;;;;;;uCAuBC,aAAa;;;;;;;;;;;;;;;;;;;;;;qCAuBf,aAAa;;;;;;;;;;;;;;;;;;;;;;sCAuBZ,aAAa;;;;;;;;;;;;;;;;;;;;;;uCAuBZ,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wCAkCZ,0BAA0B,gCACrD,aAAa,gCAAuC;;;;;;;;wBAUzC,aAAa;;;;;;;;;;;;gCAYL,aAAa;;;;;;;;;;;;;;;;gCAgBb,aAAa;;;;ADnpB/C;AAKA;AAkBA;AAUA;AA8DA;AAiBA;AAeA;AAkBiB,iBE3MD,eAAA,CF2MwB;EAK9B,OAAA;EAAA,EAAA;EAAA,aAAkB;EALoB;AAAa,CAAb,EE3M6B,mBF2MhB,CAAA,EE3MsC,SF2MtC;;;AAjJ7D;AAKA;AAkBA;AAUA;AA8DA;AAiBA;AAeA;AAkBiB,iBGxMD,aAAA,CHwMwB;EAAA,OAK9B;EAAA,EAAA;EAAA;AALsC,CAKpB,EG7M2B,iBHwMP,CAAA,EGxM2B,OHwMd"}
|
package/dist/messaging-api.js
CHANGED
|
@@ -258,7 +258,8 @@ function createClientApi({ emitter, id, forwardedKeys = [], logger }) {
|
|
|
258
258
|
const defaultConfigFactory = () => Promise.resolve({
|
|
259
259
|
components: {},
|
|
260
260
|
componentTypes: {},
|
|
261
|
-
labels: {}
|
|
261
|
+
labels: {},
|
|
262
|
+
regions: {}
|
|
262
263
|
});
|
|
263
264
|
/**
|
|
264
265
|
* Factory function to create a HostApi instance.
|
|
@@ -303,6 +304,7 @@ function createHostApi({ emitter, id, logger }) {
|
|
|
303
304
|
notifyError: messenger.toEmitter("Error"),
|
|
304
305
|
focusComponent: messenger.toEmitter("ComponentFocused"),
|
|
305
306
|
setClientConfiguration: messenger.toEmitter("ClientConfigurationChanged"),
|
|
307
|
+
notifyComponentUpdated: messenger.toEmitter("ComponentUpdated"),
|
|
306
308
|
connect: ({ configFactory = defaultConfigFactory, onClientConnected, onClientDisconnected, onError }) => {
|
|
307
309
|
if (isConnected) disconnect();
|
|
308
310
|
const { markIsReady, emptyQueue } = messenger.connect();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-api.js","names":["subscriptions: (() => void)[]","connectionTimeoutId: number | null","hostConfig: HostToClientConfiguration | null","defaultConfigFactory: ConfigFactory","subscriptions: (() => void)[]"],"sources":["../src/design/messaging-api/messenger.ts","../src/design/messaging-api/client.ts","../src/design/messaging-api/host.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { EventHandler, MessageEmitter, Source } from './api-types';\n\nexport type Logger = (message: unknown, source: 'host' | 'client') => void;\n\n/**\n * Handles the basic logic for event emitting and receiving between a client and a host.\n *\n * The `Messenger` class manages a single connection to a source event emitter,\n * allowing for the sending and receiving of typed events between two parties (e.g., client and host).\n * It distinguishes events based on their source, ensuring that only events from the opposite source are processed.\n *\n * @template TInMapping - The mapping of incoming event names to their payload types.\n * @template TOutMapping - The mapping of outgoing event names to their payload types.\n */\nexport class Messenger<TInMapping, TOutMapping> {\n private readonly source: Source;\n\n private readonly id: string;\n\n private readonly emitter: MessageEmitter<TInMapping, TOutMapping>;\n\n private readonly handlers = new Map<keyof TInMapping, EventHandler<TInMapping>[]>();\n\n private remoteId?: string;\n\n private readonly logger: Logger;\n\n private _isReady = false;\n\n private unsubscribe?: () => void;\n private queue: { eventType: keyof TOutMapping; data: Omit<TOutMapping[keyof TOutMapping], 'eventType'> }[] = [];\n\n constructor({\n source,\n id,\n emitter,\n logger = () => {\n // Noop\n },\n }: {\n source: Source;\n id: string;\n emitter: MessageEmitter<TInMapping, TOutMapping>;\n logger?: Logger;\n }) {\n this.source = source;\n this.id = id;\n this.emitter = emitter;\n this.logger = logger;\n }\n\n /**\n * Connects the given emitter. This ensures only a single connection to the provided emitter.\n *\n * This method registers a listener for events from the opposite source.\n * It ensures that only events from the opposite source are processed.\n */\n connect(): { markIsReady: () => void; emptyQueue: () => void } {\n // Unsubscribe if this is called again.\n this.unsubscribe?.();\n this._isReady = false;\n\n this.unsubscribe = this.emitter.addEventListener((event) => {\n if (event.meta?.pdMessagingApi && event.meta.source !== this.source) {\n this.logger(event, this.source === 'host' ? 'client' : 'host');\n\n [event.eventType, 'Event'].forEach((eventType) => {\n this.handlers\n .get(eventType as keyof TInMapping)\n ?.forEach((handler) => handler(event as Parameters<EventHandler<TInMapping>>[0]));\n });\n }\n });\n\n return {\n markIsReady: () => {\n this._isReady = true;\n },\n emptyQueue: () => {\n this.queue.forEach(({ eventType, data }) => this.emit(eventType, data));\n this.queue = [];\n },\n };\n }\n\n /**\n * Returns the id of the connected remote.\n */\n getRemoteId(): string | undefined {\n return this.remoteId;\n }\n\n /**\n * Sets the id of the connected remote.\n */\n setRemoteId(remoteId: string | undefined): void {\n this.remoteId = remoteId;\n }\n\n /**\n * Emits an event to the connected remote.\n * This attaches metadata to each event that is emitted.\n *\n * @param eventName - The event to emit.\n * @param data - The data to emit.\n * @param options - The options for the event.\n * @param options.requireRemoteId - Whether to require a remote id to be set before emitting the event.\n */\n emit<TEvent extends keyof TOutMapping>(\n eventType: TEvent,\n data: Omit<TOutMapping[TEvent], 'eventType'>,\n { requireRemoteId = true }: { requireRemoteId?: boolean } = {}\n ): void {\n if (requireRemoteId && !this._isReady) {\n this.queue.push({ eventType, data });\n\n return;\n }\n\n const event = {\n ...data,\n eventType,\n meta: {\n hostId: this.source === 'host' ? this.id : this.remoteId,\n clientId: this.source === 'client' ? this.id : this.remoteId,\n source: this.source,\n pdMessagingApi: true as const,\n },\n };\n\n this.logger(event, this.source);\n\n this.emitter.postMessage(event);\n }\n\n /**\n * Subscribes to an event from the connected remote.\n *\n * @param event - The event to subscribe to.\n * @param handler - The handler to call when the event is emitted.\n * @returns A function to unsubscribe from the event.\n */\n on<TEvent extends keyof TInMapping>(event: TEvent, handler: EventHandler<TInMapping, TEvent>): () => void {\n const handlers = this.handlers.get(event) ?? [];\n\n handlers.push(handler as EventHandler<TInMapping>);\n this.handlers.set(event, handlers);\n\n return () => {\n const eventHandlers = this.handlers.get(event) ?? [];\n const index = eventHandlers.indexOf(handler as EventHandler<TInMapping>);\n\n if (index > -1) {\n eventHandlers.splice(index, 1);\n }\n\n if (eventHandlers.length === 0) {\n this.handlers.delete(event);\n }\n };\n }\n\n /**\n * Returns a function that emits an event to the connected remote.\n *\n * @param eventName - The event to emit.\n * @returns A function that emits an event to the connected remote.\n */\n toEmitter<TEvent extends keyof TOutMapping>(\n eventName: TEvent\n ): (event: Omit<TOutMapping[TEvent], 'eventType'>) => void {\n return (event: Omit<TOutMapping[TEvent], 'eventType'>) => {\n this.emit(eventName, event);\n };\n }\n\n toPromise<TEvent extends keyof TInMapping>(eventName: TEvent): Promise<TInMapping[TEvent]> {\n return new Promise<TInMapping[TEvent]>((resolve) => {\n const unsub = this.on(eventName, (event) => {\n unsub();\n resolve(event as unknown as TInMapping[TEvent]);\n });\n });\n }\n\n /**\n * Disconnects the messenger.\n */\n disconnect(): void {\n this.unsubscribe?.();\n this.handlers.clear();\n this.remoteId = undefined;\n this.unsubscribe = undefined;\n }\n\n /**\n * Returns whether the messenger is ready to emit events.\n *\n * @returns Whether the messenger is ready.\n */\n isReady(): boolean {\n return this._isReady;\n }\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n ClientApi,\n ClientConfiguration,\n ClientEventNameMapping,\n HostEventNameMapping,\n WithMeta,\n} from './api-types';\nimport type { HostToClientConfiguration } from './domain-types';\nimport { Messenger } from './messenger';\n\n/**\n * Factory function to create a ClientApi instance.\n *\n * @public\n * @param _config - Configuration object for the client API (currently unused).\n * @returns {ClientApi} An instance of the ClientApi interface.\n */\nexport function createClientApi({ emitter, id, forwardedKeys = [], logger }: ClientConfiguration): ClientApi {\n const messenger = new Messenger<ClientEventNameMapping, HostEventNameMapping>({\n source: 'client',\n id,\n emitter,\n logger,\n });\n const subscriptions: (() => void)[] = [];\n\n let isConnected = false;\n let connectionTimeoutId: number | null = null;\n let hostConfig: HostToClientConfiguration | null = null;\n\n const clearConnectionTimeout = () => {\n if (connectionTimeoutId) {\n clearTimeout(connectionTimeoutId);\n connectionTimeoutId = null;\n }\n };\n\n const disconnect = ({ isReconnecting = false }: { isReconnecting?: boolean } = {}) => {\n clearConnectionTimeout();\n isConnected = false;\n subscriptions.forEach((unsubscribe) => unsubscribe());\n messenger.disconnect();\n messenger.emit('ClientDisconnected', { clientId: id, reconnect: isReconnecting });\n };\n\n const connect = ({\n interval = 1_000,\n timeout = 60_000,\n prepareClient = () => Promise.resolve(),\n onHostConnected,\n onHostDisconnected,\n onError,\n usid,\n }: {\n interval?: number;\n timeout?: number;\n prepareClient?: () => Promise<void>;\n onHostConnected?: (configuration: HostToClientConfiguration) => void;\n onHostDisconnected?: (reconnect: () => void) => void;\n onError?: (error: Error) => void;\n usid?: string;\n } = {}) => {\n if (isConnected) {\n disconnect({ isReconnecting: true });\n }\n\n const expirationTime = Date.now() + timeout;\n const { markIsReady, emptyQueue } = messenger.connect();\n\n subscriptions.push(\n messenger.on('ClientAcknowledged', async (event) => {\n if (event.meta.hostId === messenger.getRemoteId()) {\n // We've already been acknowledged by the host in this case.\n return;\n }\n\n hostConfig = event;\n messenger.setRemoteId(event.meta.hostId);\n clearConnectionTimeout();\n\n try {\n await prepareClient();\n\n markIsReady();\n messenger.emit('ClientReady', { clientId: id });\n onHostConnected?.(hostConfig);\n emptyQueue();\n } catch (error) {\n onError?.(error as Error);\n }\n }),\n messenger.on('ClientConfigurationChanged', (event) => {\n hostConfig = event;\n onHostConnected?.(hostConfig);\n }),\n messenger.on('HostDisconnected', () => {\n disconnect();\n onHostDisconnected?.(() =>\n connect({\n interval,\n timeout,\n prepareClient,\n onHostConnected,\n onHostDisconnected,\n onError,\n usid,\n })\n );\n })\n );\n\n const checkInitialization = () => {\n if (Date.now() > expirationTime) {\n throw new Error(`Timed out after waiting ${timeout}ms for host connection`);\n }\n\n messenger.emit('ClientInitialized', { clientId: id, forwardedKeys, usid }, { requireRemoteId: false });\n connectionTimeoutId = setTimeout(() => checkInitialization(), interval) as unknown as number;\n };\n\n isConnected = true;\n checkInitialization();\n };\n\n return {\n addComponentToRegion: messenger.toEmitter('ComponentAddedToRegion'),\n moveComponentToRegion: messenger.toEmitter('ComponentMovedToRegion'),\n startComponentDrag: messenger.toEmitter('ComponentDragStarted'),\n hoverInToComponent: messenger.toEmitter('ComponentHoveredIn'),\n hoverOutOfComponent: messenger.toEmitter('ComponentHoveredOut'),\n selectComponent: messenger.toEmitter('ComponentSelected'),\n deselectComponent: messenger.toEmitter('ComponentDeselected'),\n deleteComponent: messenger.toEmitter('ComponentDeleted'),\n notifyWindowScrollChanged: messenger.toEmitter('WindowScrollChanged'),\n notifyClientReady: messenger.toEmitter('ClientReady'),\n notifyError: messenger.toEmitter('Error'),\n notifyClientPageChanged: messenger.toEmitter('ClientPageChanged'),\n connect,\n on: <TEvent extends keyof ClientEventNameMapping>(\n eventName: TEvent,\n handler: (handlerEvent: Readonly<WithMeta & ClientEventNameMapping[TEvent]>) => void\n ) =>\n messenger.on(eventName, (event) => {\n // Don't receive any events besides the acknowledged event until the client is ready\n if (eventName === 'ClientAcknowledged' || messenger.isReady()) {\n handler(event);\n }\n }),\n disconnect,\n getRemoteId: () => messenger.getRemoteId(),\n };\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n HostApi,\n HostConfiguration,\n ClientEventNameMapping,\n HostEventNameMapping,\n WithMeta,\n ConfigFactory,\n} from './api-types';\nimport type { ClientInitializedEvent } from './domain-types';\nimport { Messenger } from './messenger';\n\nconst defaultConfigFactory: ConfigFactory = () => Promise.resolve({ components: {}, componentTypes: {}, labels: {} });\n/**\n * Factory function to create a HostApi instance.\n *\n * @public\n * @param {HostConfiguration} config - Configuration object for the host API.\n * @returns {HostApi} An instance of the HostApi interface.\n */\nexport function createHostApi({ emitter, id, logger }: HostConfiguration): HostApi {\n const messenger = new Messenger<HostEventNameMapping, ClientEventNameMapping>({\n source: 'host',\n id,\n emitter,\n logger,\n });\n const subscriptions: (() => void)[] = [];\n let isConnected = false;\n const disconnect = () => {\n isConnected = false;\n messenger.disconnect();\n subscriptions.forEach((unsubscribe) => unsubscribe());\n messenger.emit('HostDisconnected', {});\n };\n\n return {\n addComponentToRegion: messenger.toEmitter('ComponentAddedToRegion'),\n moveComponentToRegion: messenger.toEmitter('ComponentMovedToRegion'),\n startComponentDrag: messenger.toEmitter('ComponentDragStarted'),\n hoverInToComponent: messenger.toEmitter('ComponentHoveredIn'),\n hoverOutOfComponent: messenger.toEmitter('ComponentHoveredOut'),\n selectComponent: messenger.toEmitter('ComponentSelected'),\n deselectComponent: messenger.toEmitter('ComponentDeselected'),\n deleteComponent: messenger.toEmitter('ComponentDeleted'),\n forwardKeyPress: messenger.toEmitter('HostKeyPressed'),\n notifyClientWindowDragDropped: messenger.toEmitter('ClientWindowDragDropped'),\n notifyClientWindowDragEntered: messenger.toEmitter('ClientWindowDragEntered'),\n notifyClientWindowDragMoved: messenger.toEmitter('ClientWindowDragMoved'),\n notifyClientWindowDragExited: messenger.toEmitter('ClientWindowDragExited'),\n setComponentProperties: messenger.toEmitter('ComponentPropertiesChanged'),\n notifyWindowScrollChanged: messenger.toEmitter('WindowScrollChanged'),\n notifyPageSettingsChanged: messenger.toEmitter('PageSettingsChanged'),\n notifyMediaChanged: () => messenger.emit('MediaChangedEvent', {}),\n notifyError: messenger.toEmitter('Error'),\n focusComponent: messenger.toEmitter('ComponentFocused'),\n setClientConfiguration: messenger.toEmitter('ClientConfigurationChanged'),\n connect: ({\n configFactory = defaultConfigFactory,\n onClientConnected,\n onClientDisconnected,\n onError,\n }: {\n configFactory: ConfigFactory;\n onClientConnected?: (clientId: string, config: ClientInitializedEvent) => void;\n onClientDisconnected?: (clientId: string) => void;\n onError?: (error: Error) => void;\n }) => {\n if (isConnected) {\n disconnect();\n }\n\n const { markIsReady, emptyQueue } = messenger.connect();\n\n subscriptions.push(\n messenger.on('ClientDisconnected', (event) => {\n if (event.meta.clientId === messenger.getRemoteId()) {\n messenger.setRemoteId(undefined);\n }\n\n onClientDisconnected?.(event.meta.clientId ?? '');\n })\n );\n\n subscriptions.push(\n messenger.on('ClientInitialized', async (event) => {\n const remoteId = messenger.getRemoteId();\n\n // If the same client tries reconnecting, we should allow it.\n // If there is no remote id, we should allow any client to connect.\n if ((remoteId && event.meta.clientId === remoteId) || !remoteId) {\n messenger.setRemoteId(event.meta.clientId);\n\n try {\n const config = await configFactory();\n\n messenger.emit('ClientAcknowledged', config, { requireRemoteId: false });\n\n const { clientId } = await messenger.toPromise('ClientReady');\n\n if (clientId !== messenger.getRemoteId()) {\n throw new Error('Client id mismatch');\n }\n\n markIsReady();\n onClientConnected?.(clientId, event);\n emptyQueue();\n } catch (error) {\n onError?.(error as Error);\n }\n }\n })\n );\n\n isConnected = true;\n },\n on: <TEvent extends keyof HostEventNameMapping>(\n event: TEvent,\n handler: (handlerEvent: Readonly<WithMeta & HostEventNameMapping[TEvent]>) => void\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => messenger.on(event as any, handler as any),\n disconnect,\n getRemoteId: () => messenger.getRemoteId(),\n };\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,YAAb,MAAgD;CAC5C,AAAiB;CAEjB,AAAiB;CAEjB,AAAiB;CAEjB,AAAiB,2BAAW,IAAI,KAAmD;CAEnF,AAAQ;CAER,AAAiB;CAEjB,AAAQ,WAAW;CAEnB,AAAQ;CACR,AAAQ,QAAqG,EAAE;CAE/G,YAAY,EACR,QACA,IACA,SACA,eAAe,MAQhB;AACC,OAAK,SAAS;AACd,OAAK,KAAK;AACV,OAAK,UAAU;AACf,OAAK,SAAS;;;;;;;;CASlB,UAA+D;AAE3D,OAAK,eAAe;AACpB,OAAK,WAAW;AAEhB,OAAK,cAAc,KAAK,QAAQ,kBAAkB,UAAU;AACxD,OAAI,MAAM,MAAM,kBAAkB,MAAM,KAAK,WAAW,KAAK,QAAQ;AACjE,SAAK,OAAO,OAAO,KAAK,WAAW,SAAS,WAAW,OAAO;AAE9D,KAAC,MAAM,WAAW,QAAQ,CAAC,SAAS,cAAc;AAC9C,UAAK,SACA,IAAI,UAA8B,EACjC,SAAS,YAAY,QAAQ,MAAiD,CAAC;MACvF;;IAER;AAEF,SAAO;GACH,mBAAmB;AACf,SAAK,WAAW;;GAEpB,kBAAkB;AACd,SAAK,MAAM,SAAS,EAAE,WAAW,WAAW,KAAK,KAAK,WAAW,KAAK,CAAC;AACvE,SAAK,QAAQ,EAAE;;GAEtB;;;;;CAML,cAAkC;AAC9B,SAAO,KAAK;;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eAAe;AAEpC,gBAAU,KAAK,sBAAsB,QAAQ,EAAE,iBAAiB,OAAO,CAAC;MAExE,MAAM,EAAE,aAAa,MAAM,UAAU,UAAU,cAAc;AAE7D,UAAI,aAAa,UAAU,aAAa,CACpC,OAAM,IAAI,MAAM,qBAAqB;AAGzC,mBAAa;AACb,0BAAoB,UAAU,MAAM;AACpC,kBAAY;cACP,OAAO;AACZ,gBAAU,MAAe;;;KAGnC,CACL;AAED,iBAAc;;EAElB,KACI,OACA,YAEC,UAAU,GAAG,OAAc,QAAe;EAC/C;EACA,mBAAmB,UAAU,aAAa;EAC7C"}
|
|
1
|
+
{"version":3,"file":"messaging-api.js","names":["subscriptions: (() => void)[]","connectionTimeoutId: number | null","hostConfig: HostToClientConfiguration | null","defaultConfigFactory: ConfigFactory","subscriptions: (() => void)[]"],"sources":["../src/design/messaging-api/messenger.ts","../src/design/messaging-api/client.ts","../src/design/messaging-api/host.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { EventHandler, MessageEmitter, Source } from './api-types';\n\nexport type Logger = (message: unknown, source: 'host' | 'client') => void;\n\n/**\n * Handles the basic logic for event emitting and receiving between a client and a host.\n *\n * The `Messenger` class manages a single connection to a source event emitter,\n * allowing for the sending and receiving of typed events between two parties (e.g., client and host).\n * It distinguishes events based on their source, ensuring that only events from the opposite source are processed.\n *\n * @template TInMapping - The mapping of incoming event names to their payload types.\n * @template TOutMapping - The mapping of outgoing event names to their payload types.\n */\nexport class Messenger<TInMapping, TOutMapping> {\n private readonly source: Source;\n\n private readonly id: string;\n\n private readonly emitter: MessageEmitter<TInMapping, TOutMapping>;\n\n private readonly handlers = new Map<keyof TInMapping, EventHandler<TInMapping>[]>();\n\n private remoteId?: string;\n\n private readonly logger: Logger;\n\n private _isReady = false;\n\n private unsubscribe?: () => void;\n private queue: { eventType: keyof TOutMapping; data: Omit<TOutMapping[keyof TOutMapping], 'eventType'> }[] = [];\n\n constructor({\n source,\n id,\n emitter,\n logger = () => {\n // Noop\n },\n }: {\n source: Source;\n id: string;\n emitter: MessageEmitter<TInMapping, TOutMapping>;\n logger?: Logger;\n }) {\n this.source = source;\n this.id = id;\n this.emitter = emitter;\n this.logger = logger;\n }\n\n /**\n * Connects the given emitter. This ensures only a single connection to the provided emitter.\n *\n * This method registers a listener for events from the opposite source.\n * It ensures that only events from the opposite source are processed.\n */\n connect(): { markIsReady: () => void; emptyQueue: () => void } {\n // Unsubscribe if this is called again.\n this.unsubscribe?.();\n this._isReady = false;\n\n this.unsubscribe = this.emitter.addEventListener((event) => {\n if (event.meta?.pdMessagingApi && event.meta.source !== this.source) {\n this.logger(event, this.source === 'host' ? 'client' : 'host');\n\n [event.eventType, 'Event'].forEach((eventType) => {\n this.handlers\n .get(eventType as keyof TInMapping)\n ?.forEach((handler) => handler(event as Parameters<EventHandler<TInMapping>>[0]));\n });\n }\n });\n\n return {\n markIsReady: () => {\n this._isReady = true;\n },\n emptyQueue: () => {\n this.queue.forEach(({ eventType, data }) => this.emit(eventType, data));\n this.queue = [];\n },\n };\n }\n\n /**\n * Returns the id of the connected remote.\n */\n getRemoteId(): string | undefined {\n return this.remoteId;\n }\n\n /**\n * Sets the id of the connected remote.\n */\n setRemoteId(remoteId: string | undefined): void {\n this.remoteId = remoteId;\n }\n\n /**\n * Emits an event to the connected remote.\n * This attaches metadata to each event that is emitted.\n *\n * @param eventName - The event to emit.\n * @param data - The data to emit.\n * @param options - The options for the event.\n * @param options.requireRemoteId - Whether to require a remote id to be set before emitting the event.\n */\n emit<TEvent extends keyof TOutMapping>(\n eventType: TEvent,\n data: Omit<TOutMapping[TEvent], 'eventType'>,\n { requireRemoteId = true }: { requireRemoteId?: boolean } = {}\n ): void {\n if (requireRemoteId && !this._isReady) {\n this.queue.push({ eventType, data });\n\n return;\n }\n\n const event = {\n ...data,\n eventType,\n meta: {\n hostId: this.source === 'host' ? this.id : this.remoteId,\n clientId: this.source === 'client' ? this.id : this.remoteId,\n source: this.source,\n pdMessagingApi: true as const,\n },\n };\n\n this.logger(event, this.source);\n\n this.emitter.postMessage(event);\n }\n\n /**\n * Subscribes to an event from the connected remote.\n *\n * @param event - The event to subscribe to.\n * @param handler - The handler to call when the event is emitted.\n * @returns A function to unsubscribe from the event.\n */\n on<TEvent extends keyof TInMapping>(event: TEvent, handler: EventHandler<TInMapping, TEvent>): () => void {\n const handlers = this.handlers.get(event) ?? [];\n\n handlers.push(handler as EventHandler<TInMapping>);\n this.handlers.set(event, handlers);\n\n return () => {\n const eventHandlers = this.handlers.get(event) ?? [];\n const index = eventHandlers.indexOf(handler as EventHandler<TInMapping>);\n\n if (index > -1) {\n eventHandlers.splice(index, 1);\n }\n\n if (eventHandlers.length === 0) {\n this.handlers.delete(event);\n }\n };\n }\n\n /**\n * Returns a function that emits an event to the connected remote.\n *\n * @param eventName - The event to emit.\n * @returns A function that emits an event to the connected remote.\n */\n toEmitter<TEvent extends keyof TOutMapping>(\n eventName: TEvent\n ): (event: Omit<TOutMapping[TEvent], 'eventType'>) => void {\n return (event: Omit<TOutMapping[TEvent], 'eventType'>) => {\n this.emit(eventName, event);\n };\n }\n\n toPromise<TEvent extends keyof TInMapping>(eventName: TEvent): Promise<TInMapping[TEvent]> {\n return new Promise<TInMapping[TEvent]>((resolve) => {\n const unsub = this.on(eventName, (event) => {\n unsub();\n resolve(event as unknown as TInMapping[TEvent]);\n });\n });\n }\n\n /**\n * Disconnects the messenger.\n */\n disconnect(): void {\n this.unsubscribe?.();\n this.handlers.clear();\n this.remoteId = undefined;\n this.unsubscribe = undefined;\n }\n\n /**\n * Returns whether the messenger is ready to emit events.\n *\n * @returns Whether the messenger is ready.\n */\n isReady(): boolean {\n return this._isReady;\n }\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n ClientApi,\n ClientConfiguration,\n ClientEventNameMapping,\n HostEventNameMapping,\n WithMeta,\n} from './api-types';\nimport type { HostToClientConfiguration } from './domain-types';\nimport { Messenger } from './messenger';\n\n/**\n * Factory function to create a ClientApi instance.\n *\n * @public\n * @param _config - Configuration object for the client API (currently unused).\n * @returns {ClientApi} An instance of the ClientApi interface.\n */\nexport function createClientApi({ emitter, id, forwardedKeys = [], logger }: ClientConfiguration): ClientApi {\n const messenger = new Messenger<ClientEventNameMapping, HostEventNameMapping>({\n source: 'client',\n id,\n emitter,\n logger,\n });\n const subscriptions: (() => void)[] = [];\n\n let isConnected = false;\n let connectionTimeoutId: number | null = null;\n let hostConfig: HostToClientConfiguration | null = null;\n\n const clearConnectionTimeout = () => {\n if (connectionTimeoutId) {\n clearTimeout(connectionTimeoutId);\n connectionTimeoutId = null;\n }\n };\n\n const disconnect = ({ isReconnecting = false }: { isReconnecting?: boolean } = {}) => {\n clearConnectionTimeout();\n isConnected = false;\n subscriptions.forEach((unsubscribe) => unsubscribe());\n messenger.disconnect();\n messenger.emit('ClientDisconnected', { clientId: id, reconnect: isReconnecting });\n };\n\n const connect = ({\n interval = 1_000,\n timeout = 60_000,\n prepareClient = () => Promise.resolve(),\n onHostConnected,\n onHostDisconnected,\n onError,\n usid,\n }: {\n interval?: number;\n timeout?: number;\n prepareClient?: () => Promise<void>;\n onHostConnected?: (configuration: HostToClientConfiguration) => void;\n onHostDisconnected?: (reconnect: () => void) => void;\n onError?: (error: Error) => void;\n usid?: string;\n } = {}) => {\n if (isConnected) {\n disconnect({ isReconnecting: true });\n }\n\n const expirationTime = Date.now() + timeout;\n const { markIsReady, emptyQueue } = messenger.connect();\n\n subscriptions.push(\n messenger.on('ClientAcknowledged', async (event) => {\n if (event.meta.hostId === messenger.getRemoteId()) {\n // We've already been acknowledged by the host in this case.\n return;\n }\n\n hostConfig = event;\n messenger.setRemoteId(event.meta.hostId);\n clearConnectionTimeout();\n\n try {\n await prepareClient();\n\n markIsReady();\n messenger.emit('ClientReady', { clientId: id });\n onHostConnected?.(hostConfig);\n emptyQueue();\n } catch (error) {\n onError?.(error as Error);\n }\n }),\n messenger.on('ClientConfigurationChanged', (event) => {\n hostConfig = event;\n onHostConnected?.(hostConfig);\n }),\n messenger.on('HostDisconnected', () => {\n disconnect();\n onHostDisconnected?.(() =>\n connect({\n interval,\n timeout,\n prepareClient,\n onHostConnected,\n onHostDisconnected,\n onError,\n usid,\n })\n );\n })\n );\n\n const checkInitialization = () => {\n if (Date.now() > expirationTime) {\n throw new Error(`Timed out after waiting ${timeout}ms for host connection`);\n }\n\n messenger.emit('ClientInitialized', { clientId: id, forwardedKeys, usid }, { requireRemoteId: false });\n connectionTimeoutId = setTimeout(() => checkInitialization(), interval) as unknown as number;\n };\n\n isConnected = true;\n checkInitialization();\n };\n\n return {\n addComponentToRegion: messenger.toEmitter('ComponentAddedToRegion'),\n moveComponentToRegion: messenger.toEmitter('ComponentMovedToRegion'),\n startComponentDrag: messenger.toEmitter('ComponentDragStarted'),\n hoverInToComponent: messenger.toEmitter('ComponentHoveredIn'),\n hoverOutOfComponent: messenger.toEmitter('ComponentHoveredOut'),\n selectComponent: messenger.toEmitter('ComponentSelected'),\n deselectComponent: messenger.toEmitter('ComponentDeselected'),\n deleteComponent: messenger.toEmitter('ComponentDeleted'),\n notifyWindowScrollChanged: messenger.toEmitter('WindowScrollChanged'),\n notifyClientReady: messenger.toEmitter('ClientReady'),\n notifyError: messenger.toEmitter('Error'),\n notifyClientPageChanged: messenger.toEmitter('ClientPageChanged'),\n connect,\n on: <TEvent extends keyof ClientEventNameMapping>(\n eventName: TEvent,\n handler: (handlerEvent: Readonly<WithMeta & ClientEventNameMapping[TEvent]>) => void\n ) =>\n messenger.on(eventName, (event) => {\n // Don't receive any events besides the acknowledged event until the client is ready\n if (eventName === 'ClientAcknowledged' || messenger.isReady()) {\n handler(event);\n }\n }),\n disconnect,\n getRemoteId: () => messenger.getRemoteId(),\n };\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n HostApi,\n HostConfiguration,\n ClientEventNameMapping,\n HostEventNameMapping,\n WithMeta,\n ConfigFactory,\n} from './api-types';\nimport type { ClientInitializedEvent } from './domain-types';\nimport { Messenger } from './messenger';\n\nconst defaultConfigFactory: ConfigFactory = () =>\n Promise.resolve({ components: {}, componentTypes: {}, labels: {}, regions: {} });\n/**\n * Factory function to create a HostApi instance.\n *\n * @public\n * @param {HostConfiguration} config - Configuration object for the host API.\n * @returns {HostApi} An instance of the HostApi interface.\n */\nexport function createHostApi({ emitter, id, logger }: HostConfiguration): HostApi {\n const messenger = new Messenger<HostEventNameMapping, ClientEventNameMapping>({\n source: 'host',\n id,\n emitter,\n logger,\n });\n const subscriptions: (() => void)[] = [];\n let isConnected = false;\n const disconnect = () => {\n isConnected = false;\n messenger.disconnect();\n subscriptions.forEach((unsubscribe) => unsubscribe());\n messenger.emit('HostDisconnected', {});\n };\n\n return {\n addComponentToRegion: messenger.toEmitter('ComponentAddedToRegion'),\n moveComponentToRegion: messenger.toEmitter('ComponentMovedToRegion'),\n startComponentDrag: messenger.toEmitter('ComponentDragStarted'),\n hoverInToComponent: messenger.toEmitter('ComponentHoveredIn'),\n hoverOutOfComponent: messenger.toEmitter('ComponentHoveredOut'),\n selectComponent: messenger.toEmitter('ComponentSelected'),\n deselectComponent: messenger.toEmitter('ComponentDeselected'),\n deleteComponent: messenger.toEmitter('ComponentDeleted'),\n forwardKeyPress: messenger.toEmitter('HostKeyPressed'),\n notifyClientWindowDragDropped: messenger.toEmitter('ClientWindowDragDropped'),\n notifyClientWindowDragEntered: messenger.toEmitter('ClientWindowDragEntered'),\n notifyClientWindowDragMoved: messenger.toEmitter('ClientWindowDragMoved'),\n notifyClientWindowDragExited: messenger.toEmitter('ClientWindowDragExited'),\n setComponentProperties: messenger.toEmitter('ComponentPropertiesChanged'),\n notifyWindowScrollChanged: messenger.toEmitter('WindowScrollChanged'),\n notifyPageSettingsChanged: messenger.toEmitter('PageSettingsChanged'),\n notifyMediaChanged: () => messenger.emit('MediaChangedEvent', {}),\n notifyError: messenger.toEmitter('Error'),\n focusComponent: messenger.toEmitter('ComponentFocused'),\n setClientConfiguration: messenger.toEmitter('ClientConfigurationChanged'),\n notifyComponentUpdated: messenger.toEmitter('ComponentUpdated'),\n connect: ({\n configFactory = defaultConfigFactory,\n onClientConnected,\n onClientDisconnected,\n onError,\n }: {\n configFactory: ConfigFactory;\n onClientConnected?: (clientId: string, config: ClientInitializedEvent) => void;\n onClientDisconnected?: (clientId: string) => void;\n onError?: (error: Error) => void;\n }) => {\n if (isConnected) {\n disconnect();\n }\n\n const { markIsReady, emptyQueue } = messenger.connect();\n\n subscriptions.push(\n messenger.on('ClientDisconnected', (event) => {\n if (event.meta.clientId === messenger.getRemoteId()) {\n messenger.setRemoteId(undefined);\n }\n\n onClientDisconnected?.(event.meta.clientId ?? '');\n })\n );\n\n subscriptions.push(\n messenger.on('ClientInitialized', async (event) => {\n const remoteId = messenger.getRemoteId();\n\n // If the same client tries reconnecting, we should allow it.\n // If there is no remote id, we should allow any client to connect.\n if ((remoteId && event.meta.clientId === remoteId) || !remoteId) {\n messenger.setRemoteId(event.meta.clientId);\n\n try {\n const config = await configFactory();\n\n messenger.emit('ClientAcknowledged', config, { requireRemoteId: false });\n\n const { clientId } = await messenger.toPromise('ClientReady');\n\n if (clientId !== messenger.getRemoteId()) {\n throw new Error('Client id mismatch');\n }\n\n markIsReady();\n onClientConnected?.(clientId, event);\n emptyQueue();\n } catch (error) {\n onError?.(error as Error);\n }\n }\n })\n );\n\n isConnected = true;\n },\n on: <TEvent extends keyof HostEventNameMapping>(\n event: TEvent,\n handler: (handlerEvent: Readonly<WithMeta & HostEventNameMapping[TEvent]>) => void\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => messenger.on(event as any, handler as any),\n disconnect,\n getRemoteId: () => messenger.getRemoteId(),\n };\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,YAAb,MAAgD;CAC5C,AAAiB;CAEjB,AAAiB;CAEjB,AAAiB;CAEjB,AAAiB,2BAAW,IAAI,KAAmD;CAEnF,AAAQ;CAER,AAAiB;CAEjB,AAAQ,WAAW;CAEnB,AAAQ;CACR,AAAQ,QAAqG,EAAE;CAE/G,YAAY,EACR,QACA,IACA,SACA,eAAe,MAQhB;AACC,OAAK,SAAS;AACd,OAAK,KAAK;AACV,OAAK,UAAU;AACf,OAAK,SAAS;;;;;;;;CASlB,UAA+D;AAE3D,OAAK,eAAe;AACpB,OAAK,WAAW;AAEhB,OAAK,cAAc,KAAK,QAAQ,kBAAkB,UAAU;AACxD,OAAI,MAAM,MAAM,kBAAkB,MAAM,KAAK,WAAW,KAAK,QAAQ;AACjE,SAAK,OAAO,OAAO,KAAK,WAAW,SAAS,WAAW,OAAO;AAE9D,KAAC,MAAM,WAAW,QAAQ,CAAC,SAAS,cAAc;AAC9C,UAAK,SACA,IAAI,UAA8B,EACjC,SAAS,YAAY,QAAQ,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WAAU,YAAY,OAAU;AAGpC,2BAAuB,MAAM,KAAK,YAAY,GAAG;KACnD,CACL;AAED,iBAAc,KACV,UAAU,GAAG,qBAAqB,OAAO,UAAU;IAC/C,MAAM,WAAW,UAAU,aAAa;AAIxC,QAAK,YAAY,MAAM,KAAK,aAAa,YAAa,CAAC,UAAU;AAC7D,eAAU,YAAY,MAAM,KAAK,SAAS;AAE1C,SAAI;MACA,MAAM,SAAS,MAAM,eAAe;AAEpC,gBAAU,KAAK,sBAAsB,QAAQ,EAAE,iBAAiB,OAAO,CAAC;MAExE,MAAM,EAAE,aAAa,MAAM,UAAU,UAAU,cAAc;AAE7D,UAAI,aAAa,UAAU,aAAa,CACpC,OAAM,IAAI,MAAM,qBAAqB;AAGzC,mBAAa;AACb,0BAAoB,UAAU,MAAM;AACpC,kBAAY;cACP,OAAO;AACZ,gBAAU,MAAe;;;KAGnC,CACL;AAED,iBAAc;;EAElB,KACI,OACA,YAEC,UAAU,GAAG,OAAc,QAAe;EAC/C;EACA,mBAAmB,UAAU,aAAa;EAC7C"}
|
package/dist/scapi.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, ClientOptions, FetchOptions, FetchResponse, Middleware } from "openapi-fetch";
|
|
1
|
+
import createOpenApiFetchClient, { Client, ClientOptions, FetchOptions, FetchResponse, Middleware } from "openapi-fetch";
|
|
2
2
|
export * from "openapi-fetch";
|
|
3
3
|
|
|
4
4
|
//#region src/scapi-client/generated/shopper-baskets-v1.d.ts
|
|
@@ -16538,6 +16538,33 @@ interface paths$9 {
|
|
|
16538
16538
|
patch?: never;
|
|
16539
16539
|
trace?: never;
|
|
16540
16540
|
};
|
|
16541
|
+
"/organizations/{organizationId}/qualifiers/resolve": {
|
|
16542
|
+
parameters: {
|
|
16543
|
+
query?: never;
|
|
16544
|
+
header?: never;
|
|
16545
|
+
path?: never;
|
|
16546
|
+
cookie?: never;
|
|
16547
|
+
};
|
|
16548
|
+
get?: never;
|
|
16549
|
+
put?: never;
|
|
16550
|
+
/**
|
|
16551
|
+
* Resolve qualifiers for customer groups, campaign promotions, and data binding contexts.
|
|
16552
|
+
* @description Resolves a list of customer groups, campaigns, promotions, and data bindings for the given user.
|
|
16553
|
+
*
|
|
16554
|
+
* The endpoint takes each value and determines whether the user is active for the item:
|
|
16555
|
+
* - Customer groups are verified against the user's qualification via the EffectiveContext.
|
|
16556
|
+
* - Campaign qualifiers are checked to determine if the user is applicable for each campaign and promotion.
|
|
16557
|
+
* - Data bindings are resolved by fetching the requested records from their respective data providers.
|
|
16558
|
+
*
|
|
16559
|
+
* Returns a boolean result for each provided qualifier and resolved data binding objects grouped by provider type and record identifier. If a qualifier cannot be validated, `false` is returned for that item. If a data binding cannot be resolved, it is omitted from the response.
|
|
16560
|
+
*/
|
|
16561
|
+
post: operations$25["resolveQualifiers"];
|
|
16562
|
+
delete?: never;
|
|
16563
|
+
options?: never;
|
|
16564
|
+
head?: never;
|
|
16565
|
+
patch?: never;
|
|
16566
|
+
trace?: never;
|
|
16567
|
+
};
|
|
16541
16568
|
}
|
|
16542
16569
|
interface components$9 {
|
|
16543
16570
|
schemas: {
|
|
@@ -16608,6 +16635,24 @@ interface components$9 {
|
|
|
16608
16635
|
* @example commerce_assets.carousel
|
|
16609
16636
|
*/
|
|
16610
16637
|
typeId: string;
|
|
16638
|
+
/**
|
|
16639
|
+
* Component Name
|
|
16640
|
+
* @description Display name of the component.
|
|
16641
|
+
* @example Topseller Carousel
|
|
16642
|
+
*/
|
|
16643
|
+
name?: string;
|
|
16644
|
+
/**
|
|
16645
|
+
* Fragment
|
|
16646
|
+
* @description Indicates whether the component is a fragment. True if the component is a fragment, otherwise false.
|
|
16647
|
+
* @example false
|
|
16648
|
+
*/
|
|
16649
|
+
fragment?: boolean;
|
|
16650
|
+
/**
|
|
16651
|
+
* Content Link UUID
|
|
16652
|
+
* @description Represents a globally unique identifier for every instance of a content component (or fragment) rendered on a page.
|
|
16653
|
+
* @example 0e1f329d4ac66ff2c3bbf70301
|
|
16654
|
+
*/
|
|
16655
|
+
contentLinkUuid?: string;
|
|
16611
16656
|
/**
|
|
16612
16657
|
* Component Data
|
|
16613
16658
|
* @description The configuration data assigned to the component.
|
|
@@ -16617,6 +16662,18 @@ interface components$9 {
|
|
|
16617
16662
|
* }
|
|
16618
16663
|
*/
|
|
16619
16664
|
data?: Record<string, never>;
|
|
16665
|
+
/**
|
|
16666
|
+
* Localized
|
|
16667
|
+
* @description Whether the component has been localized with content in the current locale. If false, the components content will fallback to the default locale.
|
|
16668
|
+
* @example true
|
|
16669
|
+
*/
|
|
16670
|
+
localized?: boolean;
|
|
16671
|
+
/**
|
|
16672
|
+
* Visibility
|
|
16673
|
+
* @description Whether the component is visible based on the current visiblity rules and context.
|
|
16674
|
+
* @example true
|
|
16675
|
+
*/
|
|
16676
|
+
visible?: boolean;
|
|
16620
16677
|
/**
|
|
16621
16678
|
* Custom Component Data
|
|
16622
16679
|
* @description Any custom data added by the custom code for this component.
|
|
@@ -17036,6 +17093,115 @@ interface components$9 {
|
|
|
17036
17093
|
*/
|
|
17037
17094
|
data: components$9["schemas"]["ContentFolder"][];
|
|
17038
17095
|
} & components$9["schemas"]["ResultBase"];
|
|
17096
|
+
/** @description A data binding requirement specifying a provider type and record identifier to resolve. */
|
|
17097
|
+
DataBindingRequirement: {
|
|
17098
|
+
/**
|
|
17099
|
+
* Type
|
|
17100
|
+
* @description The data provider type identifier.
|
|
17101
|
+
* @example content_asset
|
|
17102
|
+
*/
|
|
17103
|
+
type: string;
|
|
17104
|
+
/**
|
|
17105
|
+
* ID
|
|
17106
|
+
* @description The record identifier to resolve from the data provider.
|
|
17107
|
+
* @example homepage-banner
|
|
17108
|
+
*/
|
|
17109
|
+
id: string;
|
|
17110
|
+
};
|
|
17111
|
+
/**
|
|
17112
|
+
* @description A resolved data binding object containing arbitrary key-value pairs returned by the data provider for a specific record. The shape of the object is determined by the data provider and may include any user-defined fields.
|
|
17113
|
+
* @example {
|
|
17114
|
+
* "title": "Winter Sale",
|
|
17115
|
+
* "body": "<div>Shop our winter collection</div>",
|
|
17116
|
+
* "c_showCountdown": true,
|
|
17117
|
+
* "c_endDate": "2026-03-31T23:59:59Z"
|
|
17118
|
+
* }
|
|
17119
|
+
*/
|
|
17120
|
+
ResolvedDataBinding: {
|
|
17121
|
+
[key: string]: unknown;
|
|
17122
|
+
};
|
|
17123
|
+
/** @description A campaign and promotion pair to resolve qualification for. */
|
|
17124
|
+
CampaignQualifier: {
|
|
17125
|
+
/**
|
|
17126
|
+
* Campaign ID
|
|
17127
|
+
* @description The identifier of the campaign.
|
|
17128
|
+
* @example my-campaign
|
|
17129
|
+
*/
|
|
17130
|
+
campaignId: string;
|
|
17131
|
+
/**
|
|
17132
|
+
* Promotion ID
|
|
17133
|
+
* @description The identifier of the promotion within the campaign.
|
|
17134
|
+
* @example my-promotion
|
|
17135
|
+
*/
|
|
17136
|
+
promotionId: string;
|
|
17137
|
+
};
|
|
17138
|
+
/** @description Request body for resolving customer group qualifications, campaign promotion eligibility, and data bindings. All fields are optional. An empty body is valid and returns an empty response. */
|
|
17139
|
+
QualifierResolveRequest: {
|
|
17140
|
+
/**
|
|
17141
|
+
* Customer Groups
|
|
17142
|
+
* @description List of customer group identifiers to resolve qualification for.
|
|
17143
|
+
* @example [
|
|
17144
|
+
* "VIP"
|
|
17145
|
+
* ]
|
|
17146
|
+
*/
|
|
17147
|
+
customerGroups?: string[];
|
|
17148
|
+
/**
|
|
17149
|
+
* Campaign Qualifiers
|
|
17150
|
+
* @description List of campaign and promotion pairs to resolve qualification for.
|
|
17151
|
+
*/
|
|
17152
|
+
campaignQualifiers?: components$9["schemas"]["CampaignQualifier"][];
|
|
17153
|
+
/**
|
|
17154
|
+
* Data Bindings
|
|
17155
|
+
* @description List of data binding requirements to resolve, each specifying a provider type and record identifier.
|
|
17156
|
+
*/
|
|
17157
|
+
dataBindings?: components$9["schemas"]["DataBindingRequirement"][];
|
|
17158
|
+
};
|
|
17159
|
+
/** @description Response containing the resolved qualification results for customer groups, campaign qualifiers, and data bindings. */
|
|
17160
|
+
QualifierResolveResponse: {
|
|
17161
|
+
/**
|
|
17162
|
+
* Customer Groups
|
|
17163
|
+
* @description Map of customer group identifiers to their qualification status. True if the user is qualified, false otherwise.
|
|
17164
|
+
* @example {
|
|
17165
|
+
* "VIP": true
|
|
17166
|
+
* }
|
|
17167
|
+
*/
|
|
17168
|
+
customerGroups?: {
|
|
17169
|
+
[key: string]: boolean;
|
|
17170
|
+
};
|
|
17171
|
+
/**
|
|
17172
|
+
* Campaign Qualifiers
|
|
17173
|
+
* @description Map of campaign identifiers to a map of promotion identifiers and their qualification status. True if the user is applicable, false otherwise.
|
|
17174
|
+
* @example {
|
|
17175
|
+
* "my-campaign": {
|
|
17176
|
+
* "my-promotion": false
|
|
17177
|
+
* }
|
|
17178
|
+
* }
|
|
17179
|
+
*/
|
|
17180
|
+
campaignQualifiers?: {
|
|
17181
|
+
[key: string]: {
|
|
17182
|
+
[key: string]: boolean;
|
|
17183
|
+
};
|
|
17184
|
+
};
|
|
17185
|
+
/**
|
|
17186
|
+
* Data Bindings
|
|
17187
|
+
* @description Resolved data binding objects grouped by provider type, then by record identifier. Used by the expression resolver to evaluate attribute expressions.
|
|
17188
|
+
* @example {
|
|
17189
|
+
* "content_asset": {
|
|
17190
|
+
* "homepage-banner": {
|
|
17191
|
+
* "title": "Winter Sale",
|
|
17192
|
+
* "body": "<div>Shop our winter collection</div>",
|
|
17193
|
+
* "c_showCountdown": true,
|
|
17194
|
+
* "c_endDate": "2026-03-31T23:59:59Z"
|
|
17195
|
+
* }
|
|
17196
|
+
* }
|
|
17197
|
+
* }
|
|
17198
|
+
*/
|
|
17199
|
+
dataBindings?: {
|
|
17200
|
+
[key: string]: {
|
|
17201
|
+
[key: string]: components$9["schemas"]["ResolvedDataBinding"];
|
|
17202
|
+
};
|
|
17203
|
+
};
|
|
17204
|
+
};
|
|
17039
17205
|
};
|
|
17040
17206
|
responses: {
|
|
17041
17207
|
/** @description Your access token is invalid or expired and can’t be used to identify a user. */
|
|
@@ -17491,6 +17657,50 @@ interface operations$25 {
|
|
|
17491
17657
|
403: components$9["responses"]["403forbidden"];
|
|
17492
17658
|
};
|
|
17493
17659
|
};
|
|
17660
|
+
resolveQualifiers: {
|
|
17661
|
+
parameters: {
|
|
17662
|
+
query: {
|
|
17663
|
+
/** @description The identifier of the site that a request is being made in the context of. Attributes might have site specific values, and some objects may only be assigned to specific sites. */
|
|
17664
|
+
siteId: components$9["parameters"]["siteId"];
|
|
17665
|
+
/** @description A descriptor for a geographical region by both a language and country code. By combining these two, regional differences in a language can be addressed, such as with the request header parameter `Accept-Language` following [RFC 2616](https://tools.ietf.org/html/rfc2616) & [RFC 1766](https://tools.ietf.org/html/rfc1766). This can also just refer to a language code, also RFC 2616/1766 compliant, as a default if there is no specific match for a country. Finally, can also be used to define default behavior if there is no locale specified. */
|
|
17666
|
+
locale?: components$9["parameters"]["locale"];
|
|
17667
|
+
};
|
|
17668
|
+
header?: never;
|
|
17669
|
+
path: {
|
|
17670
|
+
/**
|
|
17671
|
+
* @description An identifier for the organization the request is being made by
|
|
17672
|
+
* @example f_ecom_zzxy_prd
|
|
17673
|
+
*/
|
|
17674
|
+
organizationId: components$9["parameters"]["organizationId"];
|
|
17675
|
+
};
|
|
17676
|
+
cookie?: never;
|
|
17677
|
+
};
|
|
17678
|
+
requestBody: {
|
|
17679
|
+
content: {
|
|
17680
|
+
"application/json": components$9["schemas"]["QualifierResolveRequest"];
|
|
17681
|
+
};
|
|
17682
|
+
};
|
|
17683
|
+
responses: {
|
|
17684
|
+
/** @description Success. All qualifiers have been resolved. */
|
|
17685
|
+
200: {
|
|
17686
|
+
headers: {
|
|
17687
|
+
[name: string]: unknown;
|
|
17688
|
+
};
|
|
17689
|
+
content: {
|
|
17690
|
+
"application/json": components$9["schemas"]["QualifierResolveResponse"];
|
|
17691
|
+
};
|
|
17692
|
+
};
|
|
17693
|
+
/** @description Bad Request */
|
|
17694
|
+
400: {
|
|
17695
|
+
headers: {
|
|
17696
|
+
[name: string]: unknown;
|
|
17697
|
+
};
|
|
17698
|
+
content: {
|
|
17699
|
+
"application/problem+json": components$9["schemas"]["ErrorResponse"];
|
|
17700
|
+
};
|
|
17701
|
+
};
|
|
17702
|
+
};
|
|
17703
|
+
};
|
|
17494
17704
|
}
|
|
17495
17705
|
type WithRequired$2<T, K$1 extends keyof T> = T & { [P in K$1]-?: T[P] };
|
|
17496
17706
|
//#endregion
|
|
@@ -27648,6 +27858,24 @@ type ProxyClient<TClient extends Client<any, any>, TOperations extends Operation
|
|
|
27648
27858
|
* // OperationsOnly has getCategories, createBasket, etc., but NOT use or eject
|
|
27649
27859
|
*/
|
|
27650
27860
|
type OperationMethodsOnly<T> = T extends ProxyClient<any, any> ? Omit<T, 'use' | 'eject'> : never;
|
|
27861
|
+
/**
|
|
27862
|
+
* Utility type for extending the base client types with custom API clients.
|
|
27863
|
+
*
|
|
27864
|
+
* Used by template projects to extend the base `Clients` type with
|
|
27865
|
+
* custom API clients, adding new client entries to the type.
|
|
27866
|
+
*
|
|
27867
|
+
* @typeParam TBase - The base Clients type from the SDK
|
|
27868
|
+
* @typeParam TCustom - Object type with custom client entries
|
|
27869
|
+
*
|
|
27870
|
+
* @example
|
|
27871
|
+
* ```typescript
|
|
27872
|
+
* type AppClients = MergeClients<Clients, {
|
|
27873
|
+
* loyalty: ProxyClient<Client<LoyaltyPaths>, typeof loyaltyOps>;
|
|
27874
|
+
* storeInventory: ProxyClient<Client<InventoryPaths>, typeof inventoryOps>;
|
|
27875
|
+
* }>;
|
|
27876
|
+
* ```
|
|
27877
|
+
*/
|
|
27878
|
+
type MergeClients<TBase, TCustom extends Record<string, unknown>> = Omit<TBase, keyof TCustom> & TCustom;
|
|
27651
27879
|
//#endregion
|
|
27652
27880
|
//#region src/scapi-client/generated/shopper-login-v1.operations.d.ts
|
|
27653
27881
|
declare const operations$8: {
|
|
@@ -28885,6 +29113,11 @@ declare const operations$6: {
|
|
|
28885
29113
|
readonly b: "/organizations/{organizationId}";
|
|
28886
29114
|
readonly s: "/folders";
|
|
28887
29115
|
};
|
|
29116
|
+
readonly resolveQualifiers: {
|
|
29117
|
+
readonly m: "POST";
|
|
29118
|
+
readonly b: "/organizations/{organizationId}";
|
|
29119
|
+
readonly s: "/qualifiers/resolve";
|
|
29120
|
+
};
|
|
28888
29121
|
};
|
|
28889
29122
|
//#endregion
|
|
28890
29123
|
//#region src/scapi-client/generated/shopper-gift-certificates-v1.operations.d.ts
|
|
@@ -29346,5 +29579,17 @@ declare class AuthTokenInvalidError extends Error {
|
|
|
29346
29579
|
*/
|
|
29347
29580
|
declare const SLAS_AUTH_ENDPOINTS: readonly ["/oauth2/token", "/oauth2/authorize", "/oauth2/logout", "/oauth2/login", "/oauth2/passwordless", "/oauth2/password", "/oauth2/session-bridge", "/oauth2/trusted-agent", "/oauth2/trusted-system", "/oauth2/revoke", "/oauth2/introspect"];
|
|
29348
29581
|
//#endregion
|
|
29349
|
-
|
|
29582
|
+
//#region src/scapi-client/defaultQuerySerializer.d.ts
|
|
29583
|
+
/**
|
|
29584
|
+
* Default query serializer for Commerce Cloud APIs
|
|
29585
|
+
* - Most arrays use comma-separated format (explode: false)
|
|
29586
|
+
* e.g., expand=promotions,variations,prices
|
|
29587
|
+
* - Certain parameters use repeated format (explode: true)
|
|
29588
|
+
* e.g., refine=price=(0..10)&refine=c_refinementColor=green
|
|
29589
|
+
* - Some parameters are automatically grouped by attribute ID before serialization
|
|
29590
|
+
* e.g., ['c_color=Black', 'c_color=Green'] => 'c_color=Black|Green'
|
|
29591
|
+
*/
|
|
29592
|
+
declare function defaultQuerySerializer(queryParams: Record<string, unknown>): string;
|
|
29593
|
+
//#endregion
|
|
29594
|
+
export { ApiError, type AuthConfig, type AuthNamespace, type AuthResponse, AuthTokenInvalidError, type Basket, type BasketHelpersConfig, type BasketHelpersNamespace, Clients, CommerceApiClientConfig, CreateClientOptions, type ErrorDetail, type GetOrCreateBasketOptions, GlobalRequestParameters, type LoginAsGuestOptions, type LoginWithCredentialsOptions, type LogoutOptions, type MergeClients, type OperationInfo, type OperationMap, type OperationMethodsOnly, type PasswordRequestResetOptions, type PasswordResetOptions, type PasswordlessAuthorizeOptions, type PasswordlessExchangeTokenOptions, type ProxyClient, type RefreshTokenOptions, SLAS_AUTH_ENDPOINTS, ShopperBasketsV1, ShopperBasketsV2, type ShopperBasketsV2Client, ShopperConfigurations, ShopperConsents, ShopperContext, ShopperCustomers, ShopperExperience, ShopperGiftCertificates, ShopperLogin, ShopperOrders, ShopperPayments, ShopperProducts, ShopperPromotions, ShopperSearch, ShopperSeo, ShopperStores, type SocialAuthorizationUrlResult, type SocialExchangeCodeOptions, type SocialGetAuthorizationUrlOptions, type TokenResponse, createBasketHelpers, createClient, createCommerceApiClients, createOpenApiFetchClient, defaultQuerySerializer };
|
|
29350
29595
|
//# sourceMappingURL=scapi.d.ts.map
|