@c15t/node-sdk 1.8.0 → 2.0.0-rc.0
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/README.md +217 -13
- package/dist/client.d.ts +433 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/endpoints/consent.d.ts +17 -0
- package/dist/endpoints/consent.d.ts.map +1 -0
- package/dist/endpoints/index.d.ts +5 -0
- package/dist/endpoints/index.d.ts.map +1 -0
- package/dist/endpoints/init.d.ts +16 -0
- package/dist/endpoints/init.d.ts.map +1 -0
- package/dist/endpoints/status.d.ts +16 -0
- package/dist/endpoints/status.d.ts.map +1 -0
- package/dist/endpoints/subjects.d.ts +46 -0
- package/dist/endpoints/subjects.d.ts.map +1 -0
- package/dist/error.d.ts +86 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/fetcher.d.ts +38 -0
- package/dist/fetcher.d.ts.map +1 -0
- package/dist/index.cjs +386 -19
- package/dist/index.d.ts +31 -34
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +365 -16
- package/dist/testing.d.ts +132 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/types.d.ts +235 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +67 -72
- package/LICENSE.md +0 -595
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the C15T SDK client
|
|
3
|
+
*/
|
|
4
|
+
export interface C15TClientOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Base URL for the API server.
|
|
7
|
+
* If not provided, falls back to C15T_API_URL environment variable.
|
|
8
|
+
* @example "https://api.example.com"
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Authentication token (if needed).
|
|
13
|
+
* If not provided, falls back to C15T_API_TOKEN environment variable.
|
|
14
|
+
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Additional headers to include with each request
|
|
19
|
+
*/
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Prefix path for API endpoints
|
|
23
|
+
* @default "/"
|
|
24
|
+
*/
|
|
25
|
+
prefix?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Retry configuration for failed requests
|
|
28
|
+
*/
|
|
29
|
+
retryConfig?: RetryConfig;
|
|
30
|
+
/**
|
|
31
|
+
* Enable debug mode to log requests and responses.
|
|
32
|
+
* Can also be enabled via C15T_DEBUG=true environment variable.
|
|
33
|
+
* @default false
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const client = c15tClient({
|
|
37
|
+
* baseUrl: 'https://api.example.com',
|
|
38
|
+
* debug: true,
|
|
39
|
+
* });
|
|
40
|
+
* // Console output:
|
|
41
|
+
* // [c15t] GET /status (142ms) -> 200
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
debug?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Request timeout in milliseconds.
|
|
47
|
+
* Requests exceeding this timeout will be aborted.
|
|
48
|
+
* @default 30000 (30 seconds)
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const client = c15tClient({
|
|
52
|
+
* baseUrl: 'https://api.example.com',
|
|
53
|
+
* timeout: 5000, // 5 seconds
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
timeout?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retry configuration for HTTP requests
|
|
61
|
+
*/
|
|
62
|
+
export interface RetryConfig {
|
|
63
|
+
/**
|
|
64
|
+
* Maximum number of retry attempts
|
|
65
|
+
* @default 3
|
|
66
|
+
*/
|
|
67
|
+
maxRetries?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Initial delay in milliseconds before the first retry
|
|
70
|
+
* @default 100
|
|
71
|
+
*/
|
|
72
|
+
initialDelayMs?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Factor by which the delay increases for each subsequent retry
|
|
75
|
+
* @default 2
|
|
76
|
+
*/
|
|
77
|
+
backoffFactor?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Array of HTTP status codes that should trigger a retry
|
|
80
|
+
* @default [500, 502, 503, 504]
|
|
81
|
+
*/
|
|
82
|
+
retryableStatusCodes?: number[];
|
|
83
|
+
/**
|
|
84
|
+
* Array of HTTP status codes that should never be retried
|
|
85
|
+
* @default [400, 401, 403, 404]
|
|
86
|
+
*/
|
|
87
|
+
nonRetryableStatusCodes?: number[];
|
|
88
|
+
/**
|
|
89
|
+
* Whether to retry on network errors
|
|
90
|
+
* @default true
|
|
91
|
+
*/
|
|
92
|
+
retryOnNetworkError?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Response context returned from API requests.
|
|
96
|
+
*
|
|
97
|
+
* Provides Result-like helper methods for ergonomic error handling.
|
|
98
|
+
*/
|
|
99
|
+
export interface ResponseContext<T = unknown> {
|
|
100
|
+
/**
|
|
101
|
+
* Response data returned by the API
|
|
102
|
+
*/
|
|
103
|
+
data: T | null;
|
|
104
|
+
/**
|
|
105
|
+
* Original fetch Response object
|
|
106
|
+
*/
|
|
107
|
+
response: Response | null;
|
|
108
|
+
/**
|
|
109
|
+
* Error information if the request failed
|
|
110
|
+
*/
|
|
111
|
+
error: {
|
|
112
|
+
/**
|
|
113
|
+
* Error message describing what went wrong
|
|
114
|
+
*/
|
|
115
|
+
message: string;
|
|
116
|
+
/**
|
|
117
|
+
* HTTP status code or custom error code
|
|
118
|
+
*/
|
|
119
|
+
status: number;
|
|
120
|
+
/**
|
|
121
|
+
* Optional error code for more specific error identification
|
|
122
|
+
*/
|
|
123
|
+
code?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Optional cause of the error
|
|
126
|
+
*/
|
|
127
|
+
cause?: unknown;
|
|
128
|
+
/**
|
|
129
|
+
* Optional additional details about the error
|
|
130
|
+
*/
|
|
131
|
+
details?: Record<string, unknown> | null;
|
|
132
|
+
} | null;
|
|
133
|
+
/**
|
|
134
|
+
* Whether the request was successful
|
|
135
|
+
*/
|
|
136
|
+
ok: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Unwraps the response data, throwing an error if the request failed.
|
|
139
|
+
*
|
|
140
|
+
* @throws {Error} If the request was not successful
|
|
141
|
+
* @returns The response data
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const subject = (await client.getSubject('sub_123')).unwrap();
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
unwrap(): T;
|
|
149
|
+
/**
|
|
150
|
+
* Unwraps the response data, returning a default value if the request failed.
|
|
151
|
+
*
|
|
152
|
+
* @param defaultValue - The value to return if the request failed
|
|
153
|
+
* @returns The response data or the default value
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const subject = (await client.getSubject('sub_123')).unwrapOr(defaultSubject);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
unwrapOr(defaultValue: T): T;
|
|
161
|
+
/**
|
|
162
|
+
* Unwraps the response data, throwing a custom error message if the request failed.
|
|
163
|
+
*
|
|
164
|
+
* @param message - Custom error message to throw
|
|
165
|
+
* @throws {Error} With the provided message if the request was not successful
|
|
166
|
+
* @returns The response data
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const subject = (await client.getSubject('sub_123')).expect('Subject not found');
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
expect(message: string): T;
|
|
174
|
+
/**
|
|
175
|
+
* Maps the response data to a new value if successful.
|
|
176
|
+
*
|
|
177
|
+
* @param fn - Function to transform the data
|
|
178
|
+
* @returns A new ResponseContext with the transformed data
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const name = (await client.getSubject('sub_123')).map(s => s.name);
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
map<U>(fn: (data: T) => U): ResponseContext<U>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Options for individual fetch requests
|
|
189
|
+
*/
|
|
190
|
+
export interface FetchOptions<ResponseType = unknown, BodyType = unknown, QueryType = unknown> {
|
|
191
|
+
/**
|
|
192
|
+
* HTTP method for the request
|
|
193
|
+
* @default 'GET'
|
|
194
|
+
*/
|
|
195
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
196
|
+
/**
|
|
197
|
+
* Request body to send with the request
|
|
198
|
+
*/
|
|
199
|
+
body?: BodyType;
|
|
200
|
+
/**
|
|
201
|
+
* Query parameters to include in the request URL
|
|
202
|
+
*/
|
|
203
|
+
query?: QueryType;
|
|
204
|
+
/**
|
|
205
|
+
* Custom headers to include with this specific request
|
|
206
|
+
*/
|
|
207
|
+
headers?: Record<string, string>;
|
|
208
|
+
/**
|
|
209
|
+
* Whether to throw an error when the response is not successful
|
|
210
|
+
* @default false
|
|
211
|
+
*/
|
|
212
|
+
throw?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Callback function to execute on successful response
|
|
215
|
+
*/
|
|
216
|
+
onSuccess?: (context: ResponseContext<ResponseType>) => void | Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Callback function to execute on error response
|
|
219
|
+
*/
|
|
220
|
+
onError?: (context: ResponseContext<ResponseType>, path: string) => void | Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Request-specific retry configuration
|
|
223
|
+
*/
|
|
224
|
+
retryConfig?: RetryConfig;
|
|
225
|
+
/**
|
|
226
|
+
* Request timeout in milliseconds.
|
|
227
|
+
* Overrides the global timeout for this specific request.
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* await client.getSubject('sub_123', undefined, { timeout: 5000 });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
timeout?: number;
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC3C;;OAEG;IACH,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAE1B;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AAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7E;;OAEG;IACH,OAAO,CAAC,EAAE,CACT,OAAO,EAAE,eAAe,CAAC,YAAY,CAAC,EACtC,IAAI,EAAE,MAAM,KACR,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,73 +1,68 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"lint": "pnpm biome lint ./src",
|
|
70
|
-
"test": "vitest run",
|
|
71
|
-
"test:watch": "vitest"
|
|
72
|
-
}
|
|
73
|
-
}
|
|
2
|
+
"name": "@c15t/node-sdk",
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
|
+
"description": "Official Node.js SDK for c15t. Connects to the Consent Engine to read and write consent records and preferences. TypeScript-first, simple APIs, built-in auth and retries.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"consent",
|
|
8
|
+
"privacy",
|
|
9
|
+
"gdpr",
|
|
10
|
+
"ccpa",
|
|
11
|
+
"lgpd",
|
|
12
|
+
"headless",
|
|
13
|
+
"typescript",
|
|
14
|
+
"cookie-banner",
|
|
15
|
+
"consent-management-platform",
|
|
16
|
+
"cmp",
|
|
17
|
+
"consent-banner",
|
|
18
|
+
"user-consent",
|
|
19
|
+
"privacy-compliance",
|
|
20
|
+
"web-privacy"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://c15t.com",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/c15t/c15t.git",
|
|
26
|
+
"directory": "packages/node-sdk"
|
|
27
|
+
},
|
|
28
|
+
"license": "GPL-3.0-only",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./testing": {
|
|
37
|
+
"types": "./dist/testing.d.ts",
|
|
38
|
+
"import": "./dist/testing.js",
|
|
39
|
+
"require": "./dist/testing.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.cjs",
|
|
43
|
+
"module": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "rslib build",
|
|
50
|
+
"check-types": "tsc --noEmit",
|
|
51
|
+
"check-types:test": "tsc -p tsconfig.test.json",
|
|
52
|
+
"dev": "rslib build",
|
|
53
|
+
"fmt": "bun biome format --write . && bun biome check --formatter-enabled=false --linter-enabled=false --write",
|
|
54
|
+
"lint": "bun biome lint ./src",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"test:watch": "vitest"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@c15t/schema": "workspace:*"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@c15t/backend": "workspace:*",
|
|
63
|
+
"@c15t/typescript-config": "workspace:*",
|
|
64
|
+
"@c15t/vitest-config": "workspace:*",
|
|
65
|
+
"@types/node": "24.10.1",
|
|
66
|
+
"typescript": "5.9.3"
|
|
67
|
+
}
|
|
68
|
+
}
|