UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

142 lines (141 loc) 5.12 kB
import { Campaign } from '../types/Campaign'; import { CampaignStats } from '../types/CampaignStats'; import { Claim } from '../types/Claim'; import { Enrollment, EnrollmentResponse } from '../types/Enrollment'; import { Job } from '../types/Job'; import { MetaValues } from '../types/MetaValues'; import { Pass } from '../types/Pass'; import Endpoint from './Endpoint'; /** * Communicate with the campaigns endpoints. */ export default class CampaignsEndpoint extends Endpoint { /** * A function to encode the data into a jwt. Used by the enrollment endpoint. */ jwtEncode?: (data: Record<string, any>) => Promise<string>; /** * Returns all of the campaigns for authenticated organization. * * @returns The campaigns. */ getAll: () => Promise<Campaign[]>; /** * Returns the details of a campaign. * * @param id The ID of the campaign. */ getById: (id: string) => Promise<Campaign>; /** * Returns the passes for a campaign. * * @param campaignId The ID of the campaign. * @returns The passes. */ getPasses: (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. */ getPass: (campaignId: string, passId: string, scanner?: 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. */ updatePass: (campaignId: string, passId: string, body: Partial<Pick<Pass, "data" | "templateId" | "templateVersion" | "passTypeIdentifier">>) => 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.createBundle('123'); * console.log(link); * ``` * * @param campaignId The campaign the pass belongs to. * @param metaValues The meta values to set. * @param formValues The form values to set. * @param utm The UTM values to pass along to the api. */ createBundle: (campaignId: string, metaValues?: MetaValues, formValues?: Record<string, any>, utm?: Record<string, string>) => Promise<string>; /** * Creates an enrollment for a campaign, and returns the bundle ID and any errors. * * This method needs to encode the data into a jwt. The jwt is used to authenticate * with the site. This method requires the jwtEncode function to be set. * * @param campaignId The ID of the campaign. * @param metaValues The meta values to set. * @param formValues The form values to set. */ createEnrollment: (campaignId: string, metaValues?: MetaValues, formValues?: Record<string, any>) => Promise<EnrollmentResponse>; /** * Returns the passes for a job. * * @param campaignId The ID of the campaign. * @param jobId The ID of the job. * @returns The passes. */ getPassesByJob: (campaignId: string, jobId: string) => Promise<Pass[]>; /** * Returns the claims for a campaign. * * @param campaignId The ID of the campaign. * @returns The claims. */ getClaims: (campaignId: string) => Promise<Claim[]>; /** * Returns the jobs for a campaign. * * @param campaignId The ID of the campaign. * @returns The jobs. */ getJobs: (campaignId: string) => Promise<Job[]>; /** * Returns statistics for a campaign. * * @param campaignId The ID of the campaign. * @returns The statistics. */ getStats: (campaignId: string) => Promise<CampaignStats>; /** * Returns the enrollments for a campaign. * * @param campaignId The ID of the campaign. * @returns The enrollments. */ getEnrollments: (campaignId: string) => Promise<Enrollment[]>; /** * 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. */ redeemPass: (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>; }