@c15t/node-sdk 1.2.0 → 1.2.2-canary-20250514183211
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 +10 -4
- package/.turbo/turbo-build.log +0 -21
- package/CHANGELOG.md +0 -12
- package/rslib.config.ts +0 -25
- package/src/index.test.ts +0 -218
- package/src/index.ts +0 -82
- package/tsconfig.json +0 -11
- package/vitest.config.ts +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c15t/node-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2-canary-20250514183211",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -9,12 +9,18 @@
|
|
|
9
9
|
"require": "./dist/index.cjs"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
12
18
|
"dependencies": {
|
|
13
19
|
"@orpc/client": "1.2.0",
|
|
14
20
|
"@orpc/contract": "1.2.0",
|
|
15
21
|
"@orpc/openapi-client": "^1.2.0",
|
|
16
22
|
"@orpc/server": "1.2.0",
|
|
17
|
-
"@c15t/backend": "1.2.
|
|
23
|
+
"@c15t/backend": "1.2.2-canary-20250514183211"
|
|
18
24
|
},
|
|
19
25
|
"devDependencies": {
|
|
20
26
|
"@electric-sql/pglite": "0.2.17",
|
|
@@ -27,8 +33,8 @@
|
|
|
27
33
|
"msw": "^2.7.6",
|
|
28
34
|
"typescript": "^5.8.3",
|
|
29
35
|
"vitest": "^3.1.1",
|
|
30
|
-
"@c15t/
|
|
31
|
-
"@c15t/
|
|
36
|
+
"@c15t/vitest-config": "1.0.0",
|
|
37
|
+
"@c15t/typescript-config": "0.0.1-beta.1"
|
|
32
38
|
},
|
|
33
39
|
"scripts": {
|
|
34
40
|
"build": "rslib build",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @c15t/node-sdk@1.2.0 build /home/runner/work/c15t/c15t/packages/node-sdk
|
|
3
|
-
> rslib build
|
|
4
|
-
|
|
5
|
-
Rslib v0.6.2
|
|
6
|
-
|
|
7
|
-
ready built in [1m0.11[22m s[90m (esm)[39m
|
|
8
|
-
ready built in [1m0.11[22m s[90m (cjs)[39m
|
|
9
|
-
start generating declaration files... [90m(esm)[39m
|
|
10
|
-
start generating declaration files... [90m(cjs)[39m
|
|
11
|
-
ready declaration files generated in [1m5.51[22m s [90m(cjs)[39m
|
|
12
|
-
ready declaration files generated in [1m5.62[22m s [90m(esm)[39m
|
|
13
|
-
|
|
14
|
-
[34m File (esm) Size [39m
|
|
15
|
-
[2mdist/[22m[36mindex.js[39m 0.95 kB
|
|
16
|
-
|
|
17
|
-
[2m -----[22m
|
|
18
|
-
|
|
19
|
-
[34m File (cjs) Size [39m
|
|
20
|
-
[2mdist/[22m[36mindex.cjs[39m 1.9 kB
|
|
21
|
-
|
package/CHANGELOG.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# @c15t/node-sdk
|
|
2
|
-
|
|
3
|
-
## 1.2.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- [#224](https://github.com/c15t/c15t/pull/224) [`838a9b5`](https://github.com/c15t/c15t/commit/838a9b52c31326899ec3c903e43bf7bc31a6490f) Thanks [@BurnedChris](https://github.com/BurnedChris)! - Refactored backend to be a new orpc client / server
|
|
8
|
-
|
|
9
|
-
### Patch Changes
|
|
10
|
-
|
|
11
|
-
- Updated dependencies [[`838a9b5`](https://github.com/c15t/c15t/commit/838a9b52c31326899ec3c903e43bf7bc31a6490f)]:
|
|
12
|
-
- @c15t/backend@1.2.0
|
package/rslib.config.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from '@rslib/core';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
source: {
|
|
5
|
-
entry: {
|
|
6
|
-
index: ['./src/index.ts'],
|
|
7
|
-
},
|
|
8
|
-
},
|
|
9
|
-
lib: [
|
|
10
|
-
{
|
|
11
|
-
dts: true,
|
|
12
|
-
bundle: true,
|
|
13
|
-
format: 'esm',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
dts: true,
|
|
17
|
-
bundle: true,
|
|
18
|
-
format: 'cjs',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
output: {
|
|
22
|
-
target: 'node',
|
|
23
|
-
cleanDistPath: true,
|
|
24
|
-
},
|
|
25
|
-
});
|
package/src/index.test.ts
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http';
|
|
2
|
-
import { c15tInstance } from '@c15t/backend';
|
|
3
|
-
import type { C15TOptions } from '@c15t/backend';
|
|
4
|
-
import {
|
|
5
|
-
afterAll,
|
|
6
|
-
beforeAll,
|
|
7
|
-
beforeEach,
|
|
8
|
-
describe,
|
|
9
|
-
expect,
|
|
10
|
-
it,
|
|
11
|
-
vi,
|
|
12
|
-
} from 'vitest';
|
|
13
|
-
import { c15tClient } from './index';
|
|
14
|
-
|
|
15
|
-
// Server configuration for integration tests
|
|
16
|
-
const mockOptions: C15TOptions = {
|
|
17
|
-
appName: 'C15T Test Server',
|
|
18
|
-
basePath: '/',
|
|
19
|
-
trustedOrigins: ['localhost', 'test.example.com'],
|
|
20
|
-
cors: true,
|
|
21
|
-
advanced: {
|
|
22
|
-
cors: {
|
|
23
|
-
allowHeaders: ['content-type', 'x-request-id'],
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
// logger: {
|
|
27
|
-
// level: 'debug',
|
|
28
|
-
// },
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('C15T Node SDK', () => {
|
|
32
|
-
const PORT = 8787;
|
|
33
|
-
const mockBaseUrl = `http://localhost:${PORT}`;
|
|
34
|
-
let server: ReturnType<typeof c15tInstance>;
|
|
35
|
-
let httpServer: ReturnType<typeof createServer>;
|
|
36
|
-
let client: ReturnType<typeof c15tClient>;
|
|
37
|
-
|
|
38
|
-
beforeAll(async () => {
|
|
39
|
-
// Initialize the server for integration tests
|
|
40
|
-
server = c15tInstance(mockOptions);
|
|
41
|
-
|
|
42
|
-
// Create and start HTTP server
|
|
43
|
-
httpServer = createServer(async (req, res) => {
|
|
44
|
-
try {
|
|
45
|
-
// Read request body if present
|
|
46
|
-
let body: string | undefined;
|
|
47
|
-
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
48
|
-
const chunks: Uint8Array[] = [];
|
|
49
|
-
for await (const chunk of req) {
|
|
50
|
-
chunks.push(chunk);
|
|
51
|
-
}
|
|
52
|
-
body = Buffer.concat(chunks).toString();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Convert Node.js request to web standard Request
|
|
56
|
-
const request = new Request(`http://localhost:${PORT}${req.url}`, {
|
|
57
|
-
method: req.method,
|
|
58
|
-
headers: req.headers as Record<string, string>,
|
|
59
|
-
body: body,
|
|
60
|
-
duplex: 'half',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Handle the request with c15tInstance
|
|
64
|
-
const response = await server.handler(request);
|
|
65
|
-
|
|
66
|
-
// Set response status and headers
|
|
67
|
-
res.statusCode = response.status;
|
|
68
|
-
for (const [key, value] of response.headers.entries()) {
|
|
69
|
-
res.setHeader(key, value);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Ensure content-type is set for JSON responses
|
|
73
|
-
if (!response.headers.get('content-type')) {
|
|
74
|
-
res.setHeader('content-type', 'application/json');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Get response body
|
|
78
|
-
const responseBody = await response.text();
|
|
79
|
-
|
|
80
|
-
// Send response
|
|
81
|
-
res.end(responseBody);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
// biome-ignore lint/suspicious/noConsoleLog: its a test
|
|
84
|
-
// biome-ignore lint/suspicious/noConsole: its a test
|
|
85
|
-
console.error('Server error:', error);
|
|
86
|
-
res.statusCode = 500;
|
|
87
|
-
res.setHeader('content-type', 'application/json');
|
|
88
|
-
res.end(
|
|
89
|
-
JSON.stringify({
|
|
90
|
-
error: 'Internal Server Error',
|
|
91
|
-
message: error instanceof Error ? error.message : String(error),
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
await new Promise<void>((resolve) => {
|
|
98
|
-
httpServer.listen(PORT, () => {
|
|
99
|
-
// biome-ignore lint/suspicious/noConsoleLog: its a test
|
|
100
|
-
// biome-ignore lint/suspicious/noConsole: its a test
|
|
101
|
-
console.log(`Test server listening on port ${PORT}`);
|
|
102
|
-
resolve();
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Initialize the client for testing
|
|
107
|
-
client = c15tClient({
|
|
108
|
-
baseUrl: mockBaseUrl,
|
|
109
|
-
prefix: '/',
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
afterAll(async () => {
|
|
114
|
-
// Clean up server
|
|
115
|
-
await new Promise<void>((resolve) => {
|
|
116
|
-
httpServer.close(() => {
|
|
117
|
-
// biome-ignore lint/suspicious/noConsoleLog: its a test
|
|
118
|
-
// biome-ignore lint/suspicious/noConsole: its a test
|
|
119
|
-
console.log('Test server closed');
|
|
120
|
-
resolve();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
beforeEach(() => {
|
|
126
|
-
vi.clearAllMocks();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('Unit Tests', () => {
|
|
130
|
-
describe('Client Creation', () => {
|
|
131
|
-
it('should create a client with basic configuration', () => {
|
|
132
|
-
const client = c15tClient({ baseUrl: mockBaseUrl });
|
|
133
|
-
|
|
134
|
-
expect(client).toBeDefined();
|
|
135
|
-
expect(client.consent).toBeDefined();
|
|
136
|
-
expect(client.meta).toBeDefined();
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should include authorization header when token is provided', () => {
|
|
140
|
-
const client = c15tClient({
|
|
141
|
-
baseUrl: mockBaseUrl,
|
|
142
|
-
token: 'test-token',
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
expect(client).toBeDefined();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should include custom headers when provided', () => {
|
|
149
|
-
const client = c15tClient({
|
|
150
|
-
baseUrl: mockBaseUrl,
|
|
151
|
-
headers: { 'X-Custom-Header': 'test-value' },
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
expect(client).toBeDefined();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should apply prefix to base URL when provided', () => {
|
|
158
|
-
const prefix = '/api/v1';
|
|
159
|
-
const client = c15tClient({
|
|
160
|
-
baseUrl: mockBaseUrl,
|
|
161
|
-
prefix,
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
expect(client).toBeDefined();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('should handle URL with existing path', () => {
|
|
168
|
-
const baseUrl = 'http://localhost:8787/existing';
|
|
169
|
-
const prefix = '/api/v1';
|
|
170
|
-
const client = c15tClient({
|
|
171
|
-
baseUrl,
|
|
172
|
-
prefix,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
expect(client).toBeDefined();
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('Error Handling', () => {
|
|
180
|
-
it('should handle invalid base URL', () => {
|
|
181
|
-
expect(() => {
|
|
182
|
-
c15tClient({ baseUrl: 'invalid-url' });
|
|
183
|
-
}).toThrow();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should handle empty base URL', () => {
|
|
187
|
-
expect(() => {
|
|
188
|
-
c15tClient({ baseUrl: '' });
|
|
189
|
-
}).toThrow();
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe('Integration Tests', () => {
|
|
195
|
-
it('should connect to status endpoint', async () => {
|
|
196
|
-
const response = await client.meta.status();
|
|
197
|
-
|
|
198
|
-
// Test exact structure based on actual response
|
|
199
|
-
expect(response).toEqual({
|
|
200
|
-
status: 'ok',
|
|
201
|
-
version: expect.any(String),
|
|
202
|
-
timestamp: expect.any(String),
|
|
203
|
-
storage: {
|
|
204
|
-
type: 'memory',
|
|
205
|
-
available: true,
|
|
206
|
-
},
|
|
207
|
-
client: {
|
|
208
|
-
ip: expect.any(String),
|
|
209
|
-
userAgent: expect.any(String),
|
|
210
|
-
region: {
|
|
211
|
-
countryCode: null,
|
|
212
|
-
regionCode: null,
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { contracts } from '@c15t/backend/contracts';
|
|
2
|
-
import { createORPCClient } from '@orpc/client';
|
|
3
|
-
import type { ContractRouterClient } from '@orpc/contract';
|
|
4
|
-
import type { JsonifiedClient } from '@orpc/openapi-client';
|
|
5
|
-
import { OpenAPILink } from '@orpc/openapi-client/fetch';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Configuration options for the C15T SDK client
|
|
9
|
-
*/
|
|
10
|
-
export interface C15TClientOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Base URL for the API server
|
|
13
|
-
* @example "https://api.example.com"
|
|
14
|
-
*/
|
|
15
|
-
baseUrl: string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Authentication token (if needed)
|
|
19
|
-
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
20
|
-
*/
|
|
21
|
-
token?: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Additional headers to include with each request
|
|
25
|
-
*/
|
|
26
|
-
headers?: Record<string, string>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Prefix path for API endpoints
|
|
30
|
-
* @default "/"
|
|
31
|
-
*/
|
|
32
|
-
prefix?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a type-safe C15T client instance
|
|
37
|
-
*
|
|
38
|
-
* @param options - Configuration options for the client
|
|
39
|
-
* @returns A fully typed client for interacting with the C15T API
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // Create a client with authentication
|
|
44
|
-
* const client = createC15TClient({
|
|
45
|
-
* baseUrl: "https://api.example.com",
|
|
46
|
-
* token: "your-auth-token"
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* // Now use the client with full type safety
|
|
50
|
-
* const response = await client.users.getProfile({ userId: "123" });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export function c15tClient(options: C15TClientOptions) {
|
|
54
|
-
// Prepare authorization header if token is provided
|
|
55
|
-
const authHeaders: Record<string, string> = options.token
|
|
56
|
-
? { Authorization: `Bearer ${options.token}` }
|
|
57
|
-
: {};
|
|
58
|
-
|
|
59
|
-
// Prepare the base URL, potentially with prefix
|
|
60
|
-
const baseUrl = new URL(options.baseUrl);
|
|
61
|
-
|
|
62
|
-
// If prefix is provided, apply it to the base URL path
|
|
63
|
-
if (options.prefix) {
|
|
64
|
-
baseUrl.pathname = options.prefix;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const link = new OpenAPILink(contracts, {
|
|
68
|
-
url: baseUrl.toString(),
|
|
69
|
-
headers: {
|
|
70
|
-
...authHeaders,
|
|
71
|
-
...options.headers,
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Create and return the client with a type assertion
|
|
76
|
-
// This approach avoids complex type issues while providing
|
|
77
|
-
// the same runtime functionality
|
|
78
|
-
|
|
79
|
-
return createORPCClient(link) as JsonifiedClient<
|
|
80
|
-
ContractRouterClient<typeof contracts>
|
|
81
|
-
>;
|
|
82
|
-
}
|
package/tsconfig.json
DELETED
package/vitest.config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import { baseConfig } from '@c15t/vitest-config/base';
|
|
3
|
-
import { defineConfig, mergeConfig } from 'vitest/config';
|
|
4
|
-
|
|
5
|
-
export default mergeConfig(
|
|
6
|
-
baseConfig,
|
|
7
|
-
defineConfig({
|
|
8
|
-
resolve: {
|
|
9
|
-
alias: {
|
|
10
|
-
'~': resolve(__dirname, './src'),
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
test: {
|
|
14
|
-
environment: 'node',
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
);
|