UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

135 lines (134 loc) 5.1 kB
import { MetaValues } from '../../types/MetaValues'; import { Pass } from '../../types/Pass'; import { ScannerLog } from '../../types/ScannerLog'; import Endpoint from '../Endpoint'; /** * Communicate with the `/campaigns/:campaignId/passes/*` sub-endpoints. * * Accessed via `client.campaigns.passes`. Methods take `campaignId` as their first argument, * matching the unbound style used elsewhere in the SDK. */ export default class CampaignPassesEndpoint extends Endpoint { /** * Constructor. * * @param parent The parent `CampaignsEndpoint` whose `req`, `do`, and `qb` are * reused. */ constructor(parent: Endpoint); /** * Returns the passes for a campaign. * * @param campaignId The ID of the campaign. * @returns The passes. */ getAll: (campaignId: string) => Promise<Pass[]>; /** * Returns the details for a pass. * * @param campaignId The campaign the pass belongs to. * @param passId The ID of the pass. * @param scanner Only used by scanners. The scanner that's being used to request the pass. */ getById: (campaignId: string, passId: string, scanner?: unknown) => Promise<Pass>; /** * Queries the passes for a campaign. * * @param campaignId The ID of the campaign. * @param queries The queries to run. * @returns The passes. */ query: (campaignId: string, queries?: Record<string, any>) => Promise<Pass[]>; /** * Updates the details of a pass. * * This method also updates the wallets that contain the pass. * * @param campaignId The ID of the campaign the pass belongs to. * @param passId The ID of the pass. * @param body The new pass values. */ update: (campaignId: string, passId: string, body: Partial<Pick<Pass, "objectStore" | "templateId" | "templateVersion" | "passTypeIdentifier">>) => Promise<Pass>; /** * Merges a pass object store into the existing object store. * * @param campaignId The ID of the campaign the pass belongs to. * @param passId The ID of the pass to merge. * @param body The new pass values with objectStore key. */ mergeObjectStore: (campaignId: string, passId: string, body: Partial<Pick<Pass, "objectStore">>) => Promise<Pass>; /** * Deletes keys from a pass object store. * * @param campaignId The ID of the campaign the pass belongs to. * @param passId The ID of the pass to delete the keys from. * @param objectStoreKeys The keys to delete from the object store. */ deleteObjectStoreKeys: (campaignId: string, passId: string, objectStoreKeys: string[]) => Promise<Pass>; /** * Updates multiple passes. * * @param campaignId The ID of the campaign the passes belong to. * @param passes The passes to update. */ updateMany: (campaignId: string, passes: (Partial<Pass> & { id: string; })[]) => Promise<Pass[]>; /** * Appends a log to a pass. * * @param campaignId The ID of the campaign the pass belongs to. * @param passId The ID of the pass. * @param log The message to append to the log. */ appendLog: (campaignId: string, passId: string, log: string) => Promise<Pass>; /** * Creates a pass bundle and returns the URL to the claims page. * * Example: * ```ts * const client = new Client(auth, console); * const link = await client.campaigns.passes.createBundle('123'); * console.log(link); * ``` * * @param campaignId The campaign the pass belongs to. * @param metaValues The meta values to set. * @param objectStore The object store to set. * @param utm The UTM values to pass along to the api. */ createBundle: (campaignId: string, metaValues?: MetaValues, objectStore?: Record<string, any>, utm?: Record<string, string>) => Promise<string>; /** * Returns the passes for a job. * * @param campaignId The ID of the campaign. * @param jobId The ID of the job. * @returns The passes. */ getByJob: (campaignId: string, jobId: string) => Promise<Pass[]>; /** * Sets the redeemed status of a pass to true. * * @param campaignId The ID of the campaign. * @param passId The ID of the pass. * @returns True if the pass was redeemed, false if it was already redeemed. */ redeem: (campaignId: string, passId: string) => Promise<boolean>; /** * Returns the redeemed status of a pass. * * @param campaignId The ID of the campaign. * @param passId The ID of the pass. * @returns The redeemed status. */ getRedeemedStatus: (campaignId: string, passId: string) => Promise<boolean>; /** * Returns the scanner logs recorded against a pass. * * Each entry records one scan made by a registered scanner device. * * @param campaignId The ID of the campaign. * @param passId The ID of the pass. */ getScannerLogs: (campaignId: string, passId: string) => Promise<ScannerLog[]>; }