@unchainedshop/ticketing 4.8.11 → 5.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/express.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import express from 'express';
2
- declare const _default: (app: express.Express) => void;
1
+ import type { Express } from 'express';
2
+ declare const _default: (app: Express) => void;
3
3
  export default _default;
package/lib/express.js CHANGED
@@ -1,16 +1,27 @@
1
- import express from 'express';
2
- import appleWalletHandler from "./mobile-tickets/apple-handler-express.js";
3
- import googleWalletHandler from "./mobile-tickets/google-handler-express.js";
4
- import printTicketsHandler from "./pdf-tickets/print-handler-express.js";
1
+ import { createServerAdapter } from '@whatwg-node/server';
2
+ import { ticketingRoutes } from "./routes.js";
5
3
  export default (app) => {
6
- const { APPLE_WALLET_WEBSERVICE_PATH = '/rest/apple-wallet', GOOGLE_WALLET_WEBSERVICE_PATH = '/rest/google-wallet', UNCHAINED_PDF_PRINT_HANDLER_PATH = '/rest/print_tickets', } = process.env;
7
- app.use(UNCHAINED_PDF_PRINT_HANDLER_PATH, express.json({
8
- type: 'application/json',
9
- }), printTicketsHandler);
10
- app.use(APPLE_WALLET_WEBSERVICE_PATH, express.json({
11
- type: 'application/json',
12
- }), appleWalletHandler);
13
- app.use(`${GOOGLE_WALLET_WEBSERVICE_PATH}/download/:tokenId`, express.json({
14
- type: 'application/json',
15
- }), googleWalletHandler);
4
+ for (const route of ticketingRoutes) {
5
+ const adapter = createServerAdapter(async (request, serverContext) => {
6
+ const context = {
7
+ ...serverContext.unchainedContext,
8
+ params: serverContext.params || {},
9
+ };
10
+ return await route.handler(request, context);
11
+ });
12
+ const expressPath = route.path.replace(/\/\*$/, '/*');
13
+ app.use(expressPath, async (req, res) => {
14
+ try {
15
+ await adapter.handleNodeRequestAndResponse(req, res, {
16
+ unchainedContext: req.unchainedContext,
17
+ params: req.params,
18
+ });
19
+ }
20
+ catch {
21
+ if (!res.headersSent) {
22
+ res.status(500).json({ error: 'Internal Server Error' });
23
+ }
24
+ }
25
+ });
26
+ }
16
27
  };
package/lib/fastify.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- declare const _default: (app: FastifyInstance) => void;
2
+ declare const _default: (fastify: FastifyInstance) => void;
3
3
  export default _default;
package/lib/fastify.js CHANGED
@@ -1,26 +1,42 @@
1
- import appleWalletHandler from "./mobile-tickets/apple-handler-fastify.js";
2
- import googleWalletHandler from "./mobile-tickets/google-handler-fastify.js";
3
- import printTicketsHandler from "./pdf-tickets/print-handler-fastify.js";
4
- export default (app) => {
5
- const { APPLE_WALLET_WEBSERVICE_PATH = '/rest/apple-wallet', GOOGLE_WALLET_WEBSERVICE_PATH = '/rest/google-wallet', UNCHAINED_PDF_PRINT_HANDLER_PATH = '/rest/print_tickets', } = process.env;
6
- app.route({
7
- url: `${APPLE_WALLET_WEBSERVICE_PATH}/*`,
8
- method: ['GET', 'POST', 'DELETE'],
9
- handler: appleWalletHandler,
10
- });
11
- app.route({
12
- url: `${GOOGLE_WALLET_WEBSERVICE_PATH}/download/:tokenId`,
13
- method: 'GET',
14
- handler: googleWalletHandler,
15
- });
16
- app.route({
17
- url: `${UNCHAINED_PDF_PRINT_HANDLER_PATH}`,
18
- method: 'GET',
19
- handler: printTicketsHandler,
20
- });
21
- app.route({
22
- url: `${UNCHAINED_PDF_PRINT_HANDLER_PATH}/*`,
23
- method: 'GET',
24
- handler: printTicketsHandler,
1
+ import { createServerAdapter } from '@whatwg-node/server';
2
+ import { ticketingRoutes } from "./routes.js";
3
+ export default (fastify) => {
4
+ if (ticketingRoutes.length === 0)
5
+ return;
6
+ fastify.register((scope, opts, registered) => {
7
+ scope.removeAllContentTypeParsers();
8
+ scope.addContentTypeParser('*', function (request, payload, done) {
9
+ done(null);
10
+ });
11
+ for (const route of ticketingRoutes) {
12
+ const adapter = createServerAdapter(async (request, serverContext) => {
13
+ const context = {
14
+ ...serverContext.unchainedContext,
15
+ params: serverContext.params || {},
16
+ };
17
+ return await route.handler(request, context);
18
+ });
19
+ const fastifyPath = route.path.replace(/\/\*$/, '/*');
20
+ scope.all(fastifyPath, async (req, reply) => {
21
+ try {
22
+ const response = await adapter.handleNodeRequestAndResponse(req.raw, reply.raw, {
23
+ unchainedContext: req.unchainedContext,
24
+ params: req.params,
25
+ });
26
+ response.headers.forEach((value, key) => {
27
+ reply.header(key, value);
28
+ });
29
+ reply.status(response.status);
30
+ reply.send(response.body || undefined);
31
+ return reply;
32
+ }
33
+ catch {
34
+ if (!reply.sent) {
35
+ reply.status(500).send({ error: 'Internal Server Error' });
36
+ }
37
+ }
38
+ });
39
+ }
40
+ registered();
25
41
  });
26
42
  };
package/lib/index.d.ts CHANGED
@@ -1,8 +1,12 @@
1
+ import type { UnchainedCore } from '@unchainedshop/core';
1
2
  import { RendererTypes } from './template-registry.ts';
2
3
  import ticketingModules, { type TicketingModule } from './module.ts';
3
- import type { TicketingAPI } from './types.ts';
4
4
  import ticketingServices, { type TicketingServices } from './services.ts';
5
- export type { TicketingAPI, RendererTypes, TicketingModule, TicketingServices };
5
+ export type TicketingAPI = UnchainedCore & {
6
+ modules: TicketingModule;
7
+ services: TicketingServices;
8
+ };
9
+ export type { RendererTypes, TicketingModule, TicketingServices };
6
10
  export { ticketingServices, ticketingModules };
7
11
  export declare function setupPDFTickets({ renderOrderPDF }: {
8
12
  renderOrderPDF: any;
package/lib/routes.js CHANGED
@@ -54,7 +54,7 @@ export async function googleWalletHandler(request, context) {
54
54
  }
55
55
  const url = new URL(request.url);
56
56
  const hash = url.searchParams.get('hash');
57
- const correctHash = await modules.warehousing.buildAccessKeyForToken(tokenId);
57
+ const correctHash = await modules.warehousing.buildAccessKeyFromToken(token);
58
58
  if (!hash || hash !== correctHash) {
59
59
  return new Response(JSON.stringify({ error: 'Token hash invalid for current owner' }), {
60
60
  status: 403,
@@ -96,7 +96,7 @@ export async function appleWalletHandler(request, context) {
96
96
  });
97
97
  }
98
98
  const hash = url.searchParams.get('hash');
99
- const correctHash = await modules.warehousing.buildAccessKeyForToken(tokenId);
99
+ const correctHash = await modules.warehousing.buildAccessKeyFromToken(token);
100
100
  if (!hash || hash !== correctHash) {
101
101
  return new Response(JSON.stringify({ error: 'Token hash invalid for current owner' }), {
102
102
  status: 403,
package/lib/services.js CHANGED
@@ -7,7 +7,9 @@ async function cancelTicketsForProduct(productId) {
7
7
  await this.warehousing.invalidateToken(token._id);
8
8
  await this.passes.cancelTicket(token._id);
9
9
  }
10
- await this.products.update(productId, { 'meta.cancelled': true });
10
+ await this.products.update(productId, {
11
+ $set: { 'meta.cancelled': true },
12
+ });
11
13
  return tokensToCancel.length;
12
14
  }
13
15
  export default {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/ticketing",
3
3
  "description": "Event ticketing extension for the Unchained Engine with PDF and wallet pass support",
4
- "version": "4.8.11",
4
+ "version": "5.0.0-alpha.2",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "type": "module",
@@ -34,17 +34,17 @@
34
34
  },
35
35
  "homepage": "https://github.com/unchainedshop/unchained#readme",
36
36
  "dependencies": {
37
- "@unchainedshop/api": "^4.6.0",
38
- "@unchainedshop/core": "^4.6.0",
39
- "@unchainedshop/core-files": "^4.6.0",
40
- "@unchainedshop/core-warehousing": "^4.6.0",
41
- "@unchainedshop/core-worker": "^4.6.0",
42
- "@unchainedshop/events": "^4.6.0",
43
- "@unchainedshop/logger": "^4.6.0",
44
- "@unchainedshop/mongodb": "^4.6.0"
37
+ "@unchainedshop/api": "^5.0.0-alpha.1",
38
+ "@unchainedshop/core": "^5.0.0-alpha.1",
39
+ "@unchainedshop/core-files": "^5.0.0-alpha.1",
40
+ "@unchainedshop/core-warehousing": "^5.0.0-alpha.1",
41
+ "@unchainedshop/core-worker": "^5.0.0-alpha.1",
42
+ "@unchainedshop/events": "^5.0.0-alpha.1",
43
+ "@unchainedshop/logger": "^5.0.0-alpha.1",
44
+ "@unchainedshop/mongodb": "^5.0.0-alpha.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "@parse/node-apn": "^7.0.1",
47
+ "@parse/node-apn": "^8.1.0",
48
48
  "express": "5.x",
49
49
  "fastify": ">= 5.2 < 6"
50
50
  },
@@ -60,6 +60,7 @@
60
60
  }
61
61
  },
62
62
  "devDependencies": {
63
+ "@parse/node-apn": "^8.1.0",
63
64
  "@types/express": "^5.0.3",
64
65
  "@types/node": "^25.0.0",
65
66
  "express": "^5.1.0",