lamp-core-lst 2025.11.1-3.basic
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/.github/workflows/publish.yml +34 -0
- package/LICENSE.md +29 -0
- package/MANUAL.md +26 -0
- package/README.md +126 -0
- package/cli.js +2 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +311 -0
- package/dist/model/Activity.d.ts +81 -0
- package/dist/model/Activity.js +30 -0
- package/dist/model/ActivityEvent.d.ts +51 -0
- package/dist/model/ActivityEvent.js +21 -0
- package/dist/model/ActivitySpec.d.ts +38 -0
- package/dist/model/ActivitySpec.js +12 -0
- package/dist/model/Credential.d.ts +21 -0
- package/dist/model/Credential.js +12 -0
- package/dist/model/DynamicAttachment.d.ts +34 -0
- package/dist/model/DynamicAttachment.js +12 -0
- package/dist/model/Participant.d.ts +30 -0
- package/dist/model/Participant.js +12 -0
- package/dist/model/Researcher.d.ts +27 -0
- package/dist/model/Researcher.js +12 -0
- package/dist/model/ResearcherSettings.d.ts +57 -0
- package/dist/model/ResearcherSettings.js +12 -0
- package/dist/model/Sensor.d.ts +22 -0
- package/dist/model/Sensor.js +12 -0
- package/dist/model/SensorEvent.d.ts +18 -0
- package/dist/model/SensorEvent.js +12 -0
- package/dist/model/SensorSpec.d.ts +13 -0
- package/dist/model/SensorSpec.js +12 -0
- package/dist/model/Study.d.ts +24 -0
- package/dist/model/Study.js +12 -0
- package/dist/model/Type.d.ts +56 -0
- package/dist/model/Type.js +30 -0
- package/dist/model/index.d.ts +12 -0
- package/dist/model/index.js +24 -0
- package/dist/service/API.service.d.ts +12 -0
- package/dist/service/API.service.js +82 -0
- package/dist/service/Activity.service.d.ts +101 -0
- package/dist/service/Activity.service.js +756 -0
- package/dist/service/ActivityEvent.service.d.ts +46 -0
- package/dist/service/ActivityEvent.service.js +303 -0
- package/dist/service/ActivitySpec.service.d.ts +31 -0
- package/dist/service/ActivitySpec.service.js +173 -0
- package/dist/service/Credential.service.d.ts +38 -0
- package/dist/service/Credential.service.js +319 -0
- package/dist/service/Demo.d.ts +14 -0
- package/dist/service/Demo.js +24 -0
- package/dist/service/Fetch.d.ts +30 -0
- package/dist/service/Fetch.js +245 -0
- package/dist/service/Participant.service.d.ts +42 -0
- package/dist/service/Participant.service.js +312 -0
- package/dist/service/Researcher.service.d.ts +34 -0
- package/dist/service/Researcher.service.js +252 -0
- package/dist/service/ResearcherSettings.service.d.ts +16 -0
- package/dist/service/ResearcherSettings.service.js +114 -0
- package/dist/service/Sensor.service.d.ts +47 -0
- package/dist/service/Sensor.service.js +372 -0
- package/dist/service/SensorEvent.service.d.ts +44 -0
- package/dist/service/SensorEvent.service.js +302 -0
- package/dist/service/SensorSpec.service.d.ts +31 -0
- package/dist/service/SensorSpec.service.js +171 -0
- package/dist/service/Study.service.d.ts +42 -0
- package/dist/service/Study.service.js +286 -0
- package/dist/service/Type.service.d.ts +48 -0
- package/dist/service/Type.service.js +352 -0
- package/dist/service/index.d.ts +13 -0
- package/dist/service/index.js +25 -0
- package/docs/APIApi.md +82 -0
- package/docs/AccessCitation.md +11 -0
- package/docs/Activity.md +13 -0
- package/docs/ActivityApi.md +356 -0
- package/docs/ActivityEvent.md +13 -0
- package/docs/ActivityEventApi.md +251 -0
- package/docs/ActivitySpec.md +14 -0
- package/docs/ActivitySpecApi.md +222 -0
- package/docs/Credential.md +12 -0
- package/docs/CredentialApi.md +175 -0
- package/docs/Document.md +9 -0
- package/docs/DurationInterval.md +11 -0
- package/docs/DurationIntervalLegacy.md +10 -0
- package/docs/DynamicAttachment.md +14 -0
- package/docs/Error.md +8 -0
- package/docs/Metadata.md +8 -0
- package/docs/Participant.md +14 -0
- package/docs/ParticipantApi.md +312 -0
- package/docs/Researcher.md +12 -0
- package/docs/ResearcherApi.md +223 -0
- package/docs/Sensor.md +12 -0
- package/docs/SensorApi.md +356 -0
- package/docs/SensorEvent.md +11 -0
- package/docs/SensorEventApi.md +250 -0
- package/docs/SensorSpec.md +10 -0
- package/docs/SensorSpecApi.md +222 -0
- package/docs/Study.md +11 -0
- package/docs/StudyApi.md +268 -0
- package/docs/TemporalSlice.md +13 -0
- package/docs/TypeApi.md +274 -0
- package/package.json +44 -0
- package/src/index.ts +256 -0
- package/src/model/Activity.ts +93 -0
- package/src/model/ActivityEvent.ts +63 -0
- package/src/model/ActivitySpec.ts +45 -0
- package/src/model/Credential.ts +26 -0
- package/src/model/DynamicAttachment.ts +42 -0
- package/src/model/Participant.ts +37 -0
- package/src/model/Researcher.ts +33 -0
- package/src/model/ResearcherSettings.ts +65 -0
- package/src/model/Sensor.ts +27 -0
- package/src/model/SensorEvent.ts +22 -0
- package/src/model/SensorSpec.ts +16 -0
- package/src/model/Study.ts +29 -0
- package/src/model/Type.ts +68 -0
- package/src/model/index.ts +12 -0
- package/src/service/API.service.ts +29 -0
- package/src/service/Activity.service.ts +625 -0
- package/src/service/ActivityEvent.service.ts +244 -0
- package/src/service/ActivitySpec.service.ts +98 -0
- package/src/service/Credential.service.ts +268 -0
- package/src/service/Demo.ts +21 -0
- package/src/service/Fetch.ts +187 -0
- package/src/service/Participant.service.ts +217 -0
- package/src/service/Researcher.service.ts +147 -0
- package/src/service/ResearcherSettings.service.ts +62 -0
- package/src/service/Sensor.service.ts +256 -0
- package/src/service/SensorEvent.service.ts +239 -0
- package/src/service/SensorSpec.service.ts +96 -0
- package/src/service/Study.service.ts +187 -0
- package/src/service/Type.service.ts +297 -0
- package/src/service/index.ts +13 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.CredentialService = void 0;
|
|
54
|
+
var jose_1 = require("jose");
|
|
55
|
+
var Fetch_1 = require("./Fetch");
|
|
56
|
+
var Credential_1 = require("../model/Credential");
|
|
57
|
+
var Demo_1 = require("./Demo");
|
|
58
|
+
var jsonata_1 = __importDefault(require("jsonata"));
|
|
59
|
+
var CredentialService = /** @class */ (function () {
|
|
60
|
+
function CredentialService() {
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param typeId
|
|
65
|
+
* @param secretKey
|
|
66
|
+
*/
|
|
67
|
+
CredentialService.prototype.create = function (typeId, accessKey, secretKey, description) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
+
var auth_1, credential, token, decoded, exists, unique;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
if (accessKey === null || accessKey === undefined)
|
|
74
|
+
throw new Error("Required parameter accessKey was null or undefined when calling credentialCreate.");
|
|
75
|
+
if (secretKey === null || secretKey === undefined)
|
|
76
|
+
throw new Error("Required parameter secretKey was null or undefined when calling credentialCreate.");
|
|
77
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
78
|
+
auth_1 = (this.configuration.authorization || ":").split(":");
|
|
79
|
+
credential = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === auth_1[0] && x["secret_key"] === auth_1[1]; });
|
|
80
|
+
if (credential.length === 0)
|
|
81
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
82
|
+
if (typeId === "me")
|
|
83
|
+
typeId = credential.length > 0 ? credential[0]["origin"] : typeId;
|
|
84
|
+
token = this.configuration.token;
|
|
85
|
+
if (!token)
|
|
86
|
+
return [2 /*return*/, Promise.resolve({ error: "401.missing-credentials" })];
|
|
87
|
+
decoded = void 0;
|
|
88
|
+
// try {
|
|
89
|
+
// // decoded = verifyToken(token, this.configuration.jwt_secret);
|
|
90
|
+
// } catch (error) {
|
|
91
|
+
// return Promise.resolve({ error: "403.invalid-token" } as any);
|
|
92
|
+
// }
|
|
93
|
+
// const credential = Demo.Credential.filter(x => x["access_key"] === decoded.accessKey && x["secret_key"] === decoded.secretKey);
|
|
94
|
+
// if (!credential) return Promise.resolve({ error: "403.invalid-credentials" } as any);
|
|
95
|
+
if (typeId === "me")
|
|
96
|
+
typeId = credential.length > 0 ? credential[0]["origin"] : typeId;
|
|
97
|
+
exists = Demo_1.Demo.Researcher.filter(function (x) { return x["id"] === typeId; }).length > 0 ||
|
|
98
|
+
Demo_1.Demo.Study.filter(function (x) { return x["id"] === typeId; }).length > 0 ||
|
|
99
|
+
Demo_1.Demo.Participant.filter(function (x) { return x["id"] === typeId; }).length > 0 ||
|
|
100
|
+
Demo_1.Demo.Activity.filter(function (x) { return x["id"] === typeId; }).length > 0 // ???
|
|
101
|
+
;
|
|
102
|
+
unique = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === accessKey; }).length === 0;
|
|
103
|
+
if (exists && unique) {
|
|
104
|
+
Demo_1.Demo.Credential.push({
|
|
105
|
+
"#type": "Credential",
|
|
106
|
+
"#parent": typeId,
|
|
107
|
+
origin: typeId,
|
|
108
|
+
access_key: accessKey,
|
|
109
|
+
secret_key: secretKey,
|
|
110
|
+
description: description,
|
|
111
|
+
});
|
|
112
|
+
return [2 /*return*/, Promise.resolve({})];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return [4 /*yield*/, Fetch_1.Fetch.post("/type/" + typeId + "/credential", { origin: typeId, access_key: accessKey, secret_key: secretKey, description: description }, this.configuration)];
|
|
119
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
*
|
|
126
|
+
* @param typeId
|
|
127
|
+
* @param accessKey
|
|
128
|
+
*/
|
|
129
|
+
CredentialService.prototype.delete = function (typeId, accessKey) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var token, decoded_1, credential, idx;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
if (accessKey === null || accessKey === undefined)
|
|
136
|
+
throw new Error("Required parameter accessKey was null or undefined when calling credentialDelete.");
|
|
137
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
138
|
+
token = this.configuration.token;
|
|
139
|
+
if (!token)
|
|
140
|
+
return [2 /*return*/, Promise.resolve({ error: "401.missing-credentials" })];
|
|
141
|
+
credential = Demo_1.Demo.Credential.find(function (x) { return x["access_key"] === decoded_1.accessKey && x["secret_key"] === decoded_1.secretKey; });
|
|
142
|
+
if (typeId === "me")
|
|
143
|
+
typeId = credential.length > 0 ? credential[0]["origin"] : typeId;
|
|
144
|
+
idx = Demo_1.Demo.Credential.findIndex(function (x) { return x["#parent"] === typeId && x["access_key"] === accessKey; });
|
|
145
|
+
if (idx >= 0) {
|
|
146
|
+
Demo_1.Demo.Credential.splice(idx, 1);
|
|
147
|
+
return [2 /*return*/, Promise.resolve({})];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return [4 /*yield*/, Fetch_1.Fetch.delete("/type/" + typeId + "/credential/" + accessKey, this.configuration)];
|
|
154
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* @param typeId
|
|
162
|
+
*/
|
|
163
|
+
CredentialService.prototype.list = function (typeId, transform) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
+
var token, decoded_2, credential, exists, output;
|
|
166
|
+
return __generator(this, function (_a) {
|
|
167
|
+
switch (_a.label) {
|
|
168
|
+
case 0:
|
|
169
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
170
|
+
token = this.configuration.token;
|
|
171
|
+
if (!token)
|
|
172
|
+
return [2 /*return*/, Promise.resolve({ error: "401.missing-credentials" })];
|
|
173
|
+
credential = Demo_1.Demo.Credential.find(function (x) { return x["access_key"] === decoded_2.accessKey && x["secret_key"] === decoded_2.secretKey; });
|
|
174
|
+
// if (!credential) return Promise.resolve({ error: "403.invalid-credentials" } as any);
|
|
175
|
+
if (typeId === "me")
|
|
176
|
+
typeId = credential.length > 0 ? credential[0]["origin"] : typeId;
|
|
177
|
+
exists = Demo_1.Demo.Researcher.filter(function (x) { return x["id"] === typeId; }).length > 0 ||
|
|
178
|
+
Demo_1.Demo.Study.filter(function (x) { return x["id"] === typeId; }).length > 0 ||
|
|
179
|
+
Demo_1.Demo.Participant.filter(function (x) { return x["id"] === typeId; }).length > 0 ||
|
|
180
|
+
Demo_1.Demo.Activity.filter(function (x) { return x["id"] === typeId; }).length > 0 // ???
|
|
181
|
+
;
|
|
182
|
+
if (exists) {
|
|
183
|
+
output = Demo_1.Demo.Credential.filter(function (x) { return x["#parent"] === typeId; }).map(function (x) {
|
|
184
|
+
return Object.assign(new Credential_1.Credential(), __assign(__assign({}, x), { secret_key: "" }));
|
|
185
|
+
});
|
|
186
|
+
output = typeof transform === "string" ? jsonata_1.default(transform).evaluate(output) : output;
|
|
187
|
+
return [2 /*return*/, Promise.resolve(output)];
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return [4 /*yield*/, Fetch_1.Fetch.get("/type/" + typeId + "/credential", this.configuration)];
|
|
194
|
+
case 1: return [2 /*return*/, (_a.sent()).data.map(function (x) {
|
|
195
|
+
return Object.assign(new Credential_1.Credential(), x);
|
|
196
|
+
})];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @param typeId
|
|
204
|
+
* @param accessKey
|
|
205
|
+
* @param secretKey
|
|
206
|
+
*/
|
|
207
|
+
CredentialService.prototype.update = function (typeId, accessKey, secretKey, description) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
+
var token, decoded_3, credential, idx;
|
|
210
|
+
return __generator(this, function (_a) {
|
|
211
|
+
switch (_a.label) {
|
|
212
|
+
case 0:
|
|
213
|
+
if (accessKey === null || accessKey === undefined)
|
|
214
|
+
throw new Error("Required parameter accessKey was null or undefined when calling credentialUpdate.");
|
|
215
|
+
if (secretKey === null || secretKey === undefined)
|
|
216
|
+
throw new Error("Required parameter secretKey was null or undefined when calling credentialUpdate.");
|
|
217
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
218
|
+
token = this.configuration.token;
|
|
219
|
+
if (!token)
|
|
220
|
+
return [2 /*return*/, Promise.resolve({ error: "401.missing-credentials" })];
|
|
221
|
+
credential = Demo_1.Demo.Credential.find(function (x) { return x["access_key"] === decoded_3.accessKey && x["secret_key"] === decoded_3.secretKey; });
|
|
222
|
+
// if (!credential) return Promise.resolve({ error: "403.invalid-credentials" } as any);
|
|
223
|
+
if (typeId === "me")
|
|
224
|
+
typeId = credential.length > 0 ? credential[0]["origin"] : typeId;
|
|
225
|
+
idx = Demo_1.Demo.Credential.findIndex(function (x) { return x["#parent"] === typeId && x["access_key"] === accessKey; });
|
|
226
|
+
if (idx >= 0) {
|
|
227
|
+
Demo_1.Demo.Credential[idx] = {
|
|
228
|
+
"#type": "Credential",
|
|
229
|
+
"#parent": typeId,
|
|
230
|
+
origin: typeId,
|
|
231
|
+
access_key: accessKey,
|
|
232
|
+
secret_key: secretKey !== null && secretKey !== void 0 ? secretKey : Demo_1.Demo.Credential[idx]["secret_key"],
|
|
233
|
+
description: description !== null && description !== void 0 ? description : Demo_1.Demo.Credential[idx]["description"],
|
|
234
|
+
};
|
|
235
|
+
return [2 /*return*/, Promise.resolve({})];
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return [4 /*yield*/, Fetch_1.Fetch.put("/type/" + typeId + "/credential/" + accessKey, secretKey, this.configuration)];
|
|
242
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
* @param accessKey
|
|
250
|
+
* @param secretKey
|
|
251
|
+
*/
|
|
252
|
+
CredentialService.prototype.login = function (accessKey, secretKey) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
254
|
+
var credential, exists, secretKeyEncoded, _a, error_1;
|
|
255
|
+
return __generator(this, function (_b) {
|
|
256
|
+
switch (_b.label) {
|
|
257
|
+
case 0:
|
|
258
|
+
if (accessKey === null || accessKey === undefined)
|
|
259
|
+
throw new Error("Required parameter accessKey was null or undefined when calling login.");
|
|
260
|
+
if (secretKey === null || secretKey === undefined)
|
|
261
|
+
throw new Error("Required parameter secretKey was null or undefined when calling login.");
|
|
262
|
+
if (!(this.configuration.base === "https://demo.lamp.digital")) return [3 /*break*/, 4];
|
|
263
|
+
credential = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === accessKey && x["secret_key"] === secretKey; });
|
|
264
|
+
if (credential.length === 0)
|
|
265
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
266
|
+
exists = Demo_1.Demo.Researcher.filter(function (x) { return x["id"] === accessKey; }).length > 0 ||
|
|
267
|
+
Demo_1.Demo.Participant.filter(function (x) { return x["id"] === accessKey; }).length > 0;
|
|
268
|
+
if (!exists)
|
|
269
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
270
|
+
if (!exists) return [3 /*break*/, 4];
|
|
271
|
+
_b.label = 1;
|
|
272
|
+
case 1:
|
|
273
|
+
_b.trys.push([1, 3, , 4]);
|
|
274
|
+
secretKeyEncoded = new TextEncoder().encode(this.configuration.jwt_secret);
|
|
275
|
+
_a = this.configuration;
|
|
276
|
+
return [4 /*yield*/, new jose_1.SignJWT({ accessKey: accessKey, secretKey: secretKey })
|
|
277
|
+
.setProtectedHeader({ alg: "HS256" })
|
|
278
|
+
.setIssuedAt()
|
|
279
|
+
.setExpirationTime("2h")
|
|
280
|
+
.sign(secretKeyEncoded)];
|
|
281
|
+
case 2:
|
|
282
|
+
_a.token = _b.sent();
|
|
283
|
+
return [2 /*return*/, Promise.resolve({ success: "Login successful", token: this.configuration.token })];
|
|
284
|
+
case 3:
|
|
285
|
+
error_1 = _b.sent();
|
|
286
|
+
console.error("Error generating token:", error_1);
|
|
287
|
+
return [2 /*return*/, Promise.resolve({ error: "500.server-error" })];
|
|
288
|
+
case 4: return [4 /*yield*/, Fetch_1.Fetch.post("/login", { accessKey: accessKey, secretKey: secretKey }, this.configuration)];
|
|
289
|
+
case 5: return [2 /*return*/, _b.sent()];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
CredentialService.prototype.renewToken = function (refreshToken, base) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
var configuration;
|
|
297
|
+
return __generator(this, function (_a) {
|
|
298
|
+
switch (_a.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
configuration = { accessToken: refreshToken, base: base };
|
|
301
|
+
return [4 /*yield*/, Fetch_1.Fetch.post("/renewToken", { refreshToken: refreshToken }, configuration)];
|
|
302
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
CredentialService.prototype.logout = function (token) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
switch (_a.label) {
|
|
311
|
+
case 0: return [4 /*yield*/, Fetch_1.Fetch.post("/logout", { token: token }, this.configuration)];
|
|
312
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
return CredentialService;
|
|
318
|
+
}());
|
|
319
|
+
exports.CredentialService = CredentialService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare let Demo: {
|
|
2
|
+
ActivitySpec: any[];
|
|
3
|
+
SensorSpec: any[];
|
|
4
|
+
Researcher: any[];
|
|
5
|
+
ResearcherSettings: any[];
|
|
6
|
+
Study: any[];
|
|
7
|
+
Participant: any[];
|
|
8
|
+
Activity: any[];
|
|
9
|
+
Sensor: any[];
|
|
10
|
+
ActivityEvent: any[];
|
|
11
|
+
SensorEvent: any[];
|
|
12
|
+
Credential: any[];
|
|
13
|
+
Tags: any[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Demo = void 0;
|
|
4
|
+
//
|
|
5
|
+
// [NOTE]: Demo mode carries various restrictions and does not:
|
|
6
|
+
// (1) verify R/W permissions.
|
|
7
|
+
// (2) carry an audit log.
|
|
8
|
+
// (3) support root operations.
|
|
9
|
+
// (4) encrypt any data.
|
|
10
|
+
//
|
|
11
|
+
exports.Demo = {
|
|
12
|
+
ActivitySpec: [],
|
|
13
|
+
SensorSpec: [],
|
|
14
|
+
Researcher: [],
|
|
15
|
+
ResearcherSettings: [],
|
|
16
|
+
Study: [],
|
|
17
|
+
Participant: [],
|
|
18
|
+
Activity: [],
|
|
19
|
+
Sensor: [],
|
|
20
|
+
ActivityEvent: [],
|
|
21
|
+
SensorEvent: [],
|
|
22
|
+
Credential: [],
|
|
23
|
+
Tags: []
|
|
24
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
export declare type Configuration = {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
base: string;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
authorization?: string;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
headers?: {
|
|
17
|
+
[header: string]: string;
|
|
18
|
+
};
|
|
19
|
+
token?: string;
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
jwt_secret?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare class Fetch {
|
|
25
|
+
static get<ResultType>(route: string, configuration?: Configuration): Promise<ResultType>;
|
|
26
|
+
static post<ResultType>(route: string, body: any, configuration?: Configuration): Promise<ResultType>;
|
|
27
|
+
static put<ResultType>(route: string, body: any, configuration?: Configuration): Promise<ResultType>;
|
|
28
|
+
static patch<ResultType>(route: string, body: any, configuration?: Configuration): Promise<ResultType>;
|
|
29
|
+
static delete<ResultType>(route: string, configuration?: Configuration, body?: any): Promise<ResultType>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.Fetch = void 0;
|
|
51
|
+
var Credential_service_1 = require("./Credential.service");
|
|
52
|
+
var userTokenKey = "tokenInfo";
|
|
53
|
+
//If refresh token expired, then logout from app
|
|
54
|
+
var handleSessionExpiry = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
localStorage.removeItem(userTokenKey);
|
|
57
|
+
localStorage.setItem("verified", JSON.stringify({ value: false }));
|
|
58
|
+
sessionStorage.setItem("LAMP._auth", JSON.stringify({ id: null, password: null, serverAddress: null }));
|
|
59
|
+
return [2 /*return*/];
|
|
60
|
+
});
|
|
61
|
+
}); };
|
|
62
|
+
//If access Token expired then call api for renewing the tokens
|
|
63
|
+
var handleRenewToken = function (refreshToken, base) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
+
var credService, res, accessToken, error_1;
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
return __generator(this, function (_d) {
|
|
67
|
+
switch (_d.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
_d.trys.push([0, 2, , 3]);
|
|
70
|
+
credService = new Credential_service_1.CredentialService();
|
|
71
|
+
return [4 /*yield*/, credService.renewToken(refreshToken, base)];
|
|
72
|
+
case 1:
|
|
73
|
+
res = _d.sent();
|
|
74
|
+
accessToken = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
75
|
+
if (accessToken) {
|
|
76
|
+
sessionStorage.setItem(userTokenKey, JSON.stringify({ accessToken: (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.access_token, refreshToken: (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.refresh_token }));
|
|
77
|
+
}
|
|
78
|
+
return [2 /*return*/, accessToken];
|
|
79
|
+
case 2:
|
|
80
|
+
error_1 = _d.sent();
|
|
81
|
+
console.log(error_1);
|
|
82
|
+
return [3 /*break*/, 3];
|
|
83
|
+
case 3: return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}); };
|
|
87
|
+
function _fetch(method, route, configuration, body) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var authorization, userTokenFromLocalStore, response, result, refreshToken, token, _c, tokenError_1, error_2, message;
|
|
91
|
+
return __generator(this, function (_d) {
|
|
92
|
+
switch (_d.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!configuration)
|
|
95
|
+
throw new Error("Cannot make HTTP request due to invalid configuration.");
|
|
96
|
+
userTokenFromLocalStore = JSON.parse(sessionStorage.getItem("tokenInfo"));
|
|
97
|
+
if (userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken) {
|
|
98
|
+
authorization = "Bearer " + (configuration.accessToken ? configuration.accessToken : userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken);
|
|
99
|
+
}
|
|
100
|
+
_d.label = 1;
|
|
101
|
+
case 1:
|
|
102
|
+
_d.trys.push([1, 23, , 24]);
|
|
103
|
+
return [4 /*yield*/, fetch("" + configuration.base + route, {
|
|
104
|
+
method: method,
|
|
105
|
+
headers: new Headers(typeof authorization !== "undefined" && !!authorization
|
|
106
|
+
? __assign(__assign({ "Content-Type": "application/json", Accept: "application/json" }, (configuration.headers || {})), { Authorization: authorization }) : __assign({ "Content-Type": "application/json", Accept: "application/json" }, (configuration.headers || {}))),
|
|
107
|
+
credentials: "include",
|
|
108
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
109
|
+
})];
|
|
110
|
+
case 2:
|
|
111
|
+
response = _d.sent();
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
console.warn("HTTP error " + response.status);
|
|
114
|
+
}
|
|
115
|
+
return [4 /*yield*/, response.json().catch(function () {
|
|
116
|
+
throw new Error("Invalid JSON response");
|
|
117
|
+
})
|
|
118
|
+
// Handle invalid token
|
|
119
|
+
];
|
|
120
|
+
case 3:
|
|
121
|
+
result = _d.sent();
|
|
122
|
+
if (!((result === null || result === void 0 ? void 0 : result.error) === "401.invalid-token" || (result === null || result === void 0 ? void 0 : result.message) === "401.invalid-token")) return [3 /*break*/, 22];
|
|
123
|
+
if (!!route.includes("renewToken")) return [3 /*break*/, 21];
|
|
124
|
+
_d.label = 4;
|
|
125
|
+
case 4:
|
|
126
|
+
_d.trys.push([4, 19, , 20]);
|
|
127
|
+
refreshToken = (_a = configuration.refreshToken) !== null && _a !== void 0 ? _a : userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.refreshToken;
|
|
128
|
+
if (!refreshToken) {
|
|
129
|
+
handleSessionExpiry();
|
|
130
|
+
return [2 /*return*/, { data: [], error: "401.invalid-token" }];
|
|
131
|
+
}
|
|
132
|
+
return [4 /*yield*/, handleRenewToken(refreshToken, configuration.base)];
|
|
133
|
+
case 5:
|
|
134
|
+
token = _d.sent();
|
|
135
|
+
if (!token) return [3 /*break*/, 17];
|
|
136
|
+
configuration.authorization = token;
|
|
137
|
+
_c = method;
|
|
138
|
+
switch (_c) {
|
|
139
|
+
case "post": return [3 /*break*/, 6];
|
|
140
|
+
case "get": return [3 /*break*/, 8];
|
|
141
|
+
case "put": return [3 /*break*/, 10];
|
|
142
|
+
case "delete": return [3 /*break*/, 12];
|
|
143
|
+
case "patch": return [3 /*break*/, 14];
|
|
144
|
+
}
|
|
145
|
+
return [3 /*break*/, 16];
|
|
146
|
+
case 6: return [4 /*yield*/, Fetch.post(route, body, configuration)];
|
|
147
|
+
case 7: return [2 /*return*/, _d.sent()];
|
|
148
|
+
case 8: return [4 /*yield*/, Fetch.get(route, configuration)];
|
|
149
|
+
case 9: return [2 /*return*/, _d.sent()];
|
|
150
|
+
case 10: return [4 /*yield*/, Fetch.put(route, body, configuration)];
|
|
151
|
+
case 11: return [2 /*return*/, _d.sent()];
|
|
152
|
+
case 12: return [4 /*yield*/, Fetch.delete(route, configuration)];
|
|
153
|
+
case 13: return [2 /*return*/, _d.sent()];
|
|
154
|
+
case 14: return [4 /*yield*/, Fetch.patch(route, body, configuration)];
|
|
155
|
+
case 15: return [2 /*return*/, _d.sent()];
|
|
156
|
+
case 16: return [3 /*break*/, 18];
|
|
157
|
+
case 17:
|
|
158
|
+
handleSessionExpiry();
|
|
159
|
+
return [2 /*return*/, { data: [], error: "401.invalid-token" }];
|
|
160
|
+
case 18: return [3 /*break*/, 20];
|
|
161
|
+
case 19:
|
|
162
|
+
tokenError_1 = _d.sent();
|
|
163
|
+
console.error("Token renewal failed:", tokenError_1);
|
|
164
|
+
handleSessionExpiry();
|
|
165
|
+
return [2 /*return*/, { data: [], error: "401.invalid-token" }];
|
|
166
|
+
case 20: return [3 /*break*/, 22];
|
|
167
|
+
case 21:
|
|
168
|
+
handleSessionExpiry();
|
|
169
|
+
return [2 /*return*/, { data: [], error: "401.invalid-token" }];
|
|
170
|
+
case 22: return [2 /*return*/, result];
|
|
171
|
+
case 23:
|
|
172
|
+
error_2 = _d.sent();
|
|
173
|
+
message = ((_b = error_2) === null || _b === void 0 ? void 0 : _b.message) || String(error_2);
|
|
174
|
+
console.error("Fetch failed:", message);
|
|
175
|
+
return [2 /*return*/, { data: [], error: message || "Unknown error" }];
|
|
176
|
+
case 24: return [2 /*return*/];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
var Fetch = /** @class */ (function () {
|
|
182
|
+
function Fetch() {
|
|
183
|
+
}
|
|
184
|
+
Fetch.get = function (route, configuration) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
switch (_a.label) {
|
|
188
|
+
case 0: return [4 /*yield*/, _fetch("get", route, configuration)];
|
|
189
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
Fetch.post = function (route, body, configuration) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
return __generator(this, function (_a) {
|
|
197
|
+
switch (_a.label) {
|
|
198
|
+
case 0: return [4 /*yield*/, _fetch("post", route, configuration, body)];
|
|
199
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
Fetch.put = function (route, body, configuration) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0: return [4 /*yield*/, _fetch("put", route, configuration, body)];
|
|
209
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
Fetch.patch = function (route, body, configuration) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
return __generator(this, function (_a) {
|
|
217
|
+
switch (_a.label) {
|
|
218
|
+
case 0: return [4 /*yield*/, _fetch("patch", route, configuration, body)];
|
|
219
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
Fetch.delete = function (route, configuration, body) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0: return [4 /*yield*/, _fetch("delete", route, configuration, body)];
|
|
229
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
return Fetch;
|
|
235
|
+
}());
|
|
236
|
+
exports.Fetch = Fetch;
|
|
237
|
+
// export async function verifyToken(token: string, secretKey: string) {
|
|
238
|
+
// try {
|
|
239
|
+
// const secret_Key = new TextEncoder().encode(this.configuration.jwt_secret);
|
|
240
|
+
// const decoded = jwtVerify(token, secret_Key);
|
|
241
|
+
// return decoded;
|
|
242
|
+
// } catch (error) {
|
|
243
|
+
// throw new Error('Invalid token');
|
|
244
|
+
// }
|
|
245
|
+
// }
|