@spiffcommerce/core 20.5.1 → 21.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +135 -0
- package/README.md +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +37 -34
- package/dist/index.umd.cjs +2 -2
- package/package.json +5 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [21.0.1] - 13-03-2024
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Package now supplies this `CHANGELOG.md` in published releases.
|
|
13
|
+
|
|
14
|
+
## [21.0.0] - 13-03-2024
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- `DesignCreationMessage` now has `quantity: number | undefined`.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- `Bundle.finish()` no longer returns an array of `DesignCreationMessage` objects, but instead returns a `BundleDesignCreationMessage` object which wraps the array of `DesignCreationMessage` entries.
|
|
23
|
+
|
|
24
|
+
## [20.5.1] - 12-03-2024
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- `WorkflowExperience.getSelectionPriceSubunits()` (and consequently `getTotalPriceSubunits()`) can no longer return `NaN`.
|
|
29
|
+
|
|
30
|
+
## [20.5.0] - 12-03-2024
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `WorkflowManager.injectIntoPreviewService()` now has a second argument `refocusCamera`, a boolean which allows you to disable the automatic refocusing of the camera when the model is loaded. This requires `@spiffcommerce/preview@^5.7.0`.
|
|
35
|
+
|
|
36
|
+
## [20.4.5] - 08-03-2024
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- `RenderableScene` objects will now contain a `workflowScene: WorkflowScene` field. This is only provided for backwards compatibility and is considered deprecated functionality.
|
|
41
|
+
|
|
42
|
+
## [20.4.4] - 08-03-2024
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- Updating quantity via `WorkflowExperience.setQuantity()` will now correctly update on the server.
|
|
47
|
+
|
|
48
|
+
## [20.4.3] - 08-03-2024
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- `WorkflowExperience.setQuantity()` now returns a promise that resolves once the quantity has been updated on the server.
|
|
53
|
+
|
|
54
|
+
## [20.4.0] - 08-03-2024
|
|
55
|
+
|
|
56
|
+
### Added
|
|
57
|
+
|
|
58
|
+
- `Transaction` entities now have `quantity: number | undefined`.
|
|
59
|
+
- New functions on `WorkflowExperience` for managing quantity:
|
|
60
|
+
- `getQuantity()`: The amount that was, or will be, ordered of the underlying `Transaction`. This will default to `1` if the value is undefined. If you want to read the raw value, use `getWorkflowManager().getTransaction().quantity`.
|
|
61
|
+
- `setQuantity(<number>)`: Updates the quantity value on the underlying `Transaction` entity. Must be >= 1.
|
|
62
|
+
- New events functionality on `WorkflowExperience`. Currently the only event is `QuantityChanged`.
|
|
63
|
+
- `addEventListener(<type>, <callback>)`: Registers a callback function to be called when the specified event is raised. The associated `WorkflowExperience` is passed as a parameter to the callback function.
|
|
64
|
+
- `removeEventListener(<type>, <callback>)`: Removes a previously registered callback.
|
|
65
|
+
|
|
66
|
+
## [20.3.0] - 07-03-2024
|
|
67
|
+
|
|
68
|
+
### Added
|
|
69
|
+
|
|
70
|
+
- `CollectionProduct.getCurrentIntegration()`: returns the `IntegrationProductResource` associated with the product that is linked to the current Integration (resolved via the application key).
|
|
71
|
+
|
|
72
|
+
## [20.2.2] - 05-03-2024
|
|
73
|
+
|
|
74
|
+
### Changed
|
|
75
|
+
|
|
76
|
+
- `WorkflowExperience.getStepById(<string>)` now internally caches the `StepHandle` objects that it creates. This resolves an issue with functional rendering systems that re-render when the object reference changes, where they would re-renderer whenever this function was called even if the object was identical.
|
|
77
|
+
|
|
78
|
+
## [20.2.1] - 29-02-2024
|
|
79
|
+
|
|
80
|
+
### Changed
|
|
81
|
+
|
|
82
|
+
- The union type `GetWorkflowOptions` has some of its entries wrapped in another union. The types that will create a brand new `Transaction` are now nested under `GetNewWorkflowOptions`:
|
|
83
|
+
```ts
|
|
84
|
+
// Before
|
|
85
|
+
export type GetWorkflowOptions = GetWorkflowFromTransactionOptions | GetWorkflowFromIntegrationProductOptions | GetWorkflowFromExternalProductOptions;
|
|
86
|
+
|
|
87
|
+
// After
|
|
88
|
+
export type GetNewWorkflowOptions = GetWorkflowFromIntegrationProductOptions | GetWorkflowFromExternalProductOptions;
|
|
89
|
+
|
|
90
|
+
export type GetWorkflowOptions = GetWorkflowFromTransactionOptions | GetNewWorkflowOptions;
|
|
91
|
+
```
|
|
92
|
+
## [20.2.0] - 29-02-2024
|
|
93
|
+
|
|
94
|
+
### Added
|
|
95
|
+
|
|
96
|
+
- `SpiffCommerceClient.getIntegrationProduct(<options>)`: Fetches an `IntegrationProduct` object. Essentially a wrapper for the functions `getIntegrationProductById` and `getIntegrationProductFromExternalIds`. The options object type is as follows:
|
|
97
|
+
```ts
|
|
98
|
+
{
|
|
99
|
+
type: "integration";
|
|
100
|
+
integrationProductId: string;
|
|
101
|
+
} | {
|
|
102
|
+
type: "external";
|
|
103
|
+
externalIntegrationId: string;
|
|
104
|
+
externalProductId: string;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## [20.1.0] - 23-02-2024
|
|
109
|
+
|
|
110
|
+
### Added
|
|
111
|
+
|
|
112
|
+
- `IntegrationProduct.getAllWorkflows()`: Returns an array of `ProductWorkflow`, ordered by their internal `index` value (matches the order seen on the SpiffCommerce Hub).
|
|
113
|
+
|
|
114
|
+
## [20.0.1] - 23-02-2024
|
|
115
|
+
|
|
116
|
+
### Changed
|
|
117
|
+
|
|
118
|
+
- `StepHandle.executeAnimations()` now logs a warning to the console when the associated `WorkflowManager` is not associated with a `ThreeDPreviewService`.
|
|
119
|
+
|
|
120
|
+
## [20.0.0] - 15-02-2024
|
|
121
|
+
|
|
122
|
+
### Added
|
|
123
|
+
|
|
124
|
+
- Additional configuration options for GraphQL on bundles.
|
|
125
|
+
- A separate fetchProducts function on the ProductCollection interface.
|
|
126
|
+
|
|
127
|
+
### Changed
|
|
128
|
+
|
|
129
|
+
- Removed async on getProducts call.
|
|
130
|
+
|
|
131
|
+
### Removed
|
|
132
|
+
|
|
133
|
+
- Unused normalize.css file.
|
|
134
|
+
- Identical links assigned in each translation file.
|
|
135
|
+
- Duplicate index file for the english version.
|
package/README.md
CHANGED
|
@@ -7,6 +7,6 @@ This is the Spiff Commerce Javascript client API.
|
|
|
7
7
|
- The Client API manages the heavy lifting related to setting up, executing & finishing a workflow experience. It is a wrapper around the Workflow Manager,
|
|
8
8
|
which is responsible for executing workflow steps and managing things like state and conditions.
|
|
9
9
|
|
|
10
|
-
- Whilst the workflow manager is exposed we
|
|
10
|
+
- Whilst the workflow manager is exposed we recommend getting started with a "Workflow Experience" instead.
|
|
11
11
|
|
|
12
12
|
## Getting Started
|
package/dist/index.d.ts
CHANGED
|
@@ -545,6 +545,7 @@ interface DesignCreationMessage {
|
|
|
545
545
|
};
|
|
546
546
|
optionsCost: number;
|
|
547
547
|
processExecutionId?: string;
|
|
548
|
+
quantity?: number;
|
|
548
549
|
selectedVariants?: SelectedVariants;
|
|
549
550
|
sku?: string;
|
|
550
551
|
transactionId: string;
|
|
@@ -553,6 +554,10 @@ interface DesignCreationMessage {
|
|
|
553
554
|
workflowViewerLink: string;
|
|
554
555
|
workflowViewerReadOnlyLink: string;
|
|
555
556
|
}
|
|
557
|
+
interface BundleDesignCreationMessage {
|
|
558
|
+
bundleId: string;
|
|
559
|
+
items: DesignCreationMessage[];
|
|
560
|
+
}
|
|
556
561
|
/**
|
|
557
562
|
* Represents a transaction.
|
|
558
563
|
*/
|
|
@@ -1957,8 +1962,9 @@ interface Bundle {
|
|
|
1957
1962
|
* @param onProgressUpdate A callback that will be called when the progress of the finalization changes.
|
|
1958
1963
|
* @param createPreviewImage A callback that will be called when a preview image is required. This is used to generate a preview image for the design.
|
|
1959
1964
|
* If this callback is not provided, no preview image will be generated.
|
|
1965
|
+
* @returns {BundleDesignCreationMessage} An object containing an array of design messages, along with the Bundle's Id and the event type.
|
|
1960
1966
|
*/
|
|
1961
|
-
finish(onProgressUpdate?: DesignCreationProgressUpdate, createPreviewImage?: (workflowExperience: WorkflowExperience) => Promise<string | undefined>): Promise<
|
|
1967
|
+
finish(onProgressUpdate?: DesignCreationProgressUpdate, createPreviewImage?: (workflowExperience: WorkflowExperience) => Promise<string | undefined>): Promise<BundleDesignCreationMessage>;
|
|
1962
1968
|
/**
|
|
1963
1969
|
* Add an event listener to this bundle.
|
|
1964
1970
|
* @param event The event to listen for. Currently only "conditional-global-properties-changed" is supported.
|
|
@@ -3022,4 +3028,4 @@ declare class PromiseCache {
|
|
|
3022
3028
|
}
|
|
3023
3029
|
declare const promiseCache: PromiseCache;
|
|
3024
3030
|
|
|
3025
|
-
export { ArrayInput, AssetNotFoundError, Bundle, CollectionProduct, ColorOption, ConversionConfiguration, ConversionData, ConversionDataType, ConversionLocation, Customer, CustomerDetailsInput, DesignCreationMessage, DesignCreationProgressUpdate, DesignInputStep, EditedSteps, FlowExecutionNodeResult, FlowExecutionResult, FlowService, FrameService, FrameStep, FrameStepHandle, FrameThresholdSettings, GetNewWorkflowOptions, GetWorkflowOptions, GlobalPropertyHandle, IllustrationStepHandle, InformationMessageType, InformationResult, InformationStepHandle, IntegrationProduct, IntegrationType, LayoutNotFoundError, MandatorySteps, MaterialStepHandle, MisconfigurationError, MockWorkflowManager, ModelStepHandle, NodeType, ObjectInput, ObjectInputType, OptionNotFoundError, ParseError, PictureStepHandle, Product, ProductCameraRig, ProductCollection, ProductWorkflow, promiseCache as PromiseCache, PromiseQueue, QuestionStepHandle, QueueablePromise, RegionElement, RenderableScene, ResourceNotFoundError, SavedDesign, SelectionStorage, ShapeStepHandle, SilentIllustrationStepData, SpiffCommerceClient, Stakeholder, StakeholderType, StateMutationFunc, StepElements, StepHandle, TextInput, TextStepHandle, TextStepStorage, Transaction, Transform, TransformCollection, UnhandledBehaviorError, Variant, Vector3, WorkflowExperience, WorkflowExperienceEventType, WorkflowExperienceImpl, WorkflowManager, WorkflowMetadata, WorkflowScene, WorkflowSelections, WorkflowStorage, assetService, createDesign, designService, digitalContentStepService, frameStepService, generateCommands, generateStateFromDesignInputSteps, getBoundedOffsets, getWorkflow, getWorkflows, graphQlManager, illustrationStepService, materialStepService, modelStepService, moduleStepService, optionService, persistenceService, pictureStepService, questionStepService, shapeStepService, shortenUrl, spiffCoreConfiguration, stepAspectValuesToDesignInputSteps, textStepService, toast };
|
|
3031
|
+
export { ArrayInput, AssetNotFoundError, Bundle, BundleDesignCreationMessage, CollectionProduct, ColorOption, ConversionConfiguration, ConversionData, ConversionDataType, ConversionLocation, Customer, CustomerDetailsInput, DesignCreationMessage, DesignCreationProgressUpdate, DesignInputStep, EditedSteps, FlowExecutionNodeResult, FlowExecutionResult, FlowService, FrameService, FrameStep, FrameStepHandle, FrameThresholdSettings, GetNewWorkflowOptions, GetWorkflowOptions, GlobalPropertyHandle, IllustrationStepHandle, InformationMessageType, InformationResult, InformationStepHandle, IntegrationProduct, IntegrationType, LayoutNotFoundError, MandatorySteps, MaterialStepHandle, MisconfigurationError, MockWorkflowManager, ModelStepHandle, NodeType, ObjectInput, ObjectInputType, OptionNotFoundError, ParseError, PictureStepHandle, Product, ProductCameraRig, ProductCollection, ProductWorkflow, promiseCache as PromiseCache, PromiseQueue, QuestionStepHandle, QueueablePromise, RegionElement, RenderableScene, ResourceNotFoundError, SavedDesign, SelectionStorage, ShapeStepHandle, SilentIllustrationStepData, SpiffCommerceClient, Stakeholder, StakeholderType, StateMutationFunc, StepElements, StepHandle, TextInput, TextStepHandle, TextStepStorage, Transaction, Transform, TransformCollection, UnhandledBehaviorError, Variant, Vector3, WorkflowExperience, WorkflowExperienceEventType, WorkflowExperienceImpl, WorkflowManager, WorkflowMetadata, WorkflowScene, WorkflowSelections, WorkflowStorage, assetService, createDesign, designService, digitalContentStepService, frameStepService, generateCommands, generateStateFromDesignInputSteps, getBoundedOffsets, getWorkflow, getWorkflows, graphQlManager, illustrationStepService, materialStepService, modelStepService, moduleStepService, optionService, persistenceService, pictureStepService, questionStepService, shapeStepService, shortenUrl, spiffCoreConfiguration, stepAspectValuesToDesignInputSteps, textStepService, toast };
|
package/dist/index.js
CHANGED
|
@@ -6269,6 +6269,7 @@ const ot = F`
|
|
|
6269
6269
|
lineItemImageUrl: i || "",
|
|
6270
6270
|
optionsCost: r,
|
|
6271
6271
|
processExecutionId: s,
|
|
6272
|
+
quantity: c.quantity,
|
|
6272
6273
|
transactionId: c.id,
|
|
6273
6274
|
transactionOwnerId: l,
|
|
6274
6275
|
weight: e.weight,
|
|
@@ -6380,7 +6381,7 @@ const ot = F`
|
|
|
6380
6381
|
throw new Error("Failed to create design");
|
|
6381
6382
|
o("workflow.steps.finish.finalize.updatingTransaction");
|
|
6382
6383
|
const E = w.transaction;
|
|
6383
|
-
return
|
|
6384
|
+
return rt(
|
|
6384
6385
|
E,
|
|
6385
6386
|
n,
|
|
6386
6387
|
e,
|
|
@@ -6425,23 +6426,21 @@ const ot = F`
|
|
|
6425
6426
|
const i = await ca(a.map((s) => s.designDetails));
|
|
6426
6427
|
if (!i)
|
|
6427
6428
|
throw new Error("Failed to create designs");
|
|
6428
|
-
return e("workflow.steps.finish.finalize.updatingTransaction"),
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
})
|
|
6444
|
-
);
|
|
6429
|
+
return e("workflow.steps.finish.finalize.updatingTransaction"), i.map((s, o) => {
|
|
6430
|
+
var l;
|
|
6431
|
+
const r = c[o], g = a[o], B = s.transaction;
|
|
6432
|
+
return rt(
|
|
6433
|
+
B,
|
|
6434
|
+
r.product,
|
|
6435
|
+
r.workflow,
|
|
6436
|
+
g.cartSelectionsWithPrices,
|
|
6437
|
+
s.sku,
|
|
6438
|
+
g.cartMetadata,
|
|
6439
|
+
//lineItemImageLink,
|
|
6440
|
+
void 0,
|
|
6441
|
+
(l = s.processExecution) == null ? void 0 : l.id
|
|
6442
|
+
);
|
|
6443
|
+
});
|
|
6445
6444
|
};
|
|
6446
6445
|
class da {
|
|
6447
6446
|
constructor() {
|
|
@@ -8792,29 +8791,33 @@ class FA {
|
|
|
8792
8791
|
});
|
|
8793
8792
|
}
|
|
8794
8793
|
async finish(e, A) {
|
|
8795
|
-
|
|
8796
|
-
this.workflowExperiences.map((
|
|
8797
|
-
workflowManager:
|
|
8798
|
-
workflow:
|
|
8799
|
-
layouts:
|
|
8800
|
-
getReducerState: () =>
|
|
8801
|
-
product:
|
|
8802
|
-
transaction:
|
|
8803
|
-
workflowSelections:
|
|
8804
|
-
designName:
|
|
8805
|
-
workflowMetadata:
|
|
8794
|
+
const t = await Ba(
|
|
8795
|
+
this.workflowExperiences.map((n) => ({
|
|
8796
|
+
workflowManager: n.getWorkflowManager(),
|
|
8797
|
+
workflow: n.getWorkflowManager().getWorkflow(),
|
|
8798
|
+
layouts: n.getWorkflowManager().getLayouts(),
|
|
8799
|
+
getReducerState: () => n.getCommandContext().getState(),
|
|
8800
|
+
product: n.getWorkflowManager().getProduct(),
|
|
8801
|
+
transaction: n.getWorkflowManager().getTransaction(),
|
|
8802
|
+
workflowSelections: n.getWorkflowManager().getWorkflowSelections(),
|
|
8803
|
+
designName: n.getWorkflowManager().getWorkflow().name,
|
|
8804
|
+
workflowMetadata: n.getWorkflowManager().getWorkflowMetadata()
|
|
8806
8805
|
})),
|
|
8807
8806
|
e ?? (() => {
|
|
8808
8807
|
}),
|
|
8809
|
-
A ? (
|
|
8810
|
-
const
|
|
8811
|
-
(
|
|
8808
|
+
A ? (n, a) => {
|
|
8809
|
+
const i = this.workflowExperiences.find(
|
|
8810
|
+
(s) => s.getWorkflowManager().getTransaction().id === a
|
|
8812
8811
|
);
|
|
8813
|
-
return
|
|
8814
|
-
"SpiffCommerce - Bundle create design - Unable to find experience for transaction: " +
|
|
8812
|
+
return i ? A(i) : (console.warn(
|
|
8813
|
+
"SpiffCommerce - Bundle create design - Unable to find experience for transaction: " + a
|
|
8815
8814
|
), Promise.resolve(void 0));
|
|
8816
8815
|
} : void 0
|
|
8817
8816
|
);
|
|
8817
|
+
return {
|
|
8818
|
+
bundleId: this.id,
|
|
8819
|
+
items: t
|
|
8820
|
+
};
|
|
8818
8821
|
}
|
|
8819
8822
|
getPreviewService() {
|
|
8820
8823
|
return this.previewService;
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1960,7 +1960,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
1960
1960
|
}
|
|
1961
1961
|
}
|
|
1962
1962
|
}
|
|
1963
|
-
`,dn=async c=>{var t;return(t=(await N.getShadowGraphqlClient().mutate({mutation:ln,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c.name,layouts:c.layouts,workflowId:c.workflowId,transactionId:c.transactionId,previewImage:c.previewImage,useThreeDimPreview:c.useThreeDimPreview,metadata:c.metadata,selectedVariants:c.selectedVariants}})).data)==null?void 0:t.designCreate},wn=async c=>{var t;return(t=(await N.getShadowGraphqlClient().mutate({mutation:Bn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{inputs:c.map(A=>({name:A.name,layouts:A.layouts,workflowId:A.workflowId,transactionId:A.transactionId,previewImage:A.previewImage,useThreeDimPreview:A.useThreeDimPreview,metadata:A.metadata,selectedVariants:A.selectedVariants}))}})).data)==null?void 0:t.designCreateMany},je=(c,e,t)=>{const A=a=>{const i={};if(a.type==="Frame"){const o=c[a.stepName],s=a.data;if(!o||!o.image||s.hideImageInCart&&t)return i;i[`${a.stepTitle} image`]=o.image}if(a.type==="Illustration"){const o=c[a.stepName],s=a.data;if(!o||s.hideColorsInCart&&t||!o.colors)return i;if(o.colors.length>0){const r=o.colors.join(", ").toUpperCase();i[`${a.stepTitle} colors`]=r}}if(a.type==="Module"){const o=c[a.stepName],s=a.data;if(!o||o.text===void 0||o.text===null||s.hideTextInCart&&t)return i;i[`${a.stepTitle} text`]=o.text}if(a.type==="Text"){const o=c[a.stepName];if(!o)return i;const s=a.data;(!s.hideTextInCart||!t&&o.text!==void 0&&o.text!==null)&&(i[`${a.stepTitle} text`]=o.text),o.color&&(!s.hideColorInCart||!t)&&(i[`${a.stepTitle} color`]=o.color)}return i},n={};return e.steps.forEach(a=>{Object.assign(n,A(a))}),n},En=(c,e,t,A)=>{const n={};let a;if(t){a=je(t,e,!1);for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}else if(A){a=A;for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}for(const i of Object.keys(c)){const o=c[i],s=e.steps.find(r=>r.stepTitle===i);if(o.length===1)n[`${s==null?void 0:s.stepTitle} selection`]={value:o[0].name,priceModifier:o[0].priceModifier};else if(o.length>1)for(let r=0;r<o.length;r++)n[`${s==null?void 0:s.stepTitle} selection ${r+1}`]={value:o[r].name,priceModifier:o[r].priceModifier}}return n},Lt=(c,e,t,A,n,a,i,o)=>{var E,C;const s=e.basePrice||0,r=c.priceModifierTotal||0,l=En(A,t,void 0,a),B=(P.getMap("transactionOwnerIds")||new Map).get(c.id),w={additionalExternalProductId:(E=c.integrationProduct)==null?void 0:E.additionalExternalProductId,additionalExternalVariantId:(C=c.integrationProduct)==null?void 0:C.additionalExternalVariantId,baseCost:s,designProductId:c.externalDesignProductId,designProductVariantId:c.externalDesignProductVariantId,event:"onComplete",exportedData:l,externalCartProductId:c.externalCartProductId,externalCartProductVariantId:c.externalCartProductVariantId,lineItemImageUrl:i||"",optionsCost:r,processExecutionId:o,transactionId:c.id,transactionOwnerId:B,weight:e.weight,workflowViewerLink:c.workflowViewerLink||"",workflowViewerReadOnlyLink:c.workflowViewerReadOnlyLink||""};return a&&(w.metadata=a),A&&(w.selectedVariants=A),n&&(w.sku=n),w},Ot=async(c,e,t,A,n,a,i,o,s,r)=>{var S;await(async()=>{var T;if(r!==void 0)return r;await c.outstandingRequestsPromise();const x=(P.getMap("transactionOwnerIds")||new Map).get(n.id),H=await N.getShadowGraphqlClient().query({query:Et,variables:{ids:[n.id]},fetchPolicy:"no-cache",errorPolicy:"all",context:{transactionOwnerId:x}}),R=(T=H.data)==null?void 0:T.transactions[0].workflowState;return H.errors?(H.errors.forEach(k=>{H.errors&&console.log("Server Error:",k.message)}),null):R??null})()||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(A())),await c.updateStateWithServerImmediate(A),console.log("Server state is undefined @ Workflow completion"));const B=c.getPreviewService(),w=(S=e==null?void 0:e.finalizeStepConfig)==null?void 0:S.lookAtAnimation,E=B&&e.showModelOnFinishStep&&!!w,C=s&&je(s,e,!0),h=s&&je(s,e,!1),m=async y=>{const x={};let Y=0;if(Object.keys(a).length>0)for(const H of Object.keys(a)){const R=a[H],T=e.steps.find(k=>k.stepName===H);for(let k=0;k<R.selections.length;++k){const z=R.selections[k];if(T&&(!y||T.option&&(T.option.variants||[]).length>1&&!T.data.hideSelectionInCart&&!T.data.hideSelectionsInCart)){const Ze=T.stepTitle;x[Ze]?x[Ze].push({id:z.id||"",name:z.name,priceModifier:z.priceModifier}):x[Ze]=[{id:z.id||"",name:z.name,priceModifier:z.priceModifier}]}Y+=z.priceModifier}}return[x,Y]},[u]=await m(!0),F=Object.fromEntries(Object.keys(u).map(y=>[y,u[y].map(x=>x.id)])),[I]=await m(!1),f=Object.fromEntries(Object.keys(I).map(y=>[y,I[y].map(x=>x.id)])),D=await o(E,n.id);return{designDetails:(()=>{const y={name:i,layouts:t.map(x=>({index:x.index,panelId:x.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!E,previewImage:D};if(h){const x=[];for(const[Y,H]of Object.entries(h))x.push({key:Y,value:H});y.metadata=x}if(F){const x=[];for(const[Y,H]of Object.entries(f))x.push({key:Y,ids:H});y.selectedVariants=x}return y})(),cartSelectionsWithPrices:u,cartMetadata:C}},zt=async(c,e,t,A,n,a,i,o,s,r,l)=>{var m,u;s("workflow.steps.finish.finalize.buildingLayouts");const{designDetails:d,cartSelectionsWithPrices:B,cartMetadata:w}=await Ot(c,e,t,A,a,i,o,r,l);s("workflow.steps.finish.finalize.creatingDesign");const E=await dn(d),C=(m=E==null?void 0:E.transaction)==null?void 0:m.previewImageLink;if(!(E!=null&&E.transaction))throw new Error("Failed to create design");s("workflow.steps.finish.finalize.updatingTransaction");const h=E.transaction;return
|
|
1963
|
+
`,dn=async c=>{var t;return(t=(await N.getShadowGraphqlClient().mutate({mutation:ln,errorPolicy:"all",fetchPolicy:"no-cache",variables:{name:c.name,layouts:c.layouts,workflowId:c.workflowId,transactionId:c.transactionId,previewImage:c.previewImage,useThreeDimPreview:c.useThreeDimPreview,metadata:c.metadata,selectedVariants:c.selectedVariants}})).data)==null?void 0:t.designCreate},wn=async c=>{var t;return(t=(await N.getShadowGraphqlClient().mutate({mutation:Bn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{inputs:c.map(A=>({name:A.name,layouts:A.layouts,workflowId:A.workflowId,transactionId:A.transactionId,previewImage:A.previewImage,useThreeDimPreview:A.useThreeDimPreview,metadata:A.metadata,selectedVariants:A.selectedVariants}))}})).data)==null?void 0:t.designCreateMany},je=(c,e,t)=>{const A=a=>{const i={};if(a.type==="Frame"){const o=c[a.stepName],s=a.data;if(!o||!o.image||s.hideImageInCart&&t)return i;i[`${a.stepTitle} image`]=o.image}if(a.type==="Illustration"){const o=c[a.stepName],s=a.data;if(!o||s.hideColorsInCart&&t||!o.colors)return i;if(o.colors.length>0){const r=o.colors.join(", ").toUpperCase();i[`${a.stepTitle} colors`]=r}}if(a.type==="Module"){const o=c[a.stepName],s=a.data;if(!o||o.text===void 0||o.text===null||s.hideTextInCart&&t)return i;i[`${a.stepTitle} text`]=o.text}if(a.type==="Text"){const o=c[a.stepName];if(!o)return i;const s=a.data;(!s.hideTextInCart||!t&&o.text!==void 0&&o.text!==null)&&(i[`${a.stepTitle} text`]=o.text),o.color&&(!s.hideColorInCart||!t)&&(i[`${a.stepTitle} color`]=o.color)}return i},n={};return e.steps.forEach(a=>{Object.assign(n,A(a))}),n},En=(c,e,t,A)=>{const n={};let a;if(t){a=je(t,e,!1);for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}else if(A){a=A;for(const i of Object.keys(a))n[i]={value:a[i],priceModifier:0}}for(const i of Object.keys(c)){const o=c[i],s=e.steps.find(r=>r.stepTitle===i);if(o.length===1)n[`${s==null?void 0:s.stepTitle} selection`]={value:o[0].name,priceModifier:o[0].priceModifier};else if(o.length>1)for(let r=0;r<o.length;r++)n[`${s==null?void 0:s.stepTitle} selection ${r+1}`]={value:o[r].name,priceModifier:o[r].priceModifier}}return n},Lt=(c,e,t,A,n,a,i,o)=>{var E,C;const s=e.basePrice||0,r=c.priceModifierTotal||0,l=En(A,t,void 0,a),B=(P.getMap("transactionOwnerIds")||new Map).get(c.id),w={additionalExternalProductId:(E=c.integrationProduct)==null?void 0:E.additionalExternalProductId,additionalExternalVariantId:(C=c.integrationProduct)==null?void 0:C.additionalExternalVariantId,baseCost:s,designProductId:c.externalDesignProductId,designProductVariantId:c.externalDesignProductVariantId,event:"onComplete",exportedData:l,externalCartProductId:c.externalCartProductId,externalCartProductVariantId:c.externalCartProductVariantId,lineItemImageUrl:i||"",optionsCost:r,processExecutionId:o,quantity:c.quantity,transactionId:c.id,transactionOwnerId:B,weight:e.weight,workflowViewerLink:c.workflowViewerLink||"",workflowViewerReadOnlyLink:c.workflowViewerReadOnlyLink||""};return a&&(w.metadata=a),A&&(w.selectedVariants=A),n&&(w.sku=n),w},Ot=async(c,e,t,A,n,a,i,o,s,r)=>{var S;await(async()=>{var T;if(r!==void 0)return r;await c.outstandingRequestsPromise();const x=(P.getMap("transactionOwnerIds")||new Map).get(n.id),H=await N.getShadowGraphqlClient().query({query:Et,variables:{ids:[n.id]},fetchPolicy:"no-cache",errorPolicy:"all",context:{transactionOwnerId:x}}),R=(T=H.data)==null?void 0:T.transactions[0].workflowState;return H.errors?(H.errors.forEach(k=>{H.errors&&console.log("Server Error:",k.message)}),null):R??null})()||(console.warn("State mismatch detected. Uploading known state explicitly"),console.warn("State Object:",JSON.stringify(A())),await c.updateStateWithServerImmediate(A),console.log("Server state is undefined @ Workflow completion"));const B=c.getPreviewService(),w=(S=e==null?void 0:e.finalizeStepConfig)==null?void 0:S.lookAtAnimation,E=B&&e.showModelOnFinishStep&&!!w,C=s&&je(s,e,!0),h=s&&je(s,e,!1),m=async y=>{const x={};let Y=0;if(Object.keys(a).length>0)for(const H of Object.keys(a)){const R=a[H],T=e.steps.find(k=>k.stepName===H);for(let k=0;k<R.selections.length;++k){const z=R.selections[k];if(T&&(!y||T.option&&(T.option.variants||[]).length>1&&!T.data.hideSelectionInCart&&!T.data.hideSelectionsInCart)){const Ze=T.stepTitle;x[Ze]?x[Ze].push({id:z.id||"",name:z.name,priceModifier:z.priceModifier}):x[Ze]=[{id:z.id||"",name:z.name,priceModifier:z.priceModifier}]}Y+=z.priceModifier}}return[x,Y]},[u]=await m(!0),F=Object.fromEntries(Object.keys(u).map(y=>[y,u[y].map(x=>x.id)])),[I]=await m(!1),f=Object.fromEntries(Object.keys(I).map(y=>[y,I[y].map(x=>x.id)])),D=await o(E,n.id);return{designDetails:(()=>{const y={name:i,layouts:t.map(x=>({index:x.index,panelId:x.panelId})),workflowId:e.id,transactionId:n.id,useThreeDimPreview:!!E,previewImage:D};if(h){const x=[];for(const[Y,H]of Object.entries(h))x.push({key:Y,value:H});y.metadata=x}if(F){const x=[];for(const[Y,H]of Object.entries(f))x.push({key:Y,ids:H});y.selectedVariants=x}return y})(),cartSelectionsWithPrices:u,cartMetadata:C}},zt=async(c,e,t,A,n,a,i,o,s,r,l)=>{var m,u;s("workflow.steps.finish.finalize.buildingLayouts");const{designDetails:d,cartSelectionsWithPrices:B,cartMetadata:w}=await Ot(c,e,t,A,a,i,o,r,l);s("workflow.steps.finish.finalize.creatingDesign");const E=await dn(d),C=(m=E==null?void 0:E.transaction)==null?void 0:m.previewImageLink;if(!(E!=null&&E.transaction))throw new Error("Failed to create design");s("workflow.steps.finish.finalize.updatingTransaction");const h=E.transaction;return Lt(h,n,e,B,E==null?void 0:E.sku,w,C,(u=E==null?void 0:E.processExecution)==null?void 0:u.id)},hn=async(c,e,t)=>{e("workflow.steps.finish.finalize.buildingLayouts"),await Promise.all(c.map(async o=>{await o.workflowManager.outstandingRequestsPromise()}));const n=await(async()=>{var r;const s=await N.getShadowGraphqlClient().query({query:Et,variables:{ids:c.map(l=>l.transaction.id)},fetchPolicy:"no-cache",errorPolicy:"all"});return s.errors?(s.errors.forEach(l=>{s.errors&&console.log("Server Error:",l.message)}),null):(r=s.data)!=null&&r.transactions?s.data.transactions.map(l=>l.workflowState??null):null})(),a=await Promise.all(c.map(async(o,s)=>await Ot(o.workflowManager,o.workflow,o.layouts,o.getReducerState,o.transaction,o.workflowSelections,o.designName,t??(()=>Promise.resolve(void 0)),o.workflowMetadata,n?n[s]:void 0)));e("workflow.steps.finish.finalize.creatingDesign");const i=await wn(a.map(o=>o.designDetails));if(!i)throw new Error("Failed to create designs");return e("workflow.steps.finish.finalize.updatingTransaction"),i.map((o,s)=>{var B;const r=c[s],l=a[s],d=o.transaction;return Lt(d,r.product,r.workflow,l.cartSelectionsWithPrices,o.sku,l.cartMetadata,void 0,(B=o.processExecution)==null?void 0:B.id)})};class Cn{constructor(){this.localPersistenceKey="designTransactions",this.storageMethod="Local",this.designSavedListeners=[]}attachSaveListener(e){this.designSavedListeners.push(e)}detachSaveListener(e){this.designSavedListeners=this.designSavedListeners.filter(t=>t!==e)}async getSavedDesigns(){if(this.storageMethod==="Local"){const e=P.get(this.localPersistenceKey);return e?JSON.parse(e):[]}throw new v("Unexpected storage method requested")}async getSavedDesignByTransaction(e){return(await this.getSavedDesigns()).find(A=>A.transactionId===e)}async addDesign(e){const A=(await this.getSavedDesigns()).filter(n=>n.transactionId!==e.transactionId);A.unshift(e),await this.setDesigns(A),this.designSavedListeners.forEach(n=>n(e))}async renameDesign(e,t){const A=await this.getSavedDesigns(),n=A.find(a=>a.transactionId===e);if(!n)throw new Error(`No saved design for transaction ${e}.`);n.title=t,await this.setDesigns(A)}async removeDesign(e){const t=await this.getSavedDesigns();await this.setDesigns(t.filter(A=>A.transactionId!==e))}async setDesigns(e){if(this.storageMethod==="Local"){P.set(this.localPersistenceKey,JSON.stringify(e));return}throw new v("Unexpected storage method requested")}}const Fe=new Cn,Qn=M.gql`
|
|
1964
1964
|
mutation AddTransactionStakeholder($id: String!, $type: String!, $details: CustomerDetailsInput!) {
|
|
1965
1965
|
transactionAddStakeholder(id: $id, details: $details, type: $type) {
|
|
1966
1966
|
id
|
|
@@ -2309,7 +2309,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2309
2309
|
}
|
|
2310
2310
|
}
|
|
2311
2311
|
}
|
|
2312
|
-
`;class ta{constructor(e,t,A){this.bundleId=e,this.bundleOwnerId=t,this.initPromise=this.getOrCreateGlobalPropertyState().then(n=>{this.globalPropertyState=n}),this.onGlobalPropertyStateChange=A}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=this.globalPropertyState.aspects.find(A=>A.name===e);if(t)return t.value}async setAspect(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=Ee(this.globalPropertyState),n=this.globalPropertyState.aspects.find(a=>a.name===e);n?n.value=t:this.globalPropertyState.aspects.push({name:e,value:t}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(A,this.globalPropertyState)}async updateGlobalPropertyState(){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:_n,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects},context:{bundleOwnerId:this.bundleOwnerId}});if((t=e.data)!=null&&t.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A;const e=await N.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:$n,variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});if((A=t.data)!=null&&A.globalPropertyStateCreate&&t.data.globalPropertyStateCreate.id)return t.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}class Aa{constructor(e){this.setState(e)}setState(e){e&&(this.state=JSON.parse(e))}applyStateToWorkflowExperience(e){var i;if(!this.state||!((i=e==null?void 0:e.getWorkflowManager())!=null&&i.getModelContainer()))return;const t=this.state.transactions.find(o=>o.transactionId===e.getWorkflowManager().getTransaction().id);if(!t)return;const A=this.getTransformToApply(t);if(!A)return;const n=this.flipTransform(A,e.getWorkflowManager().getPreviewService()),a=e.getWorkflowManager().getModelContainer();a.position=n.position,a.rotation=n.rotation,a.scale=n.scale}getTransformToApply(e){return e.activeTransform&&e.transforms?e.transforms[e.activeTransform]:e.transform}updateWorkflowExperienceTransform(e,t,A){const n=e.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find(i=>i.transactionId===n);a?(a.transforms||(a.transforms={}),a.transforms[t]=A):this.state.transactions.push({transactionId:n,activeTransform:t,transforms:{[t]:A}})}activateWorkflowExperienceTransform(e,t){var s,r;if(!((s=e==null?void 0:e.getWorkflowManager())!=null&&s.getModelContainer())||!this.state)return;const A=e.getWorkflowManager().getTransaction().id,n=this.state.transactions.find(l=>l.transactionId===A),a=(r=n==null?void 0:n.transforms)==null?void 0:r[t];if(!a)return;const i=this.flipTransform(a,e.getWorkflowManager().getPreviewService()),o=e.getWorkflowManager().getModelContainer();o.position=i.position,o.rotation=i.rotation,o.scale=i.scale,n.activeTransform=t}removeStateForTransaction(e){if(!this.state||!this.state.transactions)return;const t=this.state.transactions.findIndex(A=>A.transactionId===e);t!==-1&&this.state.transactions.splice(t,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}flipTransform(e,t){return t&&t.flipTransform?t.flipTransform(e.position,{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},e.scale):{position:e.position,rotation:{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},scale:e.scale}}}class qt{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.map(e=>new ye(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new ye(t));const e=await N.getShadowGraphqlClient().query({query:kn,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new ye(t))}getTransformCollection(){if(this.collection.transformCollection)return new Zt(this.collection.transformCollection)}getResource(){return this.collection}}class ye{constructor(e){this.product=e.product,this.productResource=e}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(e,t){const n=(this.product.integrationProducts||[]).find(a=>{var r,l,d;const i=(r=a.integration)==null?void 0:r.type,o=((l=a.integration)==null?void 0:l.type)===e,s=t?((d=a.integration)==null?void 0:d.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new G("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");const t=this.productResource.workflowId;if(t){const n=e.find(a=>a.workflowName===t);if(n)return new Be(n)}const A=e[0];return new Be(A)}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(e){var n,a,i,o;const t=this.product.basePrice||0;if(!e)return t;if(!e.integrationType&&!e.externalId&&!e.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let A;return e.integrationId?A=(n=this.product.integrationProducts)==null?void 0:n.find(s=>{var r;return((r=s.integration)==null?void 0:r.id)===e.integrationId}):e.externalId?A=(a=this.product.integrationProducts)==null?void 0:a.find(s=>{var r;return((r=s.integration)==null?void 0:r.externalIntegrationId)===e.externalId}):A=(i=this.product.integrationProducts)==null?void 0:i.find(s=>{var r;return((r=s.integration)==null?void 0:r.type)===e.integrationType}),(o=A==null?void 0:A.additionalIntegrationProduct)!=null&&o.product?t+(A.additionalIntegrationProduct.product.basePrice||0):t}}class Be{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class Zt{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new $t(e))}}class $t{constructor(e){this.transform=e}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}class _t{constructor(e,t,A,n,a){var i,o;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((i=t.metadata)==null?void 0:i.map(s=>[s.key,s.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new Aa(t.bundleStateData),this.globalPropertyStateManager=new ta(this.id,this.ownerId,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Wn(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingWorkflowExperiences(((o=t.transactions)==null?void 0:o.map(s=>s.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(e,t){this.eventListeners.set(e,[...this.eventListeners.get(e)||[],t])}removeEventListener(e,t){const A=this.eventListeners.get(e)||[],n=A.indexOf(t);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(e){return this.metadata=new Map(e),this.updateBundle()}setNameAndMetadata(e,t){return this.name=e,this.metadata=new Map(t),this.updateBundle()}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter(A=>A.getType()===g.AspectType.Option).map(A=>{var n;return((n=A.getCurrentVariant())==null?void 0:n.getPrice())||0}).reduce((A,n)=>A+n,0)}getTotalSubunits(){return this.workflowExperiences.map(e=>e.getTotalPriceSubunits()).reduce((e,t)=>e+t,0)}getProductCollection(){return this.productCollection?new qt(this.productCollection):void 0}async addWorkflowExperience(e){await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e])))}async addWorkflowExperiences(e){const t=e.map(i=>i.getWorkflowManager().getTransaction().id),A=t.map(i=>this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===i));if(A.some(i=>!!i))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter(i=>!!i).map(i=>i==null?void 0:i.getWorkflowManager().getTransaction().id).join(", "));const n=P.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:Ln,variables:{id:this.id,transactionIds:t,transactionOwnerIds:a},context:{bundleOwnerId:this.ownerId}}).catch(i=>{console.error(i)}),this.workflowExperiences.push(...e),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const o of e)await this.injectExperienceIntoPreviewService(o);const i=await this.getGlobalProperties();await Promise.all(i.map(o=>o.applyGlobalState(e)))})()])}async appendWorkflowExperience(e,t=!0){const A=e.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===A))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(P.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:Tn,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&this.workflowExperiences.push(e)}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction()))}async removeWorkflowExperienceByTransaction(e){const t=this.workflowExperiences.findIndex(A=>A.getWorkflowManager().getTransaction().id===e.id);await this.removeTransaction(t,e)}async removeWorkflowExperiencesByTransactions(e){await this.removeTransactions(e)}async removeTransaction(e,t,A=!0){if(e>-1){const n=this.workflowExperiences.find(a=>a.getWorkflowManager().getTransaction().id===t.id);this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(t.id),await N.getShadowGraphqlClient().mutate({mutation:On,variables:{id:this.id,transactionId:t.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([a,i])=>({key:a,value:i})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),A&&(this.workflowExperiences.splice(e,1),await this.updateTransactionOrder())}else throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+t.id)}async removeTransactions(e){const t=e.map(n=>this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id));if(t.some(n=>n===-1))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+e.filter((n,a)=>t[a]===-1).map(n=>n.id).join(", "));const A=e.map(n=>this.workflowExperiences.splice(this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id),1)[0]);this.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:zn,variables:{id:this.id,transactionIds:e.map(n=>n.id),name:this.name,metadata:Array.from(this.metadata.entries()).map(([n,a])=>({key:n,value:a})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),await this.updateTransactionOrder()}async insertWorkflowExperience(e,t){await this.appendWorkflowExperience(e,!1),this.workflowExperiences.splice(t,0,e),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const A=await this.getGlobalProperties();await Promise.all(A.map(n=>n.applyGlobalState([e])))})()])}async replaceWorkflowExperience(e,t){if(e<0||e>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[e];if(A.getWorkflowManager().getTransaction().id===t.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(e,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(t,!1)]),this.workflowExperiences[e]=t,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const n=await this.getGlobalProperties();await Promise.all(n.map(a=>a.applyGlobalState([t])))})()])}async swapWorkflowExperiences(e,t){if(e<0||e>=this.workflowExperiences.length||t<0||t>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(e===t)return;const A=this.workflowExperiences[e];this.workflowExperiences[e]=this.workflowExperiences[t],this.workflowExperiences[t]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(e){this.workflowExperiences=this.workflowExperiences.sort(e),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(e,t){var a;const A=await N.getShadowGraphqlClient().mutate({mutation:jn,variables:{id:this.id,details:e,type:t||se.Owner},context:{bundleOwnerId:this.ownerId}});if(!((a=A.data)!=null&&a.bundleAddStakeholder))throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:Kn,variables:{id:this.id,input:e},context:{bundleOwnerId:this.ownerId}});if(!((n=t.data)!=null&&n.bundleUpdateStakeholders))throw new Error("Bundle not found!");const A=t.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const e=await N.getShadowGraphqlClient().query({query:Gn,errorPolicy:"all",variables:{id:this.id},context:{bundleOwnerId:this.ownerId}});if(!e.data.bundles||e.data.bundles.length===0)throw new Error("Bundle not found!");const t=e.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(t),t}storeStakeholderCustomers(e){e.forEach(t=>{t.customer&&this.client.storeCustomer(t.customer)})}async finish(e,t){return await hn(this.workflowExperiences.map(A=>({workflowManager:A.getWorkflowManager(),workflow:A.getWorkflowManager().getWorkflow(),layouts:A.getWorkflowManager().getLayouts(),getReducerState:()=>A.getCommandContext().getState(),product:A.getWorkflowManager().getProduct(),transaction:A.getWorkflowManager().getTransaction(),workflowSelections:A.getWorkflowManager().getWorkflowSelections(),designName:A.getWorkflowManager().getWorkflow().name,workflowMetadata:A.getWorkflowManager().getWorkflowMetadata()})),e??(()=>{}),t?(A,n)=>{const a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n);return a?t(a):(console.warn("SpiffCommerce - Bundle create design - Unable to find experience for transaction: "+n),Promise.resolve(void 0))}:void 0)}getPreviewService(){return this.previewService}async setPreviewService(e){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach(t=>t.getWorkflowManager().ejectFromPreviewService()),e))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);e&&e.registerModelLoadEventListener&&e.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==e&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=e}updateWorkflowExperienceTransform(e,t,A){return this.bundleStateManager.updateWorkflowExperienceTransform(e,t,A),this.updateBundle()}activateWorkflowExperienceTransform(e,t){return this.bundleStateManager.activateWorkflowExperienceTransform(e,t),this.updateBundle()}onModelLoadEvent(e){e.eventType==="unload"||!e.modelContainer||(e.modelContainer.registerMaterialSelectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!0)),e.modelContainer.registerMaterialDeselectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!1)))}onModelSelectedEvent(e,t){if(e&&e.metadata&&e.metadata instanceof Map&&e.metadata.has("workflowManager")){const n=e.metadata.get("workflowManager").getTransaction(),a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n.id);a&&this.fireEvent(t?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:a})}}async injectExperienceIntoPreviewService(e){if(this.previewService){const t=e.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(e)}catch(A){console.error(`Unable to apply state to workflow experience: ${A}`)}await t}}async loadExistingWorkflowExperiences(e,t){if(e.length===0)return;const A=await this.client.getWorkflowExperiences(e.map(n=>({type:"transaction",transactionId:n})),t);if(this.workflowExperiences=A,this.previewService)for(const n of A)await this.injectExperienceIntoPreviewService(n)}async updateBundle(){var t;if(!((t=(await N.getShadowGraphqlClient().mutate({mutation:Jn,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([A,n])=>({key:A,value:n})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}})).data)!=null&&t.bundleUpdate))throw new Error("Bundle not found!")}async updateTransactionOrder(){await N.getShadowGraphqlClient().mutate({mutation:Vn,variables:{id:this.id,transactionIds:this.workflowExperiences.map(e=>e.getWorkflowManager().getTransaction().id)},context:{bundleOwnerId:this.ownerId}})}async checkConditionalHandlesChanged(e,t){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,e),a=this.globalPropertyHandleService.applyConditionsFromState(A,t);(()=>{if(n.length!==a.length)return!0;for(let o=0;o<n.length;o++)if(n[o].getName()!==a[o].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(e,t){(this.eventListeners.get(e)||[]).forEach(n=>n({bundle:this,event:e,data:t}))}}const na=M.gql`
|
|
2312
|
+
`;class ta{constructor(e,t,A){this.bundleId=e,this.bundleOwnerId=t,this.initPromise=this.getOrCreateGlobalPropertyState().then(n=>{this.globalPropertyState=n}),this.onGlobalPropertyStateChange=A}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=this.globalPropertyState.aspects.find(A=>A.name===e);if(t)return t.value}async setAspect(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=Ee(this.globalPropertyState),n=this.globalPropertyState.aspects.find(a=>a.name===e);n?n.value=t:this.globalPropertyState.aspects.push({name:e,value:t}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(A,this.globalPropertyState)}async updateGlobalPropertyState(){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:_n,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects},context:{bundleOwnerId:this.bundleOwnerId}});if((t=e.data)!=null&&t.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A;const e=await N.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:$n,variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});if((A=t.data)!=null&&A.globalPropertyStateCreate&&t.data.globalPropertyStateCreate.id)return t.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}class Aa{constructor(e){this.setState(e)}setState(e){e&&(this.state=JSON.parse(e))}applyStateToWorkflowExperience(e){var i;if(!this.state||!((i=e==null?void 0:e.getWorkflowManager())!=null&&i.getModelContainer()))return;const t=this.state.transactions.find(o=>o.transactionId===e.getWorkflowManager().getTransaction().id);if(!t)return;const A=this.getTransformToApply(t);if(!A)return;const n=this.flipTransform(A,e.getWorkflowManager().getPreviewService()),a=e.getWorkflowManager().getModelContainer();a.position=n.position,a.rotation=n.rotation,a.scale=n.scale}getTransformToApply(e){return e.activeTransform&&e.transforms?e.transforms[e.activeTransform]:e.transform}updateWorkflowExperienceTransform(e,t,A){const n=e.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find(i=>i.transactionId===n);a?(a.transforms||(a.transforms={}),a.transforms[t]=A):this.state.transactions.push({transactionId:n,activeTransform:t,transforms:{[t]:A}})}activateWorkflowExperienceTransform(e,t){var s,r;if(!((s=e==null?void 0:e.getWorkflowManager())!=null&&s.getModelContainer())||!this.state)return;const A=e.getWorkflowManager().getTransaction().id,n=this.state.transactions.find(l=>l.transactionId===A),a=(r=n==null?void 0:n.transforms)==null?void 0:r[t];if(!a)return;const i=this.flipTransform(a,e.getWorkflowManager().getPreviewService()),o=e.getWorkflowManager().getModelContainer();o.position=i.position,o.rotation=i.rotation,o.scale=i.scale,n.activeTransform=t}removeStateForTransaction(e){if(!this.state||!this.state.transactions)return;const t=this.state.transactions.findIndex(A=>A.transactionId===e);t!==-1&&this.state.transactions.splice(t,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}flipTransform(e,t){return t&&t.flipTransform?t.flipTransform(e.position,{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},e.scale):{position:e.position,rotation:{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},scale:e.scale}}}class qt{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.map(e=>new ye(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new ye(t));const e=await N.getShadowGraphqlClient().query({query:kn,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new ye(t))}getTransformCollection(){if(this.collection.transformCollection)return new Zt(this.collection.transformCollection)}getResource(){return this.collection}}class ye{constructor(e){this.product=e.product,this.productResource=e}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(e,t){const n=(this.product.integrationProducts||[]).find(a=>{var r,l,d;const i=(r=a.integration)==null?void 0:r.type,o=((l=a.integration)==null?void 0:l.type)===e,s=t?((d=a.integration)==null?void 0:d.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new G("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");const t=this.productResource.workflowId;if(t){const n=e.find(a=>a.workflowName===t);if(n)return new Be(n)}const A=e[0];return new Be(A)}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(e){var n,a,i,o;const t=this.product.basePrice||0;if(!e)return t;if(!e.integrationType&&!e.externalId&&!e.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let A;return e.integrationId?A=(n=this.product.integrationProducts)==null?void 0:n.find(s=>{var r;return((r=s.integration)==null?void 0:r.id)===e.integrationId}):e.externalId?A=(a=this.product.integrationProducts)==null?void 0:a.find(s=>{var r;return((r=s.integration)==null?void 0:r.externalIntegrationId)===e.externalId}):A=(i=this.product.integrationProducts)==null?void 0:i.find(s=>{var r;return((r=s.integration)==null?void 0:r.type)===e.integrationType}),(o=A==null?void 0:A.additionalIntegrationProduct)!=null&&o.product?t+(A.additionalIntegrationProduct.product.basePrice||0):t}}class Be{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class Zt{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new $t(e))}}class $t{constructor(e){this.transform=e}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}class _t{constructor(e,t,A,n,a){var i,o;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((i=t.metadata)==null?void 0:i.map(s=>[s.key,s.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new Aa(t.bundleStateData),this.globalPropertyStateManager=new ta(this.id,this.ownerId,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Wn(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingWorkflowExperiences(((o=t.transactions)==null?void 0:o.map(s=>s.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(e,t){this.eventListeners.set(e,[...this.eventListeners.get(e)||[],t])}removeEventListener(e,t){const A=this.eventListeners.get(e)||[],n=A.indexOf(t);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(e){return this.metadata=new Map(e),this.updateBundle()}setNameAndMetadata(e,t){return this.name=e,this.metadata=new Map(t),this.updateBundle()}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter(A=>A.getType()===g.AspectType.Option).map(A=>{var n;return((n=A.getCurrentVariant())==null?void 0:n.getPrice())||0}).reduce((A,n)=>A+n,0)}getTotalSubunits(){return this.workflowExperiences.map(e=>e.getTotalPriceSubunits()).reduce((e,t)=>e+t,0)}getProductCollection(){return this.productCollection?new qt(this.productCollection):void 0}async addWorkflowExperience(e){await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e])))}async addWorkflowExperiences(e){const t=e.map(i=>i.getWorkflowManager().getTransaction().id),A=t.map(i=>this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===i));if(A.some(i=>!!i))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter(i=>!!i).map(i=>i==null?void 0:i.getWorkflowManager().getTransaction().id).join(", "));const n=P.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:Ln,variables:{id:this.id,transactionIds:t,transactionOwnerIds:a},context:{bundleOwnerId:this.ownerId}}).catch(i=>{console.error(i)}),this.workflowExperiences.push(...e),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const o of e)await this.injectExperienceIntoPreviewService(o);const i=await this.getGlobalProperties();await Promise.all(i.map(o=>o.applyGlobalState(e)))})()])}async appendWorkflowExperience(e,t=!0){const A=e.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===A))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(P.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:Tn,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&this.workflowExperiences.push(e)}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction()))}async removeWorkflowExperienceByTransaction(e){const t=this.workflowExperiences.findIndex(A=>A.getWorkflowManager().getTransaction().id===e.id);await this.removeTransaction(t,e)}async removeWorkflowExperiencesByTransactions(e){await this.removeTransactions(e)}async removeTransaction(e,t,A=!0){if(e>-1){const n=this.workflowExperiences.find(a=>a.getWorkflowManager().getTransaction().id===t.id);this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(t.id),await N.getShadowGraphqlClient().mutate({mutation:On,variables:{id:this.id,transactionId:t.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([a,i])=>({key:a,value:i})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),A&&(this.workflowExperiences.splice(e,1),await this.updateTransactionOrder())}else throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+t.id)}async removeTransactions(e){const t=e.map(n=>this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id));if(t.some(n=>n===-1))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+e.filter((n,a)=>t[a]===-1).map(n=>n.id).join(", "));const A=e.map(n=>this.workflowExperiences.splice(this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id),1)[0]);this.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:zn,variables:{id:this.id,transactionIds:e.map(n=>n.id),name:this.name,metadata:Array.from(this.metadata.entries()).map(([n,a])=>({key:n,value:a})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),await this.updateTransactionOrder()}async insertWorkflowExperience(e,t){await this.appendWorkflowExperience(e,!1),this.workflowExperiences.splice(t,0,e),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const A=await this.getGlobalProperties();await Promise.all(A.map(n=>n.applyGlobalState([e])))})()])}async replaceWorkflowExperience(e,t){if(e<0||e>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[e];if(A.getWorkflowManager().getTransaction().id===t.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(e,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(t,!1)]),this.workflowExperiences[e]=t,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const n=await this.getGlobalProperties();await Promise.all(n.map(a=>a.applyGlobalState([t])))})()])}async swapWorkflowExperiences(e,t){if(e<0||e>=this.workflowExperiences.length||t<0||t>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(e===t)return;const A=this.workflowExperiences[e];this.workflowExperiences[e]=this.workflowExperiences[t],this.workflowExperiences[t]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(e){this.workflowExperiences=this.workflowExperiences.sort(e),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(e,t){var a;const A=await N.getShadowGraphqlClient().mutate({mutation:jn,variables:{id:this.id,details:e,type:t||se.Owner},context:{bundleOwnerId:this.ownerId}});if(!((a=A.data)!=null&&a.bundleAddStakeholder))throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:Kn,variables:{id:this.id,input:e},context:{bundleOwnerId:this.ownerId}});if(!((n=t.data)!=null&&n.bundleUpdateStakeholders))throw new Error("Bundle not found!");const A=t.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const e=await N.getShadowGraphqlClient().query({query:Gn,errorPolicy:"all",variables:{id:this.id},context:{bundleOwnerId:this.ownerId}});if(!e.data.bundles||e.data.bundles.length===0)throw new Error("Bundle not found!");const t=e.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(t),t}storeStakeholderCustomers(e){e.forEach(t=>{t.customer&&this.client.storeCustomer(t.customer)})}async finish(e,t){const A=await hn(this.workflowExperiences.map(n=>({workflowManager:n.getWorkflowManager(),workflow:n.getWorkflowManager().getWorkflow(),layouts:n.getWorkflowManager().getLayouts(),getReducerState:()=>n.getCommandContext().getState(),product:n.getWorkflowManager().getProduct(),transaction:n.getWorkflowManager().getTransaction(),workflowSelections:n.getWorkflowManager().getWorkflowSelections(),designName:n.getWorkflowManager().getWorkflow().name,workflowMetadata:n.getWorkflowManager().getWorkflowMetadata()})),e??(()=>{}),t?(n,a)=>{const i=this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===a);return i?t(i):(console.warn("SpiffCommerce - Bundle create design - Unable to find experience for transaction: "+a),Promise.resolve(void 0))}:void 0);return{bundleId:this.id,items:A}}getPreviewService(){return this.previewService}async setPreviewService(e){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach(t=>t.getWorkflowManager().ejectFromPreviewService()),e))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);e&&e.registerModelLoadEventListener&&e.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==e&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=e}updateWorkflowExperienceTransform(e,t,A){return this.bundleStateManager.updateWorkflowExperienceTransform(e,t,A),this.updateBundle()}activateWorkflowExperienceTransform(e,t){return this.bundleStateManager.activateWorkflowExperienceTransform(e,t),this.updateBundle()}onModelLoadEvent(e){e.eventType==="unload"||!e.modelContainer||(e.modelContainer.registerMaterialSelectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!0)),e.modelContainer.registerMaterialDeselectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!1)))}onModelSelectedEvent(e,t){if(e&&e.metadata&&e.metadata instanceof Map&&e.metadata.has("workflowManager")){const n=e.metadata.get("workflowManager").getTransaction(),a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n.id);a&&this.fireEvent(t?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:a})}}async injectExperienceIntoPreviewService(e){if(this.previewService){const t=e.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(e)}catch(A){console.error(`Unable to apply state to workflow experience: ${A}`)}await t}}async loadExistingWorkflowExperiences(e,t){if(e.length===0)return;const A=await this.client.getWorkflowExperiences(e.map(n=>({type:"transaction",transactionId:n})),t);if(this.workflowExperiences=A,this.previewService)for(const n of A)await this.injectExperienceIntoPreviewService(n)}async updateBundle(){var t;if(!((t=(await N.getShadowGraphqlClient().mutate({mutation:Jn,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([A,n])=>({key:A,value:n})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}})).data)!=null&&t.bundleUpdate))throw new Error("Bundle not found!")}async updateTransactionOrder(){await N.getShadowGraphqlClient().mutate({mutation:Vn,variables:{id:this.id,transactionIds:this.workflowExperiences.map(e=>e.getWorkflowManager().getTransaction().id)},context:{bundleOwnerId:this.ownerId}})}async checkConditionalHandlesChanged(e,t){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,e),a=this.globalPropertyHandleService.applyConditionsFromState(A,t);(()=>{if(n.length!==a.length)return!0;for(let o=0;o<n.length;o++)if(n[o].getName()!==a[o].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(e,t){(this.eventListeners.get(e)||[]).forEach(n=>n({bundle:this,event:e,data:t}))}}const na=M.gql`
|
|
2313
2313
|
mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
|
|
2314
2314
|
processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
|
|
2315
2315
|
id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spiffcommerce/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.1",
|
|
4
4
|
"description": "Core client API for interacting with the Spiff Commerce backend.",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.umd.cjs",
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
"print"
|
|
23
23
|
],
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
26
29
|
],
|
|
27
30
|
"author": "SpiffCommerce",
|
|
28
31
|
"devDependencies": {
|