Skip to content

Commit

Permalink
Merge pull request #100 from velocitycareerlabs/VL-8115-nodejs-sample…
Browse files Browse the repository at this point in the history
…-app-3

cont
  • Loading branch information
michaelavoyan authored Jul 6, 2024
2 parents fd08d2f + 31a5aef commit af7d1ff
Show file tree
Hide file tree
Showing 31 changed files with 610 additions and 44 deletions.
25 changes: 25 additions & 0 deletions packages/sample-server/src/controllers/checkForOffers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Created by Michael Avoyan on 04/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/

import { generateOffersDescriptorFromJson, tokenFromString } from "../utils/Converter";

export async function checkForOffers(req, reply) {
try {
const offers = await req.vclSdk.checkForOffers(
generateOffersDescriptorFromJson(req.body),
tokenFromString(req.body.sessionToken.value)
);
reply.send(offers);
} catch (e: any) {
reply.code(500).send({
statusCode: "500",
error: "Failed to check offers",
message: e.message ?? e.stack ?? JSON.stringify(e),
errorCode: e.errorCode,
});
}
}
23 changes: 23 additions & 0 deletions packages/sample-server/src/controllers/generateOffers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Created by Michael Avoyan on 04/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { generateOffersDescriptorFromJson } from "../utils/Converter";

export async function generateOffers(req, reply) {
try {
const offers = await req.vclSdk.generateOffers(
generateOffersDescriptorFromJson(req.body),
);
reply.send(offers);
} catch (e: any) {
reply.code(500).send({
statusCode: "500",
error: "Failed to generate offers",
message: e.message ?? e.stack ?? JSON.stringify(e),
errorCode: e.errorCode,
});
}
}
26 changes: 26 additions & 0 deletions packages/sample-server/src/controllers/getCredentialManifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Created by Michael Avoyan on 04/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/

import {
credentialManifestDescriptorFromJson
} from "../utils/Converter";

export async function getCredentialManifest(req, reply) {
try {
const credentialManifest = await req.vclSdk.getCredentialManifest(
credentialManifestDescriptorFromJson(req.body, req.didJwk)
);
reply.send(credentialManifest);
} catch (e: any) {
reply.code(500).send({
statusCode: "500",
error: "Failed to search for organizations",
message: e.message ?? e.stack ?? JSON.stringify(e),
errorCode: e.errorCode,
});
}
}
14 changes: 4 additions & 10 deletions packages/sample-server/src/controllers/getPresentationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { VCLPresentationRequestDescriptor } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src";
import { deepLinkFromString } from "../utils/Converter";
import { presentationRequestDescriptorFromJson } from "../utils/Converter";

export async function getPresentationRequest(req, reply) {
try {
const deepLink = deepLinkFromString(req.body.value)
const presentationRequestDescriptor = new VCLPresentationRequestDescriptor(
deepLink,
null,
req.didJwk,
null
)
const presentationRequest = await req.vclSdk.getPresentationRequest(presentationRequestDescriptor);
const presentationRequest = await req.vclSdk.getPresentationRequest(
presentationRequestDescriptorFromJson(req.body, req.didJwk)
);
reply.send(presentationRequest);
} catch (e: any) {
reply.code(500).send({
Expand Down
10 changes: 9 additions & 1 deletion packages/sample-server/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
import { getPresentationRequest } from "./getPresentationRequest";
import { submitPresentation } from "./submitPresentation";
import { getExchangeProgress } from "./getExchangeProgress";
import { searchForOrganizations } from "./searchForOrganizations";
import { getCredentialManifest } from "./getCredentialManifest";
import { generateOffers } from "./generateOffers";
import { checkForOffers } from "./checkForOffers";

export {
getPresentationRequest,
submitPresentation,
getExchangeProgress
getExchangeProgress,
searchForOrganizations,
getCredentialManifest,
generateOffers,
checkForOffers
}
24 changes: 24 additions & 0 deletions packages/sample-server/src/controllers/searchForOrganizations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Created by Michael Avoyan on 04/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/

import { organizationsSearchDescriptorFromJson } from "../utils/Converter";

export async function searchForOrganizations(req, reply) {
try {
const organizations = await req.vclSdk.searchForOrganizations(
organizationsSearchDescriptorFromJson(req.body)
);
reply.send(organizations);
} catch (e: any) {
reply.code(500).send({
statusCode: "500",
error: "Failed to search for organizations",
message: e.message ?? e.stack ?? JSON.stringify(e),
errorCode: e.errorCode,
});
}
}
22 changes: 21 additions & 1 deletion packages/sample-server/src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import {
getPresentationRequest,
submitPresentation,
getExchangeProgress
getExchangeProgress,
searchForOrganizations,
getCredentialManifest,
generateOffers,
checkForOffers
} from "../controllers";

export default async function routes(fastify) {
Expand All @@ -23,4 +27,20 @@ export default async function routes(fastify) {
"/getExchangeProgress",
getExchangeProgress
);
fastify.post(
"/searchForOrganizations",
searchForOrganizations
);
fastify.post(
"/getCredentialManifest",
getCredentialManifest
);
fastify.post(
"/generateOffers",
generateOffers
);
fastify.post(
"/checkOffers",
checkForOffers
);
}
Loading

0 comments on commit af7d1ff

Please sign in to comment.