@twin.org/synchronised-storage-service 0.0.1-next.3 → 0.0.1-next.5

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 (34) hide show
  1. package/dist/cjs/index.cjs +963 -276
  2. package/dist/esm/index.mjs +965 -279
  3. package/dist/types/entities/syncSnapshotEntry.d.ts +12 -5
  4. package/dist/types/helpers/blobStorageHelper.d.ts +39 -0
  5. package/dist/types/helpers/changeSetHelper.d.ts +26 -7
  6. package/dist/types/helpers/localSyncStateHelper.d.ts +11 -25
  7. package/dist/types/helpers/remoteSyncStateHelper.d.ts +17 -12
  8. package/dist/types/helpers/versions.d.ts +3 -0
  9. package/dist/types/index.d.ts +0 -2
  10. package/dist/types/models/ISyncPointerStore.d.ts +4 -0
  11. package/dist/types/models/ISyncSnapshot.d.ts +9 -1
  12. package/dist/types/models/ISyncState.d.ts +8 -0
  13. package/dist/types/models/ISynchronisedStorageServiceConfig.d.ts +17 -6
  14. package/dist/types/models/ISynchronisedStorageServiceConstructorOptions.d.ts +6 -2
  15. package/dist/types/synchronisedStorageRoutes.d.ts +9 -1
  16. package/dist/types/synchronisedStorageService.d.ts +13 -4
  17. package/docs/architecture.md +128 -0
  18. package/docs/changelog.md +29 -0
  19. package/docs/open-api/spec.json +246 -18
  20. package/docs/reference/classes/SyncSnapshotEntry.md +22 -6
  21. package/docs/reference/classes/SynchronisedStorageService.md +38 -5
  22. package/docs/reference/functions/synchronisedStorageGetDecryptionKeyRequest.md +31 -0
  23. package/docs/reference/index.md +1 -2
  24. package/docs/reference/interfaces/ISyncPointerStore.md +8 -0
  25. package/docs/reference/interfaces/ISyncSnapshot.md +18 -2
  26. package/docs/reference/interfaces/ISyncState.md +16 -0
  27. package/docs/reference/interfaces/ISynchronisedStorageServiceConfig.md +44 -10
  28. package/docs/reference/interfaces/ISynchronisedStorageServiceConstructorOptions.md +11 -3
  29. package/locales/en.json +60 -25
  30. package/package.json +3 -2
  31. package/dist/types/models/ISyncChange.d.ts +0 -18
  32. package/dist/types/models/ISyncChangeSet.d.ts +0 -36
  33. package/docs/reference/interfaces/ISyncChange.md +0 -33
  34. package/docs/reference/interfaces/ISyncChangeSet.md +0 -65
@@ -21,30 +21,53 @@
21
21
  }
22
22
  ],
23
23
  "paths": {
24
- "/synchronised-storage": {
25
- "get": {
24
+ "/synchronised-storage/sync-changeset": {
25
+ "post": {
26
26
  "operationId": "synchronisedStorageSyncChangeSetRequest",
27
27
  "summary": "Request that the node perform a sync request for a changeset.",
28
28
  "tags": [
29
29
  "Synchronised Storage"
30
30
  ],
31
- "parameters": [
32
- {
33
- "name": "changeSetStorageId",
34
- "description": "The storage id of the changeset.",
35
- "in": "query",
36
- "required": false,
37
- "schema": {
38
- "type": "string"
39
- },
40
- "example": "12345"
41
- }
42
- ],
43
- "security": [
44
- {
45
- "jwtBearerAuthScheme": []
31
+ "requestBody": {
32
+ "description": "Request a trusted node to perform a sync request for a changeset.",
33
+ "required": true,
34
+ "content": {
35
+ "application/json": {
36
+ "schema": {
37
+ "$ref": "#/components/schemas/SyncChangeSet"
38
+ },
39
+ "examples": {
40
+ "synchronisedStorageSyncChangeSetRequestExample": {
41
+ "value": {
42
+ "id": "0909090909090909090909090909090909090909090909090909090909090909",
43
+ "dateCreated": "2025-05-29T01:00:00.000Z",
44
+ "dateModified": "2025-05-29T01:00:00.000Z",
45
+ "nodeIdentity": "did:entity-storage:0xd2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2",
46
+ "changes": [
47
+ {
48
+ "entity": {
49
+ "dateModified": "2025-01-01T00:00:00.000Z"
50
+ },
51
+ "id": "test-id-1",
52
+ "operation": "set"
53
+ }
54
+ ],
55
+ "proof": {
56
+ "@context": "https://www.w3.org/ns/credentials/v2",
57
+ "created": "2025-05-29T01:00:00.000Z",
58
+ "cryptosuite": "eddsa-jcs-2022",
59
+ "proofPurpose": "assertionMethod",
60
+ "proofValue": "z5efBErQs3YBLZoH7jgKMQaRc9YjAxA5XSYKmW3FmTBDw9WionT2NS2x1SMvcRyBvw53cSSoaCT1xQH9tkWngGCX3",
61
+ "type": "DataIntegrityProof",
62
+ "verificationMethod": "did:entity-storage:0xd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0#synchronised-storage-assertion"
63
+ },
64
+ "storageKey": "test-type"
65
+ }
66
+ }
67
+ }
68
+ }
46
69
  }
47
- ],
70
+ },
48
71
  "responses": {
49
72
  "204": {
50
73
  "description": "The rest request ended in success with no data."
@@ -70,6 +93,100 @@
70
93
  }
71
94
  }
72
95
  },
96
+ "500": {
97
+ "description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
98
+ "content": {
99
+ "application/json": {
100
+ "schema": {
101
+ "$ref": "#/components/schemas/Error"
102
+ },
103
+ "examples": {
104
+ "exampleResponse": {
105
+ "value": {
106
+ "name": "InternalServerError",
107
+ "message": "component.error"
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ },
117
+ "/synchronised-storage/decryption-key": {
118
+ "post": {
119
+ "operationId": "synchronisedStorageGetDecryptionKeyRequest",
120
+ "summary": "Request the decryption key.",
121
+ "tags": [
122
+ "Synchronised Storage"
123
+ ],
124
+ "requestBody": {
125
+ "description": "Request a trusted node to perform a sync request for a changeset.",
126
+ "required": true,
127
+ "content": {
128
+ "application/json": {
129
+ "schema": {
130
+ "$ref": "#/components/schemas/SyncChangeSet"
131
+ },
132
+ "examples": {
133
+ "synchronisedStorageSyncGetDecryptionKeyRequestExample": {
134
+ "value": {
135
+ "nodeIdentity": "did:entity-storage:0xd2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2",
136
+ "proof": {
137
+ "@context": "https://www.w3.org/ns/credentials/v2",
138
+ "created": "2025-05-29T01:00:00.000Z",
139
+ "cryptosuite": "eddsa-jcs-2022",
140
+ "proofPurpose": "assertionMethod",
141
+ "proofValue": "z5efBErQs3YBLZoH7jgKMQaRc9YjAxA5XSYKmW3FmTBDw9WionT2NS2x1SMvcRyBvw53cSSoaCT1xQH9tkWngGCX3",
142
+ "type": "DataIntegrityProof",
143
+ "verificationMethod": "did:entity-storage:0xd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0#synchronised-storage-assertion"
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ }
150
+ },
151
+ "responses": {
152
+ "200": {
153
+ "description": "Response to a request for the decryption key for the synchronised storage.",
154
+ "content": {
155
+ "application/json": {
156
+ "schema": {
157
+ "$ref": "#/components/schemas/SyncDecryptionKeyResponse"
158
+ },
159
+ "examples": {
160
+ "synchronisedStorageSyncGetDecryptionKeyResponseExample": {
161
+ "value": {
162
+ "decryptionKey": "z5efBErQs3YBLZoH7jgKMQaRc9YjAxA5XSYKmW3FmTBDw9WionT2NS2x1SMvcRyBvw53cSSoaCT1xQH9tkWngGCX3"
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+ },
169
+ "400": {
170
+ "description": "The server cannot process the request, see the content for more details.",
171
+ "content": {
172
+ "application/json": {
173
+ "schema": {
174
+ "$ref": "#/components/schemas/Error"
175
+ },
176
+ "examples": {
177
+ "exampleResponse": {
178
+ "value": {
179
+ "name": "GeneralError",
180
+ "message": "component.error",
181
+ "properties": {
182
+ "foo": "bar"
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ },
73
190
  "401": {
74
191
  "description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
75
192
  "content": {
@@ -146,6 +263,117 @@
146
263
  ],
147
264
  "additionalProperties": false,
148
265
  "description": "Model to describe serialized error."
266
+ },
267
+ "SyncChange<SynchronisedEntity>": {
268
+ "type": "object",
269
+ "properties": {
270
+ "operation": {
271
+ "$ref": "#/components/schemas/SyncChangeOperation"
272
+ },
273
+ "id": {
274
+ "type": "string",
275
+ "description": "The item id."
276
+ },
277
+ "entity": {
278
+ "$ref": "#/components/schemas/SynchronisedEntity"
279
+ }
280
+ },
281
+ "required": [
282
+ "operation",
283
+ "id"
284
+ ],
285
+ "additionalProperties": false,
286
+ "description": "The object definition for a sync change."
287
+ },
288
+ "SyncChangeOperation": {
289
+ "anyOf": [
290
+ {
291
+ "type": "string",
292
+ "const": "set",
293
+ "description": "An item was set in the storage."
294
+ },
295
+ {
296
+ "type": "string",
297
+ "const": "delete",
298
+ "description": "An item was deleted from the storage."
299
+ }
300
+ ],
301
+ "description": "The operations for a change. The operations for a change"
302
+ },
303
+ "SyncChangeSet": {
304
+ "type": "object",
305
+ "properties": {
306
+ "id": {
307
+ "type": "string",
308
+ "description": "The id of the change set."
309
+ },
310
+ "dateCreated": {
311
+ "type": "string",
312
+ "description": "The date the change set was created."
313
+ },
314
+ "storageKey": {
315
+ "type": "string",
316
+ "description": "The storage key of the change set. This is used to identify the entities being synchronised."
317
+ },
318
+ "dateModified": {
319
+ "type": "string",
320
+ "description": "The date the change set was last modified."
321
+ },
322
+ "changes": {
323
+ "type": "array",
324
+ "items": false,
325
+ "description": "The changes to apply after a snapshot.",
326
+ "prefixItems": [
327
+ {
328
+ "$ref": "#/components/schemas/SyncChange<SynchronisedEntity>"
329
+ }
330
+ ]
331
+ },
332
+ "nodeIdentity": {
333
+ "type": "string",
334
+ "description": "The identity of the node that created the change set."
335
+ },
336
+ "proof": {
337
+ "$ref": "https://schema.twindev.org/w3c-did/Proof"
338
+ }
339
+ },
340
+ "required": [
341
+ "id",
342
+ "dateCreated",
343
+ "storageKey",
344
+ "dateModified",
345
+ "changes",
346
+ "nodeIdentity"
347
+ ],
348
+ "additionalProperties": false,
349
+ "description": "The object definition for a sync change set."
350
+ },
351
+ "SyncDecryptionKeyResponse": {
352
+ "type": "object",
353
+ "properties": {
354
+ "decryptionKey": {
355
+ "type": "string",
356
+ "description": "The decryption key for the synchronised storage as base64."
357
+ }
358
+ },
359
+ "required": [
360
+ "decryptionKey"
361
+ ],
362
+ "additionalProperties": false,
363
+ "description": "The body of the response."
364
+ },
365
+ "SynchronisedEntity": {
366
+ "type": "object",
367
+ "properties": {
368
+ "dateModified": {
369
+ "type": "string",
370
+ "description": "The date the entry was modified"
371
+ }
372
+ },
373
+ "required": [
374
+ "dateModified"
375
+ ],
376
+ "additionalProperties": false
149
377
  }
150
378
  },
151
379
  "securitySchemes": {
@@ -28,6 +28,14 @@ The id for the snapshot.
28
28
 
29
29
  ***
30
30
 
31
+ ### version
32
+
33
+ > **version**: `string`
34
+
35
+ The version for the snapshot.
36
+
37
+ ***
38
+
31
39
  ### storageKey
32
40
 
33
41
  > **storageKey**: `string`
@@ -44,19 +52,27 @@ The date the snapshot was created.
44
52
 
45
53
  ***
46
54
 
47
- ### dateModified?
55
+ ### dateModified
48
56
 
49
- > `optional` **dateModified**: `string`
57
+ > **dateModified**: `string`
50
58
 
51
59
  The date the snapshot was last modified.
52
60
 
53
61
  ***
54
62
 
55
- ### isLocalSnapshot?
63
+ ### isLocal
64
+
65
+ > **isLocal**: `boolean`
66
+
67
+ The flag to determine if this is the snapshot is the local one containing changes for this node.
68
+
69
+ ***
70
+
71
+ ### isConsolidated
56
72
 
57
- > `optional` **isLocalSnapshot**: `boolean`
73
+ > **isConsolidated**: `boolean`
58
74
 
59
- The flag to determine if this is the current local snapshot containing changes for this node.
75
+ The flag to determine if this is a consolidated snapshot.
60
76
 
61
77
  ***
62
78
 
@@ -70,6 +86,6 @@ The ids of the storage for the change sets in the snapshot, if this is not a loc
70
86
 
71
87
  ### changes?
72
88
 
73
- > `optional` **changes**: [`ISyncChange`](../interfaces/ISyncChange.md)\<`T`\>[]
89
+ > `optional` **changes**: `ISyncChange`\<`T`\>[]
74
90
 
75
91
  The changes that were made in this snapshot, if this is a local snapshot.
@@ -118,19 +118,52 @@ Nothing.
118
118
 
119
119
  ***
120
120
 
121
- ### syncChangeSet()
121
+ ### getDecryptionKey()
122
122
 
123
- > **syncChangeSet**(`changeSetStorageId`): `Promise`\<`void`\>
123
+ > **getDecryptionKey**(`nodeIdentity`, `proof`): `Promise`\<`string`\>
124
124
 
125
- Synchronise a complete set of changes, assumes this is a trusted node.
125
+ Get the decryption key for the synchronised storage.
126
+ This is used to decrypt the data stored in the synchronised storage.
126
127
 
127
128
  #### Parameters
128
129
 
129
- ##### changeSetStorageId
130
+ ##### nodeIdentity
130
131
 
131
132
  `string`
132
133
 
133
- The id of the change set to synchronise in blob storage.
134
+ The identity of the node requesting the decryption key.
135
+
136
+ ##### proof
137
+
138
+ `IProof`
139
+
140
+ The proof of the request so we know the request is from the specified node.
141
+
142
+ #### Returns
143
+
144
+ `Promise`\<`string`\>
145
+
146
+ The decryption key.
147
+
148
+ #### Implementation of
149
+
150
+ `ISynchronisedStorageComponent.getDecryptionKey`
151
+
152
+ ***
153
+
154
+ ### syncChangeSet()
155
+
156
+ > **syncChangeSet**(`syncChangeSet`): `Promise`\<`void`\>
157
+
158
+ Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
159
+
160
+ #### Parameters
161
+
162
+ ##### syncChangeSet
163
+
164
+ `ISyncChangeSet`\<`T`\>
165
+
166
+ The change set to synchronise.
134
167
 
135
168
  #### Returns
136
169
 
@@ -0,0 +1,31 @@
1
+ # Function: synchronisedStorageGetDecryptionKeyRequest()
2
+
3
+ > **synchronisedStorageGetDecryptionKeyRequest**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ISyncDecryptionKeyResponse`\>
4
+
5
+ Request the decryption key.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `ISyncDecryptionKeyRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`ISyncDecryptionKeyResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -7,8 +7,6 @@
7
7
 
8
8
  ## Interfaces
9
9
 
10
- - [ISyncChange](interfaces/ISyncChange.md)
11
- - [ISyncChangeSet](interfaces/ISyncChangeSet.md)
12
10
  - [ISyncPointerStore](interfaces/ISyncPointerStore.md)
13
11
  - [ISyncSnapshot](interfaces/ISyncSnapshot.md)
14
12
  - [ISyncState](interfaces/ISyncState.md)
@@ -25,3 +23,4 @@
25
23
  - [initSchema](functions/initSchema.md)
26
24
  - [generateRestRoutesSynchronisedStorage](functions/generateRestRoutesSynchronisedStorage.md)
27
25
  - [synchronisedStorageSyncChangeSetRequest](functions/synchronisedStorageSyncChangeSetRequest.md)
26
+ - [synchronisedStorageGetDecryptionKeyRequest](functions/synchronisedStorageGetDecryptionKeyRequest.md)
@@ -4,6 +4,14 @@ The object definition for the sync pointer store.
4
4
 
5
5
  ## Properties
6
6
 
7
+ ### version
8
+
9
+ > **version**: `string`
10
+
11
+ The version of the sync pointer store.
12
+
13
+ ***
14
+
7
15
  ### syncPointers
8
16
 
9
17
  > **syncPointers**: `object`
@@ -4,6 +4,14 @@ The object definition for a sync snapshot.
4
4
 
5
5
  ## Properties
6
6
 
7
+ ### version
8
+
9
+ > **version**: `string`
10
+
11
+ The version of the sync state.
12
+
13
+ ***
14
+
7
15
  ### id
8
16
 
9
17
  > **id**: `string`
@@ -20,14 +28,22 @@ The date the snapshot was created.
20
28
 
21
29
  ***
22
30
 
23
- ### dateModified?
31
+ ### dateModified
24
32
 
25
- > `optional` **dateModified**: `string`
33
+ > **dateModified**: `string`
26
34
 
27
35
  The date the snapshot was last modified.
28
36
 
29
37
  ***
30
38
 
39
+ ### isConsolidated
40
+
41
+ > **isConsolidated**: `boolean`
42
+
43
+ Is this a consolidated snapshot?
44
+
45
+ ***
46
+
31
47
  ### changeSetStorageIds
32
48
 
33
49
  > **changeSetStorageIds**: `string`[]
@@ -4,6 +4,22 @@ The object definition for a sync state.
4
4
 
5
5
  ## Properties
6
6
 
7
+ ### version
8
+
9
+ > **version**: `string`
10
+
11
+ The version of the sync state.
12
+
13
+ ***
14
+
15
+ ### storageKey
16
+
17
+ > **storageKey**: `string`
18
+
19
+ The storage type contained in the sync state.
20
+
21
+ ***
22
+
7
23
  ### snapshots
8
24
 
9
25
  > **snapshots**: [`ISyncSnapshot`](ISyncSnapshot.md)[]
@@ -4,20 +4,11 @@ Configuration for the Synchronised Storage Service.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### synchronisedStorageKey
8
-
9
- > **synchronisedStorageKey**: `string`
10
-
11
- The key to use for the remote synchronised storage, the initial item will have been
12
- generated by a trusted node.
13
-
14
- ***
15
-
16
7
  ### synchronisedStorageMethodId?
17
8
 
18
9
  > `optional` **synchronisedStorageMethodId**: `string`
19
10
 
20
- The id of the identity method to use when signing/verifying changesets.
11
+ The id of the identity method to use when signing/verifying requests and changesets.
21
12
 
22
13
  #### Default
23
14
 
@@ -80,3 +71,46 @@ The number of entities to process in a single consolidation batch.
80
71
  ```ts
81
72
  1000
82
73
  ```
74
+
75
+ ***
76
+
77
+ ### maxConsolidations?
78
+
79
+ > `optional` **maxConsolidations**: `number`
80
+
81
+ The maximum number of consolidations to keep in storage.
82
+
83
+ #### Default
84
+
85
+ ```ts
86
+ 5
87
+ ```
88
+
89
+ ***
90
+
91
+ ### blobStorageEncryptionKeyId?
92
+
93
+ > `optional` **blobStorageEncryptionKeyId**: `string`
94
+
95
+ The encryption key id from the vault to use for blob storage, only required for trusted nodes, untrusted nodes will request the key.
96
+
97
+ #### Default
98
+
99
+ ```ts
100
+ synchronised-storage-blob-encryption-key
101
+ ```
102
+
103
+ ***
104
+
105
+ ### verifiableStorageKeyId
106
+
107
+ > **verifiableStorageKeyId**: `string`
108
+
109
+ The verifiable storage key to use, already expected to be created.
110
+ if the key is not found in the keys.json it is considered to be a custom verifiable storage id.
111
+
112
+ #### Default
113
+
114
+ ```ts
115
+ local
116
+ ```
@@ -20,6 +20,14 @@ The event bus component type.
20
20
 
21
21
  ***
22
22
 
23
+ ### vaultConnectorType?
24
+
25
+ > `optional` **vaultConnectorType**: `string`
26
+
27
+ The vault connector type.
28
+
29
+ ***
30
+
23
31
  ### syncSnapshotStorageConnectorType?
24
32
 
25
33
  > `optional` **syncSnapshotStorageConnectorType**: `string`
@@ -34,11 +42,11 @@ sync-snapshot-entry
34
42
 
35
43
  ***
36
44
 
37
- ### blobStorageComponentType?
45
+ ### blobStorageConnectorType?
38
46
 
39
- > `optional` **blobStorageComponentType**: `string`
47
+ > `optional` **blobStorageConnectorType**: `string`
40
48
 
41
- The blob storage component used for remote sync state.
49
+ The blob storage connector used for remote sync state.
42
50
 
43
51
  #### Default
44
52