UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

102 lines (101 loc) 4.01 kB
import HttpRequester, { HttpRequesterOptions } from './http/HttpRequester'; import { Logger } from './Logger'; import BarcodesEndpoint from './endpoint/BarcodesEndpoint'; import CampaignsEndpoint from './endpoint/CampaignsEndpoint'; import ClaimsEndpoint from './endpoint/ClaimsEndpoint'; import ImagesEndpoint from './endpoint/Images'; import OrganizationsEndpoint from './endpoint/OrganizationsEndpoint'; import ScannersEndpoint from './endpoint/ScannersEndpoint'; import TemplatesEndpoint from './endpoint/TemplatesEndpoint'; import WidgetsEndpoint from './endpoint/WidgetsEndpoint'; import WorkflowsEndpoint from './endpoint/WorkflowsEndpoint'; import { AuthProvider } from './provider/AuthProvider'; /** * Client class that communicates with the the addtowallet API. * * The library's main entry point. Owns an `HttpRequester` (exposed as `http`) and constructs a * set of endpoint helpers — one per API resource — that share that same requester. Construct one * per credential set; the underlying `HttpRequester` is safe to reuse across many concurrent * requests. */ export default class Client { /** * The HTTP client used for all requests to the API. * * Exposed publicly so callers can issue ad-hoc `fetch`/`doGet`/etc. requests against endpoints * that don't yet have a dedicated helper. All bundled endpoints share this same instance, so * configuration changes (base URL, auth, user agent) apply uniformly. */ readonly http: HttpRequester; /** * The campaigns endpoint. * * CRUD operations, stats, and enrollment helpers for campaigns owned by the authenticated * organization. */ readonly campaigns: CampaignsEndpoint; /** * The claims endpoint. * * Manages pass claims — fetching, claiming, and inspecting claim state. */ readonly claims: ClaimsEndpoint; /** * The templates endpoint. * * Reads and writes pass templates (Apple Wallet and Google Wallet) and their thumbnails. */ readonly templates: TemplatesEndpoint; /** * The organizations endpoint. * * Manages the authenticated organization, its members, API keys, and related settings. */ readonly organizations: OrganizationsEndpoint; /** * The scanners endpoint. * * Manages scanner apps, invites, and per-device state used by the Addtowallet scanner * companion. */ readonly scanners: ScannersEndpoint; /** * The workflows endpoint. * * Drives automated workflows — triggers, jobs, and messages associated with them. */ readonly workflows: WorkflowsEndpoint; /** * The images endpoint. * * Uploads, lists, and deletes images stored against the authenticated organization. */ readonly images: ImagesEndpoint; /** * The barcodes endpoint. * * Renders a single barcode image given a symbology and data. Lives at the site root * (outside `/api/v1`). */ readonly barcodes: BarcodesEndpoint; /** * The widgets endpoint. * * Convenience helpers for signing JWTs against either an explicit secret or a * campaign's stored open-enrollment secret. Lives at the site root (outside `/api/v1`). */ readonly widgets: WidgetsEndpoint; /** * Constructor. * * The auth provider is optional so an unauthenticated client can be used for public endpoints; * any subsequent calls that hit authenticated routes will fail until one is wired up via * `client.http.setAuth(...)`. When the logger is omitted, debug output is silently discarded. * * @param auth The authentication provider. * @param logger The logger to use. * @param options Additional options forwarded to `HttpRequester` (currently just * `baseUrl`, which overrides the default `https://app.addtowallet.io/api/v1`). */ constructor(auth?: AuthProvider, logger?: Logger, options?: HttpRequesterOptions); }