@monterosa/sdk-interact-kit 0.19.0-rc.6 → 2.0.0-rc.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.
- package/dist/core/element/factory.d.ts +3 -3
- package/dist/core/project/api.d.ts +1 -5
- package/dist/index.cjs.js +127 -99
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +48 -49
- package/dist/index.esm.js.map +1 -1
- package/package.json +10 -6
- package/dist/core/project/internal.d.ts +0 -10
|
@@ -12,8 +12,8 @@ import { ElementContext } from './context';
|
|
|
12
12
|
import { InteractEvent } from '../event/public-types';
|
|
13
13
|
import { Answer } from './answer';
|
|
14
14
|
export declare const elements: Map<string, InteractElement>;
|
|
15
|
-
export declare function buildElement(options: ElementOptions, context: ElementContext): InteractElement
|
|
15
|
+
export declare function buildElement(options: ElementOptions, context: ElementContext): Promise<InteractElement>;
|
|
16
16
|
export declare function configureEvent(event: InteractEvent): Promise<void>;
|
|
17
17
|
export declare function sendAnswer(element: InteractElement, userAnswer: Answer): Promise<void>;
|
|
18
|
-
export declare function storeAnswer(element: InteractElement, userAnswer: Answer): void
|
|
19
|
-
export declare function restoreAnswer(element: InteractElement): void
|
|
18
|
+
export declare function storeAnswer(element: InteractElement, userAnswer: Answer): Promise<void>;
|
|
19
|
+
export declare function restoreAnswer(element: InteractElement): Promise<void>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { MonterosaSdk } from '@monterosa/sdk-core';
|
|
10
10
|
import { Unsubscribe } from '@monterosa/sdk-util';
|
|
11
|
-
import { InteractProject
|
|
11
|
+
import { InteractProject } from './public-types';
|
|
12
12
|
/**
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
@@ -18,10 +18,6 @@ declare const getProjectMemoized: (...args: any[]) => Promise<InteractProject>;
|
|
|
18
18
|
* with the {@link @monterosa/sdk-core#MonterosaSdk | configured sdk}
|
|
19
19
|
*/
|
|
20
20
|
declare function getProject(sdk?: MonterosaSdk): Promise<InteractProject>;
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
export declare function fetchListings(host: string, projectId: string): Promise<Listings>;
|
|
25
21
|
/**
|
|
26
22
|
* Adds an observer for when {@link InteractProject.fields | project fields}
|
|
27
23
|
* are updated
|
package/dist/index.cjs.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var sdkConnectKit = require('@monterosa/sdk-connect-kit');
|
|
6
6
|
var sdkUtil = require('@monterosa/sdk-util');
|
|
7
7
|
var sdkCore = require('@monterosa/sdk-core');
|
|
8
|
+
var sdkInteractInterop = require('@monterosa/sdk-interact-interop');
|
|
9
|
+
var sdkStorageKit = require('@monterosa/sdk-storage-kit');
|
|
8
10
|
|
|
9
11
|
/******************************************************************************
|
|
10
12
|
Copyright (c) Microsoft Corporation.
|
|
@@ -493,31 +495,6 @@ function onConnectionHealthState(connectionHealth, callback) {
|
|
|
493
495
|
return sdkUtil.subscribe(connectionHealth, 'state', callback);
|
|
494
496
|
}
|
|
495
497
|
|
|
496
|
-
/**
|
|
497
|
-
* @license
|
|
498
|
-
* @monterosa/sdk-interact-kit
|
|
499
|
-
*
|
|
500
|
-
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
501
|
-
*
|
|
502
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
503
|
-
*/
|
|
504
|
-
function fetchSettings(host, id) {
|
|
505
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
506
|
-
var response, data;
|
|
507
|
-
return __generator(this, function (_a) {
|
|
508
|
-
switch (_a.label) {
|
|
509
|
-
case 0: return [4 /*yield*/, fetch("https://".concat(host, "/projects/").concat(id.substring(0, 2), "/").concat(id, "/settings.json"))];
|
|
510
|
-
case 1:
|
|
511
|
-
response = _a.sent();
|
|
512
|
-
return [4 /*yield*/, response.json()];
|
|
513
|
-
case 2:
|
|
514
|
-
data = _a.sent();
|
|
515
|
-
return [2 /*return*/, data];
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
|
|
521
498
|
/**
|
|
522
499
|
* @license
|
|
523
500
|
* @monterosa/sdk-interact-kit
|
|
@@ -868,7 +845,7 @@ function buildProject(options, context) {
|
|
|
868
845
|
throw new Error("Unable to fetch project ".concat(id, " listings. Possibly wrong project id."));
|
|
869
846
|
}
|
|
870
847
|
_a = project;
|
|
871
|
-
return [4 /*yield*/, fetchSettings(project.host, project.id)];
|
|
848
|
+
return [4 /*yield*/, sdkInteractInterop.fetchSettings(project.host, project.id)];
|
|
872
849
|
case 4:
|
|
873
850
|
_a.fields = _b.sent();
|
|
874
851
|
return [2 /*return*/, project];
|
|
@@ -952,7 +929,7 @@ function handleListings(project, data) {
|
|
|
952
929
|
_d.trys.push([1, 4, , 5]);
|
|
953
930
|
if (!(oldDigest !== undefined && newDigest !== oldDigest)) return [3 /*break*/, 3];
|
|
954
931
|
_b = project;
|
|
955
|
-
return [4 /*yield*/, fetchSettings(project.host, project.id)];
|
|
932
|
+
return [4 /*yield*/, sdkInteractInterop.fetchSettings(project.host, project.id)];
|
|
956
933
|
case 2:
|
|
957
934
|
_b.fields = _d.sent();
|
|
958
935
|
_d.label = 3;
|
|
@@ -1002,25 +979,6 @@ function getProject(sdk) {
|
|
|
1002
979
|
if (sdk === void 0) { sdk = sdkCore.getSdk(); }
|
|
1003
980
|
return getProjectMemoized(sdk);
|
|
1004
981
|
}
|
|
1005
|
-
/**
|
|
1006
|
-
* @internal
|
|
1007
|
-
*/
|
|
1008
|
-
function fetchListings(host, projectId) {
|
|
1009
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1010
|
-
var response, data;
|
|
1011
|
-
return __generator(this, function (_a) {
|
|
1012
|
-
switch (_a.label) {
|
|
1013
|
-
case 0: return [4 /*yield*/, fetch("https://".concat(host, "/projects/").concat(projectId.substring(0, 2), "/").concat(projectId, "/listings.json"))];
|
|
1014
|
-
case 1:
|
|
1015
|
-
response = _a.sent();
|
|
1016
|
-
return [4 /*yield*/, response.json()];
|
|
1017
|
-
case 2:
|
|
1018
|
-
data = (_a.sent());
|
|
1019
|
-
return [2 /*return*/, data];
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
982
|
/**
|
|
1025
983
|
* Adds an observer for when {@link InteractProject.fields | project fields}
|
|
1026
984
|
* are updated
|
|
@@ -2024,6 +1982,7 @@ var ElementImpl = /** @class */ (function (_super) {
|
|
|
2024
1982
|
};
|
|
2025
1983
|
ElementImpl.prototype.update = function (data) {
|
|
2026
1984
|
this._data = data;
|
|
1985
|
+
this.handleState();
|
|
2027
1986
|
};
|
|
2028
1987
|
ElementImpl.prototype.destroy = function () {
|
|
2029
1988
|
this.unsubscribeStateHandler();
|
|
@@ -2271,15 +2230,24 @@ var ElementImpl = /** @class */ (function (_super) {
|
|
|
2271
2230
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
2272
2231
|
*/
|
|
2273
2232
|
var elements = new Map();
|
|
2274
|
-
var storageAvailable = sdkUtil.checkAvailability();
|
|
2275
2233
|
function buildElement(options, context) {
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2234
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2235
|
+
var element;
|
|
2236
|
+
return __generator(this, function (_a) {
|
|
2237
|
+
switch (_a.label) {
|
|
2238
|
+
case 0:
|
|
2239
|
+
if (elements.has(options.id)) {
|
|
2240
|
+
return [2 /*return*/, elements.get(options.id)];
|
|
2241
|
+
}
|
|
2242
|
+
element = new ElementImpl(options, context);
|
|
2243
|
+
return [4 /*yield*/, restoreAnswer(element)];
|
|
2244
|
+
case 1:
|
|
2245
|
+
_a.sent();
|
|
2246
|
+
elements.set(element.id, element);
|
|
2247
|
+
return [2 /*return*/, element];
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
});
|
|
2283
2251
|
}
|
|
2284
2252
|
function getElementByPolld(pollId) {
|
|
2285
2253
|
return Array.from(elements.values()).find(function (element) { return element.pollId === pollId; });
|
|
@@ -2378,19 +2346,28 @@ function handleCreateMessage(message) {
|
|
|
2378
2346
|
if (event === null) {
|
|
2379
2347
|
return [2 /*return*/];
|
|
2380
2348
|
}
|
|
2381
|
-
if (elements.has(options.id))
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2349
|
+
if (!elements.has(options.id)) return [3 /*break*/, 2];
|
|
2350
|
+
element = elements.get(options.id);
|
|
2351
|
+
if (options.updated_at > element.updatedAt ||
|
|
2352
|
+
// This is a workaround to handle a Studio issue when two /create/ messages
|
|
2353
|
+
// are sent upon correct option reveal. The first /create/ message contains
|
|
2354
|
+
// the same duration but a different updated_at timestamp. The second /create/
|
|
2355
|
+
// message contains the same updated_at timestamp but a different duration.
|
|
2356
|
+
// Therefore, we need to check if the duration is different to ensure that
|
|
2357
|
+
// the element is updated correctly.
|
|
2358
|
+
options.duration !== element.duration) {
|
|
2359
|
+
element.update(options);
|
|
2360
|
+
event.emit('update', element);
|
|
2392
2361
|
}
|
|
2393
|
-
return [
|
|
2362
|
+
return [3 /*break*/, 4];
|
|
2363
|
+
case 2:
|
|
2364
|
+
context = __assign(__assign({}, event.context), { event: event });
|
|
2365
|
+
return [4 /*yield*/, buildElement(options, context)];
|
|
2366
|
+
case 3:
|
|
2367
|
+
element = _a.sent();
|
|
2368
|
+
event.emit('publish', element);
|
|
2369
|
+
_a.label = 4;
|
|
2370
|
+
case 4: return [2 /*return*/];
|
|
2394
2371
|
}
|
|
2395
2372
|
});
|
|
2396
2373
|
});
|
|
@@ -2439,32 +2416,70 @@ function handleRevealMessage(message) {
|
|
|
2439
2416
|
if (!element) {
|
|
2440
2417
|
return;
|
|
2441
2418
|
}
|
|
2442
|
-
element.correctOption
|
|
2443
|
-
|
|
2419
|
+
if (element.correctOption !== correctOption) {
|
|
2420
|
+
element.correctOption = correctOption;
|
|
2421
|
+
element.context.event.emit('update', element);
|
|
2422
|
+
}
|
|
2444
2423
|
}
|
|
2445
2424
|
function handleEventHistory(history) {
|
|
2425
|
+
var _a, e_1, _b, _c;
|
|
2446
2426
|
return __awaiter(this, void 0, void 0, function () {
|
|
2447
|
-
var event, context,
|
|
2448
|
-
return __generator(this, function (
|
|
2449
|
-
switch (
|
|
2427
|
+
var event, context, _d, _e, _f, snapshot, e_1_1;
|
|
2428
|
+
return __generator(this, function (_g) {
|
|
2429
|
+
switch (_g.label) {
|
|
2450
2430
|
case 0:
|
|
2451
2431
|
if (history.timeline.length === 0) {
|
|
2452
2432
|
return [2 /*return*/];
|
|
2453
2433
|
}
|
|
2454
2434
|
return [4 /*yield*/, getEvent(history.config.id)];
|
|
2455
2435
|
case 1:
|
|
2456
|
-
event =
|
|
2436
|
+
event = _g.sent();
|
|
2457
2437
|
if (event === null) {
|
|
2458
2438
|
return [2 /*return*/];
|
|
2459
2439
|
}
|
|
2460
2440
|
context = __assign(__assign({}, event.context), { event: event });
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2441
|
+
_g.label = 2;
|
|
2442
|
+
case 2:
|
|
2443
|
+
_g.trys.push([2, 11, 12, 17]);
|
|
2444
|
+
_d = true, _e = __asyncValues(history.timeline);
|
|
2445
|
+
_g.label = 3;
|
|
2446
|
+
case 3: return [4 /*yield*/, _e.next()];
|
|
2447
|
+
case 4:
|
|
2448
|
+
if (!(_f = _g.sent(), _a = _f.done, !_a)) return [3 /*break*/, 10];
|
|
2449
|
+
_c = _f.value;
|
|
2450
|
+
_d = false;
|
|
2451
|
+
_g.label = 5;
|
|
2452
|
+
case 5:
|
|
2453
|
+
_g.trys.push([5, , 8, 9]);
|
|
2454
|
+
snapshot = _c;
|
|
2455
|
+
if (!!elements.has(snapshot.id)) return [3 /*break*/, 7];
|
|
2456
|
+
return [4 /*yield*/, buildElement(snapshot, context)];
|
|
2457
|
+
case 6:
|
|
2458
|
+
_g.sent();
|
|
2459
|
+
_g.label = 7;
|
|
2460
|
+
case 7: return [3 /*break*/, 9];
|
|
2461
|
+
case 8:
|
|
2462
|
+
_d = true;
|
|
2463
|
+
return [7 /*endfinally*/];
|
|
2464
|
+
case 9: return [3 /*break*/, 3];
|
|
2465
|
+
case 10: return [3 /*break*/, 17];
|
|
2466
|
+
case 11:
|
|
2467
|
+
e_1_1 = _g.sent();
|
|
2468
|
+
e_1 = { error: e_1_1 };
|
|
2469
|
+
return [3 /*break*/, 17];
|
|
2470
|
+
case 12:
|
|
2471
|
+
_g.trys.push([12, , 15, 16]);
|
|
2472
|
+
if (!(!_d && !_a && (_b = _e.return))) return [3 /*break*/, 14];
|
|
2473
|
+
return [4 /*yield*/, _b.call(_e)];
|
|
2474
|
+
case 13:
|
|
2475
|
+
_g.sent();
|
|
2476
|
+
_g.label = 14;
|
|
2477
|
+
case 14: return [3 /*break*/, 16];
|
|
2478
|
+
case 15:
|
|
2479
|
+
if (e_1) throw e_1.error;
|
|
2480
|
+
return [7 /*endfinally*/];
|
|
2481
|
+
case 16: return [7 /*endfinally*/];
|
|
2482
|
+
case 17: return [2 /*return*/];
|
|
2468
2483
|
}
|
|
2469
2484
|
});
|
|
2470
2485
|
});
|
|
@@ -2493,27 +2508,41 @@ function sendAnswer(element, userAnswer) {
|
|
|
2493
2508
|
});
|
|
2494
2509
|
}
|
|
2495
2510
|
function storeAnswer(element, userAnswer) {
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2511
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2512
|
+
var err_1;
|
|
2513
|
+
return __generator(this, function (_a) {
|
|
2514
|
+
switch (_a.label) {
|
|
2515
|
+
case 0:
|
|
2516
|
+
_a.trys.push([0, 2, , 3]);
|
|
2517
|
+
element.userAnswer = userAnswer;
|
|
2518
|
+
return [4 /*yield*/, sdkStorageKit.storageWrite("element_".concat(element.id, "_vote"), JSON.stringify(userAnswer))];
|
|
2519
|
+
case 1:
|
|
2520
|
+
_a.sent();
|
|
2521
|
+
return [3 /*break*/, 3];
|
|
2522
|
+
case 2:
|
|
2523
|
+
err_1 = _a.sent();
|
|
2524
|
+
console.warn("Failed to store user answer: ".concat(sdkUtil.getErrorMessage(err_1)));
|
|
2525
|
+
return [3 /*break*/, 3];
|
|
2526
|
+
case 3: return [2 /*return*/];
|
|
2527
|
+
}
|
|
2528
|
+
});
|
|
2529
|
+
});
|
|
2509
2530
|
}
|
|
2510
2531
|
function restoreAnswer(element) {
|
|
2511
|
-
|
|
2512
|
-
var userAnswer
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2532
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2533
|
+
var userAnswer;
|
|
2534
|
+
return __generator(this, function (_a) {
|
|
2535
|
+
switch (_a.label) {
|
|
2536
|
+
case 0: return [4 /*yield*/, sdkStorageKit.storageRead("element_".concat(element.id, "_vote"))];
|
|
2537
|
+
case 1:
|
|
2538
|
+
userAnswer = _a.sent();
|
|
2539
|
+
if (userAnswer !== null) {
|
|
2540
|
+
element.userAnswer = Answer.fromJSON(userAnswer);
|
|
2541
|
+
}
|
|
2542
|
+
return [2 /*return*/];
|
|
2543
|
+
}
|
|
2544
|
+
});
|
|
2545
|
+
});
|
|
2517
2546
|
}
|
|
2518
2547
|
|
|
2519
2548
|
/**
|
|
@@ -2898,7 +2927,6 @@ exports.ElementImpl = ElementImpl;
|
|
|
2898
2927
|
exports.EventImpl = EventImpl;
|
|
2899
2928
|
exports.ProjectImpl = ProjectImpl;
|
|
2900
2929
|
exports.answer = answer;
|
|
2901
|
-
exports.fetchListings = fetchListings;
|
|
2902
2930
|
exports.getConnect = getConnect;
|
|
2903
2931
|
exports.getConnectionHealth = getConnectionHealth;
|
|
2904
2932
|
exports.getElement = getElement;
|