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' diff --git a/src/agent.ts b/src/agent.ts index 7d84b2908..bf8dd2500 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) { + this.interactionManager.emit('interactionResumed', interxn) } return interxn 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/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 } /** diff --git a/src/transports.ts b/src/transports.ts index 8264dd0ef..17e1d73fe 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,22 @@ export class TransportKeeper { } } - public register( - typeName: string, - handler: TransportHandler - ) { + 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) + + transportHandler.subscribe(onMessage) + } + + public register(typeName: string, handler: TransportHandler) { this._transportHandlers[typeName] = handler } @@ -49,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 diff --git a/src/types.ts b/src/types.ts index 4ccb1fbd1..b8fdb290f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,13 +47,17 @@ export interface TransportDesc { /** * @category Transports */ -export type TransportMessageHandler = (msg: string) => Promise +export type TransportMessageHandler = ( + msg: string, + error?: Error, +) => Promise /** * @category Transports */ export interface TransportHandler { configure?(...args: any[]): void + subscribe?(onMessage: TransportMessageHandler): void start(d: TransportDesc, cb?: TransportMessageHandler): TransportAPI }