From 03e1d80d1607cf1cc58dbe50e682bb5c12dd95b4 Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Mon, 13 Sep 2021 11:27:26 +0200 Subject: [PATCH 1/9] feat(interaction): push message only if it hasn't been processed before --- src/interactionManager/interaction.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interactionManager/interaction.ts b/src/interactionManager/interaction.ts index 4b3a132b4..09baa04f9 100644 --- a/src/interactionManager/interaction.ts +++ b/src/interactionManager/interaction.ts @@ -488,7 +488,11 @@ export class Interaction< token.interactionToken, token.interactionType, ) - this.messages.push(token) + if ( + this.messages.find(msg => msg.interactionType === token.interactionType) + ) { + this.messages.push(token) + } if (!fromStorage) { const eventName = From 3569dee6439447890b1772d044d7fbc06fa1de9e Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Mon, 13 Sep 2021 11:28:13 +0200 Subject: [PATCH 2/9] feat(agent): allow the repeated processing of the same token --- src/agent.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/agent.ts b/src/agent.ts index 7d84b2908..c0f3e4f92 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -378,6 +378,8 @@ export class Agent { // JWTs await interxn.processInteractionToken(token) await this.storage.store.interactionToken(token) + } else if (interxn.lastMessage.encode() === jwt) { + await interxn._processToken(token) } return interxn From 49a385691396ebd8e6e77ef12b408be60133042c Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Mon, 13 Sep 2021 11:29:27 +0200 Subject: [PATCH 3/9] feat(transport): added message error handler cb --- src/types.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 4ccb1fbd1..9b83e80d1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -48,13 +48,18 @@ export interface TransportDesc { * @category Transports */ export type TransportMessageHandler = (msg: string) => Promise +export type TransportMessageErrorHandler = (err: Error) => void /** * @category Transports */ export interface TransportHandler { configure?(...args: any[]): void - start(d: TransportDesc, cb?: TransportMessageHandler): TransportAPI + start( + d: TransportDesc, + cb?: TransportMessageHandler, + err?: TransportMessageErrorHandler, + ): TransportAPI } /** From 02a6a77ef593063b7f4aac22bf6edd6679185b13 Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Tue, 14 Sep 2021 10:15:14 +0200 Subject: [PATCH 4/9] fix(interactions): message push condition --- src/agent.ts | 1 + src/interactionManager/interaction.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/agent.ts b/src/agent.ts index c0f3e4f92..6bcbd9aa8 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -379,6 +379,7 @@ export class Agent { await interxn.processInteractionToken(token) await this.storage.store.interactionToken(token) } else if (interxn.lastMessage.encode() === jwt) { + // @ts-ignore await interxn._processToken(token) } diff --git a/src/interactionManager/interaction.ts b/src/interactionManager/interaction.ts index 09baa04f9..2f8efbc43 100644 --- a/src/interactionManager/interaction.ts +++ b/src/interactionManager/interaction.ts @@ -489,7 +489,7 @@ export class Interaction< token.interactionType, ) if ( - this.messages.find(msg => msg.interactionType === token.interactionType) + !this.messages.find(msg => msg.interactionType === token.interactionType) ) { this.messages.push(token) } From 248a7751a15370caa8a83a0585121d972939b20e Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Wed, 22 Sep 2021 11:19:58 +0200 Subject: [PATCH 5/9] fix(tests): dont check for message presence due to auth token --- src/interactionManager/interaction.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/interactionManager/interaction.ts b/src/interactionManager/interaction.ts index 2f8efbc43..4b3a132b4 100644 --- a/src/interactionManager/interaction.ts +++ b/src/interactionManager/interaction.ts @@ -488,11 +488,7 @@ export class Interaction< token.interactionToken, token.interactionType, ) - if ( - !this.messages.find(msg => msg.interactionType === token.interactionType) - ) { - this.messages.push(token) - } + this.messages.push(token) if (!fromStorage) { const eventName = From 628e5601e68cf1a0d83b589393e63c3cdd88fbdb Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Wed, 22 Sep 2021 12:01:43 +0200 Subject: [PATCH 6/9] feat(transport): added subscribe method --- src/errors.ts | 1 + src/transports.ts | 22 ++++++++++++++++------ src/types.ts | 13 ++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index e70932fd3..f54941134 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -4,6 +4,7 @@ export enum ErrorCode { SaveExternalCredentialFailed = 'SaveExtCred', SaveCredentialMetadataFailed = 'SaveCredMetadata', TransportNotSupported = 'UnsuportedTransport', + TransportSubscriptionNotSuported = 'TransportSubscriptionNotSuported', TokenExpired = 'TokenExpired', InvalidSignature = 'InvalidSignature', diff --git a/src/transports.ts b/src/transports.ts index 8264dd0ef..9ccd4127a 100644 --- a/src/transports.ts +++ b/src/transports.ts @@ -1,6 +1,11 @@ import { SDKError, ErrorCode } from './errors' import { HTTPTransport } from './http' -import { TransportHandler, TransportDesc, TransportMessageHandler, TransportAPI } from './types' +import { + TransportHandler, + TransportDesc, + TransportMessageHandler, + TransportAPI, +} from './types' import { WebSocketTransport } from './websocket' export class Transportable { @@ -18,7 +23,6 @@ export class Transportable { set transportAPI(api: TransportAPI) { this._transportAPI = api } - } export class TransportKeeper { @@ -36,10 +40,16 @@ export class TransportKeeper { } } - public register( - typeName: string, - handler: TransportHandler - ) { + public subscribe(typeName: string, onMessage: TransportMessageHandler) { + const transportHandler = this._transportHandlers[typeName] + if (!transportHandler) throw new SDKError(ErrorCode.TransportNotSupported) + if (!transportHandler.subscribe) + throw new SDKError(ErrorCode.TransportSubscriptionNotSuported) + + transportHandler.subscribe(onMessage) + } + + public register(typeName: string, handler: TransportHandler) { this._transportHandlers[typeName] = handler } diff --git a/src/types.ts b/src/types.ts index 9b83e80d1..b8fdb290f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,19 +47,18 @@ export interface TransportDesc { /** * @category Transports */ -export type TransportMessageHandler = (msg: string) => Promise -export type TransportMessageErrorHandler = (err: Error) => void +export type TransportMessageHandler = ( + msg: string, + error?: Error, +) => Promise /** * @category Transports */ export interface TransportHandler { configure?(...args: any[]): void - start( - d: TransportDesc, - cb?: TransportMessageHandler, - err?: TransportMessageErrorHandler, - ): TransportAPI + subscribe?(onMessage: TransportMessageHandler): void + start(d: TransportDesc, cb?: TransportMessageHandler): TransportAPI } /** From 0fab42e783535d4d112068ad562053aaf6b9a566 Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Thu, 23 Sep 2021 14:42:19 +0200 Subject: [PATCH 7/9] feat(interactions): emitting interactionResume event on repeated tokens --- src/agent.ts | 3 +-- src/interactionManager/interactionManager.ts | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent.ts b/src/agent.ts index 6bcbd9aa8..bf8dd2500 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -379,8 +379,7 @@ export class Agent { await interxn.processInteractionToken(token) await this.storage.store.interactionToken(token) } else if (interxn.lastMessage.encode() === jwt) { - // @ts-ignore - await interxn._processToken(token) + this.interactionManager.emit('interactionResumed', interxn) } return interxn diff --git a/src/interactionManager/interactionManager.ts b/src/interactionManager/interactionManager.ts index f07ba157e..7f9c7047c 100644 --- a/src/interactionManager/interactionManager.ts +++ b/src/interactionManager/interactionManager.ts @@ -16,6 +16,7 @@ flows.forEach((f) => { export interface InteractionEvents { interactionCreated: (interxn: Interaction) => void interactionUpdated: (interxn: Interaction) => void + interactionResumed: (interxn: Interaction) => void } /** From ceba4312c77d7022af098a7577ce777a88556c5c Mon Sep 17 00:00:00 2001 From: Cristian Lungu Date: Fri, 24 Sep 2021 13:31:46 +0200 Subject: [PATCH 8/9] ref(transport): abstracted getTransportHandler --- src/transports.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/transports.ts b/src/transports.ts index 9ccd4127a..17e1d73fe 100644 --- a/src/transports.ts +++ b/src/transports.ts @@ -40,9 +40,15 @@ export class TransportKeeper { } } - public subscribe(typeName: string, onMessage: TransportMessageHandler) { + private getTransportHandler(typeName: string) { const transportHandler = this._transportHandlers[typeName] if (!transportHandler) throw new SDKError(ErrorCode.TransportNotSupported) + + return transportHandler + } + + public subscribe(typeName: string, onMessage: TransportMessageHandler) { + const transportHandler = this.getTransportHandler(typeName) if (!transportHandler.subscribe) throw new SDKError(ErrorCode.TransportSubscriptionNotSuported) @@ -59,11 +65,9 @@ export class TransportKeeper { */ public async start( transport: TransportDesc, - onMessage?: TransportMessageHandler + onMessage?: TransportMessageHandler, ): Promise { - const transportHandler = this._transportHandlers[transport.type] - if (!transportHandler) throw new SDKError(ErrorCode.TransportNotSupported) - + const transportHandler = this.getTransportHandler(transport.type) const transportAPI = transportHandler.start(transport, onMessage) transportAPI.desc = transport return transportAPI From b209f865b7c9769cfc3bc367cbd2cb5968e0555a Mon Sep 17 00:00:00 2001 From: SBub Date: Mon, 27 Sep 2021 17:58:19 +0200 Subject: [PATCH 9/9] chore(workflow): action to create pr in rnj --- .github/workflows/create-pr.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/create-pr.yml diff --git a/.github/workflows/create-pr.yml b/.github/workflows/create-pr.yml new file mode 100644 index 000000000..e85d54913 --- /dev/null +++ b/.github/workflows/create-pr.yml @@ -0,0 +1,23 @@ +name: 'Creating PR in "react-native-jolocom" repo' +on: + push: + branches: + - master + +jobs: + pull-request: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Create pull request + uses: SBub/create-outside-pr@v1.0.0 + + env: + API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} + with: + destination_repo: 'jolocom/react-native-jolocom' + destination_base_branch: 'master' + user_name: 'SBub' + user_email: 'svetaibuben@gmail.com'