UNPKG

addtowallet

Version:

Create and manage Google Wallet and Apple Wallet passes with an easy-to-use API client for Node.js and browsers.

151 lines (150 loc) 5.71 kB
import type { AddToWalletClientOptions, CreatePassRequest, CreatePassResponse, DeletePassResponse, GetCreditsResponse, GetPassResponse, UpdatePassRequest, UpdatePassResponse } from './types'; /** * AddToWallet API client for creating and managing wallet passes * * @example * ```ts * const client = new AddToWalletClient({ * apiKey: process.env.ADDTOWALLET_API_KEY! * }); * * const { cardId, passUrl } = await client.createPass({ * logoUrl: 'https://s3.amazonaws.com/i.addtowallet.co/assets/realestatelogo.png', * cardTitle: 'Your Business Name', * header: 'Amy Jane', * textModulesData: [ * { id: 'r1start', header: 'Phone', body: '+1 8888888888' }, * { id: 'r1end', header: 'Email', body: 'amy@gmail.com' } * ], * linksModuleData: [ * { id: 'r1', description: 'Call Us', uri: 'tel:+1 8287489293' }, * { id: 'r2', description: 'Email Us', uri: 'mailto:support@addtowallet.co' }, * { id: 'r3', description: 'Visit our website', uri: 'https://app.addtowallet.co' }, * { id: 'r4', description: 'Visit our office', uri: 'geo:https://maps.google.com/?q=123+Main+Street,+Anytown,+CA' } * ], * barcodeType: 'QR_CODE', * barcodeValue: '', * barcodeAltText: '', * hexBackgroundColor: '#141f31', * appleFontColor: '#FFFFFF', * heroImage: 'https://s3.amazonaws.com/i.addtowallet.co/assets/realestatehero.png' * }); * * console.log(cardId, passUrl); * ``` */ export declare class AddToWalletClient { private readonly baseUrl; private readonly apiKey; private readonly getAuthToken; private readonly fetchFn; private readonly timeoutMs; private readonly defaultTracking; /** * Creates a new AddToWallet client instance * * @param options - Configuration options for the client * @param options.apiKey - Secret API key from AddToWallet dashboard (server-side only) * @param options.getAuthToken - Function that returns a short-lived auth token (for browser use) * @param options.baseUrl - Base URL for the AddToWallet API (defaults to https://app.addtowallet.co) * @param options.fetchFn - Custom fetch implementation (for Node < 18 or custom behavior) * @param options.timeoutMs - Request timeout in milliseconds */ constructor(options: AddToWalletClientOptions); private resolveToken; /** * Merges default tracking parameters with request-specific tracking parameters * Request-specific parameters override default ones */ private mergeTrackingParams; private request; /** * Creates a new wallet pass * * @param payload - The pass creation request * @returns Promise resolving to the created pass information, including `cardId` and `passUrl` * * @example * ```ts * const { cardId, passUrl } = await client.createPass({ * logoUrl: 'https://s3.amazonaws.com/i.addtowallet.co/assets/realestatelogo.png', * cardTitle: 'Your Business Name', * header: 'Amy Jane', * textModulesData: [ * { id: 'r1start', header: 'Phone', body: '+1 8888888888' }, * { id: 'r1end', header: 'Email', body: 'amy@gmail.com' } * ], * linksModuleData: [ * { id: 'r1', description: 'Call Us', uri: 'tel:+1 8287489293' }, * { id: 'r2', description: 'Email Us', uri: 'mailto:support@addtowallet.co' }, * { id: 'r3', description: 'Visit our website', uri: 'https://app.addtowallet.co' }, * { id: 'r4', description: 'Visit our office', uri: 'geo:https://maps.google.com/?q=123+Main+Street,+Anytown,+CA' } * ], * barcodeType: 'QR_CODE', * barcodeValue: '', * barcodeAltText: '', * hexBackgroundColor: '#141f31', * appleFontColor: '#FFFFFF', * heroImage: 'https://s3.amazonaws.com/i.addtowallet.co/assets/realestatehero.png', * }); * * console.log(cardId, passUrl); * ``` */ createPass(payload: CreatePassRequest): Promise<CreatePassResponse>; /** * Updates an existing wallet pass * * @param cardId - The ID of the pass to update * @param payload - The pass update request * @returns Promise resolving to the updated pass information * * @example * ```ts * await client.updatePass('66b6005bb7bddce8f05a3392', { * cardTitle: 'Updated Card Title', * header: 'Updated Header', * hexBackgroundColor: '#33FF57' * }); * ``` */ updatePass(cardId: string, payload: UpdatePassRequest): Promise<UpdatePassResponse>; /** * Deletes a wallet pass by ID * * @param cardId - The ID of the pass to delete * @returns Promise resolving to deletion confirmation * * @example * ```ts * const { msg } = await client.deletePass('66b6005bb7bddce8f05a3392'); * console.log('Pass deleted:', msg); * ``` */ deletePass(cardId: string): Promise<DeletePassResponse>; /** * Gets current credit information * * @returns Promise resolving to credit information * * @example * ```ts * const { premiumCredits, freeCredits } = await client.getCredits(); * console.log(`Premium credits: ${premiumCredits}, Free credits: ${freeCredits}`); * ``` */ getCredits(): Promise<GetCreditsResponse>; /** * Gets a specific pass by ID * * @param cardId - The ID of the pass to retrieve * @returns Promise resolving to pass details * * @example * ```ts * const pass = await client.getPass('66b6005bb7bddce8f05a3392'); * console.log('Pass title:', pass.cardTitle); * ``` */ getPass(cardId: string): Promise<GetPassResponse>; }