@owask/tapace-templates 0.1.1 → 0.2.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.
@@ -0,0 +1,14 @@
1
+ import { type FieldDef, type TemplateDefinition } from '../contract/index.js';
2
+ /**
3
+ * The expiry a compile renders, as an ISO date-time: the pass's own, else in a
4
+ * preview the template's rule applied now. Undefined when the coupon has none.
5
+ */
6
+ export declare function couponExpiry(def: TemplateDefinition, expiresAt: Date | null | undefined, mode: 'preview' | 'issue'): string | undefined;
7
+ /** Google shows a coupon's expiry natively, from the offer's valid time. */
8
+ export declare function couponShowsNatively(def: TemplateDefinition, field: FieldDef): boolean;
9
+ type CouponDefinition = Extract<TemplateDefinition, {
10
+ type: 'coupon';
11
+ }>;
12
+ /** The Google offer class's own texts; title and provider fall back to logo text and the organization. */
13
+ export declare function googleOfferClassFields(def: CouponDefinition): Record<string, unknown>;
14
+ export {};
@@ -0,0 +1,39 @@
1
+ import { expiryDateTime, templateExpiry, } from '../contract/index.js';
2
+ /**
3
+ * The expiry a compile renders, as an ISO date-time: the pass's own, else in a
4
+ * preview the template's rule applied now. Undefined when the coupon has none.
5
+ */
6
+ export function couponExpiry(def, expiresAt, mode) {
7
+ if (def.type !== 'coupon')
8
+ return undefined;
9
+ const rule = def.config.expiry;
10
+ if (expiresAt)
11
+ return expiryDateTime(expiresAt, rule?.timezone);
12
+ if (mode !== 'preview' || !rule)
13
+ return undefined;
14
+ return rule.kind === 'fixed' ? rule.at : expiryDateTime(templateExpiry(rule, new Date()), rule.timezone);
15
+ }
16
+ /** Google shows a coupon's expiry natively, from the offer's valid time. */
17
+ export function couponShowsNatively(def, field) {
18
+ return def.type === 'coupon' && field.binding === 'expiry';
19
+ }
20
+ const GOOGLE_CHANNELS = { inStore: 'INSTORE', online: 'ONLINE', both: 'BOTH' };
21
+ /** The Google offer class's own texts; title and provider fall back to logo text and the organization. */
22
+ export function googleOfferClassFields(def) {
23
+ const google = def.google;
24
+ return {
25
+ title: google.title ?? (def.logoText?.trim() || def.organizationName),
26
+ provider: google.provider ?? def.organizationName,
27
+ redemptionChannel: GOOGLE_CHANNELS[google.redemptionChannel ?? 'both'],
28
+ ...(google.shortTitle ? { shortTitle: google.shortTitle } : {}),
29
+ ...(google.finePrint ? { finePrint: google.finePrint } : {}),
30
+ ...(google.helpLink
31
+ ? {
32
+ helpUri: {
33
+ uri: google.helpLink.url,
34
+ ...(google.helpLink.label ? { description: google.helpLink.label } : {}),
35
+ },
36
+ }
37
+ : {}),
38
+ };
39
+ }
@@ -54,6 +54,10 @@ export interface CompileOptions {
54
54
  walletMessages?: WalletMessages;
55
55
  /** Apple `voided: true`; Google object state `INACTIVE`. */
56
56
  voided?: boolean;
57
+ /** A redeemed coupon: Apple `voided: true`; Google object state `COMPLETED`. */
58
+ redeemed?: boolean;
59
+ /** A coupon's expiry; previews use the template's rule when absent. */
60
+ expiresAt?: Date | null;
57
61
  /** A stamp card's count and drawn stamps; stand-ins are used when absent. */
58
62
  stamps?: StampRender;
59
63
  /** A points card's balance; the template's starting balance when absent. */
@@ -3,6 +3,7 @@ import { POSTER_SLOTS, STANDARD_SLOTS, featuredActions, imageAssetId, imageSlots
3
3
  import { appleDateStyle, eventFieldValue, eventSemantics, googleEvent, googleLocations, googleShowsNatively, } from './event-ticket.js';
4
4
  import { stampRenderFor } from './stamp-card.js';
5
5
  import { googleAccountId, googleLoyalty, googleProgramNames, isLoyaltyCard, loyaltyBalanceText, loyaltyFieldTexts, loyaltyShowsNatively, } from './loyalty-card.js';
6
+ import { couponExpiry, couponShowsNatively, googleOfferClassFields } from './coupon.js';
6
7
  export const PREVIEW_ISSUANCE = {
7
8
  passTypeIdentifier: 'pass.tapace.preview',
8
9
  teamIdentifier: 'TAPACEPREV',
@@ -181,17 +182,20 @@ function buildImages(def, options) {
181
182
  }
182
183
  return images;
183
184
  }
184
- function fieldValueFor(def, field, values, mode, loyaltyTexts) {
185
+ function fieldValueFor(def, field, values, mode, loyaltyTexts, expiry) {
185
186
  if (field.binding === 'event')
186
187
  return eventFieldValue(def, field, mode);
188
+ if (field.binding === 'expiry')
189
+ return expiry ?? (mode === 'preview' ? '' : undefined);
187
190
  if (field.binding === 'shared' || field.binding === 'perPass')
188
191
  return resolveFieldValue(field, values, mode);
189
192
  return loyaltyTexts[field.binding];
190
193
  }
191
- function mapField(def, field, values, mode, platform, loyaltyTexts, changeMessage) {
192
- if (platform === 'google' && (googleShowsNatively(def, field) || loyaltyShowsNatively(def, field)))
194
+ function mapField(def, field, values, mode, platform, loyaltyTexts, expiry, changeMessage) {
195
+ if (platform === 'google' &&
196
+ (googleShowsNatively(def, field) || loyaltyShowsNatively(def, field) || couponShowsNatively(def, field)))
193
197
  return undefined;
194
- const value = fieldValueFor(def, field, values, mode, loyaltyTexts);
198
+ const value = fieldValueFor(def, field, values, mode, loyaltyTexts, expiry);
195
199
  if (value === undefined)
196
200
  return undefined;
197
201
  const mapped = { key: field.key, label: field.label, value };
@@ -202,6 +206,9 @@ function mapField(def, field, values, mode, platform, loyaltyTexts, changeMessag
202
206
  const dateStyle = platform === 'apple' && value !== '' ? appleDateStyle(field) : undefined;
203
207
  if (dateStyle)
204
208
  Object.assign(mapped, dateStyle);
209
+ // Shown in the holder's own timezone, unlike an event time.
210
+ if (platform === 'apple' && field.binding === 'expiry' && value !== '')
211
+ Object.assign(mapped, { dateStyle: 'medium', timeStyle: 'short' });
205
212
  return mapped;
206
213
  }
207
214
  function actionUrl(action, links, mode) {
@@ -266,8 +273,11 @@ export function compile(def, options) {
266
273
  if (options.platform === 'apple' && options.webService) {
267
274
  base.webService = options.webService;
268
275
  }
269
- if (options.platform === 'apple' && options.voided)
276
+ if (options.platform === 'apple' && (options.voided || options.redeemed))
270
277
  base.voided = true;
278
+ const expiry = couponExpiry(def, options.expiresAt, mode);
279
+ if (expiry)
280
+ base.expirationDate = expiry;
271
281
  if (options.platform === 'apple') {
272
282
  const { locations, dates } = resolveRelevance(def, options.relevance);
273
283
  if (locations.length > 0) {
@@ -310,7 +320,7 @@ export function compile(def, options) {
310
320
  }
311
321
  if (stamps && options.platform === 'google')
312
322
  base.images.googleObject = { heroImage: { url: stamps.googleHeroUrl } };
313
- const valueOf = (field) => fieldValueFor(def, field, values, mode, loyaltyTexts);
323
+ const valueOf = (field) => fieldValueFor(def, field, values, mode, loyaltyTexts, expiry);
314
324
  if (isLoyaltyCard(def) && options.platform === 'google') {
315
325
  const accountId = googleAccountId(def, valueOf);
316
326
  // Passmint uses the serial number as the loyalty account id; applyRaw replaces it.
@@ -335,7 +345,9 @@ export function compile(def, options) {
335
345
  ? { loyalty: googleLoyalty(def, balanceText ?? '', valueOf) }
336
346
  : undefined,
337
347
  })
338
- : Pass.generic(poster ? { ...base, poster: true } : base);
348
+ : def.type === 'coupon'
349
+ ? Pass.coupon(poster ? { ...base, poster: true } : base)
350
+ : Pass.generic(poster ? { ...base, poster: true } : base);
339
351
  const adders = {
340
352
  header: (f) => builder.headerField(f),
341
353
  primary: (f) => builder.primaryField(f),
@@ -344,7 +356,7 @@ export function compile(def, options) {
344
356
  back: (f) => builder.backField(f),
345
357
  };
346
358
  const changeMessages = options.platform === 'apple' ? options.changeMessages : undefined;
347
- const map = (field) => mapField(def, field, values, mode, options.platform, loyaltyTexts, field.id !== undefined ? changeMessages?.[field.id] : undefined);
359
+ const map = (field) => mapField(def, field, values, mode, options.platform, loyaltyTexts, expiry, field.id !== undefined ? changeMessages?.[field.id] : undefined);
348
360
  // Wallet ignores the generic block's back fields on a poster, so the reserved
349
361
  // notification fields lead the back of both blocks.
350
362
  const walletMessageFields = options.platform === 'apple' && options.walletMessages
@@ -434,10 +446,19 @@ export function renderGoogle(def, options) {
434
446
  for (const cls of loyaltyClasses)
435
447
  Object.assign(cls, googleProgramNames(def));
436
448
  }
449
+ const offerClasses = (payload.offerClasses ?? []).filter(isRecord);
450
+ if (def.type === 'coupon') {
451
+ for (const cls of offerClasses)
452
+ Object.assign(cls, googleOfferClassFields(def));
453
+ }
437
454
  const classLocations = def.type === 'generic' ? [] : googleLocations(def, def.relevance?.locations ?? []);
438
455
  if (classLocations.length > 0) {
439
456
  // An event class already lists its venue (from passmint); the template's places follow it.
440
- for (const cls of [...loyaltyClasses, ...(payload.eventTicketClasses ?? []).filter(isRecord)]) {
457
+ for (const cls of [
458
+ ...loyaltyClasses,
459
+ ...offerClasses,
460
+ ...(payload.eventTicketClasses ?? []).filter(isRecord),
461
+ ]) {
441
462
  const current = Array.isArray(cls.merchantLocations) ? cls.merchantLocations : [];
442
463
  cls.merchantLocations = [...current, ...classLocations].slice(0, MAX_GOOGLE_LOCATIONS);
443
464
  }
@@ -456,14 +477,16 @@ export function renderGoogle(def, options) {
456
477
  holder.wideLogo = { sourceUri: { uri } };
457
478
  for (const cls of loyaltyClasses)
458
479
  cls.wideProgramLogo = { sourceUri: { uri } };
480
+ for (const cls of offerClasses)
481
+ cls.wideTitleImage = { sourceUri: { uri } };
459
482
  }
460
- if (options.voided) {
483
+ if (options.voided || options.redeemed) {
461
484
  // Passmint always emits `state: "ACTIVE"`.
462
485
  for (const [key, entries] of Object.entries(payload)) {
463
486
  if (!key.endsWith('Objects') || !Array.isArray(entries))
464
487
  continue;
465
488
  for (const object of entries.filter(isRecord))
466
- object.state = 'INACTIVE';
489
+ object.state = options.voided ? 'INACTIVE' : 'COMPLETED';
467
490
  }
468
491
  }
469
492
  return payload;
@@ -11,7 +11,7 @@ export interface BarcodePreview {
11
11
  message: string;
12
12
  altText?: string;
13
13
  }
14
- export type PreviewStyle = 'generic' | 'eventTicket' | 'storeCard';
14
+ export type PreviewStyle = 'generic' | 'eventTicket' | 'storeCard' | 'coupon';
15
15
  export interface ApplePreview {
16
16
  platform: 'apple';
17
17
  style: PreviewStyle;
@@ -95,12 +95,27 @@ export interface GoogleLoyaltyPreview {
95
95
  accountName?: string;
96
96
  accountId: string;
97
97
  }
98
- /** A generic card, or the native event ticket (`event`) or loyalty card (`loyalty`). */
98
+ /** A Google offer's (coupon's) native parts; its own fields are `textModules`. */
99
+ export interface GoogleOfferPreview {
100
+ title: string;
101
+ provider: string;
102
+ shortTitle?: string;
103
+ redemptionChannel: 'inStore' | 'online' | 'both';
104
+ finePrint?: string;
105
+ helpLink?: {
106
+ url: string;
107
+ label?: string;
108
+ };
109
+ /** The expiry Google shows, an ISO date-time. */
110
+ validUntil?: string;
111
+ }
112
+ /** A generic card, or the native event ticket (`event`), loyalty card (`loyalty`) or offer (`offer`). */
99
113
  export interface GooglePreview {
100
114
  platform: 'google';
101
- style: 'generic' | 'eventTicket' | 'loyalty';
115
+ style: 'generic' | 'eventTicket' | 'loyalty' | 'offer';
102
116
  event?: GoogleEventPreview;
103
117
  loyalty?: GoogleLoyaltyPreview;
118
+ offer?: GoogleOfferPreview;
104
119
  cardTitle: string;
105
120
  header: string;
106
121
  subheader?: string;
@@ -40,6 +40,7 @@ const NativeApple = z.object({
40
40
  generic: NativeStyleFields.optional(),
41
41
  eventTicket: NativeStyleFields.optional(),
42
42
  storeCard: NativeStyleFields.optional(),
43
+ coupon: NativeStyleFields.optional(),
43
44
  posterGeneric: NativePosterFields.optional(),
44
45
  featuredActions: z
45
46
  .array(z.object({ identifier: z.string(), type: z.string(), url: z.string() }))
@@ -120,6 +121,23 @@ const NativeLoyaltyObject = z.object({
120
121
  textModulesData: NativeTextModules,
121
122
  barcode: NativeBarcode,
122
123
  });
124
+ const NativeOfferClass = z.object({
125
+ title: z.string(),
126
+ provider: z.string(),
127
+ shortTitle: z.string().optional(),
128
+ redemptionChannel: z.enum(['INSTORE', 'ONLINE', 'BOTH']),
129
+ finePrint: z.string().optional(),
130
+ helpUri: z.object({ uri: z.string(), description: z.string().optional() }).optional(),
131
+ hexBackgroundColor: z.string(),
132
+ titleImage: NativeImage.optional(),
133
+ wideTitleImage: NativeImage.optional(),
134
+ heroImage: NativeImage.optional(),
135
+ });
136
+ const NativeOfferObject = z.object({
137
+ textModulesData: NativeTextModules,
138
+ barcode: NativeBarcode,
139
+ validTimeInterval: z.object({ end: z.object({ date: z.string() }) }).optional(),
140
+ });
123
141
  const NativeGoogle = z.object({
124
142
  cardTitle: LocalizedText,
125
143
  header: LocalizedText,
@@ -187,7 +205,9 @@ export function applePreview(def, options) {
187
205
  ? 'eventTicket'
188
206
  : def.type === 'stamp_card' || def.type === 'points_card'
189
207
  ? 'storeCard'
190
- : 'generic';
208
+ : def.type === 'coupon'
209
+ ? 'coupon'
210
+ : 'generic';
191
211
  const layout = native[style];
192
212
  if (!layout)
193
213
  throw new Error(`Rendered Apple pass has no ${style} fields.`);
@@ -363,9 +383,51 @@ function googleLoyaltyPreview(def, options) {
363
383
  : undefined,
364
384
  };
365
385
  }
386
+ const CHANNELS = { INSTORE: 'inStore', ONLINE: 'online', BOTH: 'both' };
387
+ function googleOfferPreview(def, options) {
388
+ const payload = renderGoogle(def, options);
389
+ const cls = NativeOfferClass.parse(payload.offerClasses?.[0]);
390
+ const obj = NativeOfferObject.parse(payload.offerObjects?.[0]);
391
+ const assetId = (image) => image
392
+ ? Object.entries(options.assets).find(([, asset]) => asset.url === image.sourceUri.uri)?.[0]
393
+ : undefined;
394
+ return {
395
+ platform: 'google',
396
+ style: 'offer',
397
+ offer: {
398
+ title: cls.title,
399
+ provider: cls.provider,
400
+ shortTitle: cls.shortTitle,
401
+ redemptionChannel: CHANNELS[cls.redemptionChannel],
402
+ finePrint: cls.finePrint,
403
+ helpLink: cls.helpUri ? { url: cls.helpUri.uri, label: cls.helpUri.description } : undefined,
404
+ validUntil: obj.validTimeInterval?.end.date,
405
+ },
406
+ cardTitle: cls.provider,
407
+ header: cls.title,
408
+ backgroundColor: cls.hexBackgroundColor,
409
+ foregroundColor: def.colors.foreground,
410
+ labelColor: def.colors.label ?? def.colors.foreground,
411
+ images: {
412
+ logo: assetId(cls.titleImage),
413
+ wideLogo: assetId(cls.wideTitleImage),
414
+ hero: assetId(cls.heroImage),
415
+ },
416
+ textModules: obj.textModulesData.map((field) => ({
417
+ key: field.id,
418
+ label: field.header,
419
+ value: field.body,
420
+ })),
421
+ barcode: obj.barcode
422
+ ? { format: obj.barcode.type, message: obj.barcode.value, altText: obj.barcode.alternateText }
423
+ : undefined,
424
+ };
425
+ }
366
426
  export function googlePreview(def, options) {
367
427
  if (def.type === 'event_ticket')
368
428
  return googleEventPreview(def, options);
429
+ if (def.type === 'coupon')
430
+ return googleOfferPreview(def, options);
369
431
  if (def.type === 'stamp_card' || def.type === 'points_card')
370
432
  return googleLoyaltyPreview(def, options);
371
433
  const native = NativeGoogle.parse(renderGoogle(def, options).genericObjects?.[0]);
@@ -18,6 +18,8 @@ export interface TemplatePreviewOptions {
18
18
  actionLinks?: Record<string, string>;
19
19
  stampCount?: number;
20
20
  pointsBalance?: number;
21
+ /** A coupon's own expiry; previews use the template's rule without one. */
22
+ expiresAt?: Date | null;
21
23
  allWallets?: boolean;
22
24
  /** Sizes of the referenced images; a missing size skips that image's size check. */
23
25
  assetSizes?: ReadonlyMap<string, AssetSize>;
@@ -1,7 +1,7 @@
1
1
  import { ZodError } from 'zod';
2
2
  import { placeholderAssets, toCompileIssues } from './passmint-compiler.js';
3
3
  import { applePreview, googlePreview } from './preview-model.js';
4
- import { EventDetailsSchema, TemplateValidationError, imageAssetId, parseTemplateDefinition, posterEnabled, previewFieldValues, referencedAssetIds, requiredFieldKeys, } from '../contract/index.js';
4
+ import { EventDetailsSchema, PAST_EXPIRY_MESSAGE, TemplateValidationError, hasPastFixedExpiry, imageAssetId, parseTemplateDefinition, posterEnabled, previewFieldValues, referencedAssetIds, requiredFieldKeys, } from '../contract/index.js';
5
5
  /** Google's minimum for the logo it crops into a circle (Wallet brand guidelines). */
6
6
  const GOOGLE_LOGO_MIN_SIZE = 660;
7
7
  const GOOGLE_WIDE_LOGO_MIN_HEIGHT = 400;
@@ -61,8 +61,12 @@ export function buildTemplatePreview(def, options = {}) {
61
61
  mode,
62
62
  ...(options.stampCount !== undefined ? { stamps: { count: options.stampCount } } : {}),
63
63
  ...(options.pointsBalance !== undefined ? { points: options.pointsBalance } : {}),
64
+ ...(options.expiresAt ? { expiresAt: options.expiresAt } : {}),
64
65
  };
65
66
  const result = { requiredFields: requiredFieldKeys(def), issues: [] };
67
+ if (mode === 'preview' && def.type === 'coupon' && hasPastFixedExpiry(def.config.expiry, new Date())) {
68
+ result.issues.push({ platform: 'template', path: 'config.expiry.at', message: PAST_EXPIRY_MESSAGE });
69
+ }
66
70
  if (def.platforms.apple || allWallets) {
67
71
  try {
68
72
  result.apple = applePreview(compileDef.def, compileOptions);
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+ export declare const MAX_COUPON_DAYS = 3650;
3
+ /**
4
+ * When a coupon expires: at a fixed date and time, or exactly `days` × 24 h after
5
+ * each pass is issued. `timezone` is the one the dashboard shows and enters times
6
+ * in, and the one TapAce writes expiry text in for Google. With no expiry, a
7
+ * coupon expires only when its pass sets one.
8
+ */
9
+ export declare const CouponExpirySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ kind: z.ZodLiteral<"fixed">;
11
+ at: z.ZodString;
12
+ timezone: z.ZodOptional<z.ZodString>;
13
+ }, z.core.$strict>, z.ZodObject<{
14
+ kind: z.ZodLiteral<"afterIssue">;
15
+ timezone: z.ZodOptional<z.ZodString>;
16
+ days: z.ZodNumber;
17
+ }, z.core.$strict>], "kind">;
18
+ export type CouponExpiry = z.infer<typeof CouponExpirySchema>;
19
+ /** What a redeem that notifies says. Apple's text goes in the pass's message field. */
20
+ export declare const CouponNotificationsSchema: z.ZodObject<{
21
+ apple: z.ZodOptional<z.ZodString>;
22
+ googleTitle: z.ZodOptional<z.ZodString>;
23
+ googleBody: z.ZodOptional<z.ZodString>;
24
+ }, z.core.$strict>;
25
+ export type CouponNotifications = z.infer<typeof CouponNotificationsSchema>;
26
+ export declare const HttpsUrlSchema: z.ZodString;
27
+ export declare const REDEMPTION_CHANNELS: readonly ["inStore", "online", "both"];
28
+ export type RedemptionChannel = (typeof REDEMPTION_CHANNELS)[number];
29
+ /** The expiry a template's rule gives a pass issued at `issuedAt`; null without a rule. */
30
+ export declare function templateExpiry(expiry: CouponExpiry | undefined, issuedAt: Date): Date | null;
31
+ /** "Dec 31, 2026, 11:59 PM" in `timezone` (UTC when unknown), for text Google shows as is. */
32
+ export declare function formatExpiry(at: Date, timezone: string | undefined): string;
33
+ /**
34
+ * `at` as an ISO date-time in `timezone`'s offset ("2026-12-31T23:59:00+05:30"), or
35
+ * in UTC without one. Wallets need the offset; previews show its wall-clock time.
36
+ */
37
+ export declare function expiryDateTime(at: Date, timezone: string | undefined): string;
38
+ export declare const PAST_EXPIRY_MESSAGE = "The expiry has passed. Pick a later date and time.";
39
+ /** True when a coupon template's fixed expiry is at or before `now`; saving is then refused. */
40
+ export declare function hasPastFixedExpiry(expiry: CouponExpiry | undefined, now: Date): boolean;
@@ -0,0 +1,90 @@
1
+ import { z } from 'zod';
2
+ import { DateTimeSchema, isTimeZone } from './relevance.js';
3
+ export const MAX_COUPON_DAYS = 3650;
4
+ const DAY_MS = 86_400_000;
5
+ const timezone = z.string().refine(isTimeZone, 'Expected a timezone like Asia/Colombo.').optional();
6
+ /**
7
+ * When a coupon expires: at a fixed date and time, or exactly `days` × 24 h after
8
+ * each pass is issued. `timezone` is the one the dashboard shows and enters times
9
+ * in, and the one TapAce writes expiry text in for Google. With no expiry, a
10
+ * coupon expires only when its pass sets one.
11
+ */
12
+ export const CouponExpirySchema = z.discriminatedUnion('kind', [
13
+ z.strictObject({ kind: z.literal('fixed'), at: DateTimeSchema, timezone }),
14
+ z.strictObject({
15
+ kind: z.literal('afterIssue'),
16
+ timezone,
17
+ days: z
18
+ .number()
19
+ .int('Enter a whole number of days.')
20
+ .min(1, 'A coupon lasts at least 1 day.')
21
+ .max(MAX_COUPON_DAYS, `A coupon lasts at most ${MAX_COUPON_DAYS} days.`),
22
+ }),
23
+ ]);
24
+ const notificationText = z.string().trim().min(1).max(200);
25
+ /** What a redeem that notifies says. Apple's text goes in the pass's message field. */
26
+ export const CouponNotificationsSchema = z.strictObject({
27
+ apple: notificationText.optional(),
28
+ googleTitle: notificationText.optional(),
29
+ googleBody: notificationText.optional(),
30
+ });
31
+ export const HttpsUrlSchema = z
32
+ .string()
33
+ .max(2048)
34
+ .refine((url) => {
35
+ try {
36
+ return new URL(url).protocol === 'https:';
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ }, 'The link must be a valid https:// URL.');
42
+ export const REDEMPTION_CHANNELS = ['inStore', 'online', 'both'];
43
+ /** The expiry a template's rule gives a pass issued at `issuedAt`; null without a rule. */
44
+ export function templateExpiry(expiry, issuedAt) {
45
+ if (!expiry)
46
+ return null;
47
+ if (expiry.kind === 'fixed')
48
+ return new Date(expiry.at);
49
+ return new Date(issuedAt.getTime() + expiry.days * DAY_MS);
50
+ }
51
+ /** "Dec 31, 2026, 11:59 PM" in `timezone` (UTC when unknown), for text Google shows as is. */
52
+ export function formatExpiry(at, timezone) {
53
+ return new Intl.DateTimeFormat('en-US', {
54
+ dateStyle: 'medium',
55
+ timeStyle: 'short',
56
+ timeZone: timezone ?? 'UTC',
57
+ }).format(at);
58
+ }
59
+ const pad = (n) => String(n).padStart(2, '0');
60
+ /**
61
+ * `at` as an ISO date-time in `timezone`'s offset ("2026-12-31T23:59:00+05:30"), or
62
+ * in UTC without one. Wallets need the offset; previews show its wall-clock time.
63
+ */
64
+ export function expiryDateTime(at, timezone) {
65
+ const seconds = Math.floor(at.getTime() / 1000) * 1000;
66
+ if (!timezone)
67
+ return new Date(seconds).toISOString().replace('.000Z', 'Z');
68
+ const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {
69
+ timeZone: timezone,
70
+ hourCycle: 'h23',
71
+ year: 'numeric',
72
+ month: '2-digit',
73
+ day: '2-digit',
74
+ hour: '2-digit',
75
+ minute: '2-digit',
76
+ second: '2-digit',
77
+ })
78
+ .formatToParts(at)
79
+ .map((part) => [part.type, part.value]));
80
+ const local = Date.UTC(+parts.year, +parts.month - 1, +parts.day, +parts.hour, +parts.minute, +parts.second);
81
+ const offset = Math.round((local - seconds) / 60_000);
82
+ const sign = offset < 0 ? '-' : '+';
83
+ const abs = Math.abs(offset);
84
+ return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
85
+ }
86
+ export const PAST_EXPIRY_MESSAGE = 'The expiry has passed. Pick a later date and time.';
87
+ /** True when a coupon template's fixed expiry is at or before `now`; saving is then refused. */
88
+ export function hasPastFixedExpiry(expiry, now) {
89
+ return expiry?.kind === 'fixed' && Date.parse(expiry.at) <= now.getTime();
90
+ }
@@ -50,6 +50,7 @@ export declare const EVENT_TICKET_IMAGE_SLOTS: readonly ["icon", "logo", "strip"
50
50
  /** A stamp card's strip is drawn from its stamp settings, never uploaded. */
51
51
  export declare const STAMP_CARD_IMAGE_SLOTS: readonly ["icon", "logo", "artwork", "primaryLogo"];
52
52
  export declare const POINTS_CARD_IMAGE_SLOTS: readonly ["icon", "logo", "strip", "artwork", "primaryLogo"];
53
+ export declare const COUPON_IMAGE_SLOTS: readonly ["icon", "logo", "strip", "artwork", "primaryLogo"];
53
54
  export type ImageSlotName = (typeof GENERIC_IMAGE_SLOTS)[number] | (typeof EVENT_TICKET_IMAGE_SLOTS)[number];
54
55
  export declare const ImageSlotsSchema: z.ZodObject<{
55
56
  icon: z.ZodString;
@@ -188,6 +189,29 @@ export declare const LoyaltyGoogleSettingsSchema: z.ZodObject<{
188
189
  memberNameField: z.ZodOptional<z.ZodString>;
189
190
  memberIdField: z.ZodOptional<z.ZodString>;
190
191
  }, z.core.$strict>;
192
+ /**
193
+ * A coupon's Google offer class. `title` and `provider` fall back to logo text and
194
+ * the organization name; the redemption channel defaults to both.
195
+ */
196
+ export declare const CouponGoogleSettingsSchema: z.ZodObject<{
197
+ heroAssetId: z.ZodOptional<z.ZodString>;
198
+ logoAssetId: z.ZodOptional<z.ZodString>;
199
+ wideLogoAssetId: z.ZodOptional<z.ZodString>;
200
+ singleHolder: z.ZodOptional<z.ZodBoolean>;
201
+ title: z.ZodOptional<z.ZodString>;
202
+ provider: z.ZodOptional<z.ZodString>;
203
+ shortTitle: z.ZodOptional<z.ZodString>;
204
+ redemptionChannel: z.ZodOptional<z.ZodEnum<{
205
+ both: "both";
206
+ inStore: "inStore";
207
+ online: "online";
208
+ }>>;
209
+ finePrint: z.ZodOptional<z.ZodString>;
210
+ helpLink: z.ZodOptional<z.ZodObject<{
211
+ url: z.ZodString;
212
+ label: z.ZodOptional<z.ZodString>;
213
+ }, z.core.$strict>>;
214
+ }, z.core.$strict>;
191
215
  export declare const GenericConfigSchema: z.ZodObject<{
192
216
  fields: z.ZodArray<z.ZodObject<{
193
217
  id: z.ZodOptional<z.ZodString>;
@@ -201,6 +225,7 @@ export declare const GenericConfigSchema: z.ZodObject<{
201
225
  points: "points";
202
226
  stampsLeft: "stampsLeft";
203
227
  pointsToGoal: "pointsToGoal";
228
+ expiry: "expiry";
204
229
  }>;
205
230
  required: z.ZodBoolean;
206
231
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -263,6 +288,7 @@ export declare const EventTicketConfigSchema: z.ZodObject<{
263
288
  points: "points";
264
289
  stampsLeft: "stampsLeft";
265
290
  pointsToGoal: "pointsToGoal";
291
+ expiry: "expiry";
266
292
  }>;
267
293
  required: z.ZodBoolean;
268
294
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -325,6 +351,7 @@ export declare const StampCardConfigSchema: z.ZodObject<{
325
351
  points: "points";
326
352
  stampsLeft: "stampsLeft";
327
353
  pointsToGoal: "pointsToGoal";
354
+ expiry: "expiry";
328
355
  }>;
329
356
  required: z.ZodBoolean;
330
357
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -439,6 +466,7 @@ export declare const PointsCardConfigSchema: z.ZodObject<{
439
466
  points: "points";
440
467
  stampsLeft: "stampsLeft";
441
468
  pointsToGoal: "pointsToGoal";
469
+ expiry: "expiry";
442
470
  }>;
443
471
  required: z.ZodBoolean;
444
472
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -501,6 +529,82 @@ export declare const PointsCardConfigSchema: z.ZodObject<{
501
529
  goalGoogleBody: z.ZodOptional<z.ZodString>;
502
530
  }, z.core.$strict>>;
503
531
  }, z.core.$strict>;
532
+ export declare const CouponConfigSchema: z.ZodObject<{
533
+ fields: z.ZodArray<z.ZodObject<{
534
+ id: z.ZodOptional<z.ZodString>;
535
+ key: z.ZodString;
536
+ label: z.ZodString;
537
+ binding: z.ZodEnum<{
538
+ shared: "shared";
539
+ perPass: "perPass";
540
+ event: "event";
541
+ stamps: "stamps";
542
+ points: "points";
543
+ stampsLeft: "stampsLeft";
544
+ pointsToGoal: "pointsToGoal";
545
+ expiry: "expiry";
546
+ }>;
547
+ required: z.ZodBoolean;
548
+ defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
549
+ sampleValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
550
+ textAlignment: z.ZodOptional<z.ZodEnum<{
551
+ left: "left";
552
+ center: "center";
553
+ right: "right";
554
+ natural: "natural";
555
+ }>>;
556
+ event: z.ZodOptional<z.ZodEnum<{
557
+ name: "name";
558
+ venueName: "venueName";
559
+ venueAddress: "venueAddress";
560
+ doorsOpen: "doorsOpen";
561
+ start: "start";
562
+ end: "end";
563
+ }>>;
564
+ dateFormat: z.ZodOptional<z.ZodEnum<{
565
+ date: "date";
566
+ dateTime: "dateTime";
567
+ time: "time";
568
+ }>>;
569
+ googleRole: z.ZodOptional<z.ZodEnum<{
570
+ seat: "seat";
571
+ row: "row";
572
+ section: "section";
573
+ gate: "gate";
574
+ ticketType: "ticketType";
575
+ }>>;
576
+ }, z.core.$strict>>;
577
+ layouts: z.ZodObject<{
578
+ standard: z.ZodObject<{
579
+ header: z.ZodDefault<z.ZodArray<z.ZodString>>;
580
+ primary: z.ZodDefault<z.ZodArray<z.ZodString>>;
581
+ secondary: z.ZodDefault<z.ZodArray<z.ZodString>>;
582
+ auxiliary: z.ZodDefault<z.ZodArray<z.ZodString>>;
583
+ back: z.ZodDefault<z.ZodArray<z.ZodString>>;
584
+ }, z.core.$strict>;
585
+ poster: z.ZodOptional<z.ZodObject<{
586
+ header: z.ZodDefault<z.ZodArray<z.ZodString>>;
587
+ primary: z.ZodDefault<z.ZodArray<z.ZodString>>;
588
+ footer: z.ZodDefault<z.ZodArray<z.ZodString>>;
589
+ additionalInfo: z.ZodDefault<z.ZodArray<z.ZodString>>;
590
+ back: z.ZodDefault<z.ZodArray<z.ZodString>>;
591
+ }, z.core.$strict>>;
592
+ }, z.core.$strict>;
593
+ expiry: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
594
+ kind: z.ZodLiteral<"fixed">;
595
+ at: z.ZodString;
596
+ timezone: z.ZodOptional<z.ZodString>;
597
+ }, z.core.$strict>, z.ZodObject<{
598
+ kind: z.ZodLiteral<"afterIssue">;
599
+ timezone: z.ZodOptional<z.ZodString>;
600
+ days: z.ZodNumber;
601
+ }, z.core.$strict>], "kind">>;
602
+ notifications: z.ZodDefault<z.ZodObject<{
603
+ apple: z.ZodOptional<z.ZodString>;
604
+ googleTitle: z.ZodOptional<z.ZodString>;
605
+ googleBody: z.ZodOptional<z.ZodString>;
606
+ }, z.core.$strict>>;
607
+ }, z.core.$strict>;
504
608
  export declare const RESERVED_FIELD_KEY_PREFIX = "tapace_";
505
609
  /**
506
610
  * The template definition: shared design fields plus a `type`-discriminated
@@ -535,6 +639,7 @@ export declare const TemplateDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObj
535
639
  points: "points";
536
640
  stampsLeft: "stampsLeft";
537
641
  pointsToGoal: "pointsToGoal";
642
+ expiry: "expiry";
538
643
  }>;
539
644
  required: z.ZodBoolean;
540
645
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -701,6 +806,7 @@ export declare const TemplateDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObj
701
806
  points: "points";
702
807
  stampsLeft: "stampsLeft";
703
808
  pointsToGoal: "pointsToGoal";
809
+ expiry: "expiry";
704
810
  }>;
705
811
  required: z.ZodBoolean;
706
812
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -867,6 +973,7 @@ export declare const TemplateDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObj
867
973
  points: "points";
868
974
  stampsLeft: "stampsLeft";
869
975
  pointsToGoal: "pointsToGoal";
976
+ expiry: "expiry";
870
977
  }>;
871
978
  required: z.ZodBoolean;
872
979
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -1087,6 +1194,7 @@ export declare const TemplateDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObj
1087
1194
  points: "points";
1088
1195
  stampsLeft: "stampsLeft";
1089
1196
  pointsToGoal: "pointsToGoal";
1197
+ expiry: "expiry";
1090
1198
  }>;
1091
1199
  required: z.ZodBoolean;
1092
1200
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -1236,6 +1344,197 @@ export declare const TemplateDefinitionSchema: z.ZodDiscriminatedUnion<[z.ZodObj
1236
1344
  }, z.core.$strict>>>;
1237
1345
  timezone: z.ZodOptional<z.ZodString>;
1238
1346
  }, z.core.$strict>>;
1347
+ }, z.core.$strict>, z.ZodObject<{
1348
+ type: z.ZodLiteral<"coupon">;
1349
+ images: z.ZodObject<{
1350
+ icon: z.ZodString;
1351
+ logo: z.ZodOptional<z.ZodString>;
1352
+ strip: z.ZodOptional<z.ZodString>;
1353
+ artwork: z.ZodOptional<z.ZodString>;
1354
+ primaryLogo: z.ZodOptional<z.ZodString>;
1355
+ }, z.core.$strict>;
1356
+ google: z.ZodDefault<z.ZodObject<{
1357
+ heroAssetId: z.ZodOptional<z.ZodString>;
1358
+ logoAssetId: z.ZodOptional<z.ZodString>;
1359
+ wideLogoAssetId: z.ZodOptional<z.ZodString>;
1360
+ singleHolder: z.ZodOptional<z.ZodBoolean>;
1361
+ title: z.ZodOptional<z.ZodString>;
1362
+ provider: z.ZodOptional<z.ZodString>;
1363
+ shortTitle: z.ZodOptional<z.ZodString>;
1364
+ redemptionChannel: z.ZodOptional<z.ZodEnum<{
1365
+ both: "both";
1366
+ inStore: "inStore";
1367
+ online: "online";
1368
+ }>>;
1369
+ finePrint: z.ZodOptional<z.ZodString>;
1370
+ helpLink: z.ZodOptional<z.ZodObject<{
1371
+ url: z.ZodString;
1372
+ label: z.ZodOptional<z.ZodString>;
1373
+ }, z.core.$strict>>;
1374
+ }, z.core.$strict>>;
1375
+ config: z.ZodObject<{
1376
+ fields: z.ZodArray<z.ZodObject<{
1377
+ id: z.ZodOptional<z.ZodString>;
1378
+ key: z.ZodString;
1379
+ label: z.ZodString;
1380
+ binding: z.ZodEnum<{
1381
+ shared: "shared";
1382
+ perPass: "perPass";
1383
+ event: "event";
1384
+ stamps: "stamps";
1385
+ points: "points";
1386
+ stampsLeft: "stampsLeft";
1387
+ pointsToGoal: "pointsToGoal";
1388
+ expiry: "expiry";
1389
+ }>;
1390
+ required: z.ZodBoolean;
1391
+ defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
1392
+ sampleValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
1393
+ textAlignment: z.ZodOptional<z.ZodEnum<{
1394
+ left: "left";
1395
+ center: "center";
1396
+ right: "right";
1397
+ natural: "natural";
1398
+ }>>;
1399
+ event: z.ZodOptional<z.ZodEnum<{
1400
+ name: "name";
1401
+ venueName: "venueName";
1402
+ venueAddress: "venueAddress";
1403
+ doorsOpen: "doorsOpen";
1404
+ start: "start";
1405
+ end: "end";
1406
+ }>>;
1407
+ dateFormat: z.ZodOptional<z.ZodEnum<{
1408
+ date: "date";
1409
+ dateTime: "dateTime";
1410
+ time: "time";
1411
+ }>>;
1412
+ googleRole: z.ZodOptional<z.ZodEnum<{
1413
+ seat: "seat";
1414
+ row: "row";
1415
+ section: "section";
1416
+ gate: "gate";
1417
+ ticketType: "ticketType";
1418
+ }>>;
1419
+ }, z.core.$strict>>;
1420
+ layouts: z.ZodObject<{
1421
+ standard: z.ZodObject<{
1422
+ header: z.ZodDefault<z.ZodArray<z.ZodString>>;
1423
+ primary: z.ZodDefault<z.ZodArray<z.ZodString>>;
1424
+ secondary: z.ZodDefault<z.ZodArray<z.ZodString>>;
1425
+ auxiliary: z.ZodDefault<z.ZodArray<z.ZodString>>;
1426
+ back: z.ZodDefault<z.ZodArray<z.ZodString>>;
1427
+ }, z.core.$strict>;
1428
+ poster: z.ZodOptional<z.ZodObject<{
1429
+ header: z.ZodDefault<z.ZodArray<z.ZodString>>;
1430
+ primary: z.ZodDefault<z.ZodArray<z.ZodString>>;
1431
+ footer: z.ZodDefault<z.ZodArray<z.ZodString>>;
1432
+ additionalInfo: z.ZodDefault<z.ZodArray<z.ZodString>>;
1433
+ back: z.ZodDefault<z.ZodArray<z.ZodString>>;
1434
+ }, z.core.$strict>>;
1435
+ }, z.core.$strict>;
1436
+ expiry: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
1437
+ kind: z.ZodLiteral<"fixed">;
1438
+ at: z.ZodString;
1439
+ timezone: z.ZodOptional<z.ZodString>;
1440
+ }, z.core.$strict>, z.ZodObject<{
1441
+ kind: z.ZodLiteral<"afterIssue">;
1442
+ timezone: z.ZodOptional<z.ZodString>;
1443
+ days: z.ZodNumber;
1444
+ }, z.core.$strict>], "kind">>;
1445
+ notifications: z.ZodDefault<z.ZodObject<{
1446
+ apple: z.ZodOptional<z.ZodString>;
1447
+ googleTitle: z.ZodOptional<z.ZodString>;
1448
+ googleBody: z.ZodOptional<z.ZodString>;
1449
+ }, z.core.$strict>>;
1450
+ }, z.core.$strict>;
1451
+ schemaVersion: z.ZodLiteral<2>;
1452
+ description: z.ZodString;
1453
+ organizationName: z.ZodString;
1454
+ logoText: z.ZodOptional<z.ZodString>;
1455
+ colors: z.ZodObject<{
1456
+ background: z.ZodString;
1457
+ foreground: z.ZodString;
1458
+ label: z.ZodOptional<z.ZodString>;
1459
+ }, z.core.$strict>;
1460
+ barcode: z.ZodOptional<z.ZodObject<{
1461
+ format: z.ZodEnum<{
1462
+ qr: "qr";
1463
+ pdf417: "pdf417";
1464
+ aztec: "aztec";
1465
+ code128: "code128";
1466
+ }>;
1467
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
1468
+ kind: z.ZodLiteral<"static">;
1469
+ value: z.ZodString;
1470
+ }, z.core.$strict>, z.ZodObject<{
1471
+ kind: z.ZodLiteral<"passValue">;
1472
+ sampleValue: z.ZodOptional<z.ZodString>;
1473
+ }, z.core.$strict>, z.ZodObject<{
1474
+ kind: z.ZodLiteral<"serialNumber">;
1475
+ }, z.core.$strict>], "kind">;
1476
+ altText: z.ZodOptional<z.ZodString>;
1477
+ showText: z.ZodOptional<z.ZodBoolean>;
1478
+ messageEncoding: z.ZodOptional<z.ZodEnum<{
1479
+ "iso-8859-1": "iso-8859-1";
1480
+ "utf-8": "utf-8";
1481
+ "utf-16": "utf-16";
1482
+ }>>;
1483
+ }, z.core.$strict>>;
1484
+ platforms: z.ZodObject<{
1485
+ apple: z.ZodBoolean;
1486
+ google: z.ZodBoolean;
1487
+ }, z.core.$strict>;
1488
+ apple: z.ZodDefault<z.ZodObject<{
1489
+ sharingProhibited: z.ZodOptional<z.ZodBoolean>;
1490
+ hideLogoText: z.ZodOptional<z.ZodBoolean>;
1491
+ poster: z.ZodOptional<z.ZodObject<{
1492
+ enabled: z.ZodBoolean;
1493
+ brand: z.ZodEnum<{
1494
+ logo: "logo";
1495
+ text: "text";
1496
+ logoAndText: "logoAndText";
1497
+ }>;
1498
+ }, z.core.$strict>>;
1499
+ featuredActions: z.ZodOptional<z.ZodArray<z.ZodObject<{
1500
+ id: z.ZodOptional<z.ZodString>;
1501
+ key: z.ZodString;
1502
+ type: z.ZodEnum<{
1503
+ viewSchedule: "viewSchedule";
1504
+ watchTrailer: "watchTrailer";
1505
+ listenToMusic: "listenToMusic";
1506
+ call: "call";
1507
+ addToBalance: "addToBalance";
1508
+ order: "order";
1509
+ shop: "shop";
1510
+ membershipBenefits: "membershipBenefits";
1511
+ bookAppointment: "bookAppointment";
1512
+ bookCar: "bookCar";
1513
+ bookFlight: "bookFlight";
1514
+ bookStay: "bookStay";
1515
+ viewOffersRewards: "viewOffersRewards";
1516
+ }>;
1517
+ binding: z.ZodEnum<{
1518
+ perPass: "perPass";
1519
+ fixed: "fixed";
1520
+ overridable: "overridable";
1521
+ }>;
1522
+ url: z.ZodOptional<z.ZodString>;
1523
+ sampleUrl: z.ZodOptional<z.ZodString>;
1524
+ }, z.core.$strict>>>;
1525
+ }, z.core.$strict>>;
1526
+ relevance: z.ZodOptional<z.ZodObject<{
1527
+ locations: z.ZodOptional<z.ZodArray<z.ZodObject<{
1528
+ latitude: z.ZodNumber;
1529
+ longitude: z.ZodNumber;
1530
+ message: z.ZodOptional<z.ZodString>;
1531
+ }, z.core.$strict>>>;
1532
+ dates: z.ZodOptional<z.ZodArray<z.ZodObject<{
1533
+ start: z.ZodString;
1534
+ end: z.ZodString;
1535
+ }, z.core.$strict>>>;
1536
+ timezone: z.ZodOptional<z.ZodString>;
1537
+ }, z.core.$strict>>;
1239
1538
  }, z.core.$strict>], "type">;
1240
1539
  /**
1241
1540
  * `event` is never stored in a revision: signing and previews overlay the
@@ -6,6 +6,7 @@ import { CardRowsSchema, cardItemRef, resolveCardItem } from './event.js';
6
6
  import { TemplateRelevanceSchema, } from './relevance.js';
7
7
  import { StampNotificationsSchema, StampSettingsSchema, stampAssetIds, } from './stamps.js';
8
8
  import { PointsNotificationsSchema, PointsSettingsSchema } from './points.js';
9
+ import { CouponExpirySchema, CouponNotificationsSchema, HttpsUrlSchema, REDEMPTION_CHANNELS, } from './coupon.js';
9
10
  import { upgradeDefinition } from './upgrade.js';
10
11
  import { newFieldId } from './ids.js';
11
12
  export const TEMPLATE_SCHEMA_VERSION = 2;
@@ -40,6 +41,7 @@ export const EVENT_TICKET_IMAGE_SLOTS = [
40
41
  /** A stamp card's strip is drawn from its stamp settings, never uploaded. */
41
42
  export const STAMP_CARD_IMAGE_SLOTS = ['icon', 'logo', 'artwork', 'primaryLogo'];
42
43
  export const POINTS_CARD_IMAGE_SLOTS = ['icon', 'logo', 'strip', 'artwork', 'primaryLogo'];
44
+ export const COUPON_IMAGE_SLOTS = ['icon', 'logo', 'strip', 'artwork', 'primaryLogo'];
43
45
  export const ImageSlotsSchema = z.strictObject({
44
46
  icon: AssetRefSchema,
45
47
  logo: AssetRefSchema.optional(),
@@ -128,6 +130,20 @@ export const LoyaltyGoogleSettingsSchema = GoogleSettingsSchema.extend({
128
130
  memberNameField: FieldKeySchema.optional(),
129
131
  memberIdField: FieldKeySchema.optional(),
130
132
  });
133
+ /**
134
+ * A coupon's Google offer class. `title` and `provider` fall back to logo text and
135
+ * the organization name; the redemption channel defaults to both.
136
+ */
137
+ export const CouponGoogleSettingsSchema = GoogleSettingsSchema.extend({
138
+ title: z.string().trim().min(1).max(100).optional(),
139
+ provider: z.string().trim().min(1).max(100).optional(),
140
+ shortTitle: z.string().trim().min(1).max(60).optional(),
141
+ redemptionChannel: z.enum(REDEMPTION_CHANNELS).optional(),
142
+ finePrint: z.string().trim().min(1).max(2000).optional(),
143
+ helpLink: z
144
+ .strictObject({ url: HttpsUrlSchema, label: z.string().trim().min(1).max(100).optional() })
145
+ .optional(),
146
+ });
131
147
  /** Design fields shared by every template type. `name` lives on the row, not here. */
132
148
  const sharedShape = {
133
149
  schemaVersion: z.literal(TEMPLATE_SCHEMA_VERSION),
@@ -178,6 +194,15 @@ export const PointsCardConfigSchema = z.strictObject({
178
194
  points: PointsSettingsSchema,
179
195
  notifications: PointsNotificationsSchema.default({}),
180
196
  });
197
+ export const CouponConfigSchema = z.strictObject({
198
+ fields: FieldListSchema,
199
+ layouts: z.strictObject({
200
+ standard: StandardLayoutSchema,
201
+ poster: PosterLayoutSchema.optional(),
202
+ }),
203
+ expiry: CouponExpirySchema.optional(),
204
+ notifications: CouponNotificationsSchema.default({}),
205
+ });
181
206
  export const RESERVED_FIELD_KEY_PREFIX = 'tapace_';
182
207
  /**
183
208
  * The template definition: shared design fields plus a `type`-discriminated
@@ -214,6 +239,13 @@ export const TemplateDefinitionSchema = z
214
239
  google: LoyaltyGoogleSettingsSchema.default({}),
215
240
  config: PointsCardConfigSchema,
216
241
  }),
242
+ z.strictObject({
243
+ ...sharedShape,
244
+ type: z.literal('coupon'),
245
+ images: PointsCardImageSlotsSchema,
246
+ google: CouponGoogleSettingsSchema.default({}),
247
+ config: CouponConfigSchema,
248
+ }),
217
249
  ])
218
250
  .superRefine((def, ctx) => {
219
251
  const fields = def.config.fields;
@@ -320,6 +352,13 @@ export const TemplateDefinitionSchema = z
320
352
  path: ['config', 'fields', index, 'binding'],
321
353
  });
322
354
  }
355
+ if (f.binding === 'expiry' && def.type !== 'coupon') {
356
+ ctx.addIssue({
357
+ code: 'custom',
358
+ message: 'The expiry field is for coupon templates.',
359
+ path: ['config', 'fields', index, 'binding'],
360
+ });
361
+ }
323
362
  if (f.binding === 'pointsToGoal' &&
324
363
  def.type === 'points_card' &&
325
364
  def.config.points.goal === undefined) {
@@ -335,6 +374,7 @@ export const TemplateDefinitionSchema = z
335
374
  ['points', 'A points card has one points field.'],
336
375
  ['stampsLeft', 'A stamp card has one stamps left field.'],
337
376
  ['pointsToGoal', 'A points card has one points to goal field.'],
377
+ ['expiry', 'A coupon has one expiry field.'],
338
378
  ];
339
379
  for (const [binding, message] of ONE_FIELD) {
340
380
  if (fields.filter((f) => f.binding === binding).length > 1) {
@@ -397,6 +437,13 @@ export const TemplateDefinitionSchema = z
397
437
  }
398
438
  }
399
439
  }
440
+ if (def.type === 'coupon') {
441
+ notificationTexts(def.config.notifications, [
442
+ ['apple', def.platforms.apple],
443
+ ['googleTitle', def.platforms.google],
444
+ ['googleBody', def.platforms.google],
445
+ ], 'Write the notification text for redeeming.');
446
+ }
400
447
  if (def.type === 'stamp_card') {
401
448
  if (def.config.layouts.standard.primary.length > 0) {
402
449
  ctx.addIssue({
@@ -678,6 +725,8 @@ export function imageSlotsOf(def) {
678
725
  return STAMP_CARD_IMAGE_SLOTS;
679
726
  case 'points_card':
680
727
  return POINTS_CARD_IMAGE_SLOTS;
728
+ case 'coupon':
729
+ return COUPON_IMAGE_SLOTS;
681
730
  case 'generic':
682
731
  return GENERIC_IMAGE_SLOTS;
683
732
  }
@@ -27,6 +27,8 @@ export declare function isEventTime(value: EventValue): value is EventTimeValue;
27
27
  * - `stampsLeft` — stamps still to earn, as "3"; stamp card templates only.
28
28
  * - `pointsToGoal` — points still to the goal, as "160"; points card templates
29
29
  * with a goal only.
30
+ * - `expiry` — the pass's expiry date and time, formatted by Apple on the device;
31
+ * Google shows the expiry natively instead. Coupon templates only.
30
32
  *
31
33
  * `googleRole` makes a per-pass field Google's native seat, row, section, gate or
32
34
  * ticket type on an event ticket; Apple shows it as an ordinary field.
@@ -47,6 +49,7 @@ export declare const FieldDefSchema: z.ZodObject<{
47
49
  points: "points";
48
50
  stampsLeft: "stampsLeft";
49
51
  pointsToGoal: "pointsToGoal";
52
+ expiry: "expiry";
50
53
  }>;
51
54
  required: z.ZodBoolean;
52
55
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -120,6 +123,7 @@ export declare const FieldListSchema: z.ZodArray<z.ZodObject<{
120
123
  points: "points";
121
124
  stampsLeft: "stampsLeft";
122
125
  pointsToGoal: "pointsToGoal";
126
+ expiry: "expiry";
123
127
  }>;
124
128
  required: z.ZodBoolean;
125
129
  defaultValue: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
@@ -28,6 +28,8 @@ export function isEventTime(value) {
28
28
  * - `stampsLeft` — stamps still to earn, as "3"; stamp card templates only.
29
29
  * - `pointsToGoal` — points still to the goal, as "160"; points card templates
30
30
  * with a goal only.
31
+ * - `expiry` — the pass's expiry date and time, formatted by Apple on the device;
32
+ * Google shows the expiry natively instead. Coupon templates only.
31
33
  *
32
34
  * `googleRole` makes a per-pass field Google's native seat, row, section, gate or
33
35
  * ticket type on an event ticket; Apple shows it as an ordinary field.
@@ -41,7 +43,7 @@ export const FieldDefSchema = z
41
43
  id: z.string().regex(FIELD_ID_RE, 'Invalid field id').optional(),
42
44
  key: FieldKeySchema,
43
45
  label: z.string().min(1).max(64),
44
- binding: z.enum(['shared', 'perPass', 'event', 'stamps', 'points', 'stampsLeft', 'pointsToGoal']),
46
+ binding: z.enum(['shared', 'perPass', 'event', 'stamps', 'points', 'stampsLeft', 'pointsToGoal', 'expiry']),
45
47
  required: z.boolean(),
46
48
  defaultValue: FieldValueSchema.optional(),
47
49
  sampleValue: FieldValueSchema.optional(),
@@ -99,6 +101,13 @@ export const FieldDefSchema = z
99
101
  });
100
102
  }
101
103
  }
104
+ else if (f.binding === 'expiry' && f.defaultValue !== undefined) {
105
+ ctx.addIssue({
106
+ code: 'custom',
107
+ message: 'The expiry field takes its value from the pass.',
108
+ path: ['defaultValue'],
109
+ });
110
+ }
102
111
  if (f.binding !== 'event' && (f.event !== undefined || f.dateFormat !== undefined)) {
103
112
  ctx.addIssue({
104
113
  code: 'custom',
@@ -5,5 +5,6 @@ export * from './relevance.js';
5
5
  export * from './event.js';
6
6
  export * from './stamps.js';
7
7
  export * from './points.js';
8
+ export * from './coupon.js';
8
9
  export * from './definition.js';
9
10
  export * from './upgrade.js';
@@ -5,5 +5,6 @@ export * from './relevance.js';
5
5
  export * from './event.js';
6
6
  export * from './stamps.js';
7
7
  export * from './points.js';
8
+ export * from './coupon.js';
8
9
  export * from './definition.js';
9
10
  export * from './upgrade.js';
@@ -2,4 +2,4 @@ export * from './contract/index.js';
2
2
  export * from './compiler/template-preview.js';
3
3
  export { previewStampCount } from './compiler/stamp-card.js';
4
4
  export type { CompileIssue } from './compiler/passmint-compiler.js';
5
- export type { ApplePreview, BarcodePreview, FieldPreview, GoogleCardItemPreview, GoogleEventPreview, GoogleLoyaltyPreview, GooglePreview, PosterPreview, PreviewStyle, } from './compiler/preview-model.js';
5
+ export type { ApplePreview, BarcodePreview, FieldPreview, GoogleCardItemPreview, GoogleEventPreview, GoogleLoyaltyPreview, GoogleOfferPreview, GooglePreview, PosterPreview, PreviewStyle, } from './compiler/preview-model.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owask/tapace-templates",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "TapAce template contract and wallet preview compiler, shared by the API and the dashboard.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "files": ["dist"],
15
15
  "dependencies": {
16
- "passmint": "npm:@owask/passmint@0.7.0-tapace.6",
16
+ "passmint": "npm:@owask/passmint@0.7.0-tapace.7",
17
17
  "zod": "^4.5.4"
18
18
  },
19
19
  "publishConfig": {