@unchainedshop/ticketing 4.3.4 → 4.4.0
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/README.md +168 -0
- package/lib/express.d.ts +0 -1
- package/lib/express.js +3 -4
- package/lib/fastify.d.ts +0 -1
- package/lib/fastify.js +3 -4
- package/lib/index.d.ts +6 -7
- package/lib/index.js +4 -5
- package/lib/magic-key.d.ts +0 -1
- package/lib/magic-key.js +0 -4
- package/lib/mobile-tickets/apple-handler-express.d.ts +1 -2
- package/lib/mobile-tickets/apple-handler-express.js +1 -8
- package/lib/mobile-tickets/apple-handler-fastify.d.ts +0 -1
- package/lib/mobile-tickets/apple-handler-fastify.js +1 -8
- package/lib/mobile-tickets/apple-wallet.d.ts +0 -1
- package/lib/mobile-tickets/apple-wallet.js +0 -1
- package/lib/mobile-tickets/google-handler-express.d.ts +1 -2
- package/lib/mobile-tickets/google-handler-express.js +0 -1
- package/lib/mobile-tickets/google-handler-fastify.d.ts +0 -1
- package/lib/mobile-tickets/google-handler-fastify.js +0 -1
- package/lib/module.d.ts +4 -5
- package/lib/module.js +3 -10
- package/lib/pdf-tickets/print-handler-express.d.ts +1 -2
- package/lib/pdf-tickets/print-handler-express.js +1 -2
- package/lib/pdf-tickets/print-handler-fastify.d.ts +0 -1
- package/lib/pdf-tickets/print-handler-fastify.js +1 -2
- package/lib/services.d.ts +2 -3
- package/lib/services.js +0 -1
- package/lib/template-registry.d.ts +10 -10
- package/lib/template-registry.js +5 -7
- package/lib/types.d.ts +3 -4
- package/lib/types.js +0 -1
- package/package.json +17 -15
- package/lib/express.d.ts.map +0 -1
- package/lib/express.js.map +0 -1
- package/lib/fastify.d.ts.map +0 -1
- package/lib/fastify.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/magic-key.d.ts.map +0 -1
- package/lib/magic-key.js.map +0 -1
- package/lib/mobile-tickets/apple-handler-express.d.ts.map +0 -1
- package/lib/mobile-tickets/apple-handler-express.js.map +0 -1
- package/lib/mobile-tickets/apple-handler-fastify.d.ts.map +0 -1
- package/lib/mobile-tickets/apple-handler-fastify.js.map +0 -1
- package/lib/mobile-tickets/apple-wallet.d.ts.map +0 -1
- package/lib/mobile-tickets/apple-wallet.js.map +0 -1
- package/lib/mobile-tickets/google-handler-express.d.ts.map +0 -1
- package/lib/mobile-tickets/google-handler-express.js.map +0 -1
- package/lib/mobile-tickets/google-handler-fastify.d.ts.map +0 -1
- package/lib/mobile-tickets/google-handler-fastify.js.map +0 -1
- package/lib/module.d.ts.map +0 -1
- package/lib/module.js.map +0 -1
- package/lib/pdf-tickets/print-handler-express.d.ts.map +0 -1
- package/lib/pdf-tickets/print-handler-express.js.map +0 -1
- package/lib/pdf-tickets/print-handler-fastify.d.ts.map +0 -1
- package/lib/pdf-tickets/print-handler-fastify.js.map +0 -1
- package/lib/services.d.ts.map +0 -1
- package/lib/services.js.map +0 -1
- package/lib/template-registry.d.ts.map +0 -1
- package/lib/template-registry.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/readme.md +0 -118
- package/src/express.ts +0 -35
- package/src/fastify.ts +0 -30
- package/src/index.ts +0 -66
- package/src/magic-key.ts +0 -43
- package/src/mobile-tickets/apple-handler-express.ts +0 -237
- package/src/mobile-tickets/apple-handler-fastify.ts +0 -279
- package/src/mobile-tickets/apple-wallet.ts +0 -31
- package/src/mobile-tickets/google-handler-express.ts +0 -57
- package/src/mobile-tickets/google-handler-fastify.ts +0 -69
- package/src/module.ts +0 -251
- package/src/pdf-tickets/print-handler-express.ts +0 -34
- package/src/pdf-tickets/print-handler-fastify.ts +0 -43
- package/src/services.ts +0 -35
- package/src/template-registry.ts +0 -48
- package/src/types.ts +0 -8
- package/tsconfig.json +0 -10
package/src/module.ts
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { buildDbIndexes, ModuleInput } from '@unchainedshop/mongodb';
|
|
3
|
-
import { MediaObjectsCollection } from '@unchainedshop/core-files';
|
|
4
|
-
import { TokenSurrogateCollection } from '@unchainedshop/core-warehousing';
|
|
5
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
6
|
-
import { TokenSurrogate } from '@unchainedshop/core-warehousing';
|
|
7
|
-
import { File } from '@unchainedshop/core-files';
|
|
8
|
-
|
|
9
|
-
import { RendererTypes, getRenderer } from './template-registry.js';
|
|
10
|
-
import { buildPassBinary, pushToApplePushNotificationService } from './mobile-tickets/apple-wallet.js';
|
|
11
|
-
|
|
12
|
-
export const APPLE_WALLET_PASSES_FILE_DIRECTORY = 'apple-wallet-passes';
|
|
13
|
-
|
|
14
|
-
const logger = createLogger('unchained:apple-wallet-webservice');
|
|
15
|
-
|
|
16
|
-
const configurePasses = async ({ db }: ModuleInput<Record<string, never>>) => {
|
|
17
|
-
const MediaObjects = await MediaObjectsCollection(db);
|
|
18
|
-
const TokenSurrogates = await TokenSurrogateCollection(db);
|
|
19
|
-
|
|
20
|
-
await buildDbIndexes(TokenSurrogates as any, [
|
|
21
|
-
{ index: { 'meta.cancelled': 1 }, options: { sparse: true } },
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
await buildDbIndexes(MediaObjects as any, [
|
|
25
|
-
{ index: { path: 1, 'meta.passTypeIdentifier': 1, 'meta.serialNumber': 1 } },
|
|
26
|
-
{
|
|
27
|
-
index: {
|
|
28
|
-
path: 1,
|
|
29
|
-
'meta.passTypeIdentifier': 1,
|
|
30
|
-
'meta.registrations.deviceLibraryIdentifier': 1,
|
|
31
|
-
},
|
|
32
|
-
} as any,
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
const upsertAppleWalletPass = async (token: TokenSurrogate, unchainedAPI: UnchainedCore) => {
|
|
36
|
-
const createAppleWalletPass = getRenderer(RendererTypes.APPLE_WALLET);
|
|
37
|
-
const pass = await createAppleWalletPass(token, unchainedAPI);
|
|
38
|
-
const rawFile = Promise.resolve(
|
|
39
|
-
// wrap in promise to make stream upload work
|
|
40
|
-
await buildPassBinary(token.tokenSerialNumber, pass as any),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const previousFile = await MediaObjects.findOne({
|
|
44
|
-
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
45
|
-
'meta.passTypeIdentifier': pass.passTypeIdentifier,
|
|
46
|
-
'meta.serialNumber': pass.serialNumber,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const registrations: any = previousFile?.meta?.registrations || [];
|
|
50
|
-
const pkpassFile = await unchainedAPI.services.files.uploadFileFromStream({
|
|
51
|
-
directoryName: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
52
|
-
rawFile,
|
|
53
|
-
meta: {
|
|
54
|
-
rawData: token,
|
|
55
|
-
passTypeIdentifier: pass.passTypeIdentifier,
|
|
56
|
-
serialNumber: pass.serialNumber,
|
|
57
|
-
registrations,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (previousFile) {
|
|
62
|
-
await unchainedAPI.services.files.removeFiles({
|
|
63
|
-
fileIds: [previousFile._id],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Push updates!
|
|
68
|
-
if (registrations?.length) {
|
|
69
|
-
try {
|
|
70
|
-
const pushTokens = registrations.map(({ pushToken }) => pushToken);
|
|
71
|
-
logger.info(`Send update pass notification to ${pushTokens.join(',')}`);
|
|
72
|
-
await pushToApplePushNotificationService(pushTokens);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
logger.error(e);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return pkpassFile;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const upsertGoogleWalletPass = async (token: TokenSurrogate, unchainedAPI: UnchainedCore) => {
|
|
82
|
-
const createGoogleWalletPass = getRenderer(RendererTypes.GOOGLE_WALLET);
|
|
83
|
-
const pass = await createGoogleWalletPass(token, unchainedAPI);
|
|
84
|
-
return pass;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const findAppleWalletPass = async (passTypeIdentifier, serialNumber) => {
|
|
88
|
-
const mediaObject = await MediaObjects.findOne({
|
|
89
|
-
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
90
|
-
'meta.passTypeIdentifier': passTypeIdentifier,
|
|
91
|
-
'meta.serialNumber': serialNumber,
|
|
92
|
-
});
|
|
93
|
-
return mediaObject;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const registerDeviceForAppleWalletPass = async (
|
|
97
|
-
passTypeIdentifier,
|
|
98
|
-
serialNumber,
|
|
99
|
-
{ deviceLibraryIdentifier, pushToken },
|
|
100
|
-
) => {
|
|
101
|
-
const result = await MediaObjects.updateOne(
|
|
102
|
-
{
|
|
103
|
-
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
104
|
-
'meta.passTypeIdentifier': passTypeIdentifier,
|
|
105
|
-
'meta.serialNumber': serialNumber,
|
|
106
|
-
'meta.registrations.deviceLibraryIdentifier': {
|
|
107
|
-
$ne: deviceLibraryIdentifier,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
$push: {
|
|
112
|
-
'meta.registrations': {
|
|
113
|
-
deviceLibraryIdentifier,
|
|
114
|
-
pushToken,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
return Boolean(result.modifiedCount);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const unregisterDeviceForAppleWalletPass = async (
|
|
123
|
-
passTypeIdentifier,
|
|
124
|
-
serialNumber,
|
|
125
|
-
deviceLibraryIdentifier,
|
|
126
|
-
) => {
|
|
127
|
-
const result = await MediaObjects.updateOne(
|
|
128
|
-
{
|
|
129
|
-
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
130
|
-
'meta.passTypeIdentifier': passTypeIdentifier,
|
|
131
|
-
'meta.serialNumber': serialNumber,
|
|
132
|
-
'meta.registrations.deviceLibraryIdentifier': deviceLibraryIdentifier,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
$pull: {
|
|
136
|
-
'meta.registrations': {
|
|
137
|
-
deviceLibraryIdentifier,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
);
|
|
142
|
-
return Boolean(result.modifiedCount);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const findUpdatedAppleWalletPasses = async (
|
|
146
|
-
passTypeIdentifier,
|
|
147
|
-
deviceLibraryIdentifier,
|
|
148
|
-
passesUpdatedSince,
|
|
149
|
-
): Promise<File[]> => {
|
|
150
|
-
const selector = {
|
|
151
|
-
$or: [
|
|
152
|
-
{
|
|
153
|
-
updated: passesUpdatedSince ? { $gt: passesUpdatedSince } : { $exists: true },
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
created: passesUpdatedSince ? { $gt: passesUpdatedSince } : { $exists: true },
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
'meta.registrations.deviceLibraryIdentifier': deviceLibraryIdentifier,
|
|
160
|
-
'meta.passTypeIdentifier': passTypeIdentifier,
|
|
161
|
-
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
162
|
-
};
|
|
163
|
-
const updatedPasses = await MediaObjects.find(selector).toArray();
|
|
164
|
-
return updatedPasses;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const invalidateAppleWalletPasses = async (unchainedAPI: UnchainedCore) => {
|
|
168
|
-
const allPasses = await MediaObjects.find({
|
|
169
|
-
path: APPLE_WALLET_PASSES_FILE_DIRECTORY,
|
|
170
|
-
}).toArray();
|
|
171
|
-
const allTokens = await TokenSurrogates.find({}).toArray();
|
|
172
|
-
|
|
173
|
-
for (const pass of allPasses) {
|
|
174
|
-
// Check if binary is already invalidated, if so, skip
|
|
175
|
-
const rawData = pass.meta?.rawData as TokenSurrogate;
|
|
176
|
-
if (rawData.invalidatedDate) continue;
|
|
177
|
-
|
|
178
|
-
const redeemedToken = allTokens.find((t) => t._id === rawData._id && t.invalidatedDate);
|
|
179
|
-
|
|
180
|
-
// Find invalidated token for the binary, if found, invalidate binary
|
|
181
|
-
if (redeemedToken) {
|
|
182
|
-
logger.info('Ticket redeemed, void pass', rawData);
|
|
183
|
-
await upsertAppleWalletPass(redeemedToken, unchainedAPI);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const buildMagicKey = async (orderId: string) => {
|
|
189
|
-
const msgUint8 = new TextEncoder().encode([orderId, process.env.UNCHAINED_SECRET].join(''));
|
|
190
|
-
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8);
|
|
191
|
-
// Convert ArrayBuffer to hex string without using Buffer
|
|
192
|
-
return Array.from(new Uint8Array(hashBuffer))
|
|
193
|
-
.map((b) => b.toString(16).padStart(2, '0'))
|
|
194
|
-
.join('');
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const cancelTicket = async (tokenId: string) => {
|
|
198
|
-
return TokenSurrogates.findOneAndUpdate(
|
|
199
|
-
{ _id: tokenId },
|
|
200
|
-
{ $set: { 'meta.cancelled': true } },
|
|
201
|
-
{
|
|
202
|
-
returnDocument: 'after',
|
|
203
|
-
},
|
|
204
|
-
);
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const isTicketCancelled = (token: TokenSurrogate) => {
|
|
208
|
-
return Boolean(token.meta?.cancelled);
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const getTicketsCreated = async (
|
|
212
|
-
{
|
|
213
|
-
productId,
|
|
214
|
-
}: {
|
|
215
|
-
productId: string;
|
|
216
|
-
},
|
|
217
|
-
{ skipCancelled }: { skipCancelled?: boolean } = {},
|
|
218
|
-
): Promise<number> => {
|
|
219
|
-
const selector: any = {
|
|
220
|
-
productId,
|
|
221
|
-
};
|
|
222
|
-
if (skipCancelled) {
|
|
223
|
-
selector['meta.cancelled'] = null;
|
|
224
|
-
}
|
|
225
|
-
return TokenSurrogates.countDocuments(selector);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
upsertAppleWalletPass,
|
|
230
|
-
findAppleWalletPass,
|
|
231
|
-
registerDeviceForAppleWalletPass,
|
|
232
|
-
unregisterDeviceForAppleWalletPass,
|
|
233
|
-
findUpdatedAppleWalletPasses,
|
|
234
|
-
invalidateAppleWalletPasses,
|
|
235
|
-
upsertGoogleWalletPass,
|
|
236
|
-
buildMagicKey,
|
|
237
|
-
cancelTicket,
|
|
238
|
-
isTicketCancelled,
|
|
239
|
-
getTicketsCreated,
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export interface TicketingModule {
|
|
244
|
-
passes: Awaited<ReturnType<typeof configurePasses>>;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export default {
|
|
248
|
-
passes: {
|
|
249
|
-
configure: configurePasses,
|
|
250
|
-
},
|
|
251
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { checkAction } from '@unchainedshop/api/lib/acl.js';
|
|
2
|
-
import { actions } from '@unchainedshop/api/lib/roles/index.js';
|
|
3
|
-
import { Context } from '@unchainedshop/api';
|
|
4
|
-
import { RendererTypes, getRenderer } from '../template-registry.js';
|
|
5
|
-
import type { Request, Response } from 'express';
|
|
6
|
-
|
|
7
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
8
|
-
|
|
9
|
-
const logger = createLogger('unchained:ticketing');
|
|
10
|
-
|
|
11
|
-
export async function printTicketsHandler(req: Request & { unchainedContext: Context }, res: Response) {
|
|
12
|
-
const { variant, orderId, otp } = req.query || {};
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
if (
|
|
16
|
-
typeof orderId !== 'string' ||
|
|
17
|
-
typeof otp !== 'string' ||
|
|
18
|
-
(variant && typeof variant !== 'string')
|
|
19
|
-
)
|
|
20
|
-
throw new Error('Invalid query parameter');
|
|
21
|
-
|
|
22
|
-
await checkAction(req.unchainedContext, actions.viewOrder, [undefined, { orderId, otp }]);
|
|
23
|
-
|
|
24
|
-
const render = getRenderer(RendererTypes.ORDER_PDF);
|
|
25
|
-
const pdfStream = await render({ orderId, variant: variant as string }, req.unchainedContext);
|
|
26
|
-
res.setHeader('Content-Type', 'application/pdf');
|
|
27
|
-
pdfStream.pipe(res);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
logger.error(error);
|
|
30
|
-
res.status(403).end();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default printTicketsHandler;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { checkAction } from '@unchainedshop/api/lib/acl.js';
|
|
2
|
-
import { actions } from '@unchainedshop/api/lib/roles/index.js';
|
|
3
|
-
import { RendererTypes, getRenderer } from '../template-registry.js';
|
|
4
|
-
import { TicketingAPI } from '../types.js';
|
|
5
|
-
import type { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
6
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
7
|
-
|
|
8
|
-
const logger = createLogger('unchained:ticketing:print-handler');
|
|
9
|
-
|
|
10
|
-
const printTicketsHandler: RouteHandlerMethod = async (
|
|
11
|
-
req: FastifyRequest & {
|
|
12
|
-
unchainedContext: TicketingAPI;
|
|
13
|
-
},
|
|
14
|
-
reply,
|
|
15
|
-
) => {
|
|
16
|
-
const { variant, orderId, otp } = (req.query as Record<string, any>) || {};
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
if (
|
|
20
|
-
typeof orderId !== 'string' ||
|
|
21
|
-
typeof otp !== 'string' ||
|
|
22
|
-
(variant && typeof variant !== 'string')
|
|
23
|
-
)
|
|
24
|
-
throw new Error('Invalid query parameter');
|
|
25
|
-
|
|
26
|
-
await checkAction(req.unchainedContext, actions.viewOrder, [undefined, { orderId, otp }]);
|
|
27
|
-
|
|
28
|
-
const render = getRenderer(RendererTypes.ORDER_PDF);
|
|
29
|
-
const pdfStream = await render({ orderId, variant: variant as string }, req.unchainedContext);
|
|
30
|
-
reply.header('content-type', 'application/pdf');
|
|
31
|
-
return reply.send(pdfStream);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
logger.error(error);
|
|
34
|
-
reply.status(403);
|
|
35
|
-
return reply.send({
|
|
36
|
-
success: false,
|
|
37
|
-
message: 'Error generating PDF',
|
|
38
|
-
name: 'PDF_GENERATION_ERROR',
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default printTicketsHandler;
|
package/src/services.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { TicketingModule } from './module.js';
|
|
2
|
-
import { Bound, UnchainedCore } from '@unchainedshop/core';
|
|
3
|
-
|
|
4
|
-
async function cancelTicketsForProduct(
|
|
5
|
-
this: TicketingModule & UnchainedCore['modules'],
|
|
6
|
-
productId: string,
|
|
7
|
-
): Promise<number> {
|
|
8
|
-
const tokensToCancel = await this.warehousing.findTokens({
|
|
9
|
-
productId,
|
|
10
|
-
'meta.cancelled': null,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
for (const token of tokensToCancel) {
|
|
14
|
-
await this.warehousing.invalidateToken(token._id);
|
|
15
|
-
await this.passes.cancelTicket(token._id);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
await this.products.update(productId, {
|
|
19
|
-
$set: { 'meta.cancelled': true },
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return tokensToCancel.length;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default {
|
|
26
|
-
ticketing: {
|
|
27
|
-
cancelTicketsForProduct,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export interface TicketingServices {
|
|
32
|
-
ticketing: {
|
|
33
|
-
cancelTicketsForProduct: Bound<typeof cancelTicketsForProduct>;
|
|
34
|
-
};
|
|
35
|
-
}
|
package/src/template-registry.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
-
import { TokenSurrogate } from '@unchainedshop/core-warehousing';
|
|
3
|
-
|
|
4
|
-
export type PDFRenderer = (
|
|
5
|
-
{
|
|
6
|
-
orderId,
|
|
7
|
-
variant,
|
|
8
|
-
}: {
|
|
9
|
-
orderId: string;
|
|
10
|
-
variant?: string;
|
|
11
|
-
},
|
|
12
|
-
context: UnchainedCore,
|
|
13
|
-
) => Promise<NodeJS.ReadableStream>;
|
|
14
|
-
|
|
15
|
-
export type PassRenderer = (
|
|
16
|
-
token: TokenSurrogate,
|
|
17
|
-
context: UnchainedCore,
|
|
18
|
-
) => Promise<{
|
|
19
|
-
asURL: () => Promise<string>;
|
|
20
|
-
asBuffer: () => Promise<Buffer>;
|
|
21
|
-
serialNumber?: string;
|
|
22
|
-
passTypeIdentifier?: string;
|
|
23
|
-
}>;
|
|
24
|
-
|
|
25
|
-
export enum RendererTypes {
|
|
26
|
-
GOOGLE_WALLET = 'google-wallet',
|
|
27
|
-
APPLE_WALLET = 'apple-wallet',
|
|
28
|
-
ORDER_PDF = 'order',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const renderers = new Map<string, PDFRenderer | PassRenderer>();
|
|
32
|
-
|
|
33
|
-
export type RegisterRendererFn = ((type: RendererTypes.ORDER_PDF, renderer: PDFRenderer) => void) &
|
|
34
|
-
((type: RendererTypes.GOOGLE_WALLET | RendererTypes.APPLE_WALLET, renderer: PassRenderer) => void);
|
|
35
|
-
|
|
36
|
-
export const registerRenderer: RegisterRendererFn = function registerRenderer(
|
|
37
|
-
type: RendererTypes,
|
|
38
|
-
renderer: PDFRenderer | PassRenderer,
|
|
39
|
-
) {
|
|
40
|
-
renderers.set(type, renderer);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type GetRendererFn = ((type: RendererTypes.ORDER_PDF) => PDFRenderer) &
|
|
44
|
-
((type: RendererTypes.GOOGLE_WALLET | RendererTypes.APPLE_WALLET) => PassRenderer);
|
|
45
|
-
|
|
46
|
-
export const getRenderer: GetRendererFn = function getRenderer(type: RendererTypes) {
|
|
47
|
-
return renderers.get(type) as any;
|
|
48
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
-
import { TicketingModule } from './module.js';
|
|
3
|
-
import { TicketingServices } from './services.js';
|
|
4
|
-
|
|
5
|
-
export type TicketingAPI = UnchainedCore & {
|
|
6
|
-
modules: TicketingModule;
|
|
7
|
-
services: TicketingServices;
|
|
8
|
-
};
|