passlet 0.2.1 → 0.2.3
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 +120 -16
- package/dist/index.cjs +75 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -16
- package/dist/index.d.ts +117 -16
- package/dist/index.js +75 -10
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -25,38 +25,42 @@ declare class WalletError extends Error {
|
|
|
25
25
|
constructor(code: WalletErrorCode, message?: string, options?: ErrorOptions);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** Credentials for signing Apple Wallet `.pkpass` files. */
|
|
28
29
|
interface AppleCredentials {
|
|
29
|
-
/** @example "pass.com.yourcompany.
|
|
30
|
+
/** Pass type identifier registered in your Apple Developer account. @example "pass.com.yourcompany.app" */
|
|
30
31
|
passTypeIdentifier: string;
|
|
31
|
-
/** PEM-encoded pass signing certificate. */
|
|
32
|
+
/** PEM-encoded pass signing certificate from Apple Developer. */
|
|
32
33
|
signerCert: string;
|
|
33
|
-
/** PEM-encoded private key paired with
|
|
34
|
+
/** PEM-encoded private key paired with `signerCert`. */
|
|
34
35
|
signerKey: string;
|
|
35
36
|
/** Your 10-character Apple Team ID. @example "ABCD1234EF" */
|
|
36
37
|
teamId: string;
|
|
37
38
|
/** PEM-encoded Apple WWDR intermediate certificate. */
|
|
38
39
|
wwdr: string;
|
|
39
40
|
}
|
|
41
|
+
/** Credentials for signing Google Wallet JWTs and calling the Wallet REST API. */
|
|
40
42
|
interface GoogleCredentials {
|
|
41
|
-
/** client_email from your Google Cloud service account JSON key. */
|
|
43
|
+
/** `client_email` from your Google Cloud service account JSON key. */
|
|
42
44
|
clientEmail: string;
|
|
43
|
-
/**
|
|
45
|
+
/** Issuer ID from the Google Pay & Wallet Console. */
|
|
44
46
|
issuerId: string;
|
|
45
|
-
/** private_key from your Google Cloud service account JSON key (PKCS#8 PEM). */
|
|
47
|
+
/** `private_key` from your Google Cloud service account JSON key (PKCS#8 PEM). */
|
|
46
48
|
privateKey: string;
|
|
47
49
|
}
|
|
50
|
+
/** Credentials passed to {@link Wallet}. Omit a provider to skip that platform. */
|
|
48
51
|
interface WalletCredentials {
|
|
49
|
-
/** Apple Wallet credentials.
|
|
52
|
+
/** Apple Wallet credentials. Required to generate `.pkpass` files. */
|
|
50
53
|
apple?: AppleCredentials;
|
|
51
|
-
/** Google Wallet credentials.
|
|
54
|
+
/** Google Wallet credentials. Required to generate Google Wallet JWTs. */
|
|
52
55
|
google?: GoogleCredentials;
|
|
53
56
|
}
|
|
57
|
+
/** Result of {@link Pass.create}. */
|
|
54
58
|
interface IssuedPass {
|
|
55
|
-
/**
|
|
59
|
+
/** Signed `.pkpass` archive ready to serve, or `null` if Apple credentials were omitted. */
|
|
56
60
|
apple: Uint8Array | null;
|
|
57
|
-
/** Signed
|
|
61
|
+
/** Signed JWT for a Google Wallet save link (`pay.google.com/gp/v/save/<jwt>`), or `null` if Google credentials were omitted. */
|
|
58
62
|
google: string | null;
|
|
59
|
-
/** Non-fatal
|
|
63
|
+
/** Non-fatal notices — e.g. a missing optional image or an unset recommended field. */
|
|
60
64
|
warnings: string[];
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -2376,36 +2380,133 @@ type AppLinkData = z.infer<typeof googleAppLinkDataSchema>;
|
|
|
2376
2380
|
|
|
2377
2381
|
type FieldOptions = Omit<FieldDef, "slot" | "key" | "label">;
|
|
2378
2382
|
type FieldArg = string | FieldOptions;
|
|
2383
|
+
/**
|
|
2384
|
+
* Builders for pass display fields. Pass the result into the `fields` array
|
|
2385
|
+
* of any pass config.
|
|
2386
|
+
*
|
|
2387
|
+
* The third argument is either a string (shorthand for `value`) or a full
|
|
2388
|
+
* {@link FieldDef} options object for formatting, alignment, and more.
|
|
2389
|
+
*
|
|
2390
|
+
* @example
|
|
2391
|
+
* fields: [
|
|
2392
|
+
* field.primary("points", "Points", "1 250"),
|
|
2393
|
+
* field.secondary("tier", "Tier", "Gold"),
|
|
2394
|
+
* field.back("terms", "Terms", { value: "No refunds." }),
|
|
2395
|
+
* ]
|
|
2396
|
+
*/
|
|
2379
2397
|
declare const field: {
|
|
2380
|
-
/**
|
|
2398
|
+
/**
|
|
2399
|
+
* Top-right corner of the pass. Space is limited — use at most one field.
|
|
2400
|
+
*
|
|
2401
|
+
* Apple → `headerFields`. Google → `textModulesData`.
|
|
2402
|
+
*/
|
|
2381
2403
|
header: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2382
|
-
/**
|
|
2404
|
+
/**
|
|
2405
|
+
* Large, prominent area below the logo.
|
|
2406
|
+
*
|
|
2407
|
+
* Apple → `primaryFields`. Google → `subheader` (label) + `header` (value).
|
|
2408
|
+
* On boarding passes, Apple renders a transit icon between the two primary fields,
|
|
2409
|
+
* so place departure on the left and arrival on the right.
|
|
2410
|
+
*/
|
|
2383
2411
|
primary: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2384
|
-
/**
|
|
2412
|
+
/**
|
|
2413
|
+
* Row below the primary area.
|
|
2414
|
+
*
|
|
2415
|
+
* Apple → `secondaryFields`. Google → `textModulesData`.
|
|
2416
|
+
*/
|
|
2385
2417
|
secondary: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2386
|
-
/**
|
|
2418
|
+
/**
|
|
2419
|
+
* Row below secondary. Supports two rows — pass `{ row: 0 }` or `{ row: 1 }` to assign.
|
|
2420
|
+
*
|
|
2421
|
+
* Apple → `auxiliaryFields`. Google → `textModulesData`.
|
|
2422
|
+
*/
|
|
2387
2423
|
auxiliary: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2388
|
-
/**
|
|
2424
|
+
/**
|
|
2425
|
+
* Back of the pass — visible only when the user flips it over.
|
|
2426
|
+
* Good for terms, redemption instructions, or contact info.
|
|
2427
|
+
*
|
|
2428
|
+
* Apple → `backFields`. Google → `infoModuleData`.
|
|
2429
|
+
*/
|
|
2389
2430
|
back: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2390
2431
|
};
|
|
2432
|
+
/**
|
|
2433
|
+
* A configured pass template. Obtain one from {@link Wallet} rather than
|
|
2434
|
+
* constructing directly.
|
|
2435
|
+
*
|
|
2436
|
+
* Config is validated at construction time — a {@link WalletError} with code
|
|
2437
|
+
* `PASS_CONFIG_INVALID` is thrown immediately if anything is wrong.
|
|
2438
|
+
*/
|
|
2391
2439
|
declare class Pass {
|
|
2392
2440
|
private readonly config;
|
|
2393
2441
|
private readonly credentials;
|
|
2394
2442
|
constructor(config: PassConfig, credentials: WalletCredentials);
|
|
2443
|
+
/**
|
|
2444
|
+
* Issue a pass to a recipient. Runs both providers in parallel.
|
|
2445
|
+
*
|
|
2446
|
+
* Returns an {@link IssuedPass} with:
|
|
2447
|
+
* - `apple` — a `.pkpass` `Uint8Array` ready to serve, or `null` if Apple credentials were omitted.
|
|
2448
|
+
* - `google` — a signed JWT for the Google Wallet save link, or `null` if Google credentials were omitted.
|
|
2449
|
+
* - `warnings` — non-fatal notices (e.g. a missing optional image).
|
|
2450
|
+
*
|
|
2451
|
+
* @throws {WalletError} `CREATE_CONFIG_INVALID` if `createConfig` fails validation.
|
|
2452
|
+
*/
|
|
2395
2453
|
create(createConfig: CreateConfig): Promise<IssuedPass>;
|
|
2454
|
+
/**
|
|
2455
|
+
* Push updated field values to an already-issued pass.
|
|
2456
|
+
*
|
|
2457
|
+
* Google: PATCHes the object via the Wallet REST API (the pass must have been
|
|
2458
|
+
* saved to a wallet first). Apple: no-op — Apple passes update when the holder
|
|
2459
|
+
* re-downloads the pass via your web service.
|
|
2460
|
+
*/
|
|
2396
2461
|
update(createConfig: CreateConfig): Promise<void>;
|
|
2462
|
+
/**
|
|
2463
|
+
* Permanently delete a pass.
|
|
2464
|
+
*
|
|
2465
|
+
* Google: removes the object via the Wallet REST API.
|
|
2466
|
+
* Apple: no-op — Apple passes cannot be remotely deleted; use {@link expire} to invalidate them.
|
|
2467
|
+
*/
|
|
2397
2468
|
delete(serialNumber: string): Promise<void>;
|
|
2469
|
+
/**
|
|
2470
|
+
* Mark a pass as expired / invalid.
|
|
2471
|
+
*
|
|
2472
|
+
* Google: transitions the object state to `EXPIRED` via the Wallet REST API.
|
|
2473
|
+
* Apple: no-op — Apple passes expire automatically when `expiresAt` is reached,
|
|
2474
|
+
* or you can set `apple.voided: true` at issue time via {@link create}.
|
|
2475
|
+
*/
|
|
2398
2476
|
expire(serialNumber: string): Promise<void>;
|
|
2399
2477
|
}
|
|
2400
2478
|
|
|
2479
|
+
/**
|
|
2480
|
+
* Entry point for building passes. Construct once with your credentials,
|
|
2481
|
+
* then call the pass-type methods to get a {@link Pass} you can issue.
|
|
2482
|
+
*
|
|
2483
|
+
* Omit a provider's credentials to skip that platform entirely —
|
|
2484
|
+
* `apple` and `google` are both optional.
|
|
2485
|
+
*
|
|
2486
|
+
* @example
|
|
2487
|
+
* const wallet = new Wallet({ apple: appleCredentials, google: googleCredentials });
|
|
2488
|
+
* const result = await wallet.loyalty({ id: "rewards", name: "Rewards Card", fields: [] })
|
|
2489
|
+
* .create({ serialNumber: "user-123" });
|
|
2490
|
+
*/
|
|
2401
2491
|
declare class Wallet {
|
|
2402
2492
|
private readonly credentials;
|
|
2403
2493
|
constructor(credentials: WalletCredentials);
|
|
2494
|
+
/** Create a loyalty / rewards card pass. */
|
|
2404
2495
|
loyalty(config: Omit<LoyaltyPassConfig, "type">): Pass;
|
|
2496
|
+
/** Create an event ticket pass. */
|
|
2405
2497
|
event(config: Omit<EventPassConfig, "type">): Pass;
|
|
2498
|
+
/**
|
|
2499
|
+
* Create a boarding pass. Covers air, train, bus, and boat transit.
|
|
2500
|
+
*
|
|
2501
|
+
* Apple boarding passes render a transit icon between the two `primary` fields,
|
|
2502
|
+
* so use `field.primary()` for the departure and arrival locations.
|
|
2503
|
+
*/
|
|
2406
2504
|
flight(config: Omit<FlightPassConfig, "type">): Pass;
|
|
2505
|
+
/** Create a coupon / offer pass. */
|
|
2407
2506
|
coupon(config: Omit<CouponPassConfig, "type">): Pass;
|
|
2507
|
+
/** Create a gift card pass. */
|
|
2408
2508
|
giftCard(config: Omit<GiftCardPassConfig, "type">): Pass;
|
|
2509
|
+
/** Create a generic pass for anything that doesn't fit the other types. */
|
|
2409
2510
|
generic(config: Omit<GenericPassConfig, "type">): Pass;
|
|
2410
2511
|
}
|
|
2411
2512
|
|
package/dist/index.d.ts
CHANGED
|
@@ -25,38 +25,42 @@ declare class WalletError extends Error {
|
|
|
25
25
|
constructor(code: WalletErrorCode, message?: string, options?: ErrorOptions);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** Credentials for signing Apple Wallet `.pkpass` files. */
|
|
28
29
|
interface AppleCredentials {
|
|
29
|
-
/** @example "pass.com.yourcompany.
|
|
30
|
+
/** Pass type identifier registered in your Apple Developer account. @example "pass.com.yourcompany.app" */
|
|
30
31
|
passTypeIdentifier: string;
|
|
31
|
-
/** PEM-encoded pass signing certificate. */
|
|
32
|
+
/** PEM-encoded pass signing certificate from Apple Developer. */
|
|
32
33
|
signerCert: string;
|
|
33
|
-
/** PEM-encoded private key paired with
|
|
34
|
+
/** PEM-encoded private key paired with `signerCert`. */
|
|
34
35
|
signerKey: string;
|
|
35
36
|
/** Your 10-character Apple Team ID. @example "ABCD1234EF" */
|
|
36
37
|
teamId: string;
|
|
37
38
|
/** PEM-encoded Apple WWDR intermediate certificate. */
|
|
38
39
|
wwdr: string;
|
|
39
40
|
}
|
|
41
|
+
/** Credentials for signing Google Wallet JWTs and calling the Wallet REST API. */
|
|
40
42
|
interface GoogleCredentials {
|
|
41
|
-
/** client_email from your Google Cloud service account JSON key. */
|
|
43
|
+
/** `client_email` from your Google Cloud service account JSON key. */
|
|
42
44
|
clientEmail: string;
|
|
43
|
-
/**
|
|
45
|
+
/** Issuer ID from the Google Pay & Wallet Console. */
|
|
44
46
|
issuerId: string;
|
|
45
|
-
/** private_key from your Google Cloud service account JSON key (PKCS#8 PEM). */
|
|
47
|
+
/** `private_key` from your Google Cloud service account JSON key (PKCS#8 PEM). */
|
|
46
48
|
privateKey: string;
|
|
47
49
|
}
|
|
50
|
+
/** Credentials passed to {@link Wallet}. Omit a provider to skip that platform. */
|
|
48
51
|
interface WalletCredentials {
|
|
49
|
-
/** Apple Wallet credentials.
|
|
52
|
+
/** Apple Wallet credentials. Required to generate `.pkpass` files. */
|
|
50
53
|
apple?: AppleCredentials;
|
|
51
|
-
/** Google Wallet credentials.
|
|
54
|
+
/** Google Wallet credentials. Required to generate Google Wallet JWTs. */
|
|
52
55
|
google?: GoogleCredentials;
|
|
53
56
|
}
|
|
57
|
+
/** Result of {@link Pass.create}. */
|
|
54
58
|
interface IssuedPass {
|
|
55
|
-
/**
|
|
59
|
+
/** Signed `.pkpass` archive ready to serve, or `null` if Apple credentials were omitted. */
|
|
56
60
|
apple: Uint8Array | null;
|
|
57
|
-
/** Signed
|
|
61
|
+
/** Signed JWT for a Google Wallet save link (`pay.google.com/gp/v/save/<jwt>`), or `null` if Google credentials were omitted. */
|
|
58
62
|
google: string | null;
|
|
59
|
-
/** Non-fatal
|
|
63
|
+
/** Non-fatal notices — e.g. a missing optional image or an unset recommended field. */
|
|
60
64
|
warnings: string[];
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -2376,36 +2380,133 @@ type AppLinkData = z.infer<typeof googleAppLinkDataSchema>;
|
|
|
2376
2380
|
|
|
2377
2381
|
type FieldOptions = Omit<FieldDef, "slot" | "key" | "label">;
|
|
2378
2382
|
type FieldArg = string | FieldOptions;
|
|
2383
|
+
/**
|
|
2384
|
+
* Builders for pass display fields. Pass the result into the `fields` array
|
|
2385
|
+
* of any pass config.
|
|
2386
|
+
*
|
|
2387
|
+
* The third argument is either a string (shorthand for `value`) or a full
|
|
2388
|
+
* {@link FieldDef} options object for formatting, alignment, and more.
|
|
2389
|
+
*
|
|
2390
|
+
* @example
|
|
2391
|
+
* fields: [
|
|
2392
|
+
* field.primary("points", "Points", "1 250"),
|
|
2393
|
+
* field.secondary("tier", "Tier", "Gold"),
|
|
2394
|
+
* field.back("terms", "Terms", { value: "No refunds." }),
|
|
2395
|
+
* ]
|
|
2396
|
+
*/
|
|
2379
2397
|
declare const field: {
|
|
2380
|
-
/**
|
|
2398
|
+
/**
|
|
2399
|
+
* Top-right corner of the pass. Space is limited — use at most one field.
|
|
2400
|
+
*
|
|
2401
|
+
* Apple → `headerFields`. Google → `textModulesData`.
|
|
2402
|
+
*/
|
|
2381
2403
|
header: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2382
|
-
/**
|
|
2404
|
+
/**
|
|
2405
|
+
* Large, prominent area below the logo.
|
|
2406
|
+
*
|
|
2407
|
+
* Apple → `primaryFields`. Google → `subheader` (label) + `header` (value).
|
|
2408
|
+
* On boarding passes, Apple renders a transit icon between the two primary fields,
|
|
2409
|
+
* so place departure on the left and arrival on the right.
|
|
2410
|
+
*/
|
|
2383
2411
|
primary: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2384
|
-
/**
|
|
2412
|
+
/**
|
|
2413
|
+
* Row below the primary area.
|
|
2414
|
+
*
|
|
2415
|
+
* Apple → `secondaryFields`. Google → `textModulesData`.
|
|
2416
|
+
*/
|
|
2385
2417
|
secondary: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2386
|
-
/**
|
|
2418
|
+
/**
|
|
2419
|
+
* Row below secondary. Supports two rows — pass `{ row: 0 }` or `{ row: 1 }` to assign.
|
|
2420
|
+
*
|
|
2421
|
+
* Apple → `auxiliaryFields`. Google → `textModulesData`.
|
|
2422
|
+
*/
|
|
2387
2423
|
auxiliary: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2388
|
-
/**
|
|
2424
|
+
/**
|
|
2425
|
+
* Back of the pass — visible only when the user flips it over.
|
|
2426
|
+
* Good for terms, redemption instructions, or contact info.
|
|
2427
|
+
*
|
|
2428
|
+
* Apple → `backFields`. Google → `infoModuleData`.
|
|
2429
|
+
*/
|
|
2389
2430
|
back: (key: string, label: string, arg?: FieldArg) => FieldDef;
|
|
2390
2431
|
};
|
|
2432
|
+
/**
|
|
2433
|
+
* A configured pass template. Obtain one from {@link Wallet} rather than
|
|
2434
|
+
* constructing directly.
|
|
2435
|
+
*
|
|
2436
|
+
* Config is validated at construction time — a {@link WalletError} with code
|
|
2437
|
+
* `PASS_CONFIG_INVALID` is thrown immediately if anything is wrong.
|
|
2438
|
+
*/
|
|
2391
2439
|
declare class Pass {
|
|
2392
2440
|
private readonly config;
|
|
2393
2441
|
private readonly credentials;
|
|
2394
2442
|
constructor(config: PassConfig, credentials: WalletCredentials);
|
|
2443
|
+
/**
|
|
2444
|
+
* Issue a pass to a recipient. Runs both providers in parallel.
|
|
2445
|
+
*
|
|
2446
|
+
* Returns an {@link IssuedPass} with:
|
|
2447
|
+
* - `apple` — a `.pkpass` `Uint8Array` ready to serve, or `null` if Apple credentials were omitted.
|
|
2448
|
+
* - `google` — a signed JWT for the Google Wallet save link, or `null` if Google credentials were omitted.
|
|
2449
|
+
* - `warnings` — non-fatal notices (e.g. a missing optional image).
|
|
2450
|
+
*
|
|
2451
|
+
* @throws {WalletError} `CREATE_CONFIG_INVALID` if `createConfig` fails validation.
|
|
2452
|
+
*/
|
|
2395
2453
|
create(createConfig: CreateConfig): Promise<IssuedPass>;
|
|
2454
|
+
/**
|
|
2455
|
+
* Push updated field values to an already-issued pass.
|
|
2456
|
+
*
|
|
2457
|
+
* Google: PATCHes the object via the Wallet REST API (the pass must have been
|
|
2458
|
+
* saved to a wallet first). Apple: no-op — Apple passes update when the holder
|
|
2459
|
+
* re-downloads the pass via your web service.
|
|
2460
|
+
*/
|
|
2396
2461
|
update(createConfig: CreateConfig): Promise<void>;
|
|
2462
|
+
/**
|
|
2463
|
+
* Permanently delete a pass.
|
|
2464
|
+
*
|
|
2465
|
+
* Google: removes the object via the Wallet REST API.
|
|
2466
|
+
* Apple: no-op — Apple passes cannot be remotely deleted; use {@link expire} to invalidate them.
|
|
2467
|
+
*/
|
|
2397
2468
|
delete(serialNumber: string): Promise<void>;
|
|
2469
|
+
/**
|
|
2470
|
+
* Mark a pass as expired / invalid.
|
|
2471
|
+
*
|
|
2472
|
+
* Google: transitions the object state to `EXPIRED` via the Wallet REST API.
|
|
2473
|
+
* Apple: no-op — Apple passes expire automatically when `expiresAt` is reached,
|
|
2474
|
+
* or you can set `apple.voided: true` at issue time via {@link create}.
|
|
2475
|
+
*/
|
|
2398
2476
|
expire(serialNumber: string): Promise<void>;
|
|
2399
2477
|
}
|
|
2400
2478
|
|
|
2479
|
+
/**
|
|
2480
|
+
* Entry point for building passes. Construct once with your credentials,
|
|
2481
|
+
* then call the pass-type methods to get a {@link Pass} you can issue.
|
|
2482
|
+
*
|
|
2483
|
+
* Omit a provider's credentials to skip that platform entirely —
|
|
2484
|
+
* `apple` and `google` are both optional.
|
|
2485
|
+
*
|
|
2486
|
+
* @example
|
|
2487
|
+
* const wallet = new Wallet({ apple: appleCredentials, google: googleCredentials });
|
|
2488
|
+
* const result = await wallet.loyalty({ id: "rewards", name: "Rewards Card", fields: [] })
|
|
2489
|
+
* .create({ serialNumber: "user-123" });
|
|
2490
|
+
*/
|
|
2401
2491
|
declare class Wallet {
|
|
2402
2492
|
private readonly credentials;
|
|
2403
2493
|
constructor(credentials: WalletCredentials);
|
|
2494
|
+
/** Create a loyalty / rewards card pass. */
|
|
2404
2495
|
loyalty(config: Omit<LoyaltyPassConfig, "type">): Pass;
|
|
2496
|
+
/** Create an event ticket pass. */
|
|
2405
2497
|
event(config: Omit<EventPassConfig, "type">): Pass;
|
|
2498
|
+
/**
|
|
2499
|
+
* Create a boarding pass. Covers air, train, bus, and boat transit.
|
|
2500
|
+
*
|
|
2501
|
+
* Apple boarding passes render a transit icon between the two `primary` fields,
|
|
2502
|
+
* so use `field.primary()` for the departure and arrival locations.
|
|
2503
|
+
*/
|
|
2406
2504
|
flight(config: Omit<FlightPassConfig, "type">): Pass;
|
|
2505
|
+
/** Create a coupon / offer pass. */
|
|
2407
2506
|
coupon(config: Omit<CouponPassConfig, "type">): Pass;
|
|
2507
|
+
/** Create a gift card pass. */
|
|
2408
2508
|
giftCard(config: Omit<GiftCardPassConfig, "type">): Pass;
|
|
2509
|
+
/** Create a generic pass for anything that doesn't fit the other types. */
|
|
2409
2510
|
generic(config: Omit<GenericPassConfig, "type">): Pass;
|
|
2410
2511
|
}
|
|
2411
2512
|
|
package/dist/index.js
CHANGED
|
@@ -574,6 +574,12 @@ function validateGoogleRequirements(pass) {
|
|
|
574
574
|
"Google Wallet logo must be a URL string, not bytes"
|
|
575
575
|
);
|
|
576
576
|
}
|
|
577
|
+
if (pass.type === "loyalty" && !pass.logo) {
|
|
578
|
+
throw new WalletError(
|
|
579
|
+
"GOOGLE_MISSING_LOGO",
|
|
580
|
+
"Google Wallet loyalty passes require a logo URL (programLogo)"
|
|
581
|
+
);
|
|
582
|
+
}
|
|
577
583
|
if (pass.type === "flight") {
|
|
578
584
|
const { carrier, flightNumber, origin, destination } = pass;
|
|
579
585
|
if (!(carrier && flightNumber && origin && destination)) {
|
|
@@ -1232,35 +1238,58 @@ function resolveOptions(arg) {
|
|
|
1232
1238
|
return typeof arg === "string" ? { value: arg } : arg;
|
|
1233
1239
|
}
|
|
1234
1240
|
var field = {
|
|
1235
|
-
/**
|
|
1241
|
+
/**
|
|
1242
|
+
* Top-right corner of the pass. Space is limited — use at most one field.
|
|
1243
|
+
*
|
|
1244
|
+
* Apple → `headerFields`. Google → `textModulesData`.
|
|
1245
|
+
*/
|
|
1236
1246
|
header: (key, label, arg) => ({
|
|
1237
1247
|
slot: "header",
|
|
1238
1248
|
key,
|
|
1239
1249
|
label,
|
|
1240
1250
|
...resolveOptions(arg)
|
|
1241
1251
|
}),
|
|
1242
|
-
/**
|
|
1252
|
+
/**
|
|
1253
|
+
* Large, prominent area below the logo.
|
|
1254
|
+
*
|
|
1255
|
+
* Apple → `primaryFields`. Google → `subheader` (label) + `header` (value).
|
|
1256
|
+
* On boarding passes, Apple renders a transit icon between the two primary fields,
|
|
1257
|
+
* so place departure on the left and arrival on the right.
|
|
1258
|
+
*/
|
|
1243
1259
|
primary: (key, label, arg) => ({
|
|
1244
1260
|
slot: "primary",
|
|
1245
1261
|
key,
|
|
1246
1262
|
label,
|
|
1247
1263
|
...resolveOptions(arg)
|
|
1248
1264
|
}),
|
|
1249
|
-
/**
|
|
1265
|
+
/**
|
|
1266
|
+
* Row below the primary area.
|
|
1267
|
+
*
|
|
1268
|
+
* Apple → `secondaryFields`. Google → `textModulesData`.
|
|
1269
|
+
*/
|
|
1250
1270
|
secondary: (key, label, arg) => ({
|
|
1251
1271
|
slot: "secondary",
|
|
1252
1272
|
key,
|
|
1253
1273
|
label,
|
|
1254
1274
|
...resolveOptions(arg)
|
|
1255
1275
|
}),
|
|
1256
|
-
/**
|
|
1276
|
+
/**
|
|
1277
|
+
* Row below secondary. Supports two rows — pass `{ row: 0 }` or `{ row: 1 }` to assign.
|
|
1278
|
+
*
|
|
1279
|
+
* Apple → `auxiliaryFields`. Google → `textModulesData`.
|
|
1280
|
+
*/
|
|
1257
1281
|
auxiliary: (key, label, arg) => ({
|
|
1258
1282
|
slot: "auxiliary",
|
|
1259
1283
|
key,
|
|
1260
1284
|
label,
|
|
1261
1285
|
...resolveOptions(arg)
|
|
1262
1286
|
}),
|
|
1263
|
-
/**
|
|
1287
|
+
/**
|
|
1288
|
+
* Back of the pass — visible only when the user flips it over.
|
|
1289
|
+
* Good for terms, redemption instructions, or contact info.
|
|
1290
|
+
*
|
|
1291
|
+
* Apple → `backFields`. Google → `infoModuleData`.
|
|
1292
|
+
*/
|
|
1264
1293
|
back: (key, label, arg) => ({
|
|
1265
1294
|
slot: "back",
|
|
1266
1295
|
key,
|
|
@@ -1294,6 +1323,16 @@ var Pass = class {
|
|
|
1294
1323
|
this.config = config;
|
|
1295
1324
|
this.credentials = credentials;
|
|
1296
1325
|
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Issue a pass to a recipient. Runs both providers in parallel.
|
|
1328
|
+
*
|
|
1329
|
+
* Returns an {@link IssuedPass} with:
|
|
1330
|
+
* - `apple` — a `.pkpass` `Uint8Array` ready to serve, or `null` if Apple credentials were omitted.
|
|
1331
|
+
* - `google` — a signed JWT for the Google Wallet save link, or `null` if Google credentials were omitted.
|
|
1332
|
+
* - `warnings` — non-fatal notices (e.g. a missing optional image).
|
|
1333
|
+
*
|
|
1334
|
+
* @throws {WalletError} `CREATE_CONFIG_INVALID` if `createConfig` fails validation.
|
|
1335
|
+
*/
|
|
1297
1336
|
async create(createConfig) {
|
|
1298
1337
|
validateCreateConfig(createConfig);
|
|
1299
1338
|
const [appleResult, googleResult] = await Promise.allSettled([
|
|
@@ -1312,7 +1351,13 @@ var Pass = class {
|
|
|
1312
1351
|
warnings: [...appleResult.value.warnings, ...googleResult.value.warnings]
|
|
1313
1352
|
};
|
|
1314
1353
|
}
|
|
1315
|
-
|
|
1354
|
+
/**
|
|
1355
|
+
* Push updated field values to an already-issued pass.
|
|
1356
|
+
*
|
|
1357
|
+
* Google: PATCHes the object via the Wallet REST API (the pass must have been
|
|
1358
|
+
* saved to a wallet first). Apple: no-op — Apple passes update when the holder
|
|
1359
|
+
* re-downloads the pass via your web service.
|
|
1360
|
+
*/
|
|
1316
1361
|
async update(createConfig) {
|
|
1317
1362
|
validateCreateConfig(createConfig);
|
|
1318
1363
|
if (this.credentials.google) {
|
|
@@ -1323,8 +1368,12 @@ var Pass = class {
|
|
|
1323
1368
|
);
|
|
1324
1369
|
}
|
|
1325
1370
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1371
|
+
/**
|
|
1372
|
+
* Permanently delete a pass.
|
|
1373
|
+
*
|
|
1374
|
+
* Google: removes the object via the Wallet REST API.
|
|
1375
|
+
* Apple: no-op — Apple passes cannot be remotely deleted; use {@link expire} to invalidate them.
|
|
1376
|
+
*/
|
|
1328
1377
|
async delete(serialNumber) {
|
|
1329
1378
|
if (this.credentials.google) {
|
|
1330
1379
|
await deleteGooglePass(
|
|
@@ -1334,8 +1383,13 @@ var Pass = class {
|
|
|
1334
1383
|
);
|
|
1335
1384
|
}
|
|
1336
1385
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1386
|
+
/**
|
|
1387
|
+
* Mark a pass as expired / invalid.
|
|
1388
|
+
*
|
|
1389
|
+
* Google: transitions the object state to `EXPIRED` via the Wallet REST API.
|
|
1390
|
+
* Apple: no-op — Apple passes expire automatically when `expiresAt` is reached,
|
|
1391
|
+
* or you can set `apple.voided: true` at issue time via {@link create}.
|
|
1392
|
+
*/
|
|
1339
1393
|
async expire(serialNumber) {
|
|
1340
1394
|
if (this.credentials.google) {
|
|
1341
1395
|
await expireGooglePass(
|
|
@@ -1353,21 +1407,32 @@ var Wallet = class {
|
|
|
1353
1407
|
constructor(credentials) {
|
|
1354
1408
|
this.credentials = credentials;
|
|
1355
1409
|
}
|
|
1410
|
+
/** Create a loyalty / rewards card pass. */
|
|
1356
1411
|
loyalty(config) {
|
|
1357
1412
|
return new Pass({ ...config, type: "loyalty" }, this.credentials);
|
|
1358
1413
|
}
|
|
1414
|
+
/** Create an event ticket pass. */
|
|
1359
1415
|
event(config) {
|
|
1360
1416
|
return new Pass({ ...config, type: "event" }, this.credentials);
|
|
1361
1417
|
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Create a boarding pass. Covers air, train, bus, and boat transit.
|
|
1420
|
+
*
|
|
1421
|
+
* Apple boarding passes render a transit icon between the two `primary` fields,
|
|
1422
|
+
* so use `field.primary()` for the departure and arrival locations.
|
|
1423
|
+
*/
|
|
1362
1424
|
flight(config) {
|
|
1363
1425
|
return new Pass({ ...config, type: "flight" }, this.credentials);
|
|
1364
1426
|
}
|
|
1427
|
+
/** Create a coupon / offer pass. */
|
|
1365
1428
|
coupon(config) {
|
|
1366
1429
|
return new Pass({ ...config, type: "coupon" }, this.credentials);
|
|
1367
1430
|
}
|
|
1431
|
+
/** Create a gift card pass. */
|
|
1368
1432
|
giftCard(config) {
|
|
1369
1433
|
return new Pass({ ...config, type: "giftCard" }, this.credentials);
|
|
1370
1434
|
}
|
|
1435
|
+
/** Create a generic pass for anything that doesn't fit the other types. */
|
|
1371
1436
|
generic(config) {
|
|
1372
1437
|
return new Pass({ ...config, type: "generic" }, this.credentials);
|
|
1373
1438
|
}
|