@croct/plug 0.10.0 → 0.10.2
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/fetch.d.ts +1 -2
- package/index.js +1 -1
- package/package.json +7 -9
- package/playground.d.ts +4 -4
- package/playground.js +27 -27
- package/plug.js +36 -28
- package/sdk/json.d.ts +2 -2
- package/sdk/json.js +1 -1
package/fetch.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var plug_1 = require("./plug");
|
|
4
|
-
/* eslint-disable-next-line import/no-default-export */
|
|
4
|
+
/* eslint-disable-next-line import/no-default-export -- Should be default export */
|
|
5
5
|
exports.default = new plug_1.GlobalPlug();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/plug",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "A fully-featured devkit for building natively personalized applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -29,29 +29,27 @@
|
|
|
29
29
|
"lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
|
|
30
30
|
"test": "jest -c jest.config.js --coverage",
|
|
31
31
|
"validate": "tsc --noEmit",
|
|
32
|
-
"build": "tsc",
|
|
32
|
+
"build": "tsc -p tsconfig.build.json",
|
|
33
33
|
"bundle": "rollup -c"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@croct/
|
|
36
|
+
"@croct/json": "^1.1.0",
|
|
37
|
+
"@croct/sdk": "^0.10.0",
|
|
37
38
|
"tslib": "^2.2.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@babel/core": "^7.14.3",
|
|
41
42
|
"@babel/preset-env": "^7.14.2",
|
|
42
43
|
"@babel/preset-typescript": "^7.13.0",
|
|
44
|
+
"@croct/eslint-plugin": "^0.6.2",
|
|
43
45
|
"@rollup/plugin-commonjs": "^19.0.0",
|
|
44
46
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
45
47
|
"@rollup/plugin-replace": "^2.4.2",
|
|
46
48
|
"@rollup/plugin-typescript": "^8.2.1",
|
|
47
49
|
"@types/jest": "^26.0.23",
|
|
48
|
-
"@typescript-eslint/
|
|
49
|
-
"@typescript-eslint/parser": "^4.24.0",
|
|
50
|
+
"@typescript-eslint/parser": "^5.30.0",
|
|
50
51
|
"babel-jest": "^26.6.3",
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"eslint-config-airbnb-base": "^14.2.1",
|
|
53
|
-
"eslint-plugin-import": "^2.23.3",
|
|
54
|
-
"eslint-plugin-jest": "^24.3.6",
|
|
52
|
+
"eslint": "^8.18.0",
|
|
55
53
|
"jest": "^26.6.3",
|
|
56
54
|
"rollup": "^2.48.0",
|
|
57
55
|
"rollup-plugin-terser": "^7.0.2",
|
package/playground.d.ts
CHANGED
|
@@ -4,10 +4,6 @@ import { Campaign, Page } from '@croct/sdk/evaluator';
|
|
|
4
4
|
import { Plugin, PluginFactory } from './plugin';
|
|
5
5
|
import { Logger, SdkEventSubscriber, Tab } from './sdk';
|
|
6
6
|
import { TokenProvider } from './sdk/token';
|
|
7
|
-
export declare type Options = {
|
|
8
|
-
connectionId?: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const factory: PluginFactory<Options>;
|
|
11
7
|
export declare type Configuration = {
|
|
12
8
|
appId: string;
|
|
13
9
|
connectionId?: string;
|
|
@@ -52,3 +48,7 @@ export declare class PlaygroundPlugin implements Plugin {
|
|
|
52
48
|
private syncToken;
|
|
53
49
|
private createContext;
|
|
54
50
|
}
|
|
51
|
+
export declare type Options = {
|
|
52
|
+
connectionId?: string;
|
|
53
|
+
};
|
|
54
|
+
export declare const factory: PluginFactory<Options>;
|
package/playground.js
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.factory = exports.PlaygroundPlugin = void 0;
|
|
4
4
|
var error_1 = require("@croct/sdk/error");
|
|
5
5
|
var evaluatorFacade_1 = require("@croct/sdk/facade/evaluatorFacade");
|
|
6
6
|
var constants_1 = require("./constants");
|
|
7
|
-
var factory = function (_a) {
|
|
8
|
-
var sdk = _a.sdk, options = _a.options;
|
|
9
|
-
return new PlaygroundPlugin({
|
|
10
|
-
sdkVersion: sdk.version,
|
|
11
|
-
appId: sdk.appId,
|
|
12
|
-
connectionId: options.connectionId,
|
|
13
|
-
tab: sdk.tab,
|
|
14
|
-
storage: sdk.getTabStorage(),
|
|
15
|
-
tokenProvider: sdk.tokenStore,
|
|
16
|
-
cidAssigner: sdk.cidAssigner,
|
|
17
|
-
contextFactory: new evaluatorFacade_1.TabContextFactory(sdk.tab),
|
|
18
|
-
eventSubscriber: sdk.eventManager,
|
|
19
|
-
logger: sdk.getLogger(),
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
exports.factory = factory;
|
|
23
7
|
var CONNECTION_PARAMETER = '__cplay';
|
|
24
8
|
var PlaygroundPlugin = /** @class */ (function () {
|
|
25
9
|
function PlaygroundPlugin(configuration) {
|
|
@@ -40,15 +24,14 @@ var PlaygroundPlugin = /** @class */ (function () {
|
|
|
40
24
|
if (connectionId === null) {
|
|
41
25
|
return;
|
|
42
26
|
}
|
|
43
|
-
this.syncListener = function () {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
27
|
+
this.syncListener = function () { return _this.cidAssigner
|
|
28
|
+
.assignCid()
|
|
29
|
+
.then(function (cid) {
|
|
30
|
+
_this.syncToken(connectionId, cid);
|
|
31
|
+
})
|
|
32
|
+
.catch(function (error) {
|
|
33
|
+
_this.logger.warn("Sync failed: ".concat((0, error_1.formatCause)(error)));
|
|
34
|
+
}); };
|
|
52
35
|
this.eventSubscriber.addListener('tokenChanged', this.syncListener);
|
|
53
36
|
this.tab.addListener('urlChange', this.syncListener);
|
|
54
37
|
return this.syncListener();
|
|
@@ -116,7 +99,8 @@ var PlaygroundPlugin = /** @class */ (function () {
|
|
|
116
99
|
sdkVersion: _this.sdkVersion,
|
|
117
100
|
tabId: _this.tab.id,
|
|
118
101
|
cid: cid,
|
|
119
|
-
token: (_b = (_a = _this.tokenProvider
|
|
102
|
+
token: (_b = (_a = _this.tokenProvider
|
|
103
|
+
.getToken()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : null,
|
|
120
104
|
context: context,
|
|
121
105
|
};
|
|
122
106
|
iframe.contentWindow.postMessage(payload, constants_1.PLAYGROUND_ORIGIN);
|
|
@@ -150,3 +134,19 @@ var PlaygroundPlugin = /** @class */ (function () {
|
|
|
150
134
|
return PlaygroundPlugin;
|
|
151
135
|
}());
|
|
152
136
|
exports.PlaygroundPlugin = PlaygroundPlugin;
|
|
137
|
+
var factory = function (props) {
|
|
138
|
+
var sdk = props.sdk, options = props.options;
|
|
139
|
+
return new PlaygroundPlugin({
|
|
140
|
+
sdkVersion: sdk.version,
|
|
141
|
+
appId: sdk.appId,
|
|
142
|
+
connectionId: options.connectionId,
|
|
143
|
+
tab: sdk.tab,
|
|
144
|
+
storage: sdk.getTabStorage(),
|
|
145
|
+
tokenProvider: sdk.tokenStore,
|
|
146
|
+
cidAssigner: sdk.cidAssigner,
|
|
147
|
+
contextFactory: new evaluatorFacade_1.TabContextFactory(sdk.tab),
|
|
148
|
+
eventSubscriber: sdk.eventManager,
|
|
149
|
+
logger: sdk.getLogger(),
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
exports.factory = factory;
|
package/plug.js
CHANGED
|
@@ -11,7 +11,7 @@ var constants_1 = require("./constants");
|
|
|
11
11
|
var playground_1 = require("./playground");
|
|
12
12
|
var PLUGIN_NAMESPACE = 'Plugin';
|
|
13
13
|
function detectAppId() {
|
|
14
|
-
var script = window.document.querySelector("script[src^='"
|
|
14
|
+
var script = window.document.querySelector("script[src^='".concat(constants_1.CDN_URL, "']"));
|
|
15
15
|
if (!(script instanceof HTMLScriptElement)) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
@@ -28,7 +28,7 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
28
28
|
}
|
|
29
29
|
GlobalPlug.prototype.extend = function (name, plugin) {
|
|
30
30
|
if (this.pluginFactories[name] !== undefined) {
|
|
31
|
-
throw new Error("Another plugin is already registered with name \""
|
|
31
|
+
throw new Error("Another plugin is already registered with name \"".concat(name, "\"."));
|
|
32
32
|
}
|
|
33
33
|
this.pluginFactories[name] = plugin;
|
|
34
34
|
};
|
|
@@ -66,19 +66,19 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
66
66
|
}
|
|
67
67
|
var pending = [];
|
|
68
68
|
var _loop_1 = function (name_1, options) {
|
|
69
|
-
logger.debug("Initializing plugin \""
|
|
69
|
+
logger.debug("Initializing plugin \"".concat(name_1, "\"..."));
|
|
70
70
|
var factory = this_1.pluginFactories[name_1];
|
|
71
71
|
if (factory === undefined) {
|
|
72
|
-
logger.error("Plugin \""
|
|
72
|
+
logger.error("Plugin \"".concat(name_1, "\" is not registered."));
|
|
73
73
|
return "continue";
|
|
74
74
|
}
|
|
75
75
|
if (typeof options !== 'boolean' && (options === null || typeof options !== 'object')) {
|
|
76
|
-
logger.error("Invalid options for plugin \""
|
|
77
|
-
+
|
|
76
|
+
logger.error("Invalid options for plugin \"".concat(name_1, "\", ")
|
|
77
|
+
+ "expected either boolean or object but got ".concat((0, validation_1.describe)(options)));
|
|
78
78
|
return "continue";
|
|
79
79
|
}
|
|
80
80
|
if (options === false) {
|
|
81
|
-
logger.warn("Plugin \""
|
|
81
|
+
logger.warn("Plugin \"".concat(name_1, "\" is declared but not enabled"));
|
|
82
82
|
return "continue";
|
|
83
83
|
}
|
|
84
84
|
var args = {
|
|
@@ -102,21 +102,21 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
102
102
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
103
103
|
namespace[_i] = arguments[_i];
|
|
104
104
|
}
|
|
105
|
-
return sdk.getLogger.apply(sdk, tslib_1.__spreadArray([PLUGIN_NAMESPACE, name_1], tslib_1.__read(namespace)));
|
|
105
|
+
return sdk.getLogger.apply(sdk, tslib_1.__spreadArray([PLUGIN_NAMESPACE, name_1], tslib_1.__read(namespace), false));
|
|
106
106
|
},
|
|
107
107
|
getTabStorage: function () {
|
|
108
108
|
var namespace = [];
|
|
109
109
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
110
110
|
namespace[_i] = arguments[_i];
|
|
111
111
|
}
|
|
112
|
-
return sdk.getTabStorage.apply(sdk, tslib_1.__spreadArray([PLUGIN_NAMESPACE, name_1], tslib_1.__read(namespace)));
|
|
112
|
+
return (sdk.getTabStorage.apply(sdk, tslib_1.__spreadArray([PLUGIN_NAMESPACE, name_1], tslib_1.__read(namespace), false)));
|
|
113
113
|
},
|
|
114
114
|
getBrowserStorage: function () {
|
|
115
115
|
var namespace = [];
|
|
116
116
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
117
117
|
namespace[_i] = arguments[_i];
|
|
118
118
|
}
|
|
119
|
-
return sdk.getBrowserStorage.apply(sdk, tslib_1.__spreadArray([PLUGIN_NAMESPACE, name_1], tslib_1.__read(namespace)));
|
|
119
|
+
return (sdk.getBrowserStorage.apply(sdk, tslib_1.__spreadArray([PLUGIN_NAMESPACE, name_1], tslib_1.__read(namespace), false)));
|
|
120
120
|
},
|
|
121
121
|
},
|
|
122
122
|
};
|
|
@@ -125,22 +125,21 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
125
125
|
plugin = factory(args);
|
|
126
126
|
}
|
|
127
127
|
catch (error) {
|
|
128
|
-
logger.error("Failed to initialize plugin \""
|
|
128
|
+
logger.error("Failed to initialize plugin \"".concat(name_1, "\": ").concat((0, error_1.formatCause)(error)));
|
|
129
129
|
return "continue";
|
|
130
130
|
}
|
|
131
|
-
logger.debug("Plugin \""
|
|
131
|
+
logger.debug("Plugin \"".concat(name_1, "\" initialized"));
|
|
132
132
|
if (typeof plugin !== 'object') {
|
|
133
133
|
return "continue";
|
|
134
134
|
}
|
|
135
135
|
this_1.plugins[name_1] = plugin;
|
|
136
136
|
var promise = plugin.enable();
|
|
137
137
|
if (!(promise instanceof Promise)) {
|
|
138
|
-
logger.debug("Plugin \""
|
|
138
|
+
logger.debug("Plugin \"".concat(name_1, "\" enabled"));
|
|
139
139
|
return "continue";
|
|
140
140
|
}
|
|
141
|
-
pending.push(promise
|
|
142
|
-
.
|
|
143
|
-
.catch(function (error) { return logger.error("Failed to enable plugin \"" + name_1 + "\": " + error_1.formatCause(error)); }));
|
|
141
|
+
pending.push(promise.then(function () { return logger.debug("Plugin \"".concat(name_1, "\" enabled")); })
|
|
142
|
+
.catch(function (error) { return logger.error("Failed to enable plugin \"".concat(name_1, "\": ").concat((0, error_1.formatCause)(error))); }));
|
|
144
143
|
};
|
|
145
144
|
var this_1 = this;
|
|
146
145
|
try {
|
|
@@ -183,7 +182,9 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
183
182
|
Object.defineProperty(GlobalPlug.prototype, "flushed", {
|
|
184
183
|
get: function () {
|
|
185
184
|
var _this = this;
|
|
186
|
-
return this.tracker
|
|
185
|
+
return this.tracker
|
|
186
|
+
.flushed
|
|
187
|
+
.then(function () { return _this; });
|
|
187
188
|
},
|
|
188
189
|
enumerable: false,
|
|
189
190
|
configurable: true
|
|
@@ -227,10 +228,14 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
227
228
|
configurable: true
|
|
228
229
|
});
|
|
229
230
|
GlobalPlug.prototype.isAnonymous = function () {
|
|
230
|
-
return this.sdk
|
|
231
|
+
return this.sdk
|
|
232
|
+
.context
|
|
233
|
+
.isAnonymous();
|
|
231
234
|
};
|
|
232
235
|
GlobalPlug.prototype.getUserId = function () {
|
|
233
|
-
return this.sdk
|
|
236
|
+
return this.sdk
|
|
237
|
+
.context
|
|
238
|
+
.getUser();
|
|
234
239
|
};
|
|
235
240
|
GlobalPlug.prototype.identify = function (userId) {
|
|
236
241
|
if (typeof userId !== 'string') {
|
|
@@ -248,11 +253,15 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
248
253
|
this.sdk.unsetToken();
|
|
249
254
|
};
|
|
250
255
|
GlobalPlug.prototype.track = function (type, payload) {
|
|
251
|
-
return this.sdk
|
|
256
|
+
return this.sdk
|
|
257
|
+
.tracker
|
|
258
|
+
.track(type, payload);
|
|
252
259
|
};
|
|
253
260
|
GlobalPlug.prototype.evaluate = function (expression, options) {
|
|
254
261
|
if (options === void 0) { options = {}; }
|
|
255
|
-
return this.sdk
|
|
262
|
+
return this.sdk
|
|
263
|
+
.evaluator
|
|
264
|
+
.evaluate(expression, options);
|
|
256
265
|
};
|
|
257
266
|
GlobalPlug.prototype.test = function (expression, options) {
|
|
258
267
|
if (options === void 0) { options = {}; }
|
|
@@ -284,15 +293,14 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
284
293
|
if (typeof controller.disable !== 'function') {
|
|
285
294
|
return "continue";
|
|
286
295
|
}
|
|
287
|
-
logger.debug("Disabling plugin \""
|
|
296
|
+
logger.debug("Disabling plugin \"".concat(pluginName, "\"..."));
|
|
288
297
|
var promise = controller.disable();
|
|
289
298
|
if (!(promise instanceof Promise)) {
|
|
290
|
-
logger.debug("Plugin \""
|
|
299
|
+
logger.debug("Plugin \"".concat(pluginName, "\" disabled"));
|
|
291
300
|
return "continue";
|
|
292
301
|
}
|
|
293
|
-
pending.push(promise
|
|
294
|
-
.
|
|
295
|
-
.catch(function (error) { return logger.error("Failed to disable \"" + pluginName + "\": " + error_1.formatCause(error)); }));
|
|
302
|
+
pending.push(promise.then(function () { return logger.debug("Plugin \"".concat(pluginName, "\" disabled")); })
|
|
303
|
+
.catch(function (error) { return logger.error("Failed to disable \"".concat(pluginName, "\": ").concat((0, error_1.formatCause)(error))); }));
|
|
296
304
|
};
|
|
297
305
|
try {
|
|
298
306
|
for (_b = tslib_1.__values(Object.entries(plugins)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -336,11 +344,11 @@ var GlobalPlug = /** @class */ (function () {
|
|
|
336
344
|
var eap = window.croctEap;
|
|
337
345
|
var method = typeof eap === 'object' ? eap[feature] : undefined;
|
|
338
346
|
if (typeof method !== 'function') {
|
|
339
|
-
throw new Error("The "
|
|
347
|
+
throw new Error("The ".concat(feature, " feature is currently available only to accounts participating in our ")
|
|
340
348
|
+ 'Early-Access Program (EAP). Please contact your Customer Success Manager or email eap@croct.com '
|
|
341
349
|
+ 'to check your account eligibility.');
|
|
342
350
|
}
|
|
343
|
-
logger.warn("The "
|
|
351
|
+
logger.warn("The ".concat(feature, " API is still unstable and subject to change in future releases."));
|
|
344
352
|
return method;
|
|
345
353
|
};
|
|
346
354
|
return GlobalPlug;
|
package/sdk/json.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { JsonObject } from '@croct/
|
|
2
|
-
export * from '@croct/
|
|
1
|
+
import { JsonObject } from '@croct/json';
|
|
2
|
+
export * from '@croct/json/mutable';
|
|
3
3
|
export declare type NullableJsonObject = JsonObject | null;
|
package/sdk/json.js
CHANGED