@dawntech/blip-tools 0.1.7 → 0.1.9

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.
@@ -0,0 +1 @@
1
+ export default function encodeBlipParams(params: Record<string, unknown>): string;
@@ -0,0 +1,13 @@
1
+ function normalizeValue(value) {
2
+ return String(value).replaceAll(' ', '%20');
3
+ }
4
+ export default function encodeBlipParams(params) {
5
+ //This function does not uses any of the standard methods of URI parsing because Blip does not follow any of them
6
+ const parsedParams = [];
7
+ for (const [key, value] of Object.entries(params)) {
8
+ if (value && key) {
9
+ parsedParams.push(`${normalizeValue(key)}=${normalizeValue(value)}`);
10
+ }
11
+ }
12
+ return parsedParams.join('&');
13
+ }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,9 @@ import { Template } from './types/template.js';
3
3
  import { Contact } from './types/contact.js';
4
4
  import { BlipConstructor } from './types/blip-constructor.js';
5
5
  import BlipError from './exceptions/blip-error.js';
6
- export { BlipError };
6
+ import { AttendanceHourContainer } from './types/attendance-hour-container.js';
7
+ import { Ticket } from './types/ticket.js';
8
+ export { BlipError, type Ticket, type AttendanceHourContainer, type Contact, type Template };
7
9
  export default class Blip {
8
10
  api: AxiosInstance;
9
11
  constructor(params: BlipConstructor);
@@ -55,4 +57,17 @@ export default class Blip {
55
57
  identity: string;
56
58
  }): Promise<void>;
57
59
  getWhatsAppIdentity(phone: string): Promise<string>;
60
+ createTrackEvent({ category, action, identity }: {
61
+ category: string;
62
+ action: string;
63
+ identity?: string;
64
+ }): Promise<void>;
65
+ getAttendanceHourContainer({ attendanceContainerId }: {
66
+ attendanceContainerId: string;
67
+ }): Promise<AttendanceHourContainer>;
68
+ searchTickets({ filter, skip, take }: {
69
+ filter?: string;
70
+ skip?: number;
71
+ take?: number;
72
+ }): Promise<Ticket[]>;
58
73
  }
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import handleError from './helpers/handle-error.js';
5
5
  import formatTemplateParams from './helpers/format-template-params.js';
6
6
  import validateInstance from './helpers/validate-instance.js';
7
7
  import BlipError from './exceptions/blip-error.js';
8
+ import encodeBlipParams from './helpers/encode-blip-params.js';
8
9
  export { BlipError };
9
10
  export default class Blip {
10
11
  api;
@@ -13,7 +14,7 @@ export default class Blip {
13
14
  this.api = axios.create({
14
15
  baseURL: `https://${params.contract}.http.msging.net`,
15
16
  headers: {
16
- Authorization: `Key ${params.authToken}`,
17
+ Authorization: `Key ${params.authToken.replace('Key ', '')}`,
17
18
  },
18
19
  timeout: 30000,
19
20
  });
@@ -202,4 +203,64 @@ export default class Blip {
202
203
  throw handleError(error);
203
204
  }
204
205
  }
206
+ async createTrackEvent({ category, action, identity }) {
207
+ try {
208
+ const body = {
209
+ id: randomUUID(),
210
+ to: 'postmaster@analytics.msging.net',
211
+ method: 'set',
212
+ type: 'application/vnd.iris.eventTrack+json',
213
+ uri: '/event-track',
214
+ resource: {
215
+ category,
216
+ action,
217
+ },
218
+ };
219
+ if (identity && body.resource) {
220
+ body.resource.contact = { identity };
221
+ }
222
+ const response = await this.api.post('/commands', body);
223
+ validateResponse(response);
224
+ }
225
+ catch (error) {
226
+ throw handleError(error);
227
+ }
228
+ }
229
+ async getAttendanceHourContainer({ attendanceContainerId }) {
230
+ try {
231
+ const body = {
232
+ id: randomUUID(),
233
+ to: 'postmaster@desk.msging.net',
234
+ method: 'get',
235
+ uri: `/attendance-hour-container/${attendanceContainerId}`,
236
+ };
237
+ const response = await this.api.post('/commands', body);
238
+ validateResponse(response);
239
+ return response.data.resource;
240
+ }
241
+ catch (error) {
242
+ throw handleError(error);
243
+ }
244
+ }
245
+ async searchTickets({ filter, skip, take }) {
246
+ try {
247
+ const params = {
248
+ $filter: filter,
249
+ $skip: skip,
250
+ $take: take,
251
+ };
252
+ const body = {
253
+ id: randomUUID(),
254
+ to: 'postmaster@desk.msging.net',
255
+ method: 'get',
256
+ uri: `/tickets?${encodeBlipParams(params)}`,
257
+ };
258
+ const response = await this.api.post('/commands', body);
259
+ validateResponse(response);
260
+ return response.data.resource.items;
261
+ }
262
+ catch (error) {
263
+ throw handleError(error);
264
+ }
265
+ }
205
266
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dawntech/blip-tools",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Node package for Blip API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",