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,278 @@
1
+ /**
2
+ * Escapes special characters in query values to prevent query injection.
3
+ * This is a security measure to ensure user-provided values cannot modify
4
+ * the query structure or inject additional query logic.
5
+ *
6
+ * @param value - The value to escape
7
+ * @returns Escaped value safe for use in Fireberry queries
8
+ */
9
+ declare function escapeQueryValue(value: string): string;
10
+ /**
11
+ * Sanitizes a query string to ensure proper syntax for the Fireberry API
12
+ * Handles common syntax issues and removes extraneous elements
13
+ *
14
+ * @param query - Query string to sanitize
15
+ * @returns Sanitized query string
16
+ */
17
+ declare function sanitizeQuery(query: string): string;
18
+ /**
19
+ * Condition builder for fluent query construction
20
+ */
21
+ interface ConditionBuilder {
22
+ /** Equals comparison (=) */
23
+ equals(value: string | number): QueryBuilder;
24
+ /** Not equals comparison (!=) */
25
+ notEquals(value: string | number): QueryBuilder;
26
+ /** Less than comparison (<) - works with numbers and dates */
27
+ lessThan(value: string | number): QueryBuilder;
28
+ /** Greater than comparison (>) - works with numbers and dates */
29
+ greaterThan(value: string | number): QueryBuilder;
30
+ /** Less than or equal (<=) - works with numbers ONLY (not dates!) */
31
+ lessThanOrEqual(value: string | number): QueryBuilder;
32
+ /** Greater than or equal (>=) - works with numbers ONLY (not dates!) */
33
+ greaterThanOrEqual(value: string | number): QueryBuilder;
34
+ /** Contains value (translates to start-with %value) */
35
+ contains(value: string): QueryBuilder;
36
+ /** Does not contain value (translates to not-start-with %value) */
37
+ notContains(value: string): QueryBuilder;
38
+ /** Starts with value (start-with) */
39
+ startsWith(value: string): QueryBuilder;
40
+ /** Does not start with value (not-start-with) */
41
+ notStartsWith(value: string): QueryBuilder;
42
+ /** Field is null (is-null) */
43
+ isNull(): QueryBuilder;
44
+ /** Field is not null (is-not-null) */
45
+ isNotNull(): QueryBuilder;
46
+ }
47
+ /**
48
+ * Fluent query builder for constructing Fireberry queries
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Build a query string
53
+ * const query = new QueryBuilder()
54
+ * .where('statuscode').equals('1')
55
+ * .and()
56
+ * .where('emailaddress1').contains('@example.com')
57
+ * .build();
58
+ * // Output: "(statuscode = 1) and (emailaddress1 start-with %@example.com)"
59
+ *
60
+ * // With select and execute (requires client)
61
+ * const result = await new QueryBuilder(client)
62
+ * .objectType('1')
63
+ * .select('accountid', 'name', 'emailaddress1')
64
+ * .where('statuscode').equals('1')
65
+ * .limit(100)
66
+ * .execute();
67
+ * ```
68
+ */
69
+ /**
70
+ * Client interface for query execution
71
+ */
72
+ interface QueryClient {
73
+ query(options: {
74
+ objectType: string;
75
+ fields: string[];
76
+ query: string;
77
+ showRealValue: boolean;
78
+ sortBy?: string;
79
+ sortType?: 'asc' | 'desc';
80
+ limit?: number;
81
+ page?: number;
82
+ signal?: AbortSignal;
83
+ }): Promise<QueryResult>;
84
+ }
85
+ /**
86
+ * Query result type
87
+ */
88
+ interface QueryResult {
89
+ records: Record<string, unknown>[];
90
+ total: number;
91
+ success: boolean;
92
+ }
93
+ declare class QueryBuilder {
94
+ private conditions;
95
+ private joinOperators;
96
+ private currentField;
97
+ private selectedFields;
98
+ private objectTypeId;
99
+ private sortByField;
100
+ private sortDirection;
101
+ private limitValue;
102
+ private pageNumber;
103
+ private showRealValueFlag;
104
+ private client;
105
+ /**
106
+ * Creates a new QueryBuilder
107
+ * @param client - Optional FireberryClient for executing queries
108
+ */
109
+ constructor(client?: QueryClient);
110
+ /**
111
+ * Sets the object type for the query
112
+ * @param objectType - Object type ID (e.g., '1' for Account)
113
+ */
114
+ objectType(objectType: string | number): this;
115
+ /**
116
+ * Adds fields to select
117
+ * @param fields - Field names to select
118
+ */
119
+ select(...fields: string[]): this;
120
+ /**
121
+ * Starts a new WHERE condition
122
+ * @param field - Field name to filter on
123
+ */
124
+ where(field: string): ConditionBuilder;
125
+ /**
126
+ * Adds an AND logical operator
127
+ */
128
+ and(): this;
129
+ /**
130
+ * Adds an OR logical operator
131
+ */
132
+ or(): this;
133
+ /**
134
+ * Sets the sort field and direction
135
+ * @param field - Field to sort by
136
+ * @param direction - Sort direction ('asc' or 'desc')
137
+ */
138
+ sortBy(field: string, direction?: 'asc' | 'desc'): this;
139
+ /**
140
+ * Sets the maximum number of records to return
141
+ * @param count - Maximum record count
142
+ */
143
+ limit(count: number): this;
144
+ /**
145
+ * Sets the page number for pagination
146
+ * @param page - Page number (1-based)
147
+ */
148
+ page(page: number): this;
149
+ /**
150
+ * Controls whether to show real values (labels) for dropdown fields
151
+ * @param show - Whether to show real values (default: true)
152
+ */
153
+ showRealValue(show: boolean): this;
154
+ /**
155
+ * Builds the query string from conditions
156
+ * @returns The built query string
157
+ */
158
+ build(): string;
159
+ /**
160
+ * Returns the selected fields array
161
+ * Useful for inspecting the query configuration
162
+ */
163
+ getFields(): string[];
164
+ /**
165
+ * Converts the query builder state to a payload compatible with @fireberry/sdk
166
+ *
167
+ * @returns Object with `fields` (comma-separated string) and `query` (filter string)
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * import FireberryClientSDK from '@fireberry/sdk/client';
172
+ * import { QueryBuilder } from 'fireberry-api-client';
173
+ *
174
+ * const sdk = new FireberryClientSDK();
175
+ * await sdk.initializeContext();
176
+ *
177
+ * const payload = new QueryBuilder()
178
+ * .select('accountid', 'accountname')
179
+ * .where('statuscode').equals('1')
180
+ * .toSDKPayload();
181
+ *
182
+ * // Use with SDK
183
+ * const results = await sdk.api.query(1, payload);
184
+ * ```
185
+ */
186
+ toSDKPayload(): {
187
+ fields: string;
188
+ query: string;
189
+ page_size?: number;
190
+ page_number?: number;
191
+ };
192
+ /**
193
+ * Executes the query (requires client to be set)
194
+ * @param signal - Optional AbortSignal for cancellation
195
+ * @returns Query results
196
+ */
197
+ execute(signal?: AbortSignal): Promise<QueryResult>;
198
+ /**
199
+ * Creates a condition builder for the current field
200
+ */
201
+ private createConditionBuilder;
202
+ /**
203
+ * Adds a condition to the query
204
+ */
205
+ private addCondition;
206
+ }
207
+
208
+ /**
209
+ * Field Type System IDs from Fireberry CRM
210
+ * These UUIDs identify different field types in the metadata API
211
+ */
212
+ declare const FIELD_TYPE_IDS: {
213
+ readonly DROPDOWN: "b4919f2e-2996-48e4-a03c-ba39fb64386c";
214
+ readonly LOOKUP: "a8fcdf65-91bc-46fd-82f6-1234758345a1";
215
+ readonly EMAIL: "c713d2f7-8fa9-43c3-8062-f07486eaf567";
216
+ readonly TEXT: "a1e7ed6f-5083-477b-b44c-9943a6181359";
217
+ readonly URL: "c820d32f-44df-4c2a-9c1e-18734e864fd5";
218
+ readonly LONG_TEXT: "80108f9d-1e75-40fa-9fa9-02be4ddc1da1";
219
+ readonly DATETIME: "ce972d02-5013-46d4-9d1d-f09df1ac346a";
220
+ readonly DATE: "83bf530c-e04c-462b-9ffc-a46f750fc072";
221
+ readonly HTML: "ed2ad39d-32fc-4585-8f5b-2e93463f050a";
222
+ readonly TELEPHONE: "3f62f67a-1cee-403a-bec6-aa02a9804edb";
223
+ readonly NUMERIC: "6a34bfe3-fece-4da1-9136-a7b1e5ae3319";
224
+ };
225
+ /**
226
+ * Human-readable mappings for field types
227
+ * Used for display purposes
228
+ */
229
+ declare const FIELD_TYPE_MAPPINGS: Record<string, string>;
230
+
231
+ /**
232
+ * Object Type ID to Primary Key Field Mapping
233
+ * Maps Fireberry object type IDs to their primary key field names
234
+ */
235
+ declare const OBJECT_ID_MAP: Record<number, string>;
236
+ /**
237
+ * Gets the primary key field name for a given object type
238
+ *
239
+ * @param objectTypeId - The numeric object type ID
240
+ * @returns The correct ID field name for the object type
241
+ */
242
+ declare function getObjectIdFieldName(objectTypeId: string | number): string;
243
+
244
+ /**
245
+ * Object Type ID to Name Field Mapping
246
+ * Maps Fireberry object type IDs to their display name field
247
+ */
248
+ declare const OBJECT_NAME_MAP: Record<number, string>;
249
+ /**
250
+ * Gets the display name field for a given object type
251
+ *
252
+ * @param objectTypeId - The numeric object type ID
253
+ * @returns The name field for the object type
254
+ */
255
+ declare function getNameFieldByObjectType(objectTypeId: string | number): string;
256
+
257
+ /**
258
+ * Fields to exclude from queries when using '*' (all fields) for specific object types
259
+ * These fields cause API errors when queried
260
+ */
261
+ declare const EXCLUDED_FIELDS_FOR_STAR_QUERY: Record<string, string[]>;
262
+ /**
263
+ * Checks if a field should be excluded from star queries for a given object type
264
+ *
265
+ * @param objectType - The object type ID
266
+ * @param fieldName - The field name to check
267
+ * @returns True if the field should be excluded
268
+ */
269
+ declare function isExcludedFromStarQuery(objectType: string | number, fieldName: string): boolean;
270
+ /**
271
+ * Gets the list of excluded fields for a given object type
272
+ *
273
+ * @param objectType - The object type ID
274
+ * @returns Array of field names to exclude, or empty array if none
275
+ */
276
+ declare function getExcludedFieldsForStarQuery(objectType: string | number): string[];
277
+
278
+ export { type ConditionBuilder as C, EXCLUDED_FIELDS_FOR_STAR_QUERY as E, FIELD_TYPE_IDS as F, OBJECT_ID_MAP as O, QueryBuilder as Q, FIELD_TYPE_MAPPINGS as a, OBJECT_NAME_MAP as b, getNameFieldByObjectType as c, getExcludedFieldsForStarQuery as d, escapeQueryValue as e, getObjectIdFieldName as g, isExcludedFromStarQuery as i, sanitizeQuery as s };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Converts a field API name to its corresponding label field.
3
+ *
4
+ * Rules:
5
+ * - Special mappings (e.g., objectid → objecttitle)
6
+ * - Fields starting with "pcf" (custom fields): append "name" → pcf_field → pcf_fieldname
7
+ * - Fields ending with "code" (unless excluded): remove "code" → statuscode → status
8
+ * - Fields ending with "id" (unless excluded): replace "id" with "name" → accountid → accountname
9
+ * - All other fields: append "name"
10
+ *
11
+ * @param fieldName - The field API name
12
+ * @param objectType - The object type ID (required for object-specific overrides)
13
+ * @returns The corresponding label field, or empty string if no label field exists
14
+ */
15
+ declare function getLabelFieldForField(fieldName: string, objectType: string | number): string;
16
+
17
+ /**
18
+ * Checks if a field is a dropdown type based on its systemFieldTypeId
19
+ *
20
+ * @param systemFieldTypeId - The system field type ID from metadata
21
+ * @returns True if the field is a dropdown
22
+ */
23
+ declare function isDropdownField(systemFieldTypeId: string): boolean;
24
+ /**
25
+ * Checks if a field is a lookup type based on its systemFieldTypeId
26
+ *
27
+ * @param systemFieldTypeId - The system field type ID from metadata
28
+ * @returns True if the field is a lookup
29
+ */
30
+ declare function isLookupField(systemFieldTypeId: string): boolean;
31
+ /**
32
+ * Checks if a field is a dropdown or lookup type
33
+ *
34
+ * @param systemFieldTypeId - The system field type ID from metadata
35
+ * @returns True if the field is a dropdown or lookup
36
+ */
37
+ declare function isDropdownOrLookupField(systemFieldTypeId: string): boolean;
38
+ /**
39
+ * Checks if a field is a text type
40
+ *
41
+ * @param systemFieldTypeId - The system field type ID from metadata
42
+ * @returns True if the field is a text field
43
+ */
44
+ declare function isTextField(systemFieldTypeId: string): boolean;
45
+ /**
46
+ * Checks if a field is a numeric type
47
+ *
48
+ * @param systemFieldTypeId - The system field type ID from metadata
49
+ * @returns True if the field is a numeric field
50
+ */
51
+ declare function isNumericField(systemFieldTypeId: string): boolean;
52
+ /**
53
+ * Checks if a field is a date type (date or datetime)
54
+ *
55
+ * @param systemFieldTypeId - The system field type ID from metadata
56
+ * @returns True if the field is a date or datetime field
57
+ */
58
+ declare function isDateField(systemFieldTypeId: string): boolean;
59
+ /**
60
+ * Gets the field type name from its system ID
61
+ *
62
+ * @param systemFieldTypeId - The system field type ID from metadata
63
+ * @returns Human-readable field type name, or 'Unknown' if not found
64
+ */
65
+ declare function getFieldTypeName(systemFieldTypeId: string): string;
66
+
67
+ export { isLookupField as a, isDropdownOrLookupField as b, isTextField as c, isNumericField as d, isDateField as e, getFieldTypeName as f, getLabelFieldForField as g, isDropdownField as i };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Converts a field API name to its corresponding label field.
3
+ *
4
+ * Rules:
5
+ * - Special mappings (e.g., objectid → objecttitle)
6
+ * - Fields starting with "pcf" (custom fields): append "name" → pcf_field → pcf_fieldname
7
+ * - Fields ending with "code" (unless excluded): remove "code" → statuscode → status
8
+ * - Fields ending with "id" (unless excluded): replace "id" with "name" → accountid → accountname
9
+ * - All other fields: append "name"
10
+ *
11
+ * @param fieldName - The field API name
12
+ * @param objectType - The object type ID (required for object-specific overrides)
13
+ * @returns The corresponding label field, or empty string if no label field exists
14
+ */
15
+ declare function getLabelFieldForField(fieldName: string, objectType: string | number): string;
16
+
17
+ /**
18
+ * Checks if a field is a dropdown type based on its systemFieldTypeId
19
+ *
20
+ * @param systemFieldTypeId - The system field type ID from metadata
21
+ * @returns True if the field is a dropdown
22
+ */
23
+ declare function isDropdownField(systemFieldTypeId: string): boolean;
24
+ /**
25
+ * Checks if a field is a lookup type based on its systemFieldTypeId
26
+ *
27
+ * @param systemFieldTypeId - The system field type ID from metadata
28
+ * @returns True if the field is a lookup
29
+ */
30
+ declare function isLookupField(systemFieldTypeId: string): boolean;
31
+ /**
32
+ * Checks if a field is a dropdown or lookup type
33
+ *
34
+ * @param systemFieldTypeId - The system field type ID from metadata
35
+ * @returns True if the field is a dropdown or lookup
36
+ */
37
+ declare function isDropdownOrLookupField(systemFieldTypeId: string): boolean;
38
+ /**
39
+ * Checks if a field is a text type
40
+ *
41
+ * @param systemFieldTypeId - The system field type ID from metadata
42
+ * @returns True if the field is a text field
43
+ */
44
+ declare function isTextField(systemFieldTypeId: string): boolean;
45
+ /**
46
+ * Checks if a field is a numeric type
47
+ *
48
+ * @param systemFieldTypeId - The system field type ID from metadata
49
+ * @returns True if the field is a numeric field
50
+ */
51
+ declare function isNumericField(systemFieldTypeId: string): boolean;
52
+ /**
53
+ * Checks if a field is a date type (date or datetime)
54
+ *
55
+ * @param systemFieldTypeId - The system field type ID from metadata
56
+ * @returns True if the field is a date or datetime field
57
+ */
58
+ declare function isDateField(systemFieldTypeId: string): boolean;
59
+ /**
60
+ * Gets the field type name from its system ID
61
+ *
62
+ * @param systemFieldTypeId - The system field type ID from metadata
63
+ * @returns Human-readable field type name, or 'Unknown' if not found
64
+ */
65
+ declare function getFieldTypeName(systemFieldTypeId: string): string;
66
+
67
+ export { isLookupField as a, isDropdownOrLookupField as b, isTextField as c, isNumericField as d, isDateField as e, getFieldTypeName as f, getLabelFieldForField as g, isDropdownField as i };