@ikatec/digisac-api-sdk 4.6.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,7 @@ const people = new PeopleApi(client)
25
25
  const result = await tickets.getMany({
26
26
  page: 1,
27
27
  perPage: 20,
28
- where: { status: 'open' },
28
+ where: { isOpen: true },
29
29
  order: [['createdAt', 'DESC']],
30
30
  })
31
31
  console.log(result.data) // Ticket[]
@@ -34,14 +34,17 @@ console.log(result.total) // number
34
34
  // Get by ID
35
35
  const ticket = await tickets.getById('ticket-uuid')
36
36
 
37
+ // Resource-specific routes
38
+ const { count } = await tickets.count({ where: { isOpen: true } })
39
+
37
40
  // Create
38
- const newTicket = await tickets.create({ /* CreateTicketPayload */ })
41
+ const person = await people.create({ /* CreatePersonPayload */ })
39
42
 
40
43
  // Update
41
- const updated = await tickets.updateById('ticket-uuid', { /* UpdateTicketPayload */ })
44
+ const updated = await people.updateById(person.id, { /* UpdatePersonPayload */ })
42
45
 
43
46
  // Delete
44
- await tickets.deleteById('ticket-uuid')
47
+ await people.deleteById(person.id)
45
48
  ```
46
49
 
47
50
  ## Architecture
@@ -224,7 +227,7 @@ import {
224
227
  } from '@ikatec/digisac-api-sdk'
225
228
 
226
229
  try {
227
- await tickets.create(payload)
230
+ await people.create(payload)
228
231
  } catch (error) {
229
232
  if (error instanceof ValidationError) {
230
233
  for (const { field, message, code } of error.validationErrors) {
@@ -292,8 +295,8 @@ function handleWebhook(payload: WebhookPayload) {
292
295
  }
293
296
 
294
297
  if (payload.event === 'ticket.updated') {
295
- // payload.data is Omit<Ticket, TicketRelationships>
296
- console.log(payload.data.isOpen)
298
+ // payload.data is TicketWebhookData: the ticket plus its contact
299
+ console.log(payload.data.isOpen, payload.data.contact.serviceId)
297
300
  }
298
301
 
299
302
  if (payload.event === 'bot.command') {
@@ -320,7 +323,7 @@ function handleMessageCreated(payload: WebhookPayload<'message.created'>) {
320
323
  | Event | `data` type |
321
324
  |---|---|
322
325
  | `message.created` / `message.updated` | `Omit<Message, MessageRelationships>` |
323
- | `ticket.created` / `ticket.updated` | `Omit<Ticket, TicketRelationships>` |
326
+ | `ticket.created` / `ticket.updated` | `TicketWebhookData` (`Omit<Ticket, TicketRelationships>` plus `contact`: `Omit<Contact, ContactRelationships>`) |
324
327
  | `contact.created` / `contact.updated` / `contact.destroyed` | `Omit<Contact, ContactRelationships>` |
325
328
  | `service.created` / `service.updated` / `service.destroyed` | `Omit<Service, ServiceRelationships>` |
326
329
  | `user.created` / `user.updated` / `user.destroyed` | `Omit<User, UserRelationships>` |
@@ -1,66 +1,133 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_chunk = require('../../_chunks/chunk-Dk0Otj32.cjs');
2
3
  const require_core_BaseCrudApi = require('../../core/BaseCrudApi.cjs');
3
4
  require('../../core/index.cjs');
5
+ let qs = require("qs");
6
+ qs = require_chunk.__toESM(qs);
4
7
 
5
8
  //#region src/apis/campaigns/CampaignsApi.ts
9
+ /**
10
+ * Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of
11
+ * the account.
12
+ * `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see
13
+ * {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the
14
+ * text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default
15
+ * `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.
16
+ */
6
17
  var CampaignsApi = class extends require_core_BaseCrudApi.BaseCrudApi {
7
18
  constructor(client) {
8
19
  super(client, "/campaigns");
9
- this.sendById = this.sendById.bind(this);
10
- this.pauseById = this.pauseById.bind(this);
11
- this.resumeById = this.resumeById.bind(this);
12
- this.duplicateById = this.duplicateById.bind(this);
13
- this.getStatsById = this.getStatsById.bind(this);
14
- this.setIntervalById = this.setIntervalById.bind(this);
15
- this.getContactCount = this.getContactCount.bind(this);
16
- this.setAutoPauseMode = this.setAutoPauseMode.bind(this);
17
- this.exportCampaignResult = this.exportCampaignResult.bind(this);
18
- this.exportTemplateCsv = this.exportTemplateCsv.bind(this);
19
- this.getHsmLimit = this.getHsmLimit.bind(this);
20
- }
21
- /** Starts sending messages for the given campaign. */
22
- sendById(id) {
23
- return this.client.post(`${this.basePath}/${id}/send`);
24
- }
25
- /** Pauses a campaign that is currently sending. */
26
- pauseById(id) {
27
- return this.client.post(`${this.basePath}/${id}/pause`);
28
- }
29
- /** Resumes a previously paused campaign. */
30
- resumeById(id) {
31
- return this.client.post(`${this.basePath}/${id}/resume`);
32
- }
33
- /** Creates a copy of an existing campaign. */
34
- duplicateById(id) {
35
- return this.client.post(`${this.basePath}/${id}/duplicate`);
36
- }
37
- /** Returns send/delivery/view statistics for a campaign. */
38
- getStatsById(id) {
39
- return this.client.get(`${this.basePath}/${id}/stats`);
40
- }
41
- /** Updates the min/max send interval for a campaign. */
42
- setIntervalById(id, data) {
43
- return this.client.post(`${this.basePath}/${id}/interval`, data);
44
- }
45
- /** Returns the total number of contacts targeted by a campaign. */
46
- getContactCount(id) {
47
- return this.client.get(`${this.basePath}/${id}/contactCount`);
48
- }
49
- /** Configures the auto-pause behavior for campaigns. */
50
- setAutoPauseMode(data) {
51
- return this.client.put(`${this.basePath}/autoPauseMode`, data);
52
- }
53
- /** Exports campaign send results as a CSV file. */
54
- exportCampaignResult(data) {
55
- return this.client.post(`${this.basePath}/export/csv`, data);
56
- }
57
- /** Exports a CSV template for importing contacts into an HSM campaign. */
58
- exportTemplateCsv(data) {
59
- return this.client.post(`${this.basePath}/exportTemplate`, data);
60
- }
61
- /** Returns the HSM message usage and limit for an account. */
62
- getHsmLimit(accountId) {
63
- return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`);
20
+ }
21
+ /**
22
+ * Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back
23
+ * to `importing_contacts`). It becomes `done` once every contact is fired.
24
+ * @permissions campaigns.view
25
+ */
26
+ sendById(id, headers) {
27
+ return this.client.post(`${this.basePath}/${id}/send`, void 0, headers);
28
+ }
29
+ /**
30
+ * Sets the campaign as `paused` and answers `true`. An unknown id answers 500.
31
+ * @permissions campaigns.view
32
+ */
33
+ pauseById(id, headers) {
34
+ return this.client.post(`${this.basePath}/${id}/pause`, void 0, headers);
35
+ }
36
+ /**
37
+ * Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.
38
+ * @permissions campaigns.view
39
+ */
40
+ resumeById(id, headers) {
41
+ return this.client.post(`${this.basePath}/${id}/resume`, void 0, headers);
42
+ }
43
+ /**
44
+ * Fires again the messages that failed: sets them as pending and the campaign as `processing`.
45
+ * Answers the text `'OK'` (also when nothing failed, and then the status does not change); an
46
+ * unknown id answers `false` (status 200).
47
+ * @permissions campaigns.view
48
+ */
49
+ retryById(id, headers) {
50
+ return this.client.post(`${this.basePath}/${id}/retry`, void 0, headers);
51
+ }
52
+ /**
53
+ * Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the
54
+ * messages. An unknown id answers 500.
55
+ * @permissions campaigns.view
56
+ */
57
+ duplicateById(id, headers) {
58
+ return this.client.post(`${this.basePath}/${id}/duplicate`, void 0, headers);
59
+ }
60
+ /** Returns the send, delivery and interaction statistics of the campaign. */
61
+ getStatsById(id, headers) {
62
+ return this.client.get(`${this.basePath}/${id}/stats`, headers);
63
+ }
64
+ /**
65
+ * Returns the events of the campaign (created, scheduled, started, finished and the last
66
+ * interruption), the most recent first.
67
+ */
68
+ getTimeline(id, headers) {
69
+ return this.client.get(`${this.basePath}/${id}/timeline`, headers);
70
+ }
71
+ /**
72
+ * Returns a page of the contacts of the campaign with their sending status (15 per page by
73
+ * default). An unknown id answers an empty page.
74
+ */
75
+ getContacts(id, query, headers) {
76
+ return this.client.get(`${this.basePath}/${id}/contacts${this.toQueryString(query)}`, headers);
77
+ }
78
+ /**
79
+ * Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.
80
+ * An unknown id answers 500.
81
+ * @permissions campaigns.view
82
+ */
83
+ setIntervalById(id, data, headers) {
84
+ return this.client.post(`${this.basePath}/${id}/interval`, data, headers);
85
+ }
86
+ /** Returns the number of contacts targeted by the campaign. */
87
+ getContactCount(id, headers) {
88
+ return this.client.get(`${this.basePath}/${id}/contactCount`, headers);
89
+ }
90
+ /** Counts the `ready` campaigns of a connection. An unknown id counts 0. */
91
+ countReadyByService(serviceId, headers) {
92
+ return this.client.get(`${this.basePath}/count-ready/${serviceId}`, headers);
93
+ }
94
+ /**
95
+ * Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the
96
+ * text `'OK'`, or `false` when the account was not updated.
97
+ */
98
+ setAutoPauseMode(data, headers) {
99
+ return this.client.put(`${this.basePath}/autoPauseMode`, data, headers);
100
+ }
101
+ /**
102
+ * Exports the contacts of the campaign and their sending result as CSV (13 columns in the
103
+ * language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.
104
+ */
105
+ exportCampaignResult(data, headers) {
106
+ return this.client.post(`${this.basePath}/export/csv`, data, headers);
107
+ }
108
+ /** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */
109
+ exportTemplateCsv(data, headers) {
110
+ return this.client.post(`${this.basePath}/exportTemplate`, data, headers);
111
+ }
112
+ /**
113
+ * Exports the rows of the import file that were not imported (invalid number, unknown or
114
+ * ambiguous username) as CSV: line, name, number, username and reason.
115
+ */
116
+ exportImportErrors(id, query, headers) {
117
+ const queryString = query?.delimiter ? `?${qs.default.stringify({ delimiter: query.delimiter })}` : "";
118
+ return this.client.get(`${this.basePath}/${id}/import-errors${queryString}`, headers);
119
+ }
120
+ /**
121
+ * Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or
122
+ * an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.
123
+ * @permissions campaigns.view OR campaigns.destroy
124
+ */
125
+ deleteMany(ids, headers) {
126
+ return this.client.request("DELETE", `${this.basePath}/delete-many`, { ids }, headers);
127
+ }
128
+ /** Returns the HSM message usage and limit of an account. */
129
+ getHsmLimit(accountId, headers) {
130
+ return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers);
64
131
  }
65
132
  };
66
133
 
@@ -1 +1 @@
1
- {"version":3,"file":"CampaignsApi.cjs","names":["BaseCrudApi"],"sources":["../../../src/apis/campaigns/CampaignsApi.ts"],"sourcesContent":["import type { ApiClient } from '../../core'\nimport { BaseCrudApi } from '../../core'\nimport type {\n AutoPauseModePayload,\n Campaign,\n CampaignStats,\n CreateCampaignPayload,\n ExportCampaignResultPayload,\n ExportTemplateCsvPayload,\n HsmLimit,\n SetIntervalPayload,\n UpdateCampaignPayload,\n} from './types'\n\nexport class CampaignsApi extends BaseCrudApi<\n Campaign,\n CreateCampaignPayload,\n UpdateCampaignPayload\n> {\n constructor(client: ApiClient) {\n super(client, '/campaigns')\n\n this.sendById = this.sendById.bind(this)\n this.pauseById = this.pauseById.bind(this)\n this.resumeById = this.resumeById.bind(this)\n this.duplicateById = this.duplicateById.bind(this)\n this.getStatsById = this.getStatsById.bind(this)\n this.setIntervalById = this.setIntervalById.bind(this)\n this.getContactCount = this.getContactCount.bind(this)\n this.setAutoPauseMode = this.setAutoPauseMode.bind(this)\n this.exportCampaignResult = this.exportCampaignResult.bind(this)\n this.exportTemplateCsv = this.exportTemplateCsv.bind(this)\n this.getHsmLimit = this.getHsmLimit.bind(this)\n }\n\n /** Starts sending messages for the given campaign. */\n sendById(id: string): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/send`)\n }\n\n /** Pauses a campaign that is currently sending. */\n pauseById(id: string): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/pause`)\n }\n\n /** Resumes a previously paused campaign. */\n resumeById(id: string): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/resume`)\n }\n\n /** Creates a copy of an existing campaign. */\n duplicateById(id: string): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/duplicate`)\n }\n\n /** Returns send/delivery/view statistics for a campaign. */\n getStatsById(id: string): Promise<CampaignStats> {\n return this.client.get<CampaignStats>(`${this.basePath}/${id}/stats`)\n }\n\n /** Updates the min/max send interval for a campaign. */\n setIntervalById(id: string, data: SetIntervalPayload): Promise<Campaign> {\n return this.client.post<Campaign, SetIntervalPayload>(`${this.basePath}/${id}/interval`, data)\n }\n\n /** Returns the total number of contacts targeted by a campaign. */\n getContactCount(id: string): Promise<number> {\n return this.client.get<number>(`${this.basePath}/${id}/contactCount`)\n }\n\n /** Configures the auto-pause behavior for campaigns. */\n setAutoPauseMode(data: AutoPauseModePayload): Promise<unknown> {\n return this.client.put(`${this.basePath}/autoPauseMode`, data)\n }\n\n /** Exports campaign send results as a CSV file. */\n exportCampaignResult(data: ExportCampaignResultPayload): Promise<unknown> {\n return this.client.post(`${this.basePath}/export/csv`, data)\n }\n\n /** Exports a CSV template for importing contacts into an HSM campaign. */\n exportTemplateCsv(data: ExportTemplateCsvPayload): Promise<unknown> {\n return this.client.post(`${this.basePath}/exportTemplate`, data)\n }\n\n /** Returns the HSM message usage and limit for an account. */\n getHsmLimit(accountId: string): Promise<HsmLimit> {\n return this.client.get<HsmLimit>(`/whatsapp-business-templates/${accountId}/hsmLimit`)\n }\n}\n"],"mappings":";;;;;AAcA,IAAa,eAAb,cAAkCA,qCAIhC;CACA,YAAY,QAAmB;AAC7B,QAAM,QAAQ,aAAa;AAE3B,OAAK,WAAW,KAAK,SAAS,KAAK,KAAK;AACxC,OAAK,YAAY,KAAK,UAAU,KAAK,KAAK;AAC1C,OAAK,aAAa,KAAK,WAAW,KAAK,KAAK;AAC5C,OAAK,gBAAgB,KAAK,cAAc,KAAK,KAAK;AAClD,OAAK,eAAe,KAAK,aAAa,KAAK,KAAK;AAChD,OAAK,kBAAkB,KAAK,gBAAgB,KAAK,KAAK;AACtD,OAAK,kBAAkB,KAAK,gBAAgB,KAAK,KAAK;AACtD,OAA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ignsApi.ts"],"sourcesContent":["import qs from 'qs'\nimport type { ApiClient } from '../../core'\nimport { BaseCrudApi } from '../../core'\nimport type {\n AutoPauseModePayload,\n Campaign,\n CampaignContactsPage,\n CampaignContactsQuery,\n CampaignListQuery,\n CampaignStats,\n CampaignTimelineEvent,\n CreateCampaignPayload,\n ExportCampaignImportErrorsQuery,\n ExportCampaignResultPayload,\n ExportTemplateCsvPayload,\n HsmLimit,\n SetIntervalPayload,\n UpdateCampaignPayload,\n} from './types'\n\n/**\n * Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of\n * the account.\n * `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see\n * {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the\n * text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default\n * `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.\n */\nexport class CampaignsApi extends BaseCrudApi<\n Campaign,\n CreateCampaignPayload,\n UpdateCampaignPayload,\n CampaignListQuery,\n 'OK'\n> {\n constructor(client: ApiClient) {\n super(client, '/campaigns')\n }\n\n /**\n * Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back\n * to `importing_contacts`). It becomes `done` once every contact is fired.\n * @permissions campaigns.view\n */\n sendById(id: string, headers?: Record<string, string>): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/send`, undefined, headers)\n }\n\n /**\n * Sets the campaign as `paused` and answers `true`. An unknown id answers 500.\n * @permissions campaigns.view\n */\n pauseById(id: string, headers?: Record<string, string>): Promise<boolean> {\n return this.client.post<boolean>(`${this.basePath}/${id}/pause`, undefined, headers)\n }\n\n /**\n * Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.\n * @permissions campaigns.view\n */\n resumeById(id: string, headers?: Record<string, string>): Promise<boolean> {\n return this.client.post<boolean>(`${this.basePath}/${id}/resume`, undefined, headers)\n }\n\n /**\n * Fires again the messages that failed: sets them as pending and the campaign as `processing`.\n * Answers the text `'OK'` (also when nothing failed, and then the status does not change); an\n * unknown id answers `false` (status 200).\n * @permissions campaigns.view\n */\n retryById(id: string, headers?: Record<string, string>): Promise<'OK' | false> {\n return this.client.post<'OK' | false>(`${this.basePath}/${id}/retry`, undefined, headers)\n }\n\n /**\n * Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the\n * messages. An unknown id answers 500.\n * @permissions campaigns.view\n */\n duplicateById(id: string, headers?: Record<string, string>): Promise<Campaign> {\n return this.client.post<Campaign>(`${this.basePath}/${id}/duplicate`, undefined, headers)\n }\n\n /** Returns the send, delivery and interaction statistics of the campaign. */\n getStatsById(id: string, headers?: Record<string, string>): Promise<CampaignStats> {\n return this.client.get<CampaignStats>(`${this.basePath}/${id}/stats`, headers)\n }\n\n /**\n * Returns the events of the campaign (created, scheduled, started, finished and the last\n * interruption), the most recent first.\n */\n getTimeline(id: string, headers?: Record<string, string>): Promise<CampaignTimelineEvent[]> {\n return this.client.get<CampaignTimelineEvent[]>(`${this.basePath}/${id}/timeline`, headers)\n }\n\n /**\n * Returns a page of the contacts of the campaign with their sending status (15 per page by\n * default). An unknown id answers an empty page.\n */\n getContacts(\n id: string,\n query?: CampaignContactsQuery,\n headers?: Record<string, string>,\n ): Promise<CampaignContactsPage> {\n return this.client.get<CampaignContactsPage>(\n `${this.basePath}/${id}/contacts${this.toQueryString(query)}`,\n headers,\n )\n }\n\n /**\n * Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.\n * An unknown id answers 500.\n * @permissions campaigns.view\n */\n setIntervalById(\n id: string,\n data: SetIntervalPayload,\n headers?: Record<string, string>,\n ): Promise<boolean> {\n return this.client.post<boolean, SetIntervalPayload>(\n `${this.basePath}/${id}/interval`,\n data,\n headers,\n )\n }\n\n /** Returns the number of contacts targeted by the campaign. */\n getContactCount(id: string, headers?: Record<string, string>): Promise<number> {\n return this.client.get<number>(`${this.basePath}/${id}/contactCount`, headers)\n }\n\n /** Counts the `ready` campaigns of a connection. An unknown id counts 0. */\n countReadyByService(serviceId: string, headers?: Record<string, string>): Promise<number> {\n return this.client.get<number>(`${this.basePath}/count-ready/${serviceId}`, headers)\n }\n\n /**\n * Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the\n * text `'OK'`, or `false` when the account was not updated.\n */\n setAutoPauseMode(\n data: AutoPauseModePayload,\n headers?: Record<string, string>,\n ): Promise<'OK' | false> {\n return this.client.put<'OK' | false, AutoPauseModePayload>(\n `${this.basePath}/autoPauseMode`,\n data,\n headers,\n )\n }\n\n /**\n * Exports the contacts of the campaign and their sending result as CSV (13 columns in the\n * language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.\n */\n exportCampaignResult(\n data: ExportCampaignResultPayload,\n headers?: Record<string, string>,\n ): Promise<string> {\n return this.client.post<string, ExportCampaignResultPayload>(\n `${this.basePath}/export/csv`,\n data,\n headers,\n )\n }\n\n /** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */\n exportTemplateCsv(\n data: ExportTemplateCsvPayload,\n headers?: Record<string, string>,\n ): Promise<string> {\n return this.client.post<string, ExportTemplateCsvPayload>(\n `${this.basePath}/exportTemplate`,\n data,\n headers,\n )\n }\n\n /**\n * Exports the rows of the import file that were not imported (invalid number, unknown or\n * ambiguous username) as CSV: line, name, number, username and reason.\n */\n exportImportErrors(\n id: string,\n query?: ExportCampaignImportErrorsQuery,\n headers?: Record<string, string>,\n ): Promise<string> {\n const queryString = query?.delimiter ? `?${qs.stringify({ delimiter: query.delimiter })}` : ''\n return this.client.get<string>(`${this.basePath}/${id}/import-errors${queryString}`, headers)\n }\n\n /**\n * Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or\n * an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.\n * @permissions campaigns.view OR campaigns.destroy\n */\n deleteMany(ids: string[], headers?: Record<string, string>): Promise<true> {\n return this.client.request<true, { ids: string[] }>(\n 'DELETE',\n `${this.basePath}/delete-many`,\n { ids },\n headers,\n )\n }\n\n /** Returns the HSM message usage and limit of an account. */\n getHsmLimit(accountId: string, headers?: Record<string, string>): Promise<HsmLimit> {\n return this.client.get<HsmLimit>(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,IAAa,eAAb,cAAkCA,qCAMhC;CACA,YAAY,QAAmB;AAC7B,QAAM,QAAQ,aAAa;;;;;;;CAQ7B,SAAS,IAAY,SAAqD;AACxE,SAAO,KAAK,OAAO,KAAe,GAAG,KAAK,SAAS,GAAG,GAAG,QAAQ,QAAW,QAAQ;;;;;;CAOtF,UAAU,IAAY,SAAoD;AACxE,SAAO,KAAK,OAAO,KAAc,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAW,QAAQ;;;;;;CAOtF,WAAW,IAAY,SAAoD;AACzE,SAAO,KAAK,OAAO,KAAc,GAAG,KAAK,SAAS,GAAG,GAAG,UAAU,QAAW,QAAQ;;;;;;;;CASvF,UAAU,IAAY,SAAyD;AAC7E,SAAO,KAAK,OAAO,KAAmB,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAW,QAAQ;;;;;;;CAQ3F,cAAc,IAAY,SAAqD;AAC7E,SAAO,KAAK,OAAO,KAAe,GAAG,KAAK,SAAS,GAAG,GAAG,aAAa,QAAW,QAAQ;;;CAI3F,aAAa,IAAY,SAA0D;AACjF,SAAO,KAAK,OAAO,IAAmB,GAAG,KAAK,SAAS,GAAG,GAAG,SAAS,QAAQ;;;;;;CAOhF,YAAY,IAAY,SAAoE;AAC1F,SAAO,KAAK,OAAO,IAA6B,GAAG,KAAK,SAAS,GAAG,GAAG,YAAY,QAAQ;;;;;;CAO7F,YACE,IACA,OACA,SAC+B;AAC/B,SAAO,KAAK,OAAO,IACjB,GAAG,KAAK,SAAS,GAAG,GAAG,WAAW,KAAK,cAAc,MAAM,IAC3D,QACD;;;;;;;CAQH,gBACE,IACA,MACA,SACkB;AAClB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,GAAG,GAAG,YACvB,MACA,QACD;;;CAIH,gBAAgB,IAAY,SAAmD;AAC7E,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,GAAG,GAAG,gBAAgB,QAAQ;;;CAIhF,oBAAoB,WAAmB,SAAmD;AACxF,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,eAAe,aAAa,QAAQ;;;;;;CAOtF,iBACE,MACA,SACuB;AACvB,SAAO,KAAK,OAAO,IACjB,GAAG,KAAK,SAAS,iBACjB,MACA,QACD;;;;;;CAOH,qBACE,MACA,SACiB;AACjB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,cACjB,MACA,QACD;;;CAIH,kBACE,MACA,SACiB;AACjB,SAAO,KAAK,OAAO,KACjB,GAAG,KAAK,SAAS,kBACjB,MACA,QACD;;;;;;CAOH,mBACE,IACA,OACA,SACiB;EACjB,MAAM,cAAc,OAAO,YAAY,IAAI,WAAG,UAAU,EAAE,WAAW,MAAM,WAAW,CAAC,KAAK;AAC5F,SAAO,KAAK,OAAO,IAAY,GAAG,KAAK,SAAS,GAAG,GAAG,gBAAgB,eAAe,QAAQ;;;;;;;CAQ/F,WAAW,KAAe,SAAiD;AACzE,SAAO,KAAK,OAAO,QACjB,UACA,GAAG,KAAK,SAAS,eACjB,EAAE,KAAK,EACP,QACD;;;CAIH,YAAY,WAAmB,SAAqD;AAClF,SAAO,KAAK,OAAO,IAAc,gCAAgC,UAAU,YAAY,QAAQ"}
@@ -1,29 +1,91 @@
1
1
  import type { ApiClient } from '../../core';
2
2
  import { BaseCrudApi } from '../../core';
3
- import type { AutoPauseModePayload, Campaign, CampaignStats, CreateCampaignPayload, ExportCampaignResultPayload, ExportTemplateCsvPayload, HsmLimit, SetIntervalPayload, UpdateCampaignPayload } from './types';
4
- export declare class CampaignsApi extends BaseCrudApi<Campaign, CreateCampaignPayload, UpdateCampaignPayload> {
3
+ import type { AutoPauseModePayload, Campaign, CampaignContactsPage, CampaignContactsQuery, CampaignListQuery, CampaignStats, CampaignTimelineEvent, CreateCampaignPayload, ExportCampaignImportErrorsQuery, ExportCampaignResultPayload, ExportTemplateCsvPayload, HsmLimit, SetIntervalPayload, UpdateCampaignPayload } from './types';
4
+ /**
5
+ * Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of
6
+ * the account.
7
+ * `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see
8
+ * {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the
9
+ * text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default
10
+ * `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.
11
+ */
12
+ export declare class CampaignsApi extends BaseCrudApi<Campaign, CreateCampaignPayload, UpdateCampaignPayload, CampaignListQuery, 'OK'> {
5
13
  constructor(client: ApiClient);
6
- /** Starts sending messages for the given campaign. */
7
- sendById(id: string): Promise<Campaign>;
8
- /** Pauses a campaign that is currently sending. */
9
- pauseById(id: string): Promise<Campaign>;
10
- /** Resumes a previously paused campaign. */
11
- resumeById(id: string): Promise<Campaign>;
12
- /** Creates a copy of an existing campaign. */
13
- duplicateById(id: string): Promise<Campaign>;
14
- /** Returns send/delivery/view statistics for a campaign. */
15
- getStatsById(id: string): Promise<CampaignStats>;
16
- /** Updates the min/max send interval for a campaign. */
17
- setIntervalById(id: string, data: SetIntervalPayload): Promise<Campaign>;
18
- /** Returns the total number of contacts targeted by a campaign. */
19
- getContactCount(id: string): Promise<number>;
20
- /** Configures the auto-pause behavior for campaigns. */
21
- setAutoPauseMode(data: AutoPauseModePayload): Promise<unknown>;
22
- /** Exports campaign send results as a CSV file. */
23
- exportCampaignResult(data: ExportCampaignResultPayload): Promise<unknown>;
24
- /** Exports a CSV template for importing contacts into an HSM campaign. */
25
- exportTemplateCsv(data: ExportTemplateCsvPayload): Promise<unknown>;
26
- /** Returns the HSM message usage and limit for an account. */
27
- getHsmLimit(accountId: string): Promise<HsmLimit>;
14
+ /**
15
+ * Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back
16
+ * to `importing_contacts`). It becomes `done` once every contact is fired.
17
+ * @permissions campaigns.view
18
+ */
19
+ sendById(id: string, headers?: Record<string, string>): Promise<Campaign>;
20
+ /**
21
+ * Sets the campaign as `paused` and answers `true`. An unknown id answers 500.
22
+ * @permissions campaigns.view
23
+ */
24
+ pauseById(id: string, headers?: Record<string, string>): Promise<boolean>;
25
+ /**
26
+ * Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.
27
+ * @permissions campaigns.view
28
+ */
29
+ resumeById(id: string, headers?: Record<string, string>): Promise<boolean>;
30
+ /**
31
+ * Fires again the messages that failed: sets them as pending and the campaign as `processing`.
32
+ * Answers the text `'OK'` (also when nothing failed, and then the status does not change); an
33
+ * unknown id answers `false` (status 200).
34
+ * @permissions campaigns.view
35
+ */
36
+ retryById(id: string, headers?: Record<string, string>): Promise<'OK' | false>;
37
+ /**
38
+ * Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the
39
+ * messages. An unknown id answers 500.
40
+ * @permissions campaigns.view
41
+ */
42
+ duplicateById(id: string, headers?: Record<string, string>): Promise<Campaign>;
43
+ /** Returns the send, delivery and interaction statistics of the campaign. */
44
+ getStatsById(id: string, headers?: Record<string, string>): Promise<CampaignStats>;
45
+ /**
46
+ * Returns the events of the campaign (created, scheduled, started, finished and the last
47
+ * interruption), the most recent first.
48
+ */
49
+ getTimeline(id: string, headers?: Record<string, string>): Promise<CampaignTimelineEvent[]>;
50
+ /**
51
+ * Returns a page of the contacts of the campaign with their sending status (15 per page by
52
+ * default). An unknown id answers an empty page.
53
+ */
54
+ getContacts(id: string, query?: CampaignContactsQuery, headers?: Record<string, string>): Promise<CampaignContactsPage>;
55
+ /**
56
+ * Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.
57
+ * An unknown id answers 500.
58
+ * @permissions campaigns.view
59
+ */
60
+ setIntervalById(id: string, data: SetIntervalPayload, headers?: Record<string, string>): Promise<boolean>;
61
+ /** Returns the number of contacts targeted by the campaign. */
62
+ getContactCount(id: string, headers?: Record<string, string>): Promise<number>;
63
+ /** Counts the `ready` campaigns of a connection. An unknown id counts 0. */
64
+ countReadyByService(serviceId: string, headers?: Record<string, string>): Promise<number>;
65
+ /**
66
+ * Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the
67
+ * text `'OK'`, or `false` when the account was not updated.
68
+ */
69
+ setAutoPauseMode(data: AutoPauseModePayload, headers?: Record<string, string>): Promise<'OK' | false>;
70
+ /**
71
+ * Exports the contacts of the campaign and their sending result as CSV (13 columns in the
72
+ * language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.
73
+ */
74
+ exportCampaignResult(data: ExportCampaignResultPayload, headers?: Record<string, string>): Promise<string>;
75
+ /** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */
76
+ exportTemplateCsv(data: ExportTemplateCsvPayload, headers?: Record<string, string>): Promise<string>;
77
+ /**
78
+ * Exports the rows of the import file that were not imported (invalid number, unknown or
79
+ * ambiguous username) as CSV: line, name, number, username and reason.
80
+ */
81
+ exportImportErrors(id: string, query?: ExportCampaignImportErrorsQuery, headers?: Record<string, string>): Promise<string>;
82
+ /**
83
+ * Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or
84
+ * an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.
85
+ * @permissions campaigns.view OR campaigns.destroy
86
+ */
87
+ deleteMany(ids: string[], headers?: Record<string, string>): Promise<true>;
88
+ /** Returns the HSM message usage and limit of an account. */
89
+ getHsmLimit(accountId: string, headers?: Record<string, string>): Promise<HsmLimit>;
28
90
  }
29
91
  //# sourceMappingURL=CampaignsApi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CampaignsApi.d.ts","sourceRoot":"","sources":["../../../src/apis/campaigns/Campaigns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,CAAC,GAC/B,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;IAQxB;;;OAGG;IACH,oBAAoB,CAClB,IAAI,EAAE,2BAA2B,EACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,MAAM,CAAC;IAQlB,6FAA6F;IAC7F,iBAAiB,CACf,IAAI,EAAE,wBAAwB,EAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,MAAM,CAAC;IAQlB;;;OAGG;IACH,kBAAkB,CAChB,EAAE,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,+BAA+B,EACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;OAIG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1E,6DAA6D;IAC7D,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGpF"}
@@ -1,65 +1,130 @@
1
1
  import { BaseCrudApi } from "../../core/BaseCrudApi.mjs";
2
2
  import "../../core/index.mjs";
3
+ import qs from "qs";
3
4
 
4
5
  //#region src/apis/campaigns/CampaignsApi.ts
6
+ /**
7
+ * Campaigns (mass sending). Every `/campaigns` route requires the campaigns feature in the plan of
8
+ * the account.
9
+ * `getMany` takes the `where` of a `ListQuery` and the flat filters of the Campaigns screen (see
10
+ * {@link CampaignListQuery}); `getById` of an unknown id resolves `null`. `deleteById` answers the
11
+ * text `'OK'`. `getMany({ paginate: false })` answers 400 `FILTER_PARAM_INVALID` with the default
12
+ * `'json'` query format (the route only takes `paginate` as a string): use `withQueryFormat('qs')`.
13
+ */
5
14
  var CampaignsApi = class extends BaseCrudApi {
6
15
  constructor(client) {
7
16
  super(client, "/campaigns");
8
- this.sendById = this.sendById.bind(this);
9
- this.pauseById = this.pauseById.bind(this);
10
- this.resumeById = this.resumeById.bind(this);
11
- this.duplicateById = this.duplicateById.bind(this);
12
- this.getStatsById = this.getStatsById.bind(this);
13
- this.setIntervalById = this.setIntervalById.bind(this);
14
- this.getContactCount = this.getContactCount.bind(this);
15
- this.setAutoPauseMode = this.setAutoPauseMode.bind(this);
16
- this.exportCampaignResult = this.exportCampaignResult.bind(this);
17
- this.exportTemplateCsv = this.exportTemplateCsv.bind(this);
18
- this.getHsmLimit = this.getHsmLimit.bind(this);
19
- }
20
- /** Starts sending messages for the given campaign. */
21
- sendById(id) {
22
- return this.client.post(`${this.basePath}/${id}/send`);
23
- }
24
- /** Pauses a campaign that is currently sending. */
25
- pauseById(id) {
26
- return this.client.post(`${this.basePath}/${id}/pause`);
27
- }
28
- /** Resumes a previously paused campaign. */
29
- resumeById(id) {
30
- return this.client.post(`${this.basePath}/${id}/resume`);
31
- }
32
- /** Creates a copy of an existing campaign. */
33
- duplicateById(id) {
34
- return this.client.post(`${this.basePath}/${id}/duplicate`);
35
- }
36
- /** Returns send/delivery/view statistics for a campaign. */
37
- getStatsById(id) {
38
- return this.client.get(`${this.basePath}/${id}/stats`);
39
- }
40
- /** Updates the min/max send interval for a campaign. */
41
- setIntervalById(id, data) {
42
- return this.client.post(`${this.basePath}/${id}/interval`, data);
43
- }
44
- /** Returns the total number of contacts targeted by a campaign. */
45
- getContactCount(id) {
46
- return this.client.get(`${this.basePath}/${id}/contactCount`);
47
- }
48
- /** Configures the auto-pause behavior for campaigns. */
49
- setAutoPauseMode(data) {
50
- return this.client.put(`${this.basePath}/autoPauseMode`, data);
51
- }
52
- /** Exports campaign send results as a CSV file. */
53
- exportCampaignResult(data) {
54
- return this.client.post(`${this.basePath}/export/csv`, data);
55
- }
56
- /** Exports a CSV template for importing contacts into an HSM campaign. */
57
- exportTemplateCsv(data) {
58
- return this.client.post(`${this.basePath}/exportTemplate`, data);
59
- }
60
- /** Returns the HSM message usage and limit for an account. */
61
- getHsmLimit(accountId) {
62
- return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`);
17
+ }
18
+ /**
19
+ * Starts sending the campaign: answers it as `processing` (an `import_error` campaign goes back
20
+ * to `importing_contacts`). It becomes `done` once every contact is fired.
21
+ * @permissions campaigns.view
22
+ */
23
+ sendById(id, headers) {
24
+ return this.client.post(`${this.basePath}/${id}/send`, void 0, headers);
25
+ }
26
+ /**
27
+ * Sets the campaign as `paused` and answers `true`. An unknown id answers 500.
28
+ * @permissions campaigns.view
29
+ */
30
+ pauseById(id, headers) {
31
+ return this.client.post(`${this.basePath}/${id}/pause`, void 0, headers);
32
+ }
33
+ /**
34
+ * Sets the campaign back to `processing` and answers `true`. An unknown id answers 500.
35
+ * @permissions campaigns.view
36
+ */
37
+ resumeById(id, headers) {
38
+ return this.client.post(`${this.basePath}/${id}/resume`, void 0, headers);
39
+ }
40
+ /**
41
+ * Fires again the messages that failed: sets them as pending and the campaign as `processing`.
42
+ * Answers the text `'OK'` (also when nothing failed, and then the status does not change); an
43
+ * unknown id answers `false` (status 200).
44
+ * @permissions campaigns.view
45
+ */
46
+ retryById(id, headers) {
47
+ return this.client.post(`${this.basePath}/${id}/retry`, void 0, headers);
48
+ }
49
+ /**
50
+ * Creates a copy of the campaign (`ready`, same title, messages and tags), answered without the
51
+ * messages. An unknown id answers 500.
52
+ * @permissions campaigns.view
53
+ */
54
+ duplicateById(id, headers) {
55
+ return this.client.post(`${this.basePath}/${id}/duplicate`, void 0, headers);
56
+ }
57
+ /** Returns the send, delivery and interaction statistics of the campaign. */
58
+ getStatsById(id, headers) {
59
+ return this.client.get(`${this.basePath}/${id}/stats`, headers);
60
+ }
61
+ /**
62
+ * Returns the events of the campaign (created, scheduled, started, finished and the last
63
+ * interruption), the most recent first.
64
+ */
65
+ getTimeline(id, headers) {
66
+ return this.client.get(`${this.basePath}/${id}/timeline`, headers);
67
+ }
68
+ /**
69
+ * Returns a page of the contacts of the campaign with their sending status (15 per page by
70
+ * default). An unknown id answers an empty page.
71
+ */
72
+ getContacts(id, query, headers) {
73
+ return this.client.get(`${this.basePath}/${id}/contacts${this.toQueryString(query)}`, headers);
74
+ }
75
+ /**
76
+ * Sets the min/max interval between the sends (whole numbers, `0` or more) and answers `true`.
77
+ * An unknown id answers 500.
78
+ * @permissions campaigns.view
79
+ */
80
+ setIntervalById(id, data, headers) {
81
+ return this.client.post(`${this.basePath}/${id}/interval`, data, headers);
82
+ }
83
+ /** Returns the number of contacts targeted by the campaign. */
84
+ getContactCount(id, headers) {
85
+ return this.client.get(`${this.basePath}/${id}/contactCount`, headers);
86
+ }
87
+ /** Counts the `ready` campaigns of a connection. An unknown id counts 0. */
88
+ countReadyByService(serviceId, headers) {
89
+ return this.client.get(`${this.basePath}/count-ready/${serviceId}`, headers);
90
+ }
91
+ /**
92
+ * Sets the auto-pause mode of the campaigns of the account (`settings.campaign`). Answers the
93
+ * text `'OK'`, or `false` when the account was not updated.
94
+ */
95
+ setAutoPauseMode(data, headers) {
96
+ return this.client.put(`${this.basePath}/autoPauseMode`, data, headers);
97
+ }
98
+ /**
99
+ * Exports the contacts of the campaign and their sending result as CSV (13 columns in the
100
+ * language of the user; `,`, or `;` with `type: 'semiColon'`), streamed without a Content-Type.
101
+ */
102
+ exportCampaignResult(data, headers) {
103
+ return this.client.post(`${this.basePath}/export/csv`, data, headers);
104
+ }
105
+ /** Exports the CSV (`;`) to fill in the contacts of a campaign of the given HSM template. */
106
+ exportTemplateCsv(data, headers) {
107
+ return this.client.post(`${this.basePath}/exportTemplate`, data, headers);
108
+ }
109
+ /**
110
+ * Exports the rows of the import file that were not imported (invalid number, unknown or
111
+ * ambiguous username) as CSV: line, name, number, username and reason.
112
+ */
113
+ exportImportErrors(id, query, headers) {
114
+ const queryString = query?.delimiter ? `?${qs.stringify({ delimiter: query.delimiter })}` : "";
115
+ return this.client.get(`${this.basePath}/${id}/import-errors${queryString}`, headers);
116
+ }
117
+ /**
118
+ * Deletes the campaigns of the given ids and answers `true` (unknown ids are skipped). No id, or
119
+ * an id that is not a UUID, answers 400 `{ error: 'Invalid ids', code: 'INVALID_IDS' }`.
120
+ * @permissions campaigns.view OR campaigns.destroy
121
+ */
122
+ deleteMany(ids, headers) {
123
+ return this.client.request("DELETE", `${this.basePath}/delete-many`, { ids }, headers);
124
+ }
125
+ /** Returns the HSM message usage and limit of an account. */
126
+ getHsmLimit(accountId, headers) {
127
+ return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`, headers);
63
128
  }
64
129
  };
65
130