Skip to content

Commit

Permalink
fix schemas, tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavoyan committed Jun 30, 2024
1 parent e765800 commit b46a4aa
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 27 deletions.
8 changes: 5 additions & 3 deletions packages/sample-server/src/app.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down
22 changes: 22 additions & 0 deletions packages/sample-server/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare global {
// eslint-disable-next-line unused-imports/no-unused-vars,no-unused-vars
interface String {
getQueryParameters(): Map<string, string>;
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<T> {
toJsonArray(): any[];
}

// eslint-disable-next-line unused-imports/no-unused-vars
interface Date {
addDaysToNow(days: number): Date;
equalsTo(date: Date): boolean;
}
}

export {};
4 changes: 2 additions & 2 deletions packages/sample-server/src/plugins/vclSdkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { CurrentEnvironment, XVnfProtocolVersion } from "../global-config";

const vclSdkPlugin: FastifyPluginAsync | FastifyPluginCallback = async (
fastify
fastify,
) => {
const vclSdk = VCLProvider.getInstance();

Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions packages/sample-server/src/routes/getPresentationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof presentationRequestSchema>;
Expand All @@ -24,7 +23,6 @@ export default async function routes(fastify: FastifyInstance) {
params: deepLinkSchema,
response: {
200: presentationRequestSchema,
"4xx": { $ref: "errorSchema#" },
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions packages/sample-server/src/schemas/deepLinkSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
},
},
};
} as const;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 12 additions & 0 deletions packages/sample-server/src/schemas/schemas.ts
Original file line number Diff line number Diff line change
@@ -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 };
10 changes: 0 additions & 10 deletions packages/sample-server/src/schemas/user.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/sample-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const devLogger = {

const app: FastifyInstance<Server, IncomingMessage, ServerResponse> = build({
logger: config.nodeEnv === 'development' ? devLogger : true,
pluginTimeout: 0,
});

app.listen({port: 8080, host: "0.0.0.0"}, (err, address) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/sample-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"sourceMap": true,
"strict": true,
"lib": ["ES6", "ES2022"],
"target": "ES6",
"moduleResolution": "node16",
"noImplicitAny": false,
},
"include": [
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*"
Expand Down

0 comments on commit b46a4aa

Please sign in to comment.