@getclarify/nodejs-sdk 0.0.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/cjs/client.d.ts +54 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +88 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors/api-error.d.ts +59 -0
- package/dist/cjs/errors/api-error.d.ts.map +1 -0
- package/dist/cjs/errors/api-error.js +104 -0
- package/dist/cjs/errors/api-error.js.map +1 -0
- package/dist/cjs/errors/index.d.ts +3 -0
- package/dist/cjs/errors/index.d.ts.map +1 -0
- package/dist/cjs/errors/index.js +10 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/http/http-client.d.ts +46 -0
- package/dist/cjs/http/http-client.d.ts.map +1 -0
- package/dist/cjs/http/http-client.js +145 -0
- package/dist/cjs/http/http-client.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/resources/base-resource.d.ts +15 -0
- package/dist/cjs/resources/base-resource.d.ts.map +1 -0
- package/dist/cjs/resources/base-resource.js +22 -0
- package/dist/cjs/resources/base-resource.js.map +1 -0
- package/dist/cjs/resources/messages.d.ts +105 -0
- package/dist/cjs/resources/messages.d.ts.map +1 -0
- package/dist/cjs/resources/messages.js +166 -0
- package/dist/cjs/resources/messages.js.map +1 -0
- package/dist/cjs/resources/records.d.ts +157 -0
- package/dist/cjs/resources/records.d.ts.map +1 -0
- package/dist/cjs/resources/records.js +264 -0
- package/dist/cjs/resources/records.js.map +1 -0
- package/dist/cjs/resources/relationships.d.ts +96 -0
- package/dist/cjs/resources/relationships.d.ts.map +1 -0
- package/dist/cjs/resources/relationships.js +157 -0
- package/dist/cjs/resources/relationships.js.map +1 -0
- package/dist/cjs/resources/tasks.d.ts +141 -0
- package/dist/cjs/resources/tasks.d.ts.map +1 -0
- package/dist/cjs/resources/tasks.js +211 -0
- package/dist/cjs/resources/tasks.js.map +1 -0
- package/dist/cjs/types/common.d.ts +126 -0
- package/dist/cjs/types/common.d.ts.map +1 -0
- package/dist/cjs/types/common.js +3 -0
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/config.d.ts +36 -0
- package/dist/cjs/types/config.d.ts.map +1 -0
- package/dist/cjs/types/config.js +11 -0
- package/dist/cjs/types/config.js.map +1 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js +6 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/client.d.ts +54 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +88 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors/api-error.d.ts +59 -0
- package/dist/esm/errors/api-error.d.ts.map +1 -0
- package/dist/esm/errors/api-error.js +104 -0
- package/dist/esm/errors/api-error.js.map +1 -0
- package/dist/esm/errors/index.d.ts +3 -0
- package/dist/esm/errors/index.d.ts.map +1 -0
- package/dist/esm/errors/index.js +10 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/http/http-client.d.ts +46 -0
- package/dist/esm/http/http-client.d.ts.map +1 -0
- package/dist/esm/http/http-client.js +145 -0
- package/dist/esm/http/http-client.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +25 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/resources/base-resource.d.ts +15 -0
- package/dist/esm/resources/base-resource.d.ts.map +1 -0
- package/dist/esm/resources/base-resource.js +22 -0
- package/dist/esm/resources/base-resource.js.map +1 -0
- package/dist/esm/resources/messages.d.ts +105 -0
- package/dist/esm/resources/messages.d.ts.map +1 -0
- package/dist/esm/resources/messages.js +166 -0
- package/dist/esm/resources/messages.js.map +1 -0
- package/dist/esm/resources/records.d.ts +157 -0
- package/dist/esm/resources/records.d.ts.map +1 -0
- package/dist/esm/resources/records.js +264 -0
- package/dist/esm/resources/records.js.map +1 -0
- package/dist/esm/resources/relationships.d.ts +96 -0
- package/dist/esm/resources/relationships.d.ts.map +1 -0
- package/dist/esm/resources/relationships.js +157 -0
- package/dist/esm/resources/relationships.js.map +1 -0
- package/dist/esm/resources/tasks.d.ts +141 -0
- package/dist/esm/resources/tasks.d.ts.map +1 -0
- package/dist/esm/resources/tasks.js +211 -0
- package/dist/esm/resources/tasks.js.map +1 -0
- package/dist/esm/types/common.d.ts +126 -0
- package/dist/esm/types/common.d.ts.map +1 -0
- package/dist/esm/types/common.js +3 -0
- package/dist/esm/types/common.js.map +1 -0
- package/dist/esm/types/config.d.ts +36 -0
- package/dist/esm/types/config.d.ts.map +1 -0
- package/dist/esm/types/config.js +11 -0
- package/dist/esm/types/config.js.map +1 -0
- package/dist/esm/types/index.d.ts +4 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +6 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/types/client.d.ts +54 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/errors/api-error.d.ts +59 -0
- package/dist/types/errors/api-error.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +3 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/http/http-client.d.ts +46 -0
- package/dist/types/http/http-client.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/resources/base-resource.d.ts +15 -0
- package/dist/types/resources/base-resource.d.ts.map +1 -0
- package/dist/types/resources/messages.d.ts +105 -0
- package/dist/types/resources/messages.d.ts.map +1 -0
- package/dist/types/resources/records.d.ts +157 -0
- package/dist/types/resources/records.d.ts.map +1 -0
- package/dist/types/resources/relationships.d.ts +96 -0
- package/dist/types/resources/relationships.d.ts.map +1 -0
- package/dist/types/resources/tasks.d.ts +141 -0
- package/dist/types/resources/tasks.d.ts.map +1 -0
- package/dist/types/types/common.d.ts +126 -0
- package/dist/types/types/common.d.ts.map +1 -0
- package/dist/types/types/config.d.ts +36 -0
- package/dist/types/types/config.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecordsResource = void 0;
|
|
4
|
+
const base_resource_js_1 = require("./base-resource.js");
|
|
5
|
+
const relationships_js_1 = require("./relationships.js");
|
|
6
|
+
/**
|
|
7
|
+
* Manages CRUD operations for records.
|
|
8
|
+
*/
|
|
9
|
+
class RecordsResource extends base_resource_js_1.BaseResource {
|
|
10
|
+
/** Sub-resource for managing record relationships */
|
|
11
|
+
relationships;
|
|
12
|
+
constructor(httpClient, config) {
|
|
13
|
+
super(httpClient, config);
|
|
14
|
+
this.relationships = new relationships_js_1.RelationshipsResource(httpClient, config);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
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
|
+
* ```
|
|
31
|
+
*/
|
|
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
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets a single record by ID.
|
|
42
|
+
*
|
|
43
|
+
* @param entity - The entity type
|
|
44
|
+
* @param id - The record ID
|
|
45
|
+
* @returns The record
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const company = await clarify.records.get('company', 'company-id');
|
|
50
|
+
* console.log(company.data.attributes.name);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
async get(entity, id) {
|
|
54
|
+
return this.httpClient.request({
|
|
55
|
+
method: 'GET',
|
|
56
|
+
path: `${this.basePath}/records/${entity}/${id}`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new record.
|
|
61
|
+
*
|
|
62
|
+
* @param entity - The entity type
|
|
63
|
+
* @param data - The resource data to create
|
|
64
|
+
* @returns The created record
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const company = await clarify.records.create('company', {
|
|
69
|
+
* type: 'company',
|
|
70
|
+
* attributes: { name: 'Acme Inc.', industry: 'technology' },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async create(entity, data) {
|
|
75
|
+
const body = { data };
|
|
76
|
+
return this.httpClient.request({
|
|
77
|
+
method: 'POST',
|
|
78
|
+
path: `${this.basePath}/records/${entity}`,
|
|
79
|
+
body,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Updates an existing record.
|
|
84
|
+
*
|
|
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
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const company = await clarify.records.update('company', 'company-id', {
|
|
93
|
+
* type: 'company',
|
|
94
|
+
* id: 'company-id',
|
|
95
|
+
* attributes: { industry: 'software' },
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
async update(entity, id, data) {
|
|
100
|
+
const body = { data };
|
|
101
|
+
return this.httpClient.request({
|
|
102
|
+
method: 'PATCH',
|
|
103
|
+
path: `${this.basePath}/records/${entity}/${id}`,
|
|
104
|
+
body,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Deletes a record.
|
|
109
|
+
*
|
|
110
|
+
* @param entity - The entity type
|
|
111
|
+
* @param id - The record ID
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```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
|
|
130
|
+
*
|
|
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
|
+
* ]);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
async createBulk(entity, data) {
|
|
140
|
+
const body = { data };
|
|
141
|
+
return this.httpClient.request({
|
|
142
|
+
method: 'POST',
|
|
143
|
+
path: `${this.basePath}/records/${entity}/bulk`,
|
|
144
|
+
body,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Updates multiple records in bulk.
|
|
149
|
+
*
|
|
150
|
+
* @param entity - The entity type
|
|
151
|
+
* @param data - Array of resources to update
|
|
152
|
+
* @returns The updated records
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```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' } },
|
|
159
|
+
* ]);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
async updateBulk(entity, data) {
|
|
163
|
+
const body = { data };
|
|
164
|
+
return this.httpClient.request({
|
|
165
|
+
method: 'PATCH',
|
|
166
|
+
path: `${this.basePath}/records/${entity}/bulk`,
|
|
167
|
+
body,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Deletes multiple records in bulk.
|
|
172
|
+
*
|
|
173
|
+
* @param entity - The entity type
|
|
174
|
+
* @param ids - Array of record IDs to delete
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* await clarify.records.deleteBulk('company', ['id-1', 'id-2', 'id-3']);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async deleteBulk(entity, ids) {
|
|
182
|
+
const body = {
|
|
183
|
+
data: ids.map((id) => ({ type: entity, id })),
|
|
184
|
+
};
|
|
185
|
+
await this.httpClient.request({
|
|
186
|
+
method: 'DELETE',
|
|
187
|
+
path: `${this.basePath}/records/${entity}/bulk`,
|
|
188
|
+
body,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Async iterator for paginating through all records.
|
|
193
|
+
*
|
|
194
|
+
* @param entity - The entity type
|
|
195
|
+
* @param options - Filter and sort options (pagination is handled automatically)
|
|
196
|
+
* @yields Individual records
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* for await (const company of clarify.records.iterate('company')) {
|
|
201
|
+
* console.log(company.attributes.name);
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
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
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.RecordsResource = RecordsResource;
|
|
264
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../../src/resources/records.ts"],"names":[],"mappings":";;;AAeA,yDAAkD;AAClD,yDAA2D;AAE3D;;GAEG;AACH,MAAa,eAAgB,SAAQ,+BAAY;IAC/C,qDAAqD;IAC5C,aAAa,CAAwB;IAE9C,YAAY,UAAsB,EAAE,MAAsB;QACxD,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,IAAI,wCAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,IAAI,CACR,MAAc,EACd,OAAqB;QAErB,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAkB;YAC9C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,YAAY,MAAM,EAAE;YAC1C,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,GAAG,CACP,MAAc,EACd,EAAU;QAEV,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAoB;YAChD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,YAAY,MAAM,IAAI,EAAE,EAAE;SACjD,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,CACV,MAAc,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AAG,EAAE,CAAC;YACT,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAC/B,OAAO,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,SAAS,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AA9SD,0CA8SC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { HttpClient } from '../http/http-client.js';
|
|
2
|
+
import type { ListOptions, ListResponse, ResolvedConfig, Resource, ResourceIdentifier } from '../types/index.js';
|
|
3
|
+
import { BaseResource } from './base-resource.js';
|
|
4
|
+
/**
|
|
5
|
+
* Request body for adding relationships.
|
|
6
|
+
*/
|
|
7
|
+
export interface AddRelationshipsBody {
|
|
8
|
+
data: ResourceIdentifier[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Request body for removing relationships.
|
|
12
|
+
*/
|
|
13
|
+
export interface RemoveRelationshipsBody {
|
|
14
|
+
data: ResourceIdentifier[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Manages relationships between records.
|
|
18
|
+
*/
|
|
19
|
+
export declare class RelationshipsResource extends BaseResource {
|
|
20
|
+
constructor(httpClient: HttpClient, config: ResolvedConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Lists related records for a given record and relationship.
|
|
23
|
+
*
|
|
24
|
+
* @param entity - The entity type of the source record
|
|
25
|
+
* @param recordId - The ID of the source record
|
|
26
|
+
* @param relationship - The name of the relationship
|
|
27
|
+
* @param options - Pagination and filter options
|
|
28
|
+
* @returns Paginated list of related records
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const people = await clarify.records.relationships.list('company', 'company-id', 'people');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
list<T = Record<string, unknown>>(entity: string, recordId: string, relationship: string, options?: ListOptions): Promise<ListResponse<T>>;
|
|
36
|
+
/**
|
|
37
|
+
* Adds relationships between a source record and target records.
|
|
38
|
+
*
|
|
39
|
+
* @param entity - The entity type of the source record
|
|
40
|
+
* @param recordId - The ID of the source record
|
|
41
|
+
* @param relationship - The name of the relationship
|
|
42
|
+
* @param targets - Array of resource identifiers to add
|
|
43
|
+
* @returns The updated list of related records
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* await clarify.records.relationships.add('company', 'company-id', 'people', [
|
|
48
|
+
* { type: 'person', id: 'person-id-1' },
|
|
49
|
+
* { type: 'person', id: 'person-id-2' },
|
|
50
|
+
* ]);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
add<T = Record<string, unknown>>(entity: string, recordId: string, relationship: string, targets: ResourceIdentifier[]): Promise<ListResponse<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Removes relationships between a source record and target records.
|
|
56
|
+
*
|
|
57
|
+
* @param entity - The entity type of the source record
|
|
58
|
+
* @param recordId - The ID of the source record
|
|
59
|
+
* @param relationship - The name of the relationship
|
|
60
|
+
* @param targets - Array of resource identifiers to remove
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* await clarify.records.relationships.remove('company', 'company-id', 'people', [
|
|
65
|
+
* { type: 'person', id: 'person-id-1' },
|
|
66
|
+
* ]);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
remove(entity: string, recordId: string, relationship: string, targets: ResourceIdentifier[]): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Async iterator for paginating through all related records.
|
|
72
|
+
*
|
|
73
|
+
* @param entity - The entity type of the source record
|
|
74
|
+
* @param recordId - The ID of the source record
|
|
75
|
+
* @param relationship - The name of the relationship
|
|
76
|
+
* @param options - Filter and sort options (pagination is handled automatically)
|
|
77
|
+
* @yields Individual related records
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* for await (const person of clarify.records.relationships.iterate('company', 'company-id', 'people')) {
|
|
82
|
+
* console.log(person.attributes.name);
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
iterate<T = Record<string, unknown>>(entity: string, recordId: string, relationship: string, options?: Omit<ListOptions, 'page'>): AsyncGenerator<Resource<T>, void, undefined>;
|
|
87
|
+
/**
|
|
88
|
+
* Builds query parameters from list options.
|
|
89
|
+
*/
|
|
90
|
+
private buildListQuery;
|
|
91
|
+
/**
|
|
92
|
+
* Extracts the cursor from a pagination URL.
|
|
93
|
+
*/
|
|
94
|
+
private extractCursor;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=relationships.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../../../src/resources/relationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc;IAI1D;;;;;;;;;;;;;OAaG;IACG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAU3B;;;;;;;;;;;;;;;;OAgBG;IACG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,EAAE,GAC5B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAU3B;;;;;;;;;;;;;;OAcG;IACG,MAAM,CACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,EAAE,GAC5B,OAAO,CAAC,IAAI,CAAC;IAUhB;;;;;;;;;;;;;;;OAeG;IACI,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAClC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC;IAkB/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAgCtB;;OAEG;IACH,OAAO,CAAC,aAAa;CAYtB"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelationshipsResource = void 0;
|
|
4
|
+
const base_resource_js_1 = require("./base-resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* Manages relationships between records.
|
|
7
|
+
*/
|
|
8
|
+
class RelationshipsResource extends base_resource_js_1.BaseResource {
|
|
9
|
+
constructor(httpClient, config) {
|
|
10
|
+
super(httpClient, config);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Lists related records for a given record and relationship.
|
|
14
|
+
*
|
|
15
|
+
* @param entity - The entity type of the source record
|
|
16
|
+
* @param recordId - The ID of the source record
|
|
17
|
+
* @param relationship - The name of the relationship
|
|
18
|
+
* @param options - Pagination and filter options
|
|
19
|
+
* @returns Paginated list of related records
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const people = await clarify.records.relationships.list('company', 'company-id', 'people');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
async list(entity, recordId, relationship, options) {
|
|
27
|
+
const query = this.buildListQuery(options);
|
|
28
|
+
return this.httpClient.request({
|
|
29
|
+
method: 'GET',
|
|
30
|
+
path: `${this.basePath}/records/${entity}/${recordId}/relationships/${relationship}`,
|
|
31
|
+
query,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds relationships between a source record and target records.
|
|
36
|
+
*
|
|
37
|
+
* @param entity - The entity type of the source record
|
|
38
|
+
* @param recordId - The ID of the source record
|
|
39
|
+
* @param relationship - The name of the relationship
|
|
40
|
+
* @param targets - Array of resource identifiers to add
|
|
41
|
+
* @returns The updated list of related records
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* await clarify.records.relationships.add('company', 'company-id', 'people', [
|
|
46
|
+
* { type: 'person', id: 'person-id-1' },
|
|
47
|
+
* { type: 'person', id: 'person-id-2' },
|
|
48
|
+
* ]);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
async add(entity, recordId, relationship, targets) {
|
|
52
|
+
const body = { data: targets };
|
|
53
|
+
return this.httpClient.request({
|
|
54
|
+
method: 'POST',
|
|
55
|
+
path: `${this.basePath}/records/${entity}/${recordId}/relationships/${relationship}`,
|
|
56
|
+
body,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Removes relationships between a source record and target records.
|
|
61
|
+
*
|
|
62
|
+
* @param entity - The entity type of the source record
|
|
63
|
+
* @param recordId - The ID of the source record
|
|
64
|
+
* @param relationship - The name of the relationship
|
|
65
|
+
* @param targets - Array of resource identifiers to remove
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* await clarify.records.relationships.remove('company', 'company-id', 'people', [
|
|
70
|
+
* { type: 'person', id: 'person-id-1' },
|
|
71
|
+
* ]);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async remove(entity, recordId, relationship, targets) {
|
|
75
|
+
const body = { data: targets };
|
|
76
|
+
await this.httpClient.request({
|
|
77
|
+
method: 'DELETE',
|
|
78
|
+
path: `${this.basePath}/records/${entity}/${recordId}/relationships/${relationship}`,
|
|
79
|
+
body,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Async iterator for paginating through all related records.
|
|
84
|
+
*
|
|
85
|
+
* @param entity - The entity type of the source record
|
|
86
|
+
* @param recordId - The ID of the source record
|
|
87
|
+
* @param relationship - The name of the relationship
|
|
88
|
+
* @param options - Filter and sort options (pagination is handled automatically)
|
|
89
|
+
* @yields Individual related records
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* for await (const person of clarify.records.relationships.iterate('company', 'company-id', 'people')) {
|
|
94
|
+
* console.log(person.attributes.name);
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
async *iterate(entity, recordId, relationship, options) {
|
|
99
|
+
let cursor;
|
|
100
|
+
do {
|
|
101
|
+
const response = await this.list(entity, recordId, relationship, {
|
|
102
|
+
...options,
|
|
103
|
+
page: { cursor, limit: 100 },
|
|
104
|
+
});
|
|
105
|
+
for (const record of response.data) {
|
|
106
|
+
yield record;
|
|
107
|
+
}
|
|
108
|
+
// Extract cursor from next link if available
|
|
109
|
+
cursor = this.extractCursor(response.links?.next);
|
|
110
|
+
} while (cursor);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Builds query parameters from list options.
|
|
114
|
+
*/
|
|
115
|
+
buildListQuery(options) {
|
|
116
|
+
const query = {};
|
|
117
|
+
if (options?.page?.cursor) {
|
|
118
|
+
query['page[cursor]'] = options.page.cursor;
|
|
119
|
+
}
|
|
120
|
+
if (options?.page?.limit) {
|
|
121
|
+
query['page[limit]'] = options.page.limit;
|
|
122
|
+
}
|
|
123
|
+
if (options?.filter) {
|
|
124
|
+
for (const [key, value] of Object.entries(options.filter)) {
|
|
125
|
+
if (value !== undefined) {
|
|
126
|
+
query[`filter[${key}]`] = Array.isArray(value)
|
|
127
|
+
? value.join(',')
|
|
128
|
+
: String(value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (options?.sort) {
|
|
133
|
+
const sorts = Array.isArray(options.sort) ? options.sort : [options.sort];
|
|
134
|
+
query['sort'] = sorts
|
|
135
|
+
.map((s) => (s.direction === 'desc' ? `-${s.field}` : s.field))
|
|
136
|
+
.join(',');
|
|
137
|
+
}
|
|
138
|
+
return query;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Extracts the cursor from a pagination URL.
|
|
142
|
+
*/
|
|
143
|
+
extractCursor(url) {
|
|
144
|
+
if (!url) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const parsedUrl = new URL(url);
|
|
149
|
+
return parsedUrl.searchParams.get('page[cursor]') ?? undefined;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.RelationshipsResource = RelationshipsResource;
|
|
157
|
+
//# sourceMappingURL=relationships.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationships.js","sourceRoot":"","sources":["../../../src/resources/relationships.ts"],"names":[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OAAO,CAAC,KAAK,CAAC;wBAC5C,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;wBACjB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1E,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK;iBAClB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;iBAC9D,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,GAAY;QAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAC/B,OAAO,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,SAAS,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAzLD,sDAyLC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { HttpClient } from '../http/http-client.js';
|
|
2
|
+
import type { ListOptions, ListResponse, ResolvedConfig, Resource, ResourceCreate, ResourceUpdate, SingleResponse } from '../types/index.js';
|
|
3
|
+
import { BaseResource } from './base-resource.js';
|
|
4
|
+
/**
|
|
5
|
+
* Task status values.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum TaskStatus {
|
|
8
|
+
Pending = "pending",
|
|
9
|
+
InProgress = "in_progress",
|
|
10
|
+
Completed = "completed",
|
|
11
|
+
Cancelled = "cancelled"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Task priority values.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum TaskPriority {
|
|
17
|
+
Low = "low",
|
|
18
|
+
Medium = "medium",
|
|
19
|
+
High = "high",
|
|
20
|
+
Urgent = "urgent"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Task attributes.
|
|
24
|
+
*/
|
|
25
|
+
export interface TaskAttributes {
|
|
26
|
+
title?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
status?: TaskStatus;
|
|
29
|
+
priority?: TaskPriority;
|
|
30
|
+
due_date?: string;
|
|
31
|
+
assignee_id?: string;
|
|
32
|
+
record_id?: string;
|
|
33
|
+
record_type?: string;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Manages tasks in the Clarify platform.
|
|
38
|
+
*/
|
|
39
|
+
export declare class TasksResource extends BaseResource {
|
|
40
|
+
constructor(httpClient: HttpClient, config: ResolvedConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Lists tasks.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Pagination, filter, and sort options
|
|
45
|
+
* @returns Paginated list of tasks
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const tasks = await clarify.tasks.list({
|
|
50
|
+
* page: { limit: 20 },
|
|
51
|
+
* filter: { status: 'pending', assignee_id: 'user-id' },
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
list<T extends TaskAttributes = TaskAttributes>(options?: ListOptions): Promise<ListResponse<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* Gets a single task by ID.
|
|
58
|
+
*
|
|
59
|
+
* @param id - The task ID
|
|
60
|
+
* @returns The task
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const task = await clarify.tasks.get('task-id');
|
|
65
|
+
* console.log(task.data.attributes.title);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
get<T extends TaskAttributes = TaskAttributes>(id: string): Promise<SingleResponse<T>>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new task.
|
|
71
|
+
*
|
|
72
|
+
* @param data - The task data to create
|
|
73
|
+
* @returns The created task
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const task = await clarify.tasks.create({
|
|
78
|
+
* type: 'task',
|
|
79
|
+
* attributes: {
|
|
80
|
+
* title: 'Follow up with client',
|
|
81
|
+
* description: 'Schedule a demo call',
|
|
82
|
+
* status: TaskStatus.Pending,
|
|
83
|
+
* priority: TaskPriority.High,
|
|
84
|
+
* due_date: '2024-12-31',
|
|
85
|
+
* },
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
create<T extends TaskAttributes = TaskAttributes>(data: ResourceCreate<T>): Promise<SingleResponse<T>>;
|
|
90
|
+
/**
|
|
91
|
+
* Updates an existing task.
|
|
92
|
+
*
|
|
93
|
+
* @param id - The task ID
|
|
94
|
+
* @param data - The task data to update
|
|
95
|
+
* @returns The updated task
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const task = await clarify.tasks.update('task-id', {
|
|
100
|
+
* type: 'task',
|
|
101
|
+
* id: 'task-id',
|
|
102
|
+
* attributes: { status: TaskStatus.Completed },
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
update<T extends TaskAttributes = TaskAttributes>(id: string, data: ResourceUpdate<T>): Promise<SingleResponse<T>>;
|
|
107
|
+
/**
|
|
108
|
+
* Deletes a task.
|
|
109
|
+
*
|
|
110
|
+
* @param id - The task ID
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* await clarify.tasks.delete('task-id');
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
delete(id: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Async iterator for paginating through all tasks.
|
|
120
|
+
*
|
|
121
|
+
* @param options - Filter and sort options (pagination is handled automatically)
|
|
122
|
+
* @yields Individual tasks
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* for await (const task of clarify.tasks.iterate({ filter: { status: 'pending' } })) {
|
|
127
|
+
* console.log(task.attributes.title);
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
iterate<T extends TaskAttributes = TaskAttributes>(options?: Omit<ListOptions, 'page'>): AsyncGenerator<Resource<T>, void, undefined>;
|
|
132
|
+
/**
|
|
133
|
+
* Builds query parameters from list options.
|
|
134
|
+
*/
|
|
135
|
+
private buildListQuery;
|
|
136
|
+
/**
|
|
137
|
+
* Extracts the cursor from a pagination URL.
|
|
138
|
+
*/
|
|
139
|
+
private extractCursor;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=tasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../../src/resources/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAEV,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;AAElD;;GAEG;AACH,oBAAY,UAAU;IACpB,OAAO,YAAY;IACnB,UAAU,gBAA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