@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,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;;;;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AAC;YACnC,MAAM,IAAI,iCAAsB,CAC9B,8BAA8B,EAC9B,MAAM,CACP,CAAC;QACJ,CAAC;QAED,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,yBAAc,CAAC,OAAO;YACjD,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,yBAAc,CAAC,OAAO;YACjD,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;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,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBAE/B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;CAKpE;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAK1C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClarifyNetworkError = exports.ClarifyTimeoutError = exports.ClarifyValidationError = exports.ClarifyApiError = exports.ClarifyError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for all Clarify SDK errors.
|
|
6
|
+
*/
|
|
7
|
+
class ClarifyError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ClarifyError';
|
|
11
|
+
// Maintains proper stack trace for where error was thrown (only available on V8)
|
|
12
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
13
|
+
Error.captureStackTrace(this, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ClarifyError = ClarifyError;
|
|
18
|
+
/**
|
|
19
|
+
* Error thrown when the API returns an error response.
|
|
20
|
+
*/
|
|
21
|
+
class ClarifyApiError extends ClarifyError {
|
|
22
|
+
/** HTTP status code */
|
|
23
|
+
status;
|
|
24
|
+
/** Error details from the API response */
|
|
25
|
+
errors;
|
|
26
|
+
/** Original response body */
|
|
27
|
+
body;
|
|
28
|
+
constructor(message, status, errors = [], body) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = 'ClarifyApiError';
|
|
31
|
+
this.status = status;
|
|
32
|
+
this.errors = errors;
|
|
33
|
+
this.body = body;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates an ApiError from an HTTP response.
|
|
37
|
+
*/
|
|
38
|
+
static async fromResponse(response) {
|
|
39
|
+
let body;
|
|
40
|
+
let errors = [];
|
|
41
|
+
let message = `API request failed with status ${response.status}`;
|
|
42
|
+
try {
|
|
43
|
+
body = await response.json();
|
|
44
|
+
if (body &&
|
|
45
|
+
typeof body === 'object' &&
|
|
46
|
+
'errors' in body &&
|
|
47
|
+
Array.isArray(body.errors)) {
|
|
48
|
+
errors = body.errors;
|
|
49
|
+
const firstError = errors[0];
|
|
50
|
+
if (firstError?.detail) {
|
|
51
|
+
message = firstError.detail;
|
|
52
|
+
}
|
|
53
|
+
else if (firstError?.title) {
|
|
54
|
+
message = firstError.title;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Response body is not JSON, use default message
|
|
60
|
+
}
|
|
61
|
+
return new ClarifyApiError(message, response.status, errors, body);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ClarifyApiError = ClarifyApiError;
|
|
65
|
+
/**
|
|
66
|
+
* Error thrown when input validation fails.
|
|
67
|
+
*/
|
|
68
|
+
class ClarifyValidationError extends ClarifyError {
|
|
69
|
+
/** Validation error details */
|
|
70
|
+
details;
|
|
71
|
+
constructor(message, details = {}) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = 'ClarifyValidationError';
|
|
74
|
+
this.details = details;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.ClarifyValidationError = ClarifyValidationError;
|
|
78
|
+
/**
|
|
79
|
+
* Error thrown when a request times out.
|
|
80
|
+
*/
|
|
81
|
+
class ClarifyTimeoutError extends ClarifyError {
|
|
82
|
+
/** Timeout duration in milliseconds */
|
|
83
|
+
timeout;
|
|
84
|
+
constructor(timeout) {
|
|
85
|
+
super(`Request timed out after ${timeout}ms`);
|
|
86
|
+
this.name = 'ClarifyTimeoutError';
|
|
87
|
+
this.timeout = timeout;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.ClarifyTimeoutError = ClarifyTimeoutError;
|
|
91
|
+
/**
|
|
92
|
+
* Error thrown when a network error occurs.
|
|
93
|
+
*/
|
|
94
|
+
class ClarifyNetworkError extends ClarifyError {
|
|
95
|
+
/** Original error that caused the network failure */
|
|
96
|
+
cause;
|
|
97
|
+
constructor(message, cause) {
|
|
98
|
+
super(message);
|
|
99
|
+
this.name = 'ClarifyNetworkError';
|
|
100
|
+
this.cause = cause;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.ClarifyNetworkError = ClarifyNetworkError;
|
|
104
|
+
//# sourceMappingURL=api-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error.js","sourceRoot":"","sources":["../../../src/errors/api-error.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,i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nB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClarifyNetworkError = exports.ClarifyTimeoutError = exports.ClarifyValidationError = exports.ClarifyApiError = exports.ClarifyError = void 0;
|
|
4
|
+
var api_error_js_1 = require("./api-error.js");
|
|
5
|
+
Object.defineProperty(exports, "ClarifyError", { enumerable: true, get: function () { return api_error_js_1.ClarifyError; } });
|
|
6
|
+
Object.defineProperty(exports, "ClarifyApiError", { enumerable: true, get: function () { return api_error_js_1.ClarifyApiError; } });
|
|
7
|
+
Object.defineProperty(exports, "ClarifyValidationError", { enumerable: true, get: function () { return api_error_js_1.ClarifyValidationError; } });
|
|
8
|
+
Object.defineProperty(exports, "ClarifyTimeoutError", { enumerable: true, get: function () { return api_error_js_1.ClarifyTimeoutError; } });
|
|
9
|
+
Object.defineProperty(exports, "ClarifyNetworkError", { enumerable: true, get: function () { return api_error_js_1.ClarifyNetworkError; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,+CAMwB;AALtB,4GAAA,YAAY,OAAA;AACZ,+GAAA,eAAe,OAAA;AACf,sHAAA,sBAAsB,OAAA;AACtB,mHAAA,mBAAmB,OAAA;AACnB,mHAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { HttpMethod, ResolvedConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Request options for the HTTP client.
|
|
4
|
+
*/
|
|
5
|
+
export interface HttpRequestOptions {
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
path: string;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
query?: Record<string, string | number | boolean | string[] | undefined>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* HTTP client with retry logic and timeout handling.
|
|
13
|
+
*/
|
|
14
|
+
export declare class HttpClient {
|
|
15
|
+
private readonly config;
|
|
16
|
+
constructor(config: ResolvedConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Makes an HTTP request to the Clarify API.
|
|
19
|
+
*/
|
|
20
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Builds the full URL including query parameters.
|
|
23
|
+
*/
|
|
24
|
+
private buildUrl;
|
|
25
|
+
/**
|
|
26
|
+
* Builds the request headers.
|
|
27
|
+
*/
|
|
28
|
+
private buildHeaders;
|
|
29
|
+
/**
|
|
30
|
+
* Executes a request with retry logic for transient failures.
|
|
31
|
+
*/
|
|
32
|
+
private executeWithRetry;
|
|
33
|
+
/**
|
|
34
|
+
* Executes a single HTTP request with timeout.
|
|
35
|
+
*/
|
|
36
|
+
private executeRequest;
|
|
37
|
+
/**
|
|
38
|
+
* Calculates exponential backoff delay with jitter.
|
|
39
|
+
*/
|
|
40
|
+
private calculateBackoff;
|
|
41
|
+
/**
|
|
42
|
+
* Sleeps for the specified duration.
|
|
43
|
+
*/
|
|
44
|
+
private sleep;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../../src/http/http-client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;CAC1E;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;gBAE5B,MAAM,EAAE,cAAc;IAIlC;;OAEG;IACG,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAezD;;OAEG;IACH,OAAO,CAAC,QAAQ;IAyBhB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;YACW,gBAAgB;IAiC9B;;OAEG;YACW,cAAc;IA6C5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const index_js_1 = require("../errors/index.js");
|
|
5
|
+
/**
|
|
6
|
+
* HTTP client with retry logic and timeout handling.
|
|
7
|
+
*/
|
|
8
|
+
class HttpClient {
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Makes an HTTP request to the Clarify API.
|
|
15
|
+
*/
|
|
16
|
+
async request(options) {
|
|
17
|
+
const url = this.buildUrl(options.path, options.query);
|
|
18
|
+
const headers = this.buildHeaders();
|
|
19
|
+
const requestInit = {
|
|
20
|
+
method: options.method,
|
|
21
|
+
headers,
|
|
22
|
+
};
|
|
23
|
+
if (options.body !== undefined) {
|
|
24
|
+
requestInit.body = JSON.stringify(options.body);
|
|
25
|
+
}
|
|
26
|
+
return this.executeWithRetry(url, requestInit);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Builds the full URL including query parameters.
|
|
30
|
+
*/
|
|
31
|
+
buildUrl(path, query) {
|
|
32
|
+
const baseUrl = this.config.baseUrl.replace(/\/$/, '');
|
|
33
|
+
const url = new URL(`${baseUrl}${path}`);
|
|
34
|
+
if (query) {
|
|
35
|
+
for (const [key, value] of Object.entries(query)) {
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
for (const v of value) {
|
|
41
|
+
url.searchParams.append(`${key}[]`, v);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
url.searchParams.set(key, String(value));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return url.toString();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds the request headers.
|
|
53
|
+
*/
|
|
54
|
+
buildHeaders() {
|
|
55
|
+
return {
|
|
56
|
+
'Content-Type': 'application/vnd.api+json',
|
|
57
|
+
Accept: 'application/vnd.api+json',
|
|
58
|
+
Authorization: `api-key ${this.config.apiKey}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Executes a request with retry logic for transient failures.
|
|
63
|
+
*/
|
|
64
|
+
async executeWithRetry(url, requestInit) {
|
|
65
|
+
let lastError;
|
|
66
|
+
for (let attempt = 0; attempt <= this.config.retries; attempt++) {
|
|
67
|
+
try {
|
|
68
|
+
return await this.executeRequest(url, requestInit);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
lastError = error;
|
|
72
|
+
// Don't retry client errors (4xx) or validation errors
|
|
73
|
+
if (error instanceof index_js_1.ClarifyApiError && error.status < 500) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
// Don't retry timeout errors
|
|
77
|
+
if (error instanceof index_js_1.ClarifyTimeoutError) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
// Retry server errors (5xx) and network errors
|
|
81
|
+
if (attempt < this.config.retries) {
|
|
82
|
+
const delay = this.calculateBackoff(attempt);
|
|
83
|
+
await this.sleep(delay);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw lastError;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Executes a single HTTP request with timeout.
|
|
91
|
+
*/
|
|
92
|
+
async executeRequest(url, requestInit) {
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
95
|
+
try {
|
|
96
|
+
const response = await this.config.fetch(url, {
|
|
97
|
+
...requestInit,
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw await index_js_1.ClarifyApiError.fromResponse(response);
|
|
102
|
+
}
|
|
103
|
+
// Handle 204 No Content responses
|
|
104
|
+
if (response.status === 204) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
return (await response.json());
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof index_js_1.ClarifyApiError) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
if (error instanceof Error) {
|
|
114
|
+
if (error.name === 'AbortError') {
|
|
115
|
+
throw new index_js_1.ClarifyTimeoutError(this.config.timeout);
|
|
116
|
+
}
|
|
117
|
+
throw new index_js_1.ClarifyNetworkError(`Network request failed: ${error.message}`, error);
|
|
118
|
+
}
|
|
119
|
+
throw new index_js_1.ClarifyNetworkError('Unknown network error', new Error(String(error)));
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
clearTimeout(timeoutId);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Calculates exponential backoff delay with jitter.
|
|
127
|
+
*/
|
|
128
|
+
calculateBackoff(attempt) {
|
|
129
|
+
// Base delay of 1 second, exponentially increasing
|
|
130
|
+
const baseDelay = 1000;
|
|
131
|
+
const maxDelay = 30000;
|
|
132
|
+
const exponentialDelay = baseDelay * Math.pow(2, attempt);
|
|
133
|
+
// Add jitter (0-50% of the delay)
|
|
134
|
+
const jitter = exponentialDelay * Math.random() * 0.5;
|
|
135
|
+
return Math.min(exponentialDelay + jitter, maxDelay);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Sleeps for the specified duration.
|
|
139
|
+
*/
|
|
140
|
+
sleep(ms) {
|
|
141
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.HttpClient = HttpClient;
|
|
145
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../../src/http/http-client.ts"],"names":[],"mappings":";;;AAAA,iDAI4B;AAa5B;;GAEG;AACH,MAAa,UAAU;IACJ,MAAM,CAAiB;IAExC,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAI,OAA2B;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACvD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACpC,MAAM,WAAW,GAAgB;YAC/B,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO;SACR,CAAC;QAEF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAI,GAAG,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACK,QAAQ,CACd,IAAY,EACZ,KAAwE;QAExE,MAAM,OAAO,GAAG,IAAI,CAAC,M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AuKC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ClarifyClient } from './client.js';
|
|
2
|
+
export { ClarifyError, ClarifyApiError, ClarifyValidationError, ClarifyTimeoutError, ClarifyNetworkError, } from './errors/index.js';
|
|
3
|
+
export type { ApiErrorDetail } from './errors/index.js';
|
|
4
|
+
export type { ClarifyClientConfig, ResourceIdentifier, Resource, ResourceCreate, ResourceUpdate, SingleResponse, ListResponse, PaginationLinks, PaginationMeta, PaginationOptions, FilterOptions, SortOptions, ListOptions, } from './types/index.js';
|
|
5
|
+
export { RecordsResource } from './resources/records.js';
|
|
6
|
+
export { RelationshipsResource } from './resources/relationships.js';
|
|
7
|
+
export { MessagesResource, type MessageAttributes } from './resources/messages.js';
|
|
8
|
+
export { TasksResource, TaskStatus, TaskPriority, type TaskAttributes, } from './resources/tasks.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
// Main client export
|
|
5
|
+
var client_js_1 = require("./client.js");
|
|
6
|
+
Object.defineProperty(exports, "ClarifyClient", { enumerable: true, get: function () { return client_js_1.ClarifyClient; } });
|
|
7
|
+
// Error exports
|
|
8
|
+
var index_js_1 = require("./errors/index.js");
|
|
9
|
+
Object.defineProperty(exports, "ClarifyError", { enumerable: true, get: function () { return index_js_1.ClarifyError; } });
|
|
10
|
+
Object.defineProperty(exports, "ClarifyApiError", { enumerable: true, get: function () { return index_js_1.ClarifyApiError; } });
|
|
11
|
+
Object.defineProperty(exports, "ClarifyValidationError", { enumerable: true, get: function () { return index_js_1.ClarifyValidationError; } });
|
|
12
|
+
Object.defineProperty(exports, "ClarifyTimeoutError", { enumerable: true, get: function () { return index_js_1.ClarifyTimeoutError; } });
|
|
13
|
+
Object.defineProperty(exports, "ClarifyNetworkError", { enumerable: true, get: function () { return index_js_1.ClarifyNetworkError; } });
|
|
14
|
+
// Resource exports for advanced usage
|
|
15
|
+
var records_js_1 = require("./resources/records.js");
|
|
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
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HttpClient } from '../http/http-client.js';
|
|
2
|
+
import type { ResolvedConfig } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base class for API resources providing access to the HTTP client and configuration.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseResource {
|
|
7
|
+
protected readonly httpClient: HttpClient;
|
|
8
|
+
protected readonly config: ResolvedConfig;
|
|
9
|
+
constructor(httpClient: HttpClient, config: ResolvedConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Gets the workspace-prefixed base path for API endpoints.
|
|
12
|
+
*/
|
|
13
|
+
protected get basePath(): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=base-resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-resource.d.ts","sourceRoot":"","sources":["../../../src/resources/base-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,8BAAsB,YAAY;IAChC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAC1C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;gBAE9B,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc;IAK1D;;OAEG;IACH,SAAS,KAAK,QAAQ,IAAI,MAAM,CAE/B;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseResource = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base class for API resources providing access to the HTTP client and configuration.
|
|
6
|
+
*/
|
|
7
|
+
class BaseResource {
|
|
8
|
+
httpClient;
|
|
9
|
+
config;
|
|
10
|
+
constructor(httpClient, config) {
|
|
11
|
+
this.httpClient = httpClient;
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Gets the workspace-prefixed base path for API endpoints.
|
|
16
|
+
*/
|
|
17
|
+
get basePath() {
|
|
18
|
+
return `/api/${this.config.workspace}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.BaseResource = BaseResource;
|
|
22
|
+
//# sourceMappingURL=base-resource.js.map
|
|
@@ -0,0 +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"}
|