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,796 @@
1
+ 'use strict';
2
+
3
+ // src/constants/objectIds.ts
4
+ var OBJECT_ID_MAP = {
5
+ 1: "accountid",
6
+ 2: "contactid",
7
+ 3: "leadid",
8
+ 4: "opportunityid",
9
+ 5: "casesid",
10
+ 6: "activityid",
11
+ 7: "noteid",
12
+ 8: "competitorid",
13
+ 9: "crmuserid",
14
+ 10: "taskid",
15
+ 13: "crmorderid",
16
+ 14: "productid",
17
+ 17: "crmorderitemid",
18
+ 20: "emailtemplateid",
19
+ 23: "businessunitid",
20
+ 27: "printtemplateid",
21
+ 28: "contractid",
22
+ 33: "accountproductid",
23
+ 46: "projectid",
24
+ 67: "campaignid",
25
+ 76: "articleid",
26
+ 86: "invoiceid",
27
+ 101: "attendanceclockid",
28
+ 102: "activitylogid",
29
+ 104: "conversationid",
30
+ 114: "calendarresourceid"
31
+ };
32
+ function getObjectIdFieldName(objectTypeId) {
33
+ const objectTypeNum = typeof objectTypeId === "string" ? parseInt(objectTypeId, 10) : objectTypeId;
34
+ if (OBJECT_ID_MAP[objectTypeNum]) {
35
+ return OBJECT_ID_MAP[objectTypeNum];
36
+ }
37
+ if (objectTypeNum >= 1e3) {
38
+ return `customobject${objectTypeNum}id`;
39
+ }
40
+ return "id";
41
+ }
42
+
43
+ // src/constants/objectNames.ts
44
+ var OBJECT_NAME_MAP = {
45
+ 1: "accountname",
46
+ // Account
47
+ 2: "fullname",
48
+ // Contact
49
+ 3: "fullname",
50
+ // Lead
51
+ 4: "name",
52
+ // Opportunity
53
+ 5: "title",
54
+ // Case
55
+ 6: "subject",
56
+ // Activity
57
+ 7: "subject",
58
+ // Note
59
+ 8: "name",
60
+ // Competitor
61
+ 9: "fullname",
62
+ // CRM User
63
+ 10: "subject",
64
+ // Task
65
+ 13: "name",
66
+ // CRM Order
67
+ 14: "productname",
68
+ // Product
69
+ 17: "productname",
70
+ // CRM Order Item
71
+ 20: "name",
72
+ // Email Template
73
+ 23: "name",
74
+ // Business Unit
75
+ 27: "name",
76
+ // Print Template
77
+ 28: "name",
78
+ // Contract
79
+ 33: "productname",
80
+ // Account Product
81
+ 46: "name",
82
+ // Project
83
+ 67: "name",
84
+ // Campaign
85
+ 76: "title",
86
+ // Article
87
+ 86: "name",
88
+ // Invoice
89
+ 101: "name",
90
+ // Attendance Clock
91
+ 102: "subject",
92
+ // Activity Log
93
+ 104: "subject",
94
+ // Conversation
95
+ 114: "name"
96
+ // Calendar Resource
97
+ };
98
+ function getNameFieldByObjectType(objectTypeId) {
99
+ const objectTypeNum = typeof objectTypeId === "string" ? parseInt(objectTypeId, 10) : objectTypeId;
100
+ if (OBJECT_NAME_MAP[objectTypeNum]) {
101
+ return OBJECT_NAME_MAP[objectTypeNum];
102
+ }
103
+ if (objectTypeNum >= 1e3) {
104
+ return "name";
105
+ }
106
+ return "name";
107
+ }
108
+
109
+ // src/utils/fieldMapping.ts
110
+ var SPECIAL_LABEL_FIELD_MAPPINGS = {
111
+ objectid: "objecttitle",
112
+ lastactionid: "lastactiontitle",
113
+ wfruleid: "rulename",
114
+ // Object 55 (Workflow Rules)
115
+ noteid: "subject"
116
+ // Object 7 (Note) - noteid maps to subject
117
+ };
118
+ var EXCLUDED_ID_FIELDS = [
119
+ "businessunitid",
120
+ // → businessunitidname (not businessunitname)
121
+ "crmuserid",
122
+ // → no name field exists
123
+ "languageid"
124
+ // → languageidname (not languagename)
125
+ ];
126
+ var EXCLUDED_CODE_FIELDS = [
127
+ "duplicaterecordcode"
128
+ // → duplicaterecordcodename (not duplicaterecord)
129
+ ];
130
+ var FIELDS_WITHOUT_LABEL_FIELD = [
131
+ "systemfieldid",
132
+ // Object 73 - no name field exists
133
+ "fieldobjecttype",
134
+ // Object 73 - base field doesn't exist, only *name exists
135
+ "invoiceid",
136
+ // Objects 78, 81 - no name field exists
137
+ "calllogid",
138
+ // Object 100 - no name field exists (primary key)
139
+ "attendanceclockid",
140
+ // Object 101 - no name field exists (primary key)
141
+ "activitylogid",
142
+ // Object 102 - no name field exists (primary key)
143
+ "conversationid",
144
+ // Object 104 - no name field exists (primary key)
145
+ "texttemplateid",
146
+ // Text Template - no name field exists (primary key)
147
+ "smstemplateid",
148
+ // Object 110 - no name field exists (primary key)
149
+ "deletedby",
150
+ // Object 7 - no name field exists
151
+ "recordid",
152
+ // Object 7 - no name field exists
153
+ "objecttypecode"
154
+ // Object 7 - no name field exists
155
+ ];
156
+ var OBJECT_TYPE_OVERRIDES = {
157
+ // CRM Orders (13) - uses *idname and *codename patterns
158
+ 13: {
159
+ excludedIdFields: ["ownerid", "accountid", "printtemplateid", "pcfaccountid"],
160
+ excludedCodeFields: [
161
+ "rounddiscountcode",
162
+ "taxincludecode",
163
+ "currencycode",
164
+ "transmissioncode",
165
+ "creditrejectioncode1",
166
+ "creditrejectioncode2",
167
+ "apartmentcode1",
168
+ "apartmentcode2",
169
+ "restrictioncode1",
170
+ "restrictioncode2",
171
+ "casescode1",
172
+ "casescode2",
173
+ "returncode1",
174
+ "returncode2",
175
+ "statuscode"
176
+ ]
177
+ },
178
+ // Products (14)
179
+ 14: {
180
+ excludedCodeFields: ["categorycode"]
181
+ // → categoryname (not category)
182
+ },
183
+ // CRM Order Items (17) - uses *idname pattern
184
+ 17: {
185
+ excludedIdFields: ["crmorderid", "productid", "ownerid"]
186
+ },
187
+ // Email Templates (20)
188
+ 20: {
189
+ excludedIdFields: ["mdobjectid"]
190
+ },
191
+ // Print Templates (27)
192
+ 27: {
193
+ excludedIdFields: ["mdobjectid"]
194
+ },
195
+ // System Fields (73) - uses *idname pattern
196
+ 73: {
197
+ excludedIdFields: ["mdobjectid", "ownerid"]
198
+ },
199
+ // Invoices (78) - uses *codename and *idname patterns extensively
200
+ 78: {
201
+ excludedIdFields: [
202
+ "crmorderid",
203
+ "invoicereceiptid",
204
+ "accountid",
205
+ "ownerid",
206
+ "invoicerenoid"
207
+ ],
208
+ excludedCodeFields: [
209
+ "taxincludecode",
210
+ "depositcode",
211
+ "rounddiscountcode",
212
+ "currencycode",
213
+ "statecode",
214
+ "invoicetypecode"
215
+ ]
216
+ },
217
+ // Invoice No (81) - uses *codename and *idname patterns extensively
218
+ 81: {
219
+ excludedIdFields: [
220
+ "ownerid",
221
+ "invoicecreditid",
222
+ "crmorderid",
223
+ "invoicereceiptid",
224
+ "invoicedeliveryid",
225
+ "accountid"
226
+ ],
227
+ excludedCodeFields: ["currencycode", "rounddiscountcode", "statecode", "taxincludecode"]
228
+ },
229
+ // Invoice Draft (82) - uses *codename and *idname patterns extensively
230
+ 82: {
231
+ excludedIdFields: ["accountid", "crmorderid", "ownerid", "invoicerenoid"],
232
+ excludedCodeFields: ["taxincludecode", "statecode", "rounddiscountcode", "currencycode"]
233
+ },
234
+ // Invoice Receipt (83) - uses *codename and *idname patterns
235
+ 83: {
236
+ excludedIdFields: ["invoicenoid", "crmorderid", "ownerid", "accountid"],
237
+ excludedCodeFields: ["statecode", "currencycode"]
238
+ },
239
+ // Invoice Tax Receipt (84) - uses *codename and *idname patterns
240
+ 84: {
241
+ excludedIdFields: ["crmorderid", "ownerid", "invoicecreditid", "accountid"],
242
+ excludedCodeFields: ["rounddiscountcode", "statecode", "taxincludecode", "currencycode"]
243
+ },
244
+ // Invoice Credit (85) - uses *codename and *idname patterns
245
+ 85: {
246
+ excludedIdFields: ["ownerid", "crmorderid", "accountid"],
247
+ excludedCodeFields: ["taxincludecode", "rounddiscountcode", "currencycode", "statecode"]
248
+ },
249
+ // Invoice (86) - uses *codename and *idname patterns
250
+ 86: {
251
+ excludedIdFields: ["accountid", "ownerid", "crmorderid"],
252
+ excludedCodeFields: ["statecode", "rounddiscountcode", "currencycode", "taxincludecode"]
253
+ },
254
+ // Call Log (100) - uses *idname pattern
255
+ 100: {
256
+ excludedIdFields: ["contactid", "leadid", "accountid", "ownerid"]
257
+ },
258
+ // Attendance Clock (101) - uses *idname pattern
259
+ 101: {
260
+ excludedIdFields: ["ownerid"]
261
+ },
262
+ // Activity Log (102) - uses *idname and *codename patterns
263
+ 102: {
264
+ excludedIdFields: ["contactid", "ownerid"],
265
+ excludedCodeFields: ["objecttypecode", "typecode", "resultcode"]
266
+ },
267
+ // Conversation (104) - uses *idname pattern
268
+ 104: {
269
+ excludedIdFields: ["leadid", "ownerid", "contactid", "accountid"]
270
+ },
271
+ // Text Template (106) - uses *idname pattern
272
+ 106: {
273
+ excludedIdFields: ["ownerid"]
274
+ },
275
+ // SMS Template (110) - uses *idname pattern
276
+ 110: {
277
+ excludedIdFields: ["ownerid"]
278
+ }
279
+ };
280
+ function getLabelFieldForField(fieldName, objectType) {
281
+ if (SPECIAL_LABEL_FIELD_MAPPINGS[fieldName]) {
282
+ return SPECIAL_LABEL_FIELD_MAPPINGS[fieldName];
283
+ }
284
+ if (FIELDS_WITHOUT_LABEL_FIELD.includes(fieldName)) {
285
+ return "";
286
+ }
287
+ if (/^customobject\d+id$/.test(fieldName)) {
288
+ return "name";
289
+ }
290
+ if (fieldName.startsWith("pcf")) {
291
+ return `${fieldName}name`;
292
+ }
293
+ const objectTypeNum = typeof objectType === "string" ? parseInt(objectType, 10) : objectType;
294
+ const overrides = OBJECT_TYPE_OVERRIDES[objectTypeNum] || null;
295
+ const isCustomObject = objectTypeNum >= 1e3;
296
+ const customObjectExclusions = isCustomObject ? ["ownerid"] : [];
297
+ const excludedCodeFields = [
298
+ ...EXCLUDED_CODE_FIELDS,
299
+ ...overrides?.excludedCodeFields || []
300
+ ];
301
+ const excludedIdFields = [
302
+ ...EXCLUDED_ID_FIELDS,
303
+ ...overrides?.excludedIdFields || [],
304
+ ...customObjectExclusions
305
+ ];
306
+ if (fieldName.endsWith("code") && !excludedCodeFields.includes(fieldName)) {
307
+ return fieldName.slice(0, -4);
308
+ }
309
+ if (fieldName.endsWith("id") && !excludedIdFields.includes(fieldName)) {
310
+ return fieldName.slice(0, -2) + "name";
311
+ }
312
+ return `${fieldName}name`;
313
+ }
314
+
315
+ // src/constants/fieldTypes.ts
316
+ var FIELD_TYPE_IDS = {
317
+ DROPDOWN: "b4919f2e-2996-48e4-a03c-ba39fb64386c",
318
+ LOOKUP: "a8fcdf65-91bc-46fd-82f6-1234758345a1",
319
+ EMAIL: "c713d2f7-8fa9-43c3-8062-f07486eaf567",
320
+ TEXT: "a1e7ed6f-5083-477b-b44c-9943a6181359",
321
+ URL: "c820d32f-44df-4c2a-9c1e-18734e864fd5",
322
+ LONG_TEXT: "80108f9d-1e75-40fa-9fa9-02be4ddc1da1",
323
+ DATETIME: "ce972d02-5013-46d4-9d1d-f09df1ac346a",
324
+ DATE: "83bf530c-e04c-462b-9ffc-a46f750fc072",
325
+ HTML: "ed2ad39d-32fc-4585-8f5b-2e93463f050a",
326
+ TELEPHONE: "3f62f67a-1cee-403a-bec6-aa02a9804edb",
327
+ NUMERIC: "6a34bfe3-fece-4da1-9136-a7b1e5ae3319"
328
+ };
329
+ var FIELD_TYPE_MAPPINGS = {
330
+ [FIELD_TYPE_IDS.DROPDOWN]: "Dropdown",
331
+ [FIELD_TYPE_IDS.EMAIL]: "Email",
332
+ [FIELD_TYPE_IDS.TEXT]: "Text",
333
+ [FIELD_TYPE_IDS.LOOKUP]: "Lookup",
334
+ [FIELD_TYPE_IDS.URL]: "URL",
335
+ [FIELD_TYPE_IDS.LONG_TEXT]: "Long Text",
336
+ [FIELD_TYPE_IDS.DATETIME]: "DateTime",
337
+ [FIELD_TYPE_IDS.DATE]: "Date",
338
+ [FIELD_TYPE_IDS.HTML]: "HTML",
339
+ [FIELD_TYPE_IDS.TELEPHONE]: "Telephone",
340
+ [FIELD_TYPE_IDS.NUMERIC]: "Number"
341
+ };
342
+
343
+ // src/utils/fieldTypes.ts
344
+ function isDropdownField(systemFieldTypeId) {
345
+ return systemFieldTypeId === FIELD_TYPE_IDS.DROPDOWN;
346
+ }
347
+ function isLookupField(systemFieldTypeId) {
348
+ return systemFieldTypeId === FIELD_TYPE_IDS.LOOKUP;
349
+ }
350
+ function isDropdownOrLookupField(systemFieldTypeId) {
351
+ return isDropdownField(systemFieldTypeId) || isLookupField(systemFieldTypeId);
352
+ }
353
+ function isTextField(systemFieldTypeId) {
354
+ return systemFieldTypeId === FIELD_TYPE_IDS.TEXT;
355
+ }
356
+ function isNumericField(systemFieldTypeId) {
357
+ return systemFieldTypeId === FIELD_TYPE_IDS.NUMERIC;
358
+ }
359
+ function isDateField(systemFieldTypeId) {
360
+ return systemFieldTypeId === FIELD_TYPE_IDS.DATE || systemFieldTypeId === FIELD_TYPE_IDS.DATETIME;
361
+ }
362
+ function getFieldTypeName(systemFieldTypeId) {
363
+ const typeMap = {
364
+ [FIELD_TYPE_IDS.DROPDOWN]: "Dropdown",
365
+ [FIELD_TYPE_IDS.LOOKUP]: "Lookup",
366
+ [FIELD_TYPE_IDS.EMAIL]: "Email",
367
+ [FIELD_TYPE_IDS.TEXT]: "Text",
368
+ [FIELD_TYPE_IDS.URL]: "URL",
369
+ [FIELD_TYPE_IDS.LONG_TEXT]: "Long Text",
370
+ [FIELD_TYPE_IDS.DATETIME]: "DateTime",
371
+ [FIELD_TYPE_IDS.DATE]: "Date",
372
+ [FIELD_TYPE_IDS.HTML]: "HTML",
373
+ [FIELD_TYPE_IDS.TELEPHONE]: "Telephone",
374
+ [FIELD_TYPE_IDS.NUMERIC]: "Number"
375
+ };
376
+ return typeMap[systemFieldTypeId] || "Unknown";
377
+ }
378
+
379
+ // src/utils/helpers.ts
380
+ function wait(ms) {
381
+ return new Promise((resolve) => {
382
+ setTimeout(resolve, ms);
383
+ });
384
+ }
385
+ function chunkArray(array, size) {
386
+ const result = [];
387
+ for (let i = 0; i < array.length; i += size) {
388
+ result.push(array.slice(i, i + size));
389
+ }
390
+ return result;
391
+ }
392
+ function safeStringValue(value) {
393
+ if (value === null || value === void 0) {
394
+ return "";
395
+ }
396
+ if (typeof value === "string") {
397
+ return value;
398
+ }
399
+ if (typeof value === "number" || typeof value === "boolean") {
400
+ return String(value);
401
+ }
402
+ if (typeof value === "object") {
403
+ return JSON.stringify(value);
404
+ }
405
+ return String(value);
406
+ }
407
+ function normalizeFields(fields) {
408
+ if (Array.isArray(fields)) {
409
+ return fields;
410
+ }
411
+ if (typeof fields === "string") {
412
+ if (!fields.trim()) {
413
+ return [];
414
+ }
415
+ return fields.split(",").map((f) => f.trim()).filter((f) => f.length > 0);
416
+ }
417
+ return [];
418
+ }
419
+ function joinFields(fields) {
420
+ return fields.join(",");
421
+ }
422
+ function isSelectAll(fields) {
423
+ if (Array.isArray(fields)) {
424
+ return fields.length === 0 || fields.length === 1 && fields[0] === "*";
425
+ }
426
+ return !fields || fields === "*";
427
+ }
428
+ function deepClone(obj) {
429
+ return JSON.parse(JSON.stringify(obj));
430
+ }
431
+ function isPlainObject(value) {
432
+ return typeof value === "object" && value !== null && !Array.isArray(value);
433
+ }
434
+
435
+ // src/utils/queryBuilder.ts
436
+ function escapeQueryValue(value) {
437
+ if (!value) {
438
+ return "";
439
+ }
440
+ let escaped = value.replace(/\\/g, "\\\\");
441
+ escaped = escaped.replace(/\(/g, "\\(");
442
+ escaped = escaped.replace(/\)/g, "\\)");
443
+ escaped = escaped.replace(/\bor\b/gi, "\\or");
444
+ escaped = escaped.replace(/\band\b/gi, "\\and");
445
+ return escaped;
446
+ }
447
+ function sanitizeQuery(query) {
448
+ if (!query) {
449
+ return "";
450
+ }
451
+ query = query.replace(
452
+ /\(\s*([a-zA-Z0-9_]+)\s+(is-null|is-not-null)\s*\)/g,
453
+ "($1 __SPECIAL_OPERATOR__$2)"
454
+ );
455
+ query = query.replace(
456
+ /\(\s*([a-zA-Z0-9_]+)\s+(start-with|not-start-with)\s+([^)]+)\s*\)/g,
457
+ "($1 __TEXT_OPERATOR__$2 $3)"
458
+ );
459
+ query = query.replace(
460
+ /\(\s*([a-zA-Z0-9_]+(?:field|Field|system|System)[0-9]*)\s+(?!__SPECIAL_OPERATOR__|__TEXT_OPERATOR__)([^()<>=!]+)\s*\)/g,
461
+ "($1 = $2)"
462
+ );
463
+ query = query.replace(
464
+ /\(\s*([a-zA-Z0-9_]+)\s+(?!__SPECIAL_OPERATOR__|__TEXT_OPERATOR__|<=|>=|!=|<|>|=\s)([^()<>]+)\s*\)/g,
465
+ "($1 = $2)"
466
+ );
467
+ query = query.replace(/__SPECIAL_OPERATOR__/g, "");
468
+ query = query.replace(/__TEXT_OPERATOR__/g, "");
469
+ query = query.replace(/\(\s*(?:<=|>=|!=|<|>|=)\s*\)/g, "");
470
+ query = query.replace(/\(\s*(?:start-with|not-start-with)\s*\)/gi, "");
471
+ query = query.replace(/\(\s*(?:and|or)\s*\)/gi, "");
472
+ query = query.replace(/\(\s*\)/g, "");
473
+ query = query.replace(/^\s*(and|or)\s*/gi, "");
474
+ query = query.replace(/\s*(and|or)\s*$/gi, "");
475
+ const nestedPattern = /\(\s*\(([^()]+)\)\s*\)/g;
476
+ while (nestedPattern.test(query)) {
477
+ query = query.replace(nestedPattern, "($1)");
478
+ }
479
+ query = query.replace(/\s+/g, " ");
480
+ return query.trim();
481
+ }
482
+ var QueryBuilder = class {
483
+ conditions = [];
484
+ joinOperators = [];
485
+ currentField = null;
486
+ selectedFields = [];
487
+ objectTypeId = null;
488
+ sortByField = null;
489
+ sortDirection = "desc";
490
+ limitValue = null;
491
+ pageNumber = 1;
492
+ showRealValueFlag = true;
493
+ client = null;
494
+ /**
495
+ * Creates a new QueryBuilder
496
+ * @param client - Optional FireberryClient for executing queries
497
+ */
498
+ constructor(client) {
499
+ this.client = client ?? null;
500
+ }
501
+ /**
502
+ * Sets the object type for the query
503
+ * @param objectType - Object type ID (e.g., '1' for Account)
504
+ */
505
+ objectType(objectType) {
506
+ this.objectTypeId = String(objectType);
507
+ return this;
508
+ }
509
+ /**
510
+ * Adds fields to select
511
+ * @param fields - Field names to select
512
+ */
513
+ select(...fields) {
514
+ this.selectedFields.push(...fields);
515
+ return this;
516
+ }
517
+ /**
518
+ * Starts a new WHERE condition
519
+ * @param field - Field name to filter on
520
+ */
521
+ where(field) {
522
+ this.currentField = field;
523
+ return this.createConditionBuilder();
524
+ }
525
+ /**
526
+ * Adds an AND logical operator
527
+ */
528
+ and() {
529
+ if (this.conditions.length > 0) {
530
+ this.joinOperators.push("and");
531
+ }
532
+ return this;
533
+ }
534
+ /**
535
+ * Adds an OR logical operator
536
+ */
537
+ or() {
538
+ if (this.conditions.length > 0) {
539
+ this.joinOperators.push("or");
540
+ }
541
+ return this;
542
+ }
543
+ /**
544
+ * Sets the sort field and direction
545
+ * @param field - Field to sort by
546
+ * @param direction - Sort direction ('asc' or 'desc')
547
+ */
548
+ sortBy(field, direction = "desc") {
549
+ this.sortByField = field;
550
+ this.sortDirection = direction;
551
+ return this;
552
+ }
553
+ /**
554
+ * Sets the maximum number of records to return
555
+ * @param count - Maximum record count
556
+ */
557
+ limit(count) {
558
+ this.limitValue = count;
559
+ return this;
560
+ }
561
+ /**
562
+ * Sets the page number for pagination
563
+ * @param page - Page number (1-based)
564
+ */
565
+ page(page) {
566
+ this.pageNumber = page;
567
+ return this;
568
+ }
569
+ /**
570
+ * Controls whether to show real values (labels) for dropdown fields
571
+ * @param show - Whether to show real values (default: true)
572
+ */
573
+ showRealValue(show) {
574
+ this.showRealValueFlag = show;
575
+ return this;
576
+ }
577
+ /**
578
+ * Builds the query string from conditions
579
+ * @returns The built query string
580
+ */
581
+ build() {
582
+ if (this.conditions.length === 0) {
583
+ return "";
584
+ }
585
+ const parts = [];
586
+ for (let i = 0; i < this.conditions.length; i++) {
587
+ const condition = this.conditions[i];
588
+ let conditionStr;
589
+ if (condition.operator === "is-null" || condition.operator === "is-not-null") {
590
+ conditionStr = `(${condition.field} ${condition.operator})`;
591
+ } else {
592
+ const escapedValue = escapeQueryValue(condition.value || "");
593
+ conditionStr = `(${condition.field} ${condition.operator} ${escapedValue})`;
594
+ }
595
+ parts.push(conditionStr);
596
+ if (i < this.joinOperators.length) {
597
+ parts.push(this.joinOperators[i]);
598
+ }
599
+ }
600
+ return parts.join(" ");
601
+ }
602
+ /**
603
+ * Returns the selected fields array
604
+ * Useful for inspecting the query configuration
605
+ */
606
+ getFields() {
607
+ return [...this.selectedFields];
608
+ }
609
+ /**
610
+ * Converts the query builder state to a payload compatible with @fireberry/sdk
611
+ *
612
+ * @returns Object with `fields` (comma-separated string) and `query` (filter string)
613
+ *
614
+ * @example
615
+ * ```typescript
616
+ * import FireberryClientSDK from '@fireberry/sdk/client';
617
+ * import { QueryBuilder } from 'fireberry-api-client';
618
+ *
619
+ * const sdk = new FireberryClientSDK();
620
+ * await sdk.initializeContext();
621
+ *
622
+ * const payload = new QueryBuilder()
623
+ * .select('accountid', 'accountname')
624
+ * .where('statuscode').equals('1')
625
+ * .toSDKPayload();
626
+ *
627
+ * // Use with SDK
628
+ * const results = await sdk.api.query(1, payload);
629
+ * ```
630
+ */
631
+ toSDKPayload() {
632
+ const payload = {
633
+ fields: this.selectedFields.length > 0 ? this.selectedFields.join(",") : "*",
634
+ query: this.build()
635
+ };
636
+ if (this.limitValue !== null) {
637
+ payload.page_size = this.limitValue;
638
+ }
639
+ if (this.pageNumber > 1) {
640
+ payload.page_number = this.pageNumber;
641
+ }
642
+ return payload;
643
+ }
644
+ /**
645
+ * Executes the query (requires client to be set)
646
+ * @param signal - Optional AbortSignal for cancellation
647
+ * @returns Query results
648
+ */
649
+ async execute(signal) {
650
+ if (!this.client) {
651
+ throw new Error("QueryBuilder requires a client to execute queries. Pass a FireberryClient to the constructor.");
652
+ }
653
+ if (!this.objectTypeId) {
654
+ throw new Error("Object type is required. Use .objectType() before executing.");
655
+ }
656
+ const queryOptions = {
657
+ objectType: this.objectTypeId,
658
+ fields: this.selectedFields.length > 0 ? this.selectedFields : ["*"],
659
+ query: this.build(),
660
+ showRealValue: this.showRealValueFlag
661
+ };
662
+ if (this.sortByField) {
663
+ queryOptions.sortBy = this.sortByField;
664
+ queryOptions.sortType = this.sortDirection;
665
+ }
666
+ if (this.limitValue !== null) {
667
+ queryOptions.limit = this.limitValue;
668
+ }
669
+ if (this.pageNumber > 1) {
670
+ queryOptions.page = this.pageNumber;
671
+ }
672
+ if (signal) {
673
+ queryOptions.signal = signal;
674
+ }
675
+ return this.client.query(queryOptions);
676
+ }
677
+ /**
678
+ * Creates a condition builder for the current field
679
+ */
680
+ createConditionBuilder() {
681
+ const field = this.currentField;
682
+ return {
683
+ equals: (value) => {
684
+ this.addCondition(field, "=", String(value));
685
+ return this;
686
+ },
687
+ notEquals: (value) => {
688
+ this.addCondition(field, "!=", String(value));
689
+ return this;
690
+ },
691
+ lessThan: (value) => {
692
+ this.addCondition(field, "<", String(value));
693
+ return this;
694
+ },
695
+ greaterThan: (value) => {
696
+ this.addCondition(field, ">", String(value));
697
+ return this;
698
+ },
699
+ lessThanOrEqual: (value) => {
700
+ this.addCondition(field, "<=", String(value));
701
+ return this;
702
+ },
703
+ greaterThanOrEqual: (value) => {
704
+ this.addCondition(field, ">=", String(value));
705
+ return this;
706
+ },
707
+ contains: (value) => {
708
+ this.addCondition(field, "start-with", `%${value}`);
709
+ return this;
710
+ },
711
+ notContains: (value) => {
712
+ this.addCondition(field, "not-start-with", `%${value}`);
713
+ return this;
714
+ },
715
+ startsWith: (value) => {
716
+ this.addCondition(field, "start-with", value);
717
+ return this;
718
+ },
719
+ notStartsWith: (value) => {
720
+ this.addCondition(field, "not-start-with", value);
721
+ return this;
722
+ },
723
+ isNull: () => {
724
+ this.addCondition(field, "is-null");
725
+ return this;
726
+ },
727
+ isNotNull: () => {
728
+ this.addCondition(field, "is-not-null");
729
+ return this;
730
+ }
731
+ };
732
+ }
733
+ /**
734
+ * Adds a condition to the query
735
+ */
736
+ addCondition(field, operator, value) {
737
+ this.conditions.push({ field, operator, value });
738
+ this.currentField = null;
739
+ }
740
+ };
741
+
742
+ // src/constants/excludedFields.ts
743
+ var EXCLUDED_FIELDS_FOR_STAR_QUERY = {
744
+ "7": ["deletedon", "deletedby"],
745
+ // Note
746
+ "8": ["deletedon", "deletedby"],
747
+ // Competitor
748
+ "114": ["deletedon", "deletedby"],
749
+ // Calendar Resource
750
+ "115": ["deletedon", "deletedby"],
751
+ // Customer Journey
752
+ "116": ["deletedon", "deletedby"],
753
+ // Profile
754
+ "117": ["deletedon", "deletedby"]
755
+ // Landing Page
756
+ };
757
+ function isExcludedFromStarQuery(objectType, fieldName) {
758
+ const objectTypeStr = String(objectType);
759
+ const excludedFields = EXCLUDED_FIELDS_FOR_STAR_QUERY[objectTypeStr];
760
+ return excludedFields ? excludedFields.includes(fieldName) : false;
761
+ }
762
+ function getExcludedFieldsForStarQuery(objectType) {
763
+ const objectTypeStr = String(objectType);
764
+ return EXCLUDED_FIELDS_FOR_STAR_QUERY[objectTypeStr] || [];
765
+ }
766
+
767
+ exports.EXCLUDED_FIELDS_FOR_STAR_QUERY = EXCLUDED_FIELDS_FOR_STAR_QUERY;
768
+ exports.FIELD_TYPE_IDS = FIELD_TYPE_IDS;
769
+ exports.FIELD_TYPE_MAPPINGS = FIELD_TYPE_MAPPINGS;
770
+ exports.OBJECT_ID_MAP = OBJECT_ID_MAP;
771
+ exports.OBJECT_NAME_MAP = OBJECT_NAME_MAP;
772
+ exports.QueryBuilder = QueryBuilder;
773
+ exports.chunkArray = chunkArray;
774
+ exports.deepClone = deepClone;
775
+ exports.escapeQueryValue = escapeQueryValue;
776
+ exports.getExcludedFieldsForStarQuery = getExcludedFieldsForStarQuery;
777
+ exports.getFieldTypeName = getFieldTypeName;
778
+ exports.getLabelFieldForField = getLabelFieldForField;
779
+ exports.getNameFieldByObjectType = getNameFieldByObjectType;
780
+ exports.getObjectIdFieldName = getObjectIdFieldName;
781
+ exports.isDateField = isDateField;
782
+ exports.isDropdownField = isDropdownField;
783
+ exports.isDropdownOrLookupField = isDropdownOrLookupField;
784
+ exports.isExcludedFromStarQuery = isExcludedFromStarQuery;
785
+ exports.isLookupField = isLookupField;
786
+ exports.isNumericField = isNumericField;
787
+ exports.isPlainObject = isPlainObject;
788
+ exports.isSelectAll = isSelectAll;
789
+ exports.isTextField = isTextField;
790
+ exports.joinFields = joinFields;
791
+ exports.normalizeFields = normalizeFields;
792
+ exports.safeStringValue = safeStringValue;
793
+ exports.sanitizeQuery = sanitizeQuery;
794
+ exports.wait = wait;
795
+ //# sourceMappingURL=index.cjs.map
796
+ //# sourceMappingURL=index.cjs.map