@screeb/sdk-vue 0.1.1

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.
@@ -0,0 +1,376 @@
1
+ import { reactive, watch, inject } from 'vue';
2
+ import * as Screeb from '@screeb/sdk-browser';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol */
19
+
20
+
21
+ var __assign = function() {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign.apply(this, arguments);
30
+ };
31
+
32
+ function __awaiter(thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ }
41
+
42
+ function __generator(thisArg, body) {
43
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
44
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
45
+ function verb(n) { return function (v) { return step([n, v]); }; }
46
+ function step(op) {
47
+ if (f) throw new TypeError("Generator is already executing.");
48
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
49
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
50
+ if (y = 0, t) op = [op[0] & 2, t.value];
51
+ switch (op[0]) {
52
+ case 0: case 1: t = op; break;
53
+ case 4: _.label++; return { value: op[1], done: false };
54
+ case 5: _.label++; y = op[1]; op = [0]; continue;
55
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
56
+ default:
57
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
58
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
59
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
60
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
61
+ if (t[2]) _.ops.pop();
62
+ _.trys.pop(); continue;
63
+ }
64
+ op = body.call(thisArg, _);
65
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
66
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
67
+ }
68
+ }
69
+
70
+ function __spreadArray(to, from, pack) {
71
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
72
+ if (ar || !(i in from)) {
73
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
74
+ ar[i] = from[i];
75
+ }
76
+ }
77
+ return to.concat(ar || Array.prototype.slice.call(from));
78
+ }
79
+
80
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
81
+ var e = new Error(message);
82
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
83
+ };
84
+
85
+ var CONSTANTS = { version: "0.0.0-dev" };
86
+
87
+ var log = function (level, message) {
88
+ var packageName = "[@screeb/vue-sdk]";
89
+ switch (level) {
90
+ case "info":
91
+ // eslint-disable-next-line no-console
92
+ console.log("".concat(packageName, " ").concat(message));
93
+ break;
94
+ case "warn":
95
+ // eslint-disable-next-line no-console
96
+ console.warn("".concat(packageName, " ").concat(message));
97
+ break;
98
+ case "error":
99
+ // eslint-disable-next-line no-console
100
+ console.error("".concat(packageName, " ").concat(message));
101
+ break;
102
+ default:
103
+ // eslint-disable-next-line no-console
104
+ console.log("".concat(packageName, " ").concat(message));
105
+ }
106
+ };
107
+
108
+ var isSSR = typeof window === "undefined";
109
+
110
+ var SCREEB_PLUGIN_KEY = Symbol("screeb");
111
+ var isInitialized = false;
112
+ var ScreebPlugin = {
113
+ install: function (app, config) {
114
+ var _this = this;
115
+ var _a;
116
+ var reactiveConfig = reactive(config);
117
+ var ensureScreeb = function (functionName_1, callback_1) {
118
+ return __awaiter(this, arguments, void 0, function (functionName, callback, onlyLoaded) {
119
+ var shouldLoad, message, message;
120
+ var _a;
121
+ if (onlyLoaded === void 0) { onlyLoaded = false; }
122
+ return __generator(this, function (_b) {
123
+ shouldLoad = (_a = reactiveConfig.shouldLoad) !== null && _a !== void 0 ? _a : true;
124
+ if (!Screeb.isLoaded() && !shouldLoad) {
125
+ message = "Screeb instance is not loaded because `shouldLoad` is set to `false` in `ScreebPlugin`";
126
+ log("warn", message);
127
+ return [2 /*return*/, Promise.reject(message)];
128
+ }
129
+ if (!isInitialized && !onlyLoaded) {
130
+ message = [
131
+ "\"".concat(functionName, "\" was called but Screeb has not been initialized yet. "),
132
+ "Please call 'init' before calling '".concat(functionName, "' or "),
133
+ "set 'autoInit' to true in the ScreebPlugin config.",
134
+ ].join("");
135
+ log("warn", message);
136
+ return [2 /*return*/, Promise.reject(message)];
137
+ }
138
+ return [2 /*return*/, Promise.resolve(callback())];
139
+ });
140
+ });
141
+ };
142
+ var close = function () { return __awaiter(_this, void 0, void 0, function () {
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ if (!Screeb.isLoaded()) return [3 /*break*/, 2];
147
+ return [4 /*yield*/, Screeb.close()];
148
+ case 1:
149
+ _a.sent();
150
+ isInitialized = false;
151
+ _a.label = 2;
152
+ case 2: return [2 /*return*/];
153
+ }
154
+ });
155
+ }); };
156
+ var debug = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0: return [4 /*yield*/, ensureScreeb("debug", function () { return Screeb.debug(); })];
159
+ case 1: return [2 /*return*/, _a.sent()];
160
+ }
161
+ }); }); };
162
+ var eventTrack = function (eventName, eventProperties) { return __awaiter(_this, void 0, void 0, function () {
163
+ return __generator(this, function (_a) {
164
+ switch (_a.label) {
165
+ case 0: return [4 /*yield*/, ensureScreeb("eventTrack", function () {
166
+ return Screeb.eventTrack(eventName, eventProperties);
167
+ })];
168
+ case 1: return [2 /*return*/, _a.sent()];
169
+ }
170
+ });
171
+ }); };
172
+ var identity = function (userId, userProperties) { return __awaiter(_this, void 0, void 0, function () {
173
+ return __generator(this, function (_a) {
174
+ switch (_a.label) {
175
+ case 0: return [4 /*yield*/, ensureScreeb("identity", function () {
176
+ return Screeb.identity(userId, userProperties);
177
+ })];
178
+ case 1: return [2 /*return*/, _a.sent()];
179
+ }
180
+ });
181
+ }); };
182
+ var identityGet = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0: return [4 /*yield*/, ensureScreeb("identityGet", function () { return Screeb.identityGet(); })];
185
+ case 1: return [2 /*return*/, _a.sent()];
186
+ }
187
+ }); }); };
188
+ var identityGroupAssign = function (groupName, groupType, groupProperties) { return __awaiter(_this, void 0, void 0, function () {
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, ensureScreeb("identityGroupAssign", function () {
192
+ return Screeb.identityGroupAssign(groupName, groupType, groupProperties);
193
+ })];
194
+ case 1: return [2 /*return*/, _a.sent()];
195
+ }
196
+ });
197
+ }); };
198
+ var identityGroupUnassign = function (groupName, groupType) { return __awaiter(_this, void 0, void 0, function () {
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0: return [4 /*yield*/, ensureScreeb("identityGroupUnassign", function () {
202
+ return Screeb.identityGroupUnassign(groupName, groupType);
203
+ })];
204
+ case 1: return [2 /*return*/, _a.sent()];
205
+ }
206
+ });
207
+ }); };
208
+ var identityProperties = function (userProperties) { return __awaiter(_this, void 0, void 0, function () {
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0: return [4 /*yield*/, ensureScreeb("identityProperties", function () {
212
+ return Screeb.identityProperties(userProperties);
213
+ })];
214
+ case 1: return [2 /*return*/, _a.sent()];
215
+ }
216
+ });
217
+ }); };
218
+ var identityReset = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
219
+ switch (_a.label) {
220
+ case 0: return [4 /*yield*/, ensureScreeb("identityReset", function () { return Screeb.identityReset(); })];
221
+ case 1: return [2 /*return*/, _a.sent()];
222
+ }
223
+ }); }); };
224
+ var init = function (websiteId, userId, userProperties, hooks, language) { return __awaiter(_this, void 0, void 0, function () {
225
+ return __generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0: return [4 /*yield*/, ensureScreeb("init", function () {
228
+ if (!isInitialized) {
229
+ Screeb.init(websiteId, userId, userProperties, hooks, language);
230
+ isInitialized = true;
231
+ }
232
+ }, true)];
233
+ case 1:
234
+ _a.sent();
235
+ return [2 /*return*/];
236
+ }
237
+ });
238
+ }); };
239
+ var load = function (options) { return __awaiter(_this, void 0, void 0, function () {
240
+ var _a;
241
+ return __generator(this, function (_b) {
242
+ switch (_b.label) {
243
+ case 0:
244
+ if (!!Screeb.isLoaded()) return [3 /*break*/, 3];
245
+ Screeb.load(__assign({ sdkName: "sdk-vue", sdkVersion: CONSTANTS.version }, options));
246
+ if (!((_a = reactiveConfig.autoInit) !== null && _a !== void 0 ? _a : false)) return [3 /*break*/, 3];
247
+ if (!reactiveConfig.websiteId) return [3 /*break*/, 2];
248
+ return [4 /*yield*/, init(reactiveConfig.websiteId, reactiveConfig.userId, reactiveConfig.userProperties, reactiveConfig.hooks, reactiveConfig.language)];
249
+ case 1:
250
+ _b.sent();
251
+ return [3 /*break*/, 3];
252
+ case 2:
253
+ log("warn", "autoInit is set to true, but no websiteId have been provided.");
254
+ _b.label = 3;
255
+ case 3: return [2 /*return*/];
256
+ }
257
+ });
258
+ }); };
259
+ var surveyClose = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
260
+ switch (_a.label) {
261
+ case 0: return [4 /*yield*/, ensureScreeb("surveyClose", function () { return Screeb.surveyClose(); })];
262
+ case 1: return [2 /*return*/, _a.sent()];
263
+ }
264
+ }); }); };
265
+ var surveyStart = function (surveyId, distributionId, allowMultipleResponses, hiddenFields, hooks, language, selectors) { return __awaiter(_this, void 0, void 0, function () {
266
+ return __generator(this, function (_a) {
267
+ switch (_a.label) {
268
+ case 0: return [4 /*yield*/, ensureScreeb("surveyStart", function () {
269
+ return Screeb.surveyStart(surveyId, distributionId, allowMultipleResponses, hiddenFields, hooks, language, selectors);
270
+ })];
271
+ case 1: return [2 /*return*/, _a.sent()];
272
+ }
273
+ });
274
+ }); };
275
+ var messageClose = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0: return [4 /*yield*/, ensureScreeb("messageClose", function () { return Screeb.messageClose(); })];
278
+ case 1: return [2 /*return*/, _a.sent()];
279
+ }
280
+ }); }); };
281
+ var messageStart = function (messageId_1) {
282
+ var args_1 = [];
283
+ for (var _i = 1; _i < arguments.length; _i++) {
284
+ args_1[_i - 1] = arguments[_i];
285
+ }
286
+ return __awaiter(_this, __spreadArray([messageId_1], args_1, true), void 0, function (messageId, allowMultipleResponses, hiddenFields, hooks, language) {
287
+ if (allowMultipleResponses === void 0) { allowMultipleResponses = true; }
288
+ return __generator(this, function (_a) {
289
+ switch (_a.label) {
290
+ case 0: return [4 /*yield*/, ensureScreeb("messageStart", function () {
291
+ return Screeb.messageStart(messageId, allowMultipleResponses, hiddenFields, hooks, language);
292
+ })];
293
+ case 1: return [2 /*return*/, _a.sent()];
294
+ }
295
+ });
296
+ });
297
+ };
298
+ var sessionReplayStop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
299
+ switch (_a.label) {
300
+ case 0: return [4 /*yield*/, ensureScreeb("sessionReplayStop", function () { return Screeb.sessionReplayStop(); })];
301
+ case 1: return [2 /*return*/, _a.sent()];
302
+ }
303
+ }); }); };
304
+ var sessionReplayStart = function () { return __awaiter(_this, void 0, void 0, function () {
305
+ return __generator(this, function (_a) {
306
+ switch (_a.label) {
307
+ case 0: return [4 /*yield*/, ensureScreeb("sessionReplayStart", function () {
308
+ return Screeb.sessionReplayStart();
309
+ })];
310
+ case 1: return [2 /*return*/, _a.sent()];
311
+ }
312
+ });
313
+ }); };
314
+ var targetingCheck = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
315
+ switch (_a.label) {
316
+ case 0: return [4 /*yield*/, ensureScreeb("targetingCheck", function () { return Screeb.targetingCheck(); })];
317
+ case 1: return [2 /*return*/, _a.sent()];
318
+ }
319
+ }); }); };
320
+ var targetingDebug = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
321
+ switch (_a.label) {
322
+ case 0: return [4 /*yield*/, ensureScreeb("targetingDebug", function () { return Screeb.targetingDebug(); })];
323
+ case 1: return [2 /*return*/, _a.sent()];
324
+ }
325
+ }); }); };
326
+ watch(function () { return reactiveConfig.userId; }, function (newId, oldId) {
327
+ if (!isInitialized)
328
+ return;
329
+ if (newId === oldId)
330
+ return;
331
+ if (newId) {
332
+ Screeb.identity(newId);
333
+ }
334
+ else {
335
+ Screeb.identityReset();
336
+ }
337
+ });
338
+ var context = {
339
+ close: close,
340
+ debug: debug,
341
+ eventTrack: eventTrack,
342
+ identity: identity,
343
+ identityGet: identityGet,
344
+ identityGroupAssign: identityGroupAssign,
345
+ identityGroupUnassign: identityGroupUnassign,
346
+ identityProperties: identityProperties,
347
+ identityReset: identityReset,
348
+ init: init,
349
+ load: load,
350
+ surveyClose: surveyClose,
351
+ surveyStart: surveyStart,
352
+ messageClose: messageClose,
353
+ messageStart: messageStart,
354
+ sessionReplayStop: sessionReplayStop,
355
+ sessionReplayStart: sessionReplayStart,
356
+ targetingCheck: targetingCheck,
357
+ targetingDebug: targetingDebug,
358
+ };
359
+ app.provide(SCREEB_PLUGIN_KEY, context);
360
+ if (!isSSR && ((_a = reactiveConfig.shouldLoad) !== null && _a !== void 0 ? _a : true)) {
361
+ load(reactiveConfig.options);
362
+ }
363
+ },
364
+ };
365
+
366
+ function useScreeb() {
367
+ var context = inject(SCREEB_PLUGIN_KEY);
368
+ if (!context) {
369
+ // eslint-disable-next-line no-console
370
+ console.warn("`useScreeb` must be called inside a component tree where ScreebPlugin is installed.");
371
+ }
372
+ return context;
373
+ }
374
+
375
+ export { SCREEB_PLUGIN_KEY, ScreebPlugin, useScreeb };
376
+ CONSTANTS.version = '0.1.1'
@@ -0,0 +1,3 @@
1
+ type LogLevel = "info" | "error" | "warn";
2
+ export declare const log: (level: LogLevel, message: string) => void;
3
+ export {};
@@ -0,0 +1,4 @@
1
+ import { InjectionKey, Plugin } from "vue";
2
+ import { ScreebContextValues } from "./types";
3
+ export declare const SCREEB_PLUGIN_KEY: InjectionKey<ScreebContextValues>;
4
+ export declare const ScreebPlugin: Plugin;
@@ -0,0 +1,69 @@
1
+ import { HooksInit, HooksMessageStart, HooksSurveyStart, PropertyRecord, ScreebIdentityGetReturn, ScreebOptions } from "@screeb/sdk-browser";
2
+ /** Configuration for the ScreebPlugin */
3
+ export type ScreebConfig = {
4
+ /** Your website/channel id. */
5
+ websiteId: string;
6
+ /** The unique identifier of your user. */
7
+ userId?: string;
8
+ /** The properties of your user. */
9
+ userProperties?: PropertyRecord;
10
+ /** Hooks to define callback for various Screeb events */
11
+ hooks?: HooksInit;
12
+ /** Force a specific language (e.g. 'en'). Default: browser language. */
13
+ language?: string;
14
+ /**
15
+ * Indicates if Screeb should be automatically loaded.
16
+ * Set to false to prevent the SDK from loading (e.g. in CI).
17
+ * @default true
18
+ */
19
+ shouldLoad?: boolean;
20
+ /**
21
+ * Indicates if Screeb should be automatically initialized.
22
+ * When true, `init` is called automatically with `websiteId` and `userId`.
23
+ * @default false
24
+ */
25
+ autoInit?: boolean;
26
+ /** Screeb tag initialization options — handle with care. */
27
+ options?: ScreebOptions;
28
+ };
29
+ export type CloseFunction = () => Promise<void>;
30
+ export type DebugFunction = () => Promise<unknown>;
31
+ export type EventTrackFunction = (eventName: string, eventProperties?: PropertyRecord) => Promise<unknown>;
32
+ export type IdentityFunction = (userId: string, userProperties?: PropertyRecord) => Promise<unknown>;
33
+ export type IdentityGetFunction = () => Promise<ScreebIdentityGetReturn>;
34
+ export type IdentityGroupAssignFunction = (groupName: string, groupType?: string, groupProperties?: PropertyRecord) => Promise<unknown>;
35
+ export type IdentityGroupUnassignFunction = (groupName: string, groupType?: string) => Promise<unknown>;
36
+ export type IdentityPropertiesFunction = (userProperties: PropertyRecord) => Promise<unknown>;
37
+ export type IdentityResetFunction = () => Promise<unknown>;
38
+ export type InitFunction = (websiteId: string, userId?: string, userProperties?: PropertyRecord, hooks?: HooksInit, language?: string) => Promise<void>;
39
+ export type LoadFunction = (options?: ScreebOptions) => Promise<void>;
40
+ export type SurveyCloseFunction = () => Promise<unknown>;
41
+ export type SurveyStartFunction = (surveyId: string, distributionId?: string, allowMultipleResponses?: boolean, hiddenFields?: PropertyRecord, hooks?: HooksSurveyStart, language?: string, selectors?: string | string[]) => Promise<unknown>;
42
+ export type MessageCloseFunction = () => Promise<unknown>;
43
+ export type MessageStartFunction = (messageId: string, allowMultipleResponses?: boolean, hiddenFields?: PropertyRecord, hooks?: HooksMessageStart, language?: string) => Promise<unknown>;
44
+ export type SessionReplayStopFunction = () => Promise<unknown>;
45
+ export type SessionReplayStartFunction = () => Promise<unknown>;
46
+ export type TargetingCheckFunction = () => Promise<unknown>;
47
+ export type TargetingDebugFunction = () => Promise<unknown>;
48
+ /** All Screeb methods provided via `useScreeb()` */
49
+ export type ScreebContextValues = {
50
+ close: CloseFunction;
51
+ debug: DebugFunction;
52
+ eventTrack: EventTrackFunction;
53
+ identity: IdentityFunction;
54
+ identityGet: IdentityGetFunction;
55
+ identityGroupAssign: IdentityGroupAssignFunction;
56
+ identityGroupUnassign: IdentityGroupUnassignFunction;
57
+ identityProperties: IdentityPropertiesFunction;
58
+ identityReset: IdentityResetFunction;
59
+ init: InitFunction;
60
+ load: LoadFunction;
61
+ surveyClose: SurveyCloseFunction;
62
+ surveyStart: SurveyStartFunction;
63
+ messageClose: MessageCloseFunction;
64
+ messageStart: MessageStartFunction;
65
+ sessionReplayStart: SessionReplayStartFunction;
66
+ sessionReplayStop: SessionReplayStopFunction;
67
+ targetingCheck: TargetingCheckFunction;
68
+ targetingDebug: TargetingDebugFunction;
69
+ };
@@ -0,0 +1 @@
1
+ export declare const isSSR: boolean;
package/docs/.nojekyll ADDED
@@ -0,0 +1 @@
1
+ TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.