@combeenation/custom-code-sdk 0.0.1-alpha1 → 0.0.1-alpha11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,25 +1,82 @@
1
1
  import { z } from 'zod';
2
- import { ZodType } from 'zod';
3
2
 
4
- declare type CmpName = string;
3
+ declare type AppLanguage = 'en' | 'de';
5
4
 
6
- declare type CmpValue = z.infer<typeof ZCmpValue>;
5
+ declare type AssetName = z.infer<typeof ZAssetName>;
7
6
 
8
- declare type CmpValue_2 = z.infer<typeof ZCmpValue_2>;
7
+ export declare class Button {
8
+ #private;
9
+ readonly id: CtrlId;
10
+ constructor(id: CtrlId);
11
+ onRendered(callback: OnRenderedCallback<HTMLButtonElement>): CallbackUnsubscribeOption;
12
+ onClick(callback: OnClickCallback): CallbackUnsubscribeOption;
13
+ setVisible(visible: boolean): Promise<void>;
14
+ setText(text: string): void;
15
+ }
9
16
 
10
- declare interface CmpValueChangedCondition<T extends CmpValue = CmpValue> {
11
- (param: T | undefined): Promise<boolean>;
17
+ declare type CallbackUnsubscribeOption = {
18
+ unsubscribe: () => void;
19
+ };
20
+
21
+ export declare namespace CbnSdk {
22
+ export {
23
+ configuratorIsInIFrame,
24
+ finishConfiguration,
25
+ fireAnalyticsEvent,
26
+ getAssetPaths,
27
+ getParentPageUrl,
28
+ navigateToLogin,
29
+ onAnyCmpValueChanged,
30
+ redirectParentPage,
31
+ sendCustomMsgToParentPage,
32
+ setConfiguratorIFrameSize,
33
+ shareConfiguration,
34
+ createSyncCmpValuesStore,
35
+ uploadFiles,
36
+ uploadImages,
37
+ convertDocument,
38
+ createPdfFromAssets,
39
+ createArPage,
40
+ version
41
+ }
12
42
  }
13
43
 
14
- declare interface CmpValueChangedCondition_2<T extends CmpValue_2 = CmpValue_2> {
15
- (param: T | undefined): Promise<boolean>;
44
+ export declare type CfgnFileUploadData<T extends string = string> = {
45
+ [fileName in T]: {
46
+ file: FileOrDataUri;
47
+ displayName?: string;
48
+ };
49
+ };
50
+
51
+ export declare class Checkbox {
52
+ #private;
53
+ readonly id: CtrlId;
54
+ constructor(id: CtrlId);
55
+ onRendered(callback: OnRenderedCallback<HTMLLabelElement>): CallbackUnsubscribeOption;
56
+ setVisible(visible: boolean): Promise<void>;
16
57
  }
17
58
 
18
- declare interface CmpValueChangedListener<T extends CmpValue = CmpValue> {
19
- (param: T | undefined): void;
59
+ declare type CmpName = string;
60
+
61
+ /**
62
+ * All possible typings for component values.
63
+ *
64
+ * Rule of thumb with this type: Limit usages to the bare minimum only when actually needed.
65
+ * Ideally, this type should not be used in the consuming app (cfgr editor etc.) at all but only in the API layer which
66
+ * does all the parsing & conversion of cmp values to raw wire format and vice versa.
67
+ *
68
+ * Why?
69
+ * This is practically an `unknown` ATM (see comment above {@link ZCmpValue}) and dealing with `unknown` in code is very
70
+ * cumbersome and leads to hard to maintain code.
71
+ */
72
+ declare type CmpValue = z.infer<typeof ZCmpValue>;
73
+
74
+ /** Interface for value changed condition function */
75
+ export declare interface CmpValueChangedCondition<T extends CmpValue = CmpValue> {
76
+ (param: T | undefined): Promise<boolean>;
20
77
  }
21
78
 
22
- declare interface CmpValueChangedListener_2<T extends CmpValue_2 = CmpValue_2> {
79
+ export declare interface CmpValueChangedListener<T extends CmpValue = CmpValue> {
23
80
  (param: T | undefined): void;
24
81
  }
25
82
 
@@ -27,38 +84,792 @@ declare type CmpValueChangedMap<TName extends string = string> = {
27
84
  [K in TName]: boolean;
28
85
  };
29
86
 
30
- declare interface CmpValuesChangedListener<TName extends string = string> {
87
+ export declare interface CmpValuesChangedListener<TName extends string = string> {
88
+ /**
89
+ * Returns an object where each key represents the given components, and the corresponding boolean value
90
+ * indicates whether that component has changed or not
91
+ */
31
92
  (changedCmps: CmpValueChangedMap<TName>): void;
32
93
  }
33
94
 
95
+ export declare class Collapsible {
96
+ #private;
97
+ readonly id: CtrlId;
98
+ constructor(id: CtrlId);
99
+ onRendered(callback: OnRenderedCallback<HTMLDivElement>): CallbackUnsubscribeOption;
100
+ setVisible(visible: boolean): Promise<void>;
101
+ }
102
+
103
+ /**
104
+ * Checks if the configurator is embedded inside an IFrame.
105
+ */
106
+ export declare const configuratorIsInIFrame: () => boolean;
107
+
108
+ /**
109
+ * Create and convert a document (e.g. HTML to PDF).\
110
+ * The conversion consists of multiple individual tasks to allow full flexibility when creating documents.
111
+ *
112
+ * Example case: Create a PDF with dynamic content (PDF asset), append a static product datasheet
113
+ * and put a watermark on each page.
114
+ *
115
+ * See also {@link createPdfFromAssets} for a simplified version to create a PDF.
116
+ * @param tasks The tasks are executed based on their connection with the properties `name` and `inputTaskName`
117
+ * (the order in the array is irrelevant)
118
+ * @returns URL to the generated cfgn file, if successful
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const resultUrl = await convertDocument([
123
+ * {
124
+ * type: DocumentConvertTaskTypes.PdfAsset,
125
+ * name: 'HtmlToPdfTask',
126
+ * bundleAliasName: 'MyBundle',
127
+ * assetPath: 'quotePdfAsset',
128
+ * context: {
129
+ * subject: 'MySubject',
130
+ * },
131
+ * },
132
+ * {
133
+ * type: DocumentConvertTaskTypes.Watermark,
134
+ * inputTaskName: 'HtmlToPdfTask',
135
+ * name: 'WatermarkTask',
136
+ * options: {
137
+ * text: 'My Watermark',
138
+ * opacity: 50
139
+ * },
140
+ * },
141
+ * {
142
+ * type: DocumentConvertTaskTypes.OutputToCfgnFile,
143
+ * name: 'OutputPdfTask',
144
+ * inputTaskName: 'WatermarkTask',
145
+ * cfgnFileName: 'QuotePdf',
146
+ * cfgnFileExtension: 'pdf',
147
+ * cfgnFileDisplayName: `Your_quote_${new Date().toISOString()}`,
148
+ * },
149
+ * ]);
150
+ * ```
151
+ */
152
+ export declare const convertDocument: (tasks: DocumentConvertTask[]) => Promise<string | undefined>;
153
+
154
+ /**
155
+ * Uploads the given GLB file to a peristent storage and creates a dedicated page with an AR viewer that loads the GLB.
156
+ *
157
+ * After successful creation, it either redirects to that page or shows a dialog with a QR code linking to that page.
158
+ *
159
+ * Whether it redirects or shows a dialog depends on the browsers capabilities to directly open AR experiences.
160
+ */
161
+ export declare const createArPage: (glb: File, options?: SdkCreateArPageOptions) => Promise<void>;
162
+
163
+ /**
164
+ * Creates a PDF from one or more assets which will be merged in the given order.
165
+ *
166
+ * Simplified helper built on top of {@link convertDocument}.
167
+ * Use {@link convertDocument} directly for advanced scenarios such as watermarking.
168
+ *
169
+ * @param bundleAliasName Bundle name where the assets are stored
170
+ * @param assetTasks One or more "assets tasks" which will be merged in the given order
171
+ * @param cfgnFileName Name of the generated cfgn file
172
+ * @param cfgnFileDisplayName Optional name which will be used when downloading the file
173
+ * @returns URL to the generated cfgn file, if successful
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const resultUrl = await createPdfFromAssets(
178
+ * 'MyBundle',
179
+ * [
180
+ * {
181
+ * type: 'PdfAsset',
182
+ * assetPath: 'quotePdfAsset',
183
+ * context: {
184
+ * subject: 'MySubject',
185
+ * },
186
+ * },
187
+ * {
188
+ * type: 'Asset',
189
+ * assetPath: 'Pdf2',
190
+ * },
191
+ * ],
192
+ * 'QuotePdf',
193
+ * `Your_quote_${new Date().toISOString()}`
194
+ * );
195
+ * ```
196
+ *
197
+ */
198
+ export declare function createPdfFromAssets(bundleAliasName: string, assetTasks: CreatePdfTasks[], cfgnFileName: string, cfgnFileDisplayName?: string): Promise<string | undefined>;
199
+
200
+ export declare type CreatePdfTasks = {
201
+ type: CreatePdfTaskTypes.PdfAsset;
202
+ assetPath: string;
203
+ context: object;
204
+ } | {
205
+ type: CreatePdfTaskTypes.Asset;
206
+ assetPath: string;
207
+ };
208
+
209
+ export declare enum CreatePdfTaskTypes {
210
+ /** Create a PDF with dynamic content based on the given `context` */
211
+ PdfAsset = 0,
212
+ /** Static pdf asset (which is stored as File Asset) */
213
+ Asset = 1
214
+ }
215
+
216
+ /**
217
+ * Creates a store holding component values which can be accessed synchronously.
218
+ *
219
+ * This is meant as an alternative to the async value access via `await cmp.getValue()` for situations where the async
220
+ * access is especially cumbersome.
221
+ *
222
+ * E.g.:
223
+ * ```ts
224
+ * const amount = await Amount.getValue();
225
+ * // vs.
226
+ * const amount = cmpValues.Amount;
227
+ * ```
228
+ *
229
+ * !!! Note !!!
230
+ *
231
+ * This shall not be used as the default way of accessing component values.\
232
+ * Using this extensively can have negative impact on the performance of your configurator.
233
+ *
234
+ * Avoid using this with too many components or components that hold very large values which change frequently.
235
+ *
236
+ * @returns An object holding the current value of each of the given `cmps`.\
237
+ * The keys of the properties in the returned object are the same as in the given `cmps`.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * // Create the store once and export for later use:
242
+ * import { Amount, ItemPrice } from './typings/cfgr-defs.generated';
243
+ * export const cmpValues = await createSyncCmpValuesStore({ Amount, ItemPrice });
244
+ *
245
+ * // Later in the code, access the values synchronously like this:
246
+ * const amount = cmpValues.Amount;
247
+ * const itemPrice = cmpValues.ItemPrice;
248
+ * // or:
249
+ * const { Amount: amount, ItemPrice: itemPrice } = cmpValues;
250
+ * ```
251
+ *
252
+ * !!! Important !!!
253
+ *
254
+ * Once the values of the returned store have been extracted, they will not update anymore.\
255
+ * -> Only extract the values in sync contexts.
256
+ *
257
+ * E.g.:
258
+ * ```ts
259
+ * import { cmpValues } from './path/to/store';
260
+ *
261
+ * const amount = cmpValues.Amount; // Current value of Amount is 10
262
+ *
263
+ * button.onClick(() => {
264
+ * // The value of Amount changed to 20 in the meantime
265
+ * console.log(amount); // 🔥 Stale value 10
266
+ * console.log(cmpValues.Amount); // ✅ Latest value 20
267
+ * });
268
+ * ```
269
+ */
270
+ export declare const createSyncCmpValuesStore: <TCmps extends {
271
+ [id: CmpName]: ValueComponent;
272
+ }>(cmps: TCmps) => Promise<Readonly<SyncCmpValuesStore<TCmps>>>;
273
+
34
274
  declare type CtrlId = z.infer<typeof ZCtrlId>;
35
275
 
36
- export declare class CustomControl<TName extends CtrlId = CtrlId> {
276
+ export declare class CustomControl {
37
277
  #private;
38
- readonly name: TName;
39
- constructor(name: TName);
40
- onRendered(callback: (element: HTMLElement | undefined, rawHtml: string | undefined) => void): void;
278
+ readonly id: CtrlId;
279
+ constructor(id: CtrlId);
280
+ /**
281
+ * This gives custom code full control over what is rendered inside the control. When setting this function, custom
282
+ * code is responsible to actively render/set the content/innerHTML of the given `element` inside the
283
+ * {@link renderFn}.
284
+ *
285
+ * The configurator will not render any content inside the control when a {@link renderFn} is set.
286
+ *
287
+ * For the {@link renderFn} to work, the property `Custom code controlled` needs to be enabled on the control.
288
+ * The {@link renderFn} will be ignored when `Custom code controlled` is not enabled.
289
+ *
290
+ * Good to know:
291
+ * - Setting a new {@link renderFn} does not trigger a re-render.\
292
+ * Use {@link render} if you want to trigger a re-render after setting a new {@link renderFn}.
293
+ * - There can only be one {@link renderFn} per control. Setting a new one will override the existing one.
294
+ * - The {@link renderFn} will be called in the following scenarios:
295
+ * - Everytime the control is being shown. This is on initial show as well as when toggling its visibility.
296
+ * - When forcing a render via the {@link render} method.
297
+ * - Difference to {@link onRendered}:
298
+ * - The {@link renderFn} is meant to control the rendered content whilst {@link onRendered} is a classic event
299
+ * listener which allows you to perform certain actions like installing event listener on DOM nodes etc.
300
+ * **after** the content has been rendered.
301
+ * - You can install multiple {@link onRendered} callbacks.
302
+ * - The {@link renderFn} and {@link onRendered} callbacks can be used side by side.
303
+ * - The {@link renderFn} should always be used instead of manually manipulating the DOM via vanilla JS.\
304
+ * When manipulating the DOM outside of the {@link renderFn}, your changes can always be overridden by the
305
+ * configurator.\
306
+ * Using the {@link renderFn} ensures that your changes are applied in a stable and predictable way.
307
+ */
308
+ set renderFn(callback: CustomCtrlRenderFn);
309
+ /**
310
+ * Forces a re-render of the control.
311
+ *
312
+ * @param renderFn Convenience param which allows setting the {@link renderFn} and triggering a render in one call.
313
+ * The given `renderFn` will be permanently installed and will override any previously set
314
+ * {@link renderFn}.
315
+ */
316
+ render(renderFn?: CustomCtrlRenderFn): Promise<void>;
317
+ /**
318
+ * This allows custom code to register callbacks in which it can perform certain actions like installing event
319
+ * listeners on DOM nodes or adding CSS classes etc. **after** the control has been rendered.
320
+ *
321
+ * The control can be rendered in the following scenarios:
322
+ * - Everytime the control is being shown. This is on initial show as well as when toggling its visibility.
323
+ * - When forcing a render via the {@link render} method.
324
+ * - When the value of the control's `HTML` property changes e.g. via Hive in controls.
325
+ *
326
+ * !!! Important !!!
327
+ *
328
+ * This is **not** meant to be used for manipulating the rendered content of the control besides simple,
329
+ * non-structural/-behavioral changes like adding CSS classes or data attributes etc.
330
+ *
331
+ * For manipulating/controlling the rendered content, use the {@link renderFn} instead.
332
+ *
333
+ * See {@link renderFn} for more differences between the two.
334
+ */
335
+ onRendered(callback: OnRenderedCallback<HTMLDivElement>): CallbackUnsubscribeOption;
41
336
  getElement(): HTMLElement | undefined;
337
+ setVisible(visible: boolean): Promise<void>;
42
338
  }
43
339
 
44
- declare interface IValueComponent<TName extends string = string, TValue extends CmpValue = CmpValue, TInput extends CmpValue = TValue> {
45
- readonly name: TName;
46
- getValue(): Promise<TValue | undefined>;
47
- setInput(value: TInput | undefined): void;
340
+ /**
341
+ * @param element The root element of the control into which you can render your custom content.
342
+ * @param rawHtml The raw HTML string which is set in the `HTML` property of the control.
343
+ */
344
+ declare type CustomCtrlRenderFn = (element: HTMLDivElement, rawHtml: string | undefined) => void | Promise<void>;
345
+
346
+ export declare class Dataview {
347
+ #private;
348
+ readonly id: CtrlId;
349
+ constructor(id: CtrlId);
350
+ onRendered(callback: OnRenderedCallback<HTMLDivElement>): CallbackUnsubscribeOption;
351
+ setVisible(visible: boolean): Promise<void>;
48
352
  }
49
353
 
50
- export declare const onAnyCmpValueChanged: <TInput extends {
51
- readonly name: string;
52
- readonly zodType: ZodType<unknown>;
53
- getValue(): Promise<unknown>;
54
- setInput(value: unknown): Promise<void>;
55
- onValueChanged(listener: CmpValueChangedListener_2<unknown>, callImmediately?: boolean, condition?: CmpValueChangedCondition_2<unknown> | undefined): void;
56
- }>(listener: CmpValuesChangedListener<TInput["name"]>, components: TInput[], lazy?: boolean) => Promise<void>;
354
+ export declare type DocumentConvertTask = {
355
+ type: DocumentConvertTaskTypes.PdfAsset;
356
+ name: string;
357
+ /** Alias name, as set in the asset bundle assignment dialog */
358
+ bundleAliasName: string;
359
+ /** Dot seperated path, e.g. 'MyPDFFolder.MyPDFAsset' */
360
+ assetPath: string;
361
+ /** Custom object which must represent the context, as defined in the PDF asset */
362
+ context: object;
363
+ } | {
364
+ type: DocumentConvertTaskTypes.Asset;
365
+ name: string;
366
+ /** Alias name, as set in the asset bundle assignment dialog */
367
+ bundleAliasName: string;
368
+ /** Dot seperated path, e.g. 'MyPDFFolder.MyStaticAsset' */
369
+ assetPath: string;
370
+ } | {
371
+ type: DocumentConvertTaskTypes.Merge;
372
+ name: string;
373
+ /** Names of the tasks which should be merged in the given order */
374
+ inputTaskNames: string[];
375
+ } | {
376
+ type: DocumentConvertTaskTypes.Watermark;
377
+ name: string;
378
+ inputTaskName: string;
379
+ /** Minimum property requirement is either a `text` or a `imageInputTaskName`
380
+ * (which points to a task of type {@link DocumentConvertTaskTypes.Asset}) */
381
+ options: WatermarkImageOptions | WatermarkTextOptions;
382
+ } | {
383
+ type: DocumentConvertTaskTypes.OutputToCfgnFile;
384
+ name: string;
385
+ inputTaskName: string;
386
+ /** Name of the generated cfgn file */
387
+ cfgnFileName: string;
388
+ cfgnFileExtension: string;
389
+ /** Optional name which will be used when downloading the file */
390
+ cfgnFileDisplayName?: string;
391
+ };
392
+
393
+ export declare enum DocumentConvertTaskTypes {
394
+ /** Create a PDF with dynamic content based on the given `context` */
395
+ PdfAsset = 0,
396
+ /** Retrieve an asset to be used for suceeding tasks (e.g. static PDF for merge or image for a watermark) */
397
+ Asset = 1,
398
+ /** Merge multiple input tasks into a single document */
399
+ Merge = 2,
400
+ /** Add a repeating watermark onto the whole document */
401
+ Watermark = 3,
402
+ /** Finalize the conversion by storing it as `Configuration file` */
403
+ OutputToCfgnFile = 4
404
+ }
405
+
406
+ declare type FileOrDataUri = File | {
407
+ dataUri: string;
408
+ extension: string;
409
+ };
410
+
411
+ /**
412
+ * Creates a finish of the current configuration by running all the Configurator's finish actions and optionally passes
413
+ * the resulting data to the parent page.
414
+ */
415
+ export declare const finishConfiguration: (options: (FinishConfigurationBaseOptions & {
416
+ sendDataToParentPage: false;
417
+ }) | (FinishConfigurationBaseOptions & {
418
+ /**
419
+ * If `true`, the data returned by `transformParentPageData` will be passed to the function
420
+ * `window.Combeenation.onConfigurationFinished(data)` on the parent page (or one of its older aliases like
421
+ * `Combeenation.onCheckout` etc.).
422
+ */
423
+ sendDataToParentPage: true;
424
+ /**
425
+ * Allows transformation of the data that is passed to the parent page after the configuration is finished.
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * const checkoutData: Shopware6CheckoutJson = { ... };
430
+ *
431
+ * finishConfiguration({
432
+ * transformParentPageData: () => {
433
+ * return {
434
+ * id: cfgnId, // E.g. from Hive's `configuration.id`
435
+ * authentication: authToken, // E.g. from Hive's `configuration.authToken`
436
+ * checkoutParameters: JSON.stringify(checkoutData),
437
+ * queryParameters: Object.fromEntries(new URLSearchParams(window.location.search)),
438
+ * checkoutParametersHash: '123', // Not actually used ATM, will be provided by the server in the future
439
+ * } satisfies ParentPageCheckoutData;
440
+ * },
441
+ * });
442
+ * ```
443
+ *
444
+ * FYI, this is mandatory ATM and does not get any input values which means that the consumer is required to
445
+ * build the return value himself. In the future we'll change this to be optional and provide the data generated
446
+ * on the server as input to the transformation function.
447
+ */
448
+ transformParentPageData: () => ParentPageCheckoutData & {
449
+ [key: string]: SerializableJsonValue;
450
+ };
451
+ })) => Promise<void>;
452
+
453
+ declare type FinishConfigurationBaseOptions = {
454
+ input?: string;
455
+ };
456
+
457
+ /**
458
+ * Pushes the given data into the Google Tag Manager data layer on the parent page.
459
+ *
460
+ * If the Configurator is not embedded in an IFrame, the event is pushed directly into the data layer of the current
461
+ * window.
462
+ *
463
+ * If embedded in an IFrame, this requires the Configurator plugin to be installed correctly on the parent page.\
464
+ * See embedding instructions for details.
465
+ *
466
+ * @param event Key for event identification
467
+ */
468
+ export declare const fireAnalyticsEvent: (event: string, eventData?: object | string) => Promise<ParentPageComResult<void>>;
469
+
470
+ export declare type FlexShopFinishJson = Shopware6FinishJson;
471
+
472
+ /**
473
+ * Returns the resolved 3D asset paths (babylon.js assets, material assets, texture image assets)
474
+ * for all pre-packed asset bundles configured for this Configurator.
475
+ *
476
+ * The result is fetched once and cached — subsequent calls resolve immediately from cache.
477
+ */
478
+ export declare const getAssetPaths: () => Promise<SdkAssetPaths>;
479
+
480
+ /**
481
+ * Retrieve the parent page's URI.
482
+ *
483
+ * Requires the Configurator plugin to be installed correctly on the parent page.\
484
+ * See embedding instructions for details.
485
+ *
486
+ * @returns `undefined` if we're not inside an IFrame or the parent page does not respond to our request.
487
+ */
488
+ export declare const getParentPageUrl: () => Promise<ParentPageComResult<{
489
+ url: string;
490
+ }>>;
491
+
492
+ export declare class Input {
493
+ #private;
494
+ readonly id: CtrlId;
495
+ constructor(id: CtrlId);
496
+ onRendered(callback: OnRenderedCallback<HTMLDivElement>): CallbackUnsubscribeOption;
497
+ setVisible(visible: boolean): Promise<void>;
498
+ }
499
+
500
+ declare type JsonArray = Array<SerializableJsonValue>;
501
+
502
+ declare type JsonObject = {
503
+ [key: string]: SerializableJsonValue;
504
+ };
505
+
506
+ declare type JsonPrimitive = string | number | boolean | null;
507
+
508
+ /**
509
+ * Raw material JSON which can be passed to Babylon.js e.g. via `Material.Parse(material)`
510
+ */
511
+ declare type MaterialObject = z.infer<typeof ZMaterialObject>;
512
+
513
+ /**
514
+ * Navigates to the login page of the Configurator.
515
+ *
516
+ * @param options.hideBackNavigation Defaults to `false`.\
517
+ * E.g. can be used if the Configurator immediately redirects to the login and
518
+ * shouldn't be accessible without a successful login.
519
+ * @param options.language Defaults to the browser language.
520
+ */
521
+ export declare const navigateToLogin: (options?: {
522
+ hideBackNavigation?: boolean;
523
+ language?: AppLanguage;
524
+ }) => void;
525
+
526
+ /**
527
+ * @param listener Called whenever the value of at least 1 component has changed.\
528
+ * Returns an object that indicates which components have actually changed.
529
+ * @param components Only call the listener if one of the given cmps have changed
530
+ * @param lazy `false` [default]: Immediately fetch the values of all changed components.\
531
+ * `true`: Trigger the listener but don't fetch values until specifically requested.
532
+ * This could reduce data traffic when only some components are required in the listener, due to
533
+ * conditions or similar.
534
+ *
535
+ * @example
536
+ * [SCENARIO 1] where `lazy: true` could be benefical
537
+ * ```typescript
538
+ * CmpUtils.onAnyCmpValueChanged(() => {
539
+ * const useBigData = CmpSimpleBool.getValue();
540
+ * if(useBigData) {
541
+ * // only now the data will be retrieved from the server
542
+ * const bigData = await CmpBigData.getValue();
543
+ * }
544
+ *
545
+ * }, [CmpBigData, CmpSimpleBool, CmpSimpleText], true);
546
+ * ```
547
+ *
548
+ * [SCENARIO 2] where `lazy: false` could be benefical
549
+ * ```typescript
550
+ * CmpUtils.onAnyCmpValueChanged(() => {
551
+ * // The data for both values has been fetched in the background, so no further server request is necessary
552
+ * const bigData1 = await CmpBigData1.getValue();
553
+ * const bigData2 = await CmpBigData2.getValue();
554
+ * }, [CmpBigData1, CmpBigData2]);
555
+ * ```
556
+ */
557
+ export declare const onAnyCmpValueChanged: <TInput extends ValueComponent>(listener: CmpValuesChangedListener<TInput["name"]>, components: TInput[], lazy?: boolean) => Promise<void>;
558
+
559
+ declare type OnClickCallback = () => void;
560
+
561
+ declare type OnRenderedCallback<T extends HTMLElement = HTMLElement> = (element: T) => void;
562
+
563
+ export declare class Panel {
564
+ #private;
565
+ readonly id: CtrlId;
566
+ constructor(id: CtrlId);
567
+ onRendered(callback: OnRenderedCallback<HTMLDivElement>): CallbackUnsubscribeOption;
568
+ setVisible(visible: boolean): Promise<void>;
569
+ }
570
+
571
+ export declare type ParentPageCheckoutData = {
572
+ /** Cfgn id */
573
+ id: string;
574
+ /** Contains the value of the `data` passed to Hive's `OnFinish.CheckoutLegacy(data, key)` as stringified JSON */
575
+ checkoutParameters: string;
576
+ /** SHA256 hash of `checkoutParameters` built with the secret `key` passed to `OnFinish.CheckoutLegacy(data, key)` */
577
+ checkoutParametersHash: string;
578
+ /** Contains all query parameters which are added to the current cfgr URL */
579
+ queryParameters: {
580
+ [key: string]: string;
581
+ };
582
+ /** Cfgn auth token */
583
+ authentication: string;
584
+ };
585
+
586
+ declare type ParentPageComErrorPayload<T> = [T] extends [void] ? {} : {
587
+ [K in keyof T]: undefined;
588
+ };
589
+
590
+ /**
591
+ * Given `T` must be an object and all its properties are directly spread into the resulting object.
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * ParentPageComResult<void>
596
+ * // -> { success: true; } | { success: false; error: Error };
597
+ *
598
+ * ParentPageComResult<{ url: string }>
599
+ * // -> { success: true; url: string; } | { success: false; error: Error; url: undefined; };
600
+ *
601
+ * // Not allowed:
602
+ * ParentPageComResult<number> // `number` is not an object
603
+ * ParentPageComResult<string[]> // `string[]` is not an object
604
+ * ParentPageComResult<{ success: string }> // Property `success` is not allowed
605
+ * ParentPageComResult<{ error: string, name: string }> // Property `error` is not allowed
606
+ * ```
607
+ */
608
+ declare type ParentPageComResult<T extends Record<string, unknown> | void> = ({
609
+ success: true;
610
+ error: undefined;
611
+ } & ([T] extends [void] ? {} : T)) | ({
612
+ success: false;
613
+ error: Error;
614
+ } & ParentPageComErrorPayload<T>);
615
+
616
+ export declare type ProductCustomFields = {
617
+ /**
618
+ * Unique identifier
619
+ */
620
+ id: string;
621
+ /**
622
+ * Label which the user will also see in the cart (if it is visible)
623
+ */
624
+ label: string;
625
+ /**
626
+ * Value of the custom field
627
+ */
628
+ value: string;
629
+ /**
630
+ * Position in the cart
631
+ */
632
+ position: number;
633
+ /**
634
+ * If it should be visible in the cart
635
+ */
636
+ isVisible: boolean;
637
+ };
638
+
639
+ /**
640
+ * Sets `window.location.href` to the given `url` on the parent page.
641
+ *
642
+ * Requires the Configurator plugin to be installed correctly on the parent page.\
643
+ * See embedding instructions for details.
644
+ */
645
+ export declare const redirectParentPage: (url: string) => Promise<ParentPageComResult<void>>;
646
+
647
+ declare type SdkAssetPaths = {
648
+ babylonJsAssets: {
649
+ [key: AssetName]: UrlString;
650
+ };
651
+ materialAssets: {
652
+ [key: AssetName]: MaterialObject;
653
+ };
654
+ textureImageAssets: {
655
+ [key: AssetName]: UrlString;
656
+ };
657
+ };
658
+
659
+ /**
660
+ * `urls` contains a map of the uploaded files, where the key represents the name and the value the url.\
661
+ * It's recommended to check for the `success` flag beforehand.
662
+ */
663
+ declare type SdkCfgnFileUploadResult<T extends string = string> = {
664
+ success: false;
665
+ urls?: never;
666
+ } | {
667
+ success: true;
668
+ urls: {
669
+ [fileName in T]: UrlString;
670
+ };
671
+ };
672
+
673
+ declare type SdkCreateArPageOptions = {
674
+ qrSubTitle?: string;
675
+ qrDescription?: string;
676
+ preparationText?: string;
677
+ popupBlockedTitle?: string;
678
+ popupBlockedDescription?: string;
679
+ popupBlockedLinkText?: string;
680
+ environment?: UrlString;
681
+ loadingScreenImg?: UrlString;
682
+ };
683
+
684
+ /**
685
+ * Send a custom message to the parent page via the "CustomMessage".\
686
+ * The parent page can handle those messages by implementing the function `Combeenation.on{msgName}`.
687
+ *
688
+ * Requires the Configurator plugin to be installed correctly on the parent page.\
689
+ * See embedding instructions for details.
690
+ */
691
+ export declare const sendCustomMsgToParentPage: (msgName: string, data?: object) => Promise<ParentPageComResult<void>>;
692
+
693
+ /** A JSON-serializable value safe to use as a `postMessage` payload etc. */
694
+ declare type SerializableJsonValue = JsonPrimitive | JsonObject | JsonArray;
695
+
696
+ /**
697
+ * Changes the width and/or height of the IFrame and/or scroll position of the parent page window.
698
+ *
699
+ * Requires the Configurator plugin to be installed correctly on the parent page.\
700
+ * See embedding instructions for details.
701
+ *
702
+ * @param width If not given or 0, the width is not changed
703
+ * @param height If not given or 0, the height is not changed
704
+ * @param scrollToX New horizontal scroll position of the parent page window
705
+ * @param scrollToY New vertical scroll position of the parent page window
706
+ */
707
+ export declare const setConfiguratorIFrameSize: (data: {
708
+ width?: string;
709
+ height?: string;
710
+ scrollToX?: number;
711
+ scrollToY?: number;
712
+ }) => Promise<ParentPageComResult<void>>;
713
+
714
+ /**
715
+ * Creates a copy of the current configuration and opens a share window for the given platform with the resulting share
716
+ * URL
717
+ */
718
+ export declare const shareConfiguration: (data: {
719
+ /** If `Custom`, no share window will be opened */
720
+ platform: "Facebook" | "Pinterest" | "Twitter" | "LinkedIn" | "WhatsApp" | "Custom" | "NativeShare";
721
+ ogTitle?: string;
722
+ ogAuthor?: string;
723
+ ogDescription?: string;
724
+ /**
725
+ * URL to an image which will be used as share preview image when supported by the platform.
726
+ *
727
+ * It's recommended to use the URL of a file uploaded via upload tooling of the configurator.
728
+ */
729
+ imageUrl?: string;
730
+ /**
731
+ * URL of the parent page where the configurator is embedded.
732
+ *
733
+ * Will be integrated into the resulting share URL, so that the share redirects to the parent page, not the standalone
734
+ * configurator.
735
+ */
736
+ embedUrl?: string;
737
+ }) => Promise<{
738
+ /**
739
+ * Url which is enhanced for sharing on social media by providing required "Open Graph" tags.
740
+ */
741
+ shareUrl: string;
742
+ shareConfigurationId: string;
743
+ }>;
744
+
745
+ export declare type ShopifyFinishJson = {
746
+ products: {
747
+ main: {
748
+ /**
749
+ * SKU id from your shop system
750
+ */
751
+ productId: string;
752
+ quantity: number;
753
+ /**
754
+ * Gross price of the configured product WITHOUT accessories
755
+ */
756
+ price: number;
757
+ /**
758
+ * Url to the image which will be used in the cart
759
+ */
760
+ imageUrl?: string;
761
+ /**
762
+ * New title of the product
763
+ */
764
+ title?: string;
765
+ /**
766
+ * New description of your product
767
+ */
768
+ productText?: string;
769
+ customFields?: ProductCustomFields[];
770
+ /**
771
+ * Weight of the main product
772
+ */
773
+ weight?: number;
774
+ /**
775
+ * Supported weight unit values: `KG`, `G`, `OZ`, `LB`.
776
+ */
777
+ weightUnit?: string;
778
+ /**
779
+ * Category id of the new product. A list of all ids can be found here:\
780
+ * {@link https://help.shopify.com/txt/product_taxonomy/en.txt}
781
+ */
782
+ categoryId?: number;
783
+ };
784
+ /**
785
+ * Additional predefined Shopify products which will be added to the cart (no custom price/image/title)
786
+ */
787
+ accessories?: {
788
+ productId: string;
789
+ quantity: number;
790
+ }[];
791
+ }[];
792
+ };
793
+
794
+ export declare type Shopware6FinishJson = {
795
+ products: {
796
+ main: {
797
+ /**
798
+ * SKU id from your shop system
799
+ */
800
+ productId: string;
801
+ quantity: number;
802
+ /**
803
+ * Gross price of the configured product WITHOUT accessories
804
+ */
805
+ price: number;
806
+ /**
807
+ * Url to the image which will be used in the cart
808
+ */
809
+ imageUrl?: string;
810
+ /**
811
+ * New title of the product
812
+ */
813
+ title?: string;
814
+ /**
815
+ * New description of your product
816
+ */
817
+ productText?: string;
818
+ customFields?: ProductCustomFields[];
819
+ };
820
+ /**
821
+ * Additional predefined Shopware products which will be added to the cart (no custom price/image/title)
822
+ */
823
+ accessories?: {
824
+ productId: string;
825
+ quantity: number;
826
+ /**
827
+ * If false the product will be linked to the main product and can't be deleted from cart
828
+ */
829
+ isSingleCartItem: boolean;
830
+ }[];
831
+ }[];
832
+ };
833
+
834
+ /**
835
+ * A simple key-value store where key = component name and value = current component value.
836
+ */
837
+ declare type SyncCmpValuesStore<TCmps extends Record<CmpName, ValueComponent>> = {
838
+ [K in keyof TCmps & CmpName]: TCmps[K] extends ValueComponent<any, infer TValue, any> ? TValue | undefined : never;
839
+ };
840
+
841
+ declare class Text_2 {
842
+ #private;
843
+ readonly id: CtrlId;
844
+ constructor(id: CtrlId);
845
+ onRendered(callback: OnRenderedCallback<HTMLSpanElement>): CallbackUnsubscribeOption;
846
+ setVisible(visible: boolean): Promise<void>;
847
+ setText(text: string): void;
848
+ }
849
+ export { Text_2 as Text }
850
+
851
+ /**
852
+ * Upload one or more files into the current configuration
853
+ *
854
+ * @param files The key represents the name, which can be used in Hive with `configuration.GetFile("")`
855
+ * @returns An object with the same keys as the input. The values contain according result information.
856
+ */
857
+ export declare const uploadFiles: <T extends string>(files: CfgnFileUploadData<T>) => Promise<SdkCfgnFileUploadResult<T>>;
858
+
859
+ /**
860
+ * Upload one or more images into the current configuration
861
+ *
862
+ * @param files The key represents the name, which can be used in Hive with `configuration.GetImage("")`
863
+ * @returns An object with the same keys as the input. The values contain according result information.
864
+ */
865
+ export declare const uploadImages: <T extends string>(images: CfgnFileUploadData<T>) => Promise<SdkCfgnFileUploadResult<T>>;
866
+
867
+ declare type UrlString = z.infer<typeof ZUrlString>;
57
868
 
58
869
  /**
59
870
  * Represents a component of type `Value`
60
871
  */
61
- export declare class ValueComponent<TName extends CmpName = CmpName, TValue extends CmpValue = CmpValue, TInput extends CmpValue = TValue> implements IValueComponent {
872
+ export declare class ValueComponent<TName extends CmpName = CmpName, TValue extends CmpValue = CmpValue, TInput extends CmpValue = TValue> {
62
873
  readonly name: TName;
63
874
  readonly zodType: z.ZodType<CmpValue>;
64
875
  constructor(name: TName, zodType: z.ZodType<CmpValue>);
@@ -82,12 +893,74 @@ export declare class ValueComponent<TName extends CmpName = CmpName, TValue exte
82
893
  onValueChanged(listener: CmpValueChangedListener<TValue>, callImmediately?: boolean, condition?: CmpValueChangedCondition<TValue>): void;
83
894
  }
84
895
 
85
- export declare const version = "@VERSION@";
896
+ export declare const version: string;
86
897
 
87
- declare const ZCmpValue: z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, z.ZodUnknown]>;
898
+ export declare enum WatermarkHorizontalAlignment {
899
+ Left = 0,
900
+ Center = 1,
901
+ Right = 2
902
+ }
903
+
904
+ declare type WatermarkImageOptions = WatermarkOptionsBase & {
905
+ imageInputTaskName: string;
906
+ imageHeight?: number;
907
+ imageWidth?: number;
908
+ text?: never;
909
+ };
910
+
911
+ declare type WatermarkOptionsBase = {
912
+ /** Opacity in % to make the watermark transparent. A value of 100 means it is fully visible. */
913
+ opacity?: number;
914
+ rotation?: number;
915
+ positionVertical?: WatermarkVerticalAlignment;
916
+ positionHorizontal?: WatermarkHorizontalAlignment;
917
+ };
918
+
919
+ declare type WatermarkTextOptions = WatermarkOptionsBase & {
920
+ text: string;
921
+ textFontSize?: number;
922
+ textFontColor?: string;
923
+ textFontName?: string;
924
+ imageInputTaskName?: never;
925
+ };
88
926
 
89
- declare const ZCmpValue_2: z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, z.ZodUnknown]>;
927
+ export declare enum WatermarkVerticalAlignment {
928
+ Top = 0,
929
+ Center = 1,
930
+ Bottom = 2
931
+ }
932
+
933
+ declare const ZAssetName: z.ZodString;
934
+
935
+ declare const ZCmpValue: z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, z.ZodUnknown]>;
90
936
 
91
937
  declare const ZCtrlId: z.ZodString;
92
938
 
939
+ /**
940
+ * Raw material JSON which can be passed to Babylon.js e.g. via `Material.Parse(material)`
941
+ *
942
+ * Whilst this is not a full zod schema for Babylon material definitions, we least check for the presence of some
943
+ * required properties like `name` and `id` to avoid passing obviously invalid material definitions.
944
+ *
945
+ * Could be extended as needed.
946
+ */
947
+ declare const ZMaterialObject: z.ZodObject<{
948
+ name: z.ZodString;
949
+ id: z.ZodString;
950
+ customType: z.ZodEnum<["BABYLON.PBRMaterial", "BABYLON.PBRMetallicRoughnessMaterial", "BABYLON.PBRSpecularGlossinessMaterial", "BABYLON.StandardMaterial", "BABYLON.BackgroundMaterial", "BABYLON.NodeMaterial"]>;
951
+ tags: z.ZodOptional<z.ZodNullable<z.ZodString>>;
952
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
953
+ name: z.ZodString;
954
+ id: z.ZodString;
955
+ customType: z.ZodEnum<["BABYLON.PBRMaterial", "BABYLON.PBRMetallicRoughnessMaterial", "BABYLON.PBRSpecularGlossinessMaterial", "BABYLON.StandardMaterial", "BABYLON.BackgroundMaterial", "BABYLON.NodeMaterial"]>;
956
+ tags: z.ZodOptional<z.ZodNullable<z.ZodString>>;
957
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
958
+ name: z.ZodString;
959
+ id: z.ZodString;
960
+ customType: z.ZodEnum<["BABYLON.PBRMaterial", "BABYLON.PBRMetallicRoughnessMaterial", "BABYLON.PBRSpecularGlossinessMaterial", "BABYLON.StandardMaterial", "BABYLON.BackgroundMaterial", "BABYLON.NodeMaterial"]>;
961
+ tags: z.ZodOptional<z.ZodNullable<z.ZodString>>;
962
+ }, z.ZodTypeAny, "passthrough">>;
963
+
964
+ declare const ZUrlString: z.ZodBranded<z.ZodString, "Url">;
965
+
93
966
  export { }