lamp-core-lst 2025.12.2 → 2026.1.19
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.d.ts +11 -1
- package/dist/index.js +35 -1
- package/dist/service/Activity.service.d.ts +83 -0
- package/dist/service/Activity.service.js +232 -25
- package/dist/service/Demo.d.ts +1 -0
- package/dist/service/Demo.js +1 -0
- package/dist/service/Fetch.js +55 -7
- package/dist/service/ImageUpload.service.js +1 -1
- package/dist/service/Participant.service.d.ts +30 -0
- package/dist/service/Participant.service.js +59 -0
- package/dist/service/SurveyResponse.service.d.ts +142 -0
- package/dist/service/SurveyResponse.service.js +292 -0
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +1 -0
- package/package.json +1 -1
- package/src/index.ts +39 -1
- package/src/service/Activity.service.ts +321 -53
- package/src/service/Demo.ts +1 -0
- package/src/service/Fetch.ts +58 -9
- package/src/service/ImageUpload.service.ts +3 -1
- package/src/service/Participant.service.ts +65 -0
- package/src/service/SurveyResponse.service.ts +306 -0
- package/src/service/index.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "isomorphic-fetch";
|
|
2
2
|
import { Researcher, Participant } from "./model/index";
|
|
3
|
-
import { APIService, ActivityService, ActivityEventService, ActivitySpecService, CredentialService, ParticipantService, ResearcherService, SensorService, SensorEventService, SensorSpecService, StudyService, TypeService, ResearcherSettingsService, ImageUploadService } from "./service/index";
|
|
3
|
+
import { APIService, ActivityService, ActivityEventService, ActivitySpecService, CredentialService, ParticipantService, ResearcherService, SensorService, SensorEventService, SensorSpecService, StudyService, TypeService, ResearcherSettingsService, ImageUploadService, SurveyResponseService } from "./service/index";
|
|
4
4
|
export * from "./service/index";
|
|
5
5
|
export * from "./model/index";
|
|
6
6
|
/**
|
|
@@ -30,6 +30,7 @@ export default class LAMP {
|
|
|
30
30
|
static SensorSpec: SensorSpecService;
|
|
31
31
|
static ResearcherSettings: ResearcherSettingsService;
|
|
32
32
|
static ImageUpload: ImageUploadService;
|
|
33
|
+
static SurveyResponse: SurveyResponseService;
|
|
33
34
|
private static get configuration();
|
|
34
35
|
private static set configuration(value);
|
|
35
36
|
private static protocol;
|
|
@@ -45,6 +46,15 @@ export default class LAMP {
|
|
|
45
46
|
secretKey: string | null;
|
|
46
47
|
serverAddress: string | undefined;
|
|
47
48
|
}): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Connect using Bearer token authentication (JWT).
|
|
51
|
+
* Use this for server-to-server communication where you have an access token.
|
|
52
|
+
* @param options - Connection options with accessToken and serverAddress
|
|
53
|
+
*/
|
|
54
|
+
static connectWithToken(options: {
|
|
55
|
+
accessToken: string;
|
|
56
|
+
serverAddress: string;
|
|
57
|
+
}): Promise<void>;
|
|
48
58
|
static Auth: {
|
|
49
59
|
new (): {};
|
|
50
60
|
_auth: IAuth;
|
package/dist/index.js
CHANGED
|
@@ -91,6 +91,7 @@ var LAMP = /** @class */ (function () {
|
|
|
91
91
|
LAMP.Type.configuration = configuration;
|
|
92
92
|
LAMP.ResearcherSettings.configuration = configuration;
|
|
93
93
|
LAMP.ImageUpload.configuration = configuration;
|
|
94
|
+
LAMP.SurveyResponse.configuration = configuration;
|
|
94
95
|
},
|
|
95
96
|
enumerable: false,
|
|
96
97
|
configurable: true
|
|
@@ -131,7 +132,7 @@ var LAMP = /** @class */ (function () {
|
|
|
131
132
|
//
|
|
132
133
|
// [Credential/Identity Management]
|
|
133
134
|
//
|
|
134
|
-
// Shorthand for console/data analysis usage.
|
|
135
|
+
// Shorthand for console/data analysis usage with Basic auth (accessKey:secretKey).
|
|
135
136
|
LAMP.connect = function (identity) {
|
|
136
137
|
if (identity === void 0) { identity = {
|
|
137
138
|
accessKey: null,
|
|
@@ -157,6 +158,38 @@ var LAMP = /** @class */ (function () {
|
|
|
157
158
|
});
|
|
158
159
|
});
|
|
159
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* Connect using Bearer token authentication (JWT).
|
|
163
|
+
* Use this for server-to-server communication where you have an access token.
|
|
164
|
+
* @param options - Connection options with accessToken and serverAddress
|
|
165
|
+
*/
|
|
166
|
+
LAMP.connectWithToken = function (options) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
if (!options.accessToken) {
|
|
170
|
+
throw new Error("accessToken is required for Bearer token authentication");
|
|
171
|
+
}
|
|
172
|
+
if (!options.serverAddress) {
|
|
173
|
+
throw new Error("serverAddress is required");
|
|
174
|
+
}
|
|
175
|
+
// Store auth info
|
|
176
|
+
LAMP.Auth._auth = {
|
|
177
|
+
id: null,
|
|
178
|
+
password: null,
|
|
179
|
+
serverAddress: options.serverAddress,
|
|
180
|
+
token: options.accessToken,
|
|
181
|
+
};
|
|
182
|
+
// Configure with Bearer token
|
|
183
|
+
LAMP.configuration = {
|
|
184
|
+
base: options.serverAddress.startsWith("http")
|
|
185
|
+
? options.serverAddress
|
|
186
|
+
: "https://" + options.serverAddress,
|
|
187
|
+
accessToken: options.accessToken,
|
|
188
|
+
};
|
|
189
|
+
return [2 /*return*/];
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
160
193
|
var _b;
|
|
161
194
|
LAMP.API = new index_1.APIService();
|
|
162
195
|
LAMP.Type = new index_1.TypeService();
|
|
@@ -172,6 +205,7 @@ var LAMP = /** @class */ (function () {
|
|
|
172
205
|
LAMP.SensorSpec = new index_1.SensorSpecService();
|
|
173
206
|
LAMP.ResearcherSettings = new index_1.ResearcherSettingsService();
|
|
174
207
|
LAMP.ImageUpload = new index_1.ImageUploadService();
|
|
208
|
+
LAMP.SurveyResponse = new index_1.SurveyResponseService();
|
|
175
209
|
LAMP.protocol = "https://";
|
|
176
210
|
LAMP.Auth = (_b = /** @class */ (function () {
|
|
177
211
|
function class_1() {
|
|
@@ -105,4 +105,87 @@ export declare class ActivityService {
|
|
|
105
105
|
* @param dateMs optional UTC ms for the day to fetch; defaults to today if omitted
|
|
106
106
|
*/
|
|
107
107
|
feedDetails(participantId: Identifier, dateMs?: string): Promise<any>;
|
|
108
|
+
/**
|
|
109
|
+
* Get multiple activities in a single request (bulk fetch).
|
|
110
|
+
* More efficient than calling view() in a loop.
|
|
111
|
+
* @param activityIds Array of activity IDs to fetch
|
|
112
|
+
* @returns Array of Activity objects
|
|
113
|
+
*/
|
|
114
|
+
viewBatch(activityIds: string[]): Promise<Activity[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Export activities with their attachments.
|
|
117
|
+
* Fetches activities and their associated attachment data (activity_details or survey_description).
|
|
118
|
+
* @param activityIds Array of activity IDs to export
|
|
119
|
+
* @returns Array of { activity, attachment } objects
|
|
120
|
+
*/
|
|
121
|
+
exportActivities(activityIds: string[]): Promise<ActivityExportResult[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Import activities with their attachments into a target study.
|
|
124
|
+
* Creates new activities and sets their attachments.
|
|
125
|
+
* @param studyId Target study ID to import activities into
|
|
126
|
+
* @param activitiesWithAttachments Array of { activity, attachment } objects (from export)
|
|
127
|
+
* @param options Import options
|
|
128
|
+
* @returns Import result with success/failure details
|
|
129
|
+
*/
|
|
130
|
+
importActivities(studyId: Identifier, activitiesWithAttachments: ActivityExportResult[], options?: ActivityImportOptions): Promise<ActivityImportResult>;
|
|
131
|
+
/**
|
|
132
|
+
* Delete an Activity bin.
|
|
133
|
+
* @param parentId Study ID for global delete, Activity ID for local delete
|
|
134
|
+
* @param binId
|
|
135
|
+
*/
|
|
136
|
+
deleteActivityBin(parentId: Identifier, binId: Identifier, isGlobalDelete?: boolean, isEdit?: boolean): Promise<Identifier>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Result of activity export
|
|
140
|
+
*/
|
|
141
|
+
export interface ActivityExportResult {
|
|
142
|
+
/** The exported activity */
|
|
143
|
+
activity: Activity;
|
|
144
|
+
/** The activity's attachment data (activity_details or survey_description) */
|
|
145
|
+
attachment: any | null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Options for activity import
|
|
149
|
+
*/
|
|
150
|
+
export interface ActivityImportOptions {
|
|
151
|
+
/** Whether to preserve the original activity name (default: true) */
|
|
152
|
+
preserveName?: boolean;
|
|
153
|
+
/** Suffix to add to activity names */
|
|
154
|
+
nameSuffix?: string;
|
|
155
|
+
/** Prefix to add to activity names */
|
|
156
|
+
namePrefix?: string;
|
|
157
|
+
/** Whether to clear schedules during import (default: false) */
|
|
158
|
+
clearSchedule?: boolean;
|
|
159
|
+
/** Whether to preserve activity photo (default: false) */
|
|
160
|
+
preservePhoto?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Result of a single activity import
|
|
164
|
+
*/
|
|
165
|
+
export interface ActivityImportResultItem {
|
|
166
|
+
/** Original activity ID from export */
|
|
167
|
+
originalId: string;
|
|
168
|
+
/** New activity ID after import (null if failed) */
|
|
169
|
+
newId: string | null;
|
|
170
|
+
/** Whether import was successful */
|
|
171
|
+
success: boolean;
|
|
172
|
+
/** Error message if failed */
|
|
173
|
+
error?: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Result of bulk import operation
|
|
177
|
+
*/
|
|
178
|
+
export interface ActivityImportResult {
|
|
179
|
+
/** Overall success (true if all imports succeeded) */
|
|
180
|
+
success: boolean;
|
|
181
|
+
/** Validation errors if data was invalid */
|
|
182
|
+
validationErrors: string[];
|
|
183
|
+
/** Individual import results */
|
|
184
|
+
results: ActivityImportResultItem[];
|
|
185
|
+
/** Summary statistics */
|
|
186
|
+
summary: {
|
|
187
|
+
total: number;
|
|
188
|
+
successful: number;
|
|
189
|
+
failed: number;
|
|
190
|
+
};
|
|
108
191
|
}
|
|
@@ -111,9 +111,7 @@ var ActivityService = /** @class */ (function () {
|
|
|
111
111
|
output = (_a = Demo_1.Demo.Activity.filter(function (x) { var _a; return (_a = Demo_1.Demo.Participant.filter(function (y) { return y["id"] === participantId; })) === null || _a === void 0 ? void 0 : _a.map(function (y) { return y["#parent"]; }).includes(x["#parent"]); })) === null || _a === void 0 ? void 0 : _a.map(function (x) { return Object.assign(new Activity_1.Activity(), x); });
|
|
112
112
|
output = typeof transform === "string" ? jsonata_1.default(transform).evaluate(output) : output;
|
|
113
113
|
total = output.length;
|
|
114
|
-
paginatedOutput = limit !== undefined && offset !== undefined
|
|
115
|
-
? output.slice(offset, offset + limit)
|
|
116
|
-
: output;
|
|
114
|
+
paginatedOutput = limit !== undefined && offset !== undefined ? output.slice(offset, offset + limit) : output;
|
|
117
115
|
return [2 /*return*/, Promise.resolve({ data: paginatedOutput, total: total })];
|
|
118
116
|
}
|
|
119
117
|
else {
|
|
@@ -121,12 +119,12 @@ var ActivityService = /** @class */ (function () {
|
|
|
121
119
|
}
|
|
122
120
|
}
|
|
123
121
|
params = new URLSearchParams();
|
|
124
|
-
params.append(
|
|
122
|
+
params.append("ignore_binary", String(ignore_binary));
|
|
125
123
|
if (limit !== undefined && limit !== null) {
|
|
126
|
-
params.append(
|
|
124
|
+
params.append("limit", limit.toString());
|
|
127
125
|
}
|
|
128
126
|
if (offset !== undefined && offset !== null) {
|
|
129
|
-
params.append(
|
|
127
|
+
params.append("offset", offset.toString());
|
|
130
128
|
}
|
|
131
129
|
queryString = params.toString();
|
|
132
130
|
return [4 /*yield*/, Fetch_1.Fetch.get("/participant/" + participantId + "/activity?" + queryString, this.configuration)
|
|
@@ -144,7 +142,7 @@ var ActivityService = /** @class */ (function () {
|
|
|
144
142
|
activitiesArray = result.data;
|
|
145
143
|
// total exists only when pagination was provided (limit > 0 OR offset >= 0)
|
|
146
144
|
// When no pagination, _select returns array, server wraps as { data: array } (no total)
|
|
147
|
-
totalCount = typeof result.total ===
|
|
145
|
+
totalCount = typeof result.total === "number" ? result.total : activitiesArray.length;
|
|
148
146
|
}
|
|
149
147
|
else if (Array.isArray(result)) {
|
|
150
148
|
// Legacy fallback: if result is directly an array (shouldn't happen with current server)
|
|
@@ -153,7 +151,7 @@ var ActivityService = /** @class */ (function () {
|
|
|
153
151
|
}
|
|
154
152
|
return [2 /*return*/, {
|
|
155
153
|
data: activitiesArray.map(function (x) { return Object.assign(new Activity_1.Activity(), x); }),
|
|
156
|
-
total: totalCount
|
|
154
|
+
total: totalCount,
|
|
157
155
|
}];
|
|
158
156
|
}
|
|
159
157
|
});
|
|
@@ -226,11 +224,9 @@ var ActivityService = /** @class */ (function () {
|
|
|
226
224
|
output = (_a = Demo_1.Demo.Activity.filter(function (x) { return x["#parent"] === studyId; })) === null || _a === void 0 ? void 0 : _a.map(function (x) { return Object.assign(new Activity_1.Activity(), x); });
|
|
227
225
|
output = typeof transform === "string" ? jsonata_1.default(transform).evaluate(output) : output;
|
|
228
226
|
// If pagination is requested, return paginated result with total
|
|
229
|
-
if (typeof limit ===
|
|
227
|
+
if ((typeof limit === "number" && limit > 0) || (typeof offset === "number" && offset > 0)) {
|
|
230
228
|
total = output.length;
|
|
231
|
-
paginatedOutput = limit !== undefined && offset !== undefined
|
|
232
|
-
? output.slice(offset, offset + limit)
|
|
233
|
-
: output;
|
|
229
|
+
paginatedOutput = limit !== undefined && offset !== undefined ? output.slice(offset, offset + limit) : output;
|
|
234
230
|
return [2 /*return*/, Promise.resolve({ data: paginatedOutput, total: total })];
|
|
235
231
|
}
|
|
236
232
|
return [2 /*return*/, Promise.resolve(output)];
|
|
@@ -240,12 +236,12 @@ var ActivityService = /** @class */ (function () {
|
|
|
240
236
|
}
|
|
241
237
|
}
|
|
242
238
|
params = new URLSearchParams();
|
|
243
|
-
params.append(
|
|
239
|
+
params.append("ignore_binary", String(ignore_binary));
|
|
244
240
|
if (limit !== undefined && limit !== null) {
|
|
245
|
-
params.append(
|
|
241
|
+
params.append("limit", limit.toString());
|
|
246
242
|
}
|
|
247
243
|
if (offset !== undefined && offset !== null) {
|
|
248
|
-
params.append(
|
|
244
|
+
params.append("offset", offset.toString());
|
|
249
245
|
}
|
|
250
246
|
queryString = params.toString();
|
|
251
247
|
return [4 /*yield*/, Fetch_1.Fetch.get("/study/" + studyId + "/activity?" + queryString, this.configuration)
|
|
@@ -259,7 +255,7 @@ var ActivityService = /** @class */ (function () {
|
|
|
259
255
|
totalCount = 0;
|
|
260
256
|
if (result && result.data && Array.isArray(result.data)) {
|
|
261
257
|
activitiesArray = result.data;
|
|
262
|
-
totalCount = typeof result.total ===
|
|
258
|
+
totalCount = typeof result.total === "number" ? result.total : activitiesArray.length;
|
|
263
259
|
}
|
|
264
260
|
else if (Array.isArray(result)) {
|
|
265
261
|
// Legacy fallback: if result is directly an array
|
|
@@ -268,7 +264,7 @@ var ActivityService = /** @class */ (function () {
|
|
|
268
264
|
}
|
|
269
265
|
mappedActivities = activitiesArray.map(function (x) { return Object.assign(new Activity_1.Activity(), x); });
|
|
270
266
|
// If pagination was requested, return { data, total }, otherwise return array for backward compatibility
|
|
271
|
-
if (typeof limit ===
|
|
267
|
+
if ((typeof limit === "number" && limit > 0) || (typeof offset === "number" && offset > 0)) {
|
|
272
268
|
return [2 /*return*/, { data: mappedActivities, total: totalCount }];
|
|
273
269
|
}
|
|
274
270
|
return [2 /*return*/, mappedActivities];
|
|
@@ -310,18 +306,18 @@ var ActivityService = /** @class */ (function () {
|
|
|
310
306
|
params = new URLSearchParams();
|
|
311
307
|
if (tab)
|
|
312
308
|
params.append("tab", tab);
|
|
313
|
-
if (typeof limit ===
|
|
309
|
+
if (typeof limit === "number" && limit > 0)
|
|
314
310
|
params.append("limit", limit.toString());
|
|
315
|
-
if (typeof offset ===
|
|
311
|
+
if (typeof offset === "number" && offset > 0)
|
|
316
312
|
params.append("offset", offset.toString());
|
|
317
313
|
queryString = params.toString();
|
|
318
|
-
return [4 /*yield*/, Fetch_1.Fetch.get("/activity/" + participantId + "/activity" + (queryString ? "?" + queryString :
|
|
314
|
+
return [4 /*yield*/, Fetch_1.Fetch.get("/activity/" + participantId + "/activity" + (queryString ? "?" + queryString : ""), this.configuration)
|
|
319
315
|
// Handle different response structures
|
|
320
316
|
];
|
|
321
317
|
case 1:
|
|
322
318
|
result = _b.sent();
|
|
323
319
|
// Handle different response structures
|
|
324
|
-
if (result && result.data !== undefined && typeof result.total ===
|
|
320
|
+
if (result && result.data !== undefined && typeof result.total === "number") {
|
|
325
321
|
return [2 /*return*/, { data: result.data, total: result.total }];
|
|
326
322
|
}
|
|
327
323
|
// Legacy fallback: if result is directly the data object
|
|
@@ -536,15 +532,17 @@ var ActivityService = /** @class */ (function () {
|
|
|
536
532
|
}
|
|
537
533
|
params = new URLSearchParams();
|
|
538
534
|
if (startTime !== undefined && startTime !== null) {
|
|
539
|
-
params.append(
|
|
535
|
+
params.append("startTime", startTime.toString());
|
|
540
536
|
}
|
|
541
537
|
if (endTime !== undefined && endTime !== null) {
|
|
542
|
-
params.append(
|
|
538
|
+
params.append("endTime", endTime.toString());
|
|
543
539
|
}
|
|
544
540
|
queryString = params.toString();
|
|
545
|
-
url = "/module/" + moduleId + "/" + participantId + (queryString ? "?" + queryString :
|
|
541
|
+
url = "/module/" + moduleId + "/" + participantId + (queryString ? "?" + queryString : "");
|
|
546
542
|
return [4 /*yield*/, Fetch_1.Fetch.get(url, this.configuration)];
|
|
547
|
-
case 1: return [2 /*return*/, (_b = (_c.sent()).data) === null || _b === void 0 ? void 0 : _b.map(function (x) {
|
|
543
|
+
case 1: return [2 /*return*/, (_b = (_c.sent()).data) === null || _b === void 0 ? void 0 : _b.map(function (x) {
|
|
544
|
+
return Object.assign(new Activity_1.Activity(), x);
|
|
545
|
+
})];
|
|
548
546
|
}
|
|
549
547
|
});
|
|
550
548
|
});
|
|
@@ -792,6 +790,215 @@ var ActivityService = /** @class */ (function () {
|
|
|
792
790
|
});
|
|
793
791
|
});
|
|
794
792
|
};
|
|
793
|
+
/**
|
|
794
|
+
* Get multiple activities in a single request (bulk fetch).
|
|
795
|
+
* More efficient than calling view() in a loop.
|
|
796
|
+
* @param activityIds Array of activity IDs to fetch
|
|
797
|
+
* @returns Array of Activity objects
|
|
798
|
+
*/
|
|
799
|
+
ActivityService.prototype.viewBatch = function (activityIds) {
|
|
800
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
801
|
+
var auth_16, credential, activities, result;
|
|
802
|
+
return __generator(this, function (_a) {
|
|
803
|
+
switch (_a.label) {
|
|
804
|
+
case 0:
|
|
805
|
+
if (!activityIds || activityIds.length === 0) {
|
|
806
|
+
return [2 /*return*/, []];
|
|
807
|
+
}
|
|
808
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
809
|
+
auth_16 = (this.configuration.authorization || ":").split(":");
|
|
810
|
+
credential = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === auth_16[0] && x["secret_key"] === auth_16[1]; });
|
|
811
|
+
if (credential.length === 0)
|
|
812
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
813
|
+
activities = Demo_1.Demo.Activity.filter(function (x) { return activityIds.includes(x["id"]); });
|
|
814
|
+
return [2 /*return*/, activities.map(function (activity) { return Object.assign(new Activity_1.Activity(), activity); })];
|
|
815
|
+
}
|
|
816
|
+
return [4 /*yield*/, Fetch_1.Fetch.post("/activity/batch", activityIds, this.configuration)];
|
|
817
|
+
case 1:
|
|
818
|
+
result = _a.sent();
|
|
819
|
+
return [2 /*return*/, (result.data || []).map(function (x) { return Object.assign(new Activity_1.Activity(), x); })];
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
});
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Export activities with their attachments.
|
|
826
|
+
* Fetches activities and their associated attachment data (activity_details or survey_description).
|
|
827
|
+
* @param activityIds Array of activity IDs to export
|
|
828
|
+
* @returns Array of { activity, attachment } objects
|
|
829
|
+
*/
|
|
830
|
+
ActivityService.prototype.exportActivities = function (activityIds) {
|
|
831
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
832
|
+
var auth_17, credential, activities, result;
|
|
833
|
+
return __generator(this, function (_a) {
|
|
834
|
+
switch (_a.label) {
|
|
835
|
+
case 0:
|
|
836
|
+
if (!activityIds || activityIds.length === 0) {
|
|
837
|
+
return [2 /*return*/, []];
|
|
838
|
+
}
|
|
839
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
840
|
+
auth_17 = (this.configuration.authorization || ":").split(":");
|
|
841
|
+
credential = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === auth_17[0] && x["secret_key"] === auth_17[1]; });
|
|
842
|
+
if (credential.length === 0)
|
|
843
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
844
|
+
activities = Demo_1.Demo.Activity.filter(function (x) { return activityIds.includes(x["id"]); });
|
|
845
|
+
return [2 /*return*/, activities.map(function (activity) { return ({
|
|
846
|
+
activity: Object.assign(new Activity_1.Activity(), activity),
|
|
847
|
+
attachment: null,
|
|
848
|
+
}); })];
|
|
849
|
+
}
|
|
850
|
+
return [4 /*yield*/, Fetch_1.Fetch.post("/activity/export", activityIds, this.configuration)];
|
|
851
|
+
case 1:
|
|
852
|
+
result = _a.sent();
|
|
853
|
+
return [2 /*return*/, result.data || []];
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Import activities with their attachments into a target study.
|
|
860
|
+
* Creates new activities and sets their attachments.
|
|
861
|
+
* @param studyId Target study ID to import activities into
|
|
862
|
+
* @param activitiesWithAttachments Array of { activity, attachment } objects (from export)
|
|
863
|
+
* @param options Import options
|
|
864
|
+
* @returns Import result with success/failure details
|
|
865
|
+
*/
|
|
866
|
+
ActivityService.prototype.importActivities = function (studyId, activitiesWithAttachments, options) {
|
|
867
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
868
|
+
var auth_18, credential, results, _i, activitiesWithAttachments_1, item, newId, name_1, result;
|
|
869
|
+
return __generator(this, function (_a) {
|
|
870
|
+
switch (_a.label) {
|
|
871
|
+
case 0:
|
|
872
|
+
if (studyId === null || studyId === undefined) {
|
|
873
|
+
throw new Error("Required parameter studyId was null or undefined when calling importActivities.");
|
|
874
|
+
}
|
|
875
|
+
if (!activitiesWithAttachments || activitiesWithAttachments.length === 0) {
|
|
876
|
+
return [2 /*return*/, {
|
|
877
|
+
success: true,
|
|
878
|
+
validationErrors: [],
|
|
879
|
+
results: [],
|
|
880
|
+
summary: { total: 0, successful: 0, failed: 0 },
|
|
881
|
+
}];
|
|
882
|
+
}
|
|
883
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
884
|
+
auth_18 = (this.configuration.authorization || ":").split(":");
|
|
885
|
+
credential = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === auth_18[0] && x["secret_key"] === auth_18[1]; });
|
|
886
|
+
if (credential.length === 0)
|
|
887
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
888
|
+
if (studyId === "me")
|
|
889
|
+
studyId = credential.length > 0 ? credential[0]["origin"] : studyId;
|
|
890
|
+
results = [];
|
|
891
|
+
for (_i = 0, activitiesWithAttachments_1 = activitiesWithAttachments; _i < activitiesWithAttachments_1.length; _i++) {
|
|
892
|
+
item = activitiesWithAttachments_1[_i];
|
|
893
|
+
newId = "activity" + Math.random().toString().substring(2, 6);
|
|
894
|
+
name_1 = (options === null || options === void 0 ? void 0 : options.namePrefix) ? "" + options.namePrefix + item.activity.name
|
|
895
|
+
: (options === null || options === void 0 ? void 0 : options.nameSuffix) ? "" + item.activity.name + options.nameSuffix
|
|
896
|
+
: item.activity.name;
|
|
897
|
+
Demo_1.Demo.Activity.push({
|
|
898
|
+
"#type": "Activity",
|
|
899
|
+
"#parent": studyId,
|
|
900
|
+
id: newId,
|
|
901
|
+
spec: item.activity.spec,
|
|
902
|
+
name: name_1,
|
|
903
|
+
settings: item.activity.settings,
|
|
904
|
+
schedule: (options === null || options === void 0 ? void 0 : options.clearSchedule) ? [] : item.activity.schedule,
|
|
905
|
+
});
|
|
906
|
+
results.push({
|
|
907
|
+
originalId: item.activity.id,
|
|
908
|
+
newId: newId,
|
|
909
|
+
success: true,
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
return [2 /*return*/, {
|
|
913
|
+
success: true,
|
|
914
|
+
validationErrors: [],
|
|
915
|
+
results: results,
|
|
916
|
+
summary: {
|
|
917
|
+
total: results.length,
|
|
918
|
+
successful: results.length,
|
|
919
|
+
failed: 0,
|
|
920
|
+
},
|
|
921
|
+
}];
|
|
922
|
+
}
|
|
923
|
+
return [4 /*yield*/, Fetch_1.Fetch.post("/study/" + studyId + "/activity/import", { activities: activitiesWithAttachments, options: options }, this.configuration)];
|
|
924
|
+
case 1:
|
|
925
|
+
result = _a.sent();
|
|
926
|
+
return [2 /*return*/, (result.data || {
|
|
927
|
+
success: false,
|
|
928
|
+
validationErrors: [],
|
|
929
|
+
results: [],
|
|
930
|
+
summary: { total: 0, successful: 0, failed: 0 },
|
|
931
|
+
})];
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Delete an Activity bin.
|
|
938
|
+
* @param parentId Study ID for global delete, Activity ID for local delete
|
|
939
|
+
* @param binId
|
|
940
|
+
*/
|
|
941
|
+
ActivityService.prototype.deleteActivityBin = function (parentId, binId, isGlobalDelete, isEdit) {
|
|
942
|
+
if (isGlobalDelete === void 0) { isGlobalDelete = false; }
|
|
943
|
+
if (isEdit === void 0) { isEdit = false; }
|
|
944
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
945
|
+
var auth_19, credential, binIdx, activityIdx, binIdx, params, queryString, route;
|
|
946
|
+
return __generator(this, function (_a) {
|
|
947
|
+
switch (_a.label) {
|
|
948
|
+
case 0:
|
|
949
|
+
if (parentId === null || parentId === undefined)
|
|
950
|
+
throw new Error("Required parameter parentId was null or undefined.");
|
|
951
|
+
if (binId === null || binId === undefined)
|
|
952
|
+
throw new Error("Required parameter binId was null or undefined.");
|
|
953
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
954
|
+
auth_19 = (this.configuration.authorization || ":").split(":");
|
|
955
|
+
credential = Demo_1.Demo.Credential.filter(function (x) { return x["access_key"] === auth_19[0] && x["secret_key"] === auth_19[1]; });
|
|
956
|
+
if (credential.length === 0)
|
|
957
|
+
return [2 /*return*/, Promise.resolve({ error: "403.invalid-credentials" })];
|
|
958
|
+
if (parentId === "me")
|
|
959
|
+
parentId = credential.length > 0 ? credential[0]["origin"] : parentId;
|
|
960
|
+
if (isGlobalDelete) {
|
|
961
|
+
binIdx = Demo_1.Demo.ActivityBin.findIndex(function (x) { return x["id"] === binId; });
|
|
962
|
+
if (binIdx >= 0) {
|
|
963
|
+
Demo_1.Demo.ActivityBin.splice(binIdx, 1);
|
|
964
|
+
return [2 /*return*/, Promise.resolve({})];
|
|
965
|
+
}
|
|
966
|
+
else {
|
|
967
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
activityIdx = Demo_1.Demo.Activity.findIndex(function (x) { return x["id"] === parentId; });
|
|
972
|
+
if (activityIdx < 0) {
|
|
973
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
974
|
+
}
|
|
975
|
+
binIdx = Demo_1.Demo.ActivityBin.findIndex(function (x) { return x["id"] === binId && x["activity"] === parentId; });
|
|
976
|
+
if (binIdx >= 0) {
|
|
977
|
+
Demo_1.Demo.ActivityBin.splice(binIdx, 1);
|
|
978
|
+
return [2 /*return*/, Promise.resolve({})];
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
return [2 /*return*/, Promise.resolve({ error: "404.not-found" })];
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
params = new URLSearchParams();
|
|
986
|
+
if (isGlobalDelete) {
|
|
987
|
+
params.append("isGlobalDelete", String(isGlobalDelete));
|
|
988
|
+
}
|
|
989
|
+
if (isEdit) {
|
|
990
|
+
params.append("isEdit", String(isEdit));
|
|
991
|
+
}
|
|
992
|
+
queryString = params.toString();
|
|
993
|
+
route = queryString
|
|
994
|
+
? "/activity/bin/" + parentId + "/" + binId + "?" + queryString
|
|
995
|
+
: "/activity/bin/" + parentId + "/" + binId;
|
|
996
|
+
return [4 /*yield*/, Fetch_1.Fetch.delete(route, this.configuration)];
|
|
997
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
});
|
|
1001
|
+
};
|
|
795
1002
|
return ActivityService;
|
|
796
1003
|
}());
|
|
797
1004
|
exports.ActivityService = ActivityService;
|
package/dist/service/Demo.d.ts
CHANGED
package/dist/service/Demo.js
CHANGED
package/dist/service/Fetch.js
CHANGED
|
@@ -68,13 +68,50 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
68
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
69
|
exports.Fetch = void 0;
|
|
70
70
|
var Credential_service_1 = require("./Credential.service");
|
|
71
|
+
// Safe wrappers for browser APIs (Node.js compatibility)
|
|
72
|
+
var safeSessionStorage = {
|
|
73
|
+
getItem: function (key) {
|
|
74
|
+
if (typeof sessionStorage !== "undefined") {
|
|
75
|
+
return sessionStorage.getItem(key);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
},
|
|
79
|
+
setItem: function (key, value) {
|
|
80
|
+
if (typeof sessionStorage !== "undefined") {
|
|
81
|
+
sessionStorage.setItem(key, value);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
removeItem: function (key) {
|
|
85
|
+
if (typeof sessionStorage !== "undefined") {
|
|
86
|
+
sessionStorage.removeItem(key);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
var safeLocalStorage = {
|
|
91
|
+
getItem: function (key) {
|
|
92
|
+
if (typeof localStorage !== "undefined") {
|
|
93
|
+
return localStorage.getItem(key);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
},
|
|
97
|
+
setItem: function (key, value) {
|
|
98
|
+
if (typeof localStorage !== "undefined") {
|
|
99
|
+
localStorage.setItem(key, value);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
removeItem: function (key) {
|
|
103
|
+
if (typeof localStorage !== "undefined") {
|
|
104
|
+
localStorage.removeItem(key);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
71
108
|
var userTokenKey = "tokenInfo";
|
|
72
109
|
//If refresh token expired, then logout from app
|
|
73
110
|
var handleSessionExpiry = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
111
|
return __generator(this, function (_a) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
112
|
+
safeLocalStorage.removeItem(userTokenKey);
|
|
113
|
+
safeLocalStorage.setItem("verified", JSON.stringify({ value: false }));
|
|
114
|
+
safeSessionStorage.setItem("LAMP._auth", JSON.stringify({ id: null, password: null, serverAddress: null }));
|
|
78
115
|
return [2 /*return*/];
|
|
79
116
|
});
|
|
80
117
|
}); };
|
|
@@ -93,7 +130,7 @@ var handleRenewToken = function (refreshToken, base, configuration) { return __a
|
|
|
93
130
|
accessToken = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
94
131
|
if (!accessToken) return [3 /*break*/, 5];
|
|
95
132
|
newRefreshToken = ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.refresh_token) || refreshToken;
|
|
96
|
-
|
|
133
|
+
safeSessionStorage.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
134
|
_j.label = 2;
|
|
98
135
|
case 2:
|
|
99
136
|
_j.trys.push([2, 4, , 5]);
|
|
@@ -136,9 +173,20 @@ function _fetch(method, route, configuration, body) {
|
|
|
136
173
|
case 0:
|
|
137
174
|
if (!configuration)
|
|
138
175
|
throw new Error("Cannot make HTTP request due to invalid configuration.");
|
|
139
|
-
userTokenFromLocalStore = JSON.parse(
|
|
140
|
-
|
|
141
|
-
|
|
176
|
+
userTokenFromLocalStore = JSON.parse(safeSessionStorage.getItem("tokenInfo") || "null");
|
|
177
|
+
// Check configuration.accessToken first (for server-side/Node.js usage)
|
|
178
|
+
// Then fallback to sessionStorage (for browser usage)
|
|
179
|
+
if (configuration.accessToken) {
|
|
180
|
+
authorization = "Bearer " + configuration.accessToken;
|
|
181
|
+
}
|
|
182
|
+
else if (userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken) {
|
|
183
|
+
authorization = "Bearer " + userTokenFromLocalStore.accessToken;
|
|
184
|
+
}
|
|
185
|
+
else if (configuration.authorization) {
|
|
186
|
+
// Fallback to Basic auth if provided
|
|
187
|
+
authorization = configuration.authorization.includes(":")
|
|
188
|
+
? "Basic " + (typeof Buffer !== "undefined" ? Buffer.from(configuration.authorization).toString("base64") : btoa(configuration.authorization))
|
|
189
|
+
: configuration.authorization;
|
|
142
190
|
}
|
|
143
191
|
_d.label = 1;
|
|
144
192
|
case 1:
|
|
@@ -74,7 +74,7 @@ var ImageUploadService = /** @class */ (function () {
|
|
|
74
74
|
}
|
|
75
75
|
formData = new FormData();
|
|
76
76
|
formData.append("image", file);
|
|
77
|
-
userTokenFromLocalStore = JSON.parse(sessionStorage.getItem("tokenInfo") || "null");
|
|
77
|
+
userTokenFromLocalStore = JSON.parse(typeof sessionStorage !== "undefined" ? sessionStorage.getItem("tokenInfo") || "null" : "null");
|
|
78
78
|
if (userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken) {
|
|
79
79
|
authorization = "Bearer " + (this.configuration.accessToken ? this.configuration.accessToken : userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken);
|
|
80
80
|
}
|