user 6 tahun lalu
induk
melakukan
260009df8e
4 mengubah file dengan 42 tambahan dan 58 penghapusan
  1. 1 2
      lib/index.d.ts
  2. 20 28
      lib/index.js
  3. 1 1
      lib/index.js.map
  4. 20 27
      src/index.ts

+ 1 - 2
lib/index.d.ts

@@ -24,10 +24,9 @@ export declare class BankClient {
     upload(params: UploadItemParameters): Promise<any>;
     upload(params: UploadItemParameters): Promise<any>;
     uploadSlimJSON(item: any): Promise<any>;
     uploadSlimJSON(item: any): Promise<any>;
     uploadSlimText(item: string): Promise<any>;
     uploadSlimText(item: string): Promise<any>;
-    appendBank(bankAddress: string, bankTopic: string, itemHash: string): Promise<void>;
+    appendPrivate(slim: boolean, peerAddr: string, topic: string, hash?: string, replaceHash?: string, deleteHash?: string): Promise<void>;
     retrievePrivate(peerAddr: string, topic: string): Promise<string>;
     retrievePrivate(peerAddr: string, topic: string): Promise<string>;
     subscribePrivate(peerAddr: string, topic: string, connectCallback: () => void, messageCallback: (data: any) => void): Promise<void>;
     subscribePrivate(peerAddr: string, topic: string, connectCallback: () => void, messageCallback: (data: any) => void): Promise<void>;
-    appendPrivate(peerAddr: string, topic: string, hash?: string, replaceHash?: string, deleteHash?: string): Promise<void>;
     getOrCreateContact(peerId: string, contactAddr: string): Promise<any>;
     getOrCreateContact(peerId: string, contactAddr: string): Promise<any>;
     getContactById(peerId: string, contactId: string): Promise<any>;
     getContactById(peerId: string, contactId: string): Promise<any>;
     updateContact(peerId: string, contactId: string, newProperties: any): Promise<any>;
     updateContact(peerId: string, contactId: string, newProperties: any): Promise<any>;

+ 20 - 28
lib/index.js

@@ -185,15 +185,28 @@ class BankClient {
             return uploadResponse.hash;
             return uploadResponse.hash;
         });
         });
     }
     }
-    appendBank(bankAddress, bankTopic, itemHash) {
+    appendPrivate(slim, peerAddr, topic, hash, replaceHash, deleteHash) {
         return __awaiter(this, void 0, void 0, function* () {
         return __awaiter(this, void 0, void 0, function* () {
-            const payload = yield this.makePlaintextPayload(itemHash);
-            const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(bankAddress) + '/' + encodeURIComponent(bankTopic);
-            yield this.webClient.requestJSON({
-                body: payload,
+            const nonce = yield this.getNonce();
+            const payload = yield this.makePlaintextPayload(JSON.stringify({
+                _date: new Date().toISOString(),
+                _nonce: nonce,
+                deleteHash,
+                hash,
+                replaceHash,
+            }));
+            const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(peerAddr) + '/' + encodeURIComponent(topic);
+            const result = yield this.webClient.request({
+                body: JSON.stringify(payload),
+                headers: {
+                    'content-type': 'application/json'
+                },
                 method: 'PUT',
                 method: 'PUT',
                 url: topicURL
                 url: topicURL
             });
             });
+            if (!slim && topic !== 'all' && !deleteHash) {
+                yield this.appendPrivate(slim, peerAddr, 'all', hash, undefined, undefined);
+            }
         });
         });
     }
     }
     retrievePrivate(peerAddr, topic) {
     retrievePrivate(peerAddr, topic) {
@@ -220,27 +233,6 @@ class BankClient {
             yield this.connectWebsocket(peerAddr, topic, connectCallback, messageCallback);
             yield this.connectWebsocket(peerAddr, topic, connectCallback, messageCallback);
         });
         });
     }
     }
-    appendPrivate(peerAddr, topic, hash, replaceHash, deleteHash) {
-        return __awaiter(this, void 0, void 0, function* () {
-            const nonce = yield this.getNonce();
-            const payload = yield this.makePlaintextPayload(JSON.stringify({
-                _date: new Date().toISOString(),
-                _nonce: nonce,
-                deleteHash,
-                hash,
-                replaceHash,
-            }));
-            const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(peerAddr) + '/' + encodeURIComponent(topic);
-            const result = yield this.webClient.request({
-                body: JSON.stringify(payload),
-                headers: {
-                    'content-type': 'application/json'
-                },
-                method: 'PUT',
-                url: topicURL
-            });
-        });
-    }
     getOrCreateContact(peerId, contactAddr) {
     getOrCreateContact(peerId, contactAddr) {
         return __awaiter(this, void 0, void 0, function* () {
         return __awaiter(this, void 0, void 0, function* () {
             const contactList = yield this.retrievePrivate(peerId, '📇');
             const contactList = yield this.retrievePrivate(peerId, '📇');
@@ -257,7 +249,7 @@ class BankClient {
                 id: util_1.uuid()
                 id: util_1.uuid()
             };
             };
             const newItemHash = yield this.uploadSlimJSON(newItem);
             const newItemHash = yield this.uploadSlimJSON(newItem);
-            yield this.appendPrivate(peerId, '📇', newItemHash);
+            yield this.appendPrivate(true, peerId, '📇', newItemHash);
             return newItem;
             return newItem;
         });
         });
     }
     }
@@ -280,7 +272,7 @@ class BankClient {
             const newItem = util_1.mergeDeep(existing, newProps);
             const newItem = util_1.mergeDeep(existing, newProps);
             delete newItem.hash;
             delete newItem.hash;
             const newItemHash = yield this.uploadSlimJSON(newItem);
             const newItemHash = yield this.uploadSlimJSON(newItem);
-            yield this.appendPrivate(peerId, '📇', newItemHash, existing.hash);
+            yield this.appendPrivate(true, peerId, '📇', newItemHash, existing.hash);
             return yield this.getContactById(peerId, contactId);
             return yield this.getContactById(peerId, contactId);
         });
         });
     }
     }

File diff ditekan karena terlalu besar
+ 1 - 1
lib/index.js.map


+ 20 - 27
src/index.ts

@@ -181,14 +181,27 @@ export class BankClient {
       return uploadResponse.hash;
       return uploadResponse.hash;
     }
     }
 
 
-    public async appendBank(bankAddress: string, bankTopic: string, itemHash: string): Promise<void> {
-      const payload = await this.makePlaintextPayload(itemHash);
-      const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(bankAddress) + '/' + encodeURIComponent(bankTopic);
-      await this.webClient.requestJSON({
-        body: payload,
+    public async appendPrivate(slim: boolean, peerAddr: string, topic: string, hash?: string, replaceHash?: string, deleteHash?: string) {
+      const nonce = await this.getNonce();
+      const payload = await this.makePlaintextPayload(JSON.stringify({
+        _date: new Date().toISOString(),
+        _nonce: nonce,
+        deleteHash,
+        hash,
+        replaceHash,
+      }));
+      const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(peerAddr) + '/' + encodeURIComponent(topic);
+      const result = await this.webClient.request({
+        body: JSON.stringify(payload),
+        headers: {
+          'content-type': 'application/json'
+        },
         method: 'PUT',
         method: 'PUT',
         url: topicURL
         url: topicURL
       });
       });
+      if (!slim && topic !== 'all' && !deleteHash) {
+        await this.appendPrivate(slim, peerAddr, 'all', hash, undefined, undefined);
+      }
     }
     }
 
 
     public async retrievePrivate(peerAddr: string, topic: string) {
     public async retrievePrivate(peerAddr: string, topic: string) {
@@ -214,26 +227,6 @@ export class BankClient {
       await this.connectWebsocket(peerAddr, topic, connectCallback, messageCallback);
       await this.connectWebsocket(peerAddr, topic, connectCallback, messageCallback);
     }
     }
 
 
-    public async appendPrivate(peerAddr: string, topic: string, hash?: string, replaceHash?: string, deleteHash?: string) {
-      const nonce = await this.getNonce();
-      const payload = await this.makePlaintextPayload(JSON.stringify({
-        _date: new Date().toISOString(),
-        _nonce: nonce,
-        deleteHash,
-        hash,
-        replaceHash,
-      }));
-      const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(peerAddr) + '/' + encodeURIComponent(topic);
-      const result = await this.webClient.request({
-        body: JSON.stringify(payload),
-        headers: {
-          'content-type': 'application/json'
-        },
-        method: 'PUT',
-        url: topicURL
-      });
-    }
-
     public async getOrCreateContact(peerId: string, contactAddr: string) {
     public async getOrCreateContact(peerId: string, contactAddr: string) {
       const contactList = await this.retrievePrivate(peerId, '📇');
       const contactList = await this.retrievePrivate(peerId, '📇');
       const itemList = await this.getItemsForCommaList(contactList);
       const itemList = await this.getItemsForCommaList(contactList);
@@ -249,7 +242,7 @@ export class BankClient {
         id: uuid()
         id: uuid()
       };
       };
       const newItemHash = await this.uploadSlimJSON(newItem);
       const newItemHash = await this.uploadSlimJSON(newItem);
-      await this.appendPrivate(peerId, '📇', newItemHash);
+      await this.appendPrivate(true, peerId, '📇', newItemHash);
       return newItem;
       return newItem;
     }
     }
 
 
@@ -270,7 +263,7 @@ export class BankClient {
       const newItem: any = mergeDeep(existing, newProps);
       const newItem: any = mergeDeep(existing, newProps);
       delete newItem.hash;
       delete newItem.hash;
       const newItemHash = await this.uploadSlimJSON(newItem);
       const newItemHash = await this.uploadSlimJSON(newItem);
-      await this.appendPrivate(peerId, '📇', newItemHash, existing.hash);
+      await this.appendPrivate(true, peerId, '📇', newItemHash, existing.hash);
       return await this.getContactById(peerId, contactId);
       return await this.getContactById(peerId, contactId);
     }
     }