UNPKG

@basetime/a2w-api-ts

Version:

Client library that communicates with the addtowallet API.

82 lines (81 loc) 2.52 kB
import { Requester } from '../http/Requester'; import { Template } from '../types/Template'; import { TemplateThumbnail } from '../types/TemplateThumbnail'; import Endpoint from './Endpoint'; /** * Argument shape for {@link TemplatesEndpoint.import}. * * Either a runtime `Blob`/`File` is passed through directly, or `{ name, content }` is * used to construct one with the supplied filename and JSON content. */ export type TemplateImportFile = Blob | File | { /** * Optional filename used in the multipart form. Defaults to `template.json`. */ name?: string; /** * The JSON content to upload, as a string. */ content: string; }; /** * Communicate with the templates endpoints. */ export default class TemplatesEndpoint extends Endpoint { /** * Constructor. * * @param req The object to use to make requests. */ constructor(req: Requester); /** * Returns a template by ID. * * @param id The ID of the template. */ getById: (id: string) => Promise<TemplateThumbnail>; /** * Returns all of the templates for authenticated organization. * * @returns The templates. */ getAll: () => Promise<Template[]>; /** * Returns all of the templates for a specific tag. * * @param tag The tag. * @returns The templates. */ getByTag: (tag: string) => Promise<TemplateThumbnail[]>; /** * Deletes a template. * * @param id The ID of the template to delete. */ delete: (id: string) => Promise<string>; /** * Clones a template and returns the new template. * * @param id The ID of the template to clone. */ clone: (id: string) => Promise<Template>; /** * Exports a template as a JSON bundle suitable for re-importing into another * organization. * * Returns the parsed JSON object as returned by the backend. * * @param id The ID of the template to export. */ export: (id: string) => Promise<Record<string, unknown>>; /** * Imports a template from a JSON bundle previously produced by {@link export}. * * Sends a `multipart/form-data` POST. The `Content-Type` header is left unset so the * runtime can attach the correct multipart boundary automatically. * * @param file The file to upload. Pass a `Blob`/`File`, or `{ name, content }` to build * one from a string. */ import: (file: TemplateImportFile) => Promise<Template>; }