lamp-core-lst 2025.11.17 → 2025.11.20
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 +2 -1
- package/dist/index.js +2 -0
- package/dist/model/ResearcherSettings.d.ts +12 -0
- package/dist/service/ActivityEvent.service.d.ts +11 -0
- package/dist/service/ActivityEvent.service.js +26 -0
- package/dist/service/Fetch.js +1 -1
- package/dist/service/ImageUpload.service.d.ts +14 -0
- package/dist/service/ImageUpload.service.js +108 -0
- package/dist/service/ResearcherSettings.service.js +1 -1
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +1 -0
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/model/ResearcherSettings.ts +12 -0
- package/src/service/ActivityEvent.service.ts +25 -0
- package/src/service/Fetch.ts +3 -1
- package/src/service/ImageUpload.service.ts +69 -0
- package/src/service/ResearcherSettings.service.ts +1 -4
- 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 } from "./service/index";
|
|
3
|
+
import { APIService, ActivityService, ActivityEventService, ActivitySpecService, CredentialService, ParticipantService, ResearcherService, SensorService, SensorEventService, SensorSpecService, StudyService, TypeService, ResearcherSettingsService, ImageUploadService } from "./service/index";
|
|
4
4
|
export * from "./service/index";
|
|
5
5
|
export * from "./model/index";
|
|
6
6
|
/**
|
|
@@ -29,6 +29,7 @@ export default class LAMP {
|
|
|
29
29
|
static SensorEvent: SensorEventService;
|
|
30
30
|
static SensorSpec: SensorSpecService;
|
|
31
31
|
static ResearcherSettings: ResearcherSettingsService;
|
|
32
|
+
static ImageUpload: ImageUploadService;
|
|
32
33
|
private static get configuration();
|
|
33
34
|
private static set configuration(value);
|
|
34
35
|
private static protocol;
|
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ var LAMP = /** @class */ (function () {
|
|
|
90
90
|
LAMP.Study.configuration = configuration;
|
|
91
91
|
LAMP.Type.configuration = configuration;
|
|
92
92
|
LAMP.ResearcherSettings.configuration = configuration;
|
|
93
|
+
LAMP.ImageUpload.configuration = configuration;
|
|
93
94
|
},
|
|
94
95
|
enumerable: false,
|
|
95
96
|
configurable: true
|
|
@@ -170,6 +171,7 @@ var LAMP = /** @class */ (function () {
|
|
|
170
171
|
LAMP.SensorEvent = new index_1.SensorEventService();
|
|
171
172
|
LAMP.SensorSpec = new index_1.SensorSpecService();
|
|
172
173
|
LAMP.ResearcherSettings = new index_1.ResearcherSettingsService();
|
|
174
|
+
LAMP.ImageUpload = new index_1.ImageUploadService();
|
|
173
175
|
LAMP.protocol = "https://";
|
|
174
176
|
LAMP.Auth = (_b = /** @class */ (function () {
|
|
175
177
|
function class_1() {
|
|
@@ -43,6 +43,18 @@ export declare class ResearcherSettings {
|
|
|
43
43
|
* The featured activity
|
|
44
44
|
*/
|
|
45
45
|
featuredActivity?: string;
|
|
46
|
+
/**
|
|
47
|
+
* The streak type
|
|
48
|
+
*/
|
|
49
|
+
streakType?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The Streak title
|
|
52
|
+
*/
|
|
53
|
+
streakTitle?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The Streak description
|
|
56
|
+
*/
|
|
57
|
+
streakDesc?: string;
|
|
46
58
|
/**
|
|
47
59
|
* The timestamp
|
|
48
60
|
*/
|
|
@@ -43,4 +43,15 @@ export declare class ActivityEventService {
|
|
|
43
43
|
* @param to
|
|
44
44
|
*/
|
|
45
45
|
delete(participantId: Identifier, origin?: string, from?: number, to?: number): Promise<Identifier>;
|
|
46
|
+
/**
|
|
47
|
+
* Get activities with events for a participant
|
|
48
|
+
* Returns array of { id: string, name: string, spec?: string }
|
|
49
|
+
* Excludes activities with specs: lamp.group, lamp.tips, lamp.module, lamp.zoom_meeting, lamp.fragmented_letters
|
|
50
|
+
* @param participantId
|
|
51
|
+
*/
|
|
52
|
+
getActivitiesWithEvents(participantId: Identifier): Promise<Array<{
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
spec?: string;
|
|
56
|
+
}>>;
|
|
46
57
|
}
|
|
@@ -298,6 +298,32 @@ var ActivityEventService = /** @class */ (function () {
|
|
|
298
298
|
});
|
|
299
299
|
});
|
|
300
300
|
};
|
|
301
|
+
/**
|
|
302
|
+
* Get activities with events for a participant
|
|
303
|
+
* Returns array of { id: string, name: string, spec?: string }
|
|
304
|
+
* Excludes activities with specs: lamp.group, lamp.tips, lamp.module, lamp.zoom_meeting, lamp.fragmented_letters
|
|
305
|
+
* @param participantId
|
|
306
|
+
*/
|
|
307
|
+
ActivityEventService.prototype.getActivitiesWithEvents = function (participantId) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
+
var result;
|
|
310
|
+
return __generator(this, function (_a) {
|
|
311
|
+
switch (_a.label) {
|
|
312
|
+
case 0:
|
|
313
|
+
if (participantId === null || participantId === undefined)
|
|
314
|
+
throw new Error("Required parameter participantId was null or undefined when calling getActivitiesWithEvents.");
|
|
315
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
316
|
+
// DEMO - return empty array for demo mode
|
|
317
|
+
return [2 /*return*/, Promise.resolve([])];
|
|
318
|
+
}
|
|
319
|
+
return [4 /*yield*/, Fetch_1.Fetch.get("/participant/" + participantId + "/activity_event/activities", this.configuration)];
|
|
320
|
+
case 1:
|
|
321
|
+
result = _a.sent();
|
|
322
|
+
return [2 /*return*/, result.data || []];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
};
|
|
301
327
|
return ActivityEventService;
|
|
302
328
|
}());
|
|
303
329
|
exports.ActivityEventService = ActivityEventService;
|
package/dist/service/Fetch.js
CHANGED
|
@@ -103,7 +103,7 @@ function _fetch(method, route, configuration, body) {
|
|
|
103
103
|
return [4 /*yield*/, fetch("" + configuration.base + route, {
|
|
104
104
|
method: method,
|
|
105
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 || {}))),
|
|
106
|
+
? __assign(__assign({ "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", Accept: "application/json" }, (configuration.headers || {})), { Authorization: authorization }) : __assign({ "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", Accept: "application/json" }, (configuration.headers || {}))),
|
|
107
107
|
credentials: "include",
|
|
108
108
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
109
109
|
})];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Configuration } from "./Fetch";
|
|
2
|
+
export declare class ImageUploadService {
|
|
3
|
+
configuration?: Configuration;
|
|
4
|
+
/**
|
|
5
|
+
* Upload an image file to Azure Blob Storage
|
|
6
|
+
* @param imageType - Type of image: "tip_images", "survey_question_icons", or "activity_images"
|
|
7
|
+
* @param file - The image file to upload
|
|
8
|
+
* @returns Promise with originalUrl and thumbnailUrl
|
|
9
|
+
*/
|
|
10
|
+
uploadImage(imageType: "tip_images" | "survey_question_icons" | "activity_images", file: File): Promise<{
|
|
11
|
+
originalUrl: string;
|
|
12
|
+
thumbnailUrl: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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.ImageUploadService = void 0;
|
|
51
|
+
var ImageUploadService = /** @class */ (function () {
|
|
52
|
+
function ImageUploadService() {
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Upload an image file to Azure Blob Storage
|
|
56
|
+
* @param imageType - Type of image: "tip_images", "survey_question_icons", or "activity_images"
|
|
57
|
+
* @param file - The image file to upload
|
|
58
|
+
* @returns Promise with originalUrl and thumbnailUrl
|
|
59
|
+
*/
|
|
60
|
+
ImageUploadService.prototype.uploadImage = function (imageType, file) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var formData, authorization, userTokenFromLocalStore, headers, response, error, result;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (!file) {
|
|
67
|
+
throw new Error("File is required for image upload");
|
|
68
|
+
}
|
|
69
|
+
if (!["tip_images", "survey_question_icons", "activity_images"].includes(imageType)) {
|
|
70
|
+
throw new Error("Invalid image type. Must be one of: tip_images, survey_question_icons, activity_images");
|
|
71
|
+
}
|
|
72
|
+
if (!this.configuration) {
|
|
73
|
+
throw new Error("Cannot make HTTP request due to invalid configuration.");
|
|
74
|
+
}
|
|
75
|
+
formData = new FormData();
|
|
76
|
+
formData.append("image", file);
|
|
77
|
+
userTokenFromLocalStore = JSON.parse(sessionStorage.getItem("tokenInfo") || "null");
|
|
78
|
+
if (userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken) {
|
|
79
|
+
authorization = "Bearer " + (this.configuration.accessToken ? this.configuration.accessToken : userTokenFromLocalStore === null || userTokenFromLocalStore === void 0 ? void 0 : userTokenFromLocalStore.accessToken);
|
|
80
|
+
}
|
|
81
|
+
headers = __assign({ "Access-Control-Allow-Origin": "*", Accept: "application/json" }, (this.configuration.headers || {}));
|
|
82
|
+
if (authorization) {
|
|
83
|
+
headers.Authorization = authorization;
|
|
84
|
+
}
|
|
85
|
+
return [4 /*yield*/, fetch(this.configuration.base + "/upload/image/" + imageType, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: headers,
|
|
88
|
+
credentials: "include",
|
|
89
|
+
body: formData,
|
|
90
|
+
})];
|
|
91
|
+
case 1:
|
|
92
|
+
response = _a.sent();
|
|
93
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
94
|
+
return [4 /*yield*/, response.json().catch(function () { return ({ error: "HTTP " + response.status }); })];
|
|
95
|
+
case 2:
|
|
96
|
+
error = _a.sent();
|
|
97
|
+
throw new Error(error.error || "Upload failed with status " + response.status);
|
|
98
|
+
case 3: return [4 /*yield*/, response.json()];
|
|
99
|
+
case 4:
|
|
100
|
+
result = _a.sent();
|
|
101
|
+
return [2 /*return*/, result.data || result];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
return ImageUploadService;
|
|
107
|
+
}());
|
|
108
|
+
exports.ImageUploadService = ImageUploadService;
|
|
@@ -103,7 +103,7 @@ var ResearcherSettingsService = /** @class */ (function () {
|
|
|
103
103
|
}
|
|
104
104
|
return [4 /*yield*/, Fetch_1.Fetch.get("/participant/researcherSettings/" + participantId, this.configuration)];
|
|
105
105
|
case 1:
|
|
106
|
-
result =
|
|
106
|
+
result = _a.sent();
|
|
107
107
|
return [2 /*return*/, result.data];
|
|
108
108
|
}
|
|
109
109
|
});
|
package/dist/service/index.d.ts
CHANGED
package/dist/service/index.js
CHANGED
|
@@ -23,3 +23,4 @@ __exportStar(require("./SensorSpec.service"), exports);
|
|
|
23
23
|
__exportStar(require("./Study.service"), exports);
|
|
24
24
|
__exportStar(require("./Type.service"), exports);
|
|
25
25
|
__exportStar(require("./API.service"), exports);
|
|
26
|
+
__exportStar(require("./ImageUpload.service"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lamp-core-lst",
|
|
3
|
-
"version": "2025.11.
|
|
3
|
+
"version": "2025.11.20",
|
|
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/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
StudyService,
|
|
15
15
|
TypeService,
|
|
16
16
|
ResearcherSettingsService,
|
|
17
|
+
ImageUploadService,
|
|
17
18
|
} from "./service/index"
|
|
18
19
|
import { Configuration } from "./service/Fetch"
|
|
19
20
|
import { Demo } from "./service/Demo"
|
|
@@ -51,6 +52,7 @@ export default class LAMP {
|
|
|
51
52
|
public static SensorEvent = new SensorEventService()
|
|
52
53
|
public static SensorSpec = new SensorSpecService()
|
|
53
54
|
public static ResearcherSettings = new ResearcherSettingsService()
|
|
55
|
+
public static ImageUpload = new ImageUploadService()
|
|
54
56
|
private static get configuration(): Configuration | undefined {
|
|
55
57
|
return LAMP.API.configuration
|
|
56
58
|
}
|
|
@@ -68,6 +70,7 @@ export default class LAMP {
|
|
|
68
70
|
LAMP.Study.configuration = configuration
|
|
69
71
|
LAMP.Type.configuration = configuration
|
|
70
72
|
LAMP.ResearcherSettings.configuration = configuration
|
|
73
|
+
LAMP.ImageUpload.configuration = configuration
|
|
71
74
|
}
|
|
72
75
|
private static protocol = "https://"
|
|
73
76
|
|
|
@@ -49,6 +49,18 @@ export class ResearcherSettings {
|
|
|
49
49
|
* The featured activity
|
|
50
50
|
*/
|
|
51
51
|
featuredActivity?: string
|
|
52
|
+
/**
|
|
53
|
+
* The streak type
|
|
54
|
+
*/
|
|
55
|
+
streakType?: string
|
|
56
|
+
/**
|
|
57
|
+
* The Streak title
|
|
58
|
+
*/
|
|
59
|
+
streakTitle?: string
|
|
60
|
+
/**
|
|
61
|
+
* The Streak description
|
|
62
|
+
*/
|
|
63
|
+
streakDesc?: string
|
|
52
64
|
/**
|
|
53
65
|
* The timestamp
|
|
54
66
|
*/
|
|
@@ -241,4 +241,29 @@ export class ActivityEventService {
|
|
|
241
241
|
this.configuration
|
|
242
242
|
)
|
|
243
243
|
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get activities with events for a participant
|
|
247
|
+
* Returns array of { id: string, name: string, spec?: string }
|
|
248
|
+
* Excludes activities with specs: lamp.group, lamp.tips, lamp.module, lamp.zoom_meeting, lamp.fragmented_letters
|
|
249
|
+
* @param participantId
|
|
250
|
+
*/
|
|
251
|
+
public async getActivitiesWithEvents(participantId: Identifier): Promise<Array<{ id: string; name: string; spec?: string }>> {
|
|
252
|
+
if (participantId === null || participantId === undefined)
|
|
253
|
+
throw new Error(
|
|
254
|
+
"Required parameter participantId was null or undefined when calling getActivitiesWithEvents."
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
258
|
+
// DEMO - return empty array for demo mode
|
|
259
|
+
return Promise.resolve([])
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const result = await Fetch.get<{ data: Array<{ id: string; name: string; spec?: string }> }>(
|
|
263
|
+
`/participant/${participantId}/activity_event/activities`,
|
|
264
|
+
this.configuration
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
return result.data || []
|
|
268
|
+
}
|
|
244
269
|
}
|
package/src/service/Fetch.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jwtVerify } from "jose"
|
|
2
2
|
import { CredentialService } from "./Credential.service"
|
|
3
|
-
import LAMP from ".."
|
|
4
3
|
/**
|
|
5
4
|
*
|
|
6
5
|
*/
|
|
@@ -64,6 +63,7 @@ async function _fetch<ResultType>(
|
|
|
64
63
|
configuration?: Configuration,
|
|
65
64
|
body?: any
|
|
66
65
|
): Promise<ResultType> {
|
|
66
|
+
|
|
67
67
|
if (!configuration) throw new Error("Cannot make HTTP request due to invalid configuration.")
|
|
68
68
|
let authorization
|
|
69
69
|
|
|
@@ -81,12 +81,14 @@ async function _fetch<ResultType>(
|
|
|
81
81
|
typeof authorization !== "undefined" && !!authorization
|
|
82
82
|
? {
|
|
83
83
|
"Content-Type": "application/json",
|
|
84
|
+
"Access-Control-Allow-Origin": "*",
|
|
84
85
|
Accept: "application/json",
|
|
85
86
|
...(configuration!.headers || {}),
|
|
86
87
|
Authorization: authorization,
|
|
87
88
|
}
|
|
88
89
|
: ({
|
|
89
90
|
"Content-Type": "application/json",
|
|
91
|
+
"Access-Control-Allow-Origin": "*",
|
|
90
92
|
Accept: "application/json",
|
|
91
93
|
...(configuration!.headers || {}),
|
|
92
94
|
} as any)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Fetch, Configuration } from "./Fetch"
|
|
2
|
+
import { Identifier } from "../model/Type"
|
|
3
|
+
|
|
4
|
+
export class ImageUploadService {
|
|
5
|
+
public configuration?: Configuration
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Upload an image file to Azure Blob Storage
|
|
9
|
+
* @param imageType - Type of image: "tip_images", "survey_question_icons", or "activity_images"
|
|
10
|
+
* @param file - The image file to upload
|
|
11
|
+
* @returns Promise with originalUrl and thumbnailUrl
|
|
12
|
+
*/
|
|
13
|
+
public async uploadImage(
|
|
14
|
+
imageType: "tip_images" | "survey_question_icons" | "activity_images",
|
|
15
|
+
file: File
|
|
16
|
+
): Promise<{ originalUrl: string; thumbnailUrl: string }> {
|
|
17
|
+
if (!file) {
|
|
18
|
+
throw new Error("File is required for image upload")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!["tip_images", "survey_question_icons", "activity_images"].includes(imageType)) {
|
|
22
|
+
throw new Error("Invalid image type. Must be one of: tip_images, survey_question_icons, activity_images")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!this.configuration) {
|
|
26
|
+
throw new Error("Cannot make HTTP request due to invalid configuration.")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create FormData for file upload
|
|
30
|
+
const formData = new FormData()
|
|
31
|
+
formData.append("image", file)
|
|
32
|
+
|
|
33
|
+
// Get authorization header - use the same format as Fetch class
|
|
34
|
+
let authorization: string | undefined
|
|
35
|
+
const userTokenFromLocalStore: any = JSON.parse(sessionStorage.getItem("tokenInfo") || "null")
|
|
36
|
+
if (userTokenFromLocalStore?.accessToken) {
|
|
37
|
+
authorization = `Bearer ${
|
|
38
|
+
this.configuration.accessToken ? this.configuration.accessToken : userTokenFromLocalStore?.accessToken
|
|
39
|
+
}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Build headers - don't set Content-Type for FormData (browser will set it with boundary)
|
|
43
|
+
const headers: HeadersInit = {
|
|
44
|
+
"Access-Control-Allow-Origin": "*",
|
|
45
|
+
Accept: "application/json",
|
|
46
|
+
...(this.configuration.headers || {}),
|
|
47
|
+
}
|
|
48
|
+
if (authorization) {
|
|
49
|
+
headers.Authorization = authorization
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Make POST request with FormData
|
|
53
|
+
const response = await fetch(`${this.configuration.base}/upload/image/${imageType}`, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers,
|
|
56
|
+
credentials: "include",
|
|
57
|
+
body: formData,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const error = await response.json().catch(() => ({ error: `HTTP ${response.status}` }))
|
|
62
|
+
throw new Error(error.error || `Upload failed with status ${response.status}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const result = await response.json()
|
|
66
|
+
return result.data || result
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
@@ -53,10 +53,7 @@ export class ResearcherSettingsService {
|
|
|
53
53
|
// DEMO
|
|
54
54
|
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
55
55
|
}
|
|
56
|
-
const result =
|
|
57
|
-
`/participant/researcherSettings/${participantId}`,
|
|
58
|
-
this.configuration
|
|
59
|
-
)) as ResearcherBanner
|
|
56
|
+
const result: any = await Fetch.get(`/participant/researcherSettings/${participantId}`, this.configuration)
|
|
60
57
|
return result.data
|
|
61
58
|
}
|
|
62
59
|
}
|
package/src/service/index.ts
CHANGED