lamp-core-lst 2025.12.1 → 2025.12.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/service/Fetch.js
CHANGED
|
@@ -10,6 +10,25 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
13
32
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
33
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
34
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -61,46 +80,57 @@ var handleSessionExpiry = function () { return __awaiter(void 0, void 0, void 0,
|
|
|
61
80
|
}); };
|
|
62
81
|
//If access Token expired then call api for renewing the tokens
|
|
63
82
|
var handleRenewToken = function (refreshToken, base, configuration) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
-
var credService, res, accessToken, newRefreshToken, LAMP, identityObject, serverAddress, error_1;
|
|
65
|
-
var _a, _b, _c, _d, _e, _f;
|
|
66
|
-
return __generator(this, function (
|
|
67
|
-
switch (
|
|
83
|
+
var credService, res, accessToken, newRefreshToken, LAMP, identityObject, serverAddress, error_1, error_2;
|
|
84
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
85
|
+
return __generator(this, function (_j) {
|
|
86
|
+
switch (_j.label) {
|
|
68
87
|
case 0:
|
|
69
|
-
|
|
88
|
+
_j.trys.push([0, 6, , 7]);
|
|
70
89
|
credService = new Credential_service_1.CredentialService();
|
|
71
90
|
return [4 /*yield*/, credService.renewToken(refreshToken, base)];
|
|
72
91
|
case 1:
|
|
73
|
-
res =
|
|
92
|
+
res = _j.sent();
|
|
74
93
|
accessToken = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
75
|
-
if (accessToken)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (LAMP && typeof LAMP.dispatchEvent === "function") {
|
|
80
|
-
identityObject = ((_d = LAMP.Auth) === null || _d === void 0 ? void 0 : _d._me) || null;
|
|
81
|
-
serverAddress = (configuration === null || configuration === void 0 ? void 0 : configuration.base) || base || ((_e = LAMP.configuration) === null || _e === void 0 ? void 0 : _e.base);
|
|
82
|
-
LAMP.dispatchEvent("renewToken", {
|
|
83
|
-
authorizationToken: (configuration === null || configuration === void 0 ? void 0 : configuration.authorization) || ((_f = LAMP.configuration) === null || _f === void 0 ? void 0 : _f.authorization),
|
|
84
|
-
identityObject: identityObject,
|
|
85
|
-
serverAddress: serverAddress,
|
|
86
|
-
accessToken: accessToken,
|
|
87
|
-
refreshToken: newRefreshToken,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return [2 /*return*/, accessToken];
|
|
94
|
+
if (!accessToken) return [3 /*break*/, 5];
|
|
95
|
+
newRefreshToken = ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.refresh_token) || refreshToken;
|
|
96
|
+
sessionStorage.setItem(userTokenKey, JSON.stringify({ accessToken: (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.access_token, refreshToken: newRefreshToken }));
|
|
97
|
+
_j.label = 2;
|
|
92
98
|
case 2:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
_j.trys.push([2, 4, , 5]);
|
|
100
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("../index")); }).then(function (module) { return module.default; })
|
|
101
|
+
// Get identity object from LAMP.Auth if available
|
|
102
|
+
];
|
|
103
|
+
case 3:
|
|
104
|
+
LAMP = _j.sent();
|
|
105
|
+
identityObject = ((_d = LAMP.Auth) === null || _d === void 0 ? void 0 : _d._me) || null;
|
|
106
|
+
serverAddress = (configuration === null || configuration === void 0 ? void 0 : configuration.base) || base || ((_f = (_e = LAMP.API) === null || _e === void 0 ? void 0 : _e.configuration) === null || _f === void 0 ? void 0 : _f.base);
|
|
107
|
+
// Dispatch the renewToken event
|
|
108
|
+
LAMP.dispatchEvent("renewToken", {
|
|
109
|
+
authorizationToken: (configuration === null || configuration === void 0 ? void 0 : configuration.authorization) || ((_h = (_g = LAMP.API) === null || _g === void 0 ? void 0 : _g.configuration) === null || _h === void 0 ? void 0 : _h.authorization),
|
|
110
|
+
identityObject: identityObject,
|
|
111
|
+
serverAddress: serverAddress,
|
|
112
|
+
accessToken: accessToken,
|
|
113
|
+
refreshToken: newRefreshToken,
|
|
114
|
+
});
|
|
115
|
+
return [3 /*break*/, 5];
|
|
116
|
+
case 4:
|
|
117
|
+
error_1 = _j.sent();
|
|
118
|
+
// Silently fail if dispatchEvent is not available (e.g., in Node.js environment)
|
|
119
|
+
console.warn("Failed to dispatch renewToken event:", error_1);
|
|
120
|
+
return [3 /*break*/, 5];
|
|
121
|
+
case 5: return [2 /*return*/, accessToken];
|
|
122
|
+
case 6:
|
|
123
|
+
error_2 = _j.sent();
|
|
124
|
+
console.log(error_2);
|
|
125
|
+
return [3 /*break*/, 7];
|
|
126
|
+
case 7: return [2 /*return*/];
|
|
97
127
|
}
|
|
98
128
|
});
|
|
99
129
|
}); };
|
|
100
130
|
function _fetch(method, route, configuration, body) {
|
|
101
131
|
var _a, _b;
|
|
102
132
|
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
-
var authorization, userTokenFromLocalStore, response, result, refreshToken, token, _c, tokenError_1,
|
|
133
|
+
var authorization, userTokenFromLocalStore, response, result, refreshToken, token, _c, tokenError_1, error_3, message;
|
|
104
134
|
return __generator(this, function (_d) {
|
|
105
135
|
switch (_d.label) {
|
|
106
136
|
case 0:
|
|
@@ -182,8 +212,8 @@ function _fetch(method, route, configuration, body) {
|
|
|
182
212
|
return [2 /*return*/, { data: [], error: "401.invalid-token" }];
|
|
183
213
|
case 22: return [2 /*return*/, result];
|
|
184
214
|
case 23:
|
|
185
|
-
|
|
186
|
-
message = ((_b =
|
|
215
|
+
error_3 = _d.sent();
|
|
216
|
+
message = ((_b = error_3) === null || _b === void 0 ? void 0 : _b.message) || String(error_3);
|
|
187
217
|
console.error("Fetch failed:", message);
|
|
188
218
|
return [2 /*return*/, { data: [], error: message || "Unknown error" }];
|
|
189
219
|
case 24: return [2 /*return*/];
|
|
@@ -266,6 +266,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
266
266
|
return [4 /*yield*/, Fetch_1.Fetch.post("/researcher/" + researcherId + "/activity-export", body, this.configuration)];
|
|
267
267
|
case 1:
|
|
268
268
|
result = _a.sent();
|
|
269
|
+
if (result.error) {
|
|
270
|
+
throw new Error(result.error);
|
|
271
|
+
}
|
|
272
|
+
if (!result.data) {
|
|
273
|
+
throw new Error("Invalid response from export API");
|
|
274
|
+
}
|
|
269
275
|
return [2 /*return*/, result.data];
|
|
270
276
|
}
|
|
271
277
|
});
|
|
@@ -289,6 +295,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
289
295
|
return [4 /*yield*/, Fetch_1.Fetch.get("/exports/" + jobId, this.configuration)];
|
|
290
296
|
case 1:
|
|
291
297
|
result = _a.sent();
|
|
298
|
+
if (result.error) {
|
|
299
|
+
throw new Error(result.error);
|
|
300
|
+
}
|
|
301
|
+
if (!result.data) {
|
|
302
|
+
throw new Error("Invalid response from export job API");
|
|
303
|
+
}
|
|
292
304
|
return [2 /*return*/, result.data];
|
|
293
305
|
}
|
|
294
306
|
});
|
|
@@ -314,6 +326,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
314
326
|
return [4 /*yield*/, Fetch_1.Fetch.get("/exports/" + jobId + "/download?ttl=" + ttl, this.configuration)];
|
|
315
327
|
case 1:
|
|
316
328
|
result = _a.sent();
|
|
329
|
+
if (result.error) {
|
|
330
|
+
throw new Error(result.error);
|
|
331
|
+
}
|
|
332
|
+
if (!result.data) {
|
|
333
|
+
throw new Error("Invalid response from export download API");
|
|
334
|
+
}
|
|
317
335
|
return [2 /*return*/, result.data];
|
|
318
336
|
}
|
|
319
337
|
});
|
|
@@ -338,6 +356,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
338
356
|
return [4 /*yield*/, Fetch_1.Fetch.post("/researcher/" + researcherId + "/activity-import", body, this.configuration)];
|
|
339
357
|
case 1:
|
|
340
358
|
result = _a.sent();
|
|
359
|
+
if (result.error) {
|
|
360
|
+
throw new Error(result.error);
|
|
361
|
+
}
|
|
362
|
+
if (!result.data) {
|
|
363
|
+
throw new Error("Invalid response from import API");
|
|
364
|
+
}
|
|
341
365
|
return [2 /*return*/, result.data];
|
|
342
366
|
}
|
|
343
367
|
});
|
|
@@ -361,6 +385,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
361
385
|
return [4 /*yield*/, Fetch_1.Fetch.get("/imports/" + jobId, this.configuration)];
|
|
362
386
|
case 1:
|
|
363
387
|
result = _a.sent();
|
|
388
|
+
if (result.error) {
|
|
389
|
+
throw new Error(result.error);
|
|
390
|
+
}
|
|
391
|
+
if (!result.data) {
|
|
392
|
+
throw new Error("Invalid response from import job API");
|
|
393
|
+
}
|
|
364
394
|
return [2 /*return*/, result.data];
|
|
365
395
|
}
|
|
366
396
|
});
|
|
@@ -386,6 +416,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
386
416
|
return [4 /*yield*/, Fetch_1.Fetch.post("/imports/" + jobId + "/upload-url", { ttl: ttl }, this.configuration)];
|
|
387
417
|
case 1:
|
|
388
418
|
result = _a.sent();
|
|
419
|
+
if (result.error) {
|
|
420
|
+
throw new Error(result.error);
|
|
421
|
+
}
|
|
422
|
+
if (!result.data) {
|
|
423
|
+
throw new Error("Invalid response from import upload URL API");
|
|
424
|
+
}
|
|
389
425
|
return [2 /*return*/, result.data];
|
|
390
426
|
}
|
|
391
427
|
});
|
|
@@ -410,6 +446,12 @@ var ResearcherService = /** @class */ (function () {
|
|
|
410
446
|
return [4 /*yield*/, Fetch_1.Fetch.post("/imports/" + jobId + "/complete-upload", { blobName: blobName }, this.configuration)];
|
|
411
447
|
case 1:
|
|
412
448
|
result = _a.sent();
|
|
449
|
+
if (result.error) {
|
|
450
|
+
throw new Error(result.error);
|
|
451
|
+
}
|
|
452
|
+
if (!result.data) {
|
|
453
|
+
throw new Error("Invalid response from complete import upload API");
|
|
454
|
+
}
|
|
413
455
|
return [2 /*return*/, result.data];
|
|
414
456
|
}
|
|
415
457
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lamp-core-lst",
|
|
3
|
-
"version": "2025.12.
|
|
3
|
+
"version": "2025.12.2",
|
|
4
4
|
"author": "BIDMC Division of Digital Psychiatry <team@digitalpsych.org>",
|
|
5
5
|
"description": "The JavaScript and TypeScript API client for the LAMP Platform.",
|
|
6
6
|
"homepage": "https://docs.lamp.digital/",
|
package/src/service/Fetch.ts
CHANGED
|
@@ -53,20 +53,26 @@ const handleRenewToken = async (refreshToken: string, base: string, configuratio
|
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
// Dispatch renewToken event similar to LOGIN event
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
// Use lazy import to avoid circular dependency issues
|
|
57
|
+
try {
|
|
58
|
+
// Dynamically import LAMP to avoid circular dependency
|
|
59
|
+
const LAMP = await import("../index").then((module) => module.default)
|
|
60
|
+
|
|
59
61
|
// Get identity object from LAMP.Auth if available
|
|
60
62
|
const identityObject = LAMP.Auth?._me || null
|
|
61
|
-
const serverAddress = configuration?.base || base || LAMP.configuration?.base
|
|
63
|
+
const serverAddress = configuration?.base || base || LAMP.API?.configuration?.base
|
|
62
64
|
|
|
65
|
+
// Dispatch the renewToken event
|
|
63
66
|
LAMP.dispatchEvent("renewToken", {
|
|
64
|
-
authorizationToken: configuration?.authorization || LAMP.configuration?.authorization,
|
|
67
|
+
authorizationToken: configuration?.authorization || LAMP.API?.configuration?.authorization,
|
|
65
68
|
identityObject: identityObject,
|
|
66
69
|
serverAddress: serverAddress,
|
|
67
70
|
accessToken: accessToken,
|
|
68
71
|
refreshToken: newRefreshToken,
|
|
69
72
|
})
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// Silently fail if dispatchEvent is not available (e.g., in Node.js environment)
|
|
75
|
+
console.warn("Failed to dispatch renewToken event:", error)
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
return accessToken
|
|
@@ -160,11 +160,17 @@ export class ResearcherService {
|
|
|
160
160
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
161
161
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
162
162
|
}
|
|
163
|
-
const result = await Fetch.post<{ data: { jobId: string; status: string } }>(
|
|
163
|
+
const result = await Fetch.post<{ data: { jobId: string; status: string }; error?: string }>(
|
|
164
164
|
`/researcher/${researcherId}/activity-export`,
|
|
165
165
|
body,
|
|
166
166
|
this.configuration
|
|
167
167
|
)
|
|
168
|
+
if (result.error) {
|
|
169
|
+
throw new Error(result.error)
|
|
170
|
+
}
|
|
171
|
+
if (!result.data) {
|
|
172
|
+
throw new Error("Invalid response from export API")
|
|
173
|
+
}
|
|
168
174
|
return result.data
|
|
169
175
|
}
|
|
170
176
|
|
|
@@ -178,7 +184,13 @@ export class ResearcherService {
|
|
|
178
184
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
179
185
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
180
186
|
}
|
|
181
|
-
const result = await Fetch.get<{ data: any }>(`/exports/${jobId}`, this.configuration)
|
|
187
|
+
const result = await Fetch.get<{ data: any; error?: string }>(`/exports/${jobId}`, this.configuration)
|
|
188
|
+
if (result.error) {
|
|
189
|
+
throw new Error(result.error)
|
|
190
|
+
}
|
|
191
|
+
if (!result.data) {
|
|
192
|
+
throw new Error("Invalid response from export job API")
|
|
193
|
+
}
|
|
182
194
|
return result.data
|
|
183
195
|
}
|
|
184
196
|
|
|
@@ -198,7 +210,13 @@ export class ResearcherService {
|
|
|
198
210
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
199
211
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
200
212
|
}
|
|
201
|
-
const result = await Fetch.get<{ data: any }>(`/exports/${jobId}/download?ttl=${ttl}`, this.configuration)
|
|
213
|
+
const result = await Fetch.get<{ data: any; error?: string }>(`/exports/${jobId}/download?ttl=${ttl}`, this.configuration)
|
|
214
|
+
if (result.error) {
|
|
215
|
+
throw new Error(result.error)
|
|
216
|
+
}
|
|
217
|
+
if (!result.data) {
|
|
218
|
+
throw new Error("Invalid response from export download API")
|
|
219
|
+
}
|
|
202
220
|
return result.data
|
|
203
221
|
}
|
|
204
222
|
|
|
@@ -216,11 +234,17 @@ export class ResearcherService {
|
|
|
216
234
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
217
235
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
218
236
|
}
|
|
219
|
-
const result = await Fetch.post<{ data: { jobId: string; status: string } }>(
|
|
237
|
+
const result = await Fetch.post<{ data: { jobId: string; status: string }; error?: string }>(
|
|
220
238
|
`/researcher/${researcherId}/activity-import`,
|
|
221
239
|
body,
|
|
222
240
|
this.configuration
|
|
223
241
|
)
|
|
242
|
+
if (result.error) {
|
|
243
|
+
throw new Error(result.error)
|
|
244
|
+
}
|
|
245
|
+
if (!result.data) {
|
|
246
|
+
throw new Error("Invalid response from import API")
|
|
247
|
+
}
|
|
224
248
|
return result.data
|
|
225
249
|
}
|
|
226
250
|
|
|
@@ -234,7 +258,13 @@ export class ResearcherService {
|
|
|
234
258
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
235
259
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
236
260
|
}
|
|
237
|
-
const result = await Fetch.get<{ data: any }>(`/imports/${jobId}`, this.configuration)
|
|
261
|
+
const result = await Fetch.get<{ data: any; error?: string }>(`/imports/${jobId}`, this.configuration)
|
|
262
|
+
if (result.error) {
|
|
263
|
+
throw new Error(result.error)
|
|
264
|
+
}
|
|
265
|
+
if (!result.data) {
|
|
266
|
+
throw new Error("Invalid response from import job API")
|
|
267
|
+
}
|
|
238
268
|
return result.data
|
|
239
269
|
}
|
|
240
270
|
|
|
@@ -253,7 +283,13 @@ export class ResearcherService {
|
|
|
253
283
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
254
284
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
255
285
|
}
|
|
256
|
-
const result = await Fetch.post<{ data: any }>(`/imports/${jobId}/upload-url`, { ttl }, this.configuration)
|
|
286
|
+
const result = await Fetch.post<{ data: any; error?: string }>(`/imports/${jobId}/upload-url`, { ttl }, this.configuration)
|
|
287
|
+
if (result.error) {
|
|
288
|
+
throw new Error(result.error)
|
|
289
|
+
}
|
|
290
|
+
if (!result.data) {
|
|
291
|
+
throw new Error("Invalid response from import upload URL API")
|
|
292
|
+
}
|
|
257
293
|
return result.data
|
|
258
294
|
}
|
|
259
295
|
|
|
@@ -268,7 +304,13 @@ export class ResearcherService {
|
|
|
268
304
|
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
269
305
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
270
306
|
}
|
|
271
|
-
const result = await Fetch.post<{ data: any }>(`/imports/${jobId}/complete-upload`, { blobName }, this.configuration)
|
|
307
|
+
const result = await Fetch.post<{ data: any; error?: string }>(`/imports/${jobId}/complete-upload`, { blobName }, this.configuration)
|
|
308
|
+
if (result.error) {
|
|
309
|
+
throw new Error(result.error)
|
|
310
|
+
}
|
|
311
|
+
if (!result.data) {
|
|
312
|
+
throw new Error("Invalid response from complete import upload API")
|
|
313
|
+
}
|
|
272
314
|
return result.data
|
|
273
315
|
}
|
|
274
316
|
}
|