fireberry-api-client 1.0.0-beta.1

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,1041 @@
1
+ 'use strict';
2
+
3
+ // src/utils/queryBuilder.ts
4
+ function escapeQueryValue(value) {
5
+ if (!value) {
6
+ return "";
7
+ }
8
+ let escaped = value.replace(/\\/g, "\\\\");
9
+ escaped = escaped.replace(/\(/g, "\\(");
10
+ escaped = escaped.replace(/\)/g, "\\)");
11
+ escaped = escaped.replace(/\bor\b/gi, "\\or");
12
+ escaped = escaped.replace(/\band\b/gi, "\\and");
13
+ return escaped;
14
+ }
15
+ function sanitizeQuery(query) {
16
+ if (!query) {
17
+ return "";
18
+ }
19
+ query = query.replace(
20
+ /\(\s*([a-zA-Z0-9_]+)\s+(is-null|is-not-null)\s*\)/g,
21
+ "($1 __SPECIAL_OPERATOR__$2)"
22
+ );
23
+ query = query.replace(
24
+ /\(\s*([a-zA-Z0-9_]+)\s+(start-with|not-start-with)\s+([^)]+)\s*\)/g,
25
+ "($1 __TEXT_OPERATOR__$2 $3)"
26
+ );
27
+ query = query.replace(
28
+ /\(\s*([a-zA-Z0-9_]+(?:field|Field|system|System)[0-9]*)\s+(?!__SPECIAL_OPERATOR__|__TEXT_OPERATOR__)([^()<>=!]+)\s*\)/g,
29
+ "($1 = $2)"
30
+ );
31
+ query = query.replace(
32
+ /\(\s*([a-zA-Z0-9_]+)\s+(?!__SPECIAL_OPERATOR__|__TEXT_OPERATOR__|<=|>=|!=|<|>|=\s)([^()<>]+)\s*\)/g,
33
+ "($1 = $2)"
34
+ );
35
+ query = query.replace(/__SPECIAL_OPERATOR__/g, "");
36
+ query = query.replace(/__TEXT_OPERATOR__/g, "");
37
+ query = query.replace(/\(\s*(?:<=|>=|!=|<|>|=)\s*\)/g, "");
38
+ query = query.replace(/\(\s*(?:start-with|not-start-with)\s*\)/gi, "");
39
+ query = query.replace(/\(\s*(?:and|or)\s*\)/gi, "");
40
+ query = query.replace(/\(\s*\)/g, "");
41
+ query = query.replace(/^\s*(and|or)\s*/gi, "");
42
+ query = query.replace(/\s*(and|or)\s*$/gi, "");
43
+ const nestedPattern = /\(\s*\(([^()]+)\)\s*\)/g;
44
+ while (nestedPattern.test(query)) {
45
+ query = query.replace(nestedPattern, "($1)");
46
+ }
47
+ query = query.replace(/\s+/g, " ");
48
+ return query.trim();
49
+ }
50
+ var QueryBuilder = class {
51
+ conditions = [];
52
+ joinOperators = [];
53
+ currentField = null;
54
+ selectedFields = [];
55
+ objectTypeId = null;
56
+ sortByField = null;
57
+ sortDirection = "desc";
58
+ limitValue = null;
59
+ pageNumber = 1;
60
+ showRealValueFlag = true;
61
+ client = null;
62
+ /**
63
+ * Creates a new QueryBuilder
64
+ * @param client - Optional FireberryClient for executing queries
65
+ */
66
+ constructor(client) {
67
+ this.client = client ?? null;
68
+ }
69
+ /**
70
+ * Sets the object type for the query
71
+ * @param objectType - Object type ID (e.g., '1' for Account)
72
+ */
73
+ objectType(objectType) {
74
+ this.objectTypeId = String(objectType);
75
+ return this;
76
+ }
77
+ /**
78
+ * Adds fields to select
79
+ * @param fields - Field names to select
80
+ */
81
+ select(...fields) {
82
+ this.selectedFields.push(...fields);
83
+ return this;
84
+ }
85
+ /**
86
+ * Starts a new WHERE condition
87
+ * @param field - Field name to filter on
88
+ */
89
+ where(field) {
90
+ this.currentField = field;
91
+ return this.createConditionBuilder();
92
+ }
93
+ /**
94
+ * Adds an AND logical operator
95
+ */
96
+ and() {
97
+ if (this.conditions.length > 0) {
98
+ this.joinOperators.push("and");
99
+ }
100
+ return this;
101
+ }
102
+ /**
103
+ * Adds an OR logical operator
104
+ */
105
+ or() {
106
+ if (this.conditions.length > 0) {
107
+ this.joinOperators.push("or");
108
+ }
109
+ return this;
110
+ }
111
+ /**
112
+ * Sets the sort field and direction
113
+ * @param field - Field to sort by
114
+ * @param direction - Sort direction ('asc' or 'desc')
115
+ */
116
+ sortBy(field, direction = "desc") {
117
+ this.sortByField = field;
118
+ this.sortDirection = direction;
119
+ return this;
120
+ }
121
+ /**
122
+ * Sets the maximum number of records to return
123
+ * @param count - Maximum record count
124
+ */
125
+ limit(count) {
126
+ this.limitValue = count;
127
+ return this;
128
+ }
129
+ /**
130
+ * Sets the page number for pagination
131
+ * @param page - Page number (1-based)
132
+ */
133
+ page(page) {
134
+ this.pageNumber = page;
135
+ return this;
136
+ }
137
+ /**
138
+ * Controls whether to show real values (labels) for dropdown fields
139
+ * @param show - Whether to show real values (default: true)
140
+ */
141
+ showRealValue(show) {
142
+ this.showRealValueFlag = show;
143
+ return this;
144
+ }
145
+ /**
146
+ * Builds the query string from conditions
147
+ * @returns The built query string
148
+ */
149
+ build() {
150
+ if (this.conditions.length === 0) {
151
+ return "";
152
+ }
153
+ const parts = [];
154
+ for (let i = 0; i < this.conditions.length; i++) {
155
+ const condition = this.conditions[i];
156
+ let conditionStr;
157
+ if (condition.operator === "is-null" || condition.operator === "is-not-null") {
158
+ conditionStr = `(${condition.field} ${condition.operator})`;
159
+ } else {
160
+ const escapedValue = escapeQueryValue(condition.value || "");
161
+ conditionStr = `(${condition.field} ${condition.operator} ${escapedValue})`;
162
+ }
163
+ parts.push(conditionStr);
164
+ if (i < this.joinOperators.length) {
165
+ parts.push(this.joinOperators[i]);
166
+ }
167
+ }
168
+ return parts.join(" ");
169
+ }
170
+ /**
171
+ * Returns the selected fields array
172
+ * Useful for inspecting the query configuration
173
+ */
174
+ getFields() {
175
+ return [...this.selectedFields];
176
+ }
177
+ /**
178
+ * Converts the query builder state to a payload compatible with @fireberry/sdk
179
+ *
180
+ * @returns Object with `fields` (comma-separated string) and `query` (filter string)
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * import FireberryClientSDK from '@fireberry/sdk/client';
185
+ * import { QueryBuilder } from 'fireberry-api-client';
186
+ *
187
+ * const sdk = new FireberryClientSDK();
188
+ * await sdk.initializeContext();
189
+ *
190
+ * const payload = new QueryBuilder()
191
+ * .select('accountid', 'accountname')
192
+ * .where('statuscode').equals('1')
193
+ * .toSDKPayload();
194
+ *
195
+ * // Use with SDK
196
+ * const results = await sdk.api.query(1, payload);
197
+ * ```
198
+ */
199
+ toSDKPayload() {
200
+ const payload = {
201
+ fields: this.selectedFields.length > 0 ? this.selectedFields.join(",") : "*",
202
+ query: this.build()
203
+ };
204
+ if (this.limitValue !== null) {
205
+ payload.page_size = this.limitValue;
206
+ }
207
+ if (this.pageNumber > 1) {
208
+ payload.page_number = this.pageNumber;
209
+ }
210
+ return payload;
211
+ }
212
+ /**
213
+ * Executes the query (requires client to be set)
214
+ * @param signal - Optional AbortSignal for cancellation
215
+ * @returns Query results
216
+ */
217
+ async execute(signal) {
218
+ if (!this.client) {
219
+ throw new Error("QueryBuilder requires a client to execute queries. Pass a FireberryClient to the constructor.");
220
+ }
221
+ if (!this.objectTypeId) {
222
+ throw new Error("Object type is required. Use .objectType() before executing.");
223
+ }
224
+ const queryOptions = {
225
+ objectType: this.objectTypeId,
226
+ fields: this.selectedFields.length > 0 ? this.selectedFields : ["*"],
227
+ query: this.build(),
228
+ showRealValue: this.showRealValueFlag
229
+ };
230
+ if (this.sortByField) {
231
+ queryOptions.sortBy = this.sortByField;
232
+ queryOptions.sortType = this.sortDirection;
233
+ }
234
+ if (this.limitValue !== null) {
235
+ queryOptions.limit = this.limitValue;
236
+ }
237
+ if (this.pageNumber > 1) {
238
+ queryOptions.page = this.pageNumber;
239
+ }
240
+ if (signal) {
241
+ queryOptions.signal = signal;
242
+ }
243
+ return this.client.query(queryOptions);
244
+ }
245
+ /**
246
+ * Creates a condition builder for the current field
247
+ */
248
+ createConditionBuilder() {
249
+ const field = this.currentField;
250
+ return {
251
+ equals: (value) => {
252
+ this.addCondition(field, "=", String(value));
253
+ return this;
254
+ },
255
+ notEquals: (value) => {
256
+ this.addCondition(field, "!=", String(value));
257
+ return this;
258
+ },
259
+ lessThan: (value) => {
260
+ this.addCondition(field, "<", String(value));
261
+ return this;
262
+ },
263
+ greaterThan: (value) => {
264
+ this.addCondition(field, ">", String(value));
265
+ return this;
266
+ },
267
+ lessThanOrEqual: (value) => {
268
+ this.addCondition(field, "<=", String(value));
269
+ return this;
270
+ },
271
+ greaterThanOrEqual: (value) => {
272
+ this.addCondition(field, ">=", String(value));
273
+ return this;
274
+ },
275
+ contains: (value) => {
276
+ this.addCondition(field, "start-with", `%${value}`);
277
+ return this;
278
+ },
279
+ notContains: (value) => {
280
+ this.addCondition(field, "not-start-with", `%${value}`);
281
+ return this;
282
+ },
283
+ startsWith: (value) => {
284
+ this.addCondition(field, "start-with", value);
285
+ return this;
286
+ },
287
+ notStartsWith: (value) => {
288
+ this.addCondition(field, "not-start-with", value);
289
+ return this;
290
+ },
291
+ isNull: () => {
292
+ this.addCondition(field, "is-null");
293
+ return this;
294
+ },
295
+ isNotNull: () => {
296
+ this.addCondition(field, "is-not-null");
297
+ return this;
298
+ }
299
+ };
300
+ }
301
+ /**
302
+ * Adds a condition to the query
303
+ */
304
+ addCondition(field, operator, value) {
305
+ this.conditions.push({ field, operator, value });
306
+ this.currentField = null;
307
+ }
308
+ };
309
+
310
+ // src/utils/fieldMapping.ts
311
+ var SPECIAL_LABEL_FIELD_MAPPINGS = {
312
+ objectid: "objecttitle",
313
+ lastactionid: "lastactiontitle",
314
+ wfruleid: "rulename",
315
+ // Object 55 (Workflow Rules)
316
+ noteid: "subject"
317
+ // Object 7 (Note) - noteid maps to subject
318
+ };
319
+ var EXCLUDED_ID_FIELDS = [
320
+ "businessunitid",
321
+ // → businessunitidname (not businessunitname)
322
+ "crmuserid",
323
+ // → no name field exists
324
+ "languageid"
325
+ // → languageidname (not languagename)
326
+ ];
327
+ var EXCLUDED_CODE_FIELDS = [
328
+ "duplicaterecordcode"
329
+ // → duplicaterecordcodename (not duplicaterecord)
330
+ ];
331
+ var FIELDS_WITHOUT_LABEL_FIELD = [
332
+ "systemfieldid",
333
+ // Object 73 - no name field exists
334
+ "fieldobjecttype",
335
+ // Object 73 - base field doesn't exist, only *name exists
336
+ "invoiceid",
337
+ // Objects 78, 81 - no name field exists
338
+ "calllogid",
339
+ // Object 100 - no name field exists (primary key)
340
+ "attendanceclockid",
341
+ // Object 101 - no name field exists (primary key)
342
+ "activitylogid",
343
+ // Object 102 - no name field exists (primary key)
344
+ "conversationid",
345
+ // Object 104 - no name field exists (primary key)
346
+ "texttemplateid",
347
+ // Text Template - no name field exists (primary key)
348
+ "smstemplateid",
349
+ // Object 110 - no name field exists (primary key)
350
+ "deletedby",
351
+ // Object 7 - no name field exists
352
+ "recordid",
353
+ // Object 7 - no name field exists
354
+ "objecttypecode"
355
+ // Object 7 - no name field exists
356
+ ];
357
+ var OBJECT_TYPE_OVERRIDES = {
358
+ // CRM Orders (13) - uses *idname and *codename patterns
359
+ 13: {
360
+ excludedIdFields: ["ownerid", "accountid", "printtemplateid", "pcfaccountid"],
361
+ excludedCodeFields: [
362
+ "rounddiscountcode",
363
+ "taxincludecode",
364
+ "currencycode",
365
+ "transmissioncode",
366
+ "creditrejectioncode1",
367
+ "creditrejectioncode2",
368
+ "apartmentcode1",
369
+ "apartmentcode2",
370
+ "restrictioncode1",
371
+ "restrictioncode2",
372
+ "casescode1",
373
+ "casescode2",
374
+ "returncode1",
375
+ "returncode2",
376
+ "statuscode"
377
+ ]
378
+ },
379
+ // Products (14)
380
+ 14: {
381
+ excludedCodeFields: ["categorycode"]
382
+ // → categoryname (not category)
383
+ },
384
+ // CRM Order Items (17) - uses *idname pattern
385
+ 17: {
386
+ excludedIdFields: ["crmorderid", "productid", "ownerid"]
387
+ },
388
+ // Email Templates (20)
389
+ 20: {
390
+ excludedIdFields: ["mdobjectid"]
391
+ },
392
+ // Print Templates (27)
393
+ 27: {
394
+ excludedIdFields: ["mdobjectid"]
395
+ },
396
+ // System Fields (73) - uses *idname pattern
397
+ 73: {
398
+ excludedIdFields: ["mdobjectid", "ownerid"]
399
+ },
400
+ // Invoices (78) - uses *codename and *idname patterns extensively
401
+ 78: {
402
+ excludedIdFields: [
403
+ "crmorderid",
404
+ "invoicereceiptid",
405
+ "accountid",
406
+ "ownerid",
407
+ "invoicerenoid"
408
+ ],
409
+ excludedCodeFields: [
410
+ "taxincludecode",
411
+ "depositcode",
412
+ "rounddiscountcode",
413
+ "currencycode",
414
+ "statecode",
415
+ "invoicetypecode"
416
+ ]
417
+ },
418
+ // Invoice No (81) - uses *codename and *idname patterns extensively
419
+ 81: {
420
+ excludedIdFields: [
421
+ "ownerid",
422
+ "invoicecreditid",
423
+ "crmorderid",
424
+ "invoicereceiptid",
425
+ "invoicedeliveryid",
426
+ "accountid"
427
+ ],
428
+ excludedCodeFields: ["currencycode", "rounddiscountcode", "statecode", "taxincludecode"]
429
+ },
430
+ // Invoice Draft (82) - uses *codename and *idname patterns extensively
431
+ 82: {
432
+ excludedIdFields: ["accountid", "crmorderid", "ownerid", "invoicerenoid"],
433
+ excludedCodeFields: ["taxincludecode", "statecode", "rounddiscountcode", "currencycode"]
434
+ },
435
+ // Invoice Receipt (83) - uses *codename and *idname patterns
436
+ 83: {
437
+ excludedIdFields: ["invoicenoid", "crmorderid", "ownerid", "accountid"],
438
+ excludedCodeFields: ["statecode", "currencycode"]
439
+ },
440
+ // Invoice Tax Receipt (84) - uses *codename and *idname patterns
441
+ 84: {
442
+ excludedIdFields: ["crmorderid", "ownerid", "invoicecreditid", "accountid"],
443
+ excludedCodeFields: ["rounddiscountcode", "statecode", "taxincludecode", "currencycode"]
444
+ },
445
+ // Invoice Credit (85) - uses *codename and *idname patterns
446
+ 85: {
447
+ excludedIdFields: ["ownerid", "crmorderid", "accountid"],
448
+ excludedCodeFields: ["taxincludecode", "rounddiscountcode", "currencycode", "statecode"]
449
+ },
450
+ // Invoice (86) - uses *codename and *idname patterns
451
+ 86: {
452
+ excludedIdFields: ["accountid", "ownerid", "crmorderid"],
453
+ excludedCodeFields: ["statecode", "rounddiscountcode", "currencycode", "taxincludecode"]
454
+ },
455
+ // Call Log (100) - uses *idname pattern
456
+ 100: {
457
+ excludedIdFields: ["contactid", "leadid", "accountid", "ownerid"]
458
+ },
459
+ // Attendance Clock (101) - uses *idname pattern
460
+ 101: {
461
+ excludedIdFields: ["ownerid"]
462
+ },
463
+ // Activity Log (102) - uses *idname and *codename patterns
464
+ 102: {
465
+ excludedIdFields: ["contactid", "ownerid"],
466
+ excludedCodeFields: ["objecttypecode", "typecode", "resultcode"]
467
+ },
468
+ // Conversation (104) - uses *idname pattern
469
+ 104: {
470
+ excludedIdFields: ["leadid", "ownerid", "contactid", "accountid"]
471
+ },
472
+ // Text Template (106) - uses *idname pattern
473
+ 106: {
474
+ excludedIdFields: ["ownerid"]
475
+ },
476
+ // SMS Template (110) - uses *idname pattern
477
+ 110: {
478
+ excludedIdFields: ["ownerid"]
479
+ }
480
+ };
481
+ function getLabelFieldForField(fieldName, objectType) {
482
+ if (SPECIAL_LABEL_FIELD_MAPPINGS[fieldName]) {
483
+ return SPECIAL_LABEL_FIELD_MAPPINGS[fieldName];
484
+ }
485
+ if (FIELDS_WITHOUT_LABEL_FIELD.includes(fieldName)) {
486
+ return "";
487
+ }
488
+ if (/^customobject\d+id$/.test(fieldName)) {
489
+ return "name";
490
+ }
491
+ if (fieldName.startsWith("pcf")) {
492
+ return `${fieldName}name`;
493
+ }
494
+ const objectTypeNum = typeof objectType === "string" ? parseInt(objectType, 10) : objectType;
495
+ const overrides = OBJECT_TYPE_OVERRIDES[objectTypeNum] || null;
496
+ const isCustomObject = objectTypeNum >= 1e3;
497
+ const customObjectExclusions = isCustomObject ? ["ownerid"] : [];
498
+ const excludedCodeFields = [
499
+ ...EXCLUDED_CODE_FIELDS,
500
+ ...overrides?.excludedCodeFields || []
501
+ ];
502
+ const excludedIdFields = [
503
+ ...EXCLUDED_ID_FIELDS,
504
+ ...overrides?.excludedIdFields || [],
505
+ ...customObjectExclusions
506
+ ];
507
+ if (fieldName.endsWith("code") && !excludedCodeFields.includes(fieldName)) {
508
+ return fieldName.slice(0, -4);
509
+ }
510
+ if (fieldName.endsWith("id") && !excludedIdFields.includes(fieldName)) {
511
+ return fieldName.slice(0, -2) + "name";
512
+ }
513
+ return `${fieldName}name`;
514
+ }
515
+
516
+ // src/constants/objectIds.ts
517
+ var OBJECT_ID_MAP = {
518
+ 1: "accountid",
519
+ 2: "contactid",
520
+ 3: "leadid",
521
+ 4: "opportunityid",
522
+ 5: "casesid",
523
+ 6: "activityid",
524
+ 7: "noteid",
525
+ 8: "competitorid",
526
+ 9: "crmuserid",
527
+ 10: "taskid",
528
+ 13: "crmorderid",
529
+ 14: "productid",
530
+ 17: "crmorderitemid",
531
+ 20: "emailtemplateid",
532
+ 23: "businessunitid",
533
+ 27: "printtemplateid",
534
+ 28: "contractid",
535
+ 33: "accountproductid",
536
+ 46: "projectid",
537
+ 67: "campaignid",
538
+ 76: "articleid",
539
+ 86: "invoiceid",
540
+ 101: "attendanceclockid",
541
+ 102: "activitylogid",
542
+ 104: "conversationid",
543
+ 114: "calendarresourceid"
544
+ };
545
+ function getObjectIdFieldName(objectTypeId) {
546
+ const objectTypeNum = typeof objectTypeId === "string" ? parseInt(objectTypeId, 10) : objectTypeId;
547
+ if (OBJECT_ID_MAP[objectTypeNum]) {
548
+ return OBJECT_ID_MAP[objectTypeNum];
549
+ }
550
+ if (objectTypeNum >= 1e3) {
551
+ return `customobject${objectTypeNum}id`;
552
+ }
553
+ return "id";
554
+ }
555
+
556
+ // src/constants/objectNames.ts
557
+ var OBJECT_NAME_MAP = {
558
+ 1: "accountname",
559
+ // Account
560
+ 2: "fullname",
561
+ // Contact
562
+ 3: "fullname",
563
+ // Lead
564
+ 4: "name",
565
+ // Opportunity
566
+ 5: "title",
567
+ // Case
568
+ 6: "subject",
569
+ // Activity
570
+ 7: "subject",
571
+ // Note
572
+ 8: "name",
573
+ // Competitor
574
+ 9: "fullname",
575
+ // CRM User
576
+ 10: "subject",
577
+ // Task
578
+ 13: "name",
579
+ // CRM Order
580
+ 14: "productname",
581
+ // Product
582
+ 17: "productname",
583
+ // CRM Order Item
584
+ 20: "name",
585
+ // Email Template
586
+ 23: "name",
587
+ // Business Unit
588
+ 27: "name",
589
+ // Print Template
590
+ 28: "name",
591
+ // Contract
592
+ 33: "productname",
593
+ // Account Product
594
+ 46: "name",
595
+ // Project
596
+ 67: "name",
597
+ // Campaign
598
+ 76: "title",
599
+ // Article
600
+ 86: "name",
601
+ // Invoice
602
+ 101: "name",
603
+ // Attendance Clock
604
+ 102: "subject",
605
+ // Activity Log
606
+ 104: "subject",
607
+ // Conversation
608
+ 114: "name"
609
+ // Calendar Resource
610
+ };
611
+ function getNameFieldByObjectType(objectTypeId) {
612
+ const objectTypeNum = typeof objectTypeId === "string" ? parseInt(objectTypeId, 10) : objectTypeId;
613
+ if (OBJECT_NAME_MAP[objectTypeNum]) {
614
+ return OBJECT_NAME_MAP[objectTypeNum];
615
+ }
616
+ if (objectTypeNum >= 1e3) {
617
+ return "name";
618
+ }
619
+ return "name";
620
+ }
621
+
622
+ // src/constants/excludedFields.ts
623
+ var EXCLUDED_FIELDS_FOR_STAR_QUERY = {
624
+ "7": ["deletedon", "deletedby"],
625
+ // Note
626
+ "8": ["deletedon", "deletedby"],
627
+ // Competitor
628
+ "114": ["deletedon", "deletedby"],
629
+ // Calendar Resource
630
+ "115": ["deletedon", "deletedby"],
631
+ // Customer Journey
632
+ "116": ["deletedon", "deletedby"],
633
+ // Profile
634
+ "117": ["deletedon", "deletedby"]
635
+ // Landing Page
636
+ };
637
+ function getExcludedFieldsForStarQuery(objectType) {
638
+ const objectTypeStr = String(objectType);
639
+ return EXCLUDED_FIELDS_FOR_STAR_QUERY[objectTypeStr] || [];
640
+ }
641
+
642
+ // src/constants/fieldTypes.ts
643
+ var FIELD_TYPE_IDS = {
644
+ DROPDOWN: "b4919f2e-2996-48e4-a03c-ba39fb64386c",
645
+ LOOKUP: "a8fcdf65-91bc-46fd-82f6-1234758345a1",
646
+ EMAIL: "c713d2f7-8fa9-43c3-8062-f07486eaf567",
647
+ TEXT: "a1e7ed6f-5083-477b-b44c-9943a6181359",
648
+ URL: "c820d32f-44df-4c2a-9c1e-18734e864fd5",
649
+ LONG_TEXT: "80108f9d-1e75-40fa-9fa9-02be4ddc1da1",
650
+ DATETIME: "ce972d02-5013-46d4-9d1d-f09df1ac346a",
651
+ DATE: "83bf530c-e04c-462b-9ffc-a46f750fc072",
652
+ HTML: "ed2ad39d-32fc-4585-8f5b-2e93463f050a",
653
+ TELEPHONE: "3f62f67a-1cee-403a-bec6-aa02a9804edb",
654
+ NUMERIC: "6a34bfe3-fece-4da1-9136-a7b1e5ae3319"
655
+ };
656
+ var FIELD_TYPE_MAPPINGS = {
657
+ [FIELD_TYPE_IDS.DROPDOWN]: "Dropdown",
658
+ [FIELD_TYPE_IDS.EMAIL]: "Email",
659
+ [FIELD_TYPE_IDS.TEXT]: "Text",
660
+ [FIELD_TYPE_IDS.LOOKUP]: "Lookup",
661
+ [FIELD_TYPE_IDS.URL]: "URL",
662
+ [FIELD_TYPE_IDS.LONG_TEXT]: "Long Text",
663
+ [FIELD_TYPE_IDS.DATETIME]: "DateTime",
664
+ [FIELD_TYPE_IDS.DATE]: "Date",
665
+ [FIELD_TYPE_IDS.HTML]: "HTML",
666
+ [FIELD_TYPE_IDS.TELEPHONE]: "Telephone",
667
+ [FIELD_TYPE_IDS.NUMERIC]: "Number"
668
+ };
669
+
670
+ // src/utils/fieldTypes.ts
671
+ function isDropdownField(systemFieldTypeId) {
672
+ return systemFieldTypeId === FIELD_TYPE_IDS.DROPDOWN;
673
+ }
674
+ function isLookupField(systemFieldTypeId) {
675
+ return systemFieldTypeId === FIELD_TYPE_IDS.LOOKUP;
676
+ }
677
+ function isDropdownOrLookupField(systemFieldTypeId) {
678
+ return isDropdownField(systemFieldTypeId) || isLookupField(systemFieldTypeId);
679
+ }
680
+
681
+ // src/sdk/index.ts
682
+ var SDKQueryBuilder = class {
683
+ builder;
684
+ objectTypeId;
685
+ sdk;
686
+ selectedFields = [];
687
+ pageSizeValue;
688
+ pageNum = 1;
689
+ constructor(sdk, objectType) {
690
+ this.sdk = sdk;
691
+ this.objectTypeId = objectType;
692
+ this.builder = new QueryBuilder();
693
+ }
694
+ /**
695
+ * Select fields to return
696
+ * @param fields - Field names to include in results
697
+ */
698
+ select(...fields) {
699
+ this.selectedFields.push(...fields);
700
+ return this;
701
+ }
702
+ /**
703
+ * Select fields with their label fields automatically included
704
+ * Useful for dropdown and lookup fields where you want both ID and display value
705
+ * @param fields - Field names to include
706
+ */
707
+ selectWithLabels(...fields) {
708
+ const objectType = typeof this.objectTypeId === "string" ? parseInt(this.objectTypeId, 10) : this.objectTypeId;
709
+ for (const field of fields) {
710
+ if (!this.selectedFields.includes(field)) {
711
+ this.selectedFields.push(field);
712
+ }
713
+ const labelField = getLabelFieldForField(field, objectType);
714
+ if (labelField && !this.selectedFields.includes(labelField)) {
715
+ this.selectedFields.push(labelField);
716
+ }
717
+ }
718
+ return this;
719
+ }
720
+ /**
721
+ * Start a WHERE condition
722
+ * @param field - Field name to filter on
723
+ */
724
+ where(field) {
725
+ const innerBuilder = this.builder.where(field);
726
+ return {
727
+ equals: (value) => {
728
+ innerBuilder.equals(value);
729
+ return this;
730
+ },
731
+ notEquals: (value) => {
732
+ innerBuilder.notEquals(value);
733
+ return this;
734
+ },
735
+ lessThan: (value) => {
736
+ innerBuilder.lessThan(value);
737
+ return this;
738
+ },
739
+ greaterThan: (value) => {
740
+ innerBuilder.greaterThan(value);
741
+ return this;
742
+ },
743
+ lessThanOrEqual: (value) => {
744
+ innerBuilder.lessThanOrEqual(value);
745
+ return this;
746
+ },
747
+ greaterThanOrEqual: (value) => {
748
+ innerBuilder.greaterThanOrEqual(value);
749
+ return this;
750
+ },
751
+ contains: (value) => {
752
+ innerBuilder.contains(value);
753
+ return this;
754
+ },
755
+ notContains: (value) => {
756
+ innerBuilder.notContains(value);
757
+ return this;
758
+ },
759
+ startsWith: (value) => {
760
+ innerBuilder.startsWith(value);
761
+ return this;
762
+ },
763
+ notStartsWith: (value) => {
764
+ innerBuilder.notStartsWith(value);
765
+ return this;
766
+ },
767
+ isNull: () => {
768
+ innerBuilder.isNull();
769
+ return this;
770
+ },
771
+ isNotNull: () => {
772
+ innerBuilder.isNotNull();
773
+ return this;
774
+ }
775
+ };
776
+ }
777
+ /**
778
+ * Add AND logical operator
779
+ */
780
+ and() {
781
+ this.builder.and();
782
+ return this;
783
+ }
784
+ /**
785
+ * Add OR logical operator
786
+ */
787
+ or() {
788
+ this.builder.or();
789
+ return this;
790
+ }
791
+ /**
792
+ * Set page size for pagination
793
+ * @param size - Number of records per page
794
+ */
795
+ pageSize(size) {
796
+ this.pageSizeValue = size;
797
+ return this;
798
+ }
799
+ /**
800
+ * Set page number for pagination
801
+ * @param page - Page number (1-based)
802
+ */
803
+ page(page) {
804
+ this.pageNum = page;
805
+ return this;
806
+ }
807
+ /**
808
+ * Build the query payload without executing
809
+ * Useful if you want to modify the payload before sending
810
+ */
811
+ toQueryPayload() {
812
+ const payload = {
813
+ fields: this.selectedFields.length > 0 ? this.selectedFields.join(",") : "*",
814
+ query: this.builder.build()
815
+ };
816
+ if (this.pageSizeValue !== void 0) {
817
+ payload.page_size = this.pageSizeValue;
818
+ }
819
+ if (this.pageNum > 1) {
820
+ payload.page_number = this.pageNum;
821
+ }
822
+ return payload;
823
+ }
824
+ /**
825
+ * Execute the query via the SDK
826
+ */
827
+ async execute() {
828
+ const payload = this.toQueryPayload();
829
+ return this.sdk.query(this.objectTypeId, payload);
830
+ }
831
+ };
832
+ function createSDKQueryBuilder(sdk) {
833
+ const api = "api" in sdk ? sdk.api : sdk;
834
+ return (objectType) => new SDKQueryBuilder(api, objectType);
835
+ }
836
+ var EnhancedSDK = class _EnhancedSDK {
837
+ sdk;
838
+ constructor(sdk) {
839
+ this.sdk = sdk;
840
+ }
841
+ /**
842
+ * Create an EnhancedSDK wrapper around an existing SDK instance
843
+ * The SDK should already be initialized with context
844
+ *
845
+ * @param sdk - Initialized Fireberry SDK client
846
+ */
847
+ static create(sdk) {
848
+ return new _EnhancedSDK(sdk);
849
+ }
850
+ /**
851
+ * Get the current context (user and record info)
852
+ */
853
+ get context() {
854
+ return this.sdk.context;
855
+ }
856
+ /**
857
+ * Get the underlying SDK API for direct access
858
+ */
859
+ get api() {
860
+ return this.sdk.api;
861
+ }
862
+ /**
863
+ * Get the current user ID from context
864
+ */
865
+ get userId() {
866
+ return this.context?.user?.id;
867
+ }
868
+ /**
869
+ * Get the current user's full name from context
870
+ */
871
+ get userFullName() {
872
+ return this.context?.user?.fullName;
873
+ }
874
+ /**
875
+ * Get the current record ID from context
876
+ */
877
+ get recordId() {
878
+ return this.context?.record?.id;
879
+ }
880
+ /**
881
+ * Get the current record's object type from context
882
+ */
883
+ get recordType() {
884
+ return this.context?.record?.type;
885
+ }
886
+ /**
887
+ * Start building a query for an object type
888
+ *
889
+ * @param objectType - Object type ID (e.g., 1 for Account, 2 for Contact)
890
+ * @returns SDKQueryBuilder for fluent query construction
891
+ *
892
+ * @example
893
+ * ```typescript
894
+ * const results = await enhanced
895
+ * .query(1)
896
+ * .select('accountid', 'accountname')
897
+ * .where('ownerid').equals(enhanced.userId)
898
+ * .execute();
899
+ * ```
900
+ */
901
+ query(objectType) {
902
+ return new SDKQueryBuilder(this.sdk.api, objectType);
903
+ }
904
+ /**
905
+ * Get the primary key field name for an object type
906
+ *
907
+ * @param objectType - Object type ID
908
+ * @returns Primary key field name (e.g., 'accountid' for type 1)
909
+ *
910
+ * @example
911
+ * ```typescript
912
+ * const idField = enhanced.getIdField(1); // 'accountid'
913
+ * const idField = enhanced.getIdField(2); // 'contactid'
914
+ * ```
915
+ */
916
+ getIdField(objectType) {
917
+ return getObjectIdFieldName(objectType);
918
+ }
919
+ /**
920
+ * Get the display name field for an object type
921
+ *
922
+ * @param objectType - Object type ID
923
+ * @returns Name field (e.g., 'accountname' for type 1, 'fullname' for type 2)
924
+ *
925
+ * @example
926
+ * ```typescript
927
+ * const nameField = enhanced.getNameField(1); // 'accountname'
928
+ * const nameField = enhanced.getNameField(2); // 'fullname'
929
+ * ```
930
+ */
931
+ getNameField(objectType) {
932
+ return getNameFieldByObjectType(objectType);
933
+ }
934
+ /**
935
+ * Get the label field for a dropdown or lookup field
936
+ *
937
+ * @param fieldName - API field name
938
+ * @param objectType - Object type ID
939
+ * @returns Label field name, or empty string if not applicable
940
+ *
941
+ * @example
942
+ * ```typescript
943
+ * const labelField = enhanced.getLabelField('statuscode', 1); // 'status'
944
+ * const labelField = enhanced.getLabelField('ownerid', 1); // 'ownername'
945
+ * ```
946
+ */
947
+ getLabelField(fieldName, objectType) {
948
+ return getLabelFieldForField(fieldName, objectType);
949
+ }
950
+ /**
951
+ * Get fields that should be excluded from * (star) queries for an object type
952
+ * Some fields cause API errors when included in broad queries
953
+ *
954
+ * @param objectType - Object type ID
955
+ * @returns Array of field names to exclude
956
+ */
957
+ getExcludedFields(objectType) {
958
+ return getExcludedFieldsForStarQuery(objectType);
959
+ }
960
+ /**
961
+ * Expand field list to include label fields for dropdowns and lookups
962
+ *
963
+ * @param fields - Original field list
964
+ * @param objectType - Object type ID
965
+ * @returns Expanded field list with label fields
966
+ *
967
+ * @example
968
+ * ```typescript
969
+ * const fields = enhanced.expandFieldsWithLabels(['statuscode', 'ownerid'], 1);
970
+ * // Returns: ['statuscode', 'status', 'ownerid', 'ownername']
971
+ * ```
972
+ */
973
+ expandFieldsWithLabels(fields, objectType) {
974
+ const result = [];
975
+ for (const field of fields) {
976
+ if (!result.includes(field)) {
977
+ result.push(field);
978
+ }
979
+ const labelField = getLabelFieldForField(field, objectType);
980
+ if (labelField && !result.includes(labelField)) {
981
+ result.push(labelField);
982
+ }
983
+ }
984
+ return result;
985
+ }
986
+ /**
987
+ * Create a record
988
+ *
989
+ * @param objectType - Object type ID
990
+ * @param data - Record data
991
+ */
992
+ create(objectType, data) {
993
+ return this.sdk.api.create(objectType, data);
994
+ }
995
+ /**
996
+ * Update a record
997
+ *
998
+ * @param objectType - Object type ID
999
+ * @param recordId - Record ID to update
1000
+ * @param data - Updated field values
1001
+ */
1002
+ update(objectType, recordId, data) {
1003
+ return this.sdk.api.update(objectType, recordId, data);
1004
+ }
1005
+ /**
1006
+ * Delete a record
1007
+ *
1008
+ * @param objectType - Object type ID
1009
+ * @param recordId - Record ID to delete
1010
+ */
1011
+ delete(objectType, recordId) {
1012
+ return this.sdk.api.delete(objectType, recordId);
1013
+ }
1014
+ /**
1015
+ * Clean up the underlying SDK
1016
+ */
1017
+ destroy() {
1018
+ this.sdk.destroy();
1019
+ }
1020
+ };
1021
+
1022
+ exports.EXCLUDED_FIELDS_FOR_STAR_QUERY = EXCLUDED_FIELDS_FOR_STAR_QUERY;
1023
+ exports.EnhancedSDK = EnhancedSDK;
1024
+ exports.FIELD_TYPE_IDS = FIELD_TYPE_IDS;
1025
+ exports.FIELD_TYPE_MAPPINGS = FIELD_TYPE_MAPPINGS;
1026
+ exports.OBJECT_ID_MAP = OBJECT_ID_MAP;
1027
+ exports.OBJECT_NAME_MAP = OBJECT_NAME_MAP;
1028
+ exports.QueryBuilder = QueryBuilder;
1029
+ exports.SDKQueryBuilder = SDKQueryBuilder;
1030
+ exports.createSDKQueryBuilder = createSDKQueryBuilder;
1031
+ exports.escapeQueryValue = escapeQueryValue;
1032
+ exports.getExcludedFieldsForStarQuery = getExcludedFieldsForStarQuery;
1033
+ exports.getLabelFieldForField = getLabelFieldForField;
1034
+ exports.getNameFieldByObjectType = getNameFieldByObjectType;
1035
+ exports.getObjectIdFieldName = getObjectIdFieldName;
1036
+ exports.isDropdownField = isDropdownField;
1037
+ exports.isDropdownOrLookupField = isDropdownOrLookupField;
1038
+ exports.isLookupField = isLookupField;
1039
+ exports.sanitizeQuery = sanitizeQuery;
1040
+ //# sourceMappingURL=index.cjs.map
1041
+ //# sourceMappingURL=index.cjs.map