From ad44f43a0a1118a5ed762d4ef0c7c5eef47a9acc Mon Sep 17 00:00:00 2001 From: chekrd <25004106+chekrd@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:03:11 +0100 Subject: [PATCH] Create schema --- src/customAppSdk.ts | 7 ++++--- src/iframeSchema.ts | 2 +- src/index.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/customAppSdk.ts b/src/customAppSdk.ts index 3c55ce8..7cfd5cd 100644 --- a/src/customAppSdk.ts +++ b/src/customAppSdk.ts @@ -3,10 +3,10 @@ import { ErrorMessage } from './iframeSchema'; import { matchesSchema } from './matchesSchema'; export enum ErrorCode { - Nnn = 'Nnn', + UnknownMessage = 'unknown-message', } -export type InitReturn = +export type InitResponse = | { readonly isError: false; readonly context: { @@ -26,7 +26,7 @@ export type InitReturn = readonly description: string; }; -export const initCustomApp = (): Promise => { +export const initCustomApp = (): Promise => { const stopListening = startListening(); return new Promise((resolve, reject) => { @@ -38,6 +38,7 @@ export const initCustomApp = (): Promise => { payload: null, }, (response) => { + if (matchesSchema(ErrorMessage, response)) { resolve({ isError: true, code: response.code, description: response.description }); } else { diff --git a/src/iframeSchema.ts b/src/iframeSchema.ts index b2f076a..76d20e2 100644 --- a/src/iframeSchema.ts +++ b/src/iframeSchema.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; enum ErrorCode { - Nnn = 'Nnn', + UnknownMessage = 'unknown-message', } export const ErrorMessage = z diff --git a/src/index.ts b/src/index.ts index a831eac..88392ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ export { initCustomApp } from './customAppSdk'; -export { InitReturn } from './customAppSdk'; +export { InitResponse } from './customAppSdk';