@monterosa/sdk-interact-kit 0.18.2-rc.1 → 0.18.2-rc.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/dist/index.cjs.js +99 -108
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +46 -28
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +98 -108
- 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 +5 -1
- package/dist/src/core/project/internal.d.ts +12 -0
- package/package.json +5 -9
package/dist/index.cjs.js
CHANGED
|
@@ -5,8 +5,6 @@ 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');
|
|
10
8
|
|
|
11
9
|
/*! *****************************************************************************
|
|
12
10
|
Copyright (c) Microsoft Corporation.
|
|
@@ -499,6 +497,33 @@ function onConnectionHealthState(connectionHealth, callback) {
|
|
|
499
497
|
return sdkUtil.subscribe(connectionHealth, 'state', callback);
|
|
500
498
|
}
|
|
501
499
|
|
|
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
|
+
|
|
502
527
|
/**
|
|
503
528
|
* @license
|
|
504
529
|
* constants.ts
|
|
@@ -796,7 +821,7 @@ function buildProject(options, context) {
|
|
|
796
821
|
throw new Error("Unable to fetch project " + id + " listings. Possibly wrong project id.");
|
|
797
822
|
}
|
|
798
823
|
_a = project;
|
|
799
|
-
return [4 /*yield*/,
|
|
824
|
+
return [4 /*yield*/, fetchSettings(project.host, project.id)];
|
|
800
825
|
case 4:
|
|
801
826
|
_a.fields = _b.sent();
|
|
802
827
|
return [2 /*return*/, project];
|
|
@@ -880,7 +905,7 @@ function handleListings(project, data) {
|
|
|
880
905
|
_d.trys.push([1, 4, , 5]);
|
|
881
906
|
if (!(oldDigest !== undefined && newDigest !== oldDigest)) return [3 /*break*/, 3];
|
|
882
907
|
_b = project;
|
|
883
|
-
return [4 /*yield*/,
|
|
908
|
+
return [4 /*yield*/, fetchSettings(project.host, project.id)];
|
|
884
909
|
case 2:
|
|
885
910
|
_b.fields = _d.sent();
|
|
886
911
|
_d.label = 3;
|
|
@@ -932,6 +957,25 @@ function getProject(sdk) {
|
|
|
932
957
|
if (sdk === void 0) { sdk = sdkCore.getSdk(); }
|
|
933
958
|
return getProjectMemoized(sdk);
|
|
934
959
|
}
|
|
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
|
+
}
|
|
935
979
|
/**
|
|
936
980
|
* Adds an observer for when {@link InteractProject.fields | project fields}
|
|
937
981
|
* are updated
|
|
@@ -2146,24 +2190,15 @@ var ElementImpl = /** @class */ (function (_super) {
|
|
|
2146
2190
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
2147
2191
|
*/
|
|
2148
2192
|
var elements = new Map();
|
|
2193
|
+
var storageAvailable = sdkUtil.checkAvailability();
|
|
2149
2194
|
function buildElement(options, context) {
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
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
|
-
});
|
|
2195
|
+
if (elements.has(options.id)) {
|
|
2196
|
+
return elements.get(options.id);
|
|
2197
|
+
}
|
|
2198
|
+
var element = new ElementImpl(options, context);
|
|
2199
|
+
restoreAnswer(element);
|
|
2200
|
+
elements.set(element.id, element);
|
|
2201
|
+
return element;
|
|
2167
2202
|
}
|
|
2168
2203
|
function getElementByPolld(pollId) {
|
|
2169
2204
|
return Array.from(elements.values()).find(function (element) { return element.pollId === pollId; });
|
|
@@ -2262,21 +2297,19 @@ function handleCreateMessage(message) {
|
|
|
2262
2297
|
if (event === null) {
|
|
2263
2298
|
return [2 /*return*/];
|
|
2264
2299
|
}
|
|
2265
|
-
if (
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2300
|
+
if (elements.has(options.id)) {
|
|
2301
|
+
element = elements.get(options.id);
|
|
2302
|
+
if (options.updated_at > element.updatedAt) {
|
|
2303
|
+
element.update(options);
|
|
2304
|
+
event.emit('update', element);
|
|
2305
|
+
}
|
|
2270
2306
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
event.emit('publish', element);
|
|
2278
|
-
_a.label = 4;
|
|
2279
|
-
case 4: return [2 /*return*/];
|
|
2307
|
+
else {
|
|
2308
|
+
context = __assign(__assign({}, event.context), { event: event });
|
|
2309
|
+
element = buildElement(options, context);
|
|
2310
|
+
event.emit('publish', element);
|
|
2311
|
+
}
|
|
2312
|
+
return [2 /*return*/];
|
|
2280
2313
|
}
|
|
2281
2314
|
});
|
|
2282
2315
|
});
|
|
@@ -2329,55 +2362,28 @@ function handleRevealMessage(message) {
|
|
|
2329
2362
|
element.context.event.emit('update', element);
|
|
2330
2363
|
}
|
|
2331
2364
|
function handleEventHistory(history) {
|
|
2332
|
-
var e_1, _a;
|
|
2333
2365
|
return __awaiter(this, void 0, void 0, function () {
|
|
2334
|
-
var event, context,
|
|
2335
|
-
return __generator(this, function (
|
|
2336
|
-
switch (
|
|
2366
|
+
var event, context, _i, _a, snapshot;
|
|
2367
|
+
return __generator(this, function (_b) {
|
|
2368
|
+
switch (_b.label) {
|
|
2337
2369
|
case 0:
|
|
2338
2370
|
if (history.timeline.length === 0) {
|
|
2339
2371
|
return [2 /*return*/];
|
|
2340
2372
|
}
|
|
2341
2373
|
return [4 /*yield*/, getEvent(history.config.id)];
|
|
2342
2374
|
case 1:
|
|
2343
|
-
event =
|
|
2375
|
+
event = _b.sent();
|
|
2344
2376
|
if (event === null) {
|
|
2345
2377
|
return [2 /*return*/];
|
|
2346
2378
|
}
|
|
2347
2379
|
context = __assign(__assign({}, event.context), { event: event });
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
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*/];
|
|
2380
|
+
for (_i = 0, _a = history.timeline; _i < _a.length; _i++) {
|
|
2381
|
+
snapshot = _a[_i];
|
|
2382
|
+
if (!elements.has(snapshot.id)) {
|
|
2383
|
+
buildElement(snapshot, context);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
return [2 /*return*/];
|
|
2381
2387
|
}
|
|
2382
2388
|
});
|
|
2383
2389
|
});
|
|
@@ -2406,43 +2412,27 @@ function sendAnswer(element, userAnswer) {
|
|
|
2406
2412
|
});
|
|
2407
2413
|
}
|
|
2408
2414
|
function storeAnswer(element, userAnswer) {
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
if (err_1 instanceof Error) {
|
|
2423
|
-
console.warn("Failed to store user answer: " + err_1.message);
|
|
2424
|
-
}
|
|
2425
|
-
return [3 /*break*/, 3];
|
|
2426
|
-
case 3: return [2 /*return*/];
|
|
2427
|
-
}
|
|
2428
|
-
});
|
|
2429
|
-
});
|
|
2415
|
+
try {
|
|
2416
|
+
element.userAnswer = userAnswer;
|
|
2417
|
+
if (storageAvailable) {
|
|
2418
|
+
// Can throw a "QuotaExceededError" DOMException exception
|
|
2419
|
+
// if the quota has been exceeded.
|
|
2420
|
+
sdkUtil.setItem("element_" + element.id + "_vote", JSON.stringify(userAnswer));
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
catch (err) {
|
|
2424
|
+
if (err instanceof Error) {
|
|
2425
|
+
console.warn("Can't store user answer: " + err.message);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2430
2428
|
}
|
|
2431
2429
|
function restoreAnswer(element) {
|
|
2432
|
-
|
|
2433
|
-
var userAnswer;
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
userAnswer = _a.sent();
|
|
2439
|
-
if (userAnswer !== null) {
|
|
2440
|
-
element.userAnswer = Answer.fromJSON(userAnswer);
|
|
2441
|
-
}
|
|
2442
|
-
return [2 /*return*/];
|
|
2443
|
-
}
|
|
2444
|
-
});
|
|
2445
|
-
});
|
|
2430
|
+
if (storageAvailable) {
|
|
2431
|
+
var userAnswer = sdkUtil.getItem("element_" + element.id + "_vote");
|
|
2432
|
+
if (userAnswer !== null) {
|
|
2433
|
+
element.userAnswer = Answer.fromJSON(userAnswer);
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2446
2436
|
}
|
|
2447
2437
|
|
|
2448
2438
|
/**
|
|
@@ -2637,6 +2627,7 @@ exports.ElementImpl = ElementImpl;
|
|
|
2637
2627
|
exports.EventImpl = EventImpl;
|
|
2638
2628
|
exports.ProjectImpl = ProjectImpl;
|
|
2639
2629
|
exports.answer = answer;
|
|
2630
|
+
exports.fetchListings = fetchListings;
|
|
2640
2631
|
exports.getConnect = getConnect;
|
|
2641
2632
|
exports.getConnectionHealth = getConnectionHealth;
|
|
2642
2633
|
exports.getElement = getElement;
|