@contentful/optimization-core 0.1.0-alpha

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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +408 -0
  3. package/dist/Consent.d.ts +44 -0
  4. package/dist/Consent.d.ts.map +1 -0
  5. package/dist/Consent.js +2 -0
  6. package/dist/Consent.js.map +1 -0
  7. package/dist/CoreBase.d.ts +161 -0
  8. package/dist/CoreBase.d.ts.map +1 -0
  9. package/dist/CoreBase.js +151 -0
  10. package/dist/CoreBase.js.map +1 -0
  11. package/dist/CoreStateful.d.ts +142 -0
  12. package/dist/CoreStateful.d.ts.map +1 -0
  13. package/dist/CoreStateful.js +137 -0
  14. package/dist/CoreStateful.js.map +1 -0
  15. package/dist/CoreStateless.d.ts +53 -0
  16. package/dist/CoreStateless.d.ts.map +1 -0
  17. package/dist/CoreStateless.js +43 -0
  18. package/dist/CoreStateless.js.map +1 -0
  19. package/dist/ProductBase.d.ts +83 -0
  20. package/dist/ProductBase.d.ts.map +1 -0
  21. package/dist/ProductBase.js +50 -0
  22. package/dist/ProductBase.js.map +1 -0
  23. package/dist/analytics/AnalyticsBase.d.ts +35 -0
  24. package/dist/analytics/AnalyticsBase.d.ts.map +1 -0
  25. package/dist/analytics/AnalyticsBase.js +13 -0
  26. package/dist/analytics/AnalyticsBase.js.map +1 -0
  27. package/dist/analytics/AnalyticsStateful.d.ts +138 -0
  28. package/dist/analytics/AnalyticsStateful.d.ts.map +1 -0
  29. package/dist/analytics/AnalyticsStateful.js +179 -0
  30. package/dist/analytics/AnalyticsStateful.js.map +1 -0
  31. package/dist/analytics/AnalyticsStateless.d.ts +48 -0
  32. package/dist/analytics/AnalyticsStateless.d.ts.map +1 -0
  33. package/dist/analytics/AnalyticsStateless.js +61 -0
  34. package/dist/analytics/AnalyticsStateless.js.map +1 -0
  35. package/dist/analytics/index.d.ts +5 -0
  36. package/dist/analytics/index.d.ts.map +1 -0
  37. package/dist/analytics/index.js +5 -0
  38. package/dist/analytics/index.js.map +1 -0
  39. package/dist/global-constants.d.ts +18 -0
  40. package/dist/global-constants.d.ts.map +1 -0
  41. package/dist/global-constants.js +18 -0
  42. package/dist/global-constants.js.map +1 -0
  43. package/dist/index.cjs +1808 -0
  44. package/dist/index.cjs.map +1 -0
  45. package/dist/index.d.ts +15 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +15 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/index.mjs +1535 -0
  50. package/dist/index.mjs.map +1 -0
  51. package/dist/lib/decorators/guardedBy.d.ts +113 -0
  52. package/dist/lib/decorators/guardedBy.d.ts.map +1 -0
  53. package/dist/lib/decorators/guardedBy.js +143 -0
  54. package/dist/lib/decorators/guardedBy.js.map +1 -0
  55. package/dist/lib/decorators/index.d.ts +2 -0
  56. package/dist/lib/decorators/index.d.ts.map +1 -0
  57. package/dist/lib/decorators/index.js +2 -0
  58. package/dist/lib/decorators/index.js.map +1 -0
  59. package/dist/lib/interceptor/InterceptorManager.d.ts +127 -0
  60. package/dist/lib/interceptor/InterceptorManager.d.ts.map +1 -0
  61. package/dist/lib/interceptor/InterceptorManager.js +125 -0
  62. package/dist/lib/interceptor/InterceptorManager.js.map +1 -0
  63. package/dist/lib/interceptor/index.d.ts +2 -0
  64. package/dist/lib/interceptor/index.d.ts.map +1 -0
  65. package/dist/lib/interceptor/index.js +2 -0
  66. package/dist/lib/interceptor/index.js.map +1 -0
  67. package/dist/lib/value-presence/ValuePresence.d.ts +123 -0
  68. package/dist/lib/value-presence/ValuePresence.d.ts.map +1 -0
  69. package/dist/lib/value-presence/ValuePresence.js +141 -0
  70. package/dist/lib/value-presence/ValuePresence.js.map +1 -0
  71. package/dist/lib/value-presence/index.d.ts +2 -0
  72. package/dist/lib/value-presence/index.d.ts.map +1 -0
  73. package/dist/lib/value-presence/index.js +2 -0
  74. package/dist/lib/value-presence/index.js.map +1 -0
  75. package/dist/personalization/PersonalizationBase.d.ts +184 -0
  76. package/dist/personalization/PersonalizationBase.d.ts.map +1 -0
  77. package/dist/personalization/PersonalizationBase.js +76 -0
  78. package/dist/personalization/PersonalizationBase.js.map +1 -0
  79. package/dist/personalization/PersonalizationStateful.d.ts +226 -0
  80. package/dist/personalization/PersonalizationStateful.d.ts.map +1 -0
  81. package/dist/personalization/PersonalizationStateful.js +297 -0
  82. package/dist/personalization/PersonalizationStateful.js.map +1 -0
  83. package/dist/personalization/PersonalizationStateless.d.ts +74 -0
  84. package/dist/personalization/PersonalizationStateless.d.ts.map +1 -0
  85. package/dist/personalization/PersonalizationStateless.js +98 -0
  86. package/dist/personalization/PersonalizationStateless.js.map +1 -0
  87. package/dist/personalization/index.d.ts +6 -0
  88. package/dist/personalization/index.d.ts.map +1 -0
  89. package/dist/personalization/index.js +6 -0
  90. package/dist/personalization/index.js.map +1 -0
  91. package/dist/personalization/resolvers/FlagsResolver.d.ts +35 -0
  92. package/dist/personalization/resolvers/FlagsResolver.d.ts.map +1 -0
  93. package/dist/personalization/resolvers/FlagsResolver.js +47 -0
  94. package/dist/personalization/resolvers/FlagsResolver.js.map +1 -0
  95. package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +74 -0
  96. package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +1 -0
  97. package/dist/personalization/resolvers/MergeTagValueResolver.js +109 -0
  98. package/dist/personalization/resolvers/MergeTagValueResolver.js.map +1 -0
  99. package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +142 -0
  100. package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +1 -0
  101. package/dist/personalization/resolvers/PersonalizedEntryResolver.js +196 -0
  102. package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +1 -0
  103. package/dist/personalization/resolvers/index.d.ts +7 -0
  104. package/dist/personalization/resolvers/index.d.ts.map +1 -0
  105. package/dist/personalization/resolvers/index.js +7 -0
  106. package/dist/personalization/resolvers/index.js.map +1 -0
  107. package/dist/signals.d.ts +35 -0
  108. package/dist/signals.d.ts.map +1 -0
  109. package/dist/signals.js +30 -0
  110. package/dist/signals.js.map +1 -0
  111. package/package.json +29 -0
@@ -0,0 +1,184 @@
1
+ import type { ChangeArray, ComponentViewBuilderArgs, IdentifyBuilderArgs, Json, MergeTagEntry, OptimizationData, PageViewBuilderArgs, Profile, ScreenViewBuilderArgs, SelectedPersonalizationArray, TrackBuilderArgs } from '@contentful/optimization-api-client';
2
+ import type { ChainModifiers, Entry, EntrySkeletonType, LocaleCode } from 'contentful';
3
+ import ProductBase from '../ProductBase';
4
+ import { type ResolvedData } from './resolvers';
5
+ /**
6
+ * These methods assist in resolving values via Resolvers
7
+ *
8
+ * @internal
9
+ * @privateRemarks
10
+ * This interface exists to document that the included methods should not be
11
+ * considered static.
12
+ */
13
+ interface ResolverMethods {
14
+ /**
15
+ * Get the specified Custom Flag's value from the supplied changes.
16
+ * @param name - The name or key of the Custom Flag.
17
+ * @param changes - Optional changes array.
18
+ * @returns The current value of the Custom Flag if found.
19
+ * @remarks
20
+ * The changes array can be sourced from the data returned when emitting any
21
+ * personalization event.
22
+ * */
23
+ getCustomFlag: (name: string, changes?: ChangeArray) => Json;
24
+ /**
25
+ * Resolve a Contentful entry to a personalized variant using the current
26
+ * or provided selected personalizations.
27
+ *
28
+ * @typeParam S - Entry skeleton type.
29
+ * @typeParam M - Chain modifiers.
30
+ * @typeParam L - Locale code.
31
+ * @param entry - The entry to personalize.
32
+ * @param personalizations - Optional selections.
33
+ * @returns The resolved entry data.
34
+ * @remarks
35
+ * Selected personalizations can be sourced from the data returned when emitting any
36
+ * personalization event.
37
+ */
38
+ personalizeEntry: <S extends EntrySkeletonType, M extends ChainModifiers, L extends LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray) => ResolvedData<S, M, L>;
39
+ /**
40
+ * Resolve a merge tag to a value based on the current (or provided) profile.
41
+ *
42
+ * @param embeddedEntryNodeTarget - The merge‑tag entry node to resolve.
43
+ * @param profile - Optional profile.
44
+ * @returns The resolved value (type depends on the tag).
45
+ * @remarks
46
+ * Merge tags are references to profile data that can be substituted into content. The
47
+ * profile can be sourced from the data returned when emitting any personalization event.
48
+ */
49
+ getMergeTagValue: (embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile) => unknown;
50
+ }
51
+ /**
52
+ * Internal base for personalization products.
53
+ *
54
+ * @internal
55
+ * @remarks
56
+ * Concrete implementations should extend this class to expose public methods for
57
+ * identify, page, and track events. This base wires in shared singleton
58
+ * resolvers used to fetch/resolve personalized data.
59
+ */
60
+ declare abstract class PersonalizationBase extends ProductBase implements ResolverMethods {
61
+ /**
62
+ * Static {@link FlagsResolver | resolver} for evaluating personalized
63
+ * custom flags.
64
+ */
65
+ readonly flagsResolver: {
66
+ resolve(changes?: ChangeArray): import("@contentful/optimization-api-schemas").Flags;
67
+ };
68
+ /**
69
+ * Static {@link MergeTagValueResolver | resolver} that returns values
70
+ * sourced from a user profile based on a Contentful Merge Tag entry.
71
+ */
72
+ readonly mergeTagValueResolver: {
73
+ isMergeTagEntry(embeddedEntryNodeTarget: unknown): embeddedEntryNodeTarget is MergeTagEntry;
74
+ normalizeSelectors(id: string): string[];
75
+ getValueFromProfile(id: string, profile?: Profile): string | undefined;
76
+ resolve(mergeTagEntry: MergeTagEntry | undefined, profile?: Profile): string | undefined;
77
+ };
78
+ /**
79
+ * Static {@link PersonalizedEntryResolver | resolver } for personalized
80
+ * Contentful entries (e.g., entry variants targeted to a profile audience).
81
+ *
82
+ * @remarks
83
+ * Used by higher-level personalization flows to materialize entry content
84
+ * prior to event emission.
85
+ */
86
+ readonly personalizedEntryResolver: {
87
+ getPersonalizationEntry({ personalizedEntry, selectedPersonalizations, }: {
88
+ personalizedEntry: import("@contentful/optimization-api-schemas").PersonalizedEntry;
89
+ selectedPersonalizations: SelectedPersonalizationArray;
90
+ }, skipValidation?: boolean): import("@contentful/optimization-api-schemas").PersonalizationEntry | undefined;
91
+ getSelectedPersonalization({ personalizationEntry, selectedPersonalizations, }: {
92
+ personalizationEntry: import("@contentful/optimization-api-schemas").PersonalizationEntry;
93
+ selectedPersonalizations: SelectedPersonalizationArray;
94
+ }, skipValidation?: boolean): import("@contentful/optimization-api-schemas").SelectedPersonalization | undefined;
95
+ getSelectedVariant({ personalizedEntry, personalizationEntry, selectedVariantIndex, }: {
96
+ personalizedEntry: import("@contentful/optimization-api-schemas").PersonalizedEntry;
97
+ personalizationEntry: import("@contentful/optimization-api-schemas").PersonalizationEntry;
98
+ selectedVariantIndex: number;
99
+ }, skipValidation?: boolean): import("@contentful/optimization-api-schemas").EntryReplacementVariant | undefined;
100
+ getSelectedVariantEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = string>({ personalizationEntry, selectedVariant, }: {
101
+ personalizationEntry: import("@contentful/optimization-api-schemas").PersonalizationEntry;
102
+ selectedVariant: import("@contentful/optimization-api-schemas").EntryReplacementVariant;
103
+ }, skipValidation?: boolean): Entry<S, M, L> | undefined;
104
+ resolve<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = string>(entry: Entry<S, M, L>, selectedPersonalizations?: SelectedPersonalizationArray): ResolvedData<S, M, L>;
105
+ };
106
+ /**
107
+ * Get the specified Custom Flag's value from the supplied changes.
108
+ * @param name - The name/key of the Custom Flag.
109
+ * @param changes - Optional changes array.
110
+ * @returns The current value of the Custom Flag if found.
111
+ * @remarks
112
+ * The changes array can be sourced from the data returned when emitting any
113
+ * personalization event.
114
+ * */
115
+ getCustomFlag(name: string, changes?: ChangeArray): Json;
116
+ /**
117
+ * Resolve a Contentful entry to a personalized variant using the current
118
+ * or provided selected personalizations.
119
+ *
120
+ * @typeParam S - Entry skeleton type.
121
+ * @typeParam M - Chain modifiers.
122
+ * @typeParam L - Locale code.
123
+ * @param entry - The entry to personalize.
124
+ * @param personalizations - Optional selected personalizations.
125
+ * @returns The resolved entry data.
126
+ * @remarks
127
+ * Selected personalizations can be sourced from the data returned when emitting any
128
+ * personalization event.
129
+ */
130
+ personalizeEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray): ResolvedData<S, M, L>;
131
+ /**
132
+ * Resolve a merge tag to a value based on the current (or provided) profile.
133
+ *
134
+ * @param embeddedEntryNodeTarget - The merge tag entry node to resolve.
135
+ * @param profile - Optional profile.
136
+ * @returns The resolved value (type depends on the tag).
137
+ * @remarks
138
+ * Merge tags are references to profile data that can be substituted into content. The
139
+ * profile can be sourced from the data returned when emitting any personalization event.
140
+ */
141
+ getMergeTagValue(embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile): unknown;
142
+ /**
143
+ * Identify the current profile/visitor to associate traits with a profile.
144
+ *
145
+ * @param payload - Identify builder payload.
146
+ * @returns The resulting {@link OptimizationData} for the identified user if the device is online.
147
+ */
148
+ abstract identify(payload: IdentifyBuilderArgs): Promise<OptimizationData | undefined>;
149
+ /**
150
+ * Record a page view.
151
+ *
152
+ * @param payload - Page view builder payload.
153
+ * @returns The evaluated {@link OptimizationData} for this page view if the device is online.
154
+ */
155
+ abstract page(payload: PageViewBuilderArgs): Promise<OptimizationData | undefined>;
156
+ /**
157
+ * Record a screen view.
158
+ *
159
+ * @param payload - Screen view builder payload.
160
+ * @returns The evaluated {@link OptimizationData} for this screen view if the device is online.
161
+ */
162
+ abstract screen(payload: ScreenViewBuilderArgs): Promise<OptimizationData | undefined>;
163
+ /**
164
+ * Record a custom track event.
165
+ *
166
+ * @param payload - Track builder payload.
167
+ * @returns The evaluated {@link OptimizationData} for this event if the device is online.
168
+ */
169
+ abstract track(payload: TrackBuilderArgs): Promise<OptimizationData | undefined>;
170
+ /**
171
+ * Record a "sticky" component view.
172
+ *
173
+ * @param payload - "Sticky" component view builder payload.
174
+ * @returns The evaluated {@link OptimizationData} for this component view if the device is online.
175
+ * @remarks
176
+ * This method is intended to be called only when a component is considered
177
+ * "sticky".
178
+ * @privateRemarks
179
+ * Duplication prevention should be handled in Stateful implementations.
180
+ */
181
+ abstract trackComponentView(payload: ComponentViewBuilderArgs, duplicationScope?: string): Promise<OptimizationData | undefined>;
182
+ }
183
+ export default PersonalizationBase;
184
+ //# sourceMappingURL=PersonalizationBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersonalizationBase.d.ts","sourceRoot":"","sources":["../../src/personalization/PersonalizationBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,IAAI,EACJ,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,OAAO,EACP,qBAAqB,EACrB,4BAA4B,EAC5B,gBAAgB,EACjB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACtF,OAAO,WAAW,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,aAAa,CAAA;AAEpB;;;;;;;GAOG;AACH,UAAU,eAAe;IACvB;;;;;;;;SAQK;IACL,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IAE5D;;;;;;;;;;;;;OAaG;IACH,gBAAgB,EAAE,CAAC,CAAC,SAAS,iBAAiB,EAAE,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,UAAU,EAC5F,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrB,gBAAgB,CAAC,EAAE,4BAA4B,KAC5C,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAE1B;;;;;;;;;OASG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAA;CACzF;AAED;;;;;;;;GAQG;AACH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EAAE,wBAAwB,EACjC,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;CACzC;AAED,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,76 @@
1
+ import ProductBase from '../ProductBase';
2
+ import { FlagsResolver, MergeTagValueResolver, PersonalizedEntryResolver, } from './resolvers';
3
+ /**
4
+ * Internal base for personalization products.
5
+ *
6
+ * @internal
7
+ * @remarks
8
+ * Concrete implementations should extend this class to expose public methods for
9
+ * identify, page, and track events. This base wires in shared singleton
10
+ * resolvers used to fetch/resolve personalized data.
11
+ */
12
+ class PersonalizationBase extends ProductBase {
13
+ /**
14
+ * Static {@link FlagsResolver | resolver} for evaluating personalized
15
+ * custom flags.
16
+ */
17
+ flagsResolver = FlagsResolver;
18
+ /**
19
+ * Static {@link MergeTagValueResolver | resolver} that returns values
20
+ * sourced from a user profile based on a Contentful Merge Tag entry.
21
+ */
22
+ mergeTagValueResolver = MergeTagValueResolver;
23
+ /**
24
+ * Static {@link PersonalizedEntryResolver | resolver } for personalized
25
+ * Contentful entries (e.g., entry variants targeted to a profile audience).
26
+ *
27
+ * @remarks
28
+ * Used by higher-level personalization flows to materialize entry content
29
+ * prior to event emission.
30
+ */
31
+ personalizedEntryResolver = PersonalizedEntryResolver;
32
+ /**
33
+ * Get the specified Custom Flag's value from the supplied changes.
34
+ * @param name - The name/key of the Custom Flag.
35
+ * @param changes - Optional changes array.
36
+ * @returns The current value of the Custom Flag if found.
37
+ * @remarks
38
+ * The changes array can be sourced from the data returned when emitting any
39
+ * personalization event.
40
+ * */
41
+ getCustomFlag(name, changes) {
42
+ return FlagsResolver.resolve(changes)[name];
43
+ }
44
+ /**
45
+ * Resolve a Contentful entry to a personalized variant using the current
46
+ * or provided selected personalizations.
47
+ *
48
+ * @typeParam S - Entry skeleton type.
49
+ * @typeParam M - Chain modifiers.
50
+ * @typeParam L - Locale code.
51
+ * @param entry - The entry to personalize.
52
+ * @param personalizations - Optional selected personalizations.
53
+ * @returns The resolved entry data.
54
+ * @remarks
55
+ * Selected personalizations can be sourced from the data returned when emitting any
56
+ * personalization event.
57
+ */
58
+ personalizeEntry(entry, personalizations) {
59
+ return PersonalizedEntryResolver.resolve(entry, personalizations);
60
+ }
61
+ /**
62
+ * Resolve a merge tag to a value based on the current (or provided) profile.
63
+ *
64
+ * @param embeddedEntryNodeTarget - The merge tag entry node to resolve.
65
+ * @param profile - Optional profile.
66
+ * @returns The resolved value (type depends on the tag).
67
+ * @remarks
68
+ * Merge tags are references to profile data that can be substituted into content. The
69
+ * profile can be sourced from the data returned when emitting any personalization event.
70
+ */
71
+ getMergeTagValue(embeddedEntryNodeTarget, profile) {
72
+ return MergeTagValueResolver.resolve(embeddedEntryNodeTarget, profile);
73
+ }
74
+ }
75
+ export default PersonalizationBase;
76
+ //# sourceMappingURL=PersonalizationBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersonalizationBase.js","sourceRoot":"","sources":["../../src/personalization/PersonalizationBase.ts"],"names":[],"mappings":"AAcA,OAAO,WAAW,MAAM,gBAAgB,CAAA;AACxC,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,yBAAyB,GAE1B,MAAM,aAAa,CAAA;AAsDpB;;;;;;;;GAQG;AACH,MAAe,mBAAoB,SAAQ,WAAW;IACpD;;;OAGG;IACM,aAAa,GAAG,aAAa,CAAA;IAEtC;;;OAGG;IACM,qBAAqB,GAAG,qBAAqB,CAAA;IAEtD;;;;;;;OAOG;IACM,yBAAyB,GAAG,yBAAyB,CAAA;IAE9D;;;;;;;;SAQK;IACL,aAAa,CAAC,IAAY,EAAE,OAAqB;QAC/C,OAAO,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAId,KAAqB,EAAE,gBAA+C;QACtE,OAAO,yBAAyB,CAAC,OAAO,CAAU,KAAK,EAAE,gBAAgB,CAAC,CAAA;IAC5E,CAAC;IAED;;;;;;;;;OASG;IACH,gBAAgB,CAAC,uBAAsC,EAAE,OAAiB;QACxE,OAAO,qBAAqB,CAAC,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAA;IACxE,CAAC;CAiDF;AAED,eAAe,mBAAmB,CAAA"}
@@ -0,0 +1,226 @@
1
+ import { type InsightsEvent as AnalyticsEvent, type ChangeArray, type ComponentViewBuilderArgs, type Flags, type IdentifyBuilderArgs, type Json, type MergeTagEntry, type OptimizationData, type PageViewBuilderArgs, ExperienceEvent as PersonalizationEvent, type Profile, type ScreenViewBuilderArgs, type SelectedPersonalizationArray, type TrackBuilderArgs } from '@contentful/optimization-api-client';
2
+ import type { ChainModifiers, Entry, EntrySkeletonType, LocaleCode } from 'contentful';
3
+ import type { ConsentGuard } from '../Consent';
4
+ import type { ProductBaseOptions, ProductConfig } from '../ProductBase';
5
+ import { type Observable } from '../signals';
6
+ import PersonalizationBase from './PersonalizationBase';
7
+ import type { ResolvedData } from './resolvers';
8
+ /**
9
+ * Default state values for {@link PersonalizationStateful} applied at construction time.
10
+ *
11
+ * @public
12
+ */
13
+ export interface PersonalizationProductConfigDefaults {
14
+ /** Whether personalization is allowed by default. */
15
+ consent?: boolean;
16
+ /** Initial diff of changes produced by the service. */
17
+ changes?: ChangeArray;
18
+ /** Default active profile used for personalization. */
19
+ profile?: Profile;
20
+ /** Preselected personalization variants (e.g., winning treatments). */
21
+ personalizations?: SelectedPersonalizationArray;
22
+ }
23
+ /**
24
+ * Configuration for {@link PersonalizationStateful}.
25
+ *
26
+ * @public
27
+ */
28
+ export interface PersonalizationProductConfig extends ProductConfig {
29
+ /** Default signal values applied during initialization. */
30
+ defaults?: PersonalizationProductConfigDefaults;
31
+ /**
32
+ * Function used to obtain an anonymous user identifier.
33
+ *
34
+ * @remarks
35
+ * If a `getAnonymousId` function has been provided, the returned value will
36
+ * take precedence over the `id` property of the current {@link Profile}
37
+ * signal value
38
+ *
39
+ * @returns A string identifier, or `undefined` if no anonymous ID is available.
40
+ */
41
+ getAnonymousId?: () => string | undefined;
42
+ }
43
+ /**
44
+ * Observables exposed by {@link PersonalizationStateful} that mirror internal signals.
45
+ *
46
+ * @public
47
+ */
48
+ export interface PersonalizationStates {
49
+ /** Observable stream of the latest {@link AnalyticsEvent} or {@link PersonalizationEvent} (or `undefined`). */
50
+ eventStream: Observable<AnalyticsEvent | PersonalizationEvent | undefined>;
51
+ /** Live view of effective flags for the current profile (if available). */
52
+ flags: Observable<Flags | undefined>;
53
+ /** Live view of the current profile. */
54
+ profile: Observable<Profile | undefined>;
55
+ /** Live view of selected personalizations (variants). */
56
+ personalizations: Observable<SelectedPersonalizationArray | undefined>;
57
+ }
58
+ /**
59
+ * Options for configuring {@link PersonalizationStateful} functionality.
60
+ *
61
+ * @public
62
+ * @see {@link ProductBaseOptions}
63
+ */
64
+ export type PersonalizationStatefulOptions = ProductBaseOptions & {
65
+ /** Configuration specific to the Personalization product */
66
+ config?: PersonalizationProductConfig;
67
+ };
68
+ /**
69
+ * Stateful personalization product that manages consent, profile, flags, and
70
+ * selected variants while emitting Experience events and updating state.
71
+ *
72
+ * @public
73
+ * @remarks
74
+ * The class maintains reactive signals and exposes read‑only observables via
75
+ * {@link PersonalizationStateful.states}. Events are validated via schema parsers and
76
+ * run through interceptors before being submitted. Resulting state is merged
77
+ * back into signals.
78
+ */
79
+ declare class PersonalizationStateful extends PersonalizationBase implements ConsentGuard {
80
+ /** In‑memory queue for offline events keyed by profile. */
81
+ private readonly offlineQueue;
82
+ /** Exposed observable state references. */
83
+ readonly states: PersonalizationStates;
84
+ /**
85
+ * Function that provides an anonymous ID when available.
86
+ *
87
+ * @internal
88
+ */
89
+ getAnonymousId: () => string | undefined;
90
+ /**
91
+ * Create a new stateful personalization instance.
92
+ *
93
+ * @param options - Options to configure the personalization product for stateful environments.
94
+ */
95
+ constructor(options: PersonalizationStatefulOptions);
96
+ /**
97
+ * Reset stateful signals managed by this product.
98
+ *
99
+ * @remarks
100
+ * Clears `changes`, `profile`, and selected `personalizations`.
101
+ */
102
+ reset(): void;
103
+ /**
104
+ * Get the specified Custom Flag's value (derived from the signal).
105
+ * @param name - The name or key of the Custom Flag.
106
+ * @returns The current value of the Custom Flag if found.
107
+ * */
108
+ getCustomFlag(name: string, changes?: ChangeArray | undefined): Json;
109
+ /**
110
+ * Resolve a Contentful entry to a personalized variant using the current
111
+ * or provided selections.
112
+ *
113
+ * @typeParam S - Entry skeleton type.
114
+ * @typeParam M - Chain modifiers.
115
+ * @typeParam L - Locale code.
116
+ * @param entry - The entry to personalize.
117
+ * @param personalizations - Optional selections; defaults to the current signal value.
118
+ * @returns The resolved entry data.
119
+ */
120
+ personalizeEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray | undefined): ResolvedData<S, M, L>;
121
+ /**
122
+ * Resolve a merge tag to a value based on the current (or provided) profile.
123
+ *
124
+ * @param embeddedEntryNodeTarget - The merge‑tag entry node to resolve.
125
+ * @param profile - Optional profile; defaults to the current signal value.
126
+ * @returns The resolved value (type depends on the tag).
127
+ * @remarks
128
+ * Merge tags are references to profile data that can be substituted into content.
129
+ */
130
+ getMergeTagValue(embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile | undefined): unknown;
131
+ /**
132
+ * Determine whether the named operation is permitted based on consent and
133
+ * allowed event type configuration.
134
+ *
135
+ * @param name - Method name; `trackComponentView` is normalized to
136
+ * `'component'` for allow‑list checks.
137
+ * @returns `true` if the operation is permitted; otherwise `false`.
138
+ */
139
+ hasConsent(name: string): boolean;
140
+ /**
141
+ * Hook invoked when an operation is blocked due to missing consent.
142
+ *
143
+ * @param name - The blocked operation name.
144
+ * @param payload - The original arguments supplied to the operation.
145
+ */
146
+ onBlockedByConsent(name: string, payload: unknown[]): void;
147
+ /**
148
+ * Guard used to suppress duplicate component view events for the same
149
+ * component based on a duplication key and the component identifier.
150
+ *
151
+ * @param _name - Operation name (unused).
152
+ * @param payload - Tuple `[builderArgs, duplicationScope]`.
153
+ * @returns `true` if the event is NOT a duplicate and should proceed.
154
+ */
155
+ isNotDuplicated(_name: string, payload: [ComponentViewBuilderArgs, string]): boolean;
156
+ /**
157
+ * Hook invoked when an operation is blocked by the duplication guard.
158
+ *
159
+ * @param _name - The blocked operation name (unused).
160
+ * @param payload - The original arguments supplied to the operation.
161
+ */
162
+ onBlockedByDuplication(_name: string, payload: unknown[]): void;
163
+ /**
164
+ * Identify the current profile/visitor to associate traits with a profile
165
+ * and update optimization state.
166
+ *
167
+ * @param payload - Identify builder payload.
168
+ * @returns The resulting {@link OptimizationData} for the identified user.
169
+ */
170
+ identify(payload: IdentifyBuilderArgs): Promise<OptimizationData | undefined>;
171
+ /**
172
+ * Record a page view and update optimization state.
173
+ *
174
+ * @param payload - Page view builder payload.
175
+ * @returns The evaluated {@link OptimizationData} for this page view.
176
+ */
177
+ page(payload: PageViewBuilderArgs): Promise<OptimizationData | undefined>;
178
+ /**
179
+ * Record a screen view and update optimization state.
180
+ *
181
+ * @param payload - Screen view builder payload.
182
+ * @returns The evaluated {@link OptimizationData} for this screen view.
183
+ */
184
+ screen(payload: ScreenViewBuilderArgs): Promise<OptimizationData | undefined>;
185
+ /**
186
+ * Record a custom track event and update optimization state.
187
+ *
188
+ * @param payload - Track builder payload.
189
+ * @returns The evaluated {@link OptimizationData} for this event.
190
+ */
191
+ track(payload: TrackBuilderArgs): Promise<OptimizationData | undefined>;
192
+ trackComponentView(payload: ComponentViewBuilderArgs, _duplicationScope?: string): Promise<OptimizationData | undefined>;
193
+ /**
194
+ * Intercept, validate, and place an event into the offline eventd queue; then
195
+ * trigger a size‑based flush if necessary.
196
+ *
197
+ * @param event - The event to enqueue.
198
+ */
199
+ private sendOrEnqueueEvent;
200
+ /**
201
+ * Flush the offline queue
202
+ */
203
+ flush(): Promise<void>;
204
+ /**
205
+ * Submit events to the Experience API, updating output signals with the
206
+ * returned state.
207
+ *
208
+ * @param events - The events to submit.
209
+ * @returns The {@link OptimizationData} returned by the service.
210
+ * @internal
211
+ * @privateRemarks
212
+ * If a `getAnonymousId` function has been provided, the returned value will
213
+ * take precedence over the `id` property of the current {@link Profile}
214
+ * signal value
215
+ */
216
+ private upsertProfile;
217
+ /**
218
+ * Apply returned optimization state to local signals after interceptor processing.
219
+ *
220
+ * @param data - Optimization state returned by the service.
221
+ * @internal
222
+ */
223
+ private updateOutputSignals;
224
+ }
225
+ export default PersonalizationStateful;
226
+ //# sourceMappingURL=PersonalizationStateful.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersonalizationStateful.d.ts","sourceRoot":"","sources":["../../src/personalization/PersonalizationStateful.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,IAAI,cAAc,EACpC,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,eAAe,IAAI,oBAAoB,EAEvC,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,gBAAgB,EACtB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAOL,KAAK,UAAU,EAKhB,MAAM,YAAY,CAAA;AACnB,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C;;;;GAIG;AACH,MAAM,WAAW,oCAAoC;IACnD,qDAAqD;IACrD,O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