diff --git a/packages/sample-server/src/app.ts b/packages/sample-server/src/app.ts index 04863e3..697b75d 100644 --- a/packages/sample-server/src/app.ts +++ b/packages/sample-server/src/app.ts @@ -1,16 +1,18 @@ import fastify, { FastifyInstance, FastifyServerOptions } from "fastify"; import autoload from "@fastify/autoload"; import path from "path"; -import { userSchema } from "./schemas/user"; -import { errorSchema } from "./schemas/error"; +import { errorSchema } from "./schemas/errorSchema"; import vclSdkPlugin from "./plugins/vclSdkPlugin"; +import { presentationRequestSchema } from "./schemas/presentationRequestSchema"; +import { deepLinkSchema } from "./schemas/deepLinkSchema"; interface buildOpts extends FastifyServerOptions {} const build = (opts: buildOpts = {}): FastifyInstance => { const app = fastify(opts); // add in common schemas - app.addSchema(userSchema); + app.addSchema(deepLinkSchema); + app.addSchema(presentationRequestSchema); app.addSchema(errorSchema); app.register(autoload, { diff --git a/packages/sample-server/src/global.d.ts b/packages/sample-server/src/global.d.ts new file mode 100644 index 0000000..4c6f946 --- /dev/null +++ b/packages/sample-server/src/global.d.ts @@ -0,0 +1,22 @@ +declare global { +// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars + interface String { + getQueryParameters(): Map; + appendQueryParams(queryParams: string): string; + getUrlSubPath(subPathPrefix: string): string | null | undefined; + randomString(length: number): string; + } + +// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars + interface Array { + toJsonArray(): any[]; + } + +// eslint-disable-next-line unused-imports/no-unused-vars + interface Date { + addDaysToNow(days: number): Date; + equalsTo(date: Date): boolean; + } +} + +export {}; \ No newline at end of file diff --git a/packages/sample-server/src/plugins/vclSdkPlugin.ts b/packages/sample-server/src/plugins/vclSdkPlugin.ts index f99a961..5cb75bd 100644 --- a/packages/sample-server/src/plugins/vclSdkPlugin.ts +++ b/packages/sample-server/src/plugins/vclSdkPlugin.ts @@ -22,7 +22,7 @@ import { import { CurrentEnvironment, XVnfProtocolVersion } from "../global-config"; const vclSdkPlugin: FastifyPluginAsync | FastifyPluginCallback = async ( - fastify + fastify, ) => { const vclSdk = VCLProvider.getInstance(); @@ -36,7 +36,7 @@ const vclSdkPlugin: FastifyPluginAsync | FastifyPluginCallback = async ( ) ); try { - await vclSdk.initialize(initializationDescriptor); + // await vclSdk.initialize(initializationDescriptor); } catch (e) { console.error('Failed to initialize VCL SDK', e); throw e; diff --git a/packages/sample-server/src/routes/getPresentationRequest.ts b/packages/sample-server/src/routes/getPresentationRequest.ts index c7af293..9497999 100644 --- a/packages/sample-server/src/routes/getPresentationRequest.ts +++ b/packages/sample-server/src/routes/getPresentationRequest.ts @@ -6,9 +6,8 @@ */ import { FastifyInstance } from "fastify"; import { FromSchema } from "json-schema-to-ts"; -import { presentationRequestSchema } from "../schemas/presentationRequestSchema"; import { getPresentationRequest } from "../controllers/getPresentationRequest"; -import { deepLinkSchema } from "../schemas/deepLinkSchema"; +import { presentationRequestSchema, deepLinkSchema } from "../schemas/schemas"; interface getPresentationRequestInterface { Params: FromSchema; @@ -24,7 +23,6 @@ export default async function routes(fastify: FastifyInstance) { params: deepLinkSchema, response: { 200: presentationRequestSchema, - "4xx": { $ref: "errorSchema#" }, }, }, }, diff --git a/packages/sample-server/src/schemas/deepLinkSchema.ts b/packages/sample-server/src/schemas/deepLinkSchema.ts index 1043fdb..ea1dd25 100644 --- a/packages/sample-server/src/schemas/deepLinkSchema.ts +++ b/packages/sample-server/src/schemas/deepLinkSchema.ts @@ -5,14 +5,17 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { JSONSchema7TypeName } from 'json-schema'; + export const deepLinkSchema = { - type: "object", + $id: "deepLinkSchema", + type: "object" as JSONSchema7TypeName, properties: { deepLink: { - type: "object", + type: "object" as JSONSchema7TypeName, properties: { - value: { type: "string" }, + value: { type: "string" as JSONSchema7TypeName }, }, }, }, -}; \ No newline at end of file +} as const; \ No newline at end of file diff --git a/packages/sample-server/src/schemas/error.ts b/packages/sample-server/src/schemas/errorSchema.ts similarity index 100% rename from packages/sample-server/src/schemas/error.ts rename to packages/sample-server/src/schemas/errorSchema.ts diff --git a/packages/sample-server/src/schemas/presentationRequestSchema.ts b/packages/sample-server/src/schemas/presentationRequestSchema.ts index 84c654c..e97c01a 100644 --- a/packages/sample-server/src/schemas/presentationRequestSchema.ts +++ b/packages/sample-server/src/schemas/presentationRequestSchema.ts @@ -4,7 +4,10 @@ * Copyright 2022 Velocity Career Labs inc. * SPDX-License-Identifier: Apache-2.0 */ +import { JSONSchema7TypeName } from 'json-schema'; export const presentationRequestSchema = { - $id: "presentationRequestSchema" -}; + $id: "presentationRequestSchema", + type: "object" as JSONSchema7TypeName, + // define the properties of the object here +} as const; diff --git a/packages/sample-server/src/schemas/schemas.ts b/packages/sample-server/src/schemas/schemas.ts new file mode 100644 index 0000000..f74ad1c --- /dev/null +++ b/packages/sample-server/src/schemas/schemas.ts @@ -0,0 +1,12 @@ +/** + * Created by Michael Avoyan on 30/06/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { errorSchema } from "./errorSchema"; +import { deepLinkSchema } from "./deepLinkSchema"; +import { presentationRequestSchema } from "./presentationRequestSchema"; + +export { errorSchema, deepLinkSchema, presentationRequestSchema }; \ No newline at end of file diff --git a/packages/sample-server/src/schemas/user.ts b/packages/sample-server/src/schemas/user.ts deleted file mode 100644 index 4e18763..0000000 --- a/packages/sample-server/src/schemas/user.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const userSchema = { - $id: "userSchema", - type: "object", - properties: { - id: { type: "string" }, - firstName: { type: "string" }, - lastName: { type: "string" }, - }, - required: ["id", "firstName"], -} as const; diff --git a/packages/sample-server/src/server.ts b/packages/sample-server/src/server.ts index ceabdb2..e0bc8af 100644 --- a/packages/sample-server/src/server.ts +++ b/packages/sample-server/src/server.ts @@ -15,6 +15,7 @@ const devLogger = { const app: FastifyInstance = build({ logger: config.nodeEnv === 'development' ? devLogger : true, + pluginTimeout: 0, }); app.listen({port: 8080, host: "0.0.0.0"}, (err, address) => { diff --git a/packages/sample-server/tsconfig.json b/packages/sample-server/tsconfig.json index a6d7b33..054b168 100644 --- a/packages/sample-server/tsconfig.json +++ b/packages/sample-server/tsconfig.json @@ -10,6 +10,8 @@ "sourceMap": true, "strict": true, "lib": ["ES6", "ES2022"], + "target": "ES6", + "moduleResolution": "node16", "noImplicitAny": false, }, "include": [ diff --git a/packages/sdk/tsconfig.json b/packages/sdk/tsconfig.json index ad083c2..8cdd478 100644 --- a/packages/sdk/tsconfig.json +++ b/packages/sdk/tsconfig.json @@ -12,17 +12,17 @@ "allowJs": true, "resolveJsonModule": true, "noImplicitAny": true, - "moduleResolution": "node", "sourceMap": true, "strict": true, "lib": ["ES6", "ES2022"], + "target": "ES6", + "moduleResolution": "node16", "downlevelIteration": true, - "target": "ES5", "declaration": true, "baseUrl": "./", "paths": { "": ["./src/"] - }, + } }, "include": [ "./src/**/*"