@c15t/node-sdk 1.2.0-canary.8 → 1.2.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/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/package.json +8 -5
- package/src/index.test.ts +218 -0
- package/src/index.ts +8 -7
|
@@ -0,0 +1,21 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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/dist/index.cjs
CHANGED
|
@@ -26,23 +26,23 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
c15tClient: ()=>c15tClient
|
|
28
28
|
});
|
|
29
|
+
const contracts_namespaceObject = require("@c15t/backend/contracts");
|
|
29
30
|
const client_namespaceObject = require("@orpc/client");
|
|
30
|
-
const fetch_namespaceObject = require("@orpc/client/fetch");
|
|
31
|
+
const fetch_namespaceObject = require("@orpc/openapi-client/fetch");
|
|
31
32
|
function c15tClient(options) {
|
|
32
33
|
const authHeaders = options.token ? {
|
|
33
34
|
Authorization: `Bearer ${options.token}`
|
|
34
35
|
} : {};
|
|
35
36
|
const baseUrl = new URL(options.baseUrl);
|
|
36
37
|
if (options.prefix) baseUrl.pathname = options.prefix;
|
|
37
|
-
const link = new fetch_namespaceObject.
|
|
38
|
+
const link = new fetch_namespaceObject.OpenAPILink(contracts_namespaceObject.contracts, {
|
|
38
39
|
url: baseUrl.toString(),
|
|
39
40
|
headers: {
|
|
40
41
|
...authHeaders,
|
|
41
42
|
...options.headers
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
-
return client;
|
|
45
|
+
return (0, client_namespaceObject.createORPCClient)(link);
|
|
46
46
|
}
|
|
47
47
|
exports.c15tClient = __webpack_exports__.c15tClient;
|
|
48
48
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import { contracts } from '@c15t/backend/contracts';
|
|
2
|
+
import type { ContractRouterClient } from '@orpc/contract';
|
|
3
|
+
import type { JsonifiedClient } from '@orpc/openapi-client';
|
|
3
4
|
/**
|
|
4
5
|
* Configuration options for the C15T SDK client
|
|
5
6
|
*/
|
|
@@ -42,5 +43,5 @@ export interface C15TClientOptions {
|
|
|
42
43
|
* const response = await client.users.getProfile({ userId: "123" });
|
|
43
44
|
* ```
|
|
44
45
|
*/
|
|
45
|
-
export declare function c15tClient(options: C15TClientOptions):
|
|
46
|
+
export declare function c15tClient(options: C15TClientOptions): JsonifiedClient<ContractRouterClient<typeof contracts>>;
|
|
46
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;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;CAChB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GA0BnB,eAAe,CAC/C,oBAAoB,CAAC,OAAO,SAAS,CAAC,CACtC,CACD"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__c15t_backend_contracts_743894b8__ from "@c15t/backend/contracts";
|
|
1
2
|
import * as __WEBPACK_EXTERNAL_MODULE__orpc_client_e16cd7f2__ from "@orpc/client";
|
|
2
|
-
import * as
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__orpc_openapi_client_fetch_375f7e70__ from "@orpc/openapi-client/fetch";
|
|
3
4
|
function c15tClient(options) {
|
|
4
5
|
const authHeaders = options.token ? {
|
|
5
6
|
Authorization: `Bearer ${options.token}`
|
|
6
7
|
} : {};
|
|
7
8
|
const baseUrl = new URL(options.baseUrl);
|
|
8
9
|
if (options.prefix) baseUrl.pathname = options.prefix;
|
|
9
|
-
const link = new
|
|
10
|
+
const link = new __WEBPACK_EXTERNAL_MODULE__orpc_openapi_client_fetch_375f7e70__.OpenAPILink(__WEBPACK_EXTERNAL_MODULE__c15t_backend_contracts_743894b8__.contracts, {
|
|
10
11
|
url: baseUrl.toString(),
|
|
11
12
|
headers: {
|
|
12
13
|
...authHeaders,
|
|
13
14
|
...options.headers
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
return client;
|
|
17
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__orpc_client_e16cd7f2__.createORPCClient)(link);
|
|
18
18
|
}
|
|
19
19
|
export { c15tClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c15t/node-sdk",
|
|
3
|
-
"version": "1.2.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@orpc/client": "1.2.0",
|
|
14
|
+
"@orpc/contract": "1.2.0",
|
|
15
|
+
"@orpc/openapi-client": "^1.2.0",
|
|
14
16
|
"@orpc/server": "1.2.0",
|
|
15
|
-
"@c15t/backend": "1.2.0
|
|
17
|
+
"@c15t/backend": "1.2.0"
|
|
16
18
|
},
|
|
17
19
|
"devDependencies": {
|
|
18
20
|
"@electric-sql/pglite": "0.2.17",
|
|
@@ -22,17 +24,18 @@
|
|
|
22
24
|
"@types/node": "20.14.13",
|
|
23
25
|
"@types/pg": "8.11.6",
|
|
24
26
|
"kysely-pglite": "^0.6.1",
|
|
27
|
+
"msw": "^2.7.6",
|
|
25
28
|
"typescript": "^5.8.3",
|
|
26
29
|
"vitest": "^3.1.1",
|
|
27
|
-
"@c15t/
|
|
28
|
-
"@c15t/
|
|
30
|
+
"@c15t/typescript-config": "0.0.1-beta.1",
|
|
31
|
+
"@c15t/vitest-config": "1.0.0"
|
|
29
32
|
},
|
|
30
33
|
"scripts": {
|
|
31
34
|
"build": "rslib build",
|
|
32
35
|
"check-types": "tsc --noEmit",
|
|
33
36
|
"check-types:test": "tsc -p tsconfig.test.json",
|
|
34
37
|
"dev": "rslib build --watch",
|
|
35
|
-
"fmt": "pnpm biome format --write . && biome check --formatter-enabled=false --linter-enabled=false --organize-imports-enabled=true --write",
|
|
38
|
+
"fmt": "pnpm biome format --write . && pnpm biome check --formatter-enabled=false --linter-enabled=false --organize-imports-enabled=true --write",
|
|
36
39
|
"lint": "pnpm biome lint ./src",
|
|
37
40
|
"test": "vitest run",
|
|
38
41
|
"test:watch": "vitest"
|
|
@@ -0,0 +1,218 @@
|
|
|
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
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { contracts } from '@c15t/backend/contracts';
|
|
2
2
|
import { createORPCClient } from '@orpc/client';
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
3
|
+
import type { ContractRouterClient } from '@orpc/contract';
|
|
4
|
+
import type { JsonifiedClient } from '@orpc/openapi-client';
|
|
5
|
+
import { OpenAPILink } from '@orpc/openapi-client/fetch';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Configuration options for the C15T SDK client
|
|
@@ -63,8 +64,7 @@ export function c15tClient(options: C15TClientOptions) {
|
|
|
63
64
|
baseUrl.pathname = options.prefix;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
const link = new RPCLink({
|
|
67
|
+
const link = new OpenAPILink(contracts, {
|
|
68
68
|
url: baseUrl.toString(),
|
|
69
69
|
headers: {
|
|
70
70
|
...authHeaders,
|
|
@@ -75,7 +75,8 @@ export function c15tClient(options: C15TClientOptions) {
|
|
|
75
75
|
// Create and return the client with a type assertion
|
|
76
76
|
// This approach avoids complex type issues while providing
|
|
77
77
|
// the same runtime functionality
|
|
78
|
-
const client = createORPCClient(link);
|
|
79
78
|
|
|
80
|
-
return
|
|
79
|
+
return createORPCClient(link) as JsonifiedClient<
|
|
80
|
+
ContractRouterClient<typeof contracts>
|
|
81
|
+
>;
|
|
81
82
|
}
|