@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,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TasksResource = exports.TaskPriority = exports.TaskStatus = void 0;
|
|
4
|
+
const base_resource_js_1 = require("./base-resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* Task status values.
|
|
7
|
+
*/
|
|
8
|
+
var TaskStatus;
|
|
9
|
+
(function (TaskStatus) {
|
|
10
|
+
TaskStatus["Pending"] = "pending";
|
|
11
|
+
TaskStatus["InProgress"] = "in_progress";
|
|
12
|
+
TaskStatus["Completed"] = "completed";
|
|
13
|
+
TaskStatus["Cancelled"] = "cancelled";
|
|
14
|
+
})(TaskStatus || (exports.TaskStatus = TaskStatus = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Task priority values.
|
|
17
|
+
*/
|
|
18
|
+
var TaskPriority;
|
|
19
|
+
(function (TaskPriority) {
|
|
20
|
+
TaskPriority["Low"] = "low";
|
|
21
|
+
TaskPriority["Medium"] = "medium";
|
|
22
|
+
TaskPriority["High"] = "high";
|
|
23
|
+
TaskPriority["Urgent"] = "urgent";
|
|
24
|
+
})(TaskPriority || (exports.TaskPriority = TaskPriority = {}));
|
|
25
|
+
/**
|
|
26
|
+
* Manages tasks in the Clarify platform.
|
|
27
|
+
*/
|
|
28
|
+
class TasksResource extends base_resource_js_1.BaseResource {
|
|
29
|
+
constructor(httpClient, config) {
|
|
30
|
+
super(httpClient, config);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Lists tasks.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Pagination, filter, and sort options
|
|
36
|
+
* @returns Paginated list of tasks
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const tasks = await clarify.tasks.list({
|
|
41
|
+
* page: { limit: 20 },
|
|
42
|
+
* filter: { status: 'pending', assignee_id: 'user-id' },
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
async list(options) {
|
|
47
|
+
const query = this.buildListQuery(options);
|
|
48
|
+
return this.httpClient.request({
|
|
49
|
+
method: 'GET',
|
|
50
|
+
path: `${this.basePath}/tasks`,
|
|
51
|
+
query,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets a single task by ID.
|
|
56
|
+
*
|
|
57
|
+
* @param id - The task ID
|
|
58
|
+
* @returns The task
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const task = await clarify.tasks.get('task-id');
|
|
63
|
+
* console.log(task.data.attributes.title);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async get(id) {
|
|
67
|
+
return this.httpClient.request({
|
|
68
|
+
method: 'GET',
|
|
69
|
+
path: `${this.basePath}/tasks/${id}`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new task.
|
|
74
|
+
*
|
|
75
|
+
* @param data - The task data to create
|
|
76
|
+
* @returns The created task
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const task = await clarify.tasks.create({
|
|
81
|
+
* type: 'task',
|
|
82
|
+
* attributes: {
|
|
83
|
+
* title: 'Follow up with client',
|
|
84
|
+
* description: 'Schedule a demo call',
|
|
85
|
+
* status: TaskStatus.Pending,
|
|
86
|
+
* priority: TaskPriority.High,
|
|
87
|
+
* due_date: '2024-12-31',
|
|
88
|
+
* },
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
async create(data) {
|
|
93
|
+
const body = { data };
|
|
94
|
+
return this.httpClient.request({
|
|
95
|
+
method: 'POST',
|
|
96
|
+
path: `${this.basePath}/tasks`,
|
|
97
|
+
body,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Updates an existing task.
|
|
102
|
+
*
|
|
103
|
+
* @param id - The task ID
|
|
104
|
+
* @param data - The task data to update
|
|
105
|
+
* @returns The updated task
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const task = await clarify.tasks.update('task-id', {
|
|
110
|
+
* type: 'task',
|
|
111
|
+
* id: 'task-id',
|
|
112
|
+
* attributes: { status: TaskStatus.Completed },
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
async update(id, data) {
|
|
117
|
+
const body = { data };
|
|
118
|
+
return this.httpClient.request({
|
|
119
|
+
method: 'PATCH',
|
|
120
|
+
path: `${this.basePath}/tasks/${id}`,
|
|
121
|
+
body,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Deletes a task.
|
|
126
|
+
*
|
|
127
|
+
* @param id - The task ID
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* await clarify.tasks.delete('task-id');
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
async delete(id) {
|
|
135
|
+
await this.httpClient.request({
|
|
136
|
+
method: 'DELETE',
|
|
137
|
+
path: `${this.basePath}/tasks/${id}`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Async iterator for paginating through all tasks.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Filter and sort options (pagination is handled automatically)
|
|
144
|
+
* @yields Individual tasks
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* for await (const task of clarify.tasks.iterate({ filter: { status: 'pending' } })) {
|
|
149
|
+
* console.log(task.attributes.title);
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
async *iterate(options) {
|
|
154
|
+
let cursor;
|
|
155
|
+
do {
|
|
156
|
+
const response = await this.list({
|
|
157
|
+
...options,
|
|
158
|
+
page: { cursor, limit: 100 },
|
|
159
|
+
});
|
|
160
|
+
for (const task of response.data) {
|
|
161
|
+
yield task;
|
|
162
|
+
}
|
|
163
|
+
cursor = this.extractCursor(response.links?.next);
|
|
164
|
+
} while (cursor);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Builds query parameters from list options.
|
|
168
|
+
*/
|
|
169
|
+
buildListQuery(options) {
|
|
170
|
+
const query = {};
|
|
171
|
+
if (options?.page?.cursor) {
|
|
172
|
+
query['page[cursor]'] = options.page.cursor;
|
|
173
|
+
}
|
|
174
|
+
if (options?.page?.limit) {
|
|
175
|
+
query['page[limit]'] = options.page.limit;
|
|
176
|
+
}
|
|
177
|
+
if (options?.filter) {
|
|
178
|
+
for (const [key, value] of Object.entries(options.filter)) {
|
|
179
|
+
if (value !== undefined) {
|
|
180
|
+
query[`filter[${key}]`] = Array.isArray(value)
|
|
181
|
+
? value.join(',')
|
|
182
|
+
: String(value);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (options?.sort) {
|
|
187
|
+
const sorts = Array.isArray(options.sort) ? options.sort : [options.sort];
|
|
188
|
+
query['sort'] = sorts
|
|
189
|
+
.map((s) => (s.direction === 'desc' ? `-${s.field}` : s.field))
|
|
190
|
+
.join(',');
|
|
191
|
+
}
|
|
192
|
+
return query;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Extracts the cursor from a pagination URL.
|
|
196
|
+
*/
|
|
197
|
+
extractCursor(url) {
|
|
198
|
+
if (!url) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const parsedUrl = new URL(url);
|
|
203
|
+
return parsedUrl.searchParams.get('page[cursor]') ?? undefined;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.TasksResource = TasksResource;
|
|
211
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../../src/resources/tasks.ts"],"names":[],"mappings":";;;AAYA,yDAAkD;AAElD;;GAEG;AACH,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,wCAA0B,CAAA;IAC1B,qCAAuB,CAAA;IACvB,qCAAuB,CAAA;AACzB,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAED;;GAEG;AACH,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,iCAAiB,CAAA;IACjB,6BAAa,CAAA;IACb,iCAAiB,CAAA;AACnB,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAiBD;;GAEG;AACH,MAAa,aAAc,SAAQ,+BAAY;IAC7C,YAAY,UAAsB,EAAE,MAAsB;QACxD,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,IAAI,CACR,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,QAAQ;YAC9B,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,GAAG,CACP,EAAU;QAEV,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAoB;YAChD,MAAM,EAAE,KAAK;YACb,IAA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AS,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;AApND,sCAoNC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON:API resource identifier.
|
|
3
|
+
*/
|
|
4
|
+
export interface ResourceIdentifier {
|
|
5
|
+
type: string;
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* JSON:API resource object with attributes.
|
|
10
|
+
*/
|
|
11
|
+
export interface Resource<T = Record<string, unknown>> {
|
|
12
|
+
type: string;
|
|
13
|
+
id: string;
|
|
14
|
+
attributes: T;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* JSON:API resource for creation (no id required).
|
|
18
|
+
*/
|
|
19
|
+
export interface ResourceCreate<T = Record<string, unknown>> {
|
|
20
|
+
type: string;
|
|
21
|
+
attributes: T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* JSON:API resource for update.
|
|
25
|
+
*/
|
|
26
|
+
export interface ResourceUpdate<T = Record<string, unknown>> {
|
|
27
|
+
type: string;
|
|
28
|
+
id: string;
|
|
29
|
+
attributes: Partial<T>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* JSON:API single resource response.
|
|
33
|
+
*/
|
|
34
|
+
export interface SingleResponse<T = Record<string, unknown>> {
|
|
35
|
+
data: Resource<T>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* JSON:API paginated list response.
|
|
39
|
+
*/
|
|
40
|
+
export interface ListResponse<T = Record<string, unknown>> {
|
|
41
|
+
data: Resource<T>[];
|
|
42
|
+
links?: PaginationLinks;
|
|
43
|
+
meta?: PaginationMeta;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* JSON:API pagination links.
|
|
47
|
+
*/
|
|
48
|
+
export interface PaginationLinks {
|
|
49
|
+
first?: string;
|
|
50
|
+
last?: string;
|
|
51
|
+
prev?: string;
|
|
52
|
+
next?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* JSON:API pagination metadata.
|
|
56
|
+
*/
|
|
57
|
+
export interface PaginationMeta {
|
|
58
|
+
total_records?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Pagination options for list requests.
|
|
62
|
+
*/
|
|
63
|
+
export interface PaginationOptions {
|
|
64
|
+
/** Page cursor for cursor-based pagination */
|
|
65
|
+
cursor?: string;
|
|
66
|
+
/** Maximum number of records to return (default: 20, max: 100) */
|
|
67
|
+
limit?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Filter options for list requests.
|
|
71
|
+
*/
|
|
72
|
+
export interface FilterOptions {
|
|
73
|
+
[key: string]: string | number | boolean | string[] | undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sort options for list requests.
|
|
77
|
+
*/
|
|
78
|
+
export interface SortOptions {
|
|
79
|
+
/** Field to sort by */
|
|
80
|
+
field: string;
|
|
81
|
+
/** Sort direction */
|
|
82
|
+
direction: 'asc' | 'desc';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Common list request options.
|
|
86
|
+
*/
|
|
87
|
+
export interface ListOptions {
|
|
88
|
+
page?: PaginationOptions;
|
|
89
|
+
filter?: FilterOptions;
|
|
90
|
+
sort?: SortOptions | SortOptions[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Request body for creating a single resource.
|
|
94
|
+
*/
|
|
95
|
+
export interface CreateBody<T = Record<string, unknown>> {
|
|
96
|
+
data: ResourceCreate<T>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Request body for updating a single resource.
|
|
100
|
+
*/
|
|
101
|
+
export interface UpdateBody<T = Record<string, unknown>> {
|
|
102
|
+
data: ResourceUpdate<T>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Request body for bulk create operations.
|
|
106
|
+
*/
|
|
107
|
+
export interface BulkCreateBody<T = Record<string, unknown>> {
|
|
108
|
+
data: ResourceCreate<T>[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Request body for bulk update operations.
|
|
112
|
+
*/
|
|
113
|
+
export interface BulkUpdateBody<T = Record<string, unknown>> {
|
|
114
|
+
data: ResourceUpdate<T>[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Request body for bulk delete operations.
|
|
118
|
+
*/
|
|
119
|
+
export interface BulkDeleteBody {
|
|
120
|
+
data: ResourceIdentifier[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* HTTP methods supported by the SDK.
|
|
124
|
+
*/
|
|
125
|
+
export type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
126
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,G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QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/types/common.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the Clarify SDK client.
|
|
3
|
+
*/
|
|
4
|
+
export interface ClarifyClientConfig {
|
|
5
|
+
/** Base URL for the Clarify API (e.g., 'https://api.clarify.ai') */
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
/** API key for authentication (format: 'clrfy_sk_...') */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/** Workspace slug for API calls */
|
|
10
|
+
workspace: string;
|
|
11
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
12
|
+
timeout?: number;
|
|
13
|
+
/** Number of retry attempts for failed requests (default: 3) */
|
|
14
|
+
retries?: number;
|
|
15
|
+
/** Custom fetch implementation (default: global fetch) */
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Internal resolved configuration with all defaults applied.
|
|
20
|
+
*/
|
|
21
|
+
export interface ResolvedConfig {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
apiKey: string;
|
|
24
|
+
workspace: string;
|
|
25
|
+
timeout: number;
|
|
26
|
+
retries: number;
|
|
27
|
+
fetch: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Default configuration values.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_CONFIG: {
|
|
33
|
+
readonly timeout: 30000;
|
|
34
|
+
readonly retries: 3;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAEhB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IAEf,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAElB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;CAGjB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration values.
|
|
6
|
+
*/
|
|
7
|
+
exports.DEFAULT_CONFIG = {
|
|
8
|
+
timeout: 30000,
|
|
9
|
+
retries: 3,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":";;;AAmCA;;GAEG;AACU,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { ClarifyClientConfig, ResolvedConfig, } from './config.js';
|
|
2
|
+
export { DEFAULT_CONFIG } from './config.js';
|
|
3
|
+
export type { ResourceIdentifier, Resource, ResourceCreate, ResourceUpdate, SingleResponse, ListResponse, PaginationLinks, PaginationMeta, PaginationOptions, FilterOptions, SortOptions, ListOptions, CreateBody, UpdateBody, BulkCreateBody, BulkUpdateBody, BulkDeleteBody, HttpMethod, } from './common.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,mBAAmB,EACnB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACV,UAAU,EACV,cAAc,EACd,cAAc,EACd,cAAc,EACd,UAAU,GACX,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
4
|
+
var config_js_1 = require("./config.js");
|
|
5
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return config_js_1.DEFAULT_CONFIG; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":";;;AAKA,yCAA6C;AAApC,2GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MessagesResource } from './resources/messages.js';
|
|
2
|
+
import { RecordsResource } from './resources/records.js';
|
|
3
|
+
import { TasksResource } from './resources/tasks.js';
|
|
4
|
+
import type { ClarifyClientConfig } from './types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* The main client for interacting with the Clarify API.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { ClarifyClient } from '@clarify/sdk';
|
|
11
|
+
*
|
|
12
|
+
* const clarify = new ClarifyClient({
|
|
13
|
+
* baseUrl: 'https://api.clarify.ai',
|
|
14
|
+
* apiKey: 'clrfy_sk_...',
|
|
15
|
+
* workspace: 'my-workspace',
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // List companies
|
|
19
|
+
* const companies = await clarify.records.list('company');
|
|
20
|
+
*
|
|
21
|
+
* // Create a new company
|
|
22
|
+
* const company = await clarify.records.create('company', {
|
|
23
|
+
* type: 'company',
|
|
24
|
+
* attributes: { name: 'Acme Inc.' },
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Iterate through all records
|
|
28
|
+
* for await (const company of clarify.records.iterate('company')) {
|
|
29
|
+
* console.log(company.attributes.name);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class ClarifyClient {
|
|
34
|
+
/** Resource for managing records */
|
|
35
|
+
readonly records: RecordsResource;
|
|
36
|
+
/** Resource for managing messages */
|
|
37
|
+
readonly messages: MessagesResource;
|
|
38
|
+
/** Resource for managing tasks */
|
|
39
|
+
readonly tasks: TasksResource;
|
|
40
|
+
private readonly config;
|
|
41
|
+
private readonly httpClient;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new Clarify client instance.
|
|
44
|
+
*
|
|
45
|
+
* @param config - Client configuration
|
|
46
|
+
* @throws {ClarifyValidationError} If required configuration is missing
|
|
47
|
+
*/
|
|
48
|
+
constructor(config: ClarifyClientConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Resolves configuration with defaults and validates required fields.
|
|
51
|
+
*/
|
|
52
|
+
private resolveConfig;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,kBAAkB,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,aAAa;IACxB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAElC,qCAAqC;IACrC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAE9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;;;OAKG;gBACS,MAAM,EAAE,mBAAmB;IASvC;;OAEG;IACH,OAAO,CAAC,aAAa;CA+BtB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClarifyClient = void 0;
|
|
4
|
+
const index_js_1 = require("./errors/index.js");
|
|
5
|
+
const http_client_js_1 = require("./http/http-client.js");
|
|
6
|
+
const messages_js_1 = require("./resources/messages.js");
|
|
7
|
+
const records_js_1 = require("./resources/records.js");
|
|
8
|
+
const tasks_js_1 = require("./resources/tasks.js");
|
|
9
|
+
const index_js_2 = require("./types/index.js");
|
|
10
|
+
/**
|
|
11
|
+
* The main client for interacting with the Clarify API.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { ClarifyClient } from '@clarify/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const clarify = new ClarifyClient({
|
|
18
|
+
* baseUrl: 'https://api.clarify.ai',
|
|
19
|
+
* apiKey: 'clrfy_sk_...',
|
|
20
|
+
* workspace: 'my-workspace',
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // List companies
|
|
24
|
+
* const companies = await clarify.records.list('company');
|
|
25
|
+
*
|
|
26
|
+
* // Create a new company
|
|
27
|
+
* const company = await clarify.records.create('company', {
|
|
28
|
+
* type: 'company',
|
|
29
|
+
* attributes: { name: 'Acme Inc.' },
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Iterate through all records
|
|
33
|
+
* for await (const company of clarify.records.iterate('company')) {
|
|
34
|
+
* console.log(company.attributes.name);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
class ClarifyClient {
|
|
39
|
+
/** Resource for managing records */
|
|
40
|
+
records;
|
|
41
|
+
/** Resource for managing messages */
|
|
42
|
+
messages;
|
|
43
|
+
/** Resource for managing tasks */
|
|
44
|
+
tasks;
|
|
45
|
+
config;
|
|
46
|
+
httpClient;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new Clarify client instance.
|
|
49
|
+
*
|
|
50
|
+
* @param config - Client configuration
|
|
51
|
+
* @throws {ClarifyValidationError} If required configuration is missing
|
|
52
|
+
*/
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = this.resolveConfig(config);
|
|
55
|
+
this.httpClient = new http_client_js_1.HttpClient(this.config);
|
|
56
|
+
this.records = new records_js_1.RecordsResource(this.httpClient, this.config);
|
|
57
|
+
this.messages = new messages_js_1.MessagesResource(this.httpClient, this.config);
|
|
58
|
+
this.tasks = new tasks_js_1.TasksResource(this.httpClient, this.config);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolves configuration with defaults and validates required fields.
|
|
62
|
+
*/
|
|
63
|
+
resolveConfig(config) {
|
|
64
|
+
const errors = {};
|
|
65
|
+
if (!config.baseUrl) {
|
|
66
|
+
errors['baseUrl'] = ['baseUrl is required'];
|
|
67
|
+
}
|
|
68
|
+
if (!config.apiKey) {
|
|
69
|
+
errors['apiKey'] = ['apiKey is required'];
|
|
70
|
+
}
|
|
71
|
+
if (!config.workspace) {
|
|
72
|
+
errors['workspace'] = ['workspace is required'];
|
|
73
|
+
}
|
|
74
|
+
if (Object.keys(errors).length > 0) {
|
|
75
|
+
throw new index_js_1.ClarifyValidationError('Invalid client configuration', errors);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
baseUrl: config.baseUrl,
|
|
79
|
+
apiKey: config.apiKey,
|
|
80
|
+
workspace: config.workspace,
|
|
81
|
+
timeout: config.timeout ?? index_js_2.DEFAULT_CONFIG.timeout,
|
|
82
|
+
retries: config.retries ?? index_js_2.DEFAULT_CONFIG.retries,
|
|
83
|
+
fetch: config.fetch ?? globalThis.fetch.bind(globalThis),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ClarifyClient = ClarifyClient;
|
|
88
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,gDAA2D;AAC3D,0DAAmD;AACnD,yDAA2D;AAC3D,uDAAyD;AACzD,mDAAqD;AAErD,+CAAkD;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAa,aAAa;IACxB,oCAAoC;IAC3B,OAAO,CAAkB;IAElC,qCAAqC;IAC5B,QAAQ,CAAmB;IAEpC,kCAAkC;IACzB,KAAK,CAAgB;IAEb,MAAM,CAAiB;IACvB,UAAU,CAAa;IAExC;;;;;OAKG;IACH,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,IAAI,2BAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE9C,IAAI,CAAC,OAAO,GAAG,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C;SACzD,CAAC;IACJ,CAAC;CACF;AA9DD,sCA8DC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Clarify SDK errors.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ClarifyError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Error details from the API response.
|
|
9
|
+
*/
|
|
10
|
+
export interface ApiErrorDetail {
|
|
11
|
+
code?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
detail?: string;
|
|
14
|
+
source?: {
|
|
15
|
+
pointer?: string;
|
|
16
|
+
parameter?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error thrown when the API returns an error response.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ClarifyApiError extends ClarifyError {
|
|
23
|
+
/** HTTP status code */
|
|
24
|
+
readonly status: number;
|
|
25
|
+
/** Error details from the API response */
|
|
26
|
+
readonly errors: ApiErrorDetail[];
|
|
27
|
+
/** Original response body */
|
|
28
|
+
readonly body: unknown;
|
|
29
|
+
constructor(message: string, status: number, errors?: ApiErrorDetail[], body?: unknown);
|
|
30
|
+
/**
|
|
31
|
+
* Creates an ApiError from an HTTP response.
|
|
32
|
+
*/
|
|
33
|
+
static fromResponse(response: Response): Promise<ClarifyApiError>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when input validation fails.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ClarifyValidationError extends ClarifyError {
|
|
39
|
+
/** Validation error details */
|
|
40
|
+
readonly details: Record<string, string[]>;
|
|
41
|
+
constructor(message: string, details?: Record<string, string[]>);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Error thrown when a request times out.
|
|
45
|
+
*/
|
|
46
|
+
export declare class ClarifyTimeoutError extends ClarifyError {
|
|
47
|
+
/** Timeout duration in milliseconds */
|
|
48
|
+
readonly timeout: number;
|
|
49
|
+
constructor(timeout: number);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Error thrown when a network error occurs.
|
|
53
|
+
*/
|
|
54
|
+
export declare class ClarifyNetworkError extends ClarifyError {
|
|
55
|
+
/** Original error that caused the network failure */
|
|
56
|
+
readonly cause: Error;
|
|
57
|
+
constructor(message: string, cause: Error);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=api-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error.d.ts","sourceRoot":"","sources":["../../../src/errors/api-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAQ5B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,uBAAuB;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IAElC,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,cAAc,EAAO,EAC7B,IAAI,CAAC,EAAE,OAAO;IAShB;;OAEG;WACU,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;CA2BxE;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,YAAY;IACtD,+BAA+B;IAC/B,QAAQ,CAAC,OAAO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