@c15t/node-sdk 3.0.0-alpha.2 → 3.0.0-alpha.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@c15t/node-sdk",
3
- "version": "3.0.0-alpha.2",
4
- "description": "Type-safe Node.js SDK for hosted and self-hosted c15t consent APIs, consent records, privacy preferences, and backend automation.",
3
+ "version": "3.0.0-alpha.4",
4
+ "description": "Typed client for the c15t consent API: check consent, link users, record consents and publish legal documents from server code.",
5
5
  "keywords": [
6
6
  "c15t",
7
7
  "ccpa",
@@ -35,6 +35,7 @@
35
35
  "dist-types"
36
36
  ],
37
37
  "type": "module",
38
+ "sideEffects": false,
38
39
  "main": "./dist/index.js",
39
40
  "types": "./dist-types/index.d.ts",
40
41
  "exports": {
@@ -51,7 +52,7 @@
51
52
  },
52
53
  "scripts": {
53
54
  "build": "bun prebuild && rslib build && bun ../../scripts/normalize-dist-types.mjs",
54
- "check-types": "bun prebuild && tsc --noEmit",
55
+ "check-types": "bun prebuild && tsc --noEmit && tsc -p tsconfig.type-tests.json",
55
56
  "check-types:test": "bun prebuild && tsc -p tsconfig.test.json",
56
57
  "dev": "sh -c 'bun prebuild && rslib build --no-dts --no-clean && rslib build --watch --no-dts --no-clean'",
57
58
  "fmt": "bun oxfmt .",
@@ -61,21 +62,14 @@
61
62
  "test:watch": "bun prebuild && vitest"
62
63
  },
63
64
  "dependencies": {
64
- "@c15t/backend": "3.0.0-alpha.2",
65
- "@c15t/schema": "3.0.0-alpha.1"
65
+ "@c15t/schema": "3.0.0-alpha.3"
66
66
  },
67
67
  "devDependencies": {
68
+ "@c15t/backend": "3.0.0-alpha.4",
68
69
  "@c15t/typescript-config": "0.0.1",
69
70
  "@c15t/vitest-config": "1.0.0",
70
- "@electric-sql/pglite": "0.4.2",
71
- "@libsql/kysely-libsql": "^0.4.1",
72
- "@types/better-sqlite3": "^7.6.13",
73
- "@types/express": "^5.0.6",
74
71
  "@types/node": "25.5.0",
75
- "@types/pg": "8.20.0",
76
72
  "genversion": "3.2.0",
77
- "kysely-pglite": "^0.6.1",
78
- "msw": "^2.14.6",
79
73
  "typescript": "7.0.2"
80
74
  }
81
75
  }
@@ -1,16 +0,0 @@
1
- import type { CheckConsentOutput, CheckConsentQuery } from '@c15t/schema/types';
2
- import type { FetcherContext } from '../fetcher.js';
3
- import type { FetchOptions, ResponseContext } from '../types.js';
4
- /**
5
- * API endpoint path for consent check
6
- */
7
- export declare const CONSENT_CHECK_PATH = "/consents/check";
8
- /**
9
- * Check consent status for an external ID
10
- *
11
- * @param context - Fetcher context
12
- * @param query - Query parameters (externalId required)
13
- * @param options - Optional fetch options
14
- * @returns Consent check response
15
- */
16
- export declare const checkConsent: (context: FetcherContext, query: CheckConsentQuery, options?: FetchOptions<CheckConsentOutput, never, CheckConsentQuery>) => Promise<ResponseContext<CheckConsentOutput>>;
@@ -1,4 +0,0 @@
1
- export { CONSENT_CHECK_PATH, checkConsent } from './consent.js';
2
- export { INIT_PATH, init } from './init.js';
3
- export { STATUS_PATH, status } from './status.js';
4
- export { createSubject, getSubject, listSubjects, patchSubject, SUBJECTS_PATH, } from './subjects.js';
@@ -1,15 +0,0 @@
1
- import type { InitOutput } from '@c15t/schema/types';
2
- import type { FetcherContext } from '../fetcher.js';
3
- import type { FetchOptions, ResponseContext } from '../types.js';
4
- /**
5
- * API endpoint path for init
6
- */
7
- export declare const INIT_PATH = "/init";
8
- /**
9
- * Initialize consent manager
10
- *
11
- * @param context - Fetcher context
12
- * @param options - Optional fetch options
13
- * @returns Init response with jurisdiction, location, translations, branding
14
- */
15
- export declare const init: (context: FetcherContext, options?: FetchOptions<InitOutput>) => Promise<ResponseContext<InitOutput>>;
@@ -1,15 +0,0 @@
1
- import type { StatusOutput } from '@c15t/schema/types';
2
- import type { FetcherContext } from '../fetcher.js';
3
- import type { FetchOptions, ResponseContext } from '../types.js';
4
- /**
5
- * API endpoint path for status
6
- */
7
- export declare const STATUS_PATH = "/status";
8
- /**
9
- * Get API status
10
- *
11
- * @param context - Fetcher context
12
- * @param options - Optional fetch options
13
- * @returns Status response
14
- */
15
- export declare const status: (context: FetcherContext, options?: FetchOptions<StatusOutput>) => Promise<ResponseContext<StatusOutput>>;
@@ -1,45 +0,0 @@
1
- import type { GetSubjectOutput, GetSubjectQuery, ListSubjectsOutput, ListSubjectsQuery, PatchSubjectFullInput, PatchSubjectOutput, PostSubjectInput, PostSubjectOutput } from '@c15t/schema/types';
2
- import type { FetcherContext } from '../fetcher.js';
3
- import type { FetchOptions, ResponseContext } from '../types.js';
4
- /**
5
- * API endpoint paths for subjects
6
- */
7
- export declare const SUBJECTS_PATH = "/subjects";
8
- /**
9
- * Create a new subject with consent preferences
10
- *
11
- * @param context - Fetcher context
12
- * @param input - Subject creation input
13
- * @param options - Optional fetch options
14
- * @returns Created subject response
15
- */
16
- export declare const createSubject: (context: FetcherContext, input: PostSubjectInput, options?: FetchOptions<PostSubjectOutput, PostSubjectInput>) => Promise<ResponseContext<PostSubjectOutput>>;
17
- /**
18
- * Get a subject by ID
19
- *
20
- * @param context - Fetcher context
21
- * @param id - Subject ID
22
- * @param query - Optional query parameters
23
- * @param options - Optional fetch options
24
- * @returns Subject data response
25
- */
26
- export declare const getSubject: (context: FetcherContext, id: string, query?: GetSubjectQuery, options?: FetchOptions<GetSubjectOutput, never, GetSubjectQuery>) => Promise<ResponseContext<GetSubjectOutput>>;
27
- /**
28
- * Update a subject (link external ID or update preferences)
29
- *
30
- * @param context - Fetcher context
31
- * @param id - Subject ID
32
- * @param input - Patch input with externalId or other fields
33
- * @param options - Optional fetch options
34
- * @returns Updated subject response
35
- */
36
- export declare const patchSubject: (context: FetcherContext, id: string, input: Omit<PatchSubjectFullInput, 'id'>, options?: FetchOptions<PatchSubjectOutput, Omit<PatchSubjectFullInput, 'id'>>) => Promise<ResponseContext<PatchSubjectOutput>>;
37
- /**
38
- * List subjects with optional filtering
39
- *
40
- * @param context - Fetcher context
41
- * @param query - Query parameters for filtering
42
- * @param options - Optional fetch options
43
- * @returns List of subjects
44
- */
45
- export declare const listSubjects: (context: FetcherContext, query?: ListSubjectsQuery, options?: FetchOptions<ListSubjectsOutput, never, ListSubjectsQuery>) => Promise<ResponseContext<ListSubjectsOutput>>;
@@ -1,85 +0,0 @@
1
- /**
2
- * C15TError - Custom error class for typed error handling
3
- *
4
- * @example
5
- * ```typescript
6
- * import { C15TError } from '@c15t/node-sdk';
7
- *
8
- * try {
9
- * const subject = (await client.getSubject('sub_123')).unwrap();
10
- * } catch (error) {
11
- * if (error instanceof C15TError) {
12
- * console.log(error.status); // 404
13
- * console.log(error.code); // 'NOT_FOUND'
14
- * console.log(error.details);
15
- * }
16
- * }
17
- * ```
18
- */
19
- export declare class C15TError extends Error {
20
- /**
21
- * HTTP status code of the error response
22
- */
23
- readonly status: number;
24
- /**
25
- * Error code for programmatic error identification
26
- */
27
- readonly code?: string;
28
- /**
29
- * Additional error details
30
- */
31
- readonly details?: Record<string, unknown> | null;
32
- /**
33
- * Original cause of the error (if any)
34
- */
35
- readonly cause?: unknown;
36
- constructor(options: {
37
- message: string;
38
- status: number;
39
- code?: string;
40
- details?: Record<string, unknown> | null;
41
- cause?: unknown;
42
- });
43
- /**
44
- * Check if the error is a specific HTTP status code
45
- */
46
- isStatus(status: number): boolean;
47
- /**
48
- * Check if the error is a not found error (404)
49
- */
50
- isNotFound(): boolean;
51
- /**
52
- * Check if the error is a validation error (400)
53
- */
54
- isValidationError(): boolean;
55
- /**
56
- * Check if the error is an authentication error (401)
57
- */
58
- isUnauthorized(): boolean;
59
- /**
60
- * Check if the error is a forbidden error (403)
61
- */
62
- isForbidden(): boolean;
63
- /**
64
- * Check if the error is a server error (5xx)
65
- */
66
- isServerError(): boolean;
67
- /**
68
- * Check if the error is a network error
69
- */
70
- isNetworkError(): boolean;
71
- /**
72
- * Convert error to a plain object for serialization
73
- */
74
- toJSON(): {
75
- name: string;
76
- message: string;
77
- status: number;
78
- code?: string;
79
- details?: Record<string, unknown> | null;
80
- };
81
- }
82
- /**
83
- * Type guard to check if an error is a C15TError
84
- */
85
- export declare const isC15TError: (error: unknown) => error is C15TError;
@@ -1,37 +0,0 @@
1
- import type { FetchOptions, ResponseContext, RetryConfig } from './types.js';
2
- /**
3
- * Default retry configuration
4
- */
5
- export declare const DEFAULT_RETRY_CONFIG: RetryConfig;
6
- /**
7
- * Default timeout in milliseconds (30 seconds)
8
- */
9
- export declare const DEFAULT_TIMEOUT_MS = 30000;
10
- /**
11
- * Base context for fetcher operations
12
- */
13
- export interface FetcherContext {
14
- baseUrl: string;
15
- headers: Record<string, string>;
16
- retryConfig: RetryConfig;
17
- debug: boolean;
18
- timeout: number;
19
- }
20
- /**
21
- * Creates a response context object with Result-like helper methods
22
- */
23
- export declare const createResponseContext: <T>(isSuccess: boolean, data?: T | null, error?: {
24
- message: string;
25
- status: number;
26
- code?: string;
27
- cause?: unknown;
28
- details?: Record<string, unknown> | null;
29
- } | null, response?: Response | null) => ResponseContext<T>;
30
- /**
31
- * Resolves a URL path against the base URL
32
- */
33
- export declare const resolveUrl: (baseUrl: string, path: string) => string;
34
- /**
35
- * Makes an HTTP request with retry logic
36
- */
37
- export declare const fetcher: <ResponseType, BodyType = unknown, QueryType = unknown>(context: FetcherContext, path: string, options?: FetchOptions<ResponseType, BodyType, QueryType>) => Promise<ResponseContext<ResponseType>>;
@@ -1,3 +0,0 @@
1
- export declare const C15T_VERSION_HEADERS: {
2
- readonly 'x-c15t-version': "3.0.0-alpha.2";
3
- };
@@ -1,234 +0,0 @@
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
- }