@croct/plug 0.15.0 → 0.16.0
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/api/evaluate.js +1 -2
- package/api/evaluate.js.map +1 -1
- package/api/fetchContent.d.ts +1 -1
- package/api/fetchContent.js +1 -2
- package/api/fetchContent.js.map +1 -1
- package/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/package.json +12 -12
- package/plug.d.ts +3 -14
- package/plug.js +16 -43
- package/plug.js.map +1 -1
- package/sdk/apiKey.d.ts +1 -0
- package/sdk/apiKey.js +5 -0
- package/sdk/apiKey.js.map +1 -0
- package/src/api/fetchContent.ts +2 -0
- package/src/plug.ts +25 -76
- package/src/sdk/apiKey.ts +1 -0
- package/eap.d.ts +0 -15
- package/eap.js +0 -3
- package/eap.js.map +0 -1
- package/src/eap.ts +0 -17
package/api/evaluate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluate =
|
|
3
|
+
exports.evaluate = evaluate;
|
|
4
4
|
const evaluator_1 = require("@croct/sdk/evaluator");
|
|
5
5
|
const error_1 = require("@croct/sdk/error");
|
|
6
6
|
function evaluate(query, options) {
|
|
@@ -21,5 +21,4 @@ function evaluate(query, options) {
|
|
|
21
21
|
}
|
|
22
22
|
return promise;
|
|
23
23
|
}
|
|
24
|
-
exports.evaluate = evaluate;
|
|
25
24
|
//# sourceMappingURL=evaluate.js.map
|
package/api/evaluate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/api/evaluate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/api/evaluate.ts"],"names":[],"mappings":";;AA0BA,4BAuBC;AAjDD,oDAAiF;AAGjF,4CAA6C;AAuB7C,SAAgB,QAAQ,CAAsB,KAAa,EAAE,OAA6B;IACtF,MAAM,EAAC,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAC,GAAG,OAAO,CAAC;IAClF,MAAM,IAAI,GAAgB,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;IACnF,MAAM,OAAO,GAAG,CAAC,IAAI,qBAAS,CAAC,EAAC,GAAG,IAAI,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,CAAC;SACvE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAe,CAAC;IAE/C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,KAAK,CAChB,KAAK,CAAC,EAAE;YACJ,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,EAAE;oBAC/B,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK;oBAC5B,CAAC,CAAC,KAAK,CAAC;gBAEZ,MAAM,CAAC,KAAK,CAAC,6BAA6B,SAAS,MAAM,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACnF,CAAC;YAED,OAAO,QAAQ,CAAC;QACpB,CAAC,CACJ,CAAC;IACN,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/api/fetchContent.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Logger } from '@croct/sdk/logging';
|
|
|
4
4
|
import { JsonObject, JsonValue } from '../sdk/json';
|
|
5
5
|
import { FetchResponse } from '../plug';
|
|
6
6
|
import { SlotContent, VersionedSlotId } from '../slot';
|
|
7
|
+
export { FetchResponse } from '../plug';
|
|
7
8
|
type FetchingOptions<T extends JsonValue> = {
|
|
8
9
|
baseEndpointUrl?: string;
|
|
9
10
|
fallback?: T;
|
|
@@ -22,4 +23,3 @@ export type DynamicContentOptions<T extends JsonObject = JsonObject> = Omit<Base
|
|
|
22
23
|
export type StaticContentOptions<T extends JsonObject = JsonObject> = Omit<BaseStaticOptions, 'version'> & FetchingOptions<T> & ServerSideAuthOptions;
|
|
23
24
|
export type FetchOptions<T extends JsonObject = SlotContent> = DynamicContentOptions<T> | StaticContentOptions<T>;
|
|
24
25
|
export declare function fetchContent<I extends VersionedSlotId, C extends JsonObject>(slotId: I, options?: FetchOptions<SlotContent<I, C>>): Promise<Omit<FetchResponse<I, C>, 'payload'>>;
|
|
25
|
-
export {};
|
package/api/fetchContent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchContent =
|
|
3
|
+
exports.fetchContent = fetchContent;
|
|
4
4
|
const contentFetcher_1 = require("@croct/sdk/contentFetcher");
|
|
5
5
|
const error_1 = require("@croct/sdk/error");
|
|
6
6
|
function fetchContent(slotId, options) {
|
|
@@ -21,5 +21,4 @@ function fetchContent(slotId, options) {
|
|
|
21
21
|
}
|
|
22
22
|
return promise;
|
|
23
23
|
}
|
|
24
|
-
exports.fetchContent = fetchContent;
|
|
25
24
|
//# sourceMappingURL=fetchContent.js.map
|
package/api/fetchContent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchContent.js","sourceRoot":"","sources":["../src/api/fetchContent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchContent.js","sourceRoot":"","sources":["../src/api/fetchContent.ts"],"names":[],"mappings":";;AAwCA,oCA6BC;AArED,8DAImC;AAGnC,4CAA6C;AAiC7C,SAAgB,YAAY,CACxB,MAAS,EACT,OAAyC;IAEzC,MAAM,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,YAAY,EAAC,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IAC1F,MAAM,IAAI,GAAG,EAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,CAAC;IAC5C,MAAM,CAAC,EAAE,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAA4C,CAAC;IAE9F,MAAM,OAAO,GAAG,CAAC,IAAI,+BAAc,CAAC,EAAC,GAAG,IAAI,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,CAAC;SAC5E,KAAK,CACF,EAAE,EACF,OAAO,KAAK,QAAQ;QAChB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,EAAC,GAAG,YAAY,EAAE,OAAO,EAAE,OAAO,EAAC,CAC5C,CAAC;IAEN,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,KAAK,CAChB,KAAK,CAAC,EAAE;YACJ,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,IAAI,OAAO,MAAM,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/F,CAAC;YAED,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,CAAC;QAC/B,CAAC,CACJ,CAAC;IACN,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/constants.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export declare const CDN_URL = "https://cdn.croct.io/js/v1/lib/plug.js";
|
|
|
2
2
|
export declare const PLAYGROUND_ORIGIN = "https://play.croct.com";
|
|
3
3
|
export declare const PLAYGROUND_CONNECT_URL = "https://play.croct.com/connect.html";
|
|
4
4
|
export declare const PREVIEW_WIDGET_ORIGIN = "https://cdn.croct.io";
|
|
5
|
-
export declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.
|
|
5
|
+
export declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.16.0.html";
|
package/constants.js
CHANGED
|
@@ -5,5 +5,5 @@ exports.CDN_URL = 'https://cdn.croct.io/js/v1/lib/plug.js';
|
|
|
5
5
|
exports.PLAYGROUND_ORIGIN = 'https://play.croct.com';
|
|
6
6
|
exports.PLAYGROUND_CONNECT_URL = 'https://play.croct.com/connect.html';
|
|
7
7
|
exports.PREVIEW_WIDGET_ORIGIN = 'https://cdn.croct.io';
|
|
8
|
-
exports.PREVIEW_WIDGET_URL = 'https://cdn.croct.io/js/v1/lib/plug/widget-0.
|
|
8
|
+
exports.PREVIEW_WIDGET_URL = 'https://cdn.croct.io/js/v1/lib/plug/widget-0.16.0.html';
|
|
9
9
|
//# sourceMappingURL=constants.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/plug",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "A fully-featured devkit for building natively personalized applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,23 +33,23 @@
|
|
|
33
33
|
"bundle": "rollup -c"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@croct/json": "^2.0
|
|
37
|
-
"@croct/sdk": "^0.
|
|
38
|
-
"tslib": "^2.
|
|
36
|
+
"@croct/json": "^2.1.0",
|
|
37
|
+
"@croct/sdk": "^0.17.2",
|
|
38
|
+
"tslib": "^2.7.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@croct/eslint-plugin": "^0.7.
|
|
42
|
-
"@rollup/plugin-commonjs": "^26.0.
|
|
43
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
44
|
-
"@rollup/plugin-replace": "^5.0.
|
|
45
|
-
"@rollup/plugin-terser": "^0.4.
|
|
46
|
-
"@rollup/plugin-typescript": "^11.
|
|
47
|
-
"@types/jest": "^29.
|
|
41
|
+
"@croct/eslint-plugin": "^0.7.1",
|
|
42
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
43
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
44
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
45
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
46
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
47
|
+
"@types/jest": "^29.5.12",
|
|
48
48
|
"@typescript-eslint/parser": "^7.0.0",
|
|
49
49
|
"eslint": "^8.27.0",
|
|
50
50
|
"jest": "^29.3.1",
|
|
51
51
|
"jest-environment-jsdom": "^29.3.1",
|
|
52
|
-
"rollup": "^
|
|
52
|
+
"rollup": "^4.0.0",
|
|
53
53
|
"ts-jest": "^29.0.3",
|
|
54
54
|
"ts-node": "^10.9.1",
|
|
55
55
|
"typescript": "^5.0.0"
|
package/plug.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { Optional } from '@croct/sdk/utilityTypes';
|
|
|
7
7
|
import { ExternalTrackingEvent as ExternalEvent, ExternalTrackingEventPayload as ExternalEventPayload, ExternalTrackingEventType as ExternalEventType } from '@croct/sdk/trackingEvents';
|
|
8
8
|
import { FetchOptions as BaseFetchOptions } from '@croct/sdk/facade/contentFetcherFacade';
|
|
9
9
|
import { PluginFactory } from './plugin';
|
|
10
|
-
import { EapFeatures } from './eap';
|
|
11
10
|
import { VersionedSlotId, SlotContent } from './slot';
|
|
12
11
|
import { JsonValue, JsonObject } from './sdk/json';
|
|
13
12
|
export interface PluginConfigurations {
|
|
@@ -20,16 +19,7 @@ export type FetchOptions = Omit<BaseFetchOptions, 'version'>;
|
|
|
20
19
|
export type FetchResponse<I extends VersionedSlotId, C extends JsonObject = JsonObject> = {
|
|
21
20
|
content: SlotContent<I, C>;
|
|
22
21
|
};
|
|
23
|
-
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export type LegacyFetchResponse<I extends VersionedSlotId, C extends JsonObject = JsonObject> = FetchResponse<I, C> & {
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use `content` instead.
|
|
29
|
-
*/
|
|
30
|
-
payload: SlotContent<I, C>;
|
|
31
|
-
};
|
|
32
|
-
export interface Plug extends EapFeatures {
|
|
22
|
+
export interface Plug {
|
|
33
23
|
readonly tracker: TrackerFacade;
|
|
34
24
|
readonly user: UserFacade;
|
|
35
25
|
readonly session: SessionFacade;
|
|
@@ -45,7 +35,7 @@ export interface Plug extends EapFeatures {
|
|
|
45
35
|
unsetToken(): void;
|
|
46
36
|
track<T extends ExternalEventType>(type: T, payload: ExternalEventPayload<T>): Promise<ExternalEvent<T>>;
|
|
47
37
|
evaluate<T extends JsonValue>(expression: string, options?: EvaluationOptions): Promise<T>;
|
|
48
|
-
fetch<P extends JsonObject, I extends VersionedSlotId>(slotId: I, options?: FetchOptions): Promise<
|
|
38
|
+
fetch<P extends JsonObject, I extends VersionedSlotId>(slotId: I, options?: FetchOptions): Promise<FetchResponse<I, P>>;
|
|
49
39
|
unplug(): Promise<void>;
|
|
50
40
|
}
|
|
51
41
|
export declare class GlobalPlug implements Plug {
|
|
@@ -74,7 +64,6 @@ export declare class GlobalPlug implements Plug {
|
|
|
74
64
|
track<T extends ExternalEventType>(type: T, payload: ExternalEventPayload<T>): Promise<ExternalEvent<T>>;
|
|
75
65
|
evaluate<T extends JsonValue>(query: string, options?: EvaluationOptions): Promise<T>;
|
|
76
66
|
test(expression: string, options?: EvaluationOptions): Promise<boolean>;
|
|
77
|
-
|
|
67
|
+
fetch<C extends JsonObject, I extends VersionedSlotId = VersionedSlotId>(slotId: I, options?: FetchOptions): Promise<FetchResponse<I, C>>;
|
|
78
68
|
unplug(): Promise<void>;
|
|
79
|
-
private eap;
|
|
80
69
|
}
|
package/plug.js
CHANGED
|
@@ -35,7 +35,7 @@ class GlobalPlug {
|
|
|
35
35
|
this.pluginFactories[name] = plugin;
|
|
36
36
|
}
|
|
37
37
|
plug(configuration = {}) {
|
|
38
|
-
var _a, _b, _c
|
|
38
|
+
var _a, _b, _c;
|
|
39
39
|
if (this.instance !== undefined) {
|
|
40
40
|
const logger = this.instance.getLogger();
|
|
41
41
|
logger.info('Croct is already plugged in.');
|
|
@@ -46,12 +46,14 @@ class GlobalPlug {
|
|
|
46
46
|
if (detectedAppId !== null && configuredAppId !== null && detectedAppId !== configuredAppId) {
|
|
47
47
|
throw new Error('The specified app ID and the auto-detected app ID are conflicting. '
|
|
48
48
|
+ 'There is no need to specify an app ID when using an application-specific tag. '
|
|
49
|
-
+ 'Please try again omitting the "appId" option.'
|
|
49
|
+
+ 'Please try again omitting the "appId" option. '
|
|
50
|
+
+ 'For help, see https://croct.help/sdk/javascript/conflicting-app-id');
|
|
50
51
|
}
|
|
51
52
|
const appId = detectedAppId !== null && detectedAppId !== void 0 ? detectedAppId : configuredAppId;
|
|
52
53
|
if (appId === null) {
|
|
53
54
|
throw new Error('The app ID must be specified when it cannot be auto-detected. '
|
|
54
|
-
+ 'Please try again specifying the "appId" option.'
|
|
55
|
+
+ 'Please try again specifying the "appId" option.'
|
|
56
|
+
+ 'For help, see https://croct.help/sdk/javascript/missing-app-id');
|
|
55
57
|
}
|
|
56
58
|
const { plugins, test, ...sdkConfiguration } = configuration;
|
|
57
59
|
const sdk = sdkFacade_1.SdkFacade.init({
|
|
@@ -129,10 +131,6 @@ class GlobalPlug {
|
|
|
129
131
|
pending.push(promise.then(() => logger.debug(`Plugin "${name}" enabled`))
|
|
130
132
|
.catch(error => logger.error(`Failed to enable plugin "${name}": ${(0, error_1.formatCause)(error)}`)));
|
|
131
133
|
}
|
|
132
|
-
const initializeEap = (_d = window.croctEap) === null || _d === void 0 ? void 0 : _d.initialize;
|
|
133
|
-
if (typeof initializeEap === 'function') {
|
|
134
|
-
initializeEap.call(this);
|
|
135
|
-
}
|
|
136
134
|
Promise.all(pending)
|
|
137
135
|
.then(() => {
|
|
138
136
|
this.initialize();
|
|
@@ -152,7 +150,7 @@ class GlobalPlug {
|
|
|
152
150
|
}
|
|
153
151
|
get sdk() {
|
|
154
152
|
if (this.instance === undefined) {
|
|
155
|
-
throw new Error('Croct is not plugged in.');
|
|
153
|
+
throw new Error('Croct is not plugged in. For help, see https://croct.help/sdk/javascript/not-plugged-in');
|
|
156
154
|
}
|
|
157
155
|
return this.instance;
|
|
158
156
|
}
|
|
@@ -180,7 +178,7 @@ class GlobalPlug {
|
|
|
180
178
|
}
|
|
181
179
|
identify(userId) {
|
|
182
180
|
if (typeof userId !== 'string') {
|
|
183
|
-
throw new Error('The user ID must be a string.
|
|
181
|
+
throw new Error('The user ID must be a string. For help, see https://croct.help/sdk/javascript/invalid-user-id');
|
|
184
182
|
}
|
|
185
183
|
this.sdk.identify(userId);
|
|
186
184
|
}
|
|
@@ -213,25 +211,15 @@ class GlobalPlug {
|
|
|
213
211
|
return this.evaluate(expression, options)
|
|
214
212
|
.then(result => result === true);
|
|
215
213
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
logger.warn('Accessing the "payload" property of the fetch response is deprecated'
|
|
226
|
-
+ ' and will be removed in a future version. Use the "content" property instead.');
|
|
227
|
-
return response.content;
|
|
228
|
-
},
|
|
229
|
-
content: response.content,
|
|
230
|
-
}))
|
|
231
|
-
.catch(error => {
|
|
232
|
-
logger.error(`Failed to fetch content for slot "${id}@${version}": ${(0, error_1.formatCause)(error)}`);
|
|
233
|
-
throw error;
|
|
234
|
-
});
|
|
214
|
+
fetch(slotId, options = {}) {
|
|
215
|
+
const [id, version = 'latest'] = slotId.split('@');
|
|
216
|
+
const logger = this.sdk.getLogger();
|
|
217
|
+
return this.sdk
|
|
218
|
+
.contentFetcher
|
|
219
|
+
.fetch(id, version === 'latest' ? options : { ...options, version: version })
|
|
220
|
+
.catch(error => {
|
|
221
|
+
logger.error(`Failed to fetch content for slot "${id}@${version}": ${(0, error_1.formatCause)(error)}`);
|
|
222
|
+
throw error;
|
|
235
223
|
});
|
|
236
224
|
}
|
|
237
225
|
async unplug() {
|
|
@@ -268,21 +256,6 @@ class GlobalPlug {
|
|
|
268
256
|
logger.info('🔌 Croct has been unplugged.');
|
|
269
257
|
}
|
|
270
258
|
}
|
|
271
|
-
eap(feature, api) {
|
|
272
|
-
const eap = window.croctEap;
|
|
273
|
-
const method = typeof eap === 'object' ? eap[feature] : undefined;
|
|
274
|
-
if (typeof method !== 'function') {
|
|
275
|
-
return api;
|
|
276
|
-
}
|
|
277
|
-
return method.bind(new Proxy(this, {
|
|
278
|
-
get: (plug, property) => {
|
|
279
|
-
if (property === feature) {
|
|
280
|
-
return api;
|
|
281
|
-
}
|
|
282
|
-
return plug[property];
|
|
283
|
-
},
|
|
284
|
-
}));
|
|
285
|
-
}
|
|
286
259
|
}
|
|
287
260
|
exports.GlobalPlug = GlobalPlug;
|
|
288
261
|
//# sourceMappingURL=plug.js.map
|
package/plug.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plug.js","sourceRoot":"","sources":["src/plug.ts"],"names":[],"mappings":";;;AAKA,2DAA+F;AAC/F,4CAA6C;AAC7C,sDAA+C;AAE/C,4CAAuC;AAMvC,oCAAmC;AAGnC,2CAAoC;AACpC,6CAAgE;AAChE,uCAA0D;
|
|
1
|
+
{"version":3,"file":"plug.js","sourceRoot":"","sources":["src/plug.ts"],"names":[],"mappings":";;;AAKA,2DAA+F;AAC/F,4CAA6C;AAC7C,sDAA+C;AAE/C,4CAAuC;AAMvC,oCAAmC;AAGnC,2CAAoC;AACpC,6CAAgE;AAChE,uCAA0D;AAoD1D,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC,SAAS,WAAW;IAChB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,gBAAgB,mBAAO,IAAI,CAAC,CAAC;IAE1E,IAAI,CAAC,CAA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AAC;IACL,CAAC;CACJ;AAxVD,gCAwVC"}
|
package/sdk/apiKey.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@croct/sdk/apiKey';
|
package/sdk/apiKey.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKey.js","sourceRoot":"","sources":["../src/sdk/apiKey.ts"],"names":[],"mappings":";;;AAAA,4DAAkC"}
|
package/src/api/fetchContent.ts
CHANGED
|
@@ -10,6 +10,8 @@ import {JsonObject, JsonValue} from '../sdk/json';
|
|
|
10
10
|
import {FetchResponse} from '../plug';
|
|
11
11
|
import {SlotContent, VersionedSlotId} from '../slot';
|
|
12
12
|
|
|
13
|
+
export {FetchResponse} from '../plug';
|
|
14
|
+
|
|
13
15
|
type FetchingOptions<T extends JsonValue> = {
|
|
14
16
|
baseEndpointUrl?: string,
|
|
15
17
|
fallback?: T,
|
package/src/plug.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {Plugin, PluginArguments, PluginFactory} from './plugin';
|
|
|
19
19
|
import {CDN_URL} from './constants';
|
|
20
20
|
import {factory as playgroundPluginFactory} from './playground';
|
|
21
21
|
import {factory as previewPluginFactory} from './preview';
|
|
22
|
-
import {EapFeatures} from './eap';
|
|
23
22
|
import {VersionedSlotId, SlotContent} from './slot';
|
|
24
23
|
import {JsonValue, JsonObject} from './sdk/json';
|
|
25
24
|
|
|
@@ -37,17 +36,7 @@ export type FetchResponse<I extends VersionedSlotId, C extends JsonObject = Json
|
|
|
37
36
|
content: SlotContent<I, C>,
|
|
38
37
|
};
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
export type LegacyFetchResponse<I extends VersionedSlotId, C extends JsonObject = JsonObject> = FetchResponse<I, C> & {
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated Use `content` instead.
|
|
46
|
-
*/
|
|
47
|
-
payload: SlotContent<I, C>,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export interface Plug extends EapFeatures {
|
|
39
|
+
export interface Plug {
|
|
51
40
|
readonly tracker: TrackerFacade;
|
|
52
41
|
readonly user: UserFacade;
|
|
53
42
|
readonly session: SessionFacade;
|
|
@@ -76,7 +65,7 @@ export interface Plug extends EapFeatures {
|
|
|
76
65
|
fetch<P extends JsonObject, I extends VersionedSlotId>(
|
|
77
66
|
slotId: I,
|
|
78
67
|
options?: FetchOptions
|
|
79
|
-
): Promise<
|
|
68
|
+
): Promise<FetchResponse<I, P>>;
|
|
80
69
|
|
|
81
70
|
unplug(): Promise<void>;
|
|
82
71
|
}
|
|
@@ -137,7 +126,9 @@ export class GlobalPlug implements Plug {
|
|
|
137
126
|
throw new Error(
|
|
138
127
|
'The specified app ID and the auto-detected app ID are conflicting. '
|
|
139
128
|
+ 'There is no need to specify an app ID when using an application-specific tag. '
|
|
140
|
-
+ 'Please try again omitting the "appId" option.'
|
|
129
|
+
+ 'Please try again omitting the "appId" option. '
|
|
130
|
+
+ 'For help, see https://croct.help/sdk/javascript/conflicting-app-id',
|
|
131
|
+
|
|
141
132
|
);
|
|
142
133
|
}
|
|
143
134
|
|
|
@@ -146,7 +137,8 @@ export class GlobalPlug implements Plug {
|
|
|
146
137
|
if (appId === null) {
|
|
147
138
|
throw new Error(
|
|
148
139
|
'The app ID must be specified when it cannot be auto-detected. '
|
|
149
|
-
+ 'Please try again specifying the "appId" option.'
|
|
140
|
+
+ 'Please try again specifying the "appId" option.'
|
|
141
|
+
+ 'For help, see https://croct.help/sdk/javascript/missing-app-id',
|
|
150
142
|
);
|
|
151
143
|
}
|
|
152
144
|
|
|
@@ -265,12 +257,6 @@ export class GlobalPlug implements Plug {
|
|
|
265
257
|
);
|
|
266
258
|
}
|
|
267
259
|
|
|
268
|
-
const initializeEap = window.croctEap?.initialize;
|
|
269
|
-
|
|
270
|
-
if (typeof initializeEap === 'function') {
|
|
271
|
-
initializeEap.call(this);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
260
|
Promise.all(pending)
|
|
275
261
|
.then(() => {
|
|
276
262
|
this.initialize();
|
|
@@ -295,7 +281,7 @@ export class GlobalPlug implements Plug {
|
|
|
295
281
|
|
|
296
282
|
private get sdk(): SdkFacade {
|
|
297
283
|
if (this.instance === undefined) {
|
|
298
|
-
throw new Error('Croct is not plugged in.');
|
|
284
|
+
throw new Error('Croct is not plugged in. For help, see https://croct.help/sdk/javascript/not-plugged-in');
|
|
299
285
|
}
|
|
300
286
|
|
|
301
287
|
return this.instance;
|
|
@@ -331,7 +317,9 @@ export class GlobalPlug implements Plug {
|
|
|
331
317
|
|
|
332
318
|
public identify(userId: string): void {
|
|
333
319
|
if (typeof userId !== 'string') {
|
|
334
|
-
throw new Error(
|
|
320
|
+
throw new Error(
|
|
321
|
+
'The user ID must be a string. For help, see https://croct.help/sdk/javascript/invalid-user-id',
|
|
322
|
+
);
|
|
335
323
|
}
|
|
336
324
|
|
|
337
325
|
this.sdk.identify(userId);
|
|
@@ -374,39 +362,21 @@ export class GlobalPlug implements Plug {
|
|
|
374
362
|
.then(result => result === true);
|
|
375
363
|
}
|
|
376
364
|
|
|
377
|
-
public
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
): Promise<LegacyFetchResponse<I, C>> => {
|
|
384
|
-
const [id, version = 'latest'] = slotId.split('@') as [string, `${number}` | 'latest' | undefined];
|
|
385
|
-
const logger = this.sdk.getLogger();
|
|
365
|
+
public fetch<C extends JsonObject, I extends VersionedSlotId = VersionedSlotId>(
|
|
366
|
+
slotId: I,
|
|
367
|
+
options: FetchOptions = {},
|
|
368
|
+
): Promise<FetchResponse<I, C>> {
|
|
369
|
+
const [id, version = 'latest'] = slotId.split('@') as [string, `${number}` | 'latest' | undefined];
|
|
370
|
+
const logger = this.sdk.getLogger();
|
|
386
371
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
+ ' and will be removed in a future version. Use the "content" property instead.',
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
return response.content;
|
|
399
|
-
},
|
|
400
|
-
content: response.content,
|
|
401
|
-
}),
|
|
402
|
-
)
|
|
403
|
-
.catch(error => {
|
|
404
|
-
logger.error(`Failed to fetch content for slot "${id}@${version}": ${formatCause(error)}`);
|
|
405
|
-
|
|
406
|
-
throw error;
|
|
407
|
-
});
|
|
408
|
-
},
|
|
409
|
-
);
|
|
372
|
+
return this.sdk
|
|
373
|
+
.contentFetcher
|
|
374
|
+
.fetch<SlotContent<I, C>>(id, version === 'latest' ? options : {...options, version: version})
|
|
375
|
+
.catch(error => {
|
|
376
|
+
logger.error(`Failed to fetch content for slot "${id}@${version}": ${formatCause(error)}`);
|
|
377
|
+
|
|
378
|
+
throw error;
|
|
379
|
+
});
|
|
410
380
|
}
|
|
411
381
|
|
|
412
382
|
public async unplug(): Promise<void> {
|
|
@@ -456,25 +426,4 @@ export class GlobalPlug implements Plug {
|
|
|
456
426
|
logger.info('🔌 Croct has been unplugged.');
|
|
457
427
|
}
|
|
458
428
|
}
|
|
459
|
-
|
|
460
|
-
private eap<T extends keyof EapFeatures>(feature: T, api: EapFeatures[T]): EapFeatures[T] {
|
|
461
|
-
const eap = window.croctEap;
|
|
462
|
-
const method: EapFeatures[T] | undefined = typeof eap === 'object' ? eap[feature] : undefined;
|
|
463
|
-
|
|
464
|
-
if (typeof method !== 'function') {
|
|
465
|
-
return api;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
return method.bind(
|
|
469
|
-
new Proxy(this, {
|
|
470
|
-
get: (plug, property): any => {
|
|
471
|
-
if (property === feature) {
|
|
472
|
-
return api;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
return plug[property as keyof GlobalPlug];
|
|
476
|
-
},
|
|
477
|
-
}),
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
429
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@croct/sdk/apiKey';
|
package/eap.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { VersionedSlotId } from './slot';
|
|
2
|
-
import { JsonObject } from './sdk/json';
|
|
3
|
-
import { LegacyFetchResponse, Plug } from './plug';
|
|
4
|
-
export interface EapFeatures {
|
|
5
|
-
fetch<P extends JsonObject, I extends VersionedSlotId>(this: Plug, slotId: I): Promise<LegacyFetchResponse<I, P>>;
|
|
6
|
-
}
|
|
7
|
-
interface EapHooks extends EapFeatures {
|
|
8
|
-
initialize(this: Plug): void;
|
|
9
|
-
}
|
|
10
|
-
declare global {
|
|
11
|
-
interface Window {
|
|
12
|
-
croctEap?: Partial<EapHooks>;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export {};
|
package/eap.js
DELETED
package/eap.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eap.js","sourceRoot":"","sources":["src/eap.ts"],"names":[],"mappings":""}
|
package/src/eap.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {VersionedSlotId} from './slot';
|
|
2
|
-
import {JsonObject} from './sdk/json';
|
|
3
|
-
import {LegacyFetchResponse, Plug} from './plug';
|
|
4
|
-
|
|
5
|
-
export interface EapFeatures {
|
|
6
|
-
fetch<P extends JsonObject, I extends VersionedSlotId>(this: Plug, slotId: I): Promise<LegacyFetchResponse<I, P>>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface EapHooks extends EapFeatures{
|
|
10
|
-
initialize(this: Plug): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare global {
|
|
14
|
-
interface Window {
|
|
15
|
-
croctEap?: Partial<EapHooks>;
|
|
16
|
-
}
|
|
17
|
-
}
|