@twin.org/synchronised-storage-rest-client 0.0.3-next.1 → 0.0.3-next.2
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/dist/es/synchronisedStorageRestClient.js +11 -17
- package/dist/es/synchronisedStorageRestClient.js.map +1 -1
- package/dist/types/synchronisedStorageRestClient.d.ts +4 -5
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/SynchronisedStorageRestClient.md +8 -8
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
4
|
-
import { ContextIdKeys } from "@twin.org/context";
|
|
5
4
|
import { Guards } from "@twin.org/core";
|
|
5
|
+
import { HeaderHelper, HeaderTypes } from "@twin.org/web";
|
|
6
6
|
/**
|
|
7
7
|
* Client for performing synchronised storage through to REST endpoints.
|
|
8
8
|
*/
|
|
@@ -28,16 +28,13 @@ export class SynchronisedStorageRestClient extends BaseRestClient {
|
|
|
28
28
|
/**
|
|
29
29
|
* Get the decryption key for the synchronised storage.
|
|
30
30
|
* This is used to decrypt the data stored in the synchronised storage.
|
|
31
|
-
* @param
|
|
31
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
32
32
|
* @returns The decryption key.
|
|
33
33
|
*/
|
|
34
|
-
async getDecryptionKey(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
authenticationData: {
|
|
39
|
-
contextId: ContextIdKeys.Organization,
|
|
40
|
-
subject: actionRequest
|
|
34
|
+
async getDecryptionKey(trustPayload) {
|
|
35
|
+
const response = await this.fetch("/decryption-key", "GET", {
|
|
36
|
+
headers: {
|
|
37
|
+
[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)
|
|
41
38
|
}
|
|
42
39
|
});
|
|
43
40
|
return response.body.decryptionKey;
|
|
@@ -45,19 +42,16 @@ export class SynchronisedStorageRestClient extends BaseRestClient {
|
|
|
45
42
|
/**
|
|
46
43
|
* Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
47
44
|
* @param syncChangeSet The change set to synchronise.
|
|
48
|
-
* @param
|
|
45
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
49
46
|
* @returns Nothing.
|
|
50
47
|
*/
|
|
51
|
-
async syncChangeSet(syncChangeSet,
|
|
48
|
+
async syncChangeSet(syncChangeSet, trustPayload) {
|
|
52
49
|
Guards.object(SynchronisedStorageRestClient.CLASS_NAME, "syncChangeSet", syncChangeSet);
|
|
53
50
|
await this.fetch("/sync-changeset", "POST", {
|
|
51
|
+
headers: {
|
|
52
|
+
[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)
|
|
53
|
+
},
|
|
54
54
|
body: syncChangeSet
|
|
55
|
-
}, {
|
|
56
|
-
authenticationGeneratorType: "verifiable-credential",
|
|
57
|
-
authenticationData: {
|
|
58
|
-
contextId: ContextIdKeys.Organization,
|
|
59
|
-
subject: actionRequest
|
|
60
|
-
}
|
|
61
55
|
});
|
|
62
56
|
}
|
|
63
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisedStorageRestClient.js","sourceRoot":"","sources":["../../src/synchronisedStorageRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"synchronisedStorageRestClient.js","sourceRoot":"","sources":["../../src/synchronisedStorageRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AASxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,6BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,mCAAmD;IAEpF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACjF,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,6BAA6B,CAAC,UAAU,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,gBAAgB,CAAC,YAAqB;QAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAChC,iBAAiB,EACjB,KAAK,EACL;YACC,OAAO,EAAE;gBACR,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC;aACpE;SACD,CACD,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,aAA6B,EAAE,YAAqB;QAC9E,MAAM,CAAC,MAAM,CACZ,6BAA6B,CAAC,UAAU,mBAExC,aAAa,CACb,CAAC;QAEF,MAAM,IAAI,CAAC,KAAK,CAA4C,iBAAiB,EAAE,MAAM,EAAE;YACtF,OAAO,EAAE;gBACR,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC;aACpE;YACD,IAAI,EAAE,aAAa;SACnB,CAAC,CAAC;IACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type { IBaseRestClientConfig, INoContentResponse } from \"@twin.org/api-models\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type {\n\tISyncChangeSet,\n\tISyncChangeSetRequest,\n\tISyncDecryptionKeyRequest,\n\tISyncDecryptionKeyResponse,\n\tISynchronisedStorageComponent\n} from \"@twin.org/synchronised-storage-models\";\nimport { HeaderHelper, HeaderTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing synchronised storage through to REST endpoints.\n */\nexport class SynchronisedStorageRestClient\n\textends BaseRestClient\n\timplements ISynchronisedStorageComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<SynchronisedStorageRestClient>();\n\n\t/**\n\t * Create a new instance of SynchronisedStorageRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(SynchronisedStorageRestClient.CLASS_NAME, config, \"synchronised-storage\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn SynchronisedStorageRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the decryption key for the synchronised storage.\n\t * This is used to decrypt the data stored in the synchronised storage.\n\t * @param trustPayload Trust payload to verify the requesters identity.\n\t * @returns The decryption key.\n\t */\n\tpublic async getDecryptionKey(trustPayload: unknown): Promise<string> {\n\t\tconst response = await this.fetch<ISyncDecryptionKeyRequest, ISyncDecryptionKeyResponse>(\n\t\t\t\"/decryption-key\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body.decryptionKey;\n\t}\n\n\t/**\n\t * Synchronise a set of changes from an untrusted node, assumes this is a trusted node.\n\t * @param syncChangeSet The change set to synchronise.\n\t * @param trustPayload Trust payload to verify the requesters identity.\n\t * @returns Nothing.\n\t */\n\tpublic async syncChangeSet(syncChangeSet: ISyncChangeSet, trustPayload: unknown): Promise<void> {\n\t\tGuards.object<ISyncChangeSet>(\n\t\t\tSynchronisedStorageRestClient.CLASS_NAME,\n\t\t\tnameof(syncChangeSet),\n\t\t\tsyncChangeSet\n\t\t);\n\n\t\tawait this.fetch<ISyncChangeSetRequest, INoContentResponse>(\"/sync-changeset\", \"POST\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)\n\t\t\t},\n\t\t\tbody: syncChangeSet\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
2
|
import type { IBaseRestClientConfig } from "@twin.org/api-models";
|
|
3
|
-
import type { IIdentityAuthenticationActionRequest } from "@twin.org/identity-authentication";
|
|
4
3
|
import type { ISyncChangeSet, ISynchronisedStorageComponent } from "@twin.org/synchronised-storage-models";
|
|
5
4
|
/**
|
|
6
5
|
* Client for performing synchronised storage through to REST endpoints.
|
|
@@ -23,15 +22,15 @@ export declare class SynchronisedStorageRestClient extends BaseRestClient implem
|
|
|
23
22
|
/**
|
|
24
23
|
* Get the decryption key for the synchronised storage.
|
|
25
24
|
* This is used to decrypt the data stored in the synchronised storage.
|
|
26
|
-
* @param
|
|
25
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
27
26
|
* @returns The decryption key.
|
|
28
27
|
*/
|
|
29
|
-
getDecryptionKey(
|
|
28
|
+
getDecryptionKey(trustPayload: unknown): Promise<string>;
|
|
30
29
|
/**
|
|
31
30
|
* Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
32
31
|
* @param syncChangeSet The change set to synchronise.
|
|
33
|
-
* @param
|
|
32
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
34
33
|
* @returns Nothing.
|
|
35
34
|
*/
|
|
36
|
-
syncChangeSet(syncChangeSet: ISyncChangeSet,
|
|
35
|
+
syncChangeSet(syncChangeSet: ISyncChangeSet, trustPayload: unknown): Promise<void>;
|
|
37
36
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.2](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.3-next.1...synchronised-storage-rest-client-v0.0.3-next.2) (2025-12-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* use trust component ([424f0d6](https://github.com/twinfoundation/synchronised-storage/commit/424f0d6aaacfdc7700c46fe6c2def23b2eacddc9))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.1](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.3-next.0...synchronised-storage-rest-client-v0.0.3-next.1) (2025-11-12)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -64,18 +64,18 @@ The class name of the component.
|
|
|
64
64
|
|
|
65
65
|
### getDecryptionKey()
|
|
66
66
|
|
|
67
|
-
> **getDecryptionKey**(`
|
|
67
|
+
> **getDecryptionKey**(`trustPayload`): `Promise`\<`string`\>
|
|
68
68
|
|
|
69
69
|
Get the decryption key for the synchronised storage.
|
|
70
70
|
This is used to decrypt the data stored in the synchronised storage.
|
|
71
71
|
|
|
72
72
|
#### Parameters
|
|
73
73
|
|
|
74
|
-
#####
|
|
74
|
+
##### trustPayload
|
|
75
75
|
|
|
76
|
-
`
|
|
76
|
+
`unknown`
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Trust payload to verify the requesters identity.
|
|
79
79
|
|
|
80
80
|
#### Returns
|
|
81
81
|
|
|
@@ -91,7 +91,7 @@ The decryption key.
|
|
|
91
91
|
|
|
92
92
|
### syncChangeSet()
|
|
93
93
|
|
|
94
|
-
> **syncChangeSet**(`syncChangeSet`, `
|
|
94
|
+
> **syncChangeSet**(`syncChangeSet`, `trustPayload`): `Promise`\<`void`\>
|
|
95
95
|
|
|
96
96
|
Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
97
97
|
|
|
@@ -103,11 +103,11 @@ Synchronise a set of changes from an untrusted node, assumes this is a trusted n
|
|
|
103
103
|
|
|
104
104
|
The change set to synchronise.
|
|
105
105
|
|
|
106
|
-
#####
|
|
106
|
+
##### trustPayload
|
|
107
107
|
|
|
108
|
-
`
|
|
108
|
+
`unknown`
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Trust payload to verify the requesters identity.
|
|
111
111
|
|
|
112
112
|
#### Returns
|
|
113
113
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/synchronised-storage-rest-client",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.2",
|
|
4
4
|
"description": "Synchronised storage contract implementation which can connect to REST endpoints",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@twin.org/identity-authentication": "next",
|
|
23
23
|
"@twin.org/nameof": "next",
|
|
24
24
|
"@twin.org/standards-w3c-did": "next",
|
|
25
|
-
"@twin.org/synchronised-storage-models": "0.0.3-next.
|
|
25
|
+
"@twin.org/synchronised-storage-models": "0.0.3-next.2",
|
|
26
26
|
"@twin.org/web": "next"
|
|
27
27
|
},
|
|
28
28
|
"main": "./dist/es/index.js",
|