UNPKG

braze-api

Version:

Track users, send messages, export data, and more with Braze API.

422 lines 14.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Braze = void 0; const campaigns = require("./campaigns"); const canvas = require("./canvas"); const catalogs = require("./catalogs"); const email = require("./email"); const messages = require("./messages"); const segments = require("./segments"); const sends = require("./sends"); const subscription = require("./subscription"); const templates = require("./templates"); const transactional = require("./transactional"); const users = require("./users"); const v2 = require("./v2"); class Braze { /** * @param apiUrl - Braze REST endpoint. * @param apiKey - Braze API key. */ constructor(apiUrl, apiKey) { /* eslint-disable tsdoc/syntax */ this.campaigns = { /** * GET /campaigns/details */ details: (parameters) => { return campaigns.details(this.apiUrl, this.apiKey, parameters); }, /** * GET /campaigns/list */ list: (parameters) => { return campaigns.list(this.apiUrl, this.apiKey, parameters); }, trigger: { schedule: { /** * POST /campaigns/trigger/schedule/create */ create: (body) => { return campaigns.trigger.schedule.create(this.apiUrl, this.apiKey, body); }, /** * POST /campaigns/trigger/schedule/delete */ delete: (body) => { return campaigns.trigger.schedule._delete(this.apiUrl, this.apiKey, body); }, /** * POST /campaigns/trigger/schedule/update */ update: (body) => { return campaigns.trigger.schedule.update(this.apiUrl, this.apiKey, body); }, }, /** * POST /campaigns/trigger/send */ send: (body) => { return campaigns.trigger.send(this.apiUrl, this.apiKey, body); }, }, }; this.canvas = { /** * GET /canvas/list */ list: (parameters) => { return canvas.list(this.apiUrl, this.apiKey, parameters); }, trigger: { schedule: { /** * POST /canvas/trigger/schedule/create */ create: (body) => { return canvas.trigger.schedule.create(this.apiUrl, this.apiKey, body); }, /** * POST /canvas/trigger/schedule/delete */ delete: (body) => { return canvas.trigger.schedule._delete(this.apiUrl, this.apiKey, body); }, /** * POST /canvas/trigger/schedule/update */ update: (body) => { return canvas.trigger.schedule.update(this.apiUrl, this.apiKey, body); }, }, /** * POST /canvas/trigger/send */ send: (body) => { return canvas.trigger.send(this.apiUrl, this.apiKey, body); }, }, }; /** * {@link https://www.braze.com/docs/api/endpoints/catalogs} */ this.catalogs = { synchronous: { /** * GET /catalogs */ list: () => { return catalogs.synchronous.listCatalogs(this.apiUrl, this.apiKey); }, /** * GET /catalogs/{catalog_name}/items */ items: (body) => { return catalogs.synchronous.getListCatalogItemsIterator(this.apiUrl, this.apiKey, body); }, /** * GET /catalogs/{catalog_name}/items/{item_id} */ item: (body) => { return catalogs.synchronous.getCatalogItem(this.apiUrl, this.apiKey, body); }, }, }; /** * {@link https://www.braze.com/docs/api/endpoints/email} */ this.email = { /** * POST /email/blacklist */ blacklist: (body) => { return email.blacklist(this.apiUrl, this.apiKey, body); }, /** * POST /email/blacklist */ bounce: { remove: (body) => { return email.bounce.remove(this.apiUrl, this.apiKey, body); }, }, /** * POST /email/spam/remove */ spam: { remove: (body) => { return email.spam.remove(this.apiUrl, this.apiKey, body); }, }, }; /** * {@link https://www.braze.com/docs/api/endpoints/messaging} */ this.messages = { schedule: { /** * POST /messages/schedule/create */ create: (body) => { return messages.schedule.create(this.apiUrl, this.apiKey, body); }, /** * POST /messages/schedule/delete */ delete: (body) => { return messages.schedule._delete(this.apiUrl, this.apiKey, body); }, /** * POST /messages/schedule/update */ update: (body) => { return messages.schedule.update(this.apiUrl, this.apiKey, body); }, }, /** * GET /messages/scheduled_broadcasts */ scheduled_broadcasts: (body) => { return messages.scheduled_broadcasts(this.apiUrl, this.apiKey, body); }, /** * POST /messages/send */ send: (body) => { return messages.send(this.apiUrl, this.apiKey, body); }, }; this.segments = { /** * GET /segments/data_series */ analytics: (parameters) => { return segments.analytics(this.apiUrl, this.apiKey, parameters); }, /** * GET /segments/details */ details: (parameters) => { return segments.details(this.apiUrl, this.apiKey, parameters); }, /** * GET /segments/list */ list: (parameters) => { return segments.list(this.apiUrl, this.apiKey, parameters); }, }; this.sends = { id: { /** * POST /sends/id/create */ create: (body) => { return sends.id.create(this.apiUrl, this.apiKey, body); }, }, }; /** * {@link https://www.braze.com/docs/api/endpoints/subscription_groups} */ this.subscription = { status: { /** * GET /subscription/status/get */ get: (body) => { return subscription.status.get(this.apiUrl, this.apiKey, body); }, /** * POST /subscription/status/set */ set: (body) => { return subscription.status.set(this.apiUrl, this.apiKey, body); }, }, user: { /** * GET /subscription/user/status */ status: (body) => { return subscription.user.status(this.apiUrl, this.apiKey, body); }, }, }; /** * {@link https://www.braze.com/docs/api/endpoints/templates} */ this.templates = { content_blocks: { /** * GET /content_blocks/info */ get: (body) => { return templates.content_blocks.getContentBlock(this.apiUrl, this.apiKey, body); }, /** * GET /content_blocks/list */ list: (body) => { return templates.content_blocks.listContentBlocks(this.apiUrl, this.apiKey, body); }, /** * POST /content_blocks/create */ create: (body) => { return templates.content_blocks.createContentBlock(this.apiUrl, this.apiKey, body); }, /** * POST /content_blocks/update */ update: (body) => { return templates.content_blocks.updateContentBlock(this.apiUrl, this.apiKey, body); }, }, email_templates: { /** * GET /templates/email/info */ get: (body) => { return templates.email_templates.getEmailTemplate(this.apiUrl, this.apiKey, body); }, /** * GET /templates/email/list */ list: (body) => { return templates.email_templates.getEmailTemplateList(this.apiUrl, this.apiKey, body); }, /** * POST /templates/email/create */ create: (body) => { return templates.email_templates.createEmailTemplate(this.apiUrl, this.apiKey, body); }, /** * POST /templates/email/update */ update: (body) => { return templates.email_templates.updateEmailTemplate(this.apiUrl, this.apiKey, body); }, }, }; this.transactional = { v1: { campaigns: { /** * POST /transactional/v1/campaigns/{campaign_id}/send */ send: (campaignId, body) => { return transactional.v1.campaigns.send(this.apiUrl, this.apiKey, campaignId, body); }, }, }, }; /** * {@link https://www.braze.com/docs/api/endpoints/user_data} */ this.users = { alias: { /** * POST /users/alias/new */ new: (body) => { return users.alias._new(this.apiUrl, this.apiKey, body); }, /** * POST /users/alias/update */ update: (body) => { return users.alias._update(this.apiUrl, this.apiKey, body); }, }, /** * POST /users/delete */ delete: (body) => { return users._delete(this.apiUrl, this.apiKey, body); }, export: { /** * POST /users/export/global_control_group */ global_control_group: (body) => { return users.export.global_control_group(this.apiUrl, this.apiKey, body); }, /** * POST /users/export/ids */ ids: (body) => { return users.export.ids(this.apiUrl, this.apiKey, body); }, /** * POST /users/export/segment */ segment: (body) => { return users.export.segment(this.apiUrl, this.apiKey, body); }, }, /** * {@link https://www.braze.com/docs/api/endpoints/user_data/external_id_migration} */ external_ids: { /** * POST /users/external_ids/remove */ remove: (body) => { return users.external_ids.remove(this.apiUrl, this.apiKey, body); }, /** * POST /users/external_ids/rename */ rename: (body) => { return users.external_ids.rename(this.apiUrl, this.apiKey, body); }, }, /** * POST /users/identify */ identify: (body) => { return users.identify(this.apiUrl, this.apiKey, body); }, /** * POST /users/merge */ merge: (body) => { return users.merge(this.apiUrl, this.apiKey, body); }, /** * POST /users/track */ track: (body, bulk) => { return users.track(this.apiUrl, this.apiKey, body, bulk); }, }; this.v2 = { /** * {@link https://www.braze.com/docs/api/endpoints/subscription_groups} */ subscription: { status: { /** * POST /v2/subscription/status/set */ set: (body) => { return v2.subscription.status.set(this.apiUrl, this.apiKey, body); }, }, }, }; if (!apiUrl || typeof apiUrl !== 'string') { throw new Error(`Invalid Braze API URL: ${apiUrl}`); } if (!apiKey || typeof apiKey !== 'string') { throw new Error(`Invalid Braze API key: ${apiKey}`); } this.apiUrl = apiUrl; this.apiKey = apiKey; } } exports.Braze = Braze; //# sourceMappingURL=Braze.js.map