@or-sdk/sku-builder 1.5.5-beta.3826.0 → 1.5.5

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/types/types.d.ts +1 -1
  3. package/dist/types/types.d.ts.map +1 -1
  4. package/package.json +5 -6
  5. package/src/types.ts +1 -1
  6. package/dist/cjs/__tests__/make-sku.spec.js +0 -615
  7. package/dist/cjs/__tests__/make-sku.spec.js.map +0 -1
  8. package/dist/cjs/__tests__/mapping-mock.js +0 -3768
  9. package/dist/cjs/__tests__/mapping-mock.js.map +0 -1
  10. package/dist/cjs/__tests__/mapping.spec.js +0 -70
  11. package/dist/cjs/__tests__/mapping.spec.js.map +0 -1
  12. package/dist/cjs/__tests__/server.js +0 -30
  13. package/dist/cjs/__tests__/server.js.map +0 -1
  14. package/dist/esm/__tests__/make-sku.spec.js +0 -388
  15. package/dist/esm/__tests__/make-sku.spec.js.map +0 -1
  16. package/dist/esm/__tests__/mapping-mock.js +0 -3765
  17. package/dist/esm/__tests__/mapping-mock.js.map +0 -1
  18. package/dist/esm/__tests__/mapping.spec.js +0 -32
  19. package/dist/esm/__tests__/mapping.spec.js.map +0 -1
  20. package/dist/esm/__tests__/server.js +0 -27
  21. package/dist/esm/__tests__/server.js.map +0 -1
  22. package/dist/types/__tests__/make-sku.spec.d.ts +0 -2
  23. package/dist/types/__tests__/make-sku.spec.d.ts.map +0 -1
  24. package/dist/types/__tests__/mapping-mock.d.ts +0 -80
  25. package/dist/types/__tests__/mapping-mock.d.ts.map +0 -1
  26. package/dist/types/__tests__/mapping.spec.d.ts +0 -2
  27. package/dist/types/__tests__/mapping.spec.d.ts.map +0 -1
  28. package/dist/types/__tests__/server.d.ts +0 -2
  29. package/dist/types/__tests__/server.d.ts.map +0 -1
  30. package/src/__tests__/make-sku.spec.ts +0 -433
  31. package/src/__tests__/mapping-mock.ts +0 -3764
  32. package/src/__tests__/mapping.spec.ts +0 -29
  33. package/src/__tests__/server.ts +0 -34
  34. package/vitest.config.mjs +0 -24
@@ -1,433 +0,0 @@
1
- import { afterEach } from 'node:test';
2
- import { afterAll, assert, beforeAll, describe, expect, it } from 'vitest';
3
-
4
- import { SkuBuilder } from '../SkuBuilder';
5
- import { CategoryNamespace } from '../types';
6
-
7
- import { mappingMock } from './mapping-mock';
8
- import { server } from './server';
9
-
10
- describe('Build SKU', () => {
11
- beforeAll(() => server.listen());
12
- afterEach(() => server.resetHandlers());
13
- afterAll(() => server.close());
14
-
15
- const builder = new SkuBuilder({ mapping: mappingMock });
16
-
17
- it(`generate SKU for ${CategoryNamespace.PROCESSING_FLOW}(seconds)`, async () => {
18
- const data = [{
19
- AccountId: '42f5a577-e120-4109-a4ef-806654dc5097',
20
- FlowId: '2a8e9b6f-db20-43cf-ba77-5a86c7f24a6d',
21
- Provider: 'AWS',
22
- Type: 'Flow',
23
- Initiations: 20,
24
- SecondsTotal: 25,
25
- Millisecond200Seg: 140,
26
- }];
27
-
28
- const results = await builder.makeSku(data, CategoryNamespace.PROCESSING_FLOW);
29
-
30
- assert.isArray(results);
31
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
32
- expect(results[0].SKU).toBe('PRC-FLO-SEC');
33
- expect(results[0].Amount).toBe(data[0].SecondsTotal);
34
- });
35
-
36
- it(`generate SKU for ${CategoryNamespace.PROCESSING_FLOW}(segments)`, async () => {
37
- const data = [{
38
- AccountId: '42f5a577-e120-4109-a4ef-806654dc5097',
39
- FlowId: '2a8e9b6f-db20-43cf-ba77-5a86c7f24a6d',
40
- Provider: 'AWS',
41
- Type: 'Flow',
42
- Initiations: 20,
43
- SecondsTotal: 25,
44
- Millisecond200Seg: 140,
45
- }];
46
-
47
- const results = await builder.makeSku(data, CategoryNamespace.PROCESSING_FLOW, { isProcessingSegment: true });
48
-
49
- assert.isArray(results);
50
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
51
- expect(results[0].SKU).toBe('PRC-FLO-SEG');
52
- expect(results[0].Amount).toBe(data[0].Millisecond200Seg);
53
- });
54
-
55
- it(`generate SKU for ${CategoryNamespace.PROCESSING_VOICE}`, async () => {
56
- const data = [{
57
- AccountId: '2e61351d-9171-4416-b74e-ac21831b5fd5',
58
- FlowId: '931fc191-afcd-4430-bac5-486447d14e46',
59
- Provider: 'AWS',
60
- Type: 'Voice Processing',
61
- Initiations: 348,
62
- BillableMinutes: 4234,
63
- }];
64
-
65
- const results = await builder.makeSku(data, CategoryNamespace.PROCESSING_VOICE);
66
-
67
- assert.isArray(results);
68
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
69
- expect(results[0].SKU).toBe('PRC-VOI-MIN');
70
- expect(results[0].Amount).toBe(data[0].BillableMinutes);
71
- });
72
-
73
- it(`generate SKU for ${CategoryNamespace.LOOKUP}`, async () => {
74
- const data = [{
75
- AccountId: '03DB4ABE-0477-47C0-AE4E-4C68F1047D59',
76
- FlowId: '0F14D856-E9E2-4B7E-9502-F6664763A272',
77
- Provider: 'Telesign',
78
- PhoneCountry: 'US',
79
- PhoneCarrier: 'United States',
80
- VisitorType: null,
81
- RiskScore: 1,
82
- RiskLevel: '2',
83
- BillableUnits: 17,
84
- }];
85
-
86
- const results = await builder.makeSku(data, CategoryNamespace.LOOKUP);
87
-
88
- assert.isArray(results);
89
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
90
- expect(results[0].SKU).toBe('EXE-LKP-TLS-NUM');
91
- expect(results[0].Amount).toBe(data[0].BillableUnits);
92
- });
93
-
94
- it(`generate SKU for ${CategoryNamespace.TELEPHONY_VOICE}`, async () => {
95
- const data = [{
96
- AccountId: '7e1bd988-2ab6-4a0e-93f4-43f605c8c1a5',
97
- Provider: 'env_monitoring',
98
- BotNumberType: 'Alphanumeric',
99
- ToCountry: 'Unknown',
100
- Type: 'SIP',
101
- Direction: 'In',
102
- BillableMinutes: 576,
103
- }];
104
-
105
- const results = await builder.makeSku(data, CategoryNamespace.TELEPHONY_VOICE);
106
-
107
- assert.isArray(results);
108
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
109
- expect(results[0].SKU).toBe('TEL-VOI-INB-LCL-UNK-NUM');
110
- expect(results[0].Amount).toBe(data[0].BillableMinutes);
111
- });
112
-
113
- it(`generate SKU for ${CategoryNamespace.MESSAGING_TEXT}`, async () => {
114
- const data = [{
115
- AccountId: 'C6126853-8498-404C-943E-E529BA157621',
116
- Provider: 'Bandwidth',
117
- BotNumberType: 'Longcode',
118
- ToCountry: 'US',
119
- Type: 'SMS',
120
- Direction: 'In',
121
- BillableSegments: '204',
122
- }];
123
-
124
- const results = await builder.makeSku(data, CategoryNamespace.MESSAGING_TEXT);
125
-
126
- assert.isArray(results);
127
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
128
- expect(results[0].SKU).toBe('MSG-SMS-INB-LCL-USA-SEG');
129
- expect(results[0].Amount).toBe(data[0].BillableSegments);
130
- });
131
-
132
- it(`generate SKU for ${CategoryNamespace.CONVERSATIONS_WAP}`, async () => {
133
- const data = [{
134
- AccountId: '672BC912-DFDA-4D5A-A3E5-67648D9648E8',
135
- Provider: 'Nexmo',
136
- ProductName: 'service',
137
- BotIdentifier: '+4942122298166',
138
- BotCountry: 'DE',
139
- VisitorCountry: 'US',
140
- BillableUnits: '5',
141
- }];
142
-
143
- const results = await builder.makeSku(data, CategoryNamespace.CONVERSATIONS_WAP);
144
-
145
- assert.isArray(results);
146
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
147
- expect(results[0].SKU).toBe('MSG-WAP-INB-SRC-USA-CON');
148
- expect(results[0].Amount).toBe(data[0].BillableUnits);
149
- });
150
-
151
- it(`generate SKU for ${CategoryNamespace.STORAGE_GENERAL}`, async () => {
152
- const data = [{
153
- DatabaseName: 'basf_prod',
154
- Type: 'Reporting',
155
- MaxGigabytes: '30',
156
- }];
157
-
158
- const results = await builder.makeSku(data, CategoryNamespace.STORAGE_GENERAL);
159
-
160
- assert.isArray(results);
161
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
162
- expect(results[0].SKU).toBe('STR-DBS-GIG');
163
- expect(results[0].Amount).toBe(data[0].MaxGigabytes);
164
- });
165
-
166
- it(`generate SKU for ${CategoryNamespace.STORAGE_WEAVIATE}`, async () => {
167
- const data = [{
168
- AccountId: '8E918168-5CEC-4E39-8CEC-1990D58E2365',
169
- FlowId: null,
170
- Provider: 'Weaviate',
171
- Type: 'VectorDimensions',
172
- 'SLA Tier': 'standard',
173
- 'High Availability': 'no',
174
- 'Storage Type': 'compression',
175
- BillableSegments: 1196544,
176
- DataObjects: 779,
177
- IndexDimensionality: 0,
178
- Gigabytes: 0,
179
- }];
180
-
181
- const results = await builder.makeSku(data, CategoryNamespace.STORAGE_WEAVIATE);
182
-
183
- assert.isArray(results);
184
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
185
- expect(results[0].SKU).toBe('STR-VKD-TST-HAN-STC-SEG');
186
- expect(results[0].Amount).toBe(data[0].BillableSegments);
187
- });
188
-
189
- it(`generate SKU for ${CategoryNamespace.CARRIER_FEE}`, async () => {
190
- const data = [{
191
- AccountId: '2e61351d-9171-4416-b74e-ac21831b5fd5',
192
- Provider: 'Nexmo',
193
- Type: 'SMS',
194
- BotNumberType: 'Longcode',
195
- MCCMNC: '302320',
196
- CarrierName: 'mobilicity',
197
- ToCountry: 'CA',
198
- Direction: 'Out',
199
- Count: 1,
200
- }];
201
-
202
- const results = await builder.makeSku(data, CategoryNamespace.CARRIER_FEE);
203
-
204
- assert.isArray(results);
205
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
206
- expect(results[0].SKU).toBe('CAR-SMS-OUT-LCL-CAN-ROG-NUM');
207
- expect(results[0].Amount).toBe(data[0].Count);
208
- });
209
-
210
- it(`generate SKU for ${CategoryNamespace.USER}`, async () => {
211
- const data = [{
212
- AccountId: 'a4a9a46e-6ae0-434b-9d38-27e9d802f3dc',
213
- CurrentRole: 'Editor',
214
- CurrentType: null,
215
- Count: 39,
216
- }];
217
-
218
- const results = await builder.makeSku(data, CategoryNamespace.USER);
219
-
220
- assert.isArray(results);
221
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
222
- expect(results[0].SKU).toBe('USR-EDT-NUM');
223
- expect(results[0].Amount).toBe(data[0].Count);
224
- });
225
-
226
- it(`generate SKU for ${CategoryNamespace.IDENTIFIER}`, async () => {
227
- const data = [{
228
- AccountId: '02a83b49-a37b-45d9-b4a9-954bf149f047',
229
- Provider: 'Nexmo',
230
- IdentifierType: 'Longcode',
231
- Country: 'US',
232
- Count: 1,
233
- }];
234
-
235
- const results = await builder.makeSku(data, CategoryNamespace.IDENTIFIER);
236
-
237
- assert.isArray(results);
238
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
239
- expect(results[0].SKU).toBe('IDN-LCL-USA-NUM');
240
- expect(results[0].Amount).toBe(data[0].Count);
241
- });
242
-
243
- it(`generate SKU for ${CategoryNamespace.EXECUTABLE_GENERAL}, handle common case`, async () => {
244
- const data = [{
245
- AccountId: '1B663A5C-3563-434D-AC87-1CBCD9847E26',
246
- FlowId: '7DA35E66-F2D7-4170-A503-1411CDE62F62',
247
- Provider: 'Amazon Polly',
248
- Type: 'Text-to-speech Advanced',
249
- ModelName: null,
250
- Initiations: '3',
251
- AudioDurationSec: null,
252
- AudioDuration15Sec: null,
253
- TokensPrimary: null,
254
- TokensSecondary: null,
255
- CharacterCount: '399',
256
- }];
257
-
258
- const results = await builder.makeSku(data, CategoryNamespace.EXECUTABLE_GENERAL);
259
-
260
- assert.isArray(results);
261
- expect(results).toHaveLength(1);
262
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
263
- expect(results[0].SKU).toBe('EXE-TTS-ANP-NUL-NUM');
264
- expect(results[0].Amount).toBe(data[0].CharacterCount);
265
- });
266
-
267
- it(`generate SKU for ${CategoryNamespace.EXECUTABLE_GENERAL}, handle Voice events`, async () => {
268
- const data = [{
269
- AccountId: 'FA201FCA-7585-4F2B-BF51-AEF87F028FA2',
270
- FlowId: '8F999274-2E13-41AB-940C-2D6A4764569B',
271
- Provider: 'Nuance',
272
- Type: 'Voice Recognition',
273
- ModelName: null,
274
- Initiations: '1',
275
- AudioDurationSec: '5',
276
- AudioDuration15Sec: '1',
277
- TokensPrimary: null,
278
- TokensSecondary: null,
279
- CharacterCount: '0',
280
- },
281
- {
282
- AccountId: 'FA201FCA-7585-4F2B-BF51-AEF87F028FA2',
283
- FlowId: '8F999274-2E13-41AB-940C-2D6A4764569B',
284
- Provider: 'Google',
285
- Type: 'Voice Recognition',
286
- ModelName: null,
287
- Initiations: '1',
288
- AudioDurationSec: '5',
289
- AudioDuration15Sec: '1',
290
- TokensPrimary: null,
291
- TokensSecondary: null,
292
- CharacterCount: '0',
293
- }];
294
-
295
- const results = await builder.makeSku(data, CategoryNamespace.EXECUTABLE_GENERAL);
296
-
297
- assert.isArray(results);
298
- expect(results).toHaveLength(2);
299
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
300
- expect(results[0].SKU).toBe('EXE-VRN-NNC-SEC');
301
- expect(results[1].SKU).toBe('EXE-VRN-GGL-SEG');
302
- expect(results[0].Amount).toBe(data[0].AudioDurationSec);
303
- expect(results[1].Amount).toBe(data[1].AudioDuration15Sec);
304
- });
305
-
306
- it(`generate SKU for ${CategoryNamespace.EXECUTABLE_GENERAL}, handle Maps events`, async () => {
307
- const data = [{
308
- AccountId: '873C0F61-4DFC-4F8A-860E-F574616703C8',
309
- FlowId: '873C0F61-4DFC-4F8A-860E-F574616703C8',
310
- Provider: 'Google',
311
- Type: 'Maps',
312
- ModelName: null,
313
- Initiations: '1',
314
- AudioDurationSec: null,
315
- AudioDuration15Sec: null,
316
- TokensPrimary: '367',
317
- TokensSecondary: null,
318
- CharacterCount: '0',
319
- }];
320
-
321
- const results = await builder.makeSku(data, CategoryNamespace.EXECUTABLE_GENERAL);
322
-
323
- assert.isArray(results);
324
- expect(results).toHaveLength(1);
325
- Object.entries(data[0]).forEach(([k, v]) => expect((results[0] as Record<string, unknown>)[k]).toBe(v));
326
- expect(results[0].SKU).toBe('EXE-MAP-GGL-NUL-PTK');
327
- expect(results[0].Amount).toBe(data[0].TokensPrimary);
328
- });
329
-
330
- it(`generate SKU for ${CategoryNamespace.EXECUTABLE_GENERAL}, handle LLM events`, async () => {
331
- const data = [{
332
- AccountId: '1E6E408B-D9DC-4CE7-AD87-05CA44183F38',
333
- FlowId: 'B666B989-F449-4105-B3A5-1ED1BCB87465',
334
- Provider: 'OpenAI',
335
- Type: 'Text Generation',
336
- ModelName: 'gpt-4o-mini',
337
- Initiations: '23',
338
- AudioDurationSec: null,
339
- AudioDuration15Sec: null,
340
- TokensPrimary: '17053',
341
- TokensSecondary: '1613',
342
- CharacterCount: '0',
343
- }];
344
-
345
- const results = await builder.makeSku(data, CategoryNamespace.EXECUTABLE_GENERAL);
346
-
347
- assert.isArray(results);
348
- expect(results).toHaveLength(2);
349
- expect(results[0]).toMatchObject({
350
- AccountId: '1E6E408B-D9DC-4CE7-AD87-05CA44183F38',
351
- FlowId: 'B666B989-F449-4105-B3A5-1ED1BCB87465',
352
- Provider: 'OpenAI',
353
- Type: 'Text Generation',
354
- ModelName: 'gpt-4o-mini',
355
- Initiations: '23',
356
- AudioDurationSec: null,
357
- AudioDuration15Sec: null,
358
- TokensPrimary: '17053',
359
- CharacterCount: '0',
360
- SKU: 'EXE-TXG-OAI-MIN-PTK',
361
- Amount: '17053',
362
- });
363
- expect(results[1]).toMatchObject({
364
- AccountId: '1E6E408B-D9DC-4CE7-AD87-05CA44183F38',
365
- FlowId: 'B666B989-F449-4105-B3A5-1ED1BCB87465',
366
- Provider: 'OpenAI',
367
- Type: 'Text Generation',
368
- ModelName: 'gpt-4o-mini',
369
- Initiations: '23',
370
- AudioDurationSec: null,
371
- AudioDuration15Sec: null,
372
- TokensSecondary: '1613',
373
- CharacterCount: '0',
374
- SKU: 'EXE-TXG-OAI-MIN-STK',
375
- Amount: '1613',
376
- });
377
- });
378
-
379
- it(`generate SKU for ${CategoryNamespace.EXECUTABLE_LLM}, Druid LLM events`, async () => {
380
- const data = [{
381
- __time: 1740870000000,
382
- ModelName: 'gpt-3.5-turbo',
383
- ApiKey: 'sk-p...aSkE',
384
- AccountId: '9c8e8e61-af8b-4b65-b8a9-c3044286af0a',
385
- FlowId: '3c74c226-c6e9-4c16-885d-b050ba056162',
386
- Provider: 'OpenAI',
387
- Type: 'Text Generation',
388
- ResponseCode: 'Success',
389
- Client: 'demo',
390
- Env: 'prod',
391
- count: 1,
392
- TokensPrimary: 117,
393
- TokensSecondary: 32,
394
- }];
395
-
396
- const results = await builder.makeSku(data, CategoryNamespace.EXECUTABLE_LLM);
397
-
398
- assert.isArray(results);
399
- expect(results).toHaveLength(2);
400
- expect(results[0]).toMatchObject({
401
- __time: 1740870000000,
402
- ModelName: 'gpt-3.5-turbo',
403
- ApiKey: 'sk-p...aSkE',
404
- AccountId: '9c8e8e61-af8b-4b65-b8a9-c3044286af0a',
405
- FlowId: '3c74c226-c6e9-4c16-885d-b050ba056162',
406
- Provider: 'OpenAI',
407
- Type: 'Text Generation',
408
- ResponseCode: 'Success',
409
- Client: 'demo',
410
- Env: 'prod',
411
- count: 1,
412
- TokensPrimary: 117,
413
- SKU: 'EXE-TXG-OAI-35T-PTK',
414
- Amount: 117,
415
- });
416
- expect(results[1]).toMatchObject({
417
- __time: 1740870000000,
418
- ModelName: 'gpt-3.5-turbo',
419
- ApiKey: 'sk-p...aSkE',
420
- AccountId: '9c8e8e61-af8b-4b65-b8a9-c3044286af0a',
421
- FlowId: '3c74c226-c6e9-4c16-885d-b050ba056162',
422
- Provider: 'OpenAI',
423
- Type: 'Text Generation',
424
- ResponseCode: 'Success',
425
- Client: 'demo',
426
- Env: 'prod',
427
- count: 1,
428
- TokensSecondary: 32,
429
- SKU: 'EXE-TXG-OAI-35T-STK',
430
- Amount: 32,
431
- });
432
- });
433
- });