@getclarify/nodejs-sdk 0.0.1 → 0.0.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 +104 -0
- package/dist/cjs/client.d.ts +0 -6
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +0 -8
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/http/http-client.d.ts.map +1 -1
- package/dist/cjs/http/http-client.js +2 -2
- package/dist/cjs/http/http-client.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources/base-resource.js +1 -1
- package/dist/cjs/resources/base-resource.js.map +1 -1
- package/dist/cjs/resources/records.d.ts +65 -90
- package/dist/cjs/resources/records.d.ts.map +1 -1
- package/dist/cjs/resources/records.js +111 -165
- package/dist/cjs/resources/records.js.map +1 -1
- package/dist/cjs/types/common.d.ts +28 -0
- package/dist/cjs/types/common.d.ts.map +1 -1
- package/dist/cjs/types/config.d.ts +4 -4
- package/dist/cjs/types/config.d.ts.map +1 -1
- package/dist/cjs/types/config.js +2 -2
- package/dist/cjs/types/config.js.map +1 -1
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/esm/client.d.ts +0 -6
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +0 -8
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/http/http-client.d.ts.map +1 -1
- package/dist/esm/http/http-client.js +2 -2
- package/dist/esm/http/http-client.js.map +1 -1
- package/dist/esm/index.d.ts +1 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/base-resource.js +1 -1
- package/dist/esm/resources/base-resource.js.map +1 -1
- package/dist/esm/resources/records.d.ts +65 -90
- package/dist/esm/resources/records.d.ts.map +1 -1
- package/dist/esm/resources/records.js +111 -165
- package/dist/esm/resources/records.js.map +1 -1
- package/dist/esm/types/common.d.ts +28 -0
- package/dist/esm/types/common.d.ts.map +1 -1
- package/dist/esm/types/config.d.ts +4 -4
- package/dist/esm/types/config.d.ts.map +1 -1
- package/dist/esm/types/config.js +2 -2
- package/dist/esm/types/config.js.map +1 -1
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/types/client.d.ts +0 -6
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/http/http-client.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resources/records.d.ts +65 -90
- package/dist/types/resources/records.d.ts.map +1 -1
- package/dist/types/types/common.d.ts +28 -0
- package/dist/types/types/common.d.ts.map +1 -1
- package/dist/types/types/config.d.ts +4 -4
- package/dist/types/types/config.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RecordsResource = exports.ClarifyNetworkError = exports.ClarifyTimeoutError = exports.ClarifyValidationError = exports.ClarifyApiError = exports.ClarifyError = exports.ClarifyClient = void 0;
|
|
4
4
|
// Main client export
|
|
5
5
|
var client_js_1 = require("./client.js");
|
|
6
6
|
Object.defineProperty(exports, "ClarifyClient", { enumerable: true, get: function () { return client_js_1.ClarifyClient; } });
|
|
@@ -14,12 +14,4 @@ Object.defineProperty(exports, "ClarifyNetworkError", { enumerable: true, get: f
|
|
|
14
14
|
// Resource exports for advanced usage
|
|
15
15
|
var records_js_1 = require("./resources/records.js");
|
|
16
16
|
Object.defineProperty(exports, "RecordsResource", { enumerable: true, get: function () { return records_js_1.RecordsResource; } });
|
|
17
|
-
var relationships_js_1 = require("./resources/relationships.js");
|
|
18
|
-
Object.defineProperty(exports, "RelationshipsResource", { enumerable: true, get: function () { return relationships_js_1.RelationshipsResource; } });
|
|
19
|
-
var messages_js_1 = require("./resources/messages.js");
|
|
20
|
-
Object.defineProperty(exports, "MessagesResource", { enumerable: true, get: function () { return messages_js_1.MessagesResource; } });
|
|
21
|
-
var tasks_js_1 = require("./resources/tasks.js");
|
|
22
|
-
Object.defineProperty(exports, "TasksResource", { enumerable: true, get: function () { return tasks_js_1.TasksResource; } });
|
|
23
|
-
Object.defineProperty(exports, "TaskStatus", { enumerable: true, get: function () { return tasks_js_1.TaskStatus; } });
|
|
24
|
-
Object.defineProperty(exports, "TaskPriority", { enumerable: true, get: function () { return tasks_js_1.TaskPriority; } });
|
|
25
17
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qBAAqB;AACrB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAEtB,gBAAgB;AAChB,8CAM2B;AALzB,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,kHAAA,sBAAsB,OAAA;AACtB,+GAAA,mBAAmB,OAAA;AACnB,+GAAA,mBAAmB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qBAAqB;AACrB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAEtB,gBAAgB;AAChB,8CAM2B;AALzB,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AACf,kHAAA,sBAAsB,OAAA;AACtB,+GAAA,mBAAmB,OAAA;AACnB,+GAAA,mBAAmB,OAAA;AAwBrB,sCAAsC;AACtC,qDAAyD;AAAhD,6GAAA,eAAe,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-resource.js","sourceRoot":"","sources":["../../../src/resources/base-resource.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAsB,YAAY;IACb,UAAU,CAAa;IACvB,MAAM,CAAiB;IAE1C,YAAY,UAAsB,EAAE,MAAsB;QACxD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAc,QAAQ;QACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"base-resource.js","sourceRoot":"","sources":["../../../src/resources/base-resource.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAsB,YAAY;IACb,UAAU,CAAa;IACvB,MAAM,CAAiB;IAE1C,YAAY,UAAsB,EAAE,MAAsB;QACxD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAc,QAAQ;QACpB,OAAO,kBAAkB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACnD,CAAC;CACF;AAfD,oCAeC"}
|
|
@@ -1,157 +1,132 @@
|
|
|
1
1
|
import type { HttpClient } from '../http/http-client.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GetRecordOptions, ListResponse, ResolvedConfig, ResourceCreate, ResourceUpdate, SingleResponse, UpdateRecordOptions } from '../types/index.js';
|
|
3
3
|
import { BaseResource } from './base-resource.js';
|
|
4
|
-
import { RelationshipsResource } from './relationships.js';
|
|
5
4
|
/**
|
|
6
5
|
* Manages CRUD operations for records.
|
|
7
6
|
*/
|
|
8
7
|
export declare class RecordsResource extends BaseResource {
|
|
9
|
-
/** Sub-resource for managing record relationships */
|
|
10
|
-
readonly relationships: RelationshipsResource;
|
|
11
8
|
constructor(httpClient: HttpClient, config: ResolvedConfig);
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
16
|
-
* @param options - Pagination, filter, and sort options
|
|
17
|
-
* @returns Paginated list of records
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const companies = await clarify.records.list('company', {
|
|
22
|
-
* page: { limit: 20 },
|
|
23
|
-
* filter: { industry: 'technology' },
|
|
24
|
-
* sort: { field: 'name', direction: 'asc' },
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
10
|
+
* Gets the base path for record operations on a specific entity.
|
|
27
11
|
*/
|
|
28
|
-
|
|
12
|
+
private getEntityPath;
|
|
29
13
|
/**
|
|
30
|
-
*
|
|
14
|
+
* Retrieves a single record by ID.
|
|
31
15
|
*
|
|
32
|
-
* @param entity - The entity type
|
|
16
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
33
17
|
* @param id - The record ID
|
|
34
|
-
* @
|
|
18
|
+
* @param options - Optional parameters including relationships to include
|
|
19
|
+
* @returns The record wrapped in a JSON:API response
|
|
35
20
|
*
|
|
36
21
|
* @example
|
|
37
22
|
* ```typescript
|
|
38
|
-
* const
|
|
39
|
-
* console.log(
|
|
23
|
+
* const response = await client.records.get('company', 'abc123');
|
|
24
|
+
* console.log(response.data.attributes.name);
|
|
25
|
+
*
|
|
26
|
+
* // With included relationships
|
|
27
|
+
* const response = await client.records.get('deal', 'xyz789', {
|
|
28
|
+
* include: ['company', 'person']
|
|
29
|
+
* });
|
|
40
30
|
* ```
|
|
41
31
|
*/
|
|
42
|
-
get<T = Record<string, unknown>>(entity: string, id: string): Promise<SingleResponse<T>>;
|
|
32
|
+
get<T = Record<string, unknown>>(entity: string, id: string, options?: GetRecordOptions): Promise<SingleResponse<T>>;
|
|
43
33
|
/**
|
|
44
|
-
* Creates a
|
|
34
|
+
* Creates a single record.
|
|
45
35
|
*
|
|
46
|
-
* @param entity - The entity type
|
|
47
|
-
* @param
|
|
48
|
-
* @returns The created record
|
|
36
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
37
|
+
* @param attributes - The record attributes to create
|
|
38
|
+
* @returns The created record wrapped in a JSON:API response
|
|
49
39
|
*
|
|
50
40
|
* @example
|
|
51
41
|
* ```typescript
|
|
52
|
-
* const
|
|
53
|
-
*
|
|
54
|
-
*
|
|
42
|
+
* const response = await client.records.create('company', {
|
|
43
|
+
* name: 'Acme Corp',
|
|
44
|
+
* website: 'https://acme.com'
|
|
55
45
|
* });
|
|
46
|
+
* console.log(response.data.id);
|
|
56
47
|
* ```
|
|
57
48
|
*/
|
|
58
|
-
create<T = Record<string, unknown>>(entity: string,
|
|
49
|
+
create<T = Record<string, unknown>>(entity: string, attributes: T): Promise<SingleResponse<T>>;
|
|
59
50
|
/**
|
|
60
|
-
*
|
|
51
|
+
* Creates multiple records in bulk.
|
|
61
52
|
*
|
|
62
|
-
* @param entity - The entity type
|
|
63
|
-
* @param
|
|
64
|
-
* @
|
|
65
|
-
* @returns The updated record
|
|
53
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
54
|
+
* @param records - Array of record create objects with type and attributes
|
|
55
|
+
* @returns The created records wrapped in a JSON:API list response
|
|
66
56
|
*
|
|
67
57
|
* @example
|
|
68
58
|
* ```typescript
|
|
69
|
-
* const
|
|
70
|
-
* type: 'company',
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
59
|
+
* const response = await client.records.createBulk('company', [
|
|
60
|
+
* { type: 'company', attributes: { name: 'Acme Corp' } },
|
|
61
|
+
* { type: 'company', attributes: { name: 'Widget Inc' } }
|
|
62
|
+
* ]);
|
|
63
|
+
* console.log(response.data.length);
|
|
74
64
|
* ```
|
|
75
65
|
*/
|
|
76
|
-
|
|
66
|
+
createBulk<T = Record<string, unknown>>(entity: string, records: ResourceCreate<T>[]): Promise<ListResponse<T>>;
|
|
77
67
|
/**
|
|
78
|
-
*
|
|
68
|
+
* Updates a single record.
|
|
79
69
|
*
|
|
80
|
-
* @param entity - The entity type
|
|
70
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
81
71
|
* @param id - The record ID
|
|
72
|
+
* @param attributes - The attributes to update
|
|
73
|
+
* @param options - Optional update options including field operation rules
|
|
74
|
+
* @returns The updated record wrapped in a JSON:API response
|
|
82
75
|
*
|
|
83
76
|
* @example
|
|
84
77
|
* ```typescript
|
|
85
|
-
* await
|
|
78
|
+
* const response = await client.records.update('company', 'abc123', {
|
|
79
|
+
* name: 'Acme Corporation'
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // With field operation rules (e.g., append to array field)
|
|
83
|
+
* const response = await client.records.update('deal', 'xyz789',
|
|
84
|
+
* { tags: ['new-tag'] },
|
|
85
|
+
* { meta: { tags: { array: 'append' } } }
|
|
86
|
+
* );
|
|
86
87
|
* ```
|
|
87
88
|
*/
|
|
88
|
-
|
|
89
|
+
update<T = Record<string, unknown>>(entity: string, id: string, attributes: Partial<T>, options?: UpdateRecordOptions): Promise<SingleResponse<T>>;
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
+
* Updates multiple records in bulk.
|
|
91
92
|
*
|
|
92
|
-
* @param entity - The entity type
|
|
93
|
-
* @param
|
|
94
|
-
* @
|
|
93
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
94
|
+
* @param records - Array of record update objects with type, id, and attributes
|
|
95
|
+
* @param options - Optional update options including field operation rules
|
|
96
|
+
* @returns The updated records wrapped in a JSON:API list response
|
|
95
97
|
*
|
|
96
98
|
* @example
|
|
97
99
|
* ```typescript
|
|
98
|
-
* const
|
|
99
|
-
* { type: 'company', attributes: {
|
|
100
|
-
* { type: 'company', attributes: {
|
|
100
|
+
* const response = await client.records.updateBulk('company', [
|
|
101
|
+
* { type: 'company', id: 'abc123', attributes: { status: 'active' } },
|
|
102
|
+
* { type: 'company', id: 'def456', attributes: { status: 'active' } }
|
|
101
103
|
* ]);
|
|
102
104
|
* ```
|
|
103
105
|
*/
|
|
104
|
-
|
|
106
|
+
updateBulk<T = Record<string, unknown>>(entity: string, records: ResourceUpdate<T>[], options?: UpdateRecordOptions): Promise<ListResponse<T>>;
|
|
105
107
|
/**
|
|
106
|
-
*
|
|
108
|
+
* Deletes a single record.
|
|
107
109
|
*
|
|
108
|
-
* @param entity - The entity type
|
|
109
|
-
* @param
|
|
110
|
-
* @returns The updated records
|
|
110
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
111
|
+
* @param id - The record ID to delete
|
|
111
112
|
*
|
|
112
113
|
* @example
|
|
113
114
|
* ```typescript
|
|
114
|
-
*
|
|
115
|
-
* { type: 'company', id: 'id-1', attributes: { industry: 'tech' } },
|
|
116
|
-
* { type: 'company', id: 'id-2', attributes: { industry: 'finance' } },
|
|
117
|
-
* ]);
|
|
115
|
+
* await client.records.delete('company', 'abc123');
|
|
118
116
|
* ```
|
|
119
117
|
*/
|
|
120
|
-
|
|
118
|
+
delete(entity: string, id: string): Promise<void>;
|
|
121
119
|
/**
|
|
122
120
|
* Deletes multiple records in bulk.
|
|
123
121
|
*
|
|
124
|
-
* @param entity - The entity type
|
|
122
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
125
123
|
* @param ids - Array of record IDs to delete
|
|
126
124
|
*
|
|
127
125
|
* @example
|
|
128
126
|
* ```typescript
|
|
129
|
-
* await
|
|
127
|
+
* await client.records.deleteBulk('company', ['abc123', 'def456']);
|
|
130
128
|
* ```
|
|
131
129
|
*/
|
|
132
130
|
deleteBulk(entity: string, ids: string[]): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Async iterator for paginating through all records.
|
|
135
|
-
*
|
|
136
|
-
* @param entity - The entity type
|
|
137
|
-
* @param options - Filter and sort options (pagination is handled automatically)
|
|
138
|
-
* @yields Individual records
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```typescript
|
|
142
|
-
* for await (const company of clarify.records.iterate('company')) {
|
|
143
|
-
* console.log(company.attributes.name);
|
|
144
|
-
* }
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
iterate<T = Record<string, unknown>>(entity: string, options?: Omit<ListOptions, 'page'>): AsyncGenerator<Resource<T>, void, undefined>;
|
|
148
|
-
/**
|
|
149
|
-
* Builds query parameters from list options.
|
|
150
|
-
*/
|
|
151
|
-
private buildListQuery;
|
|
152
|
-
/**
|
|
153
|
-
* Extracts the cursor from a pagination URL.
|
|
154
|
-
*/
|
|
155
|
-
private extractCursor;
|
|
156
131
|
}
|
|
157
132
|
//# sourceMappingURL=records.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../src/resources/records.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../src/resources/records.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAGV,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc;IAI1D;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;;;;;;;;;;;;;;;OAkBG;IACG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAc7B;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,CAAC,GACZ,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAe7B;;;;;;;;;;;;;;;OAeG;IACG,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,GAC3B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAY3B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAuB7B;;;;;;;;;;;;;;;OAeG;IACG,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,EAC5B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAmB3B;;;;;;;;;;OAUG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvD;;;;;;;;;;OAUG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAS/D"}
|
|
@@ -2,262 +2,208 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RecordsResource = void 0;
|
|
4
4
|
const base_resource_js_1 = require("./base-resource.js");
|
|
5
|
-
const relationships_js_1 = require("./relationships.js");
|
|
6
5
|
/**
|
|
7
6
|
* Manages CRUD operations for records.
|
|
8
7
|
*/
|
|
9
8
|
class RecordsResource extends base_resource_js_1.BaseResource {
|
|
10
|
-
/** Sub-resource for managing record relationships */
|
|
11
|
-
relationships;
|
|
12
9
|
constructor(httpClient, config) {
|
|
13
10
|
super(httpClient, config);
|
|
14
|
-
this.relationships = new relationships_js_1.RelationshipsResource(httpClient, config);
|
|
15
11
|
}
|
|
16
12
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
20
|
-
* @param options - Pagination, filter, and sort options
|
|
21
|
-
* @returns Paginated list of records
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const companies = await clarify.records.list('company', {
|
|
26
|
-
* page: { limit: 20 },
|
|
27
|
-
* filter: { industry: 'technology' },
|
|
28
|
-
* sort: { field: 'name', direction: 'asc' },
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
13
|
+
* Gets the base path for record operations on a specific entity.
|
|
31
14
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return this.httpClient.request({
|
|
35
|
-
method: 'GET',
|
|
36
|
-
path: `${this.basePath}/records/${entity}`,
|
|
37
|
-
query,
|
|
38
|
-
});
|
|
15
|
+
getEntityPath(entity) {
|
|
16
|
+
return `${this.basePath}/objects/${entity}/records`;
|
|
39
17
|
}
|
|
40
18
|
/**
|
|
41
|
-
*
|
|
19
|
+
* Retrieves a single record by ID.
|
|
42
20
|
*
|
|
43
|
-
* @param entity - The entity type
|
|
21
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
44
22
|
* @param id - The record ID
|
|
45
|
-
* @
|
|
23
|
+
* @param options - Optional parameters including relationships to include
|
|
24
|
+
* @returns The record wrapped in a JSON:API response
|
|
46
25
|
*
|
|
47
26
|
* @example
|
|
48
27
|
* ```typescript
|
|
49
|
-
* const
|
|
50
|
-
* console.log(
|
|
28
|
+
* const response = await client.records.get('company', 'abc123');
|
|
29
|
+
* console.log(response.data.attributes.name);
|
|
30
|
+
*
|
|
31
|
+
* // With included relationships
|
|
32
|
+
* const response = await client.records.get('deal', 'xyz789', {
|
|
33
|
+
* include: ['company', 'person']
|
|
34
|
+
* });
|
|
51
35
|
* ```
|
|
52
36
|
*/
|
|
53
|
-
async get(entity, id) {
|
|
37
|
+
async get(entity, id, options) {
|
|
38
|
+
const query = {};
|
|
39
|
+
if (options?.include && options.include.length > 0) {
|
|
40
|
+
query.include = options.include.join(',');
|
|
41
|
+
}
|
|
54
42
|
return this.httpClient.request({
|
|
55
43
|
method: 'GET',
|
|
56
|
-
path: `${this.
|
|
44
|
+
path: `${this.getEntityPath(entity)}/${id}`,
|
|
45
|
+
query,
|
|
57
46
|
});
|
|
58
47
|
}
|
|
59
48
|
/**
|
|
60
|
-
* Creates a
|
|
49
|
+
* Creates a single record.
|
|
61
50
|
*
|
|
62
|
-
* @param entity - The entity type
|
|
63
|
-
* @param
|
|
64
|
-
* @returns The created record
|
|
51
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
52
|
+
* @param attributes - The record attributes to create
|
|
53
|
+
* @returns The created record wrapped in a JSON:API response
|
|
65
54
|
*
|
|
66
55
|
* @example
|
|
67
56
|
* ```typescript
|
|
68
|
-
* const
|
|
69
|
-
*
|
|
70
|
-
*
|
|
57
|
+
* const response = await client.records.create('company', {
|
|
58
|
+
* name: 'Acme Corp',
|
|
59
|
+
* website: 'https://acme.com'
|
|
71
60
|
* });
|
|
61
|
+
* console.log(response.data.id);
|
|
72
62
|
* ```
|
|
73
63
|
*/
|
|
74
|
-
async create(entity,
|
|
75
|
-
const body = {
|
|
64
|
+
async create(entity, attributes) {
|
|
65
|
+
const body = {
|
|
66
|
+
data: {
|
|
67
|
+
type: entity,
|
|
68
|
+
attributes,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
76
71
|
return this.httpClient.request({
|
|
77
72
|
method: 'POST',
|
|
78
|
-
path:
|
|
73
|
+
path: this.getEntityPath(entity),
|
|
79
74
|
body,
|
|
80
75
|
});
|
|
81
76
|
}
|
|
82
77
|
/**
|
|
83
|
-
*
|
|
78
|
+
* Creates multiple records in bulk.
|
|
84
79
|
*
|
|
85
|
-
* @param entity - The entity type
|
|
86
|
-
* @param
|
|
87
|
-
* @
|
|
88
|
-
* @returns The updated record
|
|
80
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
81
|
+
* @param records - Array of record create objects with type and attributes
|
|
82
|
+
* @returns The created records wrapped in a JSON:API list response
|
|
89
83
|
*
|
|
90
84
|
* @example
|
|
91
85
|
* ```typescript
|
|
92
|
-
* const
|
|
93
|
-
* type: 'company',
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
86
|
+
* const response = await client.records.createBulk('company', [
|
|
87
|
+
* { type: 'company', attributes: { name: 'Acme Corp' } },
|
|
88
|
+
* { type: 'company', attributes: { name: 'Widget Inc' } }
|
|
89
|
+
* ]);
|
|
90
|
+
* console.log(response.data.length);
|
|
97
91
|
* ```
|
|
98
92
|
*/
|
|
99
|
-
async
|
|
100
|
-
const body = {
|
|
93
|
+
async createBulk(entity, records) {
|
|
94
|
+
const body = {
|
|
95
|
+
data: records,
|
|
96
|
+
};
|
|
101
97
|
return this.httpClient.request({
|
|
102
|
-
method: '
|
|
103
|
-
path: `${this.
|
|
98
|
+
method: 'POST',
|
|
99
|
+
path: `${this.getEntityPath(entity)}/bulk`,
|
|
104
100
|
body,
|
|
105
101
|
});
|
|
106
102
|
}
|
|
107
103
|
/**
|
|
108
|
-
*
|
|
104
|
+
* Updates a single record.
|
|
109
105
|
*
|
|
110
|
-
* @param entity - The entity type
|
|
106
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
111
107
|
* @param id - The record ID
|
|
108
|
+
* @param attributes - The attributes to update
|
|
109
|
+
* @param options - Optional update options including field operation rules
|
|
110
|
+
* @returns The updated record wrapped in a JSON:API response
|
|
112
111
|
*
|
|
113
112
|
* @example
|
|
114
113
|
* ```typescript
|
|
115
|
-
* await
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
async delete(entity, id) {
|
|
119
|
-
await this.httpClient.request({
|
|
120
|
-
method: 'DELETE',
|
|
121
|
-
path: `${this.basePath}/records/${entity}/${id}`,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Creates multiple records in bulk.
|
|
126
|
-
*
|
|
127
|
-
* @param entity - The entity type
|
|
128
|
-
* @param data - Array of resources to create
|
|
129
|
-
* @returns The created records
|
|
114
|
+
* const response = await client.records.update('company', 'abc123', {
|
|
115
|
+
* name: 'Acme Corporation'
|
|
116
|
+
* });
|
|
130
117
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* {
|
|
135
|
-
*
|
|
136
|
-
* ]);
|
|
118
|
+
* // With field operation rules (e.g., append to array field)
|
|
119
|
+
* const response = await client.records.update('deal', 'xyz789',
|
|
120
|
+
* { tags: ['new-tag'] },
|
|
121
|
+
* { meta: { tags: { array: 'append' } } }
|
|
122
|
+
* );
|
|
137
123
|
* ```
|
|
138
124
|
*/
|
|
139
|
-
async
|
|
140
|
-
const body = {
|
|
125
|
+
async update(entity, id, attributes, options) {
|
|
126
|
+
const body = {
|
|
127
|
+
data: {
|
|
128
|
+
type: entity,
|
|
129
|
+
id,
|
|
130
|
+
attributes,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
if (options?.meta) {
|
|
134
|
+
body.meta = options.meta;
|
|
135
|
+
}
|
|
141
136
|
return this.httpClient.request({
|
|
142
|
-
method: '
|
|
143
|
-
path: `${this.
|
|
137
|
+
method: 'PATCH',
|
|
138
|
+
path: `${this.getEntityPath(entity)}/${id}`,
|
|
144
139
|
body,
|
|
145
140
|
});
|
|
146
141
|
}
|
|
147
142
|
/**
|
|
148
143
|
* Updates multiple records in bulk.
|
|
149
144
|
*
|
|
150
|
-
* @param entity - The entity type
|
|
151
|
-
* @param
|
|
152
|
-
* @
|
|
145
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
146
|
+
* @param records - Array of record update objects with type, id, and attributes
|
|
147
|
+
* @param options - Optional update options including field operation rules
|
|
148
|
+
* @returns The updated records wrapped in a JSON:API list response
|
|
153
149
|
*
|
|
154
150
|
* @example
|
|
155
151
|
* ```typescript
|
|
156
|
-
* const
|
|
157
|
-
* { type: 'company', id: '
|
|
158
|
-
* { type: 'company', id: '
|
|
152
|
+
* const response = await client.records.updateBulk('company', [
|
|
153
|
+
* { type: 'company', id: 'abc123', attributes: { status: 'active' } },
|
|
154
|
+
* { type: 'company', id: 'def456', attributes: { status: 'active' } }
|
|
159
155
|
* ]);
|
|
160
156
|
* ```
|
|
161
157
|
*/
|
|
162
|
-
async updateBulk(entity,
|
|
163
|
-
const body = {
|
|
158
|
+
async updateBulk(entity, records, options) {
|
|
159
|
+
const body = {
|
|
160
|
+
data: records,
|
|
161
|
+
};
|
|
162
|
+
if (options?.meta) {
|
|
163
|
+
body.meta = options.meta;
|
|
164
|
+
}
|
|
164
165
|
return this.httpClient.request({
|
|
165
166
|
method: 'PATCH',
|
|
166
|
-
path:
|
|
167
|
+
path: this.getEntityPath(entity),
|
|
167
168
|
body,
|
|
168
169
|
});
|
|
169
170
|
}
|
|
170
171
|
/**
|
|
171
|
-
* Deletes
|
|
172
|
+
* Deletes a single record.
|
|
172
173
|
*
|
|
173
|
-
* @param entity - The entity type
|
|
174
|
-
* @param
|
|
174
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
175
|
+
* @param id - The record ID to delete
|
|
175
176
|
*
|
|
176
177
|
* @example
|
|
177
178
|
* ```typescript
|
|
178
|
-
* await
|
|
179
|
+
* await client.records.delete('company', 'abc123');
|
|
179
180
|
* ```
|
|
180
181
|
*/
|
|
181
|
-
async
|
|
182
|
-
const body = {
|
|
183
|
-
data: ids.map((id) => ({ type: entity, id })),
|
|
184
|
-
};
|
|
182
|
+
async delete(entity, id) {
|
|
185
183
|
await this.httpClient.request({
|
|
186
184
|
method: 'DELETE',
|
|
187
|
-
path: `${this.
|
|
188
|
-
body,
|
|
185
|
+
path: `${this.getEntityPath(entity)}/${id}`,
|
|
189
186
|
});
|
|
190
187
|
}
|
|
191
188
|
/**
|
|
192
|
-
*
|
|
189
|
+
* Deletes multiple records in bulk.
|
|
193
190
|
*
|
|
194
|
-
* @param entity - The entity type
|
|
195
|
-
* @param
|
|
196
|
-
* @yields Individual records
|
|
191
|
+
* @param entity - The entity type (e.g., 'company', 'person', 'deal')
|
|
192
|
+
* @param ids - Array of record IDs to delete
|
|
197
193
|
*
|
|
198
194
|
* @example
|
|
199
195
|
* ```typescript
|
|
200
|
-
*
|
|
201
|
-
* console.log(company.attributes.name);
|
|
202
|
-
* }
|
|
196
|
+
* await client.records.deleteBulk('company', ['abc123', 'def456']);
|
|
203
197
|
* ```
|
|
204
198
|
*/
|
|
205
|
-
async
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
yield record;
|
|
214
|
-
}
|
|
215
|
-
// Extract cursor from next link if available
|
|
216
|
-
cursor = this.extractCursor(response.links?.next);
|
|
217
|
-
} while (cursor);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Builds query parameters from list options.
|
|
221
|
-
*/
|
|
222
|
-
buildListQuery(options) {
|
|
223
|
-
const query = {};
|
|
224
|
-
if (options?.page?.cursor) {
|
|
225
|
-
query['page[cursor]'] = options.page.cursor;
|
|
226
|
-
}
|
|
227
|
-
if (options?.page?.limit) {
|
|
228
|
-
query['page[limit]'] = options.page.limit;
|
|
229
|
-
}
|
|
230
|
-
if (options?.filter) {
|
|
231
|
-
for (const [key, value] of Object.entries(options.filter)) {
|
|
232
|
-
if (value !== undefined) {
|
|
233
|
-
query[`filter[${key}]`] = Array.isArray(value)
|
|
234
|
-
? value.join(',')
|
|
235
|
-
: String(value);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (options?.sort) {
|
|
240
|
-
const sorts = Array.isArray(options.sort) ? options.sort : [options.sort];
|
|
241
|
-
query['sort'] = sorts
|
|
242
|
-
.map((s) => (s.direction === 'desc' ? `-${s.field}` : s.field))
|
|
243
|
-
.join(',');
|
|
244
|
-
}
|
|
245
|
-
return query;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Extracts the cursor from a pagination URL.
|
|
249
|
-
*/
|
|
250
|
-
extractCursor(url) {
|
|
251
|
-
if (!url) {
|
|
252
|
-
return undefined;
|
|
253
|
-
}
|
|
254
|
-
try {
|
|
255
|
-
const parsedUrl = new URL(url);
|
|
256
|
-
return parsedUrl.searchParams.get('page[cursor]') ?? undefined;
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
return undefined;
|
|
260
|
-
}
|
|
199
|
+
async deleteBulk(entity, ids) {
|
|
200
|
+
await this.httpClient.request({
|
|
201
|
+
method: 'DELETE',
|
|
202
|
+
path: this.getEntityPath(entity),
|
|
203
|
+
body: {
|
|
204
|
+
items: ids,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
261
207
|
}
|
|
262
208
|
}
|
|
263
209
|
exports.RecordsResource = RecordsResource;
|