UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

50 lines (49 loc) 1.99 kB
import { Enrollment, EnrollmentResponse } from '../../types/Enrollment'; import { MetaValues } from '../../types/MetaValues'; import Endpoint from '../Endpoint'; /** * Communicate with the enrollment endpoints. * * Accessed via `client.campaigns.enrollments`. Reads live under `/campaigns/:id/enrollments` * (handled via the inherited `this.do`); writes hit the unauthenticated `/e/campaign/:id` * route via a dedicated {@link EndpointDo} instance. */ export default class CampaignEnrollmentsEndpoint extends Endpoint { /** * A function to encode the data into a jwt. Used by {@link create}. * * Callers must set this before invoking {@link create}, otherwise that method throws. */ jwtEncode?: (data: Record<string, any>) => Promise<string>; /** * Verb wrapper for the unauthenticated enrollment endpoint (`/e`), which lives at a * different prefix from the rest of this class. */ private enrollment; /** * Constructor. * * @param parent The parent `CampaignsEndpoint` whose `req`, `do`, and `qb` are * reused. The extra `/e` enrollment endpoint is constructed against the parent's * requester. */ constructor(parent: Endpoint); /** * Returns the enrollments for a campaign. * * @param campaignId The ID of the campaign. * @returns The enrollments. */ getAll: (campaignId: string) => Promise<Enrollment[]>; /** * 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 {@link jwtEncode} to be set. * * @param campaignId The ID of the campaign. * @param metaValues The meta values to set. * @param formValues The form values to set. */ create: (campaignId: string, metaValues?: MetaValues, formValues?: Record<string, any>) => Promise<EnrollmentResponse>; }