lamp-core-lst 2025.12.0-1.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.
@@ -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 (_g) {
67
- switch (_g.label) {
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
- _g.trys.push([0, 2, , 3]);
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 = _g.sent();
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
- newRefreshToken = ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.refresh_token) || refreshToken;
77
- 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 }));
78
- LAMP = global.LAMP || (typeof window !== "undefined" ? window.LAMP : null);
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
- error_1 = _g.sent();
94
- console.log(error_1);
95
- return [3 /*break*/, 3];
96
- case 3: return [2 /*return*/];
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, error_2, message;
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
- error_2 = _d.sent();
186
- message = ((_b = error_2) === null || _b === void 0 ? void 0 : _b.message) || String(error_2);
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*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lamp-core-lst",
3
- "version": "2025.12.0-1.1",
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/",
@@ -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
- // Access LAMP from global scope to avoid circular dependency
57
- const LAMP = (global as any).LAMP || (typeof window !== "undefined" ? (window as any).LAMP : null)
58
- if (LAMP && typeof LAMP.dispatchEvent === "function") {
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