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