UNPKG

shipstation-node

Version:
78 lines (77 loc) 3.75 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { BaseResource } from '../../BaseResource'; export class Webhooks extends BaseResource { constructor(shipstation) { super(shipstation, 'webhooks'); } /** * [Official Documentation](https://www.shipstation.com/docs/api/webhooks/list/) * * Retrieves a list of registered webhooks for the account. * * @returns A list of webhooks. */ list() { return __awaiter(this, void 0, void 0, function* () { return this.shipstation.request({ url: this.baseUrl, method: 'GET' }); }); } /** * [Official Documentation](https://www.shipstation.com/docs/api/webhooks/subscribe/) * * Subscribes to a specific type of webhook. If a `store_id` is passed in, the webhooks will only be triggered for * that specific `store_id`. The `event` type that is passed in will determine what type of webhooks will be sent. * * Webhooks will be sent to the URL specified in the `target_url`. The HTTP request will be sent via POST and will * contain a [webhook JSON object](https://www.shipstation.com/docs/api/models/webhook/) in the body. * * Regardless of how the webhook was created, you can only modify an existing webhook through your ShipStation UI and * application account Settings. To view and edit your webhooks via the application UI, log in to ShipStation and go * to `Settings > Integrations > Integration Partners` under Integrations in the [Account Settings](https://ss.shipstation.com/#/settings/integrations). * Learn more about webhooks in ShipStation's UI in this [ShipStation Webhooks KB article](https://help.shipstation.com/hc/en-us/articles/360025856252). * * @param data The data to subscribe to the webhook. * * @returns The subscription response. */ subscribe(data) { return __awaiter(this, void 0, void 0, function* () { return this.shipstation.request({ url: `${this.baseUrl}/subscribe`, method: 'POST', data }); }); } /** * [Official Documentation](https://www.shipstation.com/docs/api/webhooks/unsubscribe/) * * Unsubscribes from a certain webhook. * * To view and edit your webhooks via the application UI, log in to ShipStation and go to * `Settings > Integrations > Integration Partners` under Integrations in the [Account Settings](https://ss.shipstation.com/#/settings/integrations). * * Learn more about webhooks in ShipStation's UI in this [ShipStation Webhooks KB article](https://help.shipstation.com/hc/en-us/articles/360025856252). * * @param webhookId A unique ID generated by ShipStation and assigned to each webhook. */ unsubscribe(webhookId) { return __awaiter(this, void 0, void 0, function* () { yield this.shipstation.request({ url: `${this.baseUrl}/${webhookId}`, method: 'DELETE' }); }); } }