UNPKG

@wallethero/sdk

Version:

TypeScript SDK for WalletHero API - manage pass templates and passes for Apple Wallet and Google Pay

815 lines (805 loc) 26.7 kB
type PassType = "LOYALTY" | "GIFT_CARD" | "EVENT_TICKET" | "OFFER" | "GENERIC"; type BarcodeType = "none" | "qr" | "aztec" | "code128" | "pdf417"; interface PassField { label: string; value: string; } interface CustomField { name: string; default_value?: string; } interface Location { latitude: number; longitude: number; altitude?: number; name?: string; } interface Workspace { id: string; user_created?: string; date_created?: string; user_updated?: string; date_updated?: string; name?: string; } interface Project { id: string; user_created?: string; date_created?: string; user_updated?: string; date_updated?: string; workspace_id: string; name: string; description?: string; custom_fields?: Record<string, any>; statistics?: ProjectStatistics; } interface PassTemplate { id: string; user_created?: string; date_created?: string; user_updated?: string; date_updated?: string; uuid: string; name: string; description?: string; pass_type: PassType; apple_pass_type_identifier: string; workspace_id: string; project_id: string; is_main_template?: boolean; tier_id?: string; tier_label?: string; icon?: string; logo?: string; cover_image?: string; background_color?: string; label_color?: string; value_color?: string; logo_text?: string; barcode_id?: string; barcode_type?: BarcodeType; barcode_label?: string; top_field_label?: string; top_field_value?: string; front_fields?: PassField[]; secondary_fields?: PassField[]; back_fields?: PassField[]; locations?: Location[]; location_message?: string; custom_fields?: CustomField[]; template_custom_fields?: Record<string, any>; ios_deeplink_id?: number; ios_deeplink_url?: string; statistics?: PassTemplateStatistics; } interface Pass { id: string; user_created?: string; date_created?: string; user_updated?: string; date_updated?: string; pass_template_id: string; project_id: string; workspace_id: string; current_template_id?: string; full_name?: string; email?: string; notification?: string; custom_fields?: Record<string, any>; apple_pass_url?: string; apple_qrcode_url?: string; google_pass_url?: string; google_qrcode_url?: string; } type CreateProjectRequest = Omit<Project, "id" | "user_created" | "date_created" | "user_updated" | "date_updated" | "statistics">; type UpdateProjectRequest = Partial<Omit<Project, "id" | "user_created" | "date_created" | "user_updated" | "date_updated" | "statistics">>; type CreatePassTemplateRequest = Omit<PassTemplate, "id" | "user_created" | "date_created" | "user_updated" | "date_updated" | "statistics">; type UpdatePassTemplateRequest = Partial<Omit<PassTemplate, "id" | "user_created" | "date_created" | "user_updated" | "date_updated" | "statistics">>; type CreatePassRequest = { pass_template_id: string; project_id: string; workspace_id: string; current_template_id?: string; full_name?: string; email?: string; notification?: string; custom_fields?: Record<string, any>; }; type UpdatePassRequest = Partial<Omit<Pass, "id" | "user_created" | "date_created" | "user_updated" | "date_updated">>; type CreateWorkspaceRequest = Omit<Workspace, "id" | "user_created" | "date_created" | "user_updated" | "date_updated">; type UpdateWorkspaceRequest = Partial<Omit<Workspace, "id" | "user_created" | "date_created" | "user_updated" | "date_updated">>; interface ApiResponse<T> { data: T; } interface ApiListResponse<T> { data: T[]; meta?: { total_count?: number; filter_count?: number; }; } interface ApiError { message: string; extensions?: { code?: string; [key: string]: any; }; } interface QueryOptions { fields?: string[]; filter?: Record<string, any>; sort?: string[]; limit?: number; offset?: number; search?: string; } interface DirectusFile { id: string; storage: string; filename_disk: string; filename_download: string; title?: string; type: string; folder?: string; uploaded_by?: string; uploaded_on: string; modified_by?: string; modified_on?: string; charset?: string; filesize: number; width?: number; height?: number; duration?: number; embed?: string; description?: string; location?: string; tags?: string[]; metadata?: Record<string, any>; } interface FileUploadOptions { title?: string; description?: string; folder?: string; tags?: string[]; } interface TemplateImageUpdate { icon?: string | File | Blob; logo?: string | File | Blob; cover_image?: string | File | Blob; } interface IOSDeeplinkConfig { ios_deeplink_id?: number; ios_deeplink_url?: string; } interface WalletHeroConfig { apiUrl?: string; apiToken: string; timeout?: number; } interface CompletePassData { pass: Pass; project: Project; template: PassTemplate; mainTemplate: PassTemplate | null; currentTemplate: PassTemplate; effectiveCustomFields: Record<string, any>; } interface TemplateMergeOptions { includeMainTemplate?: boolean; overridableFields?: string[]; } interface PassTemplateStatistics { apple_registrations_count: number; google_registrations_count: number; total_registrations_count: number; passes_count: number; } interface ProjectStatistics { templates_count: number; apple_registrations_count: number; google_registrations_count: number; total_registrations_count: number; passes_count: number; } declare class WalletHeroError extends Error { code?: string | undefined; status?: number | undefined; details?: any | undefined; constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any | undefined); } declare class HttpClient { private baseUrl; private token; private timeout; constructor(apiUrl: string, apiToken: string, timeout?: number); get apiBaseUrl(): string; get apiToken(): string; private buildUrl; private handleResponse; get<T>(endpoint: string, options?: QueryOptions): Promise<T>; post<T>(endpoint: string, data?: any): Promise<T>; patch<T>(endpoint: string, data?: any): Promise<T>; delete<T>(endpoint: string): Promise<T>; } declare class PassTemplatesService { private http; private files; constructor(httpClient: HttpClient); /** * Filter out fields that shouldn't be sent in update requests */ private filterUpdateData; /** * Get a list of pass templates */ list(options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Get a specific pass template by ID (UUID) */ get(id: string, options?: QueryOptions): Promise<ApiResponse<PassTemplate>>; /** * Create a new pass template */ create(data: CreatePassTemplateRequest): Promise<ApiResponse<PassTemplate>>; /** * Update an existing pass template */ update(id: string, data: UpdatePassTemplateRequest | Partial<PassTemplate>): Promise<ApiResponse<PassTemplate>>; /** * Delete a pass template */ delete(id: string): Promise<void>; /** * Get pass templates by workspace */ getByWorkspace(workspaceId: string, options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Get pass templates by project */ getByProject(projectId: string, options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Search pass templates by name */ search(query: string, options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Get pass templates by type */ getByType(passType: string, options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Duplicate a pass template */ duplicate(id: string): Promise<ApiResponse<PassTemplate>>; /** * Upload and set template images */ updateImages(id: string, images: TemplateImageUpdate): Promise<ApiResponse<PassTemplate>>; /** * Get image URLs for a template */ getImageUrls(template: PassTemplate): { icon?: string; logo?: string; cover_image?: string; }; /** * Get optimized image URLs for different uses */ getOptimizedImageUrls(template: PassTemplate): { icon?: { small: string; medium: string; large: string; }; logo?: { small: string; medium: string; large: string; }; cover_image?: { small: string; medium: string; large: string; }; }; /** * Remove images from a template */ removeImages(id: string, imageTypes: Array<"icon" | "logo" | "cover_image">): Promise<ApiResponse<PassTemplate>>; /** * Upload icon image */ uploadIcon(id: string, file: File | Blob, _options?: { title?: string; description?: string; }): Promise<ApiResponse<PassTemplate>>; /** * Upload logo image */ uploadLogo(id: string, file: File | Blob, _options?: { title?: string; description?: string; }): Promise<ApiResponse<PassTemplate>>; /** * Upload cover image */ uploadCoverImage(id: string, file: File | Blob, _options?: { title?: string; description?: string; }): Promise<ApiResponse<PassTemplate>>; /** * Add a custom field to a pass template */ addCustomField(id: string, customField: CustomField): Promise<ApiResponse<PassTemplate>>; /** * Update a custom field in a pass template */ updateCustomField(id: string, fieldName: string, updatedField: Partial<CustomField>): Promise<ApiResponse<PassTemplate>>; /** * Remove a custom field from a pass template */ removeCustomField(id: string, fieldName: string): Promise<ApiResponse<PassTemplate>>; /** * Get all custom fields for a pass template */ getCustomFields(id: string): Promise<CustomField[]>; /** * Set all custom fields for a pass template (replaces existing) */ setCustomFields(id: string, customFields: CustomField[]): Promise<ApiResponse<PassTemplate>>; /** * Set iOS deeplink configuration for a pass template */ setIOSDeeplink(id: string, deeplinkConfig: IOSDeeplinkConfig): Promise<ApiResponse<PassTemplate>>; /** * Remove iOS deeplink configuration from a pass template */ removeIOSDeeplink(id: string): Promise<ApiResponse<PassTemplate>>; /** * Get iOS deeplink configuration for a pass template */ getIOSDeeplink(id: string): Promise<IOSDeeplinkConfig>; /** * Get main templates only */ getMainTemplates(options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Get non-main templates only */ getCurrentTemplates(options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Get the main template for a project */ getMainTemplateForProject(projectId: string, options?: QueryOptions): Promise<ApiResponse<PassTemplate | null>>; /** * Set template as main template for its project */ setAsMainTemplate(id: string): Promise<ApiResponse<PassTemplate>>; /** * Unset template as main template */ unsetAsMainTemplate(id: string): Promise<ApiResponse<PassTemplate>>; /** * Update template custom fields (new template-level custom fields) */ updateTemplateCustomFields(id: string, customFields: Record<string, any>): Promise<ApiResponse<PassTemplate>>; /** * Get template custom fields */ getTemplateCustomFields(id: string): Promise<Record<string, any>>; /** * Merge template custom fields with existing ones */ mergeTemplateCustomFields(id: string, customFields: Record<string, any>): Promise<ApiResponse<PassTemplate>>; /** * Remove specific template custom fields */ removeTemplateCustomFields(id: string, fieldNames: string[]): Promise<ApiResponse<PassTemplate>>; /** * Get templates by tier */ getByTier(tierId: string, options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Set template tier */ setTier(id: string, tierId: string, tierLabel?: string): Promise<ApiResponse<PassTemplate>>; /** * Remove template tier */ removeTier(id: string): Promise<ApiResponse<PassTemplate>>; } declare class PassesService { private http; constructor(httpClient: HttpClient); /** * Get a list of passes */ list(options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Get a specific pass by ID (UUID) */ get(id: string, options?: QueryOptions): Promise<ApiResponse<Pass>>; /** * Create a new pass */ create(data: CreatePassRequest): Promise<ApiResponse<Pass>>; /** * Update an existing pass */ update(id: string, data: UpdatePassRequest): Promise<ApiResponse<Pass>>; /** * Delete a pass */ delete(id: string): Promise<void>; /** * Get passes by workspace */ getByWorkspace(workspaceId: number, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Get passes by template */ getByTemplate(templateId: string, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Get passes by project */ getByProject(projectId: string, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Get passes by current template (for template inheritance) */ getByCurrentTemplate(currentTemplateId: string, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Search passes by email or name */ search(query: string, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Send push notification to update a pass */ sendNotification(id: string, message?: string): Promise<void>; /** * Bulk create passes from template */ bulkCreateFromTemplate(templateId: string, passes: Array<Omit<CreatePassRequest, "pass_template_id">>): Promise<ApiListResponse<Pass>>; /** * Update pass custom fields (replaces the old updatePayload method) */ updateCustomFields(id: string, customFields: Record<string, any>): Promise<ApiResponse<Pass>>; /** * Get custom fields for a specific pass */ getCustomFields(id: string): Promise<Record<string, any>>; /** * Set a single custom field value */ setCustomField(id: string, fieldName: string, value: any): Promise<ApiResponse<Pass>>; /** * Get a single custom field value */ getCustomField(id: string, fieldName: string): Promise<any>; /** * Remove a custom field */ removeCustomField(id: string, fieldName: string): Promise<ApiResponse<Pass>>; /** * Merge custom fields (adds new fields without removing existing ones) */ mergeCustomFields(id: string, fieldsToMerge: Record<string, any>): Promise<ApiResponse<Pass>>; /** * Clear all custom fields */ clearCustomFields(id: string): Promise<ApiResponse<Pass>>; /** * Check if a custom field exists */ hasCustomField(id: string, fieldName: string): Promise<boolean>; /** * Get all custom field names for a pass */ getCustomFieldNames(id: string): Promise<string[]>; /** * Bulk update custom fields for multiple passes */ bulkUpdateCustomFields(updates: Array<{ passId: string; customFields: Record<string, any>; }>): Promise<ApiListResponse<Pass>>; /** * Search passes by custom field value */ searchByCustomField(fieldName: string, value: any, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Filter passes by multiple custom field criteria */ filterByCustomFields(criteria: Record<string, any>, options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * @deprecated Use updateCustomFields instead * Update pass payload (custom data) - kept for backward compatibility */ updatePayload(id: string, payload: Record<string, any>): Promise<ApiResponse<Pass>>; /** * Switch pass to a different template within the same project */ switchTemplate(id: string, newTemplateId: string): Promise<ApiResponse<Pass>>; /** * Reset pass to use its original template (unset current_template_id) */ resetToOriginalTemplate(id: string): Promise<ApiResponse<Pass>>; /** * Get complete pass data with template inheritance */ getCompleteData(id: string): Promise<any>; /** * Bulk switch passes to a different template within the same project */ bulkSwitchTemplate(passIds: string[], newTemplateId: string): Promise<ApiListResponse<Pass>>; /** * Get passes that are using template inheritance (have current_template_id) */ getPassesWithTemplateInheritance(options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Get passes that are NOT using template inheritance (no current_template_id) */ getPassesWithoutTemplateInheritance(options?: QueryOptions): Promise<ApiListResponse<Pass>>; /** * Update pass with template inheritance context */ updateWithTemplateInheritance(id: string, data: UpdatePassRequest & { current_template_id?: string; }): Promise<ApiResponse<Pass>>; } declare class ProjectsService { private http; constructor(httpClient: HttpClient); /** * Get a list of projects */ list(options?: QueryOptions): Promise<ApiListResponse<Project>>; /** * Get a specific project by ID (UUID) */ get(id: string, options?: QueryOptions): Promise<ApiResponse<Project>>; /** * Create a new project */ create(data: CreateProjectRequest): Promise<ApiResponse<Project>>; /** * Update an existing project */ update(id: string, data: UpdateProjectRequest): Promise<ApiResponse<Project>>; /** * Delete a project */ delete(id: string): Promise<void>; /** * Get projects by workspace */ getByWorkspace(workspaceId: string, options?: QueryOptions): Promise<ApiListResponse<Project>>; /** * Search projects by name */ search(query: string, options?: QueryOptions): Promise<ApiListResponse<Project>>; /** * Get the main template for a project */ getMainTemplate(projectId: string): Promise<ApiResponse<PassTemplate | null>>; /** * Set a template as the main template for a project */ setMainTemplate(projectId: string, templateId: string): Promise<ApiResponse<PassTemplate>>; /** * Unset the main template for a project */ unsetMainTemplate(projectId: string): Promise<void>; /** * Get all templates for a project */ getTemplates(projectId: string, options?: QueryOptions): Promise<ApiListResponse<PassTemplate>>; /** * Get all passes for a project */ getPasses(projectId: string, options?: QueryOptions): Promise<ApiListResponse<any>>; /** * Get complete pass data with template inheritance for a pass */ getCompletePassData(passId: string): Promise<ApiResponse<CompletePassData>>; /** * Merge templates using inheritance logic (main template + current template) */ mergeTemplates(mainTemplateId: string, currentTemplateId: string): Promise<ApiResponse<PassTemplate>>; /** * Update project custom fields */ updateCustomFields(id: string, customFields: Record<string, any>): Promise<ApiResponse<Project>>; /** * Get project custom fields */ getCustomFields(id: string): Promise<Record<string, any>>; /** * Merge custom fields with existing ones */ mergeCustomFields(id: string, customFields: Record<string, any>): Promise<ApiResponse<Project>>; /** * Remove specific custom fields */ removeCustomFields(id: string, fieldNames: string[]): Promise<ApiResponse<Project>>; /** * Get project statistics */ getStats(id: string): Promise<{ templateCount: number; passCount: number; mainTemplate: PassTemplate | null; }>; /** * Duplicate a project with all its templates */ duplicate(id: string, newName?: string): Promise<ApiResponse<Project>>; } declare class FilesService { private http; constructor(httpClient: HttpClient); /** * Upload a file */ upload(file: File | Blob, options?: FileUploadOptions): Promise<ApiResponse<DirectusFile>>; /** * Get file information by ID */ get(id: string, options?: QueryOptions): Promise<ApiResponse<DirectusFile>>; /** * List files */ list(options?: QueryOptions): Promise<ApiListResponse<DirectusFile>>; /** * Delete a file */ delete(id: string): Promise<void>; /** * Update file metadata */ update(id: string, data: Partial<Pick<DirectusFile, "title" | "description" | "tags" | "folder">>): Promise<ApiResponse<DirectusFile>>; /** * Get file URL for download/display */ getFileUrl(id: string, options?: { width?: number; height?: number; fit?: "cover" | "contain" | "inside" | "outside"; quality?: number; format?: "jpg" | "png" | "webp" | "tiff"; }): string; /** * Upload image with automatic optimization for pass templates */ uploadPassImage(file: File | Blob, type: "icon" | "logo" | "cover_image", options?: Omit<FileUploadOptions, "folder">): Promise<ApiResponse<DirectusFile>>; } interface QRCodeOptions { width?: number; margin?: number; dark?: string; light?: string; format?: "png" | "json"; } interface QRCodeResponse { passId: string; url: string; qrCode: string; format: string; } declare class QRCodeService { private http; constructor(httpClient: HttpClient); /** * Get pass data to retrieve QR code URLs */ private getPassData; /** * Private helper method to build QR code URL with query parameters */ private getQRCodeUrlForPassType; /** * Get QR code URL for Apple Pass * Returns URL that can be used directly in img src or for JSON format */ getApplePassQRCode(passId: string, options?: QRCodeOptions): Promise<string | QRCodeResponse>; /** * Get QR code URL for Google Wallet Pass * Returns URL that can be used directly in img src or for JSON format */ getGooglePassQRCode(passId: string, options?: QRCodeOptions): Promise<string | QRCodeResponse>; /** * Get Apple Pass URL for QR code generation from pass data */ getApplePassURL(passId: string): Promise<string>; /** * Get Google Wallet Pass URL for QR code generation from pass data */ getGooglePassURL(passId: string): Promise<string>; } declare class WorkspacesService { private http; constructor(httpClient: HttpClient); /** * Get a list of workspaces */ list(options?: QueryOptions): Promise<ApiListResponse<Workspace>>; /** * Get a specific workspace by ID (UUID) */ get(id: string, options?: QueryOptions): Promise<ApiResponse<Workspace>>; /** * Create a new workspace */ create(data: CreateWorkspaceRequest): Promise<ApiResponse<Workspace>>; /** * Update an existing workspace */ update(id: string, data: UpdateWorkspaceRequest): Promise<ApiResponse<Workspace>>; /** * Delete a workspace */ delete(id: string): Promise<void>; /** * Search workspaces by name */ search(query: string, options?: QueryOptions): Promise<ApiListResponse<Workspace>>; /** * Get workspaces by name (exact match) */ getByName(name: string, options?: QueryOptions): Promise<ApiListResponse<Workspace>>; /** * Get workspace with related data (passes, templates, etc.) */ getWithRelations(id: string, includeFields?: string[]): Promise<ApiResponse<Workspace>>; /** * Get workspace statistics */ getStats(id: string): Promise<{ passCount: number; templateCount: number; appleRegistrationCount: number; googleRegistrationCount: number; }>; /** * Get current user's workspaces */ getMy(options?: QueryOptions): Promise<ApiListResponse<Workspace>>; /** * Check if workspace name is available */ isNameAvailable(name: string): Promise<boolean>; /** * Get workspace members (requires junction table access) */ getMembers(id: string): Promise<ApiListResponse<any>>; /** * Add member to workspace */ addMember(workspaceId: string, userId: string): Promise<ApiResponse<any>>; /** * Remove member from workspace */ removeMember(workspaceId: string, userId: string): Promise<void>; } declare class WalletHero { private http; readonly passTemplates: PassTemplatesService; readonly passes: PassesService; readonly projects: ProjectsService; readonly files: FilesService; readonly qrCodes: QRCodeService; readonly workspaces: WorkspacesService; constructor(config: WalletHeroConfig); /** * Test the connection to the API */ ping(): Promise<boolean>; /** * Get current user information */ me(): Promise<any>; /** * Get API server information */ serverInfo(): Promise<any>; } export { type ApiError, type ApiListResponse, type ApiResponse, type BarcodeType, type CompletePassData, type CreatePassRequest, type CreatePassTemplateRequest, type CreateProjectRequest, type CreateWorkspaceRequest, type CustomField, type DirectusFile, type FileUploadOptions, FilesService, HttpClient, type IOSDeeplinkConfig, type Location, type Pass, type PassField, type PassTemplate, type PassTemplateStatistics, PassTemplatesService, type PassType, PassesService, type Project, type ProjectStatistics, ProjectsService, type QRCodeOptions, type QRCodeResponse, QRCodeService, type QueryOptions, type TemplateImageUpdate, type TemplateMergeOptions, type UpdatePassRequest, type UpdatePassTemplateRequest, type UpdateProjectRequest, type UpdateWorkspaceRequest, WalletHero, type WalletHeroConfig, WalletHeroError, type Workspace, WorkspacesService, WalletHero as default };