@larc-iu/plaid-client 0.1.0-alpha.8 → 0.2.0-alpha.0

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/index.d.ts CHANGED
@@ -4,18 +4,60 @@ interface Page<T = any> {
4
4
  nextCursor: string | null;
5
5
  }
6
6
 
7
+ /** One choice for an `enum` / `multiselect` service parameter. */
8
+ interface ServiceParamOption {
9
+ value: string;
10
+ label: string;
11
+ }
12
+
13
+ /** A single user-controllable argument a service advertises. */
14
+ interface ServiceParam {
15
+ /** Key the value is sent under in the request payload. */
16
+ key: string;
17
+ label: string;
18
+ type: 'string' | 'number' | 'boolean' | 'enum' | 'multiselect';
19
+ description?: string;
20
+ default?: any;
21
+ required?: boolean;
22
+ /** Required for `enum` / `multiselect`. */
23
+ options?: ServiceParamOption[];
24
+ /** `number` only. */
25
+ min?: number;
26
+ max?: number;
27
+ step?: number;
28
+ /** `string` only. */
29
+ placeholder?: string;
30
+ multiline?: boolean;
31
+ }
32
+
33
+ /** A service's standardized self-description (lives in `extras`). */
34
+ interface ServiceExtras {
35
+ schemaVersion?: number;
36
+ /** Tasks this service serves; from the TASKS vocabulary. */
37
+ tasks?: string[];
38
+ /** Rich human description (markdown), beyond the short `description`. */
39
+ summary?: string;
40
+ /** Ordered parameter schema, rendered into a form by the UI. */
41
+ parameters?: ServiceParam[];
42
+ [key: string]: any;
43
+ }
44
+
7
45
  interface ServiceInfo {
8
46
  serviceId: string;
9
47
  serviceName: string;
10
48
  description: string;
11
- extras?: any;
49
+ extras?: ServiceExtras;
12
50
  }
13
51
 
14
52
  interface DiscoveredService {
15
53
  serviceId: string;
16
54
  serviceName: string;
17
55
  description: string;
18
- extras: any;
56
+ extras: ServiceExtras;
57
+ /** true while the service holds an open request channel; false for previously-seen offline services. */
58
+ online: boolean;
59
+ /** ISO-8601 stamp of when the service was last seen alive, or null/undefined if never persisted. */
60
+ lastSeenAt?: string | null;
19
61
  }
20
62
 
21
63
  interface ServiceRegistration {
@@ -37,217 +79,251 @@ interface SSEConnection {
37
79
  }
38
80
 
39
81
  interface VocabLinksBundle {
40
- create(vocabItem: string, tokens: any[], metadata?: any): Promise<any>;
41
- setMetadata(id: string, body: any): Promise<any>;
42
- deleteMetadata(id: string): Promise<any>;
82
+ create(vocabItem: string, tokens: any[], metadata?: any, auditMessage?: string): Promise<any>;
83
+ bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
84
+ bulkDelete(body: any[], auditMessage?: string): Promise<void>;
85
+ setMetadata(id: string, body: any, auditMessage?: string): Promise<any>;
86
+ deleteMetadata(id: string, auditMessage?: string): Promise<any>;
87
+ patchMetadata(id: string, body: any, auditMessage?: string): Promise<any>;
43
88
  get(id: string, asOf?: string): Promise<any>;
44
- delete(id: string): Promise<any>;
89
+ delete(id: string, auditMessage?: string): Promise<any>;
45
90
  }
46
91
 
47
92
  interface VocabLayersBundle {
48
93
  get(id: string, includeItems?: boolean, asOf?: string): Promise<any>;
49
- delete(id: string): Promise<any>;
50
- update(id: string, name: string): Promise<any>;
51
- setConfig(id: string, namespace: string, configKey: string, configValue: any): Promise<any>;
52
- deleteConfig(id: string, namespace: string, configKey: string): Promise<any>;
94
+ delete(id: string, auditMessage?: string): Promise<any>;
95
+ update(id: string, name: string, auditMessage?: string): Promise<any>;
96
+ setConfig(id: string, namespace: string, configKey: string, configValue: any, auditMessage?: string): Promise<any>;
97
+ deleteConfig(id: string, namespace: string, configKey: string, auditMessage?: string): Promise<any>;
53
98
  list(asOf?: string): Promise<any[]>;
54
99
  listPage(opts?: { limit?: number; cursor?: string; asOf?: string }): Promise<Page>;
55
100
  iterPages(opts?: { pageSize?: number; asOf?: string }): AsyncGenerator<any[]>;
56
- create(name: string): Promise<any>;
57
- addMaintainer(id: string, userId: string): Promise<any>;
58
- removeMaintainer(id: string, userId: string): Promise<any>;
101
+ create(name: string, auditMessage?: string): Promise<any>;
102
+ addMaintainer(id: string, userId: string, auditMessage?: string): Promise<any>;
103
+ removeMaintainer(id: string, userId: string, auditMessage?: string): Promise<any>;
59
104
  }
60
105
 
61
106
  interface RelationsBundle {
62
- setMetadata(relationId: string, body: any): Promise<any>;
63
- deleteMetadata(relationId: string): Promise<any>;
64
- setTarget(relationId: string, spanId: string): Promise<any>;
107
+ setMetadata(relationId: string, body: any, auditMessage?: string): Promise<any>;
108
+ deleteMetadata(relationId: string, auditMessage?: string): Promise<any>;
109
+ patchMetadata(relationId: string, body: any, auditMessage?: string): Promise<any>;
110
+ setTarget(relationId: string, spanId: string, auditMessage?: string): Promise<any>;
65
111
  get(relationId: string, asOf?: string): Promise<any>;
66
- delete(relationId: string): Promise<any>;
67
- update(relationId: string, value: any): Promise<any>;
68
- setSource(relationId: string, spanId: string): Promise<any>;
69
- create(layerId: string, sourceId: string, targetId: string, value: any, metadata?: any): Promise<any>;
70
- bulkCreate(body: any[]): Promise<any>;
71
- bulkDelete(body: any[]): Promise<any>;
112
+ delete(relationId: string, auditMessage?: string): Promise<any>;
113
+ update(relationId: string, value: any, auditMessage?: string): Promise<any>;
114
+ setSource(relationId: string, spanId: string, auditMessage?: string): Promise<any>;
115
+ create(layerId: string, sourceId: string, targetId: string, value: any, metadata?: any, auditMessage?: string): Promise<any>;
116
+ bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
117
+ bulkDelete(body: any[], auditMessage?: string): Promise<void>;
72
118
  }
73
119
 
74
120
  interface SpanLayersBundle {
75
- setConfig(spanLayerId: string, namespace: string, configKey: string, configValue: any): Promise<any>;
76
- deleteConfig(spanLayerId: string, namespace: string, configKey: string): Promise<any>;
121
+ setConfig(spanLayerId: string, namespace: string, configKey: string, configValue: any, auditMessage?: string): Promise<any>;
122
+ deleteConfig(spanLayerId: string, namespace: string, configKey: string, auditMessage?: string): Promise<any>;
77
123
  get(spanLayerId: string, asOf?: string): Promise<any>;
78
- delete(spanLayerId: string): Promise<any>;
79
- update(spanLayerId: string, name: string): Promise<any>;
80
- create(tokenLayerId: string, name: string): Promise<any>;
81
- shift(spanLayerId: string, direction: string): Promise<any>;
124
+ delete(spanLayerId: string, auditMessage?: string): Promise<any>;
125
+ update(spanLayerId: string, name: string, auditMessage?: string): Promise<any>;
126
+ create(tokenLayerId: string, name: string, auditMessage?: string): Promise<any>;
127
+ shift(spanLayerId: string, direction: string, auditMessage?: string): Promise<any>;
82
128
  }
83
129
 
84
130
  interface SpansBundle {
85
- setTokens(spanId: string, tokens: any[]): Promise<any>;
86
- create(spanLayerId: string, tokens: any[], value: any, metadata?: any): Promise<any>;
131
+ setTokens(spanId: string, tokens: any[], auditMessage?: string): Promise<any>;
132
+ create(spanLayerId: string, tokens: any[], value: any, metadata?: any, auditMessage?: string): Promise<any>;
87
133
  get(spanId: string, asOf?: string): Promise<any>;
88
- delete(spanId: string): Promise<any>;
89
- update(spanId: string, value: any): Promise<any>;
90
- bulkCreate(body: any[]): Promise<any>;
91
- bulkDelete(body: any[]): Promise<any>;
92
- setMetadata(spanId: string, body: any): Promise<any>;
93
- deleteMetadata(spanId: string): Promise<any>;
134
+ delete(spanId: string, auditMessage?: string): Promise<any>;
135
+ update(spanId: string, value: any, auditMessage?: string): Promise<any>;
136
+ bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
137
+ bulkDelete(body: any[], auditMessage?: string): Promise<void>;
138
+ setMetadata(spanId: string, body: any, auditMessage?: string): Promise<any>;
139
+ deleteMetadata(spanId: string, auditMessage?: string): Promise<any>;
140
+ patchMetadata(spanId: string, body: any, auditMessage?: string): Promise<any>;
94
141
  }
95
142
 
96
143
  interface BatchBundle {
97
- submit(body: any[]): Promise<any>;
144
+ submit(body: any[], auditMessage?: string): Promise<any>;
98
145
  }
99
146
 
100
147
  interface TextsBundle {
101
- setMetadata(textId: string, body: any): Promise<any>;
102
- deleteMetadata(textId: string): Promise<any>;
103
- create(textLayerId: string, documentId: string, body: string, metadata?: any): Promise<any>;
148
+ setMetadata(textId: string, body: any, auditMessage?: string): Promise<any>;
149
+ deleteMetadata(textId: string, auditMessage?: string): Promise<any>;
150
+ patchMetadata(textId: string, body: any, auditMessage?: string): Promise<any>;
151
+ create(textLayerId: string, documentId: string, body: string, metadata?: any, auditMessage?: string): Promise<any>;
104
152
  get(textId: string, asOf?: string): Promise<any>;
105
- delete(textId: string): Promise<any>;
106
- update(textId: string, body: any): Promise<any>;
153
+ delete(textId: string, auditMessage?: string): Promise<any>;
154
+ update(textId: string, body: any, auditMessage?: string): Promise<any>;
107
155
  }
108
156
 
109
157
  interface UsersBundle {
110
158
  list(asOf?: string): Promise<any[]>;
111
159
  listPage(opts?: { limit?: number; cursor?: string; asOf?: string }): Promise<Page>;
112
160
  iterPages(opts?: { pageSize?: number; asOf?: string }): AsyncGenerator<any[]>;
113
- create(username: string, password: string, isAdmin: boolean): Promise<any>;
161
+ create(username: string, password: string, isAdmin: boolean, auditMessage?: string): Promise<any>;
114
162
  audit(userId: string, startTime?: string, endTime?: string, asOf?: string): Promise<any[]>;
115
163
  get(id: string, asOf?: string): Promise<any>;
116
- delete(id: string): Promise<any>;
117
- update(id: string, password?: string, username?: string, isAdmin?: boolean): Promise<any>;
164
+ delete(id: string, auditMessage?: string): Promise<any>;
165
+ activate(id: string, auditMessage?: string): Promise<any>;
166
+ update(id: string, password?: string, username?: string, isAdmin?: boolean, auditMessage?: string): Promise<any>;
118
167
  }
119
168
 
120
169
  interface ApiTokensBundle {
121
170
  list(userId: string): Promise<any[]>;
122
171
  listPage(userId: string, opts?: { limit?: number; cursor?: string }): Promise<Page>;
123
172
  iterPages(userId: string, opts?: { pageSize?: number }): AsyncGenerator<any[]>;
124
- create(userId: string, name: string): Promise<{ id: string; name: string; token: string }>;
125
- revoke(userId: string, tokenId: string): Promise<any>;
173
+ create(userId: string, name: string, auditMessage?: string): Promise<{ id: string; name: string; token: string }>;
174
+ revoke(userId: string, tokenId: string, auditMessage?: string): Promise<any>;
126
175
  }
127
176
 
128
177
  interface TokenLayersBundle {
129
- shift(tokenLayerId: string, direction: string): Promise<any>;
130
- create(textLayerId: string, name: string, overlapMode?: string, parentTokenLayerId?: string): Promise<any>;
131
- setConfig(tokenLayerId: string, namespace: string, configKey: string, configValue: any): Promise<any>;
132
- deleteConfig(tokenLayerId: string, namespace: string, configKey: string): Promise<any>;
178
+ shift(tokenLayerId: string, direction: string, auditMessage?: string): Promise<any>;
179
+ create(textLayerId: string, name: string, overlapMode?: string, parentTokenLayerId?: string, auditMessage?: string): Promise<any>;
180
+ setConfig(tokenLayerId: string, namespace: string, configKey: string, configValue: any, auditMessage?: string): Promise<any>;
181
+ deleteConfig(tokenLayerId: string, namespace: string, configKey: string, auditMessage?: string): Promise<any>;
133
182
  get(tokenLayerId: string, asOf?: string): Promise<any>;
134
- delete(tokenLayerId: string): Promise<any>;
135
- update(tokenLayerId: string, name: string): Promise<any>;
183
+ delete(tokenLayerId: string, auditMessage?: string): Promise<any>;
184
+ update(tokenLayerId: string, name: string, auditMessage?: string): Promise<any>;
136
185
  }
137
186
 
138
187
  interface DocumentsBundle {
139
188
  checkLock(documentId: string, asOf?: string): Promise<any>;
140
- acquireLock(documentId: string): Promise<any>;
141
- releaseLock(documentId: string): Promise<any>;
189
+ acquireLock(documentId: string, auditMessage?: string): Promise<any>;
190
+ releaseLock(documentId: string, auditMessage?: string): Promise<any>;
142
191
  getMedia(documentId: string, asOf?: string): Promise<ArrayBuffer>;
143
- uploadMedia(documentId: string, file: File): Promise<any>;
144
- deleteMedia(documentId: string): Promise<any>;
145
- setMetadata(documentId: string, body: any): Promise<any>;
146
- deleteMetadata(documentId: string): Promise<any>;
192
+ uploadMedia(documentId: string, file: File, auditMessage?: string): Promise<any>;
193
+ deleteMedia(documentId: string, auditMessage?: string): Promise<any>;
194
+ setMetadata(documentId: string, body: any, auditMessage?: string): Promise<any>;
195
+ deleteMetadata(documentId: string, auditMessage?: string): Promise<any>;
196
+ patchMetadata(documentId: string, body: any, auditMessage?: string): Promise<any>;
147
197
  audit(documentId: string, startTime?: string, endTime?: string, asOf?: string): Promise<any[]>;
148
198
  get(documentId: string, includeBody?: boolean, asOf?: string): Promise<any>;
149
- delete(documentId: string): Promise<any>;
150
- update(documentId: string, name: string): Promise<any>;
151
- create(projectId: string, name: string, metadata?: any): Promise<any>;
199
+ delete(documentId: string, auditMessage?: string): Promise<any>;
200
+ update(documentId: string, name: string, auditMessage?: string): Promise<any>;
201
+ create(projectId: string, name: string, metadata?: any, auditMessage?: string): Promise<any>;
152
202
  }
153
203
 
154
204
  interface MessagesBundle {
155
- sendMessage(projectId: string, data: any): Promise<any>;
205
+ sendMessage(projectId: string, data: any, auditMessage?: string): Promise<any>;
156
206
  listen(projectId: string, onEvent: (eventType: string, data: any) => void | boolean, path?: string): SSEConnection;
157
- /** Discover the services currently connected to a project. `timeout` is ignored (kept for back-compat). */
158
- discoverServices(projectId: string, timeout?: number): Promise<DiscoveredService[]>;
207
+ /** Discover the services seen on a project: online ones plus previously-seen offline ones (check `online`). */
208
+ discoverServices(projectId: string): Promise<DiscoveredService[]>;
209
+ /** Forget a previously-seen (offline) service. Maintainer-only; 409 if currently connected. */
210
+ discardService(projectId: string, serviceId: string): Promise<void>;
159
211
  serve(projectId: string, serviceInfo: ServiceInfo, onServiceRequest: (data: any, responseHelper: ResponseHelper) => void, extras?: any): ServiceRegistration;
160
212
  /** Submit work to a service; streams progress to `onProgress`, resolves with the result. */
161
213
  requestService(projectId: string, serviceId: string, data: any, timeout?: number, onProgress?: (progress: any) => void): Promise<any>;
162
214
  }
163
215
 
164
216
  interface ProjectsBundle {
165
- addWriter(id: string, userId: string): Promise<any>;
166
- removeWriter(id: string, userId: string): Promise<any>;
167
- addReader(id: string, userId: string): Promise<any>;
168
- removeReader(id: string, userId: string): Promise<any>;
169
- setConfig(id: string, namespace: string, configKey: string, configValue: any): Promise<any>;
170
- deleteConfig(id: string, namespace: string, configKey: string): Promise<any>;
171
- addMaintainer(id: string, userId: string): Promise<any>;
172
- removeMaintainer(id: string, userId: string): Promise<any>;
217
+ addWriter(id: string, userId: string, auditMessage?: string): Promise<any>;
218
+ removeWriter(id: string, userId: string, auditMessage?: string): Promise<any>;
219
+ addReader(id: string, userId: string, auditMessage?: string): Promise<any>;
220
+ removeReader(id: string, userId: string, auditMessage?: string): Promise<any>;
221
+ setConfig(id: string, namespace: string, configKey: string, configValue: any, auditMessage?: string): Promise<any>;
222
+ deleteConfig(id: string, namespace: string, configKey: string, auditMessage?: string): Promise<any>;
223
+ addMaintainer(id: string, userId: string, auditMessage?: string): Promise<any>;
224
+ removeMaintainer(id: string, userId: string, auditMessage?: string): Promise<any>;
173
225
  audit(projectId: string, startTime?: string, endTime?: string, asOf?: string): Promise<any[]>;
174
- linkVocab(id: string, vocabId: string): Promise<any>;
175
- unlinkVocab(id: string, vocabId: string): Promise<any>;
226
+ linkVocab(id: string, vocabId: string, auditMessage?: string): Promise<any>;
227
+ unlinkVocab(id: string, vocabId: string, auditMessage?: string): Promise<any>;
176
228
  get(id: string, asOf?: string): Promise<any>;
177
229
  listDocuments(id: string): Promise<any[]>;
178
230
  listDocumentsPage(id: string, opts?: { limit?: number; cursor?: string }): Promise<Page>;
179
231
  iterDocuments(id: string, opts?: { pageSize?: number }): AsyncGenerator<any[]>;
180
- delete(id: string): Promise<any>;
181
- update(id: string, name: string): Promise<any>;
232
+ delete(id: string, auditMessage?: string): Promise<any>;
233
+ update(id: string, name: string, auditMessage?: string): Promise<any>;
182
234
  list(asOf?: string): Promise<any[]>;
183
235
  listPage(opts?: { limit?: number; cursor?: string; asOf?: string }): Promise<Page>;
184
236
  iterPages(opts?: { pageSize?: number; asOf?: string }): AsyncGenerator<any[]>;
185
- create(name: string): Promise<any>;
237
+ create(name: string, auditMessage?: string): Promise<any>;
186
238
  }
187
239
 
188
240
  interface TextLayersBundle {
189
- setConfig(textLayerId: string, namespace: string, configKey: string, configValue: any): Promise<any>;
190
- deleteConfig(textLayerId: string, namespace: string, configKey: string): Promise<any>;
241
+ setConfig(textLayerId: string, namespace: string, configKey: string, configValue: any, auditMessage?: string): Promise<any>;
242
+ deleteConfig(textLayerId: string, namespace: string, configKey: string, auditMessage?: string): Promise<any>;
191
243
  get(textLayerId: string, asOf?: string): Promise<any>;
192
- delete(textLayerId: string): Promise<any>;
193
- update(textLayerId: string, name: string): Promise<any>;
194
- shift(textLayerId: string, direction: string): Promise<any>;
195
- create(projectId: string, name: string): Promise<any>;
244
+ delete(textLayerId: string, auditMessage?: string): Promise<any>;
245
+ update(textLayerId: string, name: string, auditMessage?: string): Promise<any>;
246
+ shift(textLayerId: string, direction: string, auditMessage?: string): Promise<any>;
247
+ create(projectId: string, name: string, auditMessage?: string): Promise<any>;
196
248
  }
197
249
 
198
250
  interface VocabItemsBundle {
199
- setMetadata(id: string, body: any): Promise<any>;
200
- deleteMetadata(id: string): Promise<any>;
201
- create(vocabLayerId: string, form: string, metadata?: any): Promise<any>;
251
+ setMetadata(id: string, body: any, auditMessage?: string): Promise<any>;
252
+ deleteMetadata(id: string, auditMessage?: string): Promise<any>;
253
+ patchMetadata(id: string, body: any, auditMessage?: string): Promise<any>;
254
+ create(vocabLayerId: string, form: string, metadata?: any, auditMessage?: string): Promise<any>;
255
+ bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
256
+ bulkDelete(body: any[], auditMessage?: string): Promise<void>;
202
257
  get(id: string, asOf?: string): Promise<any>;
203
- delete(id: string): Promise<any>;
204
- update(id: string, form: string): Promise<any>;
258
+ delete(id: string, auditMessage?: string): Promise<any>;
259
+ update(id: string, form: string, auditMessage?: string): Promise<any>;
205
260
  }
206
261
 
207
262
  interface RelationLayersBundle {
208
- shift(relationLayerId: string, direction: string): Promise<any>;
209
- create(spanLayerId: string, name: string): Promise<any>;
210
- setConfig(relationLayerId: string, namespace: string, configKey: string, configValue: any): Promise<any>;
211
- deleteConfig(relationLayerId: string, namespace: string, configKey: string): Promise<any>;
263
+ shift(relationLayerId: string, direction: string, auditMessage?: string): Promise<any>;
264
+ create(spanLayerId: string, name: string, auditMessage?: string): Promise<any>;
265
+ setConfig(relationLayerId: string, namespace: string, configKey: string, configValue: any, auditMessage?: string): Promise<any>;
266
+ deleteConfig(relationLayerId: string, namespace: string, configKey: string, auditMessage?: string): Promise<any>;
212
267
  get(relationLayerId: string, asOf?: string): Promise<any>;
213
- delete(relationLayerId: string): Promise<any>;
214
- update(relationLayerId: string, name: string): Promise<any>;
268
+ delete(relationLayerId: string, auditMessage?: string): Promise<any>;
269
+ update(relationLayerId: string, name: string, auditMessage?: string): Promise<any>;
215
270
  }
216
271
 
217
272
  interface TokensBundle {
218
- create(tokenLayerId: string, text: string, begin: number, end: number, precedence?: number | null, metadata?: any): Promise<any>;
273
+ create(tokenLayerId: string, text: string, begin: number, end: number, precedence?: number | null, metadata?: any, auditMessage?: string): Promise<any>;
219
274
  get(tokenId: string, asOf?: string): Promise<any>;
220
- delete(tokenId: string): Promise<any>;
221
- update(tokenId: string, begin?: number, end?: number, precedence?: number | null): Promise<any>;
222
- bulkCreate(body: any[]): Promise<any>;
223
- bulkDelete(body: any[]): Promise<any>;
224
- split(tokenId: string, position: number): Promise<any>;
225
- merge(tokenId: string, otherTokenId: string): Promise<any>;
226
- shift(tokenId: string, begin?: number, end?: number): Promise<any>;
227
- setMetadata(tokenId: string, body: any): Promise<any>;
228
- deleteMetadata(tokenId: string): Promise<any>;
275
+ delete(tokenId: string, auditMessage?: string): Promise<any>;
276
+ update(tokenId: string, begin?: number, end?: number, precedence?: number | null, auditMessage?: string): Promise<any>;
277
+ bulkCreate(body: any[], auditMessage?: string): Promise<{ ids: string[] }>;
278
+ bulkDelete(body: any[], auditMessage?: string): Promise<void>;
279
+ split(tokenId: string, position: number, auditMessage?: string): Promise<any>;
280
+ merge(tokenId: string, otherTokenId: string, auditMessage?: string): Promise<any>;
281
+ shift(tokenId: string, begin?: number, end?: number, auditMessage?: string): Promise<any>;
282
+ setMetadata(tokenId: string, body: any, auditMessage?: string): Promise<any>;
283
+ deleteMetadata(tokenId: string, auditMessage?: string): Promise<any>;
284
+ patchMetadata(tokenId: string, body: any, auditMessage?: string): Promise<any>;
229
285
  }
230
286
 
231
287
  interface PlaidClientOptions {
232
288
  /** Per-request timeout in ms (default 30000; 0 or null disables it). */
233
289
  timeout?: number | null;
290
+ /**
291
+ * Fired once when a request returns HTTP 401 (missing/expired/invalid token).
292
+ * Use it to discard the stored token and route back to login. 403 (forbidden)
293
+ * does NOT trigger it.
294
+ */
295
+ onAuthError?: ((error: Error) => void) | null;
234
296
  }
235
297
 
236
298
  export declare class PlaidClient {
237
299
  constructor(baseUrl: string, token: string, options?: PlaidClientOptions);
238
300
  static login(baseUrl: string, userId: string, password: string, options?: PlaidClientOptions): Promise<PlaidClient>;
239
301
  timeout: number | null;
302
+ /** Fired once on HTTP 401 (see PlaidClientOptions.onAuthError). */
303
+ onAuthError: ((error: Error) => void) | null;
240
304
 
241
305
  // Batch control methods
242
306
  beginBatch(): void;
243
307
  submitBatch(): Promise<any[]>;
244
308
  abortBatch(): void;
245
309
  isBatchMode(): boolean;
310
+ /** Run `fn` with a batch open, then submit atomically (or abort if `fn` throws). Resolves to the results array. */
311
+ batched(fn: () => void | Promise<void>): Promise<any[]>;
246
312
 
247
313
  // Strict mode methods
248
314
  enterStrictMode(documentId: string): void;
249
315
  exitStrictMode(): void;
250
316
 
317
+ // Custom audit-log message (overrides the auto-generated description; may
318
+ // template the endpoint's path/query/body params with {param} placeholders).
319
+ auditMessage: string | null;
320
+ setAuditMessage(message: string): this;
321
+ clearAuditMessage(): this;
322
+ withAuditMessage<T>(message: string, fn: () => Promise<T> | T): Promise<T>;
323
+
324
+ // Query
325
+ query(body: any, auditMessage?: string): Promise<any>;
326
+
251
327
  vocabLinks: VocabLinksBundle;
252
328
  vocabLayers: VocabLayersBundle;
253
329
  relations: RelationsBundle;
@@ -268,3 +344,107 @@ export declare class PlaidClient {
268
344
  }
269
345
 
270
346
  export default PlaidClient;
347
+
348
+ // --- Unicode code-point helpers for text offsets ---------------------------
349
+ // Token begin/end offsets are 0-based Unicode code-point indices (not UTF-16).
350
+ /** Number of Unicode code points in `s` (not `s.length`). */
351
+ export function cpLength(s: string): number;
352
+ /** Substring of `s` by code-point indices [begin, end) (end optional). */
353
+ export function cpSlice(s: string, begin: number, end?: number): string;
354
+ /** Prebuilt slicer for many code-point slices of one string (spreads once). */
355
+ export function cpSlicer(s: string): (begin: number, end?: number) => string;
356
+ /** UTF-16 index -> code-point index in `s`. */
357
+ export function utf16ToCp(s: string, u: number): number;
358
+ /** Code-point index -> UTF-16 index in `s` (clamps past the end). */
359
+ export function cpToUtf16(s: string, cp: number): number;
360
+ /** Like indexOf, but the result and `fromCp` are code-point indices; -1 if absent. */
361
+ export function cpIndexOf(s: string, sub: string, fromCp?: number): number;
362
+
363
+ // --- Shared layer-role vocabulary (cross-app interoperability) --------------
364
+ // Substrate layers are tagged with a role at `config.plaid.role` (a scalar) so
365
+ // that different apps can share a project. See the manual, "Layer Interoperability".
366
+ /** The reserved config namespace for cross-app conventions. */
367
+ export const PLAID_NAMESPACE: 'plaid';
368
+ /** The config key, under `plaid`, holding a layer's role. */
369
+ export const ROLE_KEY: 'role';
370
+ /** The fixed role inventory; only these values are interoperable across apps. */
371
+ export const ROLES: {
372
+ readonly BASELINE: 'baseline';
373
+ readonly SENTENCE: 'sentence';
374
+ readonly WORD: 'word';
375
+ readonly SYNTACTIC_WORD: 'syntactic-word';
376
+ readonly MORPHEME: 'morpheme';
377
+ readonly TIME_ALIGNMENT: 'time-alignment';
378
+ };
379
+ /** The role recorded on a layer's `config`, or null if none. */
380
+ export function readRole(config?: object): string | null;
381
+ /** The first layer in `layers` carrying the given role, or null. */
382
+ export function findByRole<T extends { config?: object }>(layers: T[] | undefined, role: string): T | null;
383
+
384
+ // --- Service self-description helpers ----------------------------------------
385
+ // Standardize how a service advertises (in `extras`) the tasks it serves, a
386
+ // summary, and a parameter schema — so a UI can offer service selection, an
387
+ // argument form, and a summary at a fixed integration point. See the manual,
388
+ // "Describing a service".
389
+ /** The controlled task vocabulary — the fixed integration-point goals. */
390
+ export const TASKS: {
391
+ readonly TOKENIZE: 'tokenize';
392
+ readonly PARSE: 'parse';
393
+ readonly TRANSCRIBE: 'transcribe';
394
+ readonly LINK_VOCAB: 'link-vocab';
395
+ };
396
+ /** Whether a service serves a task (declared `extras.tasks`, legacy id-prefix fallback). */
397
+ export function servesTask(service: DiscoveredService, task: string): boolean;
398
+ /** The discovered services that serve `task`. */
399
+ export function filterServicesByTask(services: DiscoveredService[] | undefined, task: string): DiscoveredService[];
400
+ /** The parameter schema a service declares (ordered), or []. */
401
+ export function getParamSchema(service: DiscoveredService): ServiceParam[];
402
+ /** A service's human summary: `extras.summary`, else `description`, else ''. */
403
+ export function getServiceSummary(service: DiscoveredService): string;
404
+ /** Default form values keyed by param key. */
405
+ export function buildDefaultValues(schema: ServiceParam[]): Record<string, any>;
406
+ /** Coerce/validate raw form values against the schema. */
407
+ export function coerceParamValues(schema: ServiceParam[], raw: Record<string, any>): { values: Record<string, any>; errors: Record<string, string> };
408
+
409
+ // --- Provenance ---------------------------------------------------------------
410
+ // Cross-app convention for machine-provided vs human-labeled information,
411
+ // expressed as flat metadata keys on annotation entities. Absent keys = human;
412
+ // { prov: 'inferred', provSource } = machine-made, unverified;
413
+ // + { provConfirmed: true } = machine-made, human-verified. Machine writers may
414
+ // replace unverified machine material but must never touch human/verified
415
+ // material without an explicit overwrite opt-in; any human edit verifies.
416
+ // See the manual, "Provenance".
417
+ type ProvState = 'human' | 'machine' | 'verified';
418
+ export const PROV: {
419
+ readonly key: 'prov';
420
+ readonly sourceKey: 'provSource';
421
+ readonly confirmedKey: 'provConfirmed';
422
+ readonly probKey: 'provProb';
423
+ readonly detailKey: 'provDetail';
424
+ readonly INFERRED: 'inferred';
425
+ };
426
+ export const PROV_STATES: {
427
+ readonly HUMAN: 'human';
428
+ readonly MACHINE: 'machine';
429
+ readonly VERIFIED: 'verified';
430
+ };
431
+ /** Optional prediction extras: prob = a probability in [0,1] for the chosen value
432
+ * (flat + queryable; omit unless it honestly is one); detail = an open map of
433
+ * producer extras (top-k alternatives, model version, raw scores; keep it small).
434
+ * Both describe the ORIGINAL prediction — check provConfirmed before presenting
435
+ * provProb as confidence in the current value. */
436
+ interface ProvExtras { prob?: number; detail?: Record<string, any> }
437
+ /** The metadata fragment a machine writer merges into everything it creates. */
438
+ export function stampInferred(source: string, extras?: ProvExtras):
439
+ { prov: 'inferred'; provSource: string; provProb?: number; provDetail?: Record<string, any> };
440
+ /** stampInferred + provConfirmed — for machine material born verified (e.g. imports with upstream approval). */
441
+ export function confirmedInferred(source: string, extras?: ProvExtras):
442
+ { prov: 'inferred'; provSource: string; provConfirmed: true; provProb?: number; provDetail?: Record<string, any> };
443
+ /** Classify an entity's metadata into one of the three provenance states. */
444
+ export function provState(metadata: object | null | undefined): ProvState;
445
+ /** Whether a machine writer must leave this entity alone (human or verified). */
446
+ export function isProtected(metadata: object | null | undefined): boolean;
447
+ /** The fragment a HUMAN edit should merge in: { provConfirmed: true } iff machine-unverified, else null. */
448
+ export function verifyOnEdit(metadata: object | null | undefined): { provConfirmed: true } | null;
449
+ /** Canonical provSource for a service: 'service:<serviceId>'. */
450
+ export function serviceSource(serviceId: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larc-iu/plaid-client",
3
- "version": "0.1.0-alpha.8",
3
+ "version": "0.2.0-alpha.0",
4
4
  "description": "JavaScript client for the Plaid annotation API",
5
5
  "type": "module",
6
6
  "repository": {
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Unicode code-point helpers for working with Plaid text offsets.
3
+ *
4
+ * Plaid token offsets (`begin` / `end`) are 0-based indices in Unicode CODE
5
+ * POINTS (begin inclusive, end exclusive) — NOT UTF-16 code units. JavaScript
6
+ * strings are UTF-16, so `.length`, `.slice`, `.substring`, `s[i]`,
7
+ * `String.prototype.indexOf`, and `Intl.Segmenter`'s `index` all count UTF-16
8
+ * code units, which disagree with code points for astral characters
9
+ * (>= U+10000 — emoji, and SMP scripts such as Gothic, cuneiform, CJK Ext-B).
10
+ *
11
+ * Use these to slice a text body by token offsets, and to compute offsets for
12
+ * new tokens, in code points. The spread/`for…of` string iterator yields code
13
+ * points, which is what makes this work.
14
+ */
15
+
16
+ /** Number of Unicode code points in `s` (not `s.length`, which is UTF-16). */
17
+ export function cpLength(s) {
18
+ return [...s].length;
19
+ }
20
+
21
+ /**
22
+ * Substring of `s` by CODE-POINT indices [begin, end) (end optional = to end).
23
+ * Mirrors `String.prototype.slice` semantics but in code points.
24
+ */
25
+ export function cpSlice(s, begin, end) {
26
+ return [...s].slice(begin, end).join('');
27
+ }
28
+
29
+ /**
30
+ * Prebuilt slicer for taking MANY code-point slices of the same string:
31
+ * spreads `s` into code points once, then each slice costs O(slice length).
32
+ * `cpSlice` spreads the whole string per call, which turns quadratic when a
33
+ * caller slices every token of a large text. Mirror of the server's
34
+ * `plaid.util.codepoint/cp-slicer`.
35
+ */
36
+ export function cpSlicer(s) {
37
+ const chars = [...(s ?? '')];
38
+ return (begin, end) => chars.slice(begin, end).join('');
39
+ }
40
+
41
+ /**
42
+ * Convert a UTF-16 index `u` into `s` to a code-point index — i.e. how many
43
+ * code points precede `u`. Inverse of `cpToUtf16`. Useful for converting a
44
+ * DOM/`indexOf`/`Intl.Segmenter` (UTF-16) position into a code-point offset.
45
+ */
46
+ export function utf16ToCp(s, u) {
47
+ return [...s.slice(0, u)].length;
48
+ }
49
+
50
+ /**
51
+ * Convert a code-point index `cp` into `s` to a UTF-16 index. Clamps to
52
+ * `s.length` when `cp` is past the end. Inverse of `utf16ToCp`.
53
+ */
54
+ export function cpToUtf16(s, cp) {
55
+ if (cp <= 0) return 0;
56
+ let u = 0;
57
+ let c = 0;
58
+ for (const ch of s) {
59
+ if (c >= cp) break;
60
+ u += ch.length; // 1 for BMP, 2 for an astral code point (surrogate pair)
61
+ c += 1;
62
+ }
63
+ return u;
64
+ }
65
+
66
+ /**
67
+ * Like `String.prototype.indexOf`, but the returned index and `fromCp` are
68
+ * CODE-POINT indices. Returns -1 when `sub` is not found.
69
+ */
70
+ export function cpIndexOf(s, sub, fromCp = 0) {
71
+ const u = s.indexOf(sub, cpToUtf16(s, fromCp));
72
+ return u < 0 ? -1 : utf16ToCp(s, u);
73
+ }