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,244 @@
|
|
|
1
|
+
import { Fetch, Configuration } from "./Fetch"
|
|
2
|
+
import { Identifier } from "../model/Type"
|
|
3
|
+
import { ActivityEvent } from "../model/ActivityEvent"
|
|
4
|
+
import { Demo } from "./Demo"
|
|
5
|
+
import jsonata from "jsonata"
|
|
6
|
+
|
|
7
|
+
export class ActivityEventService {
|
|
8
|
+
public configuration?: Configuration
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the set of all activity events produced by a given participant, by identifier.
|
|
12
|
+
* @param participantId
|
|
13
|
+
* @param origin
|
|
14
|
+
* @param from
|
|
15
|
+
* @param to
|
|
16
|
+
* @param limit
|
|
17
|
+
* @param ignoreBinary
|
|
18
|
+
*/
|
|
19
|
+
public async allByParticipant(
|
|
20
|
+
participantId: Identifier,
|
|
21
|
+
origin?: string,
|
|
22
|
+
from?: number,
|
|
23
|
+
to?: number,
|
|
24
|
+
limit?: number,
|
|
25
|
+
ignoreBinary?: boolean,
|
|
26
|
+
transform?: string
|
|
27
|
+
): Promise<ActivityEvent[]> {
|
|
28
|
+
if (participantId === null || participantId === undefined)
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Required parameter participantId was null or undefined when calling activityEventAllByParticipant."
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
let queryParameters = new URLSearchParams()
|
|
34
|
+
if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
|
|
35
|
+
if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
|
|
36
|
+
if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
|
|
37
|
+
if (limit !== undefined && limit !== null) queryParameters.set("limit", <any>limit)
|
|
38
|
+
queryParameters.set("ignore_binary", <any>ignoreBinary ?? false)
|
|
39
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
40
|
+
// DEMO
|
|
41
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
42
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
43
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
44
|
+
if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
|
|
45
|
+
|
|
46
|
+
if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
|
|
47
|
+
let output = Demo.ActivityEvent.filter(
|
|
48
|
+
x => x["#parent"] === participantId && (!!origin ? x["activity"] === origin : true)
|
|
49
|
+
).map(x => Object.assign(new ActivityEvent(), x))
|
|
50
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
51
|
+
return Promise.resolve(output)
|
|
52
|
+
} else {
|
|
53
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return (
|
|
57
|
+
await Fetch.get<{ data: any[] }>(
|
|
58
|
+
`/participant/${participantId}/activity_event?${queryParameters.toString()}`,
|
|
59
|
+
this.configuration
|
|
60
|
+
)
|
|
61
|
+
).data?.map(x => Object.assign(new ActivityEvent(), x))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get the set of all activity events produced by participants of any study conducted by a researcher, by researcher identifier.
|
|
66
|
+
* @param researcherId
|
|
67
|
+
* @param origin
|
|
68
|
+
* @param from
|
|
69
|
+
* @param to
|
|
70
|
+
*/
|
|
71
|
+
public async allByResearcher(
|
|
72
|
+
researcherId: Identifier,
|
|
73
|
+
origin?: string,
|
|
74
|
+
from?: number,
|
|
75
|
+
to?: number,
|
|
76
|
+
limit?: number,
|
|
77
|
+
transform?: string
|
|
78
|
+
): Promise<ActivityEvent[]> {
|
|
79
|
+
if (researcherId === null || researcherId === undefined)
|
|
80
|
+
throw new Error(
|
|
81
|
+
"Required parameter researcherId was null or undefined when calling activityEventAllByResearcher."
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
let queryParameters = new URLSearchParams()
|
|
85
|
+
if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
|
|
86
|
+
if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
|
|
87
|
+
if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
|
|
88
|
+
if (limit !== undefined && limit !== null) queryParameters.set("limit", <any>limit)
|
|
89
|
+
|
|
90
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
91
|
+
// DEMO
|
|
92
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
93
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
94
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
95
|
+
if (researcherId === "me") researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
|
|
96
|
+
|
|
97
|
+
if (Demo.Researcher.filter(x => x["id"] === researcherId).length > 0) {
|
|
98
|
+
let participants = Demo.Study.filter(x => x["#parent"] === researcherId)
|
|
99
|
+
.map(x => Demo.Participant.filter(y => y["#parent"] === x["id"]))
|
|
100
|
+
.flat(1)
|
|
101
|
+
let fn = (id: string) =>
|
|
102
|
+
Demo.ActivityEvent.filter(x => x["#parent"] === id && (!!origin ? x["activity"] === origin : true)).map(x =>
|
|
103
|
+
Object.assign(new ActivityEvent(), x)
|
|
104
|
+
)
|
|
105
|
+
let output = participants.reduce(
|
|
106
|
+
(all, participant) => ({ ...all, [participant["id"]]: fn(participant["id"]) }),
|
|
107
|
+
{}
|
|
108
|
+
) as any
|
|
109
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
110
|
+
return Promise.resolve(output)
|
|
111
|
+
} else {
|
|
112
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return (
|
|
116
|
+
await Fetch.get<{ data: any[] }>(
|
|
117
|
+
`/researcher/${researcherId}/activity_event?${queryParameters.toString()}`,
|
|
118
|
+
this.configuration
|
|
119
|
+
)
|
|
120
|
+
).data.map(x => Object.assign(new ActivityEvent(), x))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get the set of all activity events produced by participants of a single study, by study identifier.
|
|
125
|
+
* @param studyId
|
|
126
|
+
* @param origin
|
|
127
|
+
* @param from
|
|
128
|
+
* @param to
|
|
129
|
+
*/
|
|
130
|
+
public async allByStudy(
|
|
131
|
+
studyId: Identifier,
|
|
132
|
+
origin?: string,
|
|
133
|
+
from?: number,
|
|
134
|
+
to?: number,
|
|
135
|
+
limit?: number,
|
|
136
|
+
transform?: string
|
|
137
|
+
): Promise<ActivityEvent[]> {
|
|
138
|
+
if (studyId === null || studyId === undefined)
|
|
139
|
+
throw new Error("Required parameter studyId was null or undefined when calling activityEventAllByStudy.")
|
|
140
|
+
|
|
141
|
+
let queryParameters = new URLSearchParams()
|
|
142
|
+
if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
|
|
143
|
+
if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
|
|
144
|
+
if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
|
|
145
|
+
if (limit !== undefined && limit !== null) queryParameters.set("limit", <any>limit)
|
|
146
|
+
|
|
147
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
148
|
+
// DEMO
|
|
149
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
150
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
151
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
152
|
+
if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
|
|
153
|
+
|
|
154
|
+
if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
|
|
155
|
+
let participants = Demo.Participant.filter(x => x["#parent"] === studyId)
|
|
156
|
+
let fn = (id: string) =>
|
|
157
|
+
Demo.ActivityEvent.filter(x => x["#parent"] === id && (!!origin ? x["activity"] === origin : true)).map(x =>
|
|
158
|
+
Object.assign(new ActivityEvent(), x)
|
|
159
|
+
)
|
|
160
|
+
let output = participants.reduce(
|
|
161
|
+
(all, participant) => ({ ...all, [participant["id"]]: fn(participant["id"]) }),
|
|
162
|
+
{}
|
|
163
|
+
) as any
|
|
164
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
165
|
+
return Promise.resolve(output)
|
|
166
|
+
} else {
|
|
167
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return (
|
|
171
|
+
await Fetch.get<{ data: any[] }>(
|
|
172
|
+
`/study/${studyId}/activity_event?${queryParameters.toString()}`,
|
|
173
|
+
this.configuration
|
|
174
|
+
)
|
|
175
|
+
).data.map(x => Object.assign(new ActivityEvent(), x))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Create a new ActivityEvent for the given Participant.
|
|
180
|
+
* @param participantId
|
|
181
|
+
* @param activityEvent
|
|
182
|
+
*/
|
|
183
|
+
public async create(participantId: Identifier, activityEvent: ActivityEvent): Promise<Identifier> {
|
|
184
|
+
if (participantId === null || participantId === undefined)
|
|
185
|
+
throw new Error("Required parameter participantId was null or undefined when calling activityEventCreate.")
|
|
186
|
+
if (activityEvent === null || activityEvent === undefined)
|
|
187
|
+
throw new Error("Required parameter activityEvent was null or undefined when calling activityEventCreate.")
|
|
188
|
+
|
|
189
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
190
|
+
// DEMO
|
|
191
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
192
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
193
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
194
|
+
if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
|
|
195
|
+
|
|
196
|
+
if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
|
|
197
|
+
Demo.ActivityEvent.push({
|
|
198
|
+
"#type": "ActivityEvent",
|
|
199
|
+
"#parent": participantId,
|
|
200
|
+
...(activityEvent as any)
|
|
201
|
+
})
|
|
202
|
+
return Promise.resolve({} as any)
|
|
203
|
+
} else {
|
|
204
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return await Fetch.post(`/participant/${participantId}/activity_event`, activityEvent, this.configuration)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Delete a ActivityEvent.
|
|
212
|
+
* @param participantId
|
|
213
|
+
* @param origin
|
|
214
|
+
* @param from
|
|
215
|
+
* @param to
|
|
216
|
+
*/
|
|
217
|
+
public async delete(participantId: Identifier, origin?: string, from?: number, to?: number): Promise<Identifier> {
|
|
218
|
+
if (participantId === null || participantId === undefined)
|
|
219
|
+
throw new Error("Required parameter participantId was null or undefined when calling activityEventDelete.")
|
|
220
|
+
|
|
221
|
+
let queryParameters = new URLSearchParams()
|
|
222
|
+
if (origin !== undefined && origin !== null) queryParameters.set("origin", <any>origin)
|
|
223
|
+
if (from !== undefined && from !== null) queryParameters.set("from", <any>from)
|
|
224
|
+
if (to !== undefined && to !== null) queryParameters.set("to", <any>to)
|
|
225
|
+
|
|
226
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
227
|
+
// DEMO
|
|
228
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
229
|
+
let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
230
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
231
|
+
if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
|
|
232
|
+
|
|
233
|
+
if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
|
|
234
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
235
|
+
} else {
|
|
236
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return await Fetch.delete(
|
|
240
|
+
`/participant/${participantId}/activity_event?${queryParameters.toString()}`,
|
|
241
|
+
this.configuration
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Fetch, Configuration } from "./Fetch"
|
|
2
|
+
import { ActivitySpec } from "../model/ActivitySpec"
|
|
3
|
+
import { Identifier } from "../model/Type"
|
|
4
|
+
import { Demo } from "./Demo"
|
|
5
|
+
import jsonata from "jsonata"
|
|
6
|
+
|
|
7
|
+
export class ActivitySpecService {
|
|
8
|
+
public configuration?: Configuration
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get all ActivitySpecs registered.
|
|
12
|
+
*/
|
|
13
|
+
public async all(transform?: string): Promise<ActivitySpec[]> {
|
|
14
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
15
|
+
// DEMO
|
|
16
|
+
let output = Demo.ActivitySpec.map(x => Object.assign(new ActivitySpec(), x))
|
|
17
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
18
|
+
return Promise.resolve(output)
|
|
19
|
+
}
|
|
20
|
+
return (await Fetch.get<{ data: any[] }>(`/activity_spec`, this.configuration)).data.map(x =>
|
|
21
|
+
Object.assign(new ActivitySpec(), x)
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a new ActivitySpec.
|
|
27
|
+
* @param activitySpec
|
|
28
|
+
*/
|
|
29
|
+
public async create(activitySpec: ActivitySpec): Promise<Identifier> {
|
|
30
|
+
if (activitySpec === null || activitySpec === undefined)
|
|
31
|
+
throw new Error("Required parameter activitySpec was null or undefined when calling activitySpecCreate.")
|
|
32
|
+
|
|
33
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
34
|
+
// DEMO
|
|
35
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
36
|
+
}
|
|
37
|
+
return await Fetch.post(`/activity_spec`, activitySpec, this.configuration)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delete an ActivitySpec.
|
|
42
|
+
* @param activitySpecName
|
|
43
|
+
*/
|
|
44
|
+
public async delete(activitySpecName: Identifier): Promise<Identifier> {
|
|
45
|
+
if (activitySpecName === null || activitySpecName === undefined)
|
|
46
|
+
throw new Error("Required parameter activitySpecName was null or undefined when calling activitySpecDelete.")
|
|
47
|
+
|
|
48
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
49
|
+
// DEMO
|
|
50
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
51
|
+
}
|
|
52
|
+
return await Fetch.delete(`/activity_spec/${activitySpecName}`, this.configuration)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Update an ActivitySpec.
|
|
57
|
+
* @param activitySpecName
|
|
58
|
+
* @param activitySpec
|
|
59
|
+
*/
|
|
60
|
+
public async update(activitySpecName: Identifier, activitySpec: ActivitySpec): Promise<Identifier> {
|
|
61
|
+
if (activitySpecName === null || activitySpecName === undefined)
|
|
62
|
+
throw new Error("Required parameter activitySpecName was null or undefined when calling activitySpecUpdate.")
|
|
63
|
+
if (activitySpec === null || activitySpec === undefined)
|
|
64
|
+
throw new Error("Required parameter activitySpec was null or undefined when calling activitySpecUpdate.")
|
|
65
|
+
|
|
66
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
67
|
+
// DEMO
|
|
68
|
+
return Promise.resolve({ error: "500.demo-restriction" } as any)
|
|
69
|
+
}
|
|
70
|
+
return await Fetch.put(`/activity_spec/${activitySpecName}`, activitySpec, this.configuration)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* View an ActivitySpec.
|
|
75
|
+
* @param activitySpecName
|
|
76
|
+
*/
|
|
77
|
+
public async view(activitySpecName: string, transform?: string): Promise<ActivitySpec> {
|
|
78
|
+
if (activitySpecName === null || activitySpecName === undefined)
|
|
79
|
+
throw new Error("Required parameter activitySpecName was null or undefined when calling activitySpecView.")
|
|
80
|
+
|
|
81
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
82
|
+
// DEMO
|
|
83
|
+
let data = Demo.ActivitySpec.filter(x => x["name"] === activitySpecName).map(x =>
|
|
84
|
+
Object.assign(new ActivitySpec(), x)
|
|
85
|
+
)
|
|
86
|
+
if (data.length > 0) {
|
|
87
|
+
let output = data[0]
|
|
88
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
89
|
+
return Promise.resolve(output)
|
|
90
|
+
} else {
|
|
91
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return (await Fetch.get<{ data: any[] }>(`/activity_spec/${activitySpecName}`, this.configuration)).data.map(x =>
|
|
95
|
+
Object.assign(new ActivitySpec(), x)
|
|
96
|
+
)[0]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { SignJWT } from "jose"
|
|
2
|
+
import { Fetch, Configuration } from "./Fetch"
|
|
3
|
+
import { Identifier } from "../model/Type"
|
|
4
|
+
import { Credential } from "../model/Credential"
|
|
5
|
+
import { Demo } from "./Demo"
|
|
6
|
+
import jsonata from "jsonata"
|
|
7
|
+
|
|
8
|
+
export class CredentialService {
|
|
9
|
+
public configuration?: Configuration
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param typeId
|
|
14
|
+
* @param secretKey
|
|
15
|
+
*/
|
|
16
|
+
public async create(
|
|
17
|
+
typeId: Identifier,
|
|
18
|
+
accessKey: string,
|
|
19
|
+
secretKey: string,
|
|
20
|
+
description?: string
|
|
21
|
+
): Promise<Credential> {
|
|
22
|
+
if (accessKey === null || accessKey === undefined)
|
|
23
|
+
throw new Error("Required parameter accessKey was null or undefined when calling credentialCreate.")
|
|
24
|
+
if (secretKey === null || secretKey === undefined)
|
|
25
|
+
throw new Error("Required parameter secretKey was null or undefined when calling credentialCreate.")
|
|
26
|
+
|
|
27
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
28
|
+
// DEMO
|
|
29
|
+
let auth = (this.configuration.authorization || ":").split(":")
|
|
30
|
+
let credential = Demo.Credential.filter((x) => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
31
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
32
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
33
|
+
|
|
34
|
+
const token = this.configuration.token
|
|
35
|
+
if (!token) return Promise.resolve({ error: "401.missing-credentials" } as any)
|
|
36
|
+
|
|
37
|
+
let decoded
|
|
38
|
+
// try {
|
|
39
|
+
// // decoded = verifyToken(token, this.configuration.jwt_secret);
|
|
40
|
+
// } catch (error) {
|
|
41
|
+
// return Promise.resolve({ error: "403.invalid-token" } as any);
|
|
42
|
+
// }
|
|
43
|
+
// const credential = Demo.Credential.filter(x => x["access_key"] === decoded.accessKey && x["secret_key"] === decoded.secretKey);
|
|
44
|
+
// if (!credential) return Promise.resolve({ error: "403.invalid-credentials" } as any);
|
|
45
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
46
|
+
|
|
47
|
+
let exists =
|
|
48
|
+
Demo.Researcher.filter((x) => x["id"] === typeId).length > 0 ||
|
|
49
|
+
Demo.Study.filter((x) => x["id"] === typeId).length > 0 ||
|
|
50
|
+
Demo.Participant.filter((x) => x["id"] === typeId).length > 0 ||
|
|
51
|
+
Demo.Activity.filter((x) => x["id"] === typeId).length > 0 // ???
|
|
52
|
+
let unique = Demo.Credential.filter((x) => x["access_key"] === accessKey).length === 0
|
|
53
|
+
if (exists && unique) {
|
|
54
|
+
Demo.Credential.push({
|
|
55
|
+
"#type": "Credential",
|
|
56
|
+
"#parent": typeId,
|
|
57
|
+
origin: typeId,
|
|
58
|
+
access_key: accessKey,
|
|
59
|
+
secret_key: secretKey,
|
|
60
|
+
description: description,
|
|
61
|
+
})
|
|
62
|
+
return Promise.resolve({} as any)
|
|
63
|
+
} else {
|
|
64
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return await Fetch.post(
|
|
68
|
+
`/type/${typeId}/credential`,
|
|
69
|
+
{ origin: typeId, access_key: accessKey, secret_key: secretKey, description: description },
|
|
70
|
+
this.configuration
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param typeId
|
|
77
|
+
* @param accessKey
|
|
78
|
+
*/
|
|
79
|
+
public async delete(typeId: Identifier, accessKey: string): Promise<Identifier> {
|
|
80
|
+
if (accessKey === null || accessKey === undefined)
|
|
81
|
+
throw new Error("Required parameter accessKey was null or undefined when calling credentialDelete.")
|
|
82
|
+
|
|
83
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
84
|
+
// DEMO
|
|
85
|
+
// let auth = (this.configuration.authorization || ":").split(":")
|
|
86
|
+
// let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
87
|
+
// if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
88
|
+
// if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
89
|
+
|
|
90
|
+
const token = this.configuration.token
|
|
91
|
+
if (!token) return Promise.resolve({ error: "401.missing-credentials" } as any)
|
|
92
|
+
|
|
93
|
+
let decoded
|
|
94
|
+
// try {
|
|
95
|
+
// // decoded = verifyToken(token, this.configuration.jwt_secret);
|
|
96
|
+
// } catch (error) {
|
|
97
|
+
// return Promise.resolve({ error: "403.invalid-token" } as any);
|
|
98
|
+
// }
|
|
99
|
+
const credential = Demo.Credential.find(
|
|
100
|
+
(x) => x["access_key"] === decoded.accessKey && x["secret_key"] === decoded.secretKey
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
104
|
+
|
|
105
|
+
let idx = Demo.Credential.findIndex((x) => x["#parent"] === typeId && x["access_key"] === accessKey)
|
|
106
|
+
if (idx >= 0) {
|
|
107
|
+
Demo.Credential.splice(idx, 1)
|
|
108
|
+
return Promise.resolve({} as any)
|
|
109
|
+
} else {
|
|
110
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return await Fetch.delete(`/type/${typeId}/credential/${accessKey}`, this.configuration)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param typeId
|
|
119
|
+
*/
|
|
120
|
+
public async list(typeId: Identifier, transform?: string): Promise<Credential[]> {
|
|
121
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
122
|
+
// DEMO
|
|
123
|
+
// let auth = (this.configuration.authorization || ":").split(":")
|
|
124
|
+
// let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
125
|
+
// if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
126
|
+
// if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
127
|
+
|
|
128
|
+
const token = this.configuration.token
|
|
129
|
+
if (!token) return Promise.resolve({ error: "401.missing-credentials" } as any)
|
|
130
|
+
|
|
131
|
+
let decoded
|
|
132
|
+
// try {
|
|
133
|
+
// // decoded = verifyToken(token, this.configuration.jwt_secret);
|
|
134
|
+
// } catch (error) {
|
|
135
|
+
// return Promise.resolve({ error: "403.invalid-token" } as any);
|
|
136
|
+
// }
|
|
137
|
+
const credential = Demo.Credential.find(
|
|
138
|
+
(x) => x["access_key"] === decoded.accessKey && x["secret_key"] === decoded.secretKey
|
|
139
|
+
)
|
|
140
|
+
// if (!credential) return Promise.resolve({ error: "403.invalid-credentials" } as any);
|
|
141
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
142
|
+
|
|
143
|
+
let exists =
|
|
144
|
+
Demo.Researcher.filter((x) => x["id"] === typeId).length > 0 ||
|
|
145
|
+
Demo.Study.filter((x) => x["id"] === typeId).length > 0 ||
|
|
146
|
+
Demo.Participant.filter((x) => x["id"] === typeId).length > 0 ||
|
|
147
|
+
Demo.Activity.filter((x) => x["id"] === typeId).length > 0 // ???
|
|
148
|
+
if (exists) {
|
|
149
|
+
let output = Demo.Credential.filter((x) => x["#parent"] === typeId).map((x) =>
|
|
150
|
+
Object.assign(new Credential(), { ...x, secret_key: "" })
|
|
151
|
+
)
|
|
152
|
+
output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
|
|
153
|
+
return Promise.resolve(output)
|
|
154
|
+
} else {
|
|
155
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return (await Fetch.get<{ data: any[] }>(`/type/${typeId}/credential`, this.configuration)).data.map((x) =>
|
|
159
|
+
Object.assign(new Credential(), x)
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* @param typeId
|
|
166
|
+
* @param accessKey
|
|
167
|
+
* @param secretKey
|
|
168
|
+
*/
|
|
169
|
+
public async update(
|
|
170
|
+
typeId: Identifier,
|
|
171
|
+
accessKey: string,
|
|
172
|
+
secretKey: string,
|
|
173
|
+
description?: string
|
|
174
|
+
): Promise<Identifier> {
|
|
175
|
+
if (accessKey === null || accessKey === undefined)
|
|
176
|
+
throw new Error("Required parameter accessKey was null or undefined when calling credentialUpdate.")
|
|
177
|
+
if (secretKey === null || secretKey === undefined)
|
|
178
|
+
throw new Error("Required parameter secretKey was null or undefined when calling credentialUpdate.")
|
|
179
|
+
|
|
180
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
181
|
+
// DEMO
|
|
182
|
+
// let auth = (this.configuration.authorization || ":").split(":")
|
|
183
|
+
// let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
|
|
184
|
+
// if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
|
|
185
|
+
// if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
186
|
+
|
|
187
|
+
const token = this.configuration.token
|
|
188
|
+
if (!token) return Promise.resolve({ error: "401.missing-credentials" } as any)
|
|
189
|
+
|
|
190
|
+
let decoded
|
|
191
|
+
// try {
|
|
192
|
+
// // decoded = verifyToken(token, this.configuration.jwt_secret);
|
|
193
|
+
// } catch (error) {
|
|
194
|
+
// return Promise.resolve({ error: "403.invalid-token" } as any);
|
|
195
|
+
// }
|
|
196
|
+
const credential = Demo.Credential.find(
|
|
197
|
+
(x) => x["access_key"] === decoded.accessKey && x["secret_key"] === decoded.secretKey
|
|
198
|
+
)
|
|
199
|
+
// if (!credential) return Promise.resolve({ error: "403.invalid-credentials" } as any);
|
|
200
|
+
if (typeId === "me") typeId = credential.length > 0 ? credential[0]["origin"] : typeId
|
|
201
|
+
|
|
202
|
+
let idx = Demo.Credential.findIndex((x) => x["#parent"] === typeId && x["access_key"] === accessKey)
|
|
203
|
+
if (idx >= 0) {
|
|
204
|
+
Demo.Credential[idx] = {
|
|
205
|
+
"#type": "Credential",
|
|
206
|
+
"#parent": typeId,
|
|
207
|
+
origin: typeId,
|
|
208
|
+
access_key: accessKey,
|
|
209
|
+
secret_key: secretKey ?? Demo.Credential[idx]["secret_key"],
|
|
210
|
+
description: description ?? Demo.Credential[idx]["description"],
|
|
211
|
+
}
|
|
212
|
+
return Promise.resolve({} as any)
|
|
213
|
+
} else {
|
|
214
|
+
return Promise.resolve({ error: "404.not-found" } as any)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return await Fetch.put(`/type/${typeId}/credential/${accessKey}`, secretKey, this.configuration)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
*
|
|
222
|
+
* @param accessKey
|
|
223
|
+
* @param secretKey
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
public async login(accessKey: string, secretKey: string): Promise<any> {
|
|
227
|
+
if (accessKey === null || accessKey === undefined)
|
|
228
|
+
throw new Error("Required parameter accessKey was null or undefined when calling login.")
|
|
229
|
+
if (secretKey === null || secretKey === undefined)
|
|
230
|
+
throw new Error("Required parameter secretKey was null or undefined when calling login.")
|
|
231
|
+
|
|
232
|
+
if (this.configuration.base === "https://demo.lamp.digital") {
|
|
233
|
+
let credential = Demo.Credential.filter((x) => x["access_key"] === accessKey && x["secret_key"] === secretKey)
|
|
234
|
+
if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" })
|
|
235
|
+
|
|
236
|
+
let exists =
|
|
237
|
+
Demo.Researcher.filter((x) => x["id"] === accessKey).length > 0 ||
|
|
238
|
+
Demo.Participant.filter((x) => x["id"] === accessKey).length > 0
|
|
239
|
+
|
|
240
|
+
if (!exists) return Promise.resolve({ error: "403.invalid-credentials" })
|
|
241
|
+
if (exists) {
|
|
242
|
+
try {
|
|
243
|
+
// this.configuration.token = jwt.sign({ accessKey, secretKey }, this.configuration.jwt_secret, { expiresIn: '1h' })
|
|
244
|
+
const secretKeyEncoded = new TextEncoder().encode(this.configuration.jwt_secret)
|
|
245
|
+
this.configuration.token = await new SignJWT({ accessKey, secretKey })
|
|
246
|
+
.setProtectedHeader({ alg: "HS256" })
|
|
247
|
+
.setIssuedAt()
|
|
248
|
+
.setExpirationTime("2h")
|
|
249
|
+
.sign(secretKeyEncoded)
|
|
250
|
+
return Promise.resolve({ success: "Login successful", token: this.configuration.token })
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error("Error generating token:", error)
|
|
253
|
+
return Promise.resolve({ error: "500.server-error" })
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return await Fetch.post("/login", { accessKey, secretKey }, this.configuration)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public async renewToken(refreshToken: string, base: string): Promise<any> {
|
|
262
|
+
const configuration: Configuration = { accessToken: refreshToken, base: base }
|
|
263
|
+
return await Fetch.post("/renewToken", { refreshToken }, configuration)
|
|
264
|
+
}
|
|
265
|
+
public async logout(token: string): Promise<any> {
|
|
266
|
+
return await Fetch.post("/logout", { token }, this.configuration)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// [NOTE]: Demo mode carries various restrictions and does not:
|
|
3
|
+
// (1) verify R/W permissions.
|
|
4
|
+
// (2) carry an audit log.
|
|
5
|
+
// (3) support root operations.
|
|
6
|
+
// (4) encrypt any data.
|
|
7
|
+
//
|
|
8
|
+
export let Demo = {
|
|
9
|
+
ActivitySpec: [],
|
|
10
|
+
SensorSpec: [],
|
|
11
|
+
Researcher: [],
|
|
12
|
+
ResearcherSettings: [],
|
|
13
|
+
Study: [],
|
|
14
|
+
Participant: [],
|
|
15
|
+
Activity: [],
|
|
16
|
+
Sensor: [],
|
|
17
|
+
ActivityEvent: [],
|
|
18
|
+
SensorEvent: [],
|
|
19
|
+
Credential: [],
|
|
20
|
+
Tags: []
|
|
21
|
+
}
|