hono-passkit-webservice
Version:
Hono.dev integration for Apple Wallet web services
39 lines • 1.64 kB
JavaScript
import { Hono } from "hono";
import { ListEndpoint, } from "passkit-webservice-toolkit/v1/list.js";
import { HandlerNotFoundError } from "../../HandlerNotFoundError.js";
export default function ListRouter(opts) {
if (typeof (opts === null || opts === void 0 ? void 0 : opts.onListRetrieve) !== "function") {
throw new HandlerNotFoundError("onListRetrieve", "ListRouter");
}
const router = new Hono();
router.get(ListEndpoint.path, async (context) => {
const { deviceLibraryIdentifier, passTypeIdentifier } = context.req.param();
const filters = {
passesUpdatedSince: context.req.query().passesUpdatedSince ||
undefined,
};
const retrieve = await opts.onListRetrieve(deviceLibraryIdentifier, passTypeIdentifier, filters);
if (!retrieve) {
context.status(204);
return context.body(null);
}
if (!("serialNumbers" in retrieve) ||
!Array.isArray(retrieve["serialNumbers"])) {
context.status(500);
return context.json({
message: "'serialNumbers' property is missing in 'onListRetrieve' response or is not an array.",
});
}
if (!("lastUpdated" in retrieve)) {
context.status(500);
return context.json({
message: "'lastUpdated' property is missing in 'onListRetrieve' response.",
});
}
context.header("Content-Type", "application/json");
context.status(200);
return context.json(retrieve);
});
return router;
}
//# sourceMappingURL=list.js.map