@picked/client 0.0.1-dev.1772073931707 → 0.0.1-dev.1772085077346
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/api-CbXfbi_s.js +19 -0
- package/dist/api-DzSCgBQ2.cjs +1 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -0
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +552 -630
- package/dist/esm/plugins/create-experience/index.js +228 -194
- package/dist/esm/plugins/dynamic-experiences/index.js +115 -0
- package/dist/esm/server/index.js +1 -1
- package/dist/experience-instance-CU_pYPyd.js +820 -0
- package/dist/experience-instance-D_Mwuzb4.cjs +1 -0
- package/dist/types/client.d.ts +10 -12
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/entities/action/action.d.ts +2 -5
- package/dist/types/entities/action/action.d.ts.map +1 -1
- package/dist/types/entities/component/component.d.ts +2 -1
- package/dist/types/entities/component/component.d.ts.map +1 -1
- package/dist/types/entities/component/lazyComponent.d.ts +11 -0
- package/dist/types/entities/component/lazyComponent.d.ts.map +1 -0
- package/dist/types/entities/experience/experience.d.ts +6 -6
- package/dist/types/entities/experience/experience.d.ts.map +1 -1
- package/dist/types/entities/experience-instance/experience-instance.d.ts +4 -3
- package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
- package/dist/types/entities/field/field.d.ts +14 -51
- package/dist/types/entities/field/field.d.ts.map +1 -1
- package/dist/types/entities/plugin/plugin.d.ts +4 -1
- package/dist/types/entities/plugin/plugin.d.ts.map +1 -1
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/types/exports.d.ts +2 -0
- package/dist/types/exports.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/picked.d.ts +17 -17
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/ping.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +23 -26
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/hash.d.ts +18 -0
- package/dist/types/plugins/dynamic-experiences/hash.d.ts.map +1 -0
- package/dist/types/plugins/dynamic-experiences/index.d.ts +3 -0
- package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -0
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts +23 -0
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -0
- package/dist/types/plugins/dynamic-experiences/types.d.ts +15 -0
- package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -0
- package/dist/types/utils/api.d.ts +3 -0
- package/dist/types/utils/api.d.ts.map +1 -0
- package/dist/types/utils/get-step-fields.d.ts +1 -2
- package/dist/types/utils/get-step-fields.d.ts.map +1 -1
- package/dist/types/utils/rules-logic.d.ts.map +1 -1
- package/package.json +7 -1
- package/dist/experience-instance-5rr_D--s.cjs +0 -1
- package/dist/experience-instance-CLR80xop.js +0 -819
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ActionNode, Experience, ExperienceConditional, ExperienceEdge, ExperienceNode, ExperienceStep, ExperienceTarget } from '../../entities/experience/experience';
|
|
2
2
|
import { AdaptedComponent } from '../../entities/component/component';
|
|
3
3
|
import { LogicRule, LogicValue } from '../../logic-engine';
|
|
4
|
-
import { Field,
|
|
4
|
+
import { Field, FieldBooleanMultiple, FieldBooleanSingular, FieldNumberMultiple, FieldNumberSingular, FieldObjectMultiple, FieldObjectSingular, FieldTextMultiple, FieldTextSingular, JsonValue } from '../../entities/field/field';
|
|
5
5
|
import { Serialized } from './serialization';
|
|
6
|
-
export type { FieldOptionValue, FieldOption, FieldOptionArray, FieldOptions };
|
|
7
6
|
export interface Nodeable {
|
|
8
7
|
node: SerializableNode | null;
|
|
9
8
|
}
|
|
@@ -96,58 +95,56 @@ export interface SerializableConditional extends Nodeable {
|
|
|
96
95
|
export interface CreateConditionalOptions {
|
|
97
96
|
condition: LogicRule;
|
|
98
97
|
}
|
|
99
|
-
export
|
|
100
|
-
|
|
101
|
-
name: string;
|
|
102
|
-
type: 'text' | 'number' | 'boolean' | 'object';
|
|
103
|
-
label: string;
|
|
98
|
+
export type CreateFieldOptions = Omit<Field, 'options' | 'placeholder' | 'description' | 'helpText' | 'validation' | 'policies' | 'defaultValue'> & {
|
|
99
|
+
defaultValue?: string | number | boolean | object | null | string[] | number[] | boolean[] | object[];
|
|
104
100
|
placeholder?: string;
|
|
105
101
|
description?: string;
|
|
106
102
|
helpText?: string;
|
|
107
|
-
defaultValue?: T | T[] | null;
|
|
108
|
-
multiple: boolean;
|
|
109
103
|
validation?: LogicRule;
|
|
110
|
-
condition?: LogicRule;
|
|
111
|
-
required: boolean;
|
|
112
|
-
options?: FieldOptions<JsonValue>;
|
|
113
|
-
dependsOn?: string[];
|
|
114
104
|
policies?: {
|
|
115
105
|
doNotTrackValue?: boolean;
|
|
116
106
|
doNotStoreValue?: boolean;
|
|
117
107
|
};
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
options?: NonNullable<FieldTextSingular['options']>[number][] | NonNullable<FieldTextMultiple['options']>[number][] | NonNullable<FieldNumberSingular['options']>[number][] | NonNullable<FieldNumberMultiple['options']>[number][] | NonNullable<FieldBooleanSingular['options']>[number][] | NonNullable<FieldBooleanMultiple['options']>[number][] | Omit<NonNullable<FieldObjectSingular['options']>[number], 'id'>[] | Omit<NonNullable<FieldObjectMultiple['options']>[number], 'id'>[];
|
|
109
|
+
};
|
|
110
|
+
export type SerializableField<T extends JsonValue = JsonValue> = {
|
|
120
111
|
id: string;
|
|
121
112
|
name: string;
|
|
122
|
-
type: 'text' | 'number' | 'boolean' | 'object';
|
|
123
113
|
label: string;
|
|
114
|
+
type: 'text' | 'number' | 'object' | 'boolean';
|
|
115
|
+
multiple: boolean;
|
|
116
|
+
required: boolean;
|
|
117
|
+
defaultValue: string | number | boolean | object | null | string[] | number[] | boolean[] | object[];
|
|
124
118
|
placeholder?: string;
|
|
125
119
|
description?: string;
|
|
126
120
|
helpText?: string;
|
|
127
|
-
|
|
128
|
-
multiple: boolean;
|
|
129
|
-
validation?: LogicRule;
|
|
121
|
+
validation: LogicRule;
|
|
130
122
|
condition?: LogicRule;
|
|
131
|
-
required: boolean;
|
|
132
|
-
options: FieldOptionArray<JsonValue> | LogicRule | null;
|
|
133
|
-
dependsOn?: string[];
|
|
134
123
|
policies?: {
|
|
135
124
|
doNotTrackValue?: boolean;
|
|
136
125
|
doNotStoreValue?: boolean;
|
|
137
126
|
};
|
|
127
|
+
options: {
|
|
128
|
+
id: string;
|
|
129
|
+
label: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
value: JsonValue;
|
|
132
|
+
condition?: LogicRule;
|
|
133
|
+
}[] | null;
|
|
138
134
|
/**
|
|
139
135
|
* Phantom type property for TypeScript type inference.
|
|
140
136
|
* This property never exists at runtime but enables type-safe field value access.
|
|
141
137
|
* @internal
|
|
142
138
|
*/
|
|
143
139
|
__fieldType?: T;
|
|
140
|
+
} & {
|
|
144
141
|
serialize: () => Serialized<Field>;
|
|
145
|
-
}
|
|
142
|
+
};
|
|
146
143
|
export interface SerializableExperience {
|
|
147
144
|
id: string;
|
|
148
145
|
component?: AdaptedComponent;
|
|
149
146
|
name: string;
|
|
150
|
-
condition?: LogicRule;
|
|
147
|
+
condition?: LogicRule | LogicValue;
|
|
151
148
|
/** @deprecated Use `condition` instead. This property will be removed in a future version. */
|
|
152
149
|
decide?: LogicRule;
|
|
153
150
|
initializeOpen?: LogicRule | LogicValue;
|
|
@@ -175,7 +172,7 @@ export interface SerializableExperience {
|
|
|
175
172
|
export interface CreateExperienceOptions {
|
|
176
173
|
id: string;
|
|
177
174
|
name: string;
|
|
178
|
-
condition?: LogicRule;
|
|
175
|
+
condition?: LogicRule | LogicValue;
|
|
179
176
|
/** @deprecated Use `condition` instead. This property will be removed in a future version. */
|
|
180
177
|
decide?: LogicRule;
|
|
181
178
|
initializeOpen?: LogicRule | LogicValue;
|
|
@@ -207,6 +204,6 @@ export declare const createConditional: (conditionalOptions: CreateConditionalOp
|
|
|
207
204
|
* const typedField = createField<MyData>({ type: 'object', ... })
|
|
208
205
|
* ```
|
|
209
206
|
*/
|
|
210
|
-
export declare const createField: <T extends JsonValue = JsonValue>(fieldOptions: CreateFieldOptions
|
|
207
|
+
export declare const createField: <T extends JsonValue = JsonValue>(fieldOptions: CreateFieldOptions) => SerializableField<T>;
|
|
211
208
|
export declare const createExperience: (experience: CreateExperienceOptions) => SerializableExperience;
|
|
212
209
|
//# sourceMappingURL=create-experience.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-experience.d.ts","sourceRoot":"","sources":["../../../../src/plugins/create-experience/create-experience.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,cAAc,EACd,gBAAgB,EAGjB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAAK,EACV,KAAK,
|
|
1
|
+
{"version":3,"file":"create-experience.d.ts","sourceRoot":"","sources":["../../../../src/plugins/create-experience/create-experience.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,cAAc,EACd,gBAAgB,EAGjB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAAK,EACV,KAAK,EACL,oBAAoB,EACpB,oBAAoB,EACpB,mBA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AAC,mBAAmB,EAAE,kBAAkB,GAAG,iBAAiB,KAAK,IAAI,CAAA;CAChF,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,aAAa,iBAAiB,KAAG,UAgB3D,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,aAAa,iBAAiB,GAAG,UAAU,EAC3C,YAAY,sBAAsB,KACjC,gBA+BF,CAAA;AAID,eAAO,MAAM,UAAU,GACrB,aAAa,iBAAiB,EAC9B,YAAY,sBAAsB,KACjC,gBA+EF,CAAA;AAED,eAAO,MAAM,UAAU,GACrB,aAAa,iBAAiB,EAC9B,YAAY,sBAAsB,KACjC,gBAkBF,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,oBAAoB,wBAAwB,EAC5C,YAAY,sBAAsB,KACjC,uBA0CF,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,EACzD,cAAc,kBAAkB,KAC/B,iBAAiB,CAAC,CAAC,CAiOrB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,uBAAuB,KAAG,sBA2LtE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FNV-1a 32-bit hash.
|
|
3
|
+
* Deterministic, fast, well-distributed for short strings.
|
|
4
|
+
*/
|
|
5
|
+
export declare function fnv1a32(input: string): number;
|
|
6
|
+
/**
|
|
7
|
+
* Deterministic dice roll for A/B testing.
|
|
8
|
+
* Returns a value 0–99 derived from the sessionId so the same
|
|
9
|
+
* dice roll applies to every feature for a given session.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sessionDiceRoll(sessionId: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the given dice roll falls within the feature's weight.
|
|
14
|
+
* A feature with weight 50 is a strict superset of one with weight 30.
|
|
15
|
+
* If you're in the 30% group, you're always in the 50% group too.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isAllocated(diceRoll: number, weight: number): boolean;
|
|
18
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAU7C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAUrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACjE,mBAAmB,SAAS,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Plugin } from '../../entities/plugin/plugin';
|
|
2
|
+
import { DynamicExperiencesPluginOptions, ProjectConfig } from './types';
|
|
3
|
+
export declare function fetchProject(apiUrl: string, projectId: string, previewToken?: string): Promise<ProjectConfig | null>;
|
|
4
|
+
/**
|
|
5
|
+
* Plugin that fetches feature configuration from the Picked REST API
|
|
6
|
+
* and registers features with deterministic bucket allocation.
|
|
7
|
+
*
|
|
8
|
+
* Features are fetched during the `onStart` hook, before experience
|
|
9
|
+
* initialization. Search param feature overrides take precedence.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
|
|
14
|
+
*
|
|
15
|
+
* createClient({
|
|
16
|
+
* plugins: [
|
|
17
|
+
* dynamicExperiencesPlugin()
|
|
18
|
+
* ]
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function dynamicExperiencesPlugin(options?: DynamicExperiencesPluginOptions): Plugin;
|
|
23
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAK1D,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAwB,MAAM,SAAS,CAAA;AAgInG,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAgC/B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,MAAM,CAoC1F"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ProjectConfigFeature {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
weight: number;
|
|
6
|
+
version: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ProjectConfig {
|
|
9
|
+
features: ProjectConfigFeature[];
|
|
10
|
+
}
|
|
11
|
+
export interface DynamicExperiencesPluginOptions {
|
|
12
|
+
apiUrl?: string;
|
|
13
|
+
projectConfig?: ProjectConfig;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/plugins/dynamic-experiences/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CACjC;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":"AAMA,wBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAI1E;AAED,wBAAsB,IAAI,CACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,QAAQ,CAAC,CAQnB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Field } from '../entities/field/field';
|
|
2
2
|
import { Picked } from '../picked';
|
|
3
|
-
|
|
4
|
-
export declare function getStepFields<T extends Field>(client: Picked, fields: T[], context?: LogicObject): Promise<T[]>;
|
|
3
|
+
export declare function getStepFields(client: Picked, fields: Field[]): Promise<Field[]>;
|
|
5
4
|
//# sourceMappingURL=get-step-fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-step-fields.d.ts","sourceRoot":"","sources":["../../../src/utils/get-step-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"get-step-fields.d.ts","sourceRoot":"","sources":["../../../src/utils/get-step-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAWvC,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAoDrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules-logic.d.ts","sourceRoot":"","sources":["../../../src/utils/rules-logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAGvC,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE/D;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"rules-logic.d.ts","sourceRoot":"","sources":["../../../src/utils/rules-logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAGvC,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE/D;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,WAAW,gKA2CtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/client",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.1772085077346",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@withease/factories": "^1.0.5"
|
|
6
6
|
},
|
|
@@ -80,6 +80,12 @@
|
|
|
80
80
|
"import": "./dist/esm/plugins/web-components/index.js",
|
|
81
81
|
"require": "./dist/cjs/plugins/web-components/index.js",
|
|
82
82
|
"default": "./dist/esm/plugins/web-components/index.js"
|
|
83
|
+
},
|
|
84
|
+
"./plugins/dynamic-experiences": {
|
|
85
|
+
"types": "./dist/types/plugins/dynamic-experiences/index.d.ts",
|
|
86
|
+
"import": "./dist/esm/plugins/dynamic-experiences/index.js",
|
|
87
|
+
"require": "./dist/cjs/plugins/dynamic-experiences/index.js",
|
|
88
|
+
"default": "./dist/esm/plugins/dynamic-experiences/index.js"
|
|
83
89
|
}
|
|
84
90
|
},
|
|
85
91
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("effector"),W=require("@withease/factories"),j=require("./supports-YvpQZxbh.cjs"),N=require("./logger-BsmHUUw1.cjs"),Ee=require("./object-BbFTsGh3.cjs");function xe(e){return typeof e=="number"&&!isNaN(e)}function P(e){return typeof e=="string"}function x(e){return Array.isArray(e)}function ae(e){return e instanceof Promise}function oe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1}function m(e){if(xe(e))return e;const t=parseFloat(`${e}`);return isNaN(t)?0:t}function L(e){return`${e}`}const Ne={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>m(e)>m(t),">=":(e,t)=>m(e)>=m(t),"<":(e,t,r)=>{const n=m(e),c=m(t);if(r===void 0)return n<c;const a=m(r);return n<c&&c<a},"<=":(e,t,r)=>{const n=m(e),c=m(t);if(r===void 0)return n<=c;const a=m(r);return n<=c&&c<=a},"!!":async e=>await b(e),"!":async e=>!await b(e),"%":(e,t)=>m(e)%m(t),log:e=>(console.log(e),e),in:(e,t)=>t?P(t)?t.indexOf(L(e))!==-1:x(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(L).join(""),substr:(e,t,r)=>{const n=L(e),c=m(t);if(r===void 0)return n.substr(c);const a=m(r);if(a<0){const o=n.substr(c);return o.substr(0,o.length+a)}return n.substr(c,a)},"+":(...e)=>e.reduce((t,r)=>m(t)+m(r),0),"*":(...e)=>e.reduce((t,r)=>m(t)*m(r),1),"-":(e,t)=>{const r=m(e);return t===void 0?-r:r-m(t)},"/":(e,t)=>m(e)/m(t),min:(...e)=>Math.min(...e.map(m)),max:(...e)=>Math.max(...e.map(m)),merge:(...e)=>e.reduce((t,r)=>x(r)?t.concat(r):t.concat([r]),[]),var(e,t){const r=arguments.length>1?t:null;if(e===""||e==="."||e===null||e===void 0)return this;if(typeof e=="number"&&Array.isArray(this))return e>=0&&e<this.length?this[e]:r;const n=L(e);if(n===""||n===".")return this;const c=n.split(".");let a=this;for(const o of c){if(a==null)return r;if(Array.isArray(a)){const f=parseInt(o,10);isNaN(f)?a=a[o]:a=a[f]}else a=a[o]}return a!==void 0?a:r},async missing(...e){const t=x(e[0])?e[0]:e,r=[];for(const n of t){const c=await g({var:n},this);(c===null||c==="")&&r.push(`${n}`)}return r},async missing_some(e,t){const r=await g({missing:t},this);if(!x(r)||!x(t))return[];const n=r.filter(P);return t.filter(P).length-n.length>=m(e)?[]:n},invoke(...e){const[t,...r]=e;return typeof t!="function"?null:Reflect.apply(t,null,r)},regexp_matches(e,t){let r=e,n="";if(x(e)){const[a,o]=e;r=a,n=o}return!P(r)||!P(n)?!1:new RegExp(r,n).test(L(t))},throw(e){throw new Error(L(e))}};async function g(e,t){if(!e)return e;if(ae(e))return g(await e,t);if(x(e))return Promise.all(e.map(o=>g(o,t)));if(!oe(e))return e;const r=Ie(e);let n=r?e[r]??[]:[];switch(x(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await b(await g(n[o],t)))return g(n[o+1],t);return n.length%2===1?g(n[n.length-1],t):null;case"and":{let o=null;for(const f of n)if(o=await g(f,t),!await b(o))return o;return o}case"or":{let o=null;for(const f of n)if(o=await g(f,t),await b(o))return o;return o}case"map":{const o=await g(n[0],t);return x(o)?await Promise.all(o.map(f=>g(n[1],f))):[]}case"filter":{const o=await g(n[0],t);return x(o)?(await Promise.all(o.map(async p=>{const S=await b(await g(n[1],p));return{item:p,shouldInclude:S}}))).filter(({shouldInclude:p})=>p).map(({item:p})=>p):[]}case"reduce":{const o=await g(n[0],t);if(!x(o))return n.length>2?await g(n[2],t):null;const f=n[1];let S=n.length>2?await g(n[2],t):null;for(const w of o)S=await g(f,{current:w,accumulator:S});return S}case"all":{const o=await g(n[0],t);if(!x(o)||o.length===0)return!1;for(const f of o)if(!await b(await g(n[1],f)))return!1;return!0}case"some":{const o=await g(n[0],t);if(!x(o))return!1;for(const f of o)if(await b(await g(n[1],f)))return!0;return!1}case"none":{const o=await g(n[0],t);if(!x(o))return!0;for(const f of o)if(await b(await g(n[1],f)))return!1;return!0}case"catch":try{return await g(n[0],t)}catch(o){return oe(o)?await g(o,t):n[1]?await g(n[1],o):o instanceof Error?o.message:o}}const c=await Promise.all(n.map(o=>g(o,t))),a=r?Ne[r]:void 0;if(!a)throw new Error(`Unrecognized operation ${r}`);return a.apply(t,c)}async function b(e){return ae(e)?b(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function Ie(e){return Object.keys(e)[0]}function ue(e){return!Ee.isEmpty(e)}async function Q(e,t,r){const n=e.getStateSnapshot(),c=e.predicates.listStore.getState().reduce((p,S)=>({...p,[S.name]:(...w)=>S.predicate({...n,args:w})}),{}),a=e.features.listStore.getState().reduce((p,S)=>({...p,[S.id]:async()=>{const{bucket:w}=await S.getBucket();return w}}),{}),o=e.actions.listStore.getState().reduce((p,S)=>({...p,[S.name]:w=>S.action(w)}),{}),f={responses:e.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:c,features:a,actions:o,...r};return await g(t,f)}function ke(e){return!j.supportsWindow()||!j.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}const ve="open";function be(e){if(!j.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:ve})}function Ae(){return new Promise((e,t)=>{if(!j.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function Oe(e,t){const r=new MutationObserver(n=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const q="picked-root",U="picked-target",Fe="picked-root";function Be(e,t){return[...e,{selector:`${Fe}[experience-id="${t}"]`,placement:"replace"}].flatMap(n=>{const c=ke(n.selector).filter(a=>!Te(a,t)&&!fe(a,t));return{...n,elements:c}})}function _e(e,t){return e.flatMap(r=>r.elements.map(n=>Le(n,r.placement,t)))}function $e(e,t){e.classList.add(U),e.classList.add(`${U}-${t}`)}function Te(e,t){return t?e.classList.contains(`${U}-${t}`):e.classList.contains(`${U}`)}function fe(e,t){return t?e.classList.contains(`${q}-${t}`):e.classList.contains(q)}function Me(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(q),t.classList.add(`${q}-${e}`),t}function Le(e,t,r){let n;const c=Me(r);if(e instanceof Document)n=e.body.appendChild(c);else{switch(t){case"replace":e.replaceWith(c);break;case"before":e.before(c);break;case"after":e.after(c);break;case"prepend":e.prepend(c);break;default:e.append(c);break}n=c}return n}function se(e){return e.type==="conditional"}function $(e){return e.type==="step"}function ie(e){return e.type==="experience"}function X(e){return e.type==="origin"}function ce(e){return e.type==="action"}const le=(e,t,r,n,c=new Set)=>c.has(r.id)?[]:(c.add(r.id),$(r)&&!n?[r]:t.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const f=e.find(p=>p.id===o.destinationNodeId);return f?le(e,t,f,!1,c):[]})),De=(e,t,r)=>le(e,t,r,!0,new Set),de=(e,t,r,n,c=new Set)=>{if(c.has(r.id))return[-1,-1];c.add(r.id);const a=t.filter(p=>p.sourceNodeId===r.id);if(a.length===0)return[0,0];let o=1/0,f=-1/0;for(const p of a){const S=e.find(T=>T.id===p.destinationNodeId);if(!S)continue;const[w,O]=de(e,t,S,!1,new Set(c));w!==-1&&(o=Math.min(o,w+1),f=Math.max(f,O+1))}return o===1/0?[-1,-1]:[o,f]},Re=(e,t,r)=>de(e,t,r,!0,new Set),pe=(e,t,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const c=t.filter(f=>f.destinationNodeId===r.id);if(c.length===0)return[-1,-1];let a=1/0,o=-1/0;for(const f of c){const p=e.find(O=>O.id===f.sourceNodeId);if(!p)continue;const[S,w]=pe(e,t,p,new Set(n));S!==-1&&(a=Math.min(a,S+1),o=Math.max(o,w+1))}return a===1/0?[-1,-1]:[a,o]},Pe=(e,t,r)=>pe(e,t,r,new Set),ge=e=>e.find(r=>r.type==="origin")||null,J=(e,t,r)=>{if(!e)return ge(t);const n=r.find(a=>a.sourceNodeId===e.id);if(!n)return null;const c=t.find(a=>a.id===n.destinationNodeId);return c||null};async function He(e,t,r,n){const c=e?"true":"false",a=n.find(o=>o.sourceNodeHandle===c&&o.sourceNodeId===t);return r.find(o=>o.id===a?.destinationNodeId)}const Y=i.createDomain("experience-instance"),Ce=W.createFactory(({client:e,experience:t,target:r})=>{const n=i.createEvent(),c=i.createEvent(),a=i.createEvent(),o=i.createEvent(),f=i.createEvent(),p=i.createEvent(),S=t.componentStore,w=Y.store("transitioning"),O=e.history.entriesStore.map(s=>s.filter(d=>d.experienceId===t.id)),T=O.map(s=>s.filter(d=>$(d.node))),I=O.map(s=>s.at(-1)?.node||null),l=i.combine(t.treeStore,I,({steps:s},d)=>s.find(u=>d&&$(d)&&u.id===d.stepId)||null),h=i.combine(t.treeStore,T,({steps:s},d)=>{const u=d.at(-2);if(!u||!$(u.node))return null;const y=u.node;return s.find(B=>B.id===y.stepId)||null}),v=i.combine(t.treeStore,I,({nodes:s,edges:d},u)=>u?De(s,d,u):[]),M=i.combine(t.treeStore,I,({nodes:s,edges:d},u)=>u?Pe(s,d,u):[-1,-1]),D=i.combine(t.treeStore,I,({nodes:s,edges:d},u)=>u?Re(s,d,u):[-1,-1]),F=Y.store(!1),H=i.createApi(F,{open:()=>!0,close:()=>!1,toggle:s=>!s,set:(s,d)=>d}),Se=i.createEffect(async()=>{e.history.back({experienceId:t.id})}),he=i.attach({source:t.treeStore,effect:async(s,d)=>{const u=s.nodes.find(y=>$(y)&&y.stepId===d);u&&e.history.push({experienceId:t.id,node:u})}}),Z=i.attach({source:I,effect:s=>{}}),G=i.attach({source:t.treeStore,effect:async({nodes:s})=>ge(s)}),K=i.attach({source:t.treeStore,effect:async({nodes:s,edges:d},u)=>{if(X(u))return J(u,s,d)}}),V=i.attach({source:t.treeStore,effect:async({nodes:s,edges:d,conditionals:u},y)=>{if(!se(y))return;const B=u.find(A=>A.id===y.conditionalId);if(!B)return;const k=y.id,E=await Q(e,B.condition);return He(!!E,k,s,d)}}),ee=i.attach({source:t.treeStore,effect:async({nodes:s,edges:d},u)=>{if(!ce(u))return;const y=u.action;if(!y){N.logger("warn",`Action node ${u.id} has no action name`);return}const B=e.actions.getByName(y).getState();if(!B){N.logger("warn",`Action '${y}' not registered on client`);const k=d.find(E=>E.sourceNodeId===u.id&&E.sourceNodeHandle==="false");return k?s.find(E=>E.id===k.destinationNodeId):null}if(typeof B.action!="function"){N.logger("warn",`Action '${y}' is not a function`);const k=d.find(E=>E.sourceNodeId===u.id&&E.sourceNodeHandle==="false");return k?s.find(E=>E.id===k.destinationNodeId):null}try{N.logger("info",`Executing action: ${y}`),await B.action(y);const k=d.find(A=>A.sourceNodeId===u.id&&A.sourceNodeHandle==="true");if(!k)return N.logger("warn",`No 'true' edge found for action node ${u.id}`),null;const E=s.find(A=>A.id===k.destinationNodeId);return N.logger("info",`Action '${y}' succeeded, moving to node ${E?.id}`),E||null}catch(k){N.logger("warn",`Action '${y}' failed:`,k);const E=d.find(C=>C.sourceNodeId===u.id&&C.sourceNodeHandle==="false");if(!E)return N.logger("warn",`No 'false' edge found for action node ${u.id}`),null;const A=s.find(C=>C.id===E.destinationNodeId);return N.logger("info",`Action '${y}' failed, moving to node ${A?.id}`),A||null}}}),ye=i.createEffect(s=>{if(ie(s))return e.launchExperienceById(s.experienceId)}),te=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:d,edges:u}])=>J(s,d,u)}),R=i.attach({source:[I,t.treeStore],effect:async([s,{nodes:d,edges:u}])=>J(s,d,u)}),we=i.createEffect(s=>{e.history.push({experienceId:t.id,node:s})}),ne=i.attach({source:t.configStore,effect:async({initializeOpenLogic:s})=>ue(s)?!!await Q(e,s):s??!1}),_=Object.freeze({id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:S,stateStore:w,isOpenStore:F,open:H.open,close:H.close,toggleOpen:H.toggle,setOpen:H.set,treeStore:t.treeStore,fieldsStore:t.fieldsStore,currentNodeStore:I,currentStepStore:l,previousStepStore:h,nextReachableStepNodesStore:v,stepsToOriginStore:M,stepsToLeafStore:D,goToNextStep:c,goToPreviousStep:a,goToStepById:o,stepsHistoryStore:T}),z=i.createEvent(),re=i.createEvent();return i.sample({source:I,target:z}),i.sample({clock:z,filter:s=>s===null,target:G}),i.sample({clock:z,filter:s=>s!==null,target:re}),i.split({source:re,match:s=>se(s)?"condition":$(s)?"step":ie(s)?"launchExperience":X(s)?"origin":ce(s)?"action":"other",cases:{origin:K,condition:V,step:Z,launchExperience:ye,action:ee,__:i.createEvent()}}),i.sample({clock:[V.doneData,K.doneData,G.doneData,R.doneData,te.doneData,ee.doneData],filter:Boolean,target:we}),i.sample({clock:c,target:R}),i.sample({clock:c,source:l,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit",step:s,experience:_}))}),i.sample({clock:R.done,source:l,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_success",step:s,experience:_}))}),i.sample({clock:R.fail,source:l,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_error",step:s,experience:_}))}),i.sample({clock:a,target:Se}),i.sample({clock:o,target:he}),i.sample({source:i.combine([V.pending,K.pending,G.pending,R.pending]),fn:s=>s.some(Boolean)?"transitioning":"ready",target:w}),i.sample({clock:Z.doneData,source:l,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_enter",step:s,experience:_}))}),i.sample({clock:p,target:ne}),i.sample({source:ne.doneData,fn:Boolean,target:F}),i.sample({source:I,clock:n,filter:s=>s?X(s):!0,target:te}),i.sample({source:F,filter:Boolean,target:n}),i.sample({source:F,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:_}))}),i.sample({source:F,filter:s=>!s,target:e.eventBus.prepend(()=>({type:"experience_close",experience:_}))}),i.sample({clock:f,target:[p]}),f(),_});function me(e){return W.invoke(Ce,e)}const je=W.createFactory(({client:e})=>{const t=Y.store({}),r=i.createEvent(),n=i.createEvent(),c=i.createEvent(),a=i.createApi(t,{register(l,h){const v=[...l[h.experienceId]??[]];return v.push(h),{...l,[h.experienceId]:v}},unregister(l,h){const v=h.experienceId,M=l[v]?.filter(D=>D!==h);return{...l,[v]:M??[]}}}),o=i.createEffect(({experience:l,target:h})=>me({client:e,experience:l,target:h})),f=i.createEffect(l=>{a.register(l)}),p=i.createEffect(l=>{l.target&&Oe(l.target,()=>{c(l)})}),S=i.createEffect(l=>{a.unregister(l)}),w=i.createEffect(l=>{const h=l.componentStore.getState();if(!h){N.logger("warn","No app component registered. Skipping init.");return}const v=h.frameworkStore.getState();if(!v){N.logger("error",`No framework registered for component '${h.name}'. Skipping rendering.`);return}const M=l.target;if(!M){N.logger("error",`No target element registered for experience '${l.experienceId}'. Skipping rendering.`);return}const D=be(M);try{v.render(D,h.component,e,l)}catch(F){N.logger("error",F)}});i.sample({clock:r,target:o}),i.sample({clock:c,target:S}),i.sample({clock:o.doneData,target:[f,p,n]}),i.sample({clock:o.doneData,target:e.eventBus.prepend(l=>({type:"experience_initialize",experience:l}))}),i.sample({clock:n,target:w});function O(l,h){r({experience:l,target:h})}const T=t.map(l=>Object.values(l).flat());function I(l){return t.map(h=>h[l]||[],{skipVoid:!1})}return{spawn:O,getByExperienceId:I,listStore:T}});function qe(e){return W.invoke(je,e)}exports.createAppHosts=_e;exports.createExperienceInstance=me;exports.createExperienceInstanceIndex=qe;exports.domInteractive=Ae;exports.evaluateRuleLogic=Q;exports.getTargetElements=Be;exports.isPickedRoot=fe;exports.isRulesLogic=ue;exports.isStepNode=$;exports.tagTargetElement=$e;
|