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.
Files changed (130) hide show
  1. package/.github/workflows/publish.yml +34 -0
  2. package/LICENSE.md +29 -0
  3. package/MANUAL.md +26 -0
  4. package/README.md +126 -0
  5. package/cli.js +2 -0
  6. package/dist/index.d.ts +64 -0
  7. package/dist/index.js +311 -0
  8. package/dist/model/Activity.d.ts +81 -0
  9. package/dist/model/Activity.js +30 -0
  10. package/dist/model/ActivityEvent.d.ts +51 -0
  11. package/dist/model/ActivityEvent.js +21 -0
  12. package/dist/model/ActivitySpec.d.ts +38 -0
  13. package/dist/model/ActivitySpec.js +12 -0
  14. package/dist/model/Credential.d.ts +21 -0
  15. package/dist/model/Credential.js +12 -0
  16. package/dist/model/DynamicAttachment.d.ts +34 -0
  17. package/dist/model/DynamicAttachment.js +12 -0
  18. package/dist/model/Participant.d.ts +30 -0
  19. package/dist/model/Participant.js +12 -0
  20. package/dist/model/Researcher.d.ts +27 -0
  21. package/dist/model/Researcher.js +12 -0
  22. package/dist/model/ResearcherSettings.d.ts +57 -0
  23. package/dist/model/ResearcherSettings.js +12 -0
  24. package/dist/model/Sensor.d.ts +22 -0
  25. package/dist/model/Sensor.js +12 -0
  26. package/dist/model/SensorEvent.d.ts +18 -0
  27. package/dist/model/SensorEvent.js +12 -0
  28. package/dist/model/SensorSpec.d.ts +13 -0
  29. package/dist/model/SensorSpec.js +12 -0
  30. package/dist/model/Study.d.ts +24 -0
  31. package/dist/model/Study.js +12 -0
  32. package/dist/model/Type.d.ts +56 -0
  33. package/dist/model/Type.js +30 -0
  34. package/dist/model/index.d.ts +12 -0
  35. package/dist/model/index.js +24 -0
  36. package/dist/service/API.service.d.ts +12 -0
  37. package/dist/service/API.service.js +82 -0
  38. package/dist/service/Activity.service.d.ts +101 -0
  39. package/dist/service/Activity.service.js +756 -0
  40. package/dist/service/ActivityEvent.service.d.ts +46 -0
  41. package/dist/service/ActivityEvent.service.js +303 -0
  42. package/dist/service/ActivitySpec.service.d.ts +31 -0
  43. package/dist/service/ActivitySpec.service.js +173 -0
  44. package/dist/service/Credential.service.d.ts +38 -0
  45. package/dist/service/Credential.service.js +319 -0
  46. package/dist/service/Demo.d.ts +14 -0
  47. package/dist/service/Demo.js +24 -0
  48. package/dist/service/Fetch.d.ts +30 -0
  49. package/dist/service/Fetch.js +245 -0
  50. package/dist/service/Participant.service.d.ts +42 -0
  51. package/dist/service/Participant.service.js +312 -0
  52. package/dist/service/Researcher.service.d.ts +34 -0
  53. package/dist/service/Researcher.service.js +252 -0
  54. package/dist/service/ResearcherSettings.service.d.ts +16 -0
  55. package/dist/service/ResearcherSettings.service.js +114 -0
  56. package/dist/service/Sensor.service.d.ts +47 -0
  57. package/dist/service/Sensor.service.js +372 -0
  58. package/dist/service/SensorEvent.service.d.ts +44 -0
  59. package/dist/service/SensorEvent.service.js +302 -0
  60. package/dist/service/SensorSpec.service.d.ts +31 -0
  61. package/dist/service/SensorSpec.service.js +171 -0
  62. package/dist/service/Study.service.d.ts +42 -0
  63. package/dist/service/Study.service.js +286 -0
  64. package/dist/service/Type.service.d.ts +48 -0
  65. package/dist/service/Type.service.js +352 -0
  66. package/dist/service/index.d.ts +13 -0
  67. package/dist/service/index.js +25 -0
  68. package/docs/APIApi.md +82 -0
  69. package/docs/AccessCitation.md +11 -0
  70. package/docs/Activity.md +13 -0
  71. package/docs/ActivityApi.md +356 -0
  72. package/docs/ActivityEvent.md +13 -0
  73. package/docs/ActivityEventApi.md +251 -0
  74. package/docs/ActivitySpec.md +14 -0
  75. package/docs/ActivitySpecApi.md +222 -0
  76. package/docs/Credential.md +12 -0
  77. package/docs/CredentialApi.md +175 -0
  78. package/docs/Document.md +9 -0
  79. package/docs/DurationInterval.md +11 -0
  80. package/docs/DurationIntervalLegacy.md +10 -0
  81. package/docs/DynamicAttachment.md +14 -0
  82. package/docs/Error.md +8 -0
  83. package/docs/Metadata.md +8 -0
  84. package/docs/Participant.md +14 -0
  85. package/docs/ParticipantApi.md +312 -0
  86. package/docs/Researcher.md +12 -0
  87. package/docs/ResearcherApi.md +223 -0
  88. package/docs/Sensor.md +12 -0
  89. package/docs/SensorApi.md +356 -0
  90. package/docs/SensorEvent.md +11 -0
  91. package/docs/SensorEventApi.md +250 -0
  92. package/docs/SensorSpec.md +10 -0
  93. package/docs/SensorSpecApi.md +222 -0
  94. package/docs/Study.md +11 -0
  95. package/docs/StudyApi.md +268 -0
  96. package/docs/TemporalSlice.md +13 -0
  97. package/docs/TypeApi.md +274 -0
  98. package/package.json +44 -0
  99. package/src/index.ts +256 -0
  100. package/src/model/Activity.ts +93 -0
  101. package/src/model/ActivityEvent.ts +63 -0
  102. package/src/model/ActivitySpec.ts +45 -0
  103. package/src/model/Credential.ts +26 -0
  104. package/src/model/DynamicAttachment.ts +42 -0
  105. package/src/model/Participant.ts +37 -0
  106. package/src/model/Researcher.ts +33 -0
  107. package/src/model/ResearcherSettings.ts +65 -0
  108. package/src/model/Sensor.ts +27 -0
  109. package/src/model/SensorEvent.ts +22 -0
  110. package/src/model/SensorSpec.ts +16 -0
  111. package/src/model/Study.ts +29 -0
  112. package/src/model/Type.ts +68 -0
  113. package/src/model/index.ts +12 -0
  114. package/src/service/API.service.ts +29 -0
  115. package/src/service/Activity.service.ts +625 -0
  116. package/src/service/ActivityEvent.service.ts +244 -0
  117. package/src/service/ActivitySpec.service.ts +98 -0
  118. package/src/service/Credential.service.ts +268 -0
  119. package/src/service/Demo.ts +21 -0
  120. package/src/service/Fetch.ts +187 -0
  121. package/src/service/Participant.service.ts +217 -0
  122. package/src/service/Researcher.service.ts +147 -0
  123. package/src/service/ResearcherSettings.service.ts +62 -0
  124. package/src/service/Sensor.service.ts +256 -0
  125. package/src/service/SensorEvent.service.ts +239 -0
  126. package/src/service/SensorSpec.service.ts +96 -0
  127. package/src/service/Study.service.ts +187 -0
  128. package/src/service/Type.service.ts +297 -0
  129. package/src/service/index.ts +13 -0
  130. package/tsconfig.json +29 -0
@@ -0,0 +1,187 @@
1
+ import { jwtVerify } from "jose"
2
+ import { CredentialService } from "./Credential.service"
3
+ import LAMP from ".."
4
+ /**
5
+ *
6
+ */
7
+ export type Configuration = {
8
+ /**
9
+ *
10
+ */
11
+ base: string
12
+
13
+ /**
14
+ *
15
+ */
16
+ authorization?: string
17
+
18
+ /**
19
+ *
20
+ */
21
+ headers?: { [header: string]: string }
22
+
23
+ token?: string
24
+ accessToken?: string
25
+ refreshToken?: string
26
+
27
+ jwt_secret?: string
28
+ }
29
+
30
+ const userTokenKey = "tokenInfo"
31
+
32
+ //If refresh token expired, then logout from app
33
+ const handleSessionExpiry = async () => {
34
+ localStorage.removeItem(userTokenKey)
35
+ localStorage.setItem("verified", JSON.stringify({ value: false }))
36
+ sessionStorage.setItem("LAMP._auth", JSON.stringify({ id: null, password: null, serverAddress: null }))
37
+ // alert("Your session expired, Please login again.")
38
+ // window.location.href = "/#/?expired=true"
39
+ }
40
+
41
+ //If access Token expired then call api for renewing the tokens
42
+ const handleRenewToken = async (refreshToken: string, base: string) => {
43
+ try {
44
+ const credService = new CredentialService()
45
+ const res = await credService.renewToken(refreshToken, base)
46
+
47
+ const accessToken = res?.data?.access_token
48
+
49
+ if (accessToken) {
50
+ sessionStorage.setItem(
51
+ userTokenKey,
52
+ JSON.stringify({ accessToken: res?.data?.access_token, refreshToken: res?.data?.refresh_token })
53
+ )
54
+ }
55
+ return accessToken
56
+ } catch (error) {
57
+ console.log(error)
58
+ }
59
+ }
60
+
61
+ async function _fetch<ResultType>(
62
+ method: string,
63
+ route: string,
64
+ configuration?: Configuration,
65
+ body?: any
66
+ ): Promise<ResultType> {
67
+ if (!configuration) throw new Error("Cannot make HTTP request due to invalid configuration.")
68
+ let authorization
69
+
70
+ const userTokenFromLocalStore: any = JSON.parse(sessionStorage.getItem("tokenInfo"))
71
+ if (userTokenFromLocalStore?.accessToken) {
72
+ authorization = `Bearer ${
73
+ configuration.accessToken ? configuration.accessToken : userTokenFromLocalStore?.accessToken
74
+ }`
75
+ }
76
+
77
+ try {
78
+ var response = await fetch(`${configuration.base}${route}`, {
79
+ method: method,
80
+ headers: new Headers(
81
+ typeof authorization !== "undefined" && !!authorization
82
+ ? {
83
+ "Content-Type": "application/json",
84
+ Accept: "application/json",
85
+ ...(configuration!.headers || {}),
86
+ Authorization: authorization,
87
+ }
88
+ : ({
89
+ "Content-Type": "application/json",
90
+ Accept: "application/json",
91
+ ...(configuration!.headers || {}),
92
+ } as any)
93
+ ),
94
+ credentials: "include",
95
+ body: body !== undefined ? JSON.stringify(body) : undefined,
96
+ })
97
+ if (!response.ok) {
98
+ console.warn(`HTTP error ${response.status}`)
99
+ }
100
+
101
+ const result = await response.json().catch(() => {
102
+ throw new Error("Invalid JSON response")
103
+ })
104
+
105
+ // Handle invalid token
106
+ if (result?.error === "401.invalid-token" || result?.message === "401.invalid-token") {
107
+ if (!route.includes("renewToken")) {
108
+ try {
109
+ const refreshToken = configuration.refreshToken ?? userTokenFromLocalStore?.refreshToken
110
+ if (!refreshToken) {
111
+ handleSessionExpiry()
112
+ return { data: [], error: "401.invalid-token" } as unknown as ResultType
113
+ }
114
+ const token = await handleRenewToken(refreshToken, configuration.base)
115
+ if (token) {
116
+ configuration.authorization = token
117
+ // retry the same request
118
+ switch (method) {
119
+ case "post":
120
+ return await Fetch.post(route, body, configuration)
121
+ break
122
+ case "get":
123
+ return await Fetch.get(route, configuration)
124
+ break
125
+ case "put":
126
+ return await Fetch.put(route, body, configuration)
127
+ break
128
+ case "delete":
129
+ return await Fetch.delete(route, configuration)
130
+ break
131
+ case "patch":
132
+ return await Fetch.patch(route, body, configuration)
133
+ break
134
+ }
135
+ } else {
136
+ handleSessionExpiry()
137
+ return { data: [], error: "401.invalid-token" } as any
138
+ }
139
+ } catch (tokenError) {
140
+ console.error("Token renewal failed:", tokenError)
141
+ handleSessionExpiry()
142
+ return { data: [], error: "401.invalid-token" } as unknown as ResultType
143
+ }
144
+ } else {
145
+ handleSessionExpiry()
146
+ return { data: [], error: "401.invalid-token" } as unknown as ResultType
147
+ }
148
+ }
149
+ return result
150
+ } catch (error) {
151
+ const message = (error as any)?.message || String(error)
152
+ console.error("Fetch failed:", message)
153
+ return { data: [], error: message || "Unknown error" } as unknown as ResultType
154
+ }
155
+ }
156
+
157
+ export class Fetch {
158
+ public static async get<ResultType>(route: string, configuration?: Configuration): Promise<ResultType> {
159
+ return await _fetch("get", route, configuration)
160
+ }
161
+ public static async post<ResultType>(route: string, body: any, configuration?: Configuration): Promise<ResultType> {
162
+ return await _fetch("post", route, configuration, body)
163
+ }
164
+ public static async put<ResultType>(route: string, body: any, configuration?: Configuration): Promise<ResultType> {
165
+ return await _fetch("put", route, configuration, body)
166
+ }
167
+ public static async patch<ResultType>(route: string, body: any, configuration?: Configuration): Promise<ResultType> {
168
+ return await _fetch("patch", route, configuration, body)
169
+ }
170
+ public static async delete<ResultType>(
171
+ route: string,
172
+ configuration?: Configuration,
173
+ body?: any
174
+ ): Promise<ResultType> {
175
+ return await _fetch("delete", route, configuration, body)
176
+ }
177
+ }
178
+
179
+ // export async function verifyToken(token: string, secretKey: string) {
180
+ // try {
181
+ // const secret_Key = new TextEncoder().encode(this.configuration.jwt_secret);
182
+ // const decoded = jwtVerify(token, secret_Key);
183
+ // return decoded;
184
+ // } catch (error) {
185
+ // throw new Error('Invalid token');
186
+ // }
187
+ // }
@@ -0,0 +1,217 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Identifier } from "../model/Type"
3
+ import { Participant } from "../model/Participant"
4
+ import { Demo } from "./Demo"
5
+ import jsonata from "jsonata"
6
+
7
+ export class ParticipantService {
8
+ public configuration?: Configuration
9
+
10
+ /**
11
+ * Get the set of all participants.
12
+ */
13
+ public async all(transform?: string): Promise<Participant[]> {
14
+ if (this.configuration.base === "https://demo.lamp.digital") {
15
+ // DEMO
16
+ let auth = (this.configuration.authorization || ":").split(":")
17
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
18
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
19
+
20
+ let output = Demo.Participant?.map(x => Object.assign(new Participant(), x))
21
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
22
+ return Promise.resolve(output)
23
+ }
24
+ return (await Fetch.get<{ data: any[] }>(`/participant`, this.configuration)).data?.map(x =>
25
+ Object.assign(new Participant(), x)
26
+ )
27
+ }
28
+
29
+ /**
30
+ * Get the set of all participants under a single researcher.
31
+ * @param researcherId
32
+ */
33
+ public async allByResearcher(researcherId: Identifier, transform?: string): Promise<Participant[]> {
34
+ if (researcherId === null || researcherId === undefined)
35
+ throw new Error("Required parameter researcherId was null or undefined when calling participantAllByResearcher.")
36
+
37
+ if (this.configuration.base === "https://demo.lamp.digital") {
38
+ // DEMO
39
+ let auth = (this.configuration.authorization || ":").split(":")
40
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
41
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
42
+ if (researcherId === "me") researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
43
+
44
+ if (Demo.Researcher.filter(x => x["id"] === researcherId).length > 0) {
45
+ let output = Demo.Participant.filter(x =>
46
+ Demo.Study.filter(y => y["#parent"] === researcherId)
47
+ ?.map(y => y["id"])
48
+ .includes(x["#parent"])
49
+ )?.map(x => Object.assign(new Participant(), 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[] }>(`/researcher/${researcherId}/participant`, this.configuration)
58
+ ).data?.map(x => Object.assign(new Participant(), x))
59
+ }
60
+
61
+ /**
62
+ * Get the set of all participants in a single study.
63
+ * @param studyId
64
+ */
65
+ public async allByStudy(studyId: Identifier, transform?: string): Promise<Participant[]> {
66
+ if (studyId === null || studyId === undefined)
67
+ throw new Error("Required parameter studyId was null or undefined when calling participantAllByStudy.")
68
+
69
+ if (this.configuration.base === "https://demo.lamp.digital") {
70
+ // DEMO
71
+ let auth = (this.configuration.authorization || ":").split(":")
72
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
73
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
74
+ if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
75
+
76
+ if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
77
+ let output = Demo.Participant.filter(x => x["#parent"] === studyId)?.map(x =>
78
+ Object.assign(new Participant(), x)
79
+ )
80
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
81
+ return Promise.resolve(output)
82
+ } else {
83
+ return Promise.resolve({ error: "404.not-found" } as any)
84
+ }
85
+ }
86
+ return (await Fetch.get<{ data: any[] }>(`/study/${studyId}/participant`, this.configuration)).data?.map(x =>
87
+ Object.assign(new Participant(), x)
88
+ )
89
+ }
90
+
91
+ /**
92
+ * Create a new Participant for the given Study.
93
+ * @param studyId
94
+ * @param participant
95
+ */
96
+ public async create(studyId: Identifier, participant: Participant): Promise<Identifier> {
97
+ if (studyId === null || studyId === undefined)
98
+ throw new Error("Required parameter studyId was null or undefined when calling participantCreate.")
99
+ if (participant === null || participant === undefined)
100
+ throw new Error("Required parameter participant was null or undefined when calling participantCreate.")
101
+
102
+ if (this.configuration.base === "https://demo.lamp.digital") {
103
+ // DEMO
104
+ let auth = (this.configuration.authorization || ":").split(":")
105
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
106
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
107
+ if (studyId === "me") studyId = credential.length > 0 ? credential[0]["origin"] : studyId
108
+
109
+ if (Demo.Study.filter(x => x["id"] === studyId).length > 0) {
110
+ let data = {
111
+ "#type": "Participant",
112
+ "#parent": studyId,
113
+ id:
114
+ "U" +
115
+ Math.random()
116
+ .toString()
117
+ .substring(2, 11),
118
+ language: "en",
119
+ theme: "#359FFE",
120
+ emergency_contact: null,
121
+ helpline: null
122
+ }
123
+ Demo.Participant.push(data)
124
+ return Promise.resolve({ data: data["id"] } as any)
125
+ } else {
126
+ return Promise.resolve({ error: "404.not-found" } as any)
127
+ }
128
+ }
129
+ return await Fetch.post(`/study/${studyId}/participant`, participant, this.configuration)
130
+ }
131
+
132
+ /**
133
+ * Delete a participant AND all owned data or event streams.
134
+ * @param participantId
135
+ */
136
+ public async delete(participantId: Identifier): Promise<Identifier> {
137
+ if (participantId === null || participantId === undefined)
138
+ throw new Error("Required parameter participantId was null or undefined when calling participantDelete.")
139
+
140
+ if (this.configuration.base === "https://demo.lamp.digital") {
141
+ // DEMO
142
+ let auth = (this.configuration.authorization || ":").split(":")
143
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
144
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
145
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
146
+
147
+ let idx = Demo.Participant.findIndex(x => x["id"] === participantId)
148
+ if (idx >= 0) {
149
+ Demo.Participant.splice(idx, 1)
150
+ Demo.ActivityEvent = Demo.ActivityEvent.filter(x => x["#parent"] !== participantId)
151
+ Demo.SensorEvent = Demo.SensorEvent.filter(x => x["#parent"] !== participantId)
152
+ Demo.Credential = Demo.Credential.filter(x => x["#parent"] !== participantId)
153
+ Demo.Tags = Demo.Tags.filter(x => x["#parent"] !== participantId && x["target"] !== participantId)
154
+ return Promise.resolve({} as any)
155
+ } else {
156
+ return Promise.resolve({ error: "404.not-found" } as any)
157
+ }
158
+ }
159
+ return await Fetch.delete(`/participant/${participantId}`, this.configuration)
160
+ }
161
+
162
+ /**
163
+ * Update a Participant's settings.
164
+ * @param participantId
165
+ * @param participant
166
+ */
167
+ public async update(participantId: Identifier, participant: Participant): Promise<Identifier> {
168
+ if (participantId === null || participantId === undefined)
169
+ throw new Error("Required parameter participantId was null or undefined when calling participantUpdate.")
170
+ if (participant === null || participant === undefined)
171
+ throw new Error("Required parameter participant was null or undefined when calling participantUpdate.")
172
+
173
+ if (this.configuration.base === "https://demo.lamp.digital") {
174
+ // DEMO
175
+ let auth = (this.configuration.authorization || ":").split(":")
176
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
177
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
178
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
179
+
180
+ if (Demo.Participant.filter(x => x["id"] === participantId).length > 0) {
181
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
182
+ } else {
183
+ return Promise.resolve({ error: "404.not-found" } as any)
184
+ }
185
+ }
186
+ return await Fetch.put(`/participant/${participantId}`, participant, this.configuration)
187
+ }
188
+
189
+ /**
190
+ * Get a single participant, by identifier.
191
+ * @param participantId
192
+ */
193
+ public async view(participantId: Identifier, transform?: string): Promise<Participant> {
194
+ if (participantId === null || participantId === undefined)
195
+ throw new Error("Required parameter participantId was null or undefined when calling participantView.")
196
+
197
+ if (this.configuration.base === "https://demo.lamp.digital") {
198
+ // DEMO
199
+ let auth = (this.configuration.authorization || ":").split(":")
200
+ let credential = Demo.Credential.filter(x => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
201
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
202
+ if (participantId === "me") participantId = credential.length > 0 ? credential[0]["origin"] : participantId
203
+
204
+ let data = Demo.Participant.filter(x => x["id"] === participantId)?.map(x => Object.assign(new Participant(), x))
205
+ if (data.length > 0) {
206
+ let output = data[0]
207
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
208
+ return Promise.resolve(output)
209
+ } else {
210
+ return Promise.resolve({ error: "404.not-found" } as any)
211
+ }
212
+ }
213
+ return (await Fetch.get<{ data: any[] }>(`/participant/${participantId}`, this.configuration)).data?.map(x =>
214
+ Object.assign(new Participant(), x)
215
+ )[0]
216
+ }
217
+ }
@@ -0,0 +1,147 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Identifier } from "../model/Type"
3
+ import { Researcher } from "../model/Researcher"
4
+ import { Demo } from "./Demo"
5
+ import jsonata from "jsonata"
6
+
7
+ export class ResearcherService {
8
+ public configuration?: Configuration
9
+
10
+ /**
11
+ * Get the set of all researchers.
12
+ */
13
+ public async all(transform?: string): Promise<Researcher[]> {
14
+ if (this.configuration.base === "https://demo.lamp.digital") {
15
+ // DEMO
16
+ let auth = (this.configuration.authorization || ":").split(":")
17
+ let credential = Demo.Credential.filter((x) => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
18
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
19
+
20
+ let output = Demo.Researcher?.map((x) => Object.assign(new Researcher(), x))
21
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
22
+ return Promise.resolve(output)
23
+ }
24
+ return (await Fetch.get<{ data: any[] }>(`/researcher`, this.configuration))?.data?.map((x) =>
25
+ Object.assign(new Researcher(), x)
26
+ )
27
+ }
28
+
29
+ /**
30
+ * Create a new Researcher.
31
+ * @param researcher
32
+ */
33
+ public async create(researcher: Researcher): Promise<Identifier> {
34
+ if (researcher === null || researcher === undefined)
35
+ throw new Error("Required parameter researcher was null or undefined when calling researcherCreate.")
36
+
37
+ if (this.configuration.base === "https://demo.lamp.digital") {
38
+ // DEMO
39
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
40
+ }
41
+ return await Fetch.post(`/researcher`, researcher, this.configuration)
42
+ }
43
+
44
+ /**
45
+ * Delete a researcher.
46
+ * @param researcherId
47
+ */
48
+ public async delete(researcherId: Identifier): Promise<Identifier> {
49
+ if (researcherId === null || researcherId === undefined)
50
+ throw new Error("Required parameter researcherId was null or undefined when calling researcherDelete.")
51
+
52
+ if (this.configuration.base === "https://demo.lamp.digital") {
53
+ // DEMO
54
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
55
+ }
56
+ return await Fetch.delete(`/researcher/${researcherId}`, this.configuration)
57
+ }
58
+
59
+ /**
60
+ * Update a Researcher's settings.
61
+ * @param researcherId
62
+ * @param body
63
+ */
64
+ public async update(researcherId: Identifier, researcher: Researcher): Promise<Identifier> {
65
+ if (researcherId === null || researcherId === undefined)
66
+ throw new Error("Required parameter researcherId was null or undefined when calling researcherUpdate.")
67
+ if (researcher === null || researcher === undefined)
68
+ throw new Error("Required parameter researcher was null or undefined when calling researcherUpdate.")
69
+
70
+ if (this.configuration.base === "https://demo.lamp.digital") {
71
+ // DEMO
72
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
73
+ }
74
+ return await Fetch.put(`/researcher/${researcherId}`, researcher, this.configuration)
75
+ }
76
+
77
+ /**
78
+ * Get a single researcher, by identifier.
79
+ * @param researcherId
80
+ */
81
+ public async view(researcherId: Identifier, transform?: string): Promise<Researcher> {
82
+ if (researcherId === null || researcherId === undefined)
83
+ throw new Error("Required parameter researcherId was null or undefined when calling researcherView.")
84
+
85
+ if (this.configuration.base === "https://demo.lamp.digital") {
86
+ // DEMO
87
+ let auth = (this.configuration.authorization || ":").split(":")
88
+ let credential = Demo.Credential.filter((x) => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
89
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
90
+ if (researcherId === "me") researcherId = credential.length > 0 ? credential[0]["origin"] : researcherId
91
+
92
+ let data = Demo.Researcher.filter((x) => x["id"] === researcherId)?.map((x) => Object.assign(new Researcher(), x))
93
+
94
+ if (data.length > 0) {
95
+ let output = data[0]
96
+ output = typeof transform === "string" ? jsonata(transform).evaluate(output) : output
97
+ return Promise.resolve(output)
98
+ } else {
99
+ return Promise.resolve({ error: "404.not-found" } as any)
100
+ }
101
+ }
102
+ return (await Fetch.get<{ data: any[] }>(`/researcher/${researcherId}`, this.configuration))?.data?.map((x) =>
103
+ Object.assign(new Researcher(), x)
104
+ )[0]
105
+ }
106
+
107
+ public async usersList(id: string, filters: any): Promise<any> {
108
+ if (this.configuration.base === "https://demo.lamp.digital") {
109
+ // DEMO
110
+ let auth = (this.configuration.authorization || ":").split(":")
111
+ let credential = Demo.Credential.filter((x) => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
112
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
113
+
114
+ let output = Demo.Researcher?.map((x) => Object.assign(new Researcher(), x))
115
+ return Promise.resolve(output)
116
+ }
117
+ const result = await Fetch.post(`/researcher/${id}/users`, filters, this.configuration) as any
118
+ return result?.data
119
+ }
120
+
121
+ public async activitiesList(id: string, filters: any): Promise<any> {
122
+ if (this.configuration.base === "https://demo.lamp.digital") {
123
+ // DEMO
124
+ let auth = (this.configuration.authorization || ":").split(":")
125
+ let credential = Demo.Credential.filter((x) => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
126
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
127
+
128
+ let output = Demo.Researcher?.map((x) => Object.assign(new Researcher(), x))
129
+ return Promise.resolve(output)
130
+ }
131
+ const result = await Fetch.post(`/researcher/activities/${id}`, filters, this.configuration) as any
132
+ return result?.data
133
+ }
134
+ public async sensorsList(id: string, filters: any): Promise<any> {
135
+ if (this.configuration.base === "https://demo.lamp.digital") {
136
+ // DEMO
137
+ let auth = (this.configuration.authorization || ":").split(":")
138
+ let credential = Demo.Credential.filter((x) => x["access_key"] === auth[0] && x["secret_key"] === auth[1])
139
+ if (credential.length === 0) return Promise.resolve({ error: "403.invalid-credentials" } as any)
140
+
141
+ let output = Demo.Researcher?.map((x) => Object.assign(new Researcher(), x))
142
+ return Promise.resolve(output)
143
+ }
144
+ const result = await Fetch.post(`/researcher/sensors/${id}`, filters, this.configuration) as any
145
+ return result?.data
146
+ }
147
+ }
@@ -0,0 +1,62 @@
1
+ import { Fetch, Configuration } from "./Fetch"
2
+ import { Identifier } from "../model/Type"
3
+ import { ResearcherBanner, ResearcherSettings } from "../model/ResearcherSettings"
4
+
5
+ export class ResearcherSettingsService {
6
+ public configuration?: Configuration
7
+
8
+ /**
9
+ * Create Researcher Settings.
10
+ * @param researcherId
11
+ */
12
+ public async createResearcherSettings(
13
+ researcherId: Identifier,
14
+ researcherData: any,
15
+ choice?: any
16
+ ): Promise<Identifier> {
17
+ if (researcherId === null || researcherId === undefined)
18
+ throw new Error("Required parameter researcherId was null or undefined when calling researcherSettingsCreate.")
19
+
20
+ if (this.configuration.base === "https://demo.lamp.digital") {
21
+ // DEMO
22
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
23
+ }
24
+ const res: any = await Fetch.post(
25
+ `/researcherSettings/${researcherId}?choice=${choice}`,
26
+ researcherData,
27
+ this.configuration
28
+ )
29
+ return res
30
+ }
31
+
32
+ /**
33
+ * Get Researcher Settings.
34
+ * @param researcherId
35
+ */
36
+ public async getResearcherSettings(type: string, id: Identifier): Promise<any> {
37
+ if (id === null || id === undefined)
38
+ throw new Error("Required parameter id was null or undefined when calling researcherSettingsGet.")
39
+
40
+ if (this.configuration.base === "https://demo.lamp.digital") {
41
+ // DEMO
42
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
43
+ }
44
+ const result = (await Fetch.get(`/researcherSettings/${type}/${id}`, this.configuration)) as ResearcherBanner
45
+ return result.data
46
+ }
47
+
48
+ public async getResearcherSettingsforParticipant(participantId: Identifier): Promise<any> {
49
+ if (participantId === null || participantId === undefined)
50
+ throw new Error("Required parameter researcherId was null or undefined when calling researcherSettingsGet.")
51
+
52
+ if (this.configuration.base === "https://demo.lamp.digital") {
53
+ // DEMO
54
+ return Promise.resolve({ error: "500.demo-restriction" } as any)
55
+ }
56
+ const result = (await Fetch.get(
57
+ `/participant/researcherSettings/${participantId}`,
58
+ this.configuration
59
+ )) as ResearcherBanner
60
+ return result.data
61
+ }
62
+ }