@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,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,iFAAiF;QACjF,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YAClD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AATD,oCASC;AAeD;;GAEG;AACH,MAAa,eAAgB,SAAQ,YAAY;IAC/C,uBAAuB;IACd,MAAM,CAAS;IAExB,0CAA0C;IACjC,MAAM,CAAmB;IAElC,6BAA6B;IACpB,IAAI,CAAU;IAEvB,YACE,OAAe,EACf,MAAc,EACd,SAA2B,EAAE,EAC7B,IAAc;QAEd,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,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A2B,OAAO,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AATD,kDASC;AAED;;GAEG;AACH,MAAa,mBAAoB,SAAQ,YAAY;IACnD,qDAAqD;IAC5C,KAAK,CAAQ;IAEtB,YAAY,OAAe,EAAE,KAAY;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AATD,kDASC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,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,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;OAEG;IACK,gBAAgB,CAAC,OAAe;QACtC,mDAAmD;QACnD,MAAM,SAAS,GAAG,IAAI,CAAC;QACvB,MAAM,QAAQ,GAAG,KAAK,CAAC;QACvB,MAAM,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC1D,kCAAkC;QAClC,MAAM,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;QACtD,OAAO,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,MAAM,EAAE,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAvKD,gCAuKC"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { HttpClient } from '../http/http-client.js';
|
|
2
|
+
import type { ListOptions, ListResponse, ResolvedConfig, Resource, ResourceCreate, SingleResponse } from '../types/index.js';
|
|
3
|
+
import { BaseResource } from './base-resource.js';
|
|
4
|
+
/**
|
|
5
|
+
* Message attributes.
|
|
6
|
+
*/
|
|
7
|
+
export interface MessageAttributes {
|
|
8
|
+
subject?: string;
|
|
9
|
+
body?: string;
|
|
10
|
+
from?: string;
|
|
11
|
+
to?: string[];
|
|
12
|
+
cc?: string[];
|
|
13
|
+
bcc?: string[];
|
|
14
|
+
sent_at?: string;
|
|
15
|
+
received_at?: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Manages messages in the Clarify platform.
|
|
20
|
+
*/
|
|
21
|
+
export declare class MessagesResource extends BaseResource {
|
|
22
|
+
constructor(httpClient: HttpClient, config: ResolvedConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Lists messages.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Pagination, filter, and sort options
|
|
27
|
+
* @returns Paginated list of messages
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const messages = await clarify.messages.list({
|
|
32
|
+
* page: { limit: 20 },
|
|
33
|
+
* filter: { from: 'user@example.com' },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
list<T extends MessageAttributes = MessageAttributes>(options?: ListOptions): Promise<ListResponse<T>>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a single message by ID.
|
|
40
|
+
*
|
|
41
|
+
* @param id - The message ID
|
|
42
|
+
* @returns The message
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const message = await clarify.messages.get('message-id');
|
|
47
|
+
* console.log(message.data.attributes.subject);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
get<T extends MessageAttributes = MessageAttributes>(id: string): Promise<SingleResponse<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new message.
|
|
53
|
+
*
|
|
54
|
+
* @param data - The message data to create
|
|
55
|
+
* @returns The created message
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const message = await clarify.messages.create({
|
|
60
|
+
* type: 'message',
|
|
61
|
+
* attributes: {
|
|
62
|
+
* subject: 'Hello',
|
|
63
|
+
* body: 'Message content',
|
|
64
|
+
* from: 'sender@example.com',
|
|
65
|
+
* to: ['recipient@example.com'],
|
|
66
|
+
* },
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
create<T extends MessageAttributes = MessageAttributes>(data: ResourceCreate<T>): Promise<SingleResponse<T>>;
|
|
71
|
+
/**
|
|
72
|
+
* Deletes a message.
|
|
73
|
+
*
|
|
74
|
+
* @param id - The message ID
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* await clarify.messages.delete('message-id');
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
delete(id: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Async iterator for paginating through all messages.
|
|
84
|
+
*
|
|
85
|
+
* @param options - Filter and sort options (pagination is handled automatically)
|
|
86
|
+
* @yields Individual messages
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* for await (const message of clarify.messages.iterate()) {
|
|
91
|
+
* console.log(message.attributes.subject);
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
iterate<T extends MessageAttributes = MessageAttributes>(options?: Omit<ListOptions, 'page'>): AsyncGenerator<Resource<T>, void, undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Builds query parameters from list options.
|
|
98
|
+
*/
|
|
99
|
+
private buildListQuery;
|
|
100
|
+
/**
|
|
101
|
+
* Extracts the cursor from a pagination URL.
|
|
102
|
+
*/
|
|
103
|
+
private extractCursor;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/resources/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB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