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