@twin.org/auditable-item-stream-rest-client 0.0.3-next.2 → 0.0.3-next.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/examples.md CHANGED
@@ -1 +1,183 @@
1
- # @twin.org/auditable-item-stream-rest-client - Examples
1
+ # Auditable Item Stream REST Client Examples
2
+
3
+ These snippets show practical client-side workflows for creating streams, managing entries, and paging through results.
4
+
5
+ ## AuditableItemStreamRestClient
6
+
7
+ ```typescript
8
+ import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
9
+ import type { IBaseRestClientConfig } from '@twin.org/api-models';
10
+
11
+ const config: IBaseRestClientConfig = {
12
+ endpoint: 'http://localhost:3000'
13
+ };
14
+
15
+ const client = new AuditableItemStreamRestClient(config);
16
+ console.log(client.className()); // AuditableItemStreamRestClient
17
+ ```
18
+
19
+ ```typescript
20
+ import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
21
+ import type { IBaseRestClientConfig } from '@twin.org/api-models';
22
+
23
+ const config: IBaseRestClientConfig = {
24
+ endpoint: 'http://localhost:3000'
25
+ };
26
+
27
+ const client = new AuditableItemStreamRestClient(config);
28
+
29
+ const streamId = await client.create(
30
+ {
31
+ annotationObject: {
32
+ '@context': 'https://schema.org',
33
+ '@type': 'CreativeWork',
34
+ name: 'Monthly Compliance Report'
35
+ },
36
+ entries: [
37
+ {
38
+ entryObject: {
39
+ '@context': 'https://schema.org',
40
+ '@type': 'Event',
41
+ name: 'Report created'
42
+ }
43
+ }
44
+ ]
45
+ },
46
+ {
47
+ immutableInterval: 5
48
+ }
49
+ );
50
+
51
+ const stream = await client.get(streamId, {
52
+ includeEntries: true,
53
+ verifyStream: true,
54
+ verifyEntries: true
55
+ });
56
+
57
+ await client.update({
58
+ id: streamId,
59
+ annotationObject: {
60
+ '@context': 'https://schema.org',
61
+ '@type': 'CreativeWork',
62
+ name: 'Monthly Compliance Report v2'
63
+ }
64
+ });
65
+
66
+ console.log(stream.id); // ais:...
67
+ console.log(stream.numberOfItems); // 1
68
+ ```
69
+
70
+ ```typescript
71
+ import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
72
+ import type { IBaseRestClientConfig } from '@twin.org/api-models';
73
+ import { ComparisonOperator, SortDirection } from '@twin.org/entity';
74
+
75
+ const config: IBaseRestClientConfig = {
76
+ endpoint: 'http://localhost:3000'
77
+ };
78
+
79
+ const client = new AuditableItemStreamRestClient(config);
80
+
81
+ const firstPage = await client.query(
82
+ [
83
+ {
84
+ property: 'organizationIdentity',
85
+ comparison: ComparisonOperator.Equals,
86
+ value: 'did:iota:org:123'
87
+ }
88
+ ],
89
+ 'dateCreated',
90
+ SortDirection.Descending,
91
+ ['id', 'dateCreated', 'dateModified', 'numberOfItems'],
92
+ 'cursor:page-1',
93
+ 10
94
+ );
95
+
96
+ console.log(firstPage.entries.itemListElement.length); // 10
97
+ console.log(firstPage.cursor); // eyJjdXJzb3IiOiIuLi4ifQ==
98
+ ```
99
+
100
+ ```typescript
101
+ import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
102
+ import type { IBaseRestClientConfig } from '@twin.org/api-models';
103
+
104
+ const config: IBaseRestClientConfig = {
105
+ endpoint: 'http://localhost:3000'
106
+ };
107
+
108
+ const client = new AuditableItemStreamRestClient(config);
109
+ const streamId = 'ais:0f4f9de65dc44f31b4a474a0cc93ce69';
110
+
111
+ const entryId = await client.createEntry(streamId, {
112
+ '@context': 'https://schema.org',
113
+ '@type': 'Message',
114
+ text: 'Status changed to approved'
115
+ });
116
+
117
+ const entry = await client.getEntry(streamId, entryId, {
118
+ verifyEntry: true
119
+ });
120
+
121
+ await client.updateEntry(streamId, entryId, {
122
+ '@context': 'https://schema.org',
123
+ '@type': 'Message',
124
+ text: 'Status changed to approved by reviewer'
125
+ });
126
+
127
+ const entryObject = await client.getEntryObject(streamId, entryId);
128
+ console.log(entry.id); // ais:0f4f9de65dc44f31b4a474a0cc93ce69:...
129
+ console.log(entryObject['@type']); // Message
130
+
131
+ await client.removeEntry(streamId, entryId);
132
+ ```
133
+
134
+ ```typescript
135
+ import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
136
+ import type { IBaseRestClientConfig } from '@twin.org/api-models';
137
+ import { SortDirection } from '@twin.org/entity';
138
+
139
+ const config: IBaseRestClientConfig = {
140
+ endpoint: 'http://localhost:3000'
141
+ };
142
+
143
+ const client = new AuditableItemStreamRestClient(config);
144
+ const streamId = 'ais:0f4f9de65dc44f31b4a474a0cc93ce69';
145
+
146
+ const entryList = await client.getEntries(streamId, {
147
+ includeDeleted: false,
148
+ verifyEntries: false,
149
+ limit: 20,
150
+ order: SortDirection.Ascending
151
+ });
152
+
153
+ const entryObjectList = await client.getEntryObjects(streamId, {
154
+ includeDeleted: true,
155
+ limit: 20,
156
+ order: SortDirection.Descending
157
+ });
158
+
159
+ console.log(entryList.entries.itemListElement.length); // 20
160
+ console.log(entryObjectList.entries.itemListElement.length); // 20
161
+ ```
162
+
163
+ ```typescript
164
+ import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
165
+ import type { IBaseRestClientConfig } from '@twin.org/api-models';
166
+
167
+ const config: IBaseRestClientConfig = {
168
+ endpoint: 'http://localhost:3000'
169
+ };
170
+
171
+ const client = new AuditableItemStreamRestClient(config);
172
+ const streamId = 'ais:0f4f9de65dc44f31b4a474a0cc93ce69';
173
+
174
+ try {
175
+ await client.removeVerifiable(streamId);
176
+ } catch (error) {
177
+ if (error instanceof Error) {
178
+ console.log(error.name); // NotSupportedError
179
+ }
180
+ }
181
+
182
+ await client.remove(streamId);
183
+ ```
@@ -8,7 +8,7 @@ Client for performing auditable item stream through to REST endpoints.
8
8
 
9
9
  ## Implements
10
10
 
11
- - `IAuditableItemStreamComponent`
11
+ - `Omit`\<`IAuditableItemStreamComponent`, `"removeProof"`\>
12
12
 
13
13
  ## Constructors
14
14
 
@@ -36,7 +36,7 @@ The configuration for the client.
36
36
 
37
37
  ## Properties
38
38
 
39
- ### CLASS\_NAME
39
+ ### CLASS\_NAME {#class_name}
40
40
 
41
41
  > `readonly` `static` **CLASS\_NAME**: `string`
42
42
 
@@ -44,7 +44,7 @@ Runtime name for the class.
44
44
 
45
45
  ## Methods
46
46
 
47
- ### className()
47
+ ### className() {#classname}
48
48
 
49
49
  > **className**(): `string`
50
50
 
@@ -58,13 +58,13 @@ The class name of the component.
58
58
 
59
59
  #### Implementation of
60
60
 
61
- `IAuditableItemStreamComponent.className`
61
+ `Omit.className`
62
62
 
63
63
  ***
64
64
 
65
- ### create()
65
+ ### create() {#create}
66
66
 
67
- > **create**(`stream`, `options?`): `Promise`\<`string`\>
67
+ > **create**(`stream`): `Promise`\<`string`\>
68
68
 
69
69
  Create a new stream.
70
70
 
@@ -72,30 +72,9 @@ Create a new stream.
72
72
 
73
73
  ##### stream
74
74
 
75
- The stream to create.
76
-
77
- ###### annotationObject?
78
-
79
- `IJsonLdNodeObject`
80
-
81
- The object for the stream as JSON-LD.
82
-
83
- ###### entries?
84
-
85
- `object`[]
75
+ `IAuditableItemStreamBase`
86
76
 
87
- Entries to store in the stream.
88
-
89
- ##### options?
90
-
91
- Options for creating the stream.
92
-
93
- ###### immutableInterval?
94
-
95
- `number`
96
-
97
- After how many entries do we add immutable checks, defaults to service configured value.
98
- A value of 0 will disable integrity checks, 1 will be every item, or any other integer for an interval.
77
+ The stream to create.
99
78
 
100
79
  #### Returns
101
80
 
@@ -105,13 +84,13 @@ The id of the new stream item.
105
84
 
106
85
  #### Implementation of
107
86
 
108
- `IAuditableItemStreamComponent.create`
87
+ `Omit.create`
109
88
 
110
89
  ***
111
90
 
112
- ### get()
91
+ ### get() {#get}
113
92
 
114
- > **get**(`id`, `options?`): `Promise`\<`IAuditableItemStream`\>
93
+ > **get**(`id`, `cursor?`, `limit?`, `options?`): `Promise`\<\{ `stream`: `IAuditableItemStream`; `cursor?`: `string`; \}\>
115
94
 
116
95
  Get a stream header without the entries.
117
96
 
@@ -123,6 +102,18 @@ Get a stream header without the entries.
123
102
 
124
103
  The id of the stream to get.
125
104
 
105
+ ##### cursor?
106
+
107
+ `string`
108
+
109
+ Cursor to use for next chunk of entries.
110
+
111
+ ##### limit?
112
+
113
+ `number`
114
+
115
+ Limit the number of entries to return, only applicable if includeEntries is true.
116
+
126
117
  ##### options?
127
118
 
128
119
  Additional options for the get operation.
@@ -153,7 +144,7 @@ Should the entries be verified, defaults to false.
153
144
 
154
145
  #### Returns
155
146
 
156
- `Promise`\<`IAuditableItemStream`\>
147
+ `Promise`\<\{ `stream`: `IAuditableItemStream`; `cursor?`: `string`; \}\>
157
148
 
158
149
  The stream and entries if found.
159
150
 
@@ -163,11 +154,11 @@ NotFoundError if the stream is not found
163
154
 
164
155
  #### Implementation of
165
156
 
166
- `IAuditableItemStreamComponent.get`
157
+ `Omit.get`
167
158
 
168
159
  ***
169
160
 
170
- ### update()
161
+ ### update() {#update}
171
162
 
172
163
  > **update**(`stream`): `Promise`\<`void`\>
173
164
 
@@ -177,19 +168,35 @@ Update a stream.
177
168
 
178
169
  ##### stream
179
170
 
180
- The stream to update.
171
+ `Pick`\<`IAuditableItemStream`, `"@context"` \| `"type"` \| `"id"` \| `"annotationObject"`\>
181
172
 
182
- ###### id
173
+ The stream to update, does not update entries.
183
174
 
184
- `string`
175
+ #### Returns
185
176
 
186
- The id of the stream to update.
177
+ `Promise`\<`void`\>
187
178
 
188
- ###### annotationObject?
179
+ Nothing.
189
180
 
190
- `IJsonLdNodeObject`
181
+ #### Implementation of
191
182
 
192
- The object for the stream as JSON-LD.
183
+ `Omit.update`
184
+
185
+ ***
186
+
187
+ ### close() {#close}
188
+
189
+ > **close**(`id`): `Promise`\<`void`\>
190
+
191
+ Close the stream.
192
+
193
+ #### Parameters
194
+
195
+ ##### id
196
+
197
+ `string`
198
+
199
+ The id of the stream to close.
193
200
 
194
201
  #### Returns
195
202
 
@@ -199,11 +206,11 @@ Nothing.
199
206
 
200
207
  #### Implementation of
201
208
 
202
- `IAuditableItemStreamComponent.update`
209
+ `Omit.close`
203
210
 
204
211
  ***
205
212
 
206
- ### remove()
213
+ ### remove() {#remove}
207
214
 
208
215
  > **remove**(`id`): `Promise`\<`void`\>
209
216
 
@@ -225,13 +232,13 @@ Nothing.
225
232
 
226
233
  #### Implementation of
227
234
 
228
- `IAuditableItemStreamComponent.remove`
235
+ `Omit.remove`
229
236
 
230
237
  ***
231
238
 
232
- ### query()
239
+ ### query() {#query}
233
240
 
234
- > **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `properties?`, `cursor?`, `limit?`): `Promise`\<`IAuditableItemStreamList`\>
241
+ > **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IAuditableItemStreamList`; `cursor?`: `string`; \}\>
235
242
 
236
243
  Query all the streams, will not return entries.
237
244
 
@@ -245,9 +252,9 @@ Conditions to use in the query.
245
252
 
246
253
  ##### orderBy?
247
254
 
248
- The order for the results, defaults to created.
255
+ `"dateCreated"` \| `"dateModified"`
249
256
 
250
- `"dateCreated"` | `"dateModified"`
257
+ The order for the results, defaults to created.
251
258
 
252
259
  ##### orderByDirection?
253
260
 
@@ -275,17 +282,17 @@ Limit the number of entities to return.
275
282
 
276
283
  #### Returns
277
284
 
278
- `Promise`\<`IAuditableItemStreamList`\>
285
+ `Promise`\<\{ `entries`: `IAuditableItemStreamList`; `cursor?`: `string`; \}\>
279
286
 
280
287
  The entities, which can be partial if a limited keys list was provided.
281
288
 
282
289
  #### Implementation of
283
290
 
284
- `IAuditableItemStreamComponent.query`
291
+ `Omit.query`
285
292
 
286
293
  ***
287
294
 
288
- ### createEntry()
295
+ ### createEntry() {#createentry}
289
296
 
290
297
  > **createEntry**(`id`, `entryObject`): `Promise`\<`string`\>
291
298
 
@@ -313,11 +320,11 @@ The id of the created entry, if not provided.
313
320
 
314
321
  #### Implementation of
315
322
 
316
- `IAuditableItemStreamComponent.createEntry`
323
+ `Omit.createEntry`
317
324
 
318
325
  ***
319
326
 
320
- ### getEntry()
327
+ ### getEntry() {#getentry}
321
328
 
322
329
  > **getEntry**(`id`, `entryId`, `options?`): `Promise`\<`IAuditableItemStreamEntry`\>
323
330
 
@@ -359,11 +366,11 @@ NotFoundError if the stream is not found.
359
366
 
360
367
  #### Implementation of
361
368
 
362
- `IAuditableItemStreamComponent.getEntry`
369
+ `Omit.getEntry`
363
370
 
364
371
  ***
365
372
 
366
- ### getEntryObject()
373
+ ### getEntryObject() {#getentryobject}
367
374
 
368
375
  > **getEntryObject**(`id`, `entryId`): `Promise`\<`IJsonLdNodeObject`\>
369
376
 
@@ -395,11 +402,11 @@ NotFoundError if the stream is not found.
395
402
 
396
403
  #### Implementation of
397
404
 
398
- `IAuditableItemStreamComponent.getEntryObject`
405
+ `Omit.getEntryObject`
399
406
 
400
407
  ***
401
408
 
402
- ### updateEntry()
409
+ ### updateEntry() {#updateentry}
403
410
 
404
411
  > **updateEntry**(`id`, `entryId`, `entryObject`): `Promise`\<`void`\>
405
412
 
@@ -433,11 +440,11 @@ Nothing.
433
440
 
434
441
  #### Implementation of
435
442
 
436
- `IAuditableItemStreamComponent.updateEntry`
443
+ `Omit.updateEntry`
437
444
 
438
445
  ***
439
446
 
440
- ### removeEntry()
447
+ ### removeEntry() {#removeentry}
441
448
 
442
449
  > **removeEntry**(`id`, `entryId`): `Promise`\<`void`\>
443
450
 
@@ -465,23 +472,23 @@ Nothing.
465
472
 
466
473
  #### Implementation of
467
474
 
468
- `IAuditableItemStreamComponent.removeEntry`
475
+ `Omit.removeEntry`
469
476
 
470
477
  ***
471
478
 
472
- ### getEntries()
479
+ ### getEntries() {#getentries}
473
480
 
474
- > **getEntries**(`id`, `options?`): `Promise`\<`IAuditableItemStreamEntryList`\>
481
+ > **getEntries**(`id?`, `options?`): `Promise`\<\{ `entries`: `IAuditableItemStreamEntryList`; `cursor?`: `string`; \}\>
475
482
 
476
483
  Get the entries for the stream.
477
484
 
478
485
  #### Parameters
479
486
 
480
- ##### id
487
+ ##### id?
481
488
 
482
489
  `string`
483
490
 
484
- The id of the stream to get.
491
+ The id of the stream to get, if undefined returns all matching entries.
485
492
 
486
493
  ##### options?
487
494
 
@@ -525,7 +532,7 @@ Retrieve the entries in ascending/descending time order, defaults to Ascending.
525
532
 
526
533
  #### Returns
527
534
 
528
- `Promise`\<`IAuditableItemStreamEntryList`\>
535
+ `Promise`\<\{ `entries`: `IAuditableItemStreamEntryList`; `cursor?`: `string`; \}\>
529
536
 
530
537
  The stream and entries if found.
531
538
 
@@ -535,23 +542,23 @@ NotFoundError if the stream is not found.
535
542
 
536
543
  #### Implementation of
537
544
 
538
- `IAuditableItemStreamComponent.getEntries`
545
+ `Omit.getEntries`
539
546
 
540
547
  ***
541
548
 
542
- ### getEntryObjects()
549
+ ### getEntryObjects() {#getentryobjects}
543
550
 
544
- > **getEntryObjects**(`id`, `options?`): `Promise`\<`IAuditableItemStreamEntryObjectList`\>
551
+ > **getEntryObjects**(`id?`, `options?`): `Promise`\<\{ `entries`: `IAuditableItemStreamEntryObjectList`; `cursor?`: `string`; \}\>
545
552
 
546
553
  Get the entry objects for the stream.
547
554
 
548
555
  #### Parameters
549
556
 
550
- ##### id
557
+ ##### id?
551
558
 
552
559
  `string`
553
560
 
554
- The id of the stream to get.
561
+ The id of the stream to get, if undefined returns all matching entries.
555
562
 
556
563
  ##### options?
557
564
 
@@ -589,7 +596,7 @@ Retrieve the entries in ascending/descending time order, defaults to Ascending.
589
596
 
590
597
  #### Returns
591
598
 
592
- `Promise`\<`IAuditableItemStreamEntryObjectList`\>
599
+ `Promise`\<\{ `entries`: `IAuditableItemStreamEntryObjectList`; `cursor?`: `string`; \}\>
593
600
 
594
601
  The stream and entries if found.
595
602
 
@@ -599,34 +606,4 @@ NotFoundError if the stream is not found.
599
606
 
600
607
  #### Implementation of
601
608
 
602
- `IAuditableItemStreamComponent.getEntryObjects`
603
-
604
- ***
605
-
606
- ### removeVerifiable()
607
-
608
- > **removeVerifiable**(`id`): `Promise`\<`void`\>
609
-
610
- Remove the verifiable storage for the stream and entries, not supported on client.
611
-
612
- #### Parameters
613
-
614
- ##### id
615
-
616
- `string`
617
-
618
- The id of the stream to remove the storage from.
619
-
620
- #### Returns
621
-
622
- `Promise`\<`void`\>
623
-
624
- Nothing.
625
-
626
- #### Throws
627
-
628
- NotFoundError if the vertex is not found.
629
-
630
- #### Implementation of
631
-
632
- `IAuditableItemStreamComponent.removeVerifiable`
609
+ `Omit.getEntryObjects`
package/locales/en.json CHANGED
@@ -1,7 +1 @@
1
- {
2
- "error": {
3
- "auditableItemStreamRestClient": {
4
- "notSupportedOnClient": "The method \"{methodName}\" is not supported on the REST client, it can only be used on a server side component"
5
- }
6
- }
7
- }
1
+ {}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/auditable-item-stream-rest-client",
3
- "version": "0.0.3-next.2",
4
- "description": "Auditable Item Stream contract implementation which can connect to REST endpoints",
3
+ "version": "0.0.3-next.20",
4
+ "description": "HTTP client for interacting with auditable stream service endpoints.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/auditable-item-stream.git",
7
+ "url": "git+https://github.com/iotaledger/twin-auditable-item-stream.git",
8
8
  "directory": "packages/auditable-item-stream-rest-client"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@twin.org/api-core": "next",
18
18
  "@twin.org/api-models": "next",
19
- "@twin.org/auditable-item-stream-models": "0.0.3-next.2",
19
+ "@twin.org/auditable-item-stream-models": "0.0.3-next.20",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/data-json-ld": "next",
22
22
  "@twin.org/entity": "next",
@@ -48,7 +48,7 @@
48
48
  "auditable-item-stream"
49
49
  ],
50
50
  "bugs": {
51
- "url": "git+https://github.com/twinfoundation/auditable-item-stream/issues"
51
+ "url": "git+https://github.com/iotaledger/twin-auditable-item-stream/issues"
52
52
  },
53
53
  "homepage": "https://twindev.org"
54
54
  }