fireberry-api-client 1.0.2-beta.1.0 → 1.0.2-beta.1.2

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 CHANGED
@@ -7,6 +7,7 @@ A standalone, framework-agnostic TypeScript/JavaScript client for the Fireberry
7
7
  - Full TypeScript support with comprehensive type definitions
8
8
  - Zero runtime dependencies (uses native `fetch`)
9
9
  - Supports both ESM and CommonJS
10
+ - **SDK integration** - works with `@fireberry/sdk` for iframe-based plugins and widgets
10
11
  - Automatic retry on rate limits (429)
11
12
  - Optional metadata and query result caching
12
13
  - Smart cache invalidation on mutations (auto-clears query cache when records are modified)
@@ -32,18 +33,20 @@ npm install fireberry-api-client@latest
32
33
  ### Import Paths
33
34
 
34
35
  ```typescript
35
- // Main export
36
+ // Main export (supports both API and SDK modes)
36
37
  import { FireberryClient } from 'fireberry-api-client';
37
38
 
38
39
  // Utilities export
39
40
  import { getObjectIdFieldName } from 'fireberry-api-client/utils';
40
41
 
41
- // SDK adapter
42
- import { createSDKQueryBuilder } from 'fireberry-api-client/sdk';
42
+ // SDK utilities (for standalone SDK usage)
43
+ import { createSDKQueryBuilder, EnhancedSDK } from 'fireberry-api-client/sdk';
43
44
  ```
44
45
 
45
46
  ## Quick Start
46
47
 
48
+ ### With API Key (Node.js / External API)
49
+
47
50
  ```typescript
48
51
  import { FireberryClient } from 'fireberry-api-client';
49
52
 
@@ -61,18 +64,45 @@ const accounts = await client.query({
61
64
  console.log(accounts.records);
62
65
  ```
63
66
 
67
+ ### With SDK (Fireberry Plugins / Widgets)
68
+
69
+ ```typescript
70
+ import FireberryClientSDK from '@fireberry/sdk/client';
71
+ import { FireberryClient } from 'fireberry-api-client';
72
+
73
+ // Initialize SDK
74
+ const sdk = new FireberryClientSDK();
75
+ await sdk.initializeContext();
76
+
77
+ // Create client with SDK
78
+ const client = new FireberryClient({ sdk });
79
+
80
+ // Use all client features (CRUD via SDK messaging)
81
+ const accounts = await client.queryBuilder()
82
+ .objectType(1)
83
+ .select('accountid', 'accountname')
84
+ .where('statuscode').equals('1')
85
+ .execute();
86
+ ```
87
+
64
88
  ## API Reference
65
89
 
66
90
  ### Client Configuration
67
91
 
68
92
  ```typescript
69
93
  const client = new FireberryClient({
70
- apiKey: 'your-api-key', // Required
94
+ // Authentication (at least one required)
95
+ apiKey: 'your-api-key', // Optional, API key for HTTP API mode
96
+ sdk: sdkInstance, // Optional, SDK instance for iframe mode
97
+
98
+ // HTTP Options (API mode only)
71
99
  baseUrl: 'https://api.fireberry.com', // Optional, default shown
72
100
  timeout: 30000, // Optional, request timeout in ms
73
101
  retryOn429: true, // Optional, auto-retry on rate limit
74
102
  maxRetries: 120, // Optional, max retry attempts
75
103
  retryDelay: 1000, // Optional, delay between retries in ms
104
+
105
+ // Caching Options
76
106
  cacheMetadata: false, // Optional, enable metadata caching
77
107
  cacheTTL: 300000, // Optional, metadata cache TTL in ms (5 min default)
78
108
  cacheQueryResults: false, // Optional, enable query result caching
@@ -81,6 +111,12 @@ const client = new FireberryClient({
81
111
  });
82
112
  ```
83
113
 
114
+ **Initialization Modes:**
115
+
116
+ - **API-only mode**: Pass only `apiKey` - all operations use HTTP API
117
+ - **SDK-only mode**: Pass only `sdk` - CRUD via iframe messaging (no metadata support)
118
+ - **Hybrid mode**: Pass both `apiKey` and `sdk` - CRUD via SDK, metadata via API
119
+
84
120
  ### Query Records
85
121
 
86
122
  ```typescript
@@ -484,24 +520,75 @@ const promise = client.query({
484
520
  controller.abort();
485
521
  ```
486
522
 
487
- ## SDK Adapter (for @fireberry/sdk)
523
+ ## SDK Integration (for @fireberry/sdk)
488
524
 
489
- If you're building embedded Fireberry widgets/plugins using `@fireberry/sdk`, you can use this library's utilities with the SDK adapter:
525
+ If you're building embedded Fireberry widgets/plugins using `@fireberry/sdk`, you can integrate it with this library in two ways:
526
+
527
+ ### Option 1: Direct SDK Integration with FireberryClient (Recommended)
528
+
529
+ Pass the SDK instance directly to FireberryClient for seamless integration with all client features:
490
530
 
491
531
  ```typescript
492
532
  import FireberryClientSDK from '@fireberry/sdk/client';
493
- import { createSDKQueryBuilder, EnhancedSDK } from 'fireberry-api-client/sdk';
533
+ import { FireberryClient } from 'fireberry-api-client';
494
534
 
495
535
  // Initialize Fireberry SDK (runs in iframe)
496
536
  const sdk = new FireberryClientSDK();
497
537
  await sdk.initializeContext();
538
+
539
+ // Create client with SDK (CRUD via SDK, metadata requires apiKey)
540
+ const client = new FireberryClient({
541
+ sdk: sdk,
542
+ // Optional: Add apiKey for metadata operations
543
+ // apiKey: 'your-api-key',
544
+ });
545
+
546
+ // Use all regular client features
547
+ const accounts = await client.queryBuilder()
548
+ .objectType(1)
549
+ .select('accountid', 'accountname')
550
+ .where('statuscode').equals('1')
551
+ .execute();
552
+
553
+ // CRUD operations work through SDK
554
+ await client.records.create(1, { accountname: 'New Account' });
498
555
  ```
499
556
 
500
- ### Option 1: Query Builder Factory
557
+ **Three initialization modes:**
501
558
 
559
+ 1. **SDK-only mode** - CRUD operations only (no metadata):
502
560
  ```typescript
561
+ const client = new FireberryClient({ sdk });
562
+ ```
563
+
564
+ 2. **Hybrid mode** - SDK for CRUD, API for metadata (recommended):
565
+ ```typescript
566
+ const client = new FireberryClient({
567
+ sdk,
568
+ apiKey: 'your-api-key',
569
+ });
570
+ ```
571
+
572
+ 3. **API-only mode** - Traditional HTTP API:
573
+ ```typescript
574
+ const client = new FireberryClient({
575
+ apiKey: 'your-api-key',
576
+ });
577
+ ```
578
+
579
+ ### Option 2: Standalone SDK Utilities
580
+
581
+ Use SDK-specific utilities from the `/sdk` export for more granular control:
582
+
583
+ #### 2a. Query Builder Factory
584
+
585
+ ```typescript
586
+ import FireberryClientSDK from '@fireberry/sdk/client';
503
587
  import { createSDKQueryBuilder } from 'fireberry-api-client/sdk';
504
588
 
589
+ const sdk = new FireberryClientSDK();
590
+ await sdk.initializeContext();
591
+
505
592
  const queryBuilder = createSDKQueryBuilder(sdk);
506
593
 
507
594
  // Build and execute queries with fluent API
@@ -513,7 +600,7 @@ const results = await queryBuilder(1) // 1 = Account
513
600
  .execute();
514
601
  ```
515
602
 
516
- ### Option 2: Enhanced SDK Wrapper
603
+ #### 2b. Enhanced SDK Wrapper
517
604
 
518
605
  ```typescript
519
606
  import { EnhancedSDK } from 'fireberry-api-client/sdk';
@@ -546,7 +633,7 @@ await enhanced.update(1, 'record-id', { accountname: 'Updated' });
546
633
  await enhanced.delete(1, 'record-id');
547
634
  ```
548
635
 
549
- ### Option 3: Use QueryBuilder Directly
636
+ #### 2c. Use QueryBuilder Directly
550
637
 
551
638
  ```typescript
552
639
  import { QueryBuilder } from 'fireberry-api-client';
@@ -1,3 +1,97 @@
1
+ /**
2
+ * Type definitions for @fireberry/sdk compatibility
3
+ * These types mirror the Fireberry SDK's API for seamless integration
4
+ */
5
+ /**
6
+ * Query payload expected by the Fireberry SDK
7
+ */
8
+ interface SDKQueryPayload {
9
+ /** Comma-separated field names to return */
10
+ fields: string;
11
+ /** Query filter string */
12
+ query: string;
13
+ /** Number of records per page */
14
+ page_size?: number;
15
+ /** Page number (1-based) */
16
+ page_number?: number;
17
+ }
18
+ /**
19
+ * Response error from SDK
20
+ */
21
+ interface SDKResponseError {
22
+ data: Record<string, unknown> & {
23
+ Message?: string;
24
+ };
25
+ status: number;
26
+ statusText: string;
27
+ }
28
+ /**
29
+ * Response data from SDK operations
30
+ */
31
+ interface SDKResponseData<T = Record<string, unknown>> {
32
+ type?: string;
33
+ success: boolean;
34
+ data: T & {
35
+ requestId?: string;
36
+ };
37
+ error?: SDKResponseError;
38
+ isParentReady: boolean;
39
+ requestId: string;
40
+ }
41
+ /**
42
+ * Record details from SDK context
43
+ */
44
+ interface SDKRecordDetails {
45
+ type?: number;
46
+ id?: string;
47
+ }
48
+ /**
49
+ * User details from SDK context
50
+ */
51
+ interface SDKUserDetails {
52
+ fullName?: string;
53
+ id?: string;
54
+ }
55
+ /**
56
+ * SDK context information
57
+ */
58
+ interface SDKContext {
59
+ user: SDKUserDetails;
60
+ record: SDKRecordDetails;
61
+ }
62
+ /**
63
+ * Generic payload type for create/update operations
64
+ */
65
+ type SDKPayload = Record<string, unknown>;
66
+ /**
67
+ * Fireberry SDK API interface
68
+ * Matches the API surface of @fireberry/sdk
69
+ */
70
+ interface FireberrySDKAPI<TData = Record<string, unknown>> {
71
+ /** Query records with filtering and pagination */
72
+ query: (objectType: string | number, payload: SDKQueryPayload) => Promise<SDKResponseData<TData>>;
73
+ /** Create a new record */
74
+ create: <T extends SDKPayload>(objectType: string | number, payload: T) => Promise<SDKResponseData<TData>>;
75
+ /** Delete a record by ID */
76
+ delete: (objectType: string | number, recordId: string) => Promise<SDKResponseData<TData>>;
77
+ /** Update an existing record */
78
+ update: <T extends SDKPayload>(objectType: string | number, recordId: string, payload: T) => Promise<SDKResponseData<TData>>;
79
+ }
80
+ /**
81
+ * Fireberry SDK Client interface
82
+ * Matches the structure of FireberryClientSDK from @fireberry/sdk
83
+ */
84
+ interface FireberrySDKClient<TData = Record<string, unknown>> {
85
+ /** Access to CRUD API methods */
86
+ readonly api: FireberrySDKAPI<TData>;
87
+ /** Current context (record and user info) - null if not initialized */
88
+ readonly context: SDKContext | null;
89
+ /** Initialize context from parent Fireberry window */
90
+ initializeContext(): Promise<FireberrySDKClient<TData>>;
91
+ /** Clean up event listeners and pending requests */
92
+ destroy(): void;
93
+ }
94
+
1
95
  /**
2
96
  * Options for query operations
3
97
  */
@@ -641,4 +735,4 @@ declare function isExcludedFromStarQuery(objectType: string | number, fieldName:
641
735
  */
642
736
  declare function getExcludedFieldsForStarQuery(objectType: string | number): string[];
643
737
 
644
- export { type ConditionBuilder as C, type DateConditionBuilder as D, EXCLUDED_FIELDS_FOR_STAR_QUERY as E, FIELD_TYPE_IDS as F, OBJECT_ID_MAP as O, QueryBuilder as Q, type QueryOptions as a, type QueryResult$1 as b, type QueryConditionItem as c, type QuerySeparatorItem as d, escapeQueryValue as e, type QueryItem as f, type QueryOperator as g, type QueryExplainResult as h, FIELD_TYPE_MAPPINGS as i, OBJECT_NAME_MAP as j, getObjectIdFieldName as k, getNameFieldByObjectType as l, isPureDate as m, addDays as n, getToday as o, getStartOfWeek as p, getStartOfMonth as q, isExcludedFromStarQuery as r, sanitizeQuery as s, getExcludedFieldsForStarQuery as t };
738
+ export { type ConditionBuilder as C, type DateConditionBuilder as D, EXCLUDED_FIELDS_FOR_STAR_QUERY as E, type FireberrySDKClient as F, OBJECT_ID_MAP as O, QueryBuilder as Q, type SDKQueryPayload as S, type QueryOptions as a, type QueryResult$1 as b, type QueryConditionItem as c, type QuerySeparatorItem as d, escapeQueryValue as e, type QueryItem as f, type QueryOperator as g, type QueryExplainResult as h, type FireberrySDKAPI as i, type SDKResponseData as j, type SDKContext as k, FIELD_TYPE_IDS as l, FIELD_TYPE_MAPPINGS as m, OBJECT_NAME_MAP as n, getObjectIdFieldName as o, getNameFieldByObjectType as p, isPureDate as q, addDays as r, sanitizeQuery as s, getToday as t, getStartOfWeek as u, getStartOfMonth as v, isExcludedFromStarQuery as w, getExcludedFieldsForStarQuery as x };
@@ -1,3 +1,97 @@
1
+ /**
2
+ * Type definitions for @fireberry/sdk compatibility
3
+ * These types mirror the Fireberry SDK's API for seamless integration
4
+ */
5
+ /**
6
+ * Query payload expected by the Fireberry SDK
7
+ */
8
+ interface SDKQueryPayload {
9
+ /** Comma-separated field names to return */
10
+ fields: string;
11
+ /** Query filter string */
12
+ query: string;
13
+ /** Number of records per page */
14
+ page_size?: number;
15
+ /** Page number (1-based) */
16
+ page_number?: number;
17
+ }
18
+ /**
19
+ * Response error from SDK
20
+ */
21
+ interface SDKResponseError {
22
+ data: Record<string, unknown> & {
23
+ Message?: string;
24
+ };
25
+ status: number;
26
+ statusText: string;
27
+ }
28
+ /**
29
+ * Response data from SDK operations
30
+ */
31
+ interface SDKResponseData<T = Record<string, unknown>> {
32
+ type?: string;
33
+ success: boolean;
34
+ data: T & {
35
+ requestId?: string;
36
+ };
37
+ error?: SDKResponseError;
38
+ isParentReady: boolean;
39
+ requestId: string;
40
+ }
41
+ /**
42
+ * Record details from SDK context
43
+ */
44
+ interface SDKRecordDetails {
45
+ type?: number;
46
+ id?: string;
47
+ }
48
+ /**
49
+ * User details from SDK context
50
+ */
51
+ interface SDKUserDetails {
52
+ fullName?: string;
53
+ id?: string;
54
+ }
55
+ /**
56
+ * SDK context information
57
+ */
58
+ interface SDKContext {
59
+ user: SDKUserDetails;
60
+ record: SDKRecordDetails;
61
+ }
62
+ /**
63
+ * Generic payload type for create/update operations
64
+ */
65
+ type SDKPayload = Record<string, unknown>;
66
+ /**
67
+ * Fireberry SDK API interface
68
+ * Matches the API surface of @fireberry/sdk
69
+ */
70
+ interface FireberrySDKAPI<TData = Record<string, unknown>> {
71
+ /** Query records with filtering and pagination */
72
+ query: (objectType: string | number, payload: SDKQueryPayload) => Promise<SDKResponseData<TData>>;
73
+ /** Create a new record */
74
+ create: <T extends SDKPayload>(objectType: string | number, payload: T) => Promise<SDKResponseData<TData>>;
75
+ /** Delete a record by ID */
76
+ delete: (objectType: string | number, recordId: string) => Promise<SDKResponseData<TData>>;
77
+ /** Update an existing record */
78
+ update: <T extends SDKPayload>(objectType: string | number, recordId: string, payload: T) => Promise<SDKResponseData<TData>>;
79
+ }
80
+ /**
81
+ * Fireberry SDK Client interface
82
+ * Matches the structure of FireberryClientSDK from @fireberry/sdk
83
+ */
84
+ interface FireberrySDKClient<TData = Record<string, unknown>> {
85
+ /** Access to CRUD API methods */
86
+ readonly api: FireberrySDKAPI<TData>;
87
+ /** Current context (record and user info) - null if not initialized */
88
+ readonly context: SDKContext | null;
89
+ /** Initialize context from parent Fireberry window */
90
+ initializeContext(): Promise<FireberrySDKClient<TData>>;
91
+ /** Clean up event listeners and pending requests */
92
+ destroy(): void;
93
+ }
94
+
1
95
  /**
2
96
  * Options for query operations
3
97
  */
@@ -641,4 +735,4 @@ declare function isExcludedFromStarQuery(objectType: string | number, fieldName:
641
735
  */
642
736
  declare function getExcludedFieldsForStarQuery(objectType: string | number): string[];
643
737
 
644
- export { type ConditionBuilder as C, type DateConditionBuilder as D, EXCLUDED_FIELDS_FOR_STAR_QUERY as E, FIELD_TYPE_IDS as F, OBJECT_ID_MAP as O, QueryBuilder as Q, type QueryOptions as a, type QueryResult$1 as b, type QueryConditionItem as c, type QuerySeparatorItem as d, escapeQueryValue as e, type QueryItem as f, type QueryOperator as g, type QueryExplainResult as h, FIELD_TYPE_MAPPINGS as i, OBJECT_NAME_MAP as j, getObjectIdFieldName as k, getNameFieldByObjectType as l, isPureDate as m, addDays as n, getToday as o, getStartOfWeek as p, getStartOfMonth as q, isExcludedFromStarQuery as r, sanitizeQuery as s, getExcludedFieldsForStarQuery as t };
738
+ export { type ConditionBuilder as C, type DateConditionBuilder as D, EXCLUDED_FIELDS_FOR_STAR_QUERY as E, type FireberrySDKClient as F, OBJECT_ID_MAP as O, QueryBuilder as Q, type SDKQueryPayload as S, type QueryOptions as a, type QueryResult$1 as b, type QueryConditionItem as c, type QuerySeparatorItem as d, escapeQueryValue as e, type QueryItem as f, type QueryOperator as g, type QueryExplainResult as h, type FireberrySDKAPI as i, type SDKResponseData as j, type SDKContext as k, FIELD_TYPE_IDS as l, FIELD_TYPE_MAPPINGS as m, OBJECT_NAME_MAP as n, getObjectIdFieldName as o, getNameFieldByObjectType as p, isPureDate as q, addDays as r, sanitizeQuery as s, getToday as t, getStartOfWeek as u, getStartOfMonth as v, isExcludedFromStarQuery as w, getExcludedFieldsForStarQuery as x };