@twin.org/synchronised-storage-rest-client 0.0.3-next.2 → 0.0.3-next.3
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.
|
@@ -32,6 +32,7 @@ export class SynchronisedStorageRestClient extends BaseRestClient {
|
|
|
32
32
|
* @returns The decryption key.
|
|
33
33
|
*/
|
|
34
34
|
async getDecryptionKey(trustPayload) {
|
|
35
|
+
Guards.stringValue(SynchronisedStorageRestClient.CLASS_NAME, "trustPayload", trustPayload);
|
|
35
36
|
const response = await this.fetch("/decryption-key", "GET", {
|
|
36
37
|
headers: {
|
|
37
38
|
[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)
|
|
@@ -47,6 +48,7 @@ export class SynchronisedStorageRestClient extends BaseRestClient {
|
|
|
47
48
|
*/
|
|
48
49
|
async syncChangeSet(syncChangeSet, trustPayload) {
|
|
49
50
|
Guards.object(SynchronisedStorageRestClient.CLASS_NAME, "syncChangeSet", syncChangeSet);
|
|
51
|
+
Guards.stringValue(SynchronisedStorageRestClient.CLASS_NAME, "trustPayload", trustPayload);
|
|
50
52
|
await this.fetch("/sync-changeset", "POST", {
|
|
51
53
|
headers: {
|
|
52
54
|
[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)
|
|
@@ -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,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
|
+
{"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,CAAC,WAAW,CACjB,6BAA6B,CAAC,UAAU,kBAExC,YAAY,CACZ,CAAC;QAEF,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,CAAC,WAAW,CACjB,6BAA6B,CAAC,UAAU,kBAExC,YAAY,CACZ,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\tGuards.stringValue(\n\t\t\tSynchronisedStorageRestClient.CLASS_NAME,\n\t\t\tnameof(trustPayload),\n\t\t\ttrustPayload\n\t\t);\n\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\tGuards.stringValue(\n\t\t\tSynchronisedStorageRestClient.CLASS_NAME,\n\t\t\tnameof(trustPayload),\n\t\t\ttrustPayload\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"]}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.3](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.3-next.2...synchronised-storage-rest-client-v0.0.3-next.3) (2026-01-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add trustPayload guards ([cf1622f](https://github.com/twinfoundation/synchronised-storage/commit/cf1622f8b65a4b77032e31ecaa41664499f4c892))
|
|
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.2 to 0.0.3-next.3
|
|
16
|
+
|
|
3
17
|
## [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
18
|
|
|
5
19
|
|
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.3",
|
|
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.3",
|
|
26
26
|
"@twin.org/web": "next"
|
|
27
27
|
},
|
|
28
28
|
"main": "./dist/es/index.js",
|