@monterosa/sdk-interact-kit 0.18.2 → 0.18.3
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/index.cjs.js +106 -99
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +28 -48
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +106 -98
- package/dist/index.esm5.js.map +1 -1
- package/dist/src/core/element/factory.d.ts +3 -3
- package/dist/src/core/project/api.d.ts +1 -5
- package/package.json +10 -6
- package/dist/src/core/project/internal.d.ts +0 -12
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.
|
|
@@ -497,33 +499,6 @@ function onConnectionHealthState(connectionHealth, callback) {
|
|
|
497
499
|
return sdkUtil.subscribe(connectionHealth, 'state', callback);
|
|
498
500
|
}
|
|
499
501
|
|
|
500
|
-
/**
|
|
501
|
-
* @license
|
|
502
|
-
* internal.ts
|
|
503
|
-
* interact-kit
|
|
504
|
-
*
|
|
505
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
|
|
506
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
507
|
-
*
|
|
508
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
509
|
-
*/
|
|
510
|
-
function fetchSettings(host, id) {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
512
|
-
var response, data;
|
|
513
|
-
return __generator(this, function (_a) {
|
|
514
|
-
switch (_a.label) {
|
|
515
|
-
case 0: return [4 /*yield*/, fetch("https://" + host + "/projects/" + id.substring(0, 2) + "/" + id + "/settings.json")];
|
|
516
|
-
case 1:
|
|
517
|
-
response = _a.sent();
|
|
518
|
-
return [4 /*yield*/, response.json()];
|
|
519
|
-
case 2:
|
|
520
|
-
data = _a.sent();
|
|
521
|
-
return [2 /*return*/, data];
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
|
|
527
502
|
/**
|
|
528
503
|
* @license
|
|
529
504
|
* constants.ts
|
|
@@ -821,7 +796,7 @@ function buildProject(options, context) {
|
|
|
821
796
|
throw new Error("Unable to fetch project " + id + " listings. Possibly wrong project id.");
|
|
822
797
|
}
|
|
823
798
|
_a = project;
|
|
824
|
-
return [4 /*yield*/, fetchSettings(project.host, project.id)];
|
|
799
|
+
return [4 /*yield*/, sdkInteractInterop.fetchSettings(project.host, project.id)];
|
|
825
800
|
case 4:
|
|
826
801
|
_a.fields = _b.sent();
|
|
827
802
|
return [2 /*return*/, project];
|
|
@@ -905,7 +880,7 @@ function handleListings(project, data) {
|
|
|
905
880
|
_d.trys.push([1, 4, , 5]);
|
|
906
881
|
if (!(oldDigest !== undefined && newDigest !== oldDigest)) return [3 /*break*/, 3];
|
|
907
882
|
_b = project;
|
|
908
|
-
return [4 /*yield*/, fetchSettings(project.host, project.id)];
|
|
883
|
+
return [4 /*yield*/, sdkInteractInterop.fetchSettings(project.host, project.id)];
|
|
909
884
|
case 2:
|
|
910
885
|
_b.fields = _d.sent();
|
|
911
886
|
_d.label = 3;
|
|
@@ -957,25 +932,6 @@ function getProject(sdk) {
|
|
|
957
932
|
if (sdk === void 0) { sdk = sdkCore.getSdk(); }
|
|
958
933
|
return getProjectMemoized(sdk);
|
|
959
934
|
}
|
|
960
|
-
/**
|
|
961
|
-
* @internal
|
|
962
|
-
*/
|
|
963
|
-
function fetchListings(host, projectId) {
|
|
964
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
965
|
-
var response, data;
|
|
966
|
-
return __generator(this, function (_a) {
|
|
967
|
-
switch (_a.label) {
|
|
968
|
-
case 0: return [4 /*yield*/, fetch("https://" + host + "/projects/" + projectId.substring(0, 2) + "/" + projectId + "/listings.json")];
|
|
969
|
-
case 1:
|
|
970
|
-
response = _a.sent();
|
|
971
|
-
return [4 /*yield*/, response.json()];
|
|
972
|
-
case 2:
|
|
973
|
-
data = (_a.sent());
|
|
974
|
-
return [2 /*return*/, data];
|
|
975
|
-
}
|
|
976
|
-
});
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
935
|
/**
|
|
980
936
|
* Adds an observer for when {@link InteractProject.fields | project fields}
|
|
981
937
|
* are updated
|
|
@@ -2190,15 +2146,24 @@ var ElementImpl = /** @class */ (function (_super) {
|
|
|
2190
2146
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
2191
2147
|
*/
|
|
2192
2148
|
var elements = new Map();
|
|
2193
|
-
var storageAvailable = sdkUtil.checkAvailability();
|
|
2194
2149
|
function buildElement(options, context) {
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2151
|
+
var element;
|
|
2152
|
+
return __generator(this, function (_a) {
|
|
2153
|
+
switch (_a.label) {
|
|
2154
|
+
case 0:
|
|
2155
|
+
if (elements.has(options.id)) {
|
|
2156
|
+
return [2 /*return*/, elements.get(options.id)];
|
|
2157
|
+
}
|
|
2158
|
+
element = new ElementImpl(options, context);
|
|
2159
|
+
return [4 /*yield*/, restoreAnswer(element)];
|
|
2160
|
+
case 1:
|
|
2161
|
+
_a.sent();
|
|
2162
|
+
elements.set(element.id, element);
|
|
2163
|
+
return [2 /*return*/, element];
|
|
2164
|
+
}
|
|
2165
|
+
});
|
|
2166
|
+
});
|
|
2202
2167
|
}
|
|
2203
2168
|
function getElementByPolld(pollId) {
|
|
2204
2169
|
return Array.from(elements.values()).find(function (element) { return element.pollId === pollId; });
|
|
@@ -2297,19 +2262,21 @@ function handleCreateMessage(message) {
|
|
|
2297
2262
|
if (event === null) {
|
|
2298
2263
|
return [2 /*return*/];
|
|
2299
2264
|
}
|
|
2300
|
-
if (elements.has(options.id))
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
else {
|
|
2308
|
-
context = __assign(__assign({}, event.context), { event: event });
|
|
2309
|
-
element = buildElement(options, context);
|
|
2310
|
-
event.emit('publish', element);
|
|
2265
|
+
if (!elements.has(options.id)) return [3 /*break*/, 2];
|
|
2266
|
+
element = elements.get(options.id);
|
|
2267
|
+
if (options.updated_at > element.updatedAt) {
|
|
2268
|
+
element.update(options);
|
|
2269
|
+
event.emit('update', element);
|
|
2311
2270
|
}
|
|
2312
|
-
return [
|
|
2271
|
+
return [3 /*break*/, 4];
|
|
2272
|
+
case 2:
|
|
2273
|
+
context = __assign(__assign({}, event.context), { event: event });
|
|
2274
|
+
return [4 /*yield*/, buildElement(options, context)];
|
|
2275
|
+
case 3:
|
|
2276
|
+
element = _a.sent();
|
|
2277
|
+
event.emit('publish', element);
|
|
2278
|
+
_a.label = 4;
|
|
2279
|
+
case 4: return [2 /*return*/];
|
|
2313
2280
|
}
|
|
2314
2281
|
});
|
|
2315
2282
|
});
|
|
@@ -2362,28 +2329,55 @@ function handleRevealMessage(message) {
|
|
|
2362
2329
|
element.context.event.emit('update', element);
|
|
2363
2330
|
}
|
|
2364
2331
|
function handleEventHistory(history) {
|
|
2332
|
+
var e_1, _a;
|
|
2365
2333
|
return __awaiter(this, void 0, void 0, function () {
|
|
2366
|
-
var event, context,
|
|
2367
|
-
return __generator(this, function (
|
|
2368
|
-
switch (
|
|
2334
|
+
var event, context, _b, _c, snapshot, e_1_1;
|
|
2335
|
+
return __generator(this, function (_d) {
|
|
2336
|
+
switch (_d.label) {
|
|
2369
2337
|
case 0:
|
|
2370
2338
|
if (history.timeline.length === 0) {
|
|
2371
2339
|
return [2 /*return*/];
|
|
2372
2340
|
}
|
|
2373
2341
|
return [4 /*yield*/, getEvent(history.config.id)];
|
|
2374
2342
|
case 1:
|
|
2375
|
-
event =
|
|
2343
|
+
event = _d.sent();
|
|
2376
2344
|
if (event === null) {
|
|
2377
2345
|
return [2 /*return*/];
|
|
2378
2346
|
}
|
|
2379
2347
|
context = __assign(__assign({}, event.context), { event: event });
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2348
|
+
_d.label = 2;
|
|
2349
|
+
case 2:
|
|
2350
|
+
_d.trys.push([2, 8, 9, 14]);
|
|
2351
|
+
_b = __asyncValues(history.timeline);
|
|
2352
|
+
_d.label = 3;
|
|
2353
|
+
case 3: return [4 /*yield*/, _b.next()];
|
|
2354
|
+
case 4:
|
|
2355
|
+
if (!(_c = _d.sent(), !_c.done)) return [3 /*break*/, 7];
|
|
2356
|
+
snapshot = _c.value;
|
|
2357
|
+
if (!!elements.has(snapshot.id)) return [3 /*break*/, 6];
|
|
2358
|
+
return [4 /*yield*/, buildElement(snapshot, context)];
|
|
2359
|
+
case 5:
|
|
2360
|
+
_d.sent();
|
|
2361
|
+
_d.label = 6;
|
|
2362
|
+
case 6: return [3 /*break*/, 3];
|
|
2363
|
+
case 7: return [3 /*break*/, 14];
|
|
2364
|
+
case 8:
|
|
2365
|
+
e_1_1 = _d.sent();
|
|
2366
|
+
e_1 = { error: e_1_1 };
|
|
2367
|
+
return [3 /*break*/, 14];
|
|
2368
|
+
case 9:
|
|
2369
|
+
_d.trys.push([9, , 12, 13]);
|
|
2370
|
+
if (!(_c && !_c.done && (_a = _b.return))) return [3 /*break*/, 11];
|
|
2371
|
+
return [4 /*yield*/, _a.call(_b)];
|
|
2372
|
+
case 10:
|
|
2373
|
+
_d.sent();
|
|
2374
|
+
_d.label = 11;
|
|
2375
|
+
case 11: return [3 /*break*/, 13];
|
|
2376
|
+
case 12:
|
|
2377
|
+
if (e_1) throw e_1.error;
|
|
2378
|
+
return [7 /*endfinally*/];
|
|
2379
|
+
case 13: return [7 /*endfinally*/];
|
|
2380
|
+
case 14: return [2 /*return*/];
|
|
2387
2381
|
}
|
|
2388
2382
|
});
|
|
2389
2383
|
});
|
|
@@ -2412,27 +2406,41 @@ function sendAnswer(element, userAnswer) {
|
|
|
2412
2406
|
});
|
|
2413
2407
|
}
|
|
2414
2408
|
function storeAnswer(element, userAnswer) {
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2410
|
+
var err_1;
|
|
2411
|
+
return __generator(this, function (_a) {
|
|
2412
|
+
switch (_a.label) {
|
|
2413
|
+
case 0:
|
|
2414
|
+
_a.trys.push([0, 2, , 3]);
|
|
2415
|
+
element.userAnswer = userAnswer;
|
|
2416
|
+
return [4 /*yield*/, sdkStorageKit.storageWrite("element_" + element.id + "_vote", JSON.stringify(userAnswer))];
|
|
2417
|
+
case 1:
|
|
2418
|
+
_a.sent();
|
|
2419
|
+
return [3 /*break*/, 3];
|
|
2420
|
+
case 2:
|
|
2421
|
+
err_1 = _a.sent();
|
|
2422
|
+
console.warn("Failed to store user answer: " + sdkUtil.getErrorMessage(err_1));
|
|
2423
|
+
return [3 /*break*/, 3];
|
|
2424
|
+
case 3: return [2 /*return*/];
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2427
|
+
});
|
|
2428
2428
|
}
|
|
2429
2429
|
function restoreAnswer(element) {
|
|
2430
|
-
|
|
2431
|
-
var userAnswer
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2430
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2431
|
+
var userAnswer;
|
|
2432
|
+
return __generator(this, function (_a) {
|
|
2433
|
+
switch (_a.label) {
|
|
2434
|
+
case 0: return [4 /*yield*/, sdkStorageKit.storageRead("element_" + element.id + "_vote")];
|
|
2435
|
+
case 1:
|
|
2436
|
+
userAnswer = _a.sent();
|
|
2437
|
+
if (userAnswer !== null) {
|
|
2438
|
+
element.userAnswer = Answer.fromJSON(userAnswer);
|
|
2439
|
+
}
|
|
2440
|
+
return [2 /*return*/];
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
});
|
|
2436
2444
|
}
|
|
2437
2445
|
|
|
2438
2446
|
/**
|
|
@@ -2627,7 +2635,6 @@ exports.ElementImpl = ElementImpl;
|
|
|
2627
2635
|
exports.EventImpl = EventImpl;
|
|
2628
2636
|
exports.ProjectImpl = ProjectImpl;
|
|
2629
2637
|
exports.answer = answer;
|
|
2630
|
-
exports.fetchListings = fetchListings;
|
|
2631
2638
|
exports.getConnect = getConnect;
|
|
2632
2639
|
exports.getConnectionHealth = getConnectionHealth;
|
|
2633
2640
|
exports.getElement = getElement;
|