fireberry-api-client 1.0.0-beta.2 → 1.0.0-beta.2.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/dist/index.d.cts CHANGED
@@ -148,7 +148,14 @@ interface FireberryField {
148
148
  maxLength?: number;
149
149
  /** Precision for number fields */
150
150
  precision?: number;
151
- /** Related object ID for lookup fields */
151
+ /**
152
+ * Related object type ID for lookup fields.
153
+ * Only populated when getFields is called with includeLookupRelations: true
154
+ */
155
+ relatedObjectType?: number;
156
+ /**
157
+ * @deprecated Use `relatedObjectType` instead. This was never populated by the API.
158
+ */
152
159
  relatedObjectId?: string;
153
160
  }
154
161
  /**
@@ -223,16 +230,31 @@ declare class MetadataAPI {
223
230
  * Gets all fields for a specific object type
224
231
  *
225
232
  * @param objectType - The object type ID (e.g., '1' for Account)
226
- * @param signal - Optional AbortSignal for cancellation
233
+ * @param options - Optional settings
234
+ * @param options.includeLookupRelations - If true, fetches related object types for lookup fields (requires additional API call)
235
+ * @param options.signal - Optional AbortSignal for cancellation
227
236
  * @returns List of fields with metadata
228
237
  *
229
238
  * @example
230
239
  * ```typescript
231
240
  * const result = await client.metadata.getFields('1');
232
241
  * console.log(result.fields); // [{ fieldName: 'accountid', label: 'Account ID', ... }, ...]
242
+ *
243
+ * // With lookup relations
244
+ * const result = await client.metadata.getFields('1', { includeLookupRelations: true });
245
+ * console.log(result.fields.find(f => f.fieldName === 'primarycontactid')?.relatedObjectType); // 2
233
246
  * ```
234
247
  */
235
- getFields(objectType: string | number, signal?: AbortSignal): Promise<GetFieldsResult>;
248
+ getFields(objectType: string | number, options?: {
249
+ includeLookupRelations?: boolean;
250
+ signal?: AbortSignal;
251
+ } | AbortSignal): Promise<GetFieldsResult>;
252
+ /**
253
+ * Fetches related object types for lookup fields using the query endpoint.
254
+ * The query endpoint returns Columns metadata with fieldobjecttype even without records.
255
+ * Excludes fields that cause API errors (e.g., deletedby, deletedon).
256
+ */
257
+ private fetchLookupRelations;
236
258
  /**
237
259
  * Gets all possible values for a dropdown field
238
260
  *
package/dist/index.d.ts CHANGED
@@ -148,7 +148,14 @@ interface FireberryField {
148
148
  maxLength?: number;
149
149
  /** Precision for number fields */
150
150
  precision?: number;
151
- /** Related object ID for lookup fields */
151
+ /**
152
+ * Related object type ID for lookup fields.
153
+ * Only populated when getFields is called with includeLookupRelations: true
154
+ */
155
+ relatedObjectType?: number;
156
+ /**
157
+ * @deprecated Use `relatedObjectType` instead. This was never populated by the API.
158
+ */
152
159
  relatedObjectId?: string;
153
160
  }
154
161
  /**
@@ -223,16 +230,31 @@ declare class MetadataAPI {
223
230
  * Gets all fields for a specific object type
224
231
  *
225
232
  * @param objectType - The object type ID (e.g., '1' for Account)
226
- * @param signal - Optional AbortSignal for cancellation
233
+ * @param options - Optional settings
234
+ * @param options.includeLookupRelations - If true, fetches related object types for lookup fields (requires additional API call)
235
+ * @param options.signal - Optional AbortSignal for cancellation
227
236
  * @returns List of fields with metadata
228
237
  *
229
238
  * @example
230
239
  * ```typescript
231
240
  * const result = await client.metadata.getFields('1');
232
241
  * console.log(result.fields); // [{ fieldName: 'accountid', label: 'Account ID', ... }, ...]
242
+ *
243
+ * // With lookup relations
244
+ * const result = await client.metadata.getFields('1', { includeLookupRelations: true });
245
+ * console.log(result.fields.find(f => f.fieldName === 'primarycontactid')?.relatedObjectType); // 2
233
246
  * ```
234
247
  */
235
- getFields(objectType: string | number, signal?: AbortSignal): Promise<GetFieldsResult>;
248
+ getFields(objectType: string | number, options?: {
249
+ includeLookupRelations?: boolean;
250
+ signal?: AbortSignal;
251
+ } | AbortSignal): Promise<GetFieldsResult>;
252
+ /**
253
+ * Fetches related object types for lookup fields using the query endpoint.
254
+ * The query endpoint returns Columns metadata with fieldobjecttype even without records.
255
+ * Excludes fields that cause API errors (e.g., deletedby, deletedon).
256
+ */
257
+ private fetchLookupRelations;
236
258
  /**
237
259
  * Gets all possible values for a dropdown field
238
260
  *
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ var __export = (target, all) => {
12
12
  var excludedFields_exports = {};
13
13
  __export(excludedFields_exports, {
14
14
  EXCLUDED_FIELDS_FOR_STAR_QUERY: () => EXCLUDED_FIELDS_FOR_STAR_QUERY,
15
+ EXCLUDED_LOOKUP_FIELDS: () => EXCLUDED_LOOKUP_FIELDS,
15
16
  getExcludedFieldsForStarQuery: () => getExcludedFieldsForStarQuery,
16
17
  isExcludedFromStarQuery: () => isExcludedFromStarQuery
17
18
  });
@@ -24,7 +25,7 @@ function getExcludedFieldsForStarQuery(objectType) {
24
25
  const objectTypeStr = String(objectType);
25
26
  return EXCLUDED_FIELDS_FOR_STAR_QUERY[objectTypeStr] || [];
26
27
  }
27
- var EXCLUDED_FIELDS_FOR_STAR_QUERY;
28
+ var EXCLUDED_FIELDS_FOR_STAR_QUERY, EXCLUDED_LOOKUP_FIELDS;
28
29
  var init_excludedFields = __esm({
29
30
  "src/constants/excludedFields.ts"() {
30
31
  EXCLUDED_FIELDS_FOR_STAR_QUERY = {
@@ -41,6 +42,7 @@ var init_excludedFields = __esm({
41
42
  "117": ["deletedon", "deletedby"]
42
43
  // Landing Page
43
44
  };
45
+ EXCLUDED_LOOKUP_FIELDS = ["deletedby", "deletedon"];
44
46
  }
45
47
  });
46
48
 
@@ -520,6 +522,13 @@ var FIELD_TYPE_MAPPINGS = {
520
522
  };
521
523
 
522
524
  // src/api/metadata.ts
525
+ init_excludedFields();
526
+ var ENDPOINTS = {
527
+ OBJECTS: "/metadata/records",
528
+ FIELDS: (objectType) => `/metadata/records/${objectType}/fields`,
529
+ FIELD_VALUES: (objectType, fieldName) => `/metadata/records/${objectType}/fields/${fieldName}/values`,
530
+ QUERY: "/api/query"
531
+ };
523
532
  var MetadataAPI = class {
524
533
  constructor(client) {
525
534
  this.client = client;
@@ -543,7 +552,7 @@ var MetadataAPI = class {
543
552
  }
544
553
  const response = await this.client.request({
545
554
  method: "GET",
546
- endpoint: "/metadata/records",
555
+ endpoint: ENDPOINTS.OBJECTS,
547
556
  signal
548
557
  });
549
558
  const result = {
@@ -558,30 +567,55 @@ var MetadataAPI = class {
558
567
  * Gets all fields for a specific object type
559
568
  *
560
569
  * @param objectType - The object type ID (e.g., '1' for Account)
561
- * @param signal - Optional AbortSignal for cancellation
570
+ * @param options - Optional settings
571
+ * @param options.includeLookupRelations - If true, fetches related object types for lookup fields (requires additional API call)
572
+ * @param options.signal - Optional AbortSignal for cancellation
562
573
  * @returns List of fields with metadata
563
574
  *
564
575
  * @example
565
576
  * ```typescript
566
577
  * const result = await client.metadata.getFields('1');
567
578
  * console.log(result.fields); // [{ fieldName: 'accountid', label: 'Account ID', ... }, ...]
579
+ *
580
+ * // With lookup relations
581
+ * const result = await client.metadata.getFields('1', { includeLookupRelations: true });
582
+ * console.log(result.fields.find(f => f.fieldName === 'primarycontactid')?.relatedObjectType); // 2
568
583
  * ```
569
584
  */
570
- async getFields(objectType, signal) {
585
+ async getFields(objectType, options) {
571
586
  const objectTypeStr = String(objectType);
572
- const cached = this.client.getCached("fields", objectTypeStr);
573
- if (cached) {
574
- return cached;
587
+ const opts = options instanceof AbortSignal ? { signal: options, includeLookupRelations: false } : { signal: options?.signal, includeLookupRelations: options?.includeLookupRelations };
588
+ if (!opts.includeLookupRelations) {
589
+ const cached = this.client.getCached("fields", objectTypeStr);
590
+ if (cached) {
591
+ return cached;
592
+ }
575
593
  }
576
594
  const response = await this.client.request({
577
595
  method: "GET",
578
- endpoint: `/metadata/records/${objectTypeStr}/fields`,
579
- signal
596
+ endpoint: ENDPOINTS.FIELDS(objectTypeStr),
597
+ signal: opts.signal
580
598
  });
581
- const fields = (response.data || []).map((field) => ({
599
+ let fields = (response.data || []).map((field) => ({
582
600
  ...field,
583
601
  fieldType: FIELD_TYPE_MAPPINGS[field.systemFieldTypeId] || field.systemFieldTypeId
584
602
  }));
603
+ if (opts.includeLookupRelations) {
604
+ const lookupFields = fields.filter(
605
+ (field) => field.systemFieldTypeId === FIELD_TYPE_IDS.LOOKUP
606
+ );
607
+ if (lookupFields.length > 0) {
608
+ const lookupRelations = await this.fetchLookupRelations(
609
+ objectTypeStr,
610
+ lookupFields.map((f) => f.fieldName),
611
+ opts.signal
612
+ );
613
+ fields = fields.map((field) => ({
614
+ ...field,
615
+ relatedObjectType: lookupRelations.get(field.fieldName)
616
+ }));
617
+ }
618
+ }
585
619
  const result = {
586
620
  objectTypeId: objectTypeStr,
587
621
  fields,
@@ -591,6 +625,40 @@ var MetadataAPI = class {
591
625
  this.client.setCache("fields", objectTypeStr, result);
592
626
  return result;
593
627
  }
628
+ /**
629
+ * Fetches related object types for lookup fields using the query endpoint.
630
+ * The query endpoint returns Columns metadata with fieldobjecttype even without records.
631
+ * Excludes fields that cause API errors (e.g., deletedby, deletedon).
632
+ */
633
+ async fetchLookupRelations(objectType, lookupFieldNames, signal) {
634
+ const relations = /* @__PURE__ */ new Map();
635
+ const queryableFields = lookupFieldNames.filter(
636
+ (fieldName) => !EXCLUDED_LOOKUP_FIELDS.includes(fieldName)
637
+ );
638
+ if (queryableFields.length === 0) {
639
+ return relations;
640
+ }
641
+ const response = await this.client.request({
642
+ method: "POST",
643
+ endpoint: ENDPOINTS.QUERY,
644
+ body: {
645
+ objecttype: objectType,
646
+ fields: queryableFields.join(","),
647
+ query: "",
648
+ page_size: 1,
649
+ page_number: 1,
650
+ show_real_value: 0
651
+ },
652
+ signal
653
+ });
654
+ const columns = response.data?.Columns || [];
655
+ for (const column of columns) {
656
+ if (column.fieldobjecttype !== null && column.fieldobjecttype !== void 0) {
657
+ relations.set(column.fieldname, column.fieldobjecttype);
658
+ }
659
+ }
660
+ return relations;
661
+ }
594
662
  /**
595
663
  * Gets all possible values for a dropdown field
596
664
  *
@@ -617,7 +685,7 @@ var MetadataAPI = class {
617
685
  }
618
686
  const response = await this.client.request({
619
687
  method: "GET",
620
- endpoint: `/metadata/records/${objectTypeStr}/fields/${fieldName}/values`,
688
+ endpoint: ENDPOINTS.FIELD_VALUES(objectTypeStr, fieldName),
621
689
  signal
622
690
  });
623
691
  const result = {