@albatrossai/albatross-sdk 0.5.4 → 0.11.27

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
@@ -1,7 +1,9 @@
1
1
  # @albatrossai/albatross-sdk
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@albatrossai/albatross-sdk.svg)](https://www.npmjs.com/package/@albatrossai/albatross-sdk)
4
- [![Documentation](https://img.shields.io/badge/docs-typedoc-blue)](https://albatross-core.github.io/fake-ecommerce/)
4
+ [![Documentation](https://img.shields.io/badge/docs-typedoc-blue)](https://albatross-core.github.io/app/)
5
+
6
+ **[NPM Package](https://www.npmjs.com/package/@albatrossai/albatross-sdk)** | **[Documentation](https://albatross-core.github.io/app/)**
5
7
 
6
8
  Official TypeScript/JavaScript SDK for Albatross AI - intelligent content selection, recommendations, and personalization.
7
9
 
@@ -36,7 +38,7 @@ await client.putEvent({
36
38
 
37
39
  ## Documentation
38
40
 
39
- **📖 [Complete API Documentation](https://albatross-core.github.io/fake-ecommerce/)**
41
+ **📖 [Complete API Documentation](https://albatross-core.github.io/app/)**
40
42
 
41
43
  The full API reference with detailed examples, type definitions, and method documentation is available in the auto-generated TypeDoc documentation.
42
44
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var sync = require('csv-stringify/sync');
3
4
  var zod = require('zod');
4
5
 
5
6
  // src/request.ts
@@ -90,610 +91,6 @@ var makeRequest = async ({
90
91
  }
91
92
  throw lastError || new Error("Unexpected error in makeRequest");
92
93
  };
93
-
94
- // ../../node_modules/csv-stringify/lib/utils/get.js
95
- var charCodeOfDot = ".".charCodeAt(0);
96
- var reEscapeChar = /\\(\\)?/g;
97
- var rePropName = RegExp(
98
- // Match anything that isn't a dot or bracket.
99
- `[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,
100
- "g"
101
- );
102
- var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
103
- var reIsPlainProp = /^\w*$/;
104
- var getTag = function(value) {
105
- return Object.prototype.toString.call(value);
106
- };
107
- var isSymbol = function(value) {
108
- const type = typeof value;
109
- return type === "symbol" || type === "object" && value && getTag(value) === "[object Symbol]";
110
- };
111
- var isKey = function(value, object) {
112
- if (Array.isArray(value)) {
113
- return false;
114
- }
115
- const type = typeof value;
116
- if (type === "number" || type === "symbol" || type === "boolean" || !value || isSymbol(value)) {
117
- return true;
118
- }
119
- return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
120
- };
121
- var stringToPath = function(string) {
122
- const result = [];
123
- if (string.charCodeAt(0) === charCodeOfDot) {
124
- result.push("");
125
- }
126
- string.replace(rePropName, function(match, expression, quote, subString) {
127
- let key = match;
128
- if (quote) {
129
- key = subString.replace(reEscapeChar, "$1");
130
- } else if (expression) {
131
- key = expression.trim();
132
- }
133
- result.push(key);
134
- });
135
- return result;
136
- };
137
- var castPath = function(value, object) {
138
- if (Array.isArray(value)) {
139
- return value;
140
- } else {
141
- return isKey(value, object) ? [value] : stringToPath(value);
142
- }
143
- };
144
- var toKey = function(value) {
145
- if (typeof value === "string" || isSymbol(value)) return value;
146
- const result = `${value}`;
147
- return result == "0" && 1 / value == -INFINITY ? "-0" : result;
148
- };
149
- var get = function(object, path) {
150
- path = castPath(path, object);
151
- let index = 0;
152
- const length = path.length;
153
- while (object != null && index < length) {
154
- object = object[toKey(path[index++])];
155
- }
156
- return index && index === length ? object : void 0;
157
- };
158
-
159
- // ../../node_modules/csv-stringify/lib/utils/is_object.js
160
- var is_object = function(obj) {
161
- return typeof obj === "object" && obj !== null && !Array.isArray(obj);
162
- };
163
-
164
- // ../../node_modules/csv-stringify/lib/api/normalize_columns.js
165
- var normalize_columns = function(columns) {
166
- if (columns === void 0 || columns === null) {
167
- return [void 0, void 0];
168
- }
169
- if (typeof columns !== "object") {
170
- return [Error('Invalid option "columns": expect an array or an object')];
171
- }
172
- if (!Array.isArray(columns)) {
173
- const newcolumns = [];
174
- for (const k in columns) {
175
- newcolumns.push({
176
- key: k,
177
- header: columns[k]
178
- });
179
- }
180
- columns = newcolumns;
181
- } else {
182
- const newcolumns = [];
183
- for (const column of columns) {
184
- if (typeof column === "string") {
185
- newcolumns.push({
186
- key: column,
187
- header: column
188
- });
189
- } else if (typeof column === "object" && column !== null && !Array.isArray(column)) {
190
- if (!column.key) {
191
- return [
192
- Error('Invalid column definition: property "key" is required')
193
- ];
194
- }
195
- if (column.header === void 0) {
196
- column.header = column.key;
197
- }
198
- newcolumns.push(column);
199
- } else {
200
- return [
201
- Error("Invalid column definition: expect a string or an object")
202
- ];
203
- }
204
- }
205
- columns = newcolumns;
206
- }
207
- return [void 0, columns];
208
- };
209
-
210
- // ../../node_modules/csv-stringify/lib/api/CsvError.js
211
- var CsvError = class _CsvError extends Error {
212
- constructor(code, message, ...contexts) {
213
- if (Array.isArray(message)) message = message.join(" ");
214
- super(message);
215
- if (Error.captureStackTrace !== void 0) {
216
- Error.captureStackTrace(this, _CsvError);
217
- }
218
- this.code = code;
219
- for (const context of contexts) {
220
- for (const key in context) {
221
- const value = context[key];
222
- this[key] = Buffer.isBuffer(value) ? value.toString() : value == null ? value : JSON.parse(JSON.stringify(value));
223
- }
224
- }
225
- }
226
- };
227
-
228
- // ../../node_modules/csv-stringify/lib/utils/underscore.js
229
- var underscore = function(str) {
230
- return str.replace(/([A-Z])/g, function(_, match) {
231
- return "_" + match.toLowerCase();
232
- });
233
- };
234
-
235
- // ../../node_modules/csv-stringify/lib/api/normalize_options.js
236
- var normalize_options = function(opts) {
237
- const options = {};
238
- for (const opt in opts) {
239
- options[underscore(opt)] = opts[opt];
240
- }
241
- if (options.bom === void 0 || options.bom === null || options.bom === false) {
242
- options.bom = false;
243
- } else if (options.bom !== true) {
244
- return [
245
- new CsvError("CSV_OPTION_BOOLEAN_INVALID_TYPE", [
246
- "option `bom` is optional and must be a boolean value,",
247
- `got ${JSON.stringify(options.bom)}`
248
- ])
249
- ];
250
- }
251
- if (options.delimiter === void 0 || options.delimiter === null) {
252
- options.delimiter = ",";
253
- } else if (Buffer.isBuffer(options.delimiter)) {
254
- options.delimiter = options.delimiter.toString();
255
- } else if (typeof options.delimiter !== "string") {
256
- return [
257
- new CsvError("CSV_OPTION_DELIMITER_INVALID_TYPE", [
258
- "option `delimiter` must be a buffer or a string,",
259
- `got ${JSON.stringify(options.delimiter)}`
260
- ])
261
- ];
262
- }
263
- if (options.quote === void 0 || options.quote === null) {
264
- options.quote = '"';
265
- } else if (options.quote === true) {
266
- options.quote = '"';
267
- } else if (options.quote === false) {
268
- options.quote = "";
269
- } else if (Buffer.isBuffer(options.quote)) {
270
- options.quote = options.quote.toString();
271
- } else if (typeof options.quote !== "string") {
272
- return [
273
- new CsvError("CSV_OPTION_QUOTE_INVALID_TYPE", [
274
- "option `quote` must be a boolean, a buffer or a string,",
275
- `got ${JSON.stringify(options.quote)}`
276
- ])
277
- ];
278
- }
279
- if (options.quoted === void 0 || options.quoted === null) {
280
- options.quoted = false;
281
- }
282
- if (options.escape_formulas === void 0 || options.escape_formulas === null) {
283
- options.escape_formulas = false;
284
- } else if (typeof options.escape_formulas !== "boolean") {
285
- return [
286
- new CsvError("CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE", [
287
- "option `escape_formulas` must be a boolean,",
288
- `got ${JSON.stringify(options.escape_formulas)}`
289
- ])
290
- ];
291
- }
292
- if (options.quoted_empty === void 0 || options.quoted_empty === null) {
293
- options.quoted_empty = void 0;
294
- }
295
- if (options.quoted_match === void 0 || options.quoted_match === null || options.quoted_match === false) {
296
- options.quoted_match = null;
297
- } else if (!Array.isArray(options.quoted_match)) {
298
- options.quoted_match = [options.quoted_match];
299
- }
300
- if (options.quoted_match) {
301
- for (const quoted_match of options.quoted_match) {
302
- const isString = typeof quoted_match === "string";
303
- const isRegExp = quoted_match instanceof RegExp;
304
- if (!isString && !isRegExp) {
305
- return [
306
- Error(
307
- `Invalid Option: quoted_match must be a string or a regex, got ${JSON.stringify(quoted_match)}`
308
- )
309
- ];
310
- }
311
- }
312
- }
313
- if (options.quoted_string === void 0 || options.quoted_string === null) {
314
- options.quoted_string = false;
315
- }
316
- if (options.eof === void 0 || options.eof === null) {
317
- options.eof = true;
318
- }
319
- if (options.escape === void 0 || options.escape === null) {
320
- options.escape = '"';
321
- } else if (Buffer.isBuffer(options.escape)) {
322
- options.escape = options.escape.toString();
323
- } else if (typeof options.escape !== "string") {
324
- return [
325
- Error(
326
- `Invalid Option: escape must be a buffer or a string, got ${JSON.stringify(options.escape)}`
327
- )
328
- ];
329
- }
330
- if (options.escape.length > 1) {
331
- return [
332
- Error(
333
- `Invalid Option: escape must be one character, got ${options.escape.length} characters`
334
- )
335
- ];
336
- }
337
- if (options.header === void 0 || options.header === null) {
338
- options.header = false;
339
- }
340
- const [errColumns, columns] = normalize_columns(options.columns);
341
- if (errColumns !== void 0) return [errColumns];
342
- options.columns = columns;
343
- if (options.quoted === void 0 || options.quoted === null) {
344
- options.quoted = false;
345
- }
346
- if (options.cast === void 0 || options.cast === null) {
347
- options.cast = {};
348
- }
349
- if (options.cast.bigint === void 0 || options.cast.bigint === null) {
350
- options.cast.bigint = (value) => "" + value;
351
- }
352
- if (options.cast.boolean === void 0 || options.cast.boolean === null) {
353
- options.cast.boolean = (value) => value ? "1" : "";
354
- }
355
- if (options.cast.date === void 0 || options.cast.date === null) {
356
- options.cast.date = (value) => "" + value.getTime();
357
- }
358
- if (options.cast.number === void 0 || options.cast.number === null) {
359
- options.cast.number = (value) => "" + value;
360
- }
361
- if (options.cast.object === void 0 || options.cast.object === null) {
362
- options.cast.object = (value) => JSON.stringify(value);
363
- }
364
- if (options.cast.string === void 0 || options.cast.string === null) {
365
- options.cast.string = function(value) {
366
- return value;
367
- };
368
- }
369
- if (options.on_record !== void 0 && typeof options.on_record !== "function") {
370
- return [Error(`Invalid Option: "on_record" must be a function.`)];
371
- }
372
- if (options.record_delimiter === void 0 || options.record_delimiter === null) {
373
- options.record_delimiter = "\n";
374
- } else if (Buffer.isBuffer(options.record_delimiter)) {
375
- options.record_delimiter = options.record_delimiter.toString();
376
- } else if (typeof options.record_delimiter !== "string") {
377
- return [
378
- Error(
379
- `Invalid Option: record_delimiter must be a buffer or a string, got ${JSON.stringify(options.record_delimiter)}`
380
- )
381
- ];
382
- }
383
- switch (options.record_delimiter) {
384
- case "unix":
385
- options.record_delimiter = "\n";
386
- break;
387
- case "mac":
388
- options.record_delimiter = "\r";
389
- break;
390
- case "windows":
391
- options.record_delimiter = "\r\n";
392
- break;
393
- case "ascii":
394
- options.record_delimiter = "";
395
- break;
396
- case "unicode":
397
- options.record_delimiter = "\u2028";
398
- break;
399
- }
400
- return [void 0, options];
401
- };
402
-
403
- // ../../node_modules/csv-stringify/lib/api/index.js
404
- var bom_utf8 = Buffer.from([239, 187, 191]);
405
- var stringifier = function(options, state, info) {
406
- return {
407
- options,
408
- state,
409
- info,
410
- __transform: function(chunk, push) {
411
- if (!Array.isArray(chunk) && typeof chunk !== "object") {
412
- return Error(
413
- `Invalid Record: expect an array or an object, got ${JSON.stringify(chunk)}`
414
- );
415
- }
416
- if (this.info.records === 0) {
417
- if (Array.isArray(chunk)) {
418
- if (this.options.header === true && this.options.columns === void 0) {
419
- return Error(
420
- "Undiscoverable Columns: header option requires column option or object records"
421
- );
422
- }
423
- } else if (this.options.columns === void 0) {
424
- const [err2, columns] = normalize_columns(Object.keys(chunk));
425
- if (err2) return;
426
- this.options.columns = columns;
427
- }
428
- }
429
- if (this.info.records === 0) {
430
- this.bom(push);
431
- const err2 = this.headers(push);
432
- if (err2) return err2;
433
- }
434
- try {
435
- if (this.options.on_record) {
436
- this.options.on_record(chunk, this.info.records);
437
- }
438
- } catch (err2) {
439
- return err2;
440
- }
441
- let err, chunk_string;
442
- if (this.options.eof) {
443
- [err, chunk_string] = this.stringify(chunk);
444
- if (err) return err;
445
- if (chunk_string === void 0) {
446
- return;
447
- } else {
448
- chunk_string = chunk_string + this.options.record_delimiter;
449
- }
450
- } else {
451
- [err, chunk_string] = this.stringify(chunk);
452
- if (err) return err;
453
- if (chunk_string === void 0) {
454
- return;
455
- } else {
456
- if (this.options.header || this.info.records) {
457
- chunk_string = this.options.record_delimiter + chunk_string;
458
- }
459
- }
460
- }
461
- this.info.records++;
462
- push(chunk_string);
463
- },
464
- stringify: function(chunk, chunkIsHeader = false) {
465
- if (typeof chunk !== "object") {
466
- return [void 0, chunk];
467
- }
468
- const { columns } = this.options;
469
- const record = [];
470
- if (Array.isArray(chunk)) {
471
- if (columns) {
472
- chunk.splice(columns.length);
473
- }
474
- for (let i = 0; i < chunk.length; i++) {
475
- const field = chunk[i];
476
- const [err, value] = this.__cast(field, {
477
- index: i,
478
- column: i,
479
- records: this.info.records,
480
- header: chunkIsHeader
481
- });
482
- if (err) return [err];
483
- record[i] = [value, field];
484
- }
485
- } else {
486
- for (let i = 0; i < columns.length; i++) {
487
- const field = get(chunk, columns[i].key);
488
- const [err, value] = this.__cast(field, {
489
- index: i,
490
- column: columns[i].key,
491
- records: this.info.records,
492
- header: chunkIsHeader
493
- });
494
- if (err) return [err];
495
- record[i] = [value, field];
496
- }
497
- }
498
- let csvrecord = "";
499
- for (let i = 0; i < record.length; i++) {
500
- let options2, err;
501
- let [value, field] = record[i];
502
- if (typeof value === "string") {
503
- options2 = this.options;
504
- } else if (is_object(value)) {
505
- options2 = value;
506
- value = options2.value;
507
- delete options2.value;
508
- if (typeof value !== "string" && value !== void 0 && value !== null) {
509
- if (err)
510
- return [
511
- Error(
512
- `Invalid Casting Value: returned value must return a string, null or undefined, got ${JSON.stringify(value)}`
513
- )
514
- ];
515
- }
516
- options2 = { ...this.options, ...options2 };
517
- [err, options2] = normalize_options(options2);
518
- if (err !== void 0) {
519
- return [err];
520
- }
521
- } else if (value === void 0 || value === null) {
522
- options2 = this.options;
523
- } else {
524
- return [
525
- Error(
526
- `Invalid Casting Value: returned value must return a string, an object, null or undefined, got ${JSON.stringify(value)}`
527
- )
528
- ];
529
- }
530
- const {
531
- delimiter,
532
- escape,
533
- quote,
534
- quoted,
535
- quoted_empty,
536
- quoted_string,
537
- quoted_match,
538
- record_delimiter,
539
- escape_formulas
540
- } = options2;
541
- if ("" === value && "" === field) {
542
- let quotedMatch = quoted_match && quoted_match.filter((quoted_match2) => {
543
- if (typeof quoted_match2 === "string") {
544
- return value.indexOf(quoted_match2) !== -1;
545
- } else {
546
- return quoted_match2.test(value);
547
- }
548
- });
549
- quotedMatch = quotedMatch && quotedMatch.length > 0;
550
- const shouldQuote = quotedMatch || true === quoted_empty || true === quoted_string && false !== quoted_empty;
551
- if (shouldQuote === true) {
552
- value = quote + value + quote;
553
- }
554
- csvrecord += value;
555
- } else if (value) {
556
- if (typeof value !== "string") {
557
- return [
558
- Error(
559
- `Formatter must return a string, null or undefined, got ${JSON.stringify(value)}`
560
- )
561
- ];
562
- }
563
- const containsdelimiter = delimiter.length && value.indexOf(delimiter) >= 0;
564
- const containsQuote = quote !== "" && value.indexOf(quote) >= 0;
565
- const containsEscape = value.indexOf(escape) >= 0 && escape !== quote;
566
- const containsRecordDelimiter = value.indexOf(record_delimiter) >= 0;
567
- const quotedString = quoted_string && typeof field === "string";
568
- let quotedMatch = quoted_match && quoted_match.filter((quoted_match2) => {
569
- if (typeof quoted_match2 === "string") {
570
- return value.indexOf(quoted_match2) !== -1;
571
- } else {
572
- return quoted_match2.test(value);
573
- }
574
- });
575
- quotedMatch = quotedMatch && quotedMatch.length > 0;
576
- if (escape_formulas) {
577
- switch (value[0]) {
578
- case "=":
579
- case "+":
580
- case "-":
581
- case "@":
582
- case " ":
583
- case "\r":
584
- case "\uFF1D":
585
- // Unicode '='
586
- case "\uFF0B":
587
- // Unicode '+'
588
- case "\uFF0D":
589
- // Unicode '-'
590
- case "\uFF20":
591
- value = `'${value}`;
592
- break;
593
- }
594
- }
595
- const shouldQuote = containsQuote === true || containsdelimiter || containsRecordDelimiter || quoted || quotedString || quotedMatch;
596
- if (shouldQuote === true && containsEscape === true) {
597
- const regexp = escape === "\\" ? new RegExp(escape + escape, "g") : new RegExp(escape, "g");
598
- value = value.replace(regexp, escape + escape);
599
- }
600
- if (containsQuote === true) {
601
- const regexp = new RegExp(quote, "g");
602
- value = value.replace(regexp, escape + quote);
603
- }
604
- if (shouldQuote === true) {
605
- value = quote + value + quote;
606
- }
607
- csvrecord += value;
608
- } else if (quoted_empty === true || field === "" && quoted_string === true && quoted_empty !== false) {
609
- csvrecord += quote + quote;
610
- }
611
- if (i !== record.length - 1) {
612
- csvrecord += delimiter;
613
- }
614
- }
615
- return [void 0, csvrecord];
616
- },
617
- bom: function(push) {
618
- if (this.options.bom !== true) {
619
- return;
620
- }
621
- push(bom_utf8);
622
- },
623
- headers: function(push) {
624
- if (this.options.header === false) {
625
- return;
626
- }
627
- if (this.options.columns === void 0) {
628
- return;
629
- }
630
- let err;
631
- let headers = this.options.columns.map((column) => column.header);
632
- if (this.options.eof) {
633
- [err, headers] = this.stringify(headers, true);
634
- headers += this.options.record_delimiter;
635
- } else {
636
- [err, headers] = this.stringify(headers);
637
- }
638
- if (err) return err;
639
- push(headers);
640
- },
641
- __cast: function(value, context) {
642
- const type = typeof value;
643
- try {
644
- if (type === "string") {
645
- return [void 0, this.options.cast.string(value, context)];
646
- } else if (type === "bigint") {
647
- return [void 0, this.options.cast.bigint(value, context)];
648
- } else if (type === "number") {
649
- return [void 0, this.options.cast.number(value, context)];
650
- } else if (type === "boolean") {
651
- return [void 0, this.options.cast.boolean(value, context)];
652
- } else if (value instanceof Date) {
653
- return [void 0, this.options.cast.date(value, context)];
654
- } else if (type === "object" && value !== null) {
655
- return [void 0, this.options.cast.object(value, context)];
656
- } else {
657
- return [void 0, value, value];
658
- }
659
- } catch (err) {
660
- return [err];
661
- }
662
- }
663
- };
664
- };
665
-
666
- // ../../node_modules/csv-stringify/lib/sync.js
667
- var stringify = function(records, opts = {}) {
668
- const data = [];
669
- const [err, options] = normalize_options(opts);
670
- if (err !== void 0) throw err;
671
- const state = {
672
- stop: false
673
- };
674
- const info = {
675
- records: 0
676
- };
677
- const api = stringifier(options, state, info);
678
- for (const record of records) {
679
- const err2 = api.__transform(record, function(record2) {
680
- data.push(record2);
681
- });
682
- if (err2 !== void 0) throw err2;
683
- }
684
- if (data.length === 0) {
685
- api.bom((d) => {
686
- data.push(d);
687
- });
688
- const err2 = api.headers((headers) => {
689
- data.push(headers);
690
- });
691
- if (err2 !== void 0) throw err2;
692
- }
693
- return data.join("");
694
- };
695
-
696
- // src/utils.ts
697
94
  function flattenNested(obj) {
698
95
  const result = {};
699
96
  Object.entries(obj).forEach(([key, value]) => {
@@ -743,7 +140,7 @@ var bodyToCSV = (data) => {
743
140
  rowHeaders,
744
141
  ...data.map((row) => preFormatRow(rowHeaders, row))
745
142
  ];
746
- return stringify(csvData, {
143
+ return sync.stringify(csvData, {
747
144
  delimiter: ",",
748
145
  quote: true,
749
146
  quoted_string: true,
@@ -959,6 +356,9 @@ var Client = class {
959
356
  this.makeRequest = options.makeRequest || makeRequest;
960
357
  this.predictionPreProcessing = options.predictionPreProcessing || ((data) => data);
961
358
  }
359
+ token;
360
+ tenantId;
361
+ baseUrl;
962
362
  makeRequest;
963
363
  predictionPreProcessing;
964
364
  /**