@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.
Files changed (65) hide show
  1. package/README.md +104 -0
  2. package/dist/cjs/client.d.ts +0 -6
  3. package/dist/cjs/client.d.ts.map +1 -1
  4. package/dist/cjs/client.js +0 -8
  5. package/dist/cjs/client.js.map +1 -1
  6. package/dist/cjs/http/http-client.d.ts.map +1 -1
  7. package/dist/cjs/http/http-client.js +2 -2
  8. package/dist/cjs/http/http-client.js.map +1 -1
  9. package/dist/cjs/index.d.ts +1 -4
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +1 -9
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/resources/base-resource.js +1 -1
  14. package/dist/cjs/resources/base-resource.js.map +1 -1
  15. package/dist/cjs/resources/records.d.ts +65 -90
  16. package/dist/cjs/resources/records.d.ts.map +1 -1
  17. package/dist/cjs/resources/records.js +111 -165
  18. package/dist/cjs/resources/records.js.map +1 -1
  19. package/dist/cjs/types/common.d.ts +28 -0
  20. package/dist/cjs/types/common.d.ts.map +1 -1
  21. package/dist/cjs/types/config.d.ts +4 -4
  22. package/dist/cjs/types/config.d.ts.map +1 -1
  23. package/dist/cjs/types/config.js +2 -2
  24. package/dist/cjs/types/config.js.map +1 -1
  25. package/dist/cjs/types/index.d.ts +1 -1
  26. package/dist/cjs/types/index.d.ts.map +1 -1
  27. package/dist/esm/client.d.ts +0 -6
  28. package/dist/esm/client.d.ts.map +1 -1
  29. package/dist/esm/client.js +0 -8
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/http/http-client.d.ts.map +1 -1
  32. package/dist/esm/http/http-client.js +2 -2
  33. package/dist/esm/http/http-client.js.map +1 -1
  34. package/dist/esm/index.d.ts +1 -4
  35. package/dist/esm/index.d.ts.map +1 -1
  36. package/dist/esm/index.js +1 -9
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/resources/base-resource.js +1 -1
  39. package/dist/esm/resources/base-resource.js.map +1 -1
  40. package/dist/esm/resources/records.d.ts +65 -90
  41. package/dist/esm/resources/records.d.ts.map +1 -1
  42. package/dist/esm/resources/records.js +111 -165
  43. package/dist/esm/resources/records.js.map +1 -1
  44. package/dist/esm/types/common.d.ts +28 -0
  45. package/dist/esm/types/common.d.ts.map +1 -1
  46. package/dist/esm/types/config.d.ts +4 -4
  47. package/dist/esm/types/config.d.ts.map +1 -1
  48. package/dist/esm/types/config.js +2 -2
  49. package/dist/esm/types/config.js.map +1 -1
  50. package/dist/esm/types/index.d.ts +1 -1
  51. package/dist/esm/types/index.d.ts.map +1 -1
  52. package/dist/types/client.d.ts +0 -6
  53. package/dist/types/client.d.ts.map +1 -1
  54. package/dist/types/http/http-client.d.ts.map +1 -1
  55. package/dist/types/index.d.ts +1 -4
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/resources/records.d.ts +65 -90
  58. package/dist/types/resources/records.d.ts.map +1 -1
  59. package/dist/types/types/common.d.ts +28 -0
  60. package/dist/types/types/common.d.ts.map +1 -1
  61. package/dist/types/types/config.d.ts +4 -4
  62. package/dist/types/types/config.d.ts.map +1 -1
  63. package/dist/types/types/index.d.ts +1 -1
  64. package/dist/types/types/index.d.ts.map +1 -1
  65. 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.TaskPriority = exports.TaskStatus = exports.TasksResource = exports.MessagesResource = exports.RelationshipsResource = exports.RecordsResource = exports.ClarifyNetworkError = exports.ClarifyTimeoutError = exports.ClarifyValidationError = exports.ClarifyApiError = exports.ClarifyError = exports.ClarifyClient = void 0;
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
@@ -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;AAqBrB,sCAAsC;AACtC,qDAAyD;AAAhD,6GAAA,eAAe,OAAA;AACxB,iEAAqE;AAA5D,yHAAA,qBAAqB,OAAA;AAC9B,uDAAmF;AAA1E,+GAAA,gBAAgB,OAAA;AACzB,iDAK8B;AAJ5B,yGAAA,aAAa,OAAA;AACb,sGAAA,UAAU,OAAA;AACV,wGAAA,YAAY,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"}
@@ -15,7 +15,7 @@ class BaseResource {
15
15
  * Gets the workspace-prefixed base path for API endpoints.
16
16
  */
17
17
  get basePath() {
18
- return `/api/${this.config.workspace}`;
18
+ return `/v1/workspaces/${this.config.workspace}`;
19
19
  }
20
20
  }
21
21
  exports.BaseResource = BaseResource;
@@ -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,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACzC,CAAC;CACF;AAfD,oCAeC"}
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 { ListOptions, ListResponse, ResolvedConfig, Resource, ResourceCreate, ResourceUpdate, SingleResponse } from '../types/index.js';
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
- * Lists records of a given entity type.
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
- list<T = Record<string, unknown>>(entity: string, options?: ListOptions): Promise<ListResponse<T>>;
12
+ private getEntityPath;
29
13
  /**
30
- * Gets a single record by ID.
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
- * @returns The record
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 company = await clarify.records.get('company', 'company-id');
39
- * console.log(company.data.attributes.name);
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 new record.
34
+ * Creates a single record.
45
35
  *
46
- * @param entity - The entity type
47
- * @param data - The resource data to create
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 company = await clarify.records.create('company', {
53
- * type: 'company',
54
- * attributes: { name: 'Acme Inc.', industry: 'technology' },
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, data: ResourceCreate<T>): Promise<SingleResponse<T>>;
49
+ create<T = Record<string, unknown>>(entity: string, attributes: T): Promise<SingleResponse<T>>;
59
50
  /**
60
- * Updates an existing record.
51
+ * Creates multiple records in bulk.
61
52
  *
62
- * @param entity - The entity type
63
- * @param id - The record ID
64
- * @param data - The resource data to update
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 company = await clarify.records.update('company', 'company-id', {
70
- * type: 'company',
71
- * id: 'company-id',
72
- * attributes: { industry: 'software' },
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
- update<T = Record<string, unknown>>(entity: string, id: string, data: ResourceUpdate<T>): Promise<SingleResponse<T>>;
66
+ createBulk<T = Record<string, unknown>>(entity: string, records: ResourceCreate<T>[]): Promise<ListResponse<T>>;
77
67
  /**
78
- * Deletes a record.
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 clarify.records.delete('company', 'company-id');
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
- delete(entity: string, id: string): Promise<void>;
89
+ update<T = Record<string, unknown>>(entity: string, id: string, attributes: Partial<T>, options?: UpdateRecordOptions): Promise<SingleResponse<T>>;
89
90
  /**
90
- * Creates multiple records in bulk.
91
+ * Updates multiple records in bulk.
91
92
  *
92
- * @param entity - The entity type
93
- * @param data - Array of resources to create
94
- * @returns The created records
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 companies = await clarify.records.createBulk('company', [
99
- * { type: 'company', attributes: { name: 'Acme Inc.' } },
100
- * { type: 'company', attributes: { name: 'Globex Corp.' } },
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
- createBulk<T = Record<string, unknown>>(entity: string, data: ResourceCreate<T>[]): Promise<ListResponse<T>>;
106
+ updateBulk<T = Record<string, unknown>>(entity: string, records: ResourceUpdate<T>[], options?: UpdateRecordOptions): Promise<ListResponse<T>>;
105
107
  /**
106
- * Updates multiple records in bulk.
108
+ * Deletes a single record.
107
109
  *
108
- * @param entity - The entity type
109
- * @param data - Array of resources to update
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
- * const companies = await clarify.records.updateBulk('company', [
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
- updateBulk<T = Record<string, unknown>>(entity: string, data: ResourceUpdate<T>[]): Promise<ListResponse<T>>;
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 clarify.records.deleteBulk('company', ['id-1', 'id-2', 'id-3']);
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,EAKV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,qDAAqD;IACrD,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC;gBAElC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc;IAK1D;;;;;;;;;;;;;;;OAeG;IACG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAU3B;;;;;;;;;;;;OAYG;IACG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAO7B;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,cAAc,CAAC,C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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
- * Lists records of a given entity type.
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
- async list(entity, options) {
33
- const query = this.buildListQuery(options);
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
- * Gets a single record by ID.
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
- * @returns The record
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 company = await clarify.records.get('company', 'company-id');
50
- * console.log(company.data.attributes.name);
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.basePath}/records/${entity}/${id}`,
44
+ path: `${this.getEntityPath(entity)}/${id}`,
45
+ query,
57
46
  });
58
47
  }
59
48
  /**
60
- * Creates a new record.
49
+ * Creates a single record.
61
50
  *
62
- * @param entity - The entity type
63
- * @param data - The resource data to create
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 company = await clarify.records.create('company', {
69
- * type: 'company',
70
- * attributes: { name: 'Acme Inc.', industry: 'technology' },
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, data) {
75
- const body = { data };
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: `${this.basePath}/records/${entity}`,
73
+ path: this.getEntityPath(entity),
79
74
  body,
80
75
  });
81
76
  }
82
77
  /**
83
- * Updates an existing record.
78
+ * Creates multiple records in bulk.
84
79
  *
85
- * @param entity - The entity type
86
- * @param id - The record ID
87
- * @param data - The resource data to update
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 company = await clarify.records.update('company', 'company-id', {
93
- * type: 'company',
94
- * id: 'company-id',
95
- * attributes: { industry: 'software' },
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 update(entity, id, data) {
100
- const body = { data };
93
+ async createBulk(entity, records) {
94
+ const body = {
95
+ data: records,
96
+ };
101
97
  return this.httpClient.request({
102
- method: 'PATCH',
103
- path: `${this.basePath}/records/${entity}/${id}`,
98
+ method: 'POST',
99
+ path: `${this.getEntityPath(entity)}/bulk`,
104
100
  body,
105
101
  });
106
102
  }
107
103
  /**
108
- * Deletes a record.
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 clarify.records.delete('company', 'company-id');
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
- * @example
132
- * ```typescript
133
- * const companies = await clarify.records.createBulk('company', [
134
- * { type: 'company', attributes: { name: 'Acme Inc.' } },
135
- * { type: 'company', attributes: { name: 'Globex Corp.' } },
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 createBulk(entity, data) {
140
- const body = { data };
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: 'POST',
143
- path: `${this.basePath}/records/${entity}/bulk`,
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 data - Array of resources to update
152
- * @returns The updated records
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 companies = await clarify.records.updateBulk('company', [
157
- * { type: 'company', id: 'id-1', attributes: { industry: 'tech' } },
158
- * { type: 'company', id: 'id-2', attributes: { industry: 'finance' } },
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, data) {
163
- const body = { data };
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: `${this.basePath}/records/${entity}/bulk`,
167
+ path: this.getEntityPath(entity),
167
168
  body,
168
169
  });
169
170
  }
170
171
  /**
171
- * Deletes multiple records in bulk.
172
+ * Deletes a single record.
172
173
  *
173
- * @param entity - The entity type
174
- * @param ids - Array of record IDs to delete
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 clarify.records.deleteBulk('company', ['id-1', 'id-2', 'id-3']);
179
+ * await client.records.delete('company', 'abc123');
179
180
  * ```
180
181
  */
181
- async deleteBulk(entity, ids) {
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.basePath}/records/${entity}/bulk`,
188
- body,
185
+ path: `${this.getEntityPath(entity)}/${id}`,
189
186
  });
190
187
  }
191
188
  /**
192
- * Async iterator for paginating through all records.
189
+ * Deletes multiple records in bulk.
193
190
  *
194
- * @param entity - The entity type
195
- * @param options - Filter and sort options (pagination is handled automatically)
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
- * for await (const company of clarify.records.iterate('company')) {
201
- * console.log(company.attributes.name);
202
- * }
196
+ * await client.records.deleteBulk('company', ['abc123', 'def456']);
203
197
  * ```
204
198
  */
205
- async *iterate(entity, options) {
206
- let cursor;
207
- do {
208
- const response = await this.list(entity, {
209
- ...options,
210
- page: { cursor, limit: 100 },
211
- });
212
- for (const record of response.data) {
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;