@unchainedshop/ticketing 4.0.0-rc.15 → 4.0.0-rc.17
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/fastify.js +2 -2
- package/lib/fastify.js.map +1 -1
- package/lib/magic-key.js +4 -4
- package/lib/magic-key.js.map +1 -1
- package/lib/mobile-tickets/apple-handler-express.js +63 -64
- package/lib/mobile-tickets/apple-handler-express.js.map +1 -1
- package/lib/mobile-tickets/apple-handler-fastify.d.ts.map +1 -1
- package/lib/mobile-tickets/apple-handler-fastify.js +93 -42
- package/lib/mobile-tickets/apple-handler-fastify.js.map +1 -1
- package/lib/mobile-tickets/apple-wallet.d.ts +3 -3
- package/lib/mobile-tickets/apple-wallet.d.ts.map +1 -1
- package/lib/mobile-tickets/apple-wallet.js +3 -3
- package/lib/mobile-tickets/apple-wallet.js.map +1 -1
- package/lib/mobile-tickets/apple-webservice.d.ts +7 -0
- package/lib/mobile-tickets/apple-webservice.d.ts.map +1 -0
- package/lib/mobile-tickets/apple-webservice.js +177 -0
- package/lib/mobile-tickets/apple-webservice.js.map +1 -0
- package/lib/mobile-tickets/google-handler-express.d.ts.map +1 -1
- package/lib/mobile-tickets/google-handler-express.js +10 -12
- package/lib/mobile-tickets/google-handler-express.js.map +1 -1
- package/lib/mobile-tickets/google-handler-fastify.d.ts.map +1 -1
- package/lib/mobile-tickets/google-handler-fastify.js +19 -6
- package/lib/mobile-tickets/google-handler-fastify.js.map +1 -1
- package/lib/mobile-tickets/google-webservice.d.ts +7 -0
- package/lib/mobile-tickets/google-webservice.d.ts.map +1 -0
- package/lib/mobile-tickets/google-webservice.js +52 -0
- package/lib/mobile-tickets/google-webservice.js.map +1 -0
- package/lib/module.d.ts +8 -8
- package/lib/module.d.ts.map +1 -1
- package/lib/module.js +2 -2
- package/lib/module.js.map +1 -1
- package/lib/pdf-tickets/print-handler-express.d.ts.map +1 -1
- package/lib/pdf-tickets/print-handler-express.js +4 -3
- package/lib/pdf-tickets/print-handler-express.js.map +1 -1
- package/lib/pdf-tickets/print-handler-fastify.d.ts.map +1 -1
- package/lib/pdf-tickets/print-handler-fastify.js +8 -2
- package/lib/pdf-tickets/print-handler-fastify.js.map +1 -1
- package/lib/pdf-tickets/print-webservice.d.ts +7 -0
- package/lib/pdf-tickets/print-webservice.d.ts.map +1 -0
- package/lib/pdf-tickets/print-webservice.js +31 -0
- package/lib/pdf-tickets/print-webservice.js.map +1 -0
- package/lib/template-registry.d.ts +2 -2
- package/lib/template-registry.d.ts.map +1 -1
- package/package.json +11 -11
- package/readme.md +1 -1
- package/src/fastify.ts +2 -2
- package/src/magic-key.ts +4 -4
- package/src/mobile-tickets/apple-handler-express.ts +71 -71
- package/src/mobile-tickets/apple-handler-fastify.ts +103 -51
- package/src/mobile-tickets/apple-wallet.ts +3 -3
- package/src/mobile-tickets/google-handler-express.ts +11 -12
- package/src/mobile-tickets/google-handler-fastify.ts +21 -6
- package/src/module.ts +3 -3
- package/src/pdf-tickets/print-handler-express.ts +6 -3
- package/src/pdf-tickets/print-handler-fastify.ts +9 -2
- package/src/template-registry.ts +2 -2
- package/tsconfig.json +2 -1
|
@@ -17,8 +17,7 @@ export const googleWalletHandler = async (
|
|
|
17
17
|
const [, , tokenId] = req.path.split('/');
|
|
18
18
|
|
|
19
19
|
if (!tokenId) {
|
|
20
|
-
res.
|
|
21
|
-
res.end();
|
|
20
|
+
res.status(404).end();
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -27,32 +26,32 @@ export const googleWalletHandler = async (
|
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
if (!token) {
|
|
30
|
-
res.
|
|
31
|
-
res.end('Token not found');
|
|
29
|
+
res.status(404).send('Token not found');
|
|
32
30
|
return;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
const { hash } = req.query;
|
|
36
34
|
const correctHash = await modules.warehousing.buildAccessKeyForToken(tokenId);
|
|
37
|
-
if (hash !== correctHash) {
|
|
38
|
-
res.
|
|
39
|
-
res.end('Token hash invalid for current owner');
|
|
35
|
+
if (!hash || hash !== correctHash) {
|
|
36
|
+
res.status(403).send('Token hash invalid for current owner');
|
|
40
37
|
return;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
const pass = await modules.passes.upsertGoogleWalletPass(token, resolvedContext);
|
|
44
41
|
|
|
42
|
+
if (!pass) {
|
|
43
|
+
throw new Error('Could not create Google Wallet pass');
|
|
44
|
+
}
|
|
45
|
+
|
|
45
46
|
res.redirect(await pass.asURL());
|
|
46
47
|
return;
|
|
47
48
|
} catch (e) {
|
|
48
|
-
|
|
49
|
+
logger.error(e);
|
|
49
50
|
}
|
|
50
|
-
res.
|
|
51
|
-
res.end();
|
|
51
|
+
res.status(500).end();
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
res.
|
|
55
|
-
res.end();
|
|
54
|
+
res.status(404).end();
|
|
56
55
|
};
|
|
57
56
|
|
|
58
57
|
export default googleWalletHandler;
|
|
@@ -31,24 +31,39 @@ const googleWalletHandler: RouteHandlerMethod = async (
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
if (!token) {
|
|
34
|
+
logger.error('Token not found', { tokenId });
|
|
34
35
|
reply.status(404);
|
|
35
|
-
return reply.send(
|
|
36
|
+
return reply.send();
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const { hash } = req.query as Record<string, string>;
|
|
39
40
|
const correctHash = await modules.warehousing.buildAccessKeyForToken(tokenId);
|
|
40
|
-
if (hash !== correctHash) {
|
|
41
|
+
if (!hash || hash !== correctHash) {
|
|
42
|
+
logger.error('Token hash invalid for current owner', { tokenId });
|
|
41
43
|
reply.status(403);
|
|
42
|
-
return reply.send(
|
|
44
|
+
return reply.send({
|
|
45
|
+
success: false,
|
|
46
|
+
message: 'Token hash invalid for current owner',
|
|
47
|
+
name: 'HASH_MISMATCH',
|
|
48
|
+
});
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
const pass = await modules.passes.upsertGoogleWalletPass(token, resolvedContext);
|
|
52
|
+
|
|
53
|
+
if (!pass) {
|
|
54
|
+
throw new Error('Could not create Google Wallet pass');
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
return reply.redirect(await pass.asURL());
|
|
47
58
|
} catch (e) {
|
|
48
|
-
|
|
59
|
+
logger.error(e);
|
|
60
|
+
reply.status(500);
|
|
61
|
+
return reply.send({
|
|
62
|
+
success: false,
|
|
63
|
+
message: 'Error generating pass',
|
|
64
|
+
name: 'PASS_GENERATION_ERROR',
|
|
65
|
+
});
|
|
49
66
|
}
|
|
50
|
-
reply.status(500);
|
|
51
|
-
return reply.send();
|
|
52
67
|
}
|
|
53
68
|
reply.status(404);
|
|
54
69
|
return reply.send();
|
package/src/module.ts
CHANGED
|
@@ -37,7 +37,7 @@ const configurePasses = async ({ db }: ModuleInput<Record<string, never>>) => {
|
|
|
37
37
|
const pass = await createAppleWalletPass(token, unchainedAPI);
|
|
38
38
|
const rawFile = Promise.resolve(
|
|
39
39
|
// wrap in promise to make stream upload work
|
|
40
|
-
await buildPassBinary(token.
|
|
40
|
+
await buildPassBinary(token.tokenSerialNumber, pass as any),
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
const previousFile = await MediaObjects.findOne({
|
|
@@ -84,7 +84,7 @@ const configurePasses = async ({ db }: ModuleInput<Record<string, never>>) => {
|
|
|
84
84
|
return pass;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
const findAppleWalletPass = async (passTypeIdentifier, serialNumber)
|
|
87
|
+
const findAppleWalletPass = async (passTypeIdentifier, serialNumber) => {
|
|
88
88
|
const mediaObject = await MediaObjects.findOne({
|
|
89
89
|
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
90
90
|
'meta.passTypeIdentifier': passTypeIdentifier,
|
|
@@ -172,7 +172,7 @@ const configurePasses = async ({ db }: ModuleInput<Record<string, never>>) => {
|
|
|
172
172
|
|
|
173
173
|
for (const pass of allPasses) {
|
|
174
174
|
// Check if binary is already invalidated, if so, skip
|
|
175
|
-
const rawData = pass.meta
|
|
175
|
+
const rawData = pass.meta?.rawData as TokenSurrogate;
|
|
176
176
|
if (rawData.invalidatedDate) continue;
|
|
177
177
|
|
|
178
178
|
const redeemedToken = allTokens.find((t) => t._id === rawData._id && t.invalidatedDate);
|
|
@@ -4,6 +4,10 @@ import { Context } from '@unchainedshop/api';
|
|
|
4
4
|
import { RendererTypes, getRenderer } from '../template-registry.js';
|
|
5
5
|
import type { Request, Response } from 'express';
|
|
6
6
|
|
|
7
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
8
|
+
|
|
9
|
+
const logger = createLogger('unchained:ticketing');
|
|
10
|
+
|
|
7
11
|
export async function printTicketsHandler(req: Request & { unchainedContext: Context }, res: Response) {
|
|
8
12
|
const { variant, orderId, otp } = req.query || {};
|
|
9
13
|
|
|
@@ -22,9 +26,8 @@ export async function printTicketsHandler(req: Request & { unchainedContext: Con
|
|
|
22
26
|
res.setHeader('Content-Type', 'application/pdf');
|
|
23
27
|
pdfStream.pipe(res);
|
|
24
28
|
} catch (error) {
|
|
25
|
-
|
|
26
|
-
res.status(403);
|
|
27
|
-
res.end();
|
|
29
|
+
logger.error(error);
|
|
30
|
+
res.status(403).end();
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -3,6 +3,9 @@ import { actions } from '@unchainedshop/api/lib/roles/index.js';
|
|
|
3
3
|
import { RendererTypes, getRenderer } from '../template-registry.js';
|
|
4
4
|
import { TicketingAPI } from '../types.js';
|
|
5
5
|
import type { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
6
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
7
|
+
|
|
8
|
+
const logger = createLogger('unchained:ticketing:print-handler');
|
|
6
9
|
|
|
7
10
|
const printTicketsHandler: RouteHandlerMethod = async (
|
|
8
11
|
req: FastifyRequest & {
|
|
@@ -27,9 +30,13 @@ const printTicketsHandler: RouteHandlerMethod = async (
|
|
|
27
30
|
reply.header('content-type', 'application/pdf');
|
|
28
31
|
return reply.send(pdfStream);
|
|
29
32
|
} catch (error) {
|
|
30
|
-
|
|
33
|
+
logger.error(error);
|
|
31
34
|
reply.status(403);
|
|
32
|
-
return reply.send(
|
|
35
|
+
return reply.send({
|
|
36
|
+
success: false,
|
|
37
|
+
message: 'Error generating PDF',
|
|
38
|
+
name: 'PDF_GENERATION_ERROR',
|
|
39
|
+
});
|
|
33
40
|
}
|
|
34
41
|
};
|
|
35
42
|
|
package/src/template-registry.ts
CHANGED
|
@@ -16,8 +16,8 @@ export type PassRenderer = (
|
|
|
16
16
|
token: TokenSurrogate,
|
|
17
17
|
context: UnchainedCore,
|
|
18
18
|
) => Promise<{
|
|
19
|
-
asURL
|
|
20
|
-
asBuffer
|
|
19
|
+
asURL: () => Promise<string>;
|
|
20
|
+
asBuffer: () => Promise<Buffer>;
|
|
21
21
|
serialNumber?: string;
|
|
22
22
|
passTypeIdentifier?: string;
|
|
23
23
|
}>;
|