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,274 @@
1
+ # LAMP.Type
2
+
3
+ Method | HTTP request | Description
4
+ ------------- | ------------- | -------------
5
+ [**getAttachment**](TypeApi.md#getAttachment) | **GET** /type/{type_id}/attachment/{attachment_key} |
6
+ [**getDynamicAttachment**](TypeApi.md#getDynamicAttachment) | **GET** /type/{type_id}/attachment/dynamic/{attachment_key} |
7
+ [**listAttachments**](TypeApi.md#listAttachments) | **GET** /type/{type_id}/attachment |
8
+ [**parent**](TypeApi.md#parent) | **GET** /type/{type_id}/parent | Find the owner(s) of the resource.
9
+ [**setAttachment**](TypeApi.md#setAttachment) | **PUT** /type/{type_id}/attachment/{attachment_key}/{target} |
10
+ [**setDynamicAttachment**](TypeApi.md#setDynamicAttachment) | **PUT** /type/{type_id}/attachment/dynamic/{attachment_key}/{target} |
11
+
12
+
13
+ # **getAttachment**
14
+ > object getAttachment(type_id, attachment_key)
15
+
16
+
17
+
18
+ ### Example
19
+ ```javascript
20
+ import LAMP from 'lamp-core'
21
+
22
+ let type_id = 'type_id_example' // string
23
+ let attachment_key = 'attachment_key_example' // string
24
+
25
+ const result = LAMP.Type.getAttachment(type_id, attachment_key)
26
+ console.dir(result)
27
+ ```
28
+
29
+ ### Parameters
30
+
31
+ Name | Type | Description | Notes
32
+ ------------- | ------------- | ------------- | -------------
33
+ **type_id** | **string**| |
34
+ **attachment_key** | **string**| |
35
+
36
+ ### Return type
37
+
38
+ **object**
39
+
40
+ ### HTTP request headers
41
+
42
+ - **Content-Type**: `application/json`
43
+ - **Accept**: `application/json`
44
+
45
+ ### HTTP response details
46
+ | Status code | Description | Response headers |
47
+ |-------------|-------------|------------------|
48
+ | **200** | 200 Success | - |
49
+ | **400** | 400 Bad Request | - |
50
+ | **403** | 403 Authorization Failed | - |
51
+ | **404** | 404 Not Found | - |
52
+ | **0** | 500 Internal Error | - |
53
+
54
+ # **getDynamicAttachment**
55
+ > object getDynamicAttachment(type_id, attachment_key, invoke_always, include_logs, ignore_output)
56
+
57
+
58
+
59
+ ### Example
60
+ ```javascript
61
+ import LAMP from 'lamp-core'
62
+
63
+ let type_id = 'type_id_example' // string
64
+ let attachment_key = 'attachment_key_example' // string
65
+ let invoke_always = false // boolean
66
+ let include_logs = false // boolean
67
+ let ignore_output = false // boolean
68
+
69
+ const result = LAMP.Type.getDynamicAttachment(type_id, attachment_key, invoke_always, include_logs, ignore_output)
70
+ console.dir(result)
71
+ ```
72
+
73
+ ### Parameters
74
+
75
+ Name | Type | Description | Notes
76
+ ------------- | ------------- | ------------- | -------------
77
+ **type_id** | **string**| |
78
+ **attachment_key** | **string**| |
79
+ **invoke_always** | **boolean**| |
80
+ **include_logs** | **boolean**| |
81
+ **ignore_output** | **boolean**| |
82
+
83
+ ### Return type
84
+
85
+ **object**
86
+
87
+ ### HTTP request headers
88
+
89
+ - **Content-Type**: `application/json`
90
+ - **Accept**: `application/json`
91
+
92
+ ### HTTP response details
93
+ | Status code | Description | Response headers |
94
+ |-------------|-------------|------------------|
95
+ | **200** | 200 Success | - |
96
+ | **400** | 400 Bad Request | - |
97
+ | **403** | 403 Authorization Failed | - |
98
+ | **404** | 404 Not Found | - |
99
+ | **0** | 500 Internal Error | - |
100
+
101
+ # **listAttachments**
102
+ > object listAttachments(type_id)
103
+
104
+
105
+
106
+ ### Example
107
+ ```javascript
108
+ import LAMP from 'lamp-core'
109
+
110
+ let type_id = 'type_id_example' // string
111
+
112
+ const result = LAMP.Type.listAttachments(type_id)
113
+ console.dir(result)
114
+ ```
115
+
116
+ ### Parameters
117
+
118
+ Name | Type | Description | Notes
119
+ ------------- | ------------- | ------------- | -------------
120
+ **type_id** | **string**| |
121
+
122
+ ### Return type
123
+
124
+ **object**
125
+
126
+ ### HTTP request headers
127
+
128
+ - **Content-Type**: `application/json`
129
+ - **Accept**: `application/json`
130
+
131
+ ### HTTP response details
132
+ | Status code | Description | Response headers |
133
+ |-------------|-------------|------------------|
134
+ | **200** | 200 Success | - |
135
+ | **400** | 400 Bad Request | - |
136
+ | **403** | 403 Authorization Failed | - |
137
+ | **404** | 404 Not Found | - |
138
+ | **0** | 500 Internal Error | - |
139
+
140
+ # **parent**
141
+ > character parent(type_id)
142
+
143
+ Find the owner(s) of the resource.
144
+
145
+ Get the parent type identifier of the data structure referenced by the identifier.
146
+
147
+ ### Example
148
+ ```javascript
149
+ import LAMP from 'lamp-core'
150
+
151
+ let type_id = 'type_id_example' // string
152
+
153
+ // Find the owner(s) of the resource.
154
+ const result = LAMP.Type.parent(type_id)
155
+ console.dir(result)
156
+ ```
157
+
158
+ ### Parameters
159
+
160
+ Name | Type | Description | Notes
161
+ ------------- | ------------- | ------------- | -------------
162
+ **type_id** | **string**| |
163
+ **transform** | **string**| | [optional]
164
+
165
+ ### Return type
166
+
167
+ **string**
168
+
169
+ ### HTTP request headers
170
+
171
+ - **Content-Type**: `application/json`
172
+ - **Accept**: `application/json`
173
+
174
+ ### HTTP response details
175
+ | Status code | Description | Response headers |
176
+ |-------------|-------------|------------------|
177
+ | **200** | 200 Success | - |
178
+ | **400** | 400 Bad Request | - |
179
+ | **403** | 403 Authorization Failed | - |
180
+ | **404** | 404 Not Found | - |
181
+ | **0** | 500 Internal Error | - |
182
+
183
+ # **setAttachment**
184
+ > object setAttachment(type_id, target, attachment_key, body)
185
+
186
+
187
+
188
+ ### Example
189
+ ```javascript
190
+ import LAMP from 'lamp-core'
191
+
192
+ let type_id = 'type_id_example' // string
193
+ let target = 'target_example' // string
194
+ let attachment_key = 'attachment_key_example' // string
195
+ let body = null // object
196
+
197
+ const result = LAMP.Type.setAttachment(type_id, target, attachment_key, body)
198
+ console.dir(result)
199
+ ```
200
+
201
+ ### Parameters
202
+
203
+ Name | Type | Description | Notes
204
+ ------------- | ------------- | ------------- | -------------
205
+ **type_id** | **string**| |
206
+ **target** | **string**| |
207
+ **attachment_key** | **string**| |
208
+ **body** | **object**| |
209
+
210
+ ### Return type
211
+
212
+ **object**
213
+
214
+ ### HTTP request headers
215
+
216
+ - **Content-Type**: `application/json`
217
+ - **Accept**: `application/json`
218
+
219
+ ### HTTP response details
220
+ | Status code | Description | Response headers |
221
+ |-------------|-------------|------------------|
222
+ | **200** | 200 Success | - |
223
+ | **400** | 400 Bad Request | - |
224
+ | **403** | 403 Authorization Failed | - |
225
+ | **404** | 404 Not Found | - |
226
+ | **0** | 500 Internal Error | - |
227
+
228
+ # **setDynamicAttachment**
229
+ > object setDynamicAttachment(type_id, target, attachment_key, invoke_once, dynamic.attachment)
230
+
231
+
232
+
233
+ ### Example
234
+ ```javascript
235
+ import LAMP from 'lamp-core'
236
+
237
+ let type_id = 'type_id_example' // string
238
+ let target = 'target_example' // string
239
+ let attachment_key = 'attachment_key_example' // string
240
+ let invoke_once = 'invoke_once_example' // string
241
+ let dynamic.attachment = DynamicAttachment.new("key_example", "from_example", "to_example", list(123), "language_example", "contents_example", list(123)) // DynamicAttachment
242
+
243
+ const result = LAMP.Type.setDynamicAttachment(type_id, target, attachment_key, invoke_once, dynamic.attachment)
244
+ console.dir(result)
245
+ ```
246
+
247
+ ### Parameters
248
+
249
+ Name | Type | Description | Notes
250
+ ------------- | ------------- | ------------- | -------------
251
+ **type_id** | **string**| |
252
+ **target** | **string**| |
253
+ **attachment_key** | **string**| |
254
+ **invoke_once** | **string**| |
255
+ **dynamic.attachment** | [**DynamicAttachment**](DynamicAttachment.md)| |
256
+
257
+ ### Return type
258
+
259
+ **object**
260
+
261
+ ### HTTP request headers
262
+
263
+ - **Content-Type**: `application/json`
264
+ - **Accept**: `application/json`
265
+
266
+ ### HTTP response details
267
+ | Status code | Description | Response headers |
268
+ |-------------|-------------|------------------|
269
+ | **200** | 200 Success | - |
270
+ | **400** | 400 Bad Request | - |
271
+ | **403** | 403 Authorization Failed | - |
272
+ | **404** | 404 Not Found | - |
273
+ | **0** | 500 Internal Error | - |
274
+
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "lamp-core-lst",
3
+ "version": "2025.11.1-3.basic",
4
+ "author": "BIDMC Division of Digital Psychiatry <team@digitalpsych.org>",
5
+ "description": "The JavaScript and TypeScript API client for the LAMP Platform.",
6
+ "homepage": "https://docs.lamp.digital/",
7
+ "license": "BSD-3-Clause",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/BIDMCDigitalPsychiatry/LAMP-js.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/BIDMCDigitalPsychiatry/LAMP-js/issues"
14
+ },
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "bin": {
18
+ "lamp": "cli.js"
19
+ },
20
+ "dependencies": {
21
+ "isomorphic-fetch": "^3.0.0",
22
+ "jose": "^5.8.0",
23
+ "jsonata": "^1.8.4",
24
+ "url-search-params-polyfill": "^7.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^13.11.1",
28
+ "source-map-support": "^0.5.16",
29
+ "typescript": "^3.7.0"
30
+ },
31
+ "scripts": {
32
+ "start": "tsc-watch --onSuccess \"node -r source-map-support/register ./dist/index.js\"",
33
+ "build": "tsc",
34
+ "prepublishOnly": "tsc",
35
+ "test": "echo \"No tests to run...\" && exit 0"
36
+ },
37
+ "prettier": {
38
+ "semi": false,
39
+ "printWidth": 120
40
+ },
41
+ "directories": {
42
+ "doc": "docs"
43
+ }
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,256 @@
1
+ import "isomorphic-fetch"
2
+ import { Researcher, Participant, Identifier } from "./model/index"
3
+ import {
4
+ APIService,
5
+ ActivityService,
6
+ ActivityEventService,
7
+ ActivitySpecService,
8
+ CredentialService,
9
+ ParticipantService,
10
+ ResearcherService,
11
+ SensorService,
12
+ SensorEventService,
13
+ SensorSpecService,
14
+ StudyService,
15
+ TypeService,
16
+ ResearcherSettingsService,
17
+ } from "./service/index"
18
+ import { Configuration } from "./service/Fetch"
19
+ import { Demo } from "./service/Demo"
20
+
21
+ export * from "./service/index"
22
+ export * from "./model/index"
23
+
24
+ /**
25
+ *
26
+ */
27
+ interface IAuth {
28
+ id: string | null
29
+ password: string | null
30
+ serverAddress: string | undefined
31
+ token?: string | undefined
32
+ }
33
+
34
+ //
35
+ const _bus: HTMLElement | undefined = (global as any).document?.createElement("_lamp_fake")
36
+
37
+ /**
38
+ * The root type in LAMP. You must use `LAMP.connect(...)` to begin using any LAMP classes.
39
+ */
40
+ export default class LAMP {
41
+ public static API = new APIService()
42
+ public static Type = new TypeService()
43
+ public static Credential = new CredentialService()
44
+ public static Researcher = new ResearcherService()
45
+ public static Participant = new ParticipantService()
46
+ public static Study = new StudyService()
47
+ public static Activity = new ActivityService()
48
+ public static ActivityEvent = new ActivityEventService()
49
+ public static ActivitySpec = new ActivitySpecService()
50
+ public static Sensor = new SensorService()
51
+ public static SensorEvent = new SensorEventService()
52
+ public static SensorSpec = new SensorSpecService()
53
+ public static ResearcherSettings = new ResearcherSettingsService()
54
+ private static get configuration(): Configuration | undefined {
55
+ return LAMP.API.configuration
56
+ }
57
+ private static set configuration(configuration: Configuration | undefined) {
58
+ LAMP.API.configuration = configuration
59
+ LAMP.Activity.configuration = configuration
60
+ LAMP.ActivityEvent.configuration = configuration
61
+ LAMP.ActivitySpec.configuration = configuration
62
+ LAMP.Credential.configuration = configuration
63
+ LAMP.Participant.configuration = configuration
64
+ LAMP.Researcher.configuration = configuration
65
+ LAMP.Sensor.configuration = configuration
66
+ LAMP.SensorEvent.configuration = configuration
67
+ LAMP.SensorSpec.configuration = configuration
68
+ LAMP.Study.configuration = configuration
69
+ LAMP.Type.configuration = configuration
70
+ LAMP.ResearcherSettings.configuration = configuration
71
+ }
72
+ private static protocol = "https://"
73
+
74
+ public static enableDevMode() {
75
+ // Make all future server requests over http
76
+ // Only use this for local development
77
+ LAMP.protocol = "http://"
78
+ }
79
+
80
+ public static addEventListener(event: string, callback: (any) => void) {
81
+ _bus?.addEventListener(event, callback)
82
+ }
83
+ public static removeEventListener(event: string, callback: (any) => void) {
84
+ _bus?.removeEventListener(event, callback)
85
+ }
86
+ public static dispatchEvent(event: string, detail: any = null) {
87
+ _bus?.dispatchEvent(new CustomEvent(event, { detail }))
88
+ }
89
+
90
+ //
91
+ // [Demo API]
92
+ //
93
+
94
+ public static initializeDemoDB(db: { [key: string]: any }) {
95
+ db = JSON.parse(JSON.stringify(db)) // make a deep copy first!
96
+ Demo.ActivitySpec = db.ActivitySpec ?? []
97
+ Demo.SensorSpec = db.SensorSpec ?? []
98
+ Demo.Researcher = db.Researcher ?? []
99
+ Demo.Study = db.Study ?? []
100
+ Demo.Participant = db.Participant ?? []
101
+ Demo.Activity = db.Activity ?? []
102
+ Demo.Sensor = db.Sensor ?? []
103
+ Demo.ActivityEvent = db.ActivityEvent ?? []
104
+ Demo.SensorEvent = db.SensorEvent ?? []
105
+ Demo.Credential = db.Credential ?? []
106
+ Demo.Tags = db.Tags ?? []
107
+ }
108
+
109
+ //
110
+ // [Credential/Identity Management]
111
+ //
112
+
113
+ // Shorthand for console/data analysis usage.
114
+ public static async connect(
115
+ identity: {
116
+ accessKey: string | null
117
+ secretKey: string | null
118
+ serverAddress: string | undefined
119
+ } = {
120
+ accessKey: null,
121
+ secretKey: null,
122
+ serverAddress: undefined,
123
+ }
124
+ ) {
125
+ // Propogate the authorization.
126
+ // await LAMP.Credential.login(identity.accessKey!, identity.secretKey!);
127
+ LAMP.Auth._auth = {
128
+ id: identity.accessKey,
129
+ password: identity.secretKey,
130
+ serverAddress: identity.serverAddress,
131
+ }
132
+
133
+ LAMP.configuration = !!LAMP.Auth._auth.id ? {
134
+ base: !!identity.serverAddress ? `https://${identity.serverAddress}` : "https://api.lamp.digital",
135
+ authorization: `${LAMP.Auth._auth.id}:${LAMP.Auth._auth.password}`
136
+ } : {
137
+ base: !!identity.serverAddress ? `https://${identity.serverAddress}` : "https://api.lamp.digital",
138
+ }
139
+ }
140
+
141
+ public static Auth = class {
142
+ public static _auth: IAuth = { id: null, password: null, serverAddress: null }
143
+ public static _me: Researcher[] | Researcher | Participant | null | undefined
144
+ public static _type: "admin" | "researcher" | "participant" | null = null
145
+
146
+ /**
147
+ * Authenticate/authorize as a user of a given `type`.
148
+ * If all values are null (especially `type`), the authorization is cleared.
149
+ */
150
+ public static async set_identity(
151
+ identity: {
152
+ id: string | null
153
+ password: string | null
154
+ serverAddress: string | null
155
+ } = {
156
+ id: null,
157
+ password: null,
158
+ serverAddress: null,
159
+ }
160
+ ) {
161
+ LAMP.configuration = {
162
+ base: !!identity.serverAddress ? `${LAMP.protocol}${identity.serverAddress}` : `${LAMP.protocol}api.lamp.digital`,
163
+ }
164
+
165
+ // Ensure there's actually a change to process.
166
+ // let l: IAuth = LAMP.Auth._auth || { id: null, password: null, serverAddress: null }
167
+ // if (l.id === identity.id && l.password === identity.password && l.serverAddress === identity.serverAddress) return
168
+
169
+ // Propogate the authorization.
170
+ LAMP.Auth._auth = {
171
+ id: identity.id,
172
+ password: identity.password,
173
+ serverAddress: identity.serverAddress,
174
+ }
175
+
176
+ LAMP.configuration = !!LAMP.Auth._auth.id ? {
177
+ ...(LAMP.configuration || { base: undefined, headers: undefined }),
178
+ authorization: `${LAMP.Auth._auth.id}:${LAMP.Auth._auth.password}`,
179
+ } : {
180
+ ...(LAMP.configuration || { base: undefined, headers: undefined }),
181
+ }
182
+
183
+ //await LAMP.Credential.login( identity.id!, identity.password! );
184
+ try {
185
+ // If we aren't clearing the credential, get the "self" identity.
186
+ if (!!identity.id && !!identity.password) {
187
+ // Get our 'me' context so we know what object type we are.
188
+ let typeData
189
+ try {
190
+ typeData = await LAMP.Type.parent("me")
191
+ } catch (e) {}
192
+ LAMP.Auth._type =
193
+ typeData.data === "admin"
194
+ ? "admin"
195
+ : Object.entries(typeData.data).length === 0
196
+ ? "researcher"
197
+ : !!typeData.data
198
+ ? "participant"
199
+ : null
200
+
201
+ // Get our 'me' object now that we figured out our type.
202
+ LAMP.Auth._me = await (LAMP.Auth._type === "admin"
203
+ ? { id: identity.id }
204
+ : LAMP.Auth._type === "researcher"
205
+ ? LAMP.Researcher.view("me")
206
+ : LAMP.Participant.view("me"))
207
+
208
+ LAMP.dispatchEvent("LOGIN", {
209
+ authorizationToken: LAMP.configuration.authorization,
210
+ // authorizationToken: LAMP.configuration.token,
211
+ identityObject: LAMP.Auth._me,
212
+ serverAddress: LAMP.configuration.base,
213
+ accessToken: LAMP.configuration.accessToken,
214
+ refreshToken: LAMP.configuration.refreshToken,
215
+ })
216
+ } else {
217
+ LAMP.dispatchEvent("LOGOUT", {
218
+ deleteCache: true, // FIXME!
219
+ })
220
+ }
221
+ } catch (err) {
222
+ console.log(`#####LAMP err`, err)
223
+ // We failed: clear and propogate the authorization.
224
+ LAMP.Auth._auth = { id: null, password: null, serverAddress: null }
225
+ // if (!!LAMP.configuration) LAMP.configuration.token = undefined
226
+ // if (!!LAMP.configuration) LAMP.configuration.authorization = undefined
227
+
228
+ // Delete the "self" identity and throw the error we received.
229
+ LAMP.Auth._me = null
230
+ LAMP.Auth._type = null
231
+ throw new Error("invalid id or password")
232
+ } finally {
233
+ // Save the authorization in sessionStorage for later.
234
+ ;(global as any).sessionStorage?.setItem("LAMP._auth", JSON.stringify(LAMP.Auth._auth))
235
+ }
236
+ }
237
+
238
+ public static async refresh_identity() {
239
+ let _saved = JSON.parse((global as any).sessionStorage?.getItem("LAMP._auth") ?? "null") || LAMP.Auth._auth
240
+ await LAMP.Auth.set_identity({
241
+ id: _saved.id,
242
+ password: _saved.password,
243
+ serverAddress: _saved.serverAddress,
244
+ })
245
+ }
246
+ }
247
+ }
248
+
249
+ export const main = () => {
250
+ if (process === undefined) {
251
+ console.error("This function cannot be invoked from within the library.")
252
+ return
253
+ }
254
+ console.log("This command-line tool is currently disabled.")
255
+ process?.exit(1)
256
+ }
@@ -0,0 +1,93 @@
1
+ import { Identifier, Timestamp } from "./Type"
2
+
3
+ /**
4
+ *
5
+ */
6
+ export class DurationInterval {
7
+ /**
8
+ *
9
+ */
10
+ start?: Timestamp
11
+
12
+ /**
13
+ *
14
+ */
15
+ interval?: Array<any>
16
+
17
+ /**
18
+ *
19
+ */
20
+ repeatCount?: number
21
+
22
+ /**
23
+ *
24
+ */
25
+ end?: Timestamp
26
+ }
27
+
28
+ /**
29
+ *
30
+ */
31
+ export class DurationIntervalLegacy {
32
+ /**
33
+ *
34
+ */
35
+ repeatType?: string
36
+
37
+ /**
38
+ *
39
+ */
40
+ date?: Timestamp
41
+
42
+ /**
43
+ *
44
+ */
45
+ customTimes?: Array<any>
46
+ }
47
+
48
+ /**
49
+ * tab setting for Activity
50
+ */
51
+ type Tab = "learn" | "assess" | "manage" | "prevent"
52
+ /**
53
+ * An activity that may be performed by a participant in a study.
54
+ */
55
+ export class Activity {
56
+ /**
57
+ *
58
+ */
59
+ id?: Identifier
60
+ /**
61
+ * The study id of the activity.
62
+ */
63
+ studyId?: Identifier
64
+ /**
65
+ *
66
+ */
67
+ spec?: Identifier
68
+
69
+ /**
70
+ * The name of the activity.
71
+ */
72
+ name?: string
73
+
74
+ /**
75
+ *
76
+ */
77
+ schedule?: DurationIntervalLegacy
78
+
79
+ /**
80
+ * The configuration settings for the activity.
81
+ */
82
+ settings?: any
83
+
84
+ /**
85
+ * The tab settings for the activity.
86
+ */
87
+ category?: Tab[] | null
88
+
89
+ /**
90
+ * The type of streak for the activity.
91
+ */
92
+ streakType?: string
93
+ }