@contentful/optimization-core 0.1.0-alpha → 0.1.0-alpha10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +221 -31
- package/dist/260.mjs +14 -0
- package/dist/260.mjs.map +1 -0
- package/dist/499.mjs +4 -0
- package/dist/632.mjs +5 -0
- package/dist/632.mjs.map +1 -0
- package/dist/808.mjs +2 -0
- package/dist/942.mjs +2 -0
- package/dist/api-client.cjs +60 -0
- package/dist/api-client.cjs.map +1 -0
- package/dist/api-client.d.cts +4 -0
- package/dist/api-client.d.mts +4 -0
- package/dist/api-client.d.ts +4 -0
- package/dist/api-client.mjs +2 -0
- package/dist/api-schemas.cjs +60 -0
- package/dist/api-schemas.cjs.map +1 -0
- package/dist/api-schemas.d.cts +4 -0
- package/dist/api-schemas.d.mts +4 -0
- package/dist/api-schemas.d.ts +4 -0
- package/dist/api-schemas.mjs +2 -0
- package/dist/constants.cjs +78 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +88 -0
- package/dist/constants.d.mts +88 -0
- package/dist/constants.d.ts +88 -0
- package/dist/constants.mjs +1 -0
- package/dist/index.cjs +1853 -1665
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2432 -0
- package/dist/index.d.mts +2432 -0
- package/dist/index.d.ts +2432 -15
- package/dist/index.mjs +625 -327
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +67 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +8 -0
- package/dist/logger.d.mts +8 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.mjs +2 -0
- package/dist/symbols.cjs +42 -0
- package/dist/symbols.cjs.map +1 -0
- package/dist/symbols.d.cts +10 -0
- package/dist/symbols.d.mts +10 -0
- package/dist/symbols.d.ts +10 -0
- package/dist/symbols.mjs +1 -0
- package/package.json +65 -12
- package/dist/Consent.d.ts +0 -44
- package/dist/Consent.d.ts.map +0 -1
- package/dist/Consent.js +0 -2
- package/dist/Consent.js.map +0 -1
- package/dist/CoreBase.d.ts +0 -161
- package/dist/CoreBase.d.ts.map +0 -1
- package/dist/CoreBase.js +0 -151
- package/dist/CoreBase.js.map +0 -1
- package/dist/CoreStateful.d.ts +0 -142
- package/dist/CoreStateful.d.ts.map +0 -1
- package/dist/CoreStateful.js +0 -137
- package/dist/CoreStateful.js.map +0 -1
- package/dist/CoreStateless.d.ts +0 -53
- package/dist/CoreStateless.d.ts.map +0 -1
- package/dist/CoreStateless.js +0 -43
- package/dist/CoreStateless.js.map +0 -1
- package/dist/ProductBase.d.ts +0 -83
- package/dist/ProductBase.d.ts.map +0 -1
- package/dist/ProductBase.js +0 -50
- package/dist/ProductBase.js.map +0 -1
- package/dist/analytics/AnalyticsBase.d.ts +0 -35
- package/dist/analytics/AnalyticsBase.d.ts.map +0 -1
- package/dist/analytics/AnalyticsBase.js +0 -13
- package/dist/analytics/AnalyticsBase.js.map +0 -1
- package/dist/analytics/AnalyticsStateful.d.ts +0 -138
- package/dist/analytics/AnalyticsStateful.d.ts.map +0 -1
- package/dist/analytics/AnalyticsStateful.js +0 -179
- package/dist/analytics/AnalyticsStateful.js.map +0 -1
- package/dist/analytics/AnalyticsStateless.d.ts +0 -48
- package/dist/analytics/AnalyticsStateless.d.ts.map +0 -1
- package/dist/analytics/AnalyticsStateless.js +0 -61
- package/dist/analytics/AnalyticsStateless.js.map +0 -1
- package/dist/analytics/index.d.ts +0 -5
- package/dist/analytics/index.d.ts.map +0 -1
- package/dist/analytics/index.js +0 -5
- package/dist/analytics/index.js.map +0 -1
- package/dist/global-constants.d.ts +0 -18
- package/dist/global-constants.d.ts.map +0 -1
- package/dist/global-constants.js +0 -18
- package/dist/global-constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/lib/decorators/guardedBy.d.ts +0 -113
- package/dist/lib/decorators/guardedBy.d.ts.map +0 -1
- package/dist/lib/decorators/guardedBy.js +0 -143
- package/dist/lib/decorators/guardedBy.js.map +0 -1
- package/dist/lib/decorators/index.d.ts +0 -2
- package/dist/lib/decorators/index.d.ts.map +0 -1
- package/dist/lib/decorators/index.js +0 -2
- package/dist/lib/decorators/index.js.map +0 -1
- package/dist/lib/interceptor/InterceptorManager.d.ts +0 -127
- package/dist/lib/interceptor/InterceptorManager.d.ts.map +0 -1
- package/dist/lib/interceptor/InterceptorManager.js +0 -125
- package/dist/lib/interceptor/InterceptorManager.js.map +0 -1
- package/dist/lib/interceptor/index.d.ts +0 -2
- package/dist/lib/interceptor/index.d.ts.map +0 -1
- package/dist/lib/interceptor/index.js +0 -2
- package/dist/lib/interceptor/index.js.map +0 -1
- package/dist/lib/value-presence/ValuePresence.d.ts +0 -123
- package/dist/lib/value-presence/ValuePresence.d.ts.map +0 -1
- package/dist/lib/value-presence/ValuePresence.js +0 -141
- package/dist/lib/value-presence/ValuePresence.js.map +0 -1
- package/dist/lib/value-presence/index.d.ts +0 -2
- package/dist/lib/value-presence/index.d.ts.map +0 -1
- package/dist/lib/value-presence/index.js +0 -2
- package/dist/lib/value-presence/index.js.map +0 -1
- package/dist/personalization/PersonalizationBase.d.ts +0 -184
- package/dist/personalization/PersonalizationBase.d.ts.map +0 -1
- package/dist/personalization/PersonalizationBase.js +0 -76
- package/dist/personalization/PersonalizationBase.js.map +0 -1
- package/dist/personalization/PersonalizationStateful.d.ts +0 -226
- package/dist/personalization/PersonalizationStateful.d.ts.map +0 -1
- package/dist/personalization/PersonalizationStateful.js +0 -297
- package/dist/personalization/PersonalizationStateful.js.map +0 -1
- package/dist/personalization/PersonalizationStateless.d.ts +0 -74
- package/dist/personalization/PersonalizationStateless.d.ts.map +0 -1
- package/dist/personalization/PersonalizationStateless.js +0 -98
- package/dist/personalization/PersonalizationStateless.js.map +0 -1
- package/dist/personalization/index.d.ts +0 -6
- package/dist/personalization/index.d.ts.map +0 -1
- package/dist/personalization/index.js +0 -6
- package/dist/personalization/index.js.map +0 -1
- package/dist/personalization/resolvers/FlagsResolver.d.ts +0 -35
- package/dist/personalization/resolvers/FlagsResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/FlagsResolver.js +0 -47
- package/dist/personalization/resolvers/FlagsResolver.js.map +0 -1
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +0 -74
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/MergeTagValueResolver.js +0 -109
- package/dist/personalization/resolvers/MergeTagValueResolver.js.map +0 -1
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +0 -142
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js +0 -196
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +0 -1
- package/dist/personalization/resolvers/index.d.ts +0 -7
- package/dist/personalization/resolvers/index.d.ts.map +0 -1
- package/dist/personalization/resolvers/index.js +0 -7
- package/dist/personalization/resolvers/index.js.map +0 -1
- package/dist/signals.d.ts +0 -35
- package/dist/signals.d.ts.map +0 -1
- package/dist/signals.js +0 -30
- package/dist/signals.js.map +0 -1
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { InsightsEvent as AnalyticsEvent, type ComponentViewBuilderArgs, type ExperienceEvent as PersonalizationEvent, type Profile } from '@contentful/optimization-api-client';
|
|
2
|
-
import type { ConsentGuard } from '../Consent';
|
|
3
|
-
import type { ProductBaseOptions, ProductConfig } from '../ProductBase';
|
|
4
|
-
import { type Observable } from '../signals';
|
|
5
|
-
import AnalyticsBase from './AnalyticsBase';
|
|
6
|
-
/**
|
|
7
|
-
* Default analytics state values applied at construction time.
|
|
8
|
-
*
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export interface AnalyticsProductConfigDefaults {
|
|
12
|
-
/** Whether analytics collection is allowed by default. */
|
|
13
|
-
consent?: boolean;
|
|
14
|
-
/** Default profile to associate with events. */
|
|
15
|
-
profile?: Profile;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Configuration for the stateful analytics implementation.
|
|
19
|
-
*
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
export interface AnalyticsProductConfig extends ProductConfig {
|
|
23
|
-
/**
|
|
24
|
-
* Default signal values applied on initialization.
|
|
25
|
-
*/
|
|
26
|
-
defaults?: AnalyticsProductConfigDefaults;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Observables exposed by the stateful analytics product.
|
|
30
|
-
*
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export interface AnalyticsStates {
|
|
34
|
-
/** Observable stream of the latest {@link AnalyticsEvent} or {@link PersonalizationEvent} (or `undefined`). */
|
|
35
|
-
eventStream: Observable<AnalyticsEvent | PersonalizationEvent | undefined>;
|
|
36
|
-
/** Observable stream of the active {@link Profile} (or `undefined`). */
|
|
37
|
-
profile: Observable<Profile | undefined>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Options for configuring {@link AnalyticsStateful} functionality.
|
|
41
|
-
*
|
|
42
|
-
* @public
|
|
43
|
-
* @see {@link ProductBaseOptions}
|
|
44
|
-
*/
|
|
45
|
-
export type AnalyticsStatefulOptions = ProductBaseOptions & {
|
|
46
|
-
/** Configuration specific to the Analytics product */
|
|
47
|
-
config?: AnalyticsProductConfig;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Analytics implementation that maintains local state (consent, profile) and
|
|
51
|
-
* queues events until flushed or the queue reaches a maximum size.
|
|
52
|
-
*
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
declare class AnalyticsStateful extends AnalyticsBase implements ConsentGuard {
|
|
56
|
-
/** In‑memory queue keyed by profile. */
|
|
57
|
-
private readonly queue;
|
|
58
|
-
/** Exposed observable state references. */
|
|
59
|
-
readonly states: AnalyticsStates;
|
|
60
|
-
/**
|
|
61
|
-
* Create a new stateful analytics instance.
|
|
62
|
-
*
|
|
63
|
-
* @param options - Options to configure the analytics product for stateful environments.
|
|
64
|
-
*/
|
|
65
|
-
constructor(options: AnalyticsStatefulOptions);
|
|
66
|
-
/**
|
|
67
|
-
* Reset analytics‑related signals and the last emitted event.
|
|
68
|
-
*/
|
|
69
|
-
reset(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Determine whether the named operation is permitted based on consent and
|
|
72
|
-
* allowed event type configuration.
|
|
73
|
-
*
|
|
74
|
-
* @param name - The method name; `'trackComponentView'` is normalized
|
|
75
|
-
* to `'component'` for allow‑list checks.
|
|
76
|
-
* @returns `true` if the operation is permitted; otherwise `false`.
|
|
77
|
-
*/
|
|
78
|
-
hasConsent(name: string): boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Hook invoked when an operation is blocked due to missing consent.
|
|
81
|
-
*
|
|
82
|
-
* @param name - The blocked operation name.
|
|
83
|
-
* @param payload - The original arguments supplied to the operation.
|
|
84
|
-
*/
|
|
85
|
-
onBlockedByConsent(name: string, payload: unknown[]): void;
|
|
86
|
-
/**
|
|
87
|
-
* Guard used to suppress duplicate component/flag view events based on a
|
|
88
|
-
* duplication key and the component identifier.
|
|
89
|
-
*
|
|
90
|
-
* @param _name - The operation name (unused).
|
|
91
|
-
* @param payload - Tuple of [builderArgs, duplicationScope].
|
|
92
|
-
* @returns `true` if the event is NOT a duplicate and should proceed.
|
|
93
|
-
*/
|
|
94
|
-
isNotDuplicated(_name: string, payload: [ComponentViewBuilderArgs, string]): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Hook invoked when an operation is blocked by the duplication guard.
|
|
97
|
-
*
|
|
98
|
-
* @param name - The blocked operation name.
|
|
99
|
-
* @param payload - The original arguments supplied to the operation.
|
|
100
|
-
*/
|
|
101
|
-
onBlockedByDuplication(name: string, payload: unknown[]): void;
|
|
102
|
-
/**
|
|
103
|
-
* Queue a component view event for the active profile.
|
|
104
|
-
*
|
|
105
|
-
* @param payload - Component view builder arguments.
|
|
106
|
-
* @param _duplicationScope - Optional string used to scope duplication (used
|
|
107
|
-
* by guards); an empty string `''` is converted to the `undefined` scope
|
|
108
|
-
*/
|
|
109
|
-
trackComponentView(payload: ComponentViewBuilderArgs, _duplicationScope?: string): Promise<void>;
|
|
110
|
-
/**
|
|
111
|
-
* Queue a flag view event for the active profile.
|
|
112
|
-
*
|
|
113
|
-
* @param payload - Flag view builder arguments.
|
|
114
|
-
* @param _duplicationScope - Optional string used to scope duplication (used
|
|
115
|
-
* by guards); an empty string `''` is converted to the `undefined` scope
|
|
116
|
-
*/
|
|
117
|
-
trackFlagView(payload: ComponentViewBuilderArgs, _duplicationScope?: string): Promise<void>;
|
|
118
|
-
/**
|
|
119
|
-
* Intercept, validate, and place an event into the profile‑scoped queue; then
|
|
120
|
-
* trigger a size‑based flush if necessary.
|
|
121
|
-
*
|
|
122
|
-
* @param event - The event to enqueue.
|
|
123
|
-
*/
|
|
124
|
-
private enqueueEvent;
|
|
125
|
-
/**
|
|
126
|
-
* Flush the queue automatically when the total number of queued events
|
|
127
|
-
* reaches {@link MAX_QUEUED_EVENTS}.
|
|
128
|
-
*/
|
|
129
|
-
private flushMaxEvents;
|
|
130
|
-
/**
|
|
131
|
-
* Send all queued events grouped by profile and clear the queue.
|
|
132
|
-
* @remarks Only under rare circumstances should there be more than one
|
|
133
|
-
* profile in a stateful application.
|
|
134
|
-
*/
|
|
135
|
-
flush(): Promise<void>;
|
|
136
|
-
}
|
|
137
|
-
export default AnalyticsStateful;
|
|
138
|
-
//# sourceMappingURL=AnalyticsStateful.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsStateful.d.ts","sourceRoot":"","sources":["../../src/analytics/AnalyticsStateful.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,IAAI,cAAc,EAE/B,KAAK,wBAAwB,EAE7B,KAAK,eAAe,IAAI,oBAAoB,EAC5C,KAAK,OAAO,EACb,MAAM,qCAAqC,CAAA;AAE5C,OAAO,KA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AM1D;;;;;;;OAOG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,wBAAwB,EAAE,MAAM,CAAC,GAAG,OAAO;IAUpF;;;;;OAKG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IAQ9D;;;;;;OAMG;IAGG,kBAAkB,CACtB,OAAO,EAAE,wBAAwB,EACjC,iBAAiB,SAAK,GACrB,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;;;OAMG;IAGG,aAAa,CAAC,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,SAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7F;;;;;OAKG;YACW,YAAY;IA4B1B;;;OAGG;YACW,cAAc;IAI5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAa7B;AAED,eAAe,iBAAiB,CAAA"}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { InsightsEvent as AnalyticsEvent, } from '@contentful/optimization-api-client';
|
|
2
|
-
import { createScopedLogger } from 'logger';
|
|
3
|
-
import { guardedBy } from '../lib/decorators';
|
|
4
|
-
import { batch, consent, effect, event as eventSignal, online as onlineSignal, profile as profileSignal, toObservable, } from '../signals';
|
|
5
|
-
import AnalyticsBase from './AnalyticsBase';
|
|
6
|
-
const logger = createScopedLogger('Analytics');
|
|
7
|
-
/**
|
|
8
|
-
* Maximum number of queued events before an automatic flush is triggered.
|
|
9
|
-
*/
|
|
10
|
-
const MAX_QUEUED_EVENTS = 25;
|
|
11
|
-
/**
|
|
12
|
-
* Analytics implementation that maintains local state (consent, profile) and
|
|
13
|
-
* queues events until flushed or the queue reaches a maximum size.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
class AnalyticsStateful extends AnalyticsBase {
|
|
18
|
-
/** In‑memory queue keyed by profile. */
|
|
19
|
-
queue = new Map();
|
|
20
|
-
/** Exposed observable state references. */
|
|
21
|
-
states = {
|
|
22
|
-
eventStream: toObservable(eventSignal),
|
|
23
|
-
profile: toObservable(profileSignal),
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Create a new stateful analytics instance.
|
|
27
|
-
*
|
|
28
|
-
* @param options - Options to configure the analytics product for stateful environments.
|
|
29
|
-
*/
|
|
30
|
-
constructor(options) {
|
|
31
|
-
const { api, builder, config, interceptors } = options;
|
|
32
|
-
super({ api, builder, config, interceptors });
|
|
33
|
-
const { defaults } = config ?? {};
|
|
34
|
-
if (defaults?.profile !== undefined) {
|
|
35
|
-
const { profile: defaultProfile } = defaults;
|
|
36
|
-
profileSignal.value = defaultProfile;
|
|
37
|
-
}
|
|
38
|
-
effect(() => {
|
|
39
|
-
const id = profileSignal.value?.id;
|
|
40
|
-
logger.info(`Analytics ${consent.value ? 'will' : 'will not'} be collected due to consent (${consent.value})`);
|
|
41
|
-
logger.debug(`Profile ${id && `with ID ${id}`} has been ${id ? 'set' : 'cleared'}`);
|
|
42
|
-
});
|
|
43
|
-
effect(() => {
|
|
44
|
-
if (onlineSignal.value)
|
|
45
|
-
void this.flush();
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Reset analytics‑related signals and the last emitted event.
|
|
50
|
-
*/
|
|
51
|
-
reset() {
|
|
52
|
-
batch(() => {
|
|
53
|
-
eventSignal.value = undefined;
|
|
54
|
-
profileSignal.value = undefined;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Determine whether the named operation is permitted based on consent and
|
|
59
|
-
* allowed event type configuration.
|
|
60
|
-
*
|
|
61
|
-
* @param name - The method name; `'trackComponentView'` is normalized
|
|
62
|
-
* to `'component'` for allow‑list checks.
|
|
63
|
-
* @returns `true` if the operation is permitted; otherwise `false`.
|
|
64
|
-
*/
|
|
65
|
-
hasConsent(name) {
|
|
66
|
-
return (!!consent.value ||
|
|
67
|
-
(this.allowedEventTypes ?? []).includes(name === 'trackComponentView' || name === 'trackFlagView' ? 'component' : name));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Hook invoked when an operation is blocked due to missing consent.
|
|
71
|
-
*
|
|
72
|
-
* @param name - The blocked operation name.
|
|
73
|
-
* @param payload - The original arguments supplied to the operation.
|
|
74
|
-
*/
|
|
75
|
-
onBlockedByConsent(name, payload) {
|
|
76
|
-
logger.warn(`Event "${name}" was blocked due to lack of consent; payload: ${JSON.stringify(payload)}`);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Guard used to suppress duplicate component/flag view events based on a
|
|
80
|
-
* duplication key and the component identifier.
|
|
81
|
-
*
|
|
82
|
-
* @param _name - The operation name (unused).
|
|
83
|
-
* @param payload - Tuple of [builderArgs, duplicationScope].
|
|
84
|
-
* @returns `true` if the event is NOT a duplicate and should proceed.
|
|
85
|
-
*/
|
|
86
|
-
isNotDuplicated(_name, payload) {
|
|
87
|
-
const [{ componentId: value }, duplicationScope] = payload;
|
|
88
|
-
const isDuplicated = this.duplicationDetector.isPresent(duplicationScope, value);
|
|
89
|
-
if (!isDuplicated)
|
|
90
|
-
this.duplicationDetector.addValue(duplicationScope, value);
|
|
91
|
-
return !isDuplicated;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Hook invoked when an operation is blocked by the duplication guard.
|
|
95
|
-
*
|
|
96
|
-
* @param name - The blocked operation name.
|
|
97
|
-
* @param payload - The original arguments supplied to the operation.
|
|
98
|
-
*/
|
|
99
|
-
onBlockedByDuplication(name, payload) {
|
|
100
|
-
const componentType = name === 'trackFlagView' ? 'flag' : 'component';
|
|
101
|
-
logger.debug(`Duplicate "${componentType} view" event detected, skipping; payload: ${JSON.stringify(payload)}`);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Queue a component view event for the active profile.
|
|
105
|
-
*
|
|
106
|
-
* @param payload - Component view builder arguments.
|
|
107
|
-
* @param _duplicationScope - Optional string used to scope duplication (used
|
|
108
|
-
* by guards); an empty string `''` is converted to the `undefined` scope
|
|
109
|
-
*/
|
|
110
|
-
@guardedBy('isNotDuplicated', { onBlocked: 'onBlockedByDuplication' })
|
|
111
|
-
@guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
|
|
112
|
-
async trackComponentView(payload, _duplicationScope = '') {
|
|
113
|
-
logger.info(`Processing "component view" event for ${payload.componentId}`);
|
|
114
|
-
await this.enqueueEvent(this.builder.buildComponentView(payload));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Queue a flag view event for the active profile.
|
|
118
|
-
*
|
|
119
|
-
* @param payload - Flag view builder arguments.
|
|
120
|
-
* @param _duplicationScope - Optional string used to scope duplication (used
|
|
121
|
-
* by guards); an empty string `''` is converted to the `undefined` scope
|
|
122
|
-
*/
|
|
123
|
-
@guardedBy('isNotDuplicated', { onBlocked: 'onBlockedByDuplication' })
|
|
124
|
-
@guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
|
|
125
|
-
async trackFlagView(payload, _duplicationScope = '') {
|
|
126
|
-
logger.debug(`Processing "flag view" event for ${payload.componentId}`);
|
|
127
|
-
await this.enqueueEvent(this.builder.buildFlagView(payload));
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Intercept, validate, and place an event into the profile‑scoped queue; then
|
|
131
|
-
* trigger a size‑based flush if necessary.
|
|
132
|
-
*
|
|
133
|
-
* @param event - The event to enqueue.
|
|
134
|
-
*/
|
|
135
|
-
async enqueueEvent(event) {
|
|
136
|
-
const { value: profile } = profileSignal;
|
|
137
|
-
if (!profile) {
|
|
138
|
-
logger.warn('Attempting to emit an event without an Optimization profile');
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const intercepted = await this.interceptors.event.run(event);
|
|
142
|
-
const validEvent = AnalyticsEvent.parse(intercepted);
|
|
143
|
-
logger.debug(`Queueing ${validEvent.type} event for profile ${profile.id}`, validEvent);
|
|
144
|
-
const profileEventQueue = this.queue.get(profile);
|
|
145
|
-
eventSignal.value = validEvent;
|
|
146
|
-
if (profileEventQueue) {
|
|
147
|
-
profileEventQueue.push(validEvent);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
this.queue.set(profile, [validEvent]);
|
|
151
|
-
}
|
|
152
|
-
await this.flushMaxEvents();
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Flush the queue automatically when the total number of queued events
|
|
156
|
-
* reaches {@link MAX_QUEUED_EVENTS}.
|
|
157
|
-
*/
|
|
158
|
-
async flushMaxEvents() {
|
|
159
|
-
if (this.queue.values().toArray().flat().length >= MAX_QUEUED_EVENTS)
|
|
160
|
-
await this.flush();
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Send all queued events grouped by profile and clear the queue.
|
|
164
|
-
* @remarks Only under rare circumstances should there be more than one
|
|
165
|
-
* profile in a stateful application.
|
|
166
|
-
*/
|
|
167
|
-
async flush() {
|
|
168
|
-
logger.debug('Flushing event queue');
|
|
169
|
-
const batches = [];
|
|
170
|
-
this.queue.forEach((events, profile) => batches.push({ profile, events }));
|
|
171
|
-
if (!batches.length)
|
|
172
|
-
return;
|
|
173
|
-
const sendSuccess = await this.api.insights.sendBatchEvents(batches);
|
|
174
|
-
if (sendSuccess)
|
|
175
|
-
this.queue.clear();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export default AnalyticsStateful;
|
|
179
|
-
//# sourceMappingURL=AnalyticsStateful.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsStateful.js","sourceRoot":"","sources":["../../src/analytics/AnalyticsStateful.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,IAAI,cAAc,GAMhC,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EACL,KA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EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;QAE1E,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAM;QAE3B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QAEpE,IAAI,WAAW;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACrC,CAAC;CACF;AAED,eAAe,iBAAiB,CAAA"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type ComponentViewBuilderArgs, type PartialProfile } from '@contentful/optimization-api-client';
|
|
2
|
-
import AnalyticsBase from './AnalyticsBase';
|
|
3
|
-
/**
|
|
4
|
-
* Arguments for tracking a component/flag view in stateless mode.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
* @remarks
|
|
8
|
-
* The `profile` is optional; when omitted, the APIs may infer identity via
|
|
9
|
-
* other means.
|
|
10
|
-
*/
|
|
11
|
-
export type TrackViewArgs = ComponentViewBuilderArgs & {
|
|
12
|
-
profile?: PartialProfile;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Stateless analytics implementation that sends each event immediately in a
|
|
16
|
-
* single‑event batch.
|
|
17
|
-
*
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
declare class AnalyticsStateless extends AnalyticsBase {
|
|
21
|
-
/**
|
|
22
|
-
* Build, intercept, validate, and send a component view event.
|
|
23
|
-
*
|
|
24
|
-
* @param args - {@link TrackViewArgs} used to build the event. Includes an
|
|
25
|
-
* optional partial profile.
|
|
26
|
-
* @returns A promise that resolves once the batch has been sent.
|
|
27
|
-
*/
|
|
28
|
-
trackComponentView(args: TrackViewArgs): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Build, intercept, validate, and send a flag view event.
|
|
31
|
-
*
|
|
32
|
-
* @param args - {@link TrackViewArgs} used to build the event. Includes an
|
|
33
|
-
* optional partial profile.
|
|
34
|
-
* @returns A promise that resolves once the batch has been sent.
|
|
35
|
-
*/
|
|
36
|
-
trackFlagView(args: TrackViewArgs): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Send a single {@link InsightsEvent} wrapped in a one‑item batch.
|
|
39
|
-
*
|
|
40
|
-
* @param event - The event to send.
|
|
41
|
-
* @param profile - Optional partial profile to attach to the batch.
|
|
42
|
-
* @returns A promise that resolves when the API call completes.
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
private sendBatchEvent;
|
|
46
|
-
}
|
|
47
|
-
export default AnalyticsStateless;
|
|
48
|
-
//# sourceMappingURL=AnalyticsStateless.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsStateless.d.ts","sourceRoot":"","sources":["../../src/analytics/AnalyticsStateless.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,wBAAwB,EAG7B,KAAK,cAAc,EACpB,MAAM,qCAAqC,CAAA;AAE5C,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAI3C;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,wBAAwB,GAAG;IAAE,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,CAAA;AAEnF;;;;;GAKG;AACH,cAAM,kBAAmB,SAAQ,aAAa;IAC5C;;;;;;OAMG;IACG,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5D;;;;;;OAMG;IACG,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAcvD;;;;;;;OAOG;YACW,cAAc;CAU7B;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { BatchInsightsEventArray, ComponentViewEvent, } from '@contentful/optimization-api-client';
|
|
2
|
-
import { createScopedLogger } from 'logger';
|
|
3
|
-
import AnalyticsBase from './AnalyticsBase';
|
|
4
|
-
const logger = createScopedLogger('Analytics');
|
|
5
|
-
/**
|
|
6
|
-
* Stateless analytics implementation that sends each event immediately in a
|
|
7
|
-
* single‑event batch.
|
|
8
|
-
*
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
class AnalyticsStateless extends AnalyticsBase {
|
|
12
|
-
/**
|
|
13
|
-
* Build, intercept, validate, and send a component view event.
|
|
14
|
-
*
|
|
15
|
-
* @param args - {@link TrackViewArgs} used to build the event. Includes an
|
|
16
|
-
* optional partial profile.
|
|
17
|
-
* @returns A promise that resolves once the batch has been sent.
|
|
18
|
-
*/
|
|
19
|
-
async trackComponentView(args) {
|
|
20
|
-
logger.info('Processing "component view" event');
|
|
21
|
-
const { profile, ...builderArgs } = args;
|
|
22
|
-
const event = this.builder.buildComponentView(builderArgs);
|
|
23
|
-
const intercepted = await this.interceptors.event.run(event);
|
|
24
|
-
const parsed = ComponentViewEvent.parse(intercepted);
|
|
25
|
-
await this.sendBatchEvent(parsed, profile);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Build, intercept, validate, and send a flag view event.
|
|
29
|
-
*
|
|
30
|
-
* @param args - {@link TrackViewArgs} used to build the event. Includes an
|
|
31
|
-
* optional partial profile.
|
|
32
|
-
* @returns A promise that resolves once the batch has been sent.
|
|
33
|
-
*/
|
|
34
|
-
async trackFlagView(args) {
|
|
35
|
-
logger.debug('Processing "flag view" event');
|
|
36
|
-
const { profile, ...builderArgs } = args;
|
|
37
|
-
const event = this.builder.buildFlagView(builderArgs);
|
|
38
|
-
const intercepted = await this.interceptors.event.run(event);
|
|
39
|
-
const parsed = ComponentViewEvent.parse(intercepted);
|
|
40
|
-
await this.sendBatchEvent(parsed, profile);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Send a single {@link InsightsEvent} wrapped in a one‑item batch.
|
|
44
|
-
*
|
|
45
|
-
* @param event - The event to send.
|
|
46
|
-
* @param profile - Optional partial profile to attach to the batch.
|
|
47
|
-
* @returns A promise that resolves when the API call completes.
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
async sendBatchEvent(event, profile) {
|
|
51
|
-
const batchEvent = BatchInsightsEventArray.parse([
|
|
52
|
-
{
|
|
53
|
-
profile,
|
|
54
|
-
events: [event],
|
|
55
|
-
},
|
|
56
|
-
]);
|
|
57
|
-
await this.api.insights.sendBatchEvents(batchEvent);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export default AnalyticsStateless;
|
|
61
|
-
//# sourceMappingURL=AnalyticsStateless.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsStateless.js","sourceRoot":"","sources":["../../src/analytics/AnalyticsStateless.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,GAGnB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAE3C,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAA;AAY9C;;;;;GAKG;AACH,MAAM,kBAAmB,SAAQ,aAAa;IAC5C;;;;;;OAMG;IACH,KAAK,CAAC,kBAAkB,CAAC,IAAmB;QAC1C,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAA;QAEhD,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,IAAI,CAAA;QAExC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAA;QAE1D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAE5D,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAEpD,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,aAAa,CAAC,IAAmB;QACrC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAE5C,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,IAAI,CAAA;QAExC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;QAErD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAE5D,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAEpD,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,cAAc,CAAC,KAAoB,EAAE,OAAwB;QACzE,MAAM,UAAU,GAA4B,uBAAuB,CAAC,KAAK,CAAC;YACxE;gBACE,OAAO;gBACP,MAAM,EAAE,CAAC,KAAK,CAAC;aAChB;SACF,CAAC,CAAA;QAEF,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,CAAA;IACrD,CAAC;CACF;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAElE,cAAc,sBAAsB,CAAA;AACpC,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/analytics/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAElE,cAAc,sBAAsB,CAAA;AACpC,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const OPTIMIZATION_CORE_SDK_VERSION: string;
|
|
2
|
-
/**
|
|
3
|
-
* Anonymous-ID cookie name used by the Optimization Core.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
* @remarks
|
|
7
|
-
* This constant represents the cookie key used by the Optimization Framework
|
|
8
|
-
* to persist an anonymous identifier for tracking personalization and analytics
|
|
9
|
-
* events when no explicit profile is known.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { ANONYMOUS_ID_COOKIE } from '@contentful/optimization-core'
|
|
14
|
-
* const profileId = request.cookies[ANONYMOUS_ID_COOKIE]
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare const ANONYMOUS_ID_COOKIE = "ctfl-opt-aid";
|
|
18
|
-
//# sourceMappingURL=global-constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-constants.d.ts","sourceRoot":"","sources":["../src/global-constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,6BAA6B,QACyC,CAAA;AAEnF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,iBAAiB,CAAA"}
|
package/dist/global-constants.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const OPTIMIZATION_CORE_SDK_VERSION = typeof __OPTIMIZATION_VERSION__ === 'string' ? __OPTIMIZATION_VERSION__ : '0.0.0';
|
|
2
|
-
/**
|
|
3
|
-
* Anonymous-ID cookie name used by the Optimization Core.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
* @remarks
|
|
7
|
-
* This constant represents the cookie key used by the Optimization Framework
|
|
8
|
-
* to persist an anonymous identifier for tracking personalization and analytics
|
|
9
|
-
* events when no explicit profile is known.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { ANONYMOUS_ID_COOKIE } from '@contentful/optimization-core'
|
|
14
|
-
* const profileId = request.cookies[ANONYMOUS_ID_COOKIE]
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';
|
|
18
|
-
//# sourceMappingURL=global-constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"global-constants.js","sourceRoot":"","sources":["../src/global-constants.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,6BAA6B,GACxC,OAAO,wBAAwB,KAAK,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,OAAO,CAAA;AAEnF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAA"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAA;AAE7E,cAAc,qCAAqC,CAAA;AACnD,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { batch, effect, signals } from './signals';
|
|
2
|
-
export * from '@contentful/optimization-api-client';
|
|
3
|
-
export * from 'logger';
|
|
4
|
-
export * from './analytics';
|
|
5
|
-
export * from './CoreBase';
|
|
6
|
-
export * from './CoreStateful';
|
|
7
|
-
export * from './CoreStateless';
|
|
8
|
-
export * from './global-constants';
|
|
9
|
-
export * from './lib/decorators';
|
|
10
|
-
export * from './lib/interceptor';
|
|
11
|
-
export * from './lib/value-presence';
|
|
12
|
-
export * from './personalization';
|
|
13
|
-
export { default as CoreStateful } from './CoreStateful';
|
|
14
|
-
export { default as CoreStateless } from './CoreStateless';
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAA6B,MAAM,WAAW,CAAA;AAE7E,cAAc,qCAAqC,CAAA;AACnD,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A callback invoked when a method call is blocked by {@link guardedBy}.
|
|
3
|
-
*
|
|
4
|
-
* @param methodName - The name of the method that was attempted.
|
|
5
|
-
* @param args - The readonly array of arguments supplied to the blocked call.
|
|
6
|
-
* @returns Nothing.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
type BlockHandler = (methodName: string, args: readonly unknown[]) => void;
|
|
11
|
-
/**
|
|
12
|
-
* The original method implementation.
|
|
13
|
-
*
|
|
14
|
-
* @typeParam A - The parameter tuple of the original method.
|
|
15
|
-
* @typeParam R - The return type of the original method.
|
|
16
|
-
* @param value - The method being decorated.
|
|
17
|
-
* @param context - The Stage-3 decorator context for a class method.
|
|
18
|
-
* @returns Nothing.
|
|
19
|
-
*
|
|
20
|
-
* @remarks
|
|
21
|
-
* Users do not call this directly; it's returned by {@link guardedBy}.
|
|
22
|
-
*/
|
|
23
|
-
type GuardedByFunction<T extends object> = <A extends readonly unknown[], R>(value: (...args: A) => R, context: ClassMethodDecoratorContext<T, (...args: A) => R>) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Options that tweak the behavior of {@link guardedBy}.
|
|
26
|
-
*
|
|
27
|
-
* @typeParam T - The instance type on which the decorator is applied.
|
|
28
|
-
*
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export interface GuardedByOptions<T extends object> {
|
|
32
|
-
/**
|
|
33
|
-
* Inverts the predicate result.
|
|
34
|
-
*
|
|
35
|
-
* When `true`, a truthy predicate result **blocks** the method.
|
|
36
|
-
* When `false` (default) or omitted, a truthy predicate result **allows** the method.
|
|
37
|
-
*
|
|
38
|
-
* @defaultValue `false`
|
|
39
|
-
* @remarks
|
|
40
|
-
* This option is useful when the predicate expresses a *forbid* condition
|
|
41
|
-
* (e.g. "isLocked" or "isDestroyed") rather than an *allow* condition.
|
|
42
|
-
*/
|
|
43
|
-
readonly invert?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Either a function to call when a method is blocked, or the name/symbol of
|
|
46
|
-
* an instance method on `this` to call when blocked.
|
|
47
|
-
*
|
|
48
|
-
* Both forms are **synchronous** and receive `(methodName, argsArray)`.
|
|
49
|
-
* If omitted, blocked calls fail silently (i.e., return `undefined` or
|
|
50
|
-
* `Promise<undefined>` for async methods).
|
|
51
|
-
*
|
|
52
|
-
* @remarks
|
|
53
|
-
* - If a property key is supplied and the instance does not have a callable at that key,
|
|
54
|
-
* the hook is ignored.
|
|
55
|
-
* - The hook **must not** be `async`; any async work should be scheduled manually.
|
|
56
|
-
*/
|
|
57
|
-
readonly onBlocked?: BlockHandler | (keyof T & (string | symbol));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Decorator factory that **guards** class methods behind a synchronous predicate.
|
|
61
|
-
*
|
|
62
|
-
* When a decorated method is invoked:
|
|
63
|
-
* - If the predicate returns a value that evaluates to **allowed** (see `invert`), the original
|
|
64
|
-
* method is executed and its result is returned.
|
|
65
|
-
* - If the call is **blocked**, the optional `onBlocked` hook is invoked (if configured) and:
|
|
66
|
-
* - `undefined` is returned for sync methods; or
|
|
67
|
-
* - `Promise<undefined>` is returned for async methods (to preserve `await` compatibility).
|
|
68
|
-
*
|
|
69
|
-
* @typeParam T - The instance type that owns both the predicate and the decorated method.
|
|
70
|
-
*
|
|
71
|
-
* @param predicateName - The name (string or symbol) of a **synchronous** instance method on `this`
|
|
72
|
-
* that acts as the predicate. It is called as `this[predicateName](methodName, argsArray)`.
|
|
73
|
-
* @param opts - Optional {@link GuardedByOptions | options} to configure inversion and `onBlocked`.
|
|
74
|
-
*
|
|
75
|
-
* @returns A methods-only class decorator compatible with Stage-3 decorators that wraps the method.
|
|
76
|
-
*
|
|
77
|
-
* @throws TypeError
|
|
78
|
-
* Thrown at initialization time (first instance construction) if `predicateName` does not resolve
|
|
79
|
-
* to a **synchronous function** on the instance.
|
|
80
|
-
*
|
|
81
|
-
* @remarks
|
|
82
|
-
* - This is a **methods-only** decorator; applying it to accessors/fields is a no-op.
|
|
83
|
-
* - The decorator preserves the original method's sync/async shape.
|
|
84
|
-
* - The predicate is invoked with `(decoratedMethodName, argsArray)` to support context-aware checks.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* Here, `canRun` allows the call when it returns truthy:
|
|
88
|
-
* ```ts
|
|
89
|
-
* class Runner {
|
|
90
|
-
* canRun(method: string, _args: readonly unknown[]) { return method !== 'stop'; }
|
|
91
|
-
*
|
|
92
|
-
* @guardedBy<Runner>('canRun')
|
|
93
|
-
* go() { console.log('running'); }
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* Invert the predicate and call a handler on block:
|
|
99
|
-
* ```ts
|
|
100
|
-
* class Door {
|
|
101
|
-
* isLocked() { return true } // truthy means "locked"
|
|
102
|
-
* onBlocked(method: string) { console.warn(`${method} blocked`) }
|
|
103
|
-
*
|
|
104
|
-
* @guardedBy<Door>('isLocked', { invert: true, onBlocked: 'onBlocked' })
|
|
105
|
-
* open() { /* ... *\/ }
|
|
106
|
-
* }
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* @public
|
|
110
|
-
*/
|
|
111
|
-
export declare function guardedBy<T extends object>(predicateName: keyof T & (string | symbol), opts?: GuardedByOptions<T>): GuardedByFunction<T>;
|
|
112
|
-
export {};
|
|
113
|
-
//# sourceMappingURL=guardedBy.d.ts.map
|