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

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