galileo-generated 0.2.7 → 0.2.9
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/.release-please-config.json +7 -0
- package/.release-please-manifest.json +1 -1
- package/dist/commonjs/hooks/cert-management.d.ts +73 -0
- package/dist/commonjs/hooks/cert-management.d.ts.map +1 -0
- package/dist/commonjs/hooks/cert-management.js +258 -0
- package/dist/commonjs/hooks/cert-management.js.map +1 -0
- package/dist/commonjs/hooks/registration.d.ts.map +1 -1
- package/dist/commonjs/hooks/registration.js +8 -0
- package/dist/commonjs/hooks/registration.js.map +1 -1
- package/dist/commonjs/hooks/sdk-identifier.d.ts +5 -0
- package/dist/commonjs/hooks/sdk-identifier.d.ts.map +1 -0
- package/dist/commonjs/hooks/sdk-identifier.js +37 -0
- package/dist/commonjs/hooks/sdk-identifier.js.map +1 -0
- package/dist/commonjs/lib/galileo-config.d.ts +101 -12
- package/dist/commonjs/lib/galileo-config.d.ts.map +1 -1
- package/dist/commonjs/lib/galileo-config.js +153 -12
- package/dist/commonjs/lib/galileo-config.js.map +1 -1
- package/dist/commonjs/tests/hooks/cert-management.test.d.ts +2 -0
- package/dist/commonjs/tests/hooks/cert-management.test.d.ts.map +1 -0
- package/dist/commonjs/tests/hooks/cert-management.test.js +794 -0
- package/dist/commonjs/tests/hooks/cert-management.test.js.map +1 -0
- package/dist/commonjs/tests/hooks/sdk-identifier.test.d.ts +2 -0
- package/dist/commonjs/tests/hooks/sdk-identifier.test.d.ts.map +1 -0
- package/dist/commonjs/tests/hooks/sdk-identifier.test.js +136 -0
- package/dist/commonjs/tests/hooks/sdk-identifier.test.js.map +1 -0
- package/dist/commonjs/tests/lib/galileo-config.test.js +101 -0
- package/dist/commonjs/tests/lib/galileo-config.test.js.map +1 -1
- package/dist/esm/hooks/cert-management.d.ts +73 -0
- package/dist/esm/hooks/cert-management.d.ts.map +1 -0
- package/dist/esm/hooks/cert-management.js +254 -0
- package/dist/esm/hooks/cert-management.js.map +1 -0
- package/dist/esm/hooks/registration.d.ts.map +1 -1
- package/dist/esm/hooks/registration.js +8 -0
- package/dist/esm/hooks/registration.js.map +1 -1
- package/dist/esm/hooks/sdk-identifier.d.ts +5 -0
- package/dist/esm/hooks/sdk-identifier.d.ts.map +1 -0
- package/dist/esm/hooks/sdk-identifier.js +33 -0
- package/dist/esm/hooks/sdk-identifier.js.map +1 -0
- package/dist/esm/lib/galileo-config.d.ts +101 -12
- package/dist/esm/lib/galileo-config.d.ts.map +1 -1
- package/dist/esm/lib/galileo-config.js +153 -12
- package/dist/esm/lib/galileo-config.js.map +1 -1
- package/dist/esm/tests/hooks/cert-management.test.d.ts +2 -0
- package/dist/esm/tests/hooks/cert-management.test.d.ts.map +1 -0
- package/dist/esm/tests/hooks/cert-management.test.js +792 -0
- package/dist/esm/tests/hooks/cert-management.test.js.map +1 -0
- package/dist/esm/tests/hooks/sdk-identifier.test.d.ts +2 -0
- package/dist/esm/tests/hooks/sdk-identifier.test.d.ts.map +1 -0
- package/dist/esm/tests/hooks/sdk-identifier.test.js +134 -0
- package/dist/esm/tests/hooks/sdk-identifier.test.js.map +1 -0
- package/dist/esm/tests/lib/galileo-config.test.js +101 -0
- package/dist/esm/tests/lib/galileo-config.test.js.map +1 -1
- package/package.json +5 -3
- package/src/hooks/cert-management.ts +288 -0
- package/src/hooks/registration.ts +10 -0
- package/src/hooks/sdk-identifier.ts +41 -0
- package/src/lib/galileo-config.ts +214 -15
- package/src/tests/hooks/cert-management.test.ts +958 -0
- package/src/tests/hooks/sdk-identifier.test.ts +176 -0
- package/src/tests/lib/galileo-config.test.ts +110 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { describe, test, expect, vi } from "vitest";
|
|
2
|
+
import { SDKIdentifierHook } from "../../hooks/sdk-identifier.js";
|
|
3
|
+
import type { BeforeRequestContext } from "../../hooks/types.js";
|
|
4
|
+
|
|
5
|
+
describe("SDKIdentifierHook", () => {
|
|
6
|
+
const mockContext: BeforeRequestContext = {
|
|
7
|
+
baseURL: new URL("http://localhost:8088"),
|
|
8
|
+
operationID: "testOperation",
|
|
9
|
+
oAuth2Scopes: null,
|
|
10
|
+
retryConfig: { strategy: "none" },
|
|
11
|
+
resolvedSecurity: null,
|
|
12
|
+
options: {},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("beforeRequest", () => {
|
|
16
|
+
test("adds X-Galileo-SDK header to request", async () => {
|
|
17
|
+
const hook = new SDKIdentifierHook();
|
|
18
|
+
const request = new Request("http://localhost:8088/api/test");
|
|
19
|
+
|
|
20
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
21
|
+
|
|
22
|
+
expect(modifiedRequest.headers.has("X-Galileo-SDK")).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("header contains galileo-generated prefix", async () => {
|
|
26
|
+
const hook = new SDKIdentifierHook();
|
|
27
|
+
const request = new Request("http://localhost:8088/api/test");
|
|
28
|
+
|
|
29
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
30
|
+
const headerValue = modifiedRequest.headers.get("X-Galileo-SDK");
|
|
31
|
+
|
|
32
|
+
expect(headerValue).toMatch(/^galileo-generated\//);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("header contains valid version format", async () => {
|
|
36
|
+
const hook = new SDKIdentifierHook();
|
|
37
|
+
const request = new Request("http://localhost:8088/api/test");
|
|
38
|
+
|
|
39
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
40
|
+
const headerValue = modifiedRequest.headers.get("X-Galileo-SDK");
|
|
41
|
+
|
|
42
|
+
expect(headerValue).toMatch(/^galileo-generated\/\d+\.\d+\.\d+/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("preserves existing headers", async () => {
|
|
46
|
+
const hook = new SDKIdentifierHook();
|
|
47
|
+
const request = new Request("http://localhost:8088/api/test", {
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
Authorization: "Bearer token",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
55
|
+
|
|
56
|
+
expect(modifiedRequest.headers.get("Content-Type")).toBe("application/json");
|
|
57
|
+
expect(modifiedRequest.headers.get("Authorization")).toBe("Bearer token");
|
|
58
|
+
expect(modifiedRequest.headers.has("X-Galileo-SDK")).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("returns a Request object", async () => {
|
|
62
|
+
const hook = new SDKIdentifierHook();
|
|
63
|
+
const request = new Request("http://localhost:8088/api/test");
|
|
64
|
+
|
|
65
|
+
const result = await hook.beforeRequest(mockContext, request);
|
|
66
|
+
|
|
67
|
+
expect(result instanceof Request).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("does not modify request method or body", async () => {
|
|
71
|
+
const hook = new SDKIdentifierHook();
|
|
72
|
+
const body = JSON.stringify({ test: "data" });
|
|
73
|
+
const request = new Request("http://localhost:8088/api/test", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
79
|
+
|
|
80
|
+
expect(modifiedRequest.method).toBe("POST");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("works with different HTTP methods", async () => {
|
|
84
|
+
const hook = new SDKIdentifierHook();
|
|
85
|
+
|
|
86
|
+
for (const method of ["GET", "POST", "PUT", "DELETE", "PATCH"]) {
|
|
87
|
+
const request = new Request("http://localhost:8088/api/test", {
|
|
88
|
+
method,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
92
|
+
|
|
93
|
+
expect(modifiedRequest.headers.has("X-Galileo-SDK")).toBe(true);
|
|
94
|
+
expect(modifiedRequest.method).toBe(method);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("header value is consistent across multiple calls", async () => {
|
|
99
|
+
const hook = new SDKIdentifierHook();
|
|
100
|
+
const request1 = new Request("http://localhost:8088/api/test");
|
|
101
|
+
const request2 = new Request("http://localhost:8088/api/test");
|
|
102
|
+
|
|
103
|
+
const modifiedRequest1 = await hook.beforeRequest(mockContext, request1);
|
|
104
|
+
const modifiedRequest2 = await hook.beforeRequest(mockContext, request2);
|
|
105
|
+
|
|
106
|
+
const header1 = modifiedRequest1.headers.get("X-Galileo-SDK");
|
|
107
|
+
const header2 = modifiedRequest2.headers.get("X-Galileo-SDK");
|
|
108
|
+
|
|
109
|
+
expect(header1).toBe(header2);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("overwrites existing X-Galileo-SDK header", async () => {
|
|
113
|
+
const hook = new SDKIdentifierHook();
|
|
114
|
+
const request = new Request("http://localhost:8088/api/test", {
|
|
115
|
+
headers: {
|
|
116
|
+
"X-Galileo-SDK": "old-value",
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
121
|
+
const headerValue = modifiedRequest.headers.get("X-Galileo-SDK");
|
|
122
|
+
|
|
123
|
+
expect(headerValue).toMatch(/^galileo-generated\//);
|
|
124
|
+
expect(headerValue).not.toBe("old-value");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("handles loadVersion() failure gracefully with fallback to unknown", async () => {
|
|
128
|
+
vi.resetModules();
|
|
129
|
+
|
|
130
|
+
vi.doMock("../../hooks/sdk-identifier.js", async () => {
|
|
131
|
+
return {
|
|
132
|
+
SDKIdentifierHook: class {
|
|
133
|
+
async beforeRequest(
|
|
134
|
+
_hookCtx: BeforeRequestContext,
|
|
135
|
+
request: Request,
|
|
136
|
+
): Promise<Request> {
|
|
137
|
+
const newRequest = request.clone();
|
|
138
|
+
|
|
139
|
+
const loadVersionWithFailure = (): string => {
|
|
140
|
+
try {
|
|
141
|
+
throw new Error("Failed to load package.json (ESM runtime issue)");
|
|
142
|
+
} catch {
|
|
143
|
+
return "unknown";
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const version = loadVersionWithFailure();
|
|
148
|
+
const sdkIdentifier = `galileo-generated/${version}`;
|
|
149
|
+
newRequest.headers.set("X-Galileo-SDK", sdkIdentifier);
|
|
150
|
+
return newRequest;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const { SDKIdentifierHook: MockedHook } = await import("../../hooks/sdk-identifier.js");
|
|
157
|
+
const hook = new MockedHook();
|
|
158
|
+
const request = new Request("http://localhost:8088/api/test");
|
|
159
|
+
|
|
160
|
+
const modifiedRequest = await hook.beforeRequest(mockContext, request);
|
|
161
|
+
const headerValue = modifiedRequest.headers.get("X-Galileo-SDK");
|
|
162
|
+
|
|
163
|
+
expect(headerValue).toBe("galileo-generated/unknown");
|
|
164
|
+
|
|
165
|
+
vi.doUnmock("../../hooks/sdk-identifier.js");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("hook integration", () => {
|
|
170
|
+
test("hook implements BeforeRequestHook interface", () => {
|
|
171
|
+
const hook = new SDKIdentifierHook();
|
|
172
|
+
|
|
173
|
+
expect(typeof hook.beforeRequest).toBe("function");
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
@@ -13,6 +13,11 @@ const ENV_KEYS = [
|
|
|
13
13
|
'GALILEO_PROJECT_NAME',
|
|
14
14
|
'GALILEO_LOG_STREAM',
|
|
15
15
|
'GALILEO_LOG_STREAM_NAME',
|
|
16
|
+
'GALILEO_CA_CERT_PATH',
|
|
17
|
+
'GALILEO_CA_CERT_CONTENT',
|
|
18
|
+
'GALILEO_CLIENT_CERT_PATH',
|
|
19
|
+
'GALILEO_CLIENT_KEY_PATH',
|
|
20
|
+
'GALILEO_REJECT_UNAUTHORIZED',
|
|
16
21
|
] as const;
|
|
17
22
|
|
|
18
23
|
function clearGalileoEnv(): void {
|
|
@@ -233,4 +238,109 @@ describe('GalileoConfig', () => {
|
|
|
233
238
|
expect(() => config.logConfig()).not.toThrow();
|
|
234
239
|
spy.mockRestore();
|
|
235
240
|
});
|
|
241
|
+
|
|
242
|
+
test('test getCertConfig returns cert fields from overrides', () => {
|
|
243
|
+
GalileoConfig.reset();
|
|
244
|
+
const config = GalileoConfig.get({
|
|
245
|
+
apiKey: 'key',
|
|
246
|
+
apiUrl: 'https://api.example.com',
|
|
247
|
+
caCertPath: '/path/to/ca.pem',
|
|
248
|
+
caCertContent: '-----BEGIN CERTIFICATE-----',
|
|
249
|
+
clientCertPath: '/path/to/client.pem',
|
|
250
|
+
clientKeyPath: '/path/to/key.pem',
|
|
251
|
+
rejectUnauthorized: false,
|
|
252
|
+
});
|
|
253
|
+
const cert = config.getCertConfig();
|
|
254
|
+
expect(cert).not.toBeNull();
|
|
255
|
+
if (!cert) throw new Error("unreachable");
|
|
256
|
+
expect(cert.caCertPath).toBe('/path/to/ca.pem');
|
|
257
|
+
expect(cert.caCertContent).toBe('-----BEGIN CERTIFICATE-----');
|
|
258
|
+
expect(cert.clientCertPath).toBe('/path/to/client.pem');
|
|
259
|
+
expect(cert.clientKeyPath).toBe('/path/to/key.pem');
|
|
260
|
+
expect(cert.rejectUnauthorized).toBe(false);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('test getCertConfig empty when no cert set', () => {
|
|
264
|
+
GalileoConfig.reset();
|
|
265
|
+
const config = GalileoConfig.get({
|
|
266
|
+
apiKey: 'key',
|
|
267
|
+
apiUrl: 'https://api.example.com',
|
|
268
|
+
});
|
|
269
|
+
const cert = config.getCertConfig();
|
|
270
|
+
expect(cert).toBeNull();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('test snapshot includes cert when set', () => {
|
|
274
|
+
GalileoConfig.reset();
|
|
275
|
+
const config = GalileoConfig.get({
|
|
276
|
+
apiKey: 'key',
|
|
277
|
+
apiUrl: 'https://api.example.com',
|
|
278
|
+
caCertPath: '/ca.pem',
|
|
279
|
+
rejectUnauthorized: true,
|
|
280
|
+
});
|
|
281
|
+
expect(config.snapshot.cert).toEqual({
|
|
282
|
+
caCertPath: '/ca.pem',
|
|
283
|
+
rejectUnauthorized: true,
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('test cert from env', () => {
|
|
288
|
+
GalileoConfig.reset();
|
|
289
|
+
process.env['GALILEO_API_KEY'] = 'env-key';
|
|
290
|
+
process.env['GALILEO_CA_CERT_PATH'] = '/env/ca.pem';
|
|
291
|
+
process.env['GALILEO_REJECT_UNAUTHORIZED'] = 'false';
|
|
292
|
+
const config = GalileoConfig.get({});
|
|
293
|
+
const cert = config.getCertConfig();
|
|
294
|
+
expect(cert).not.toBeNull();
|
|
295
|
+
if (!cert) throw new Error("unreachable");
|
|
296
|
+
expect(cert.caCertPath).toBe('/env/ca.pem');
|
|
297
|
+
expect(cert.rejectUnauthorized).toBe(false);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('test empty GALILEO_REJECT_UNAUTHORIZED treated as undefined', () => {
|
|
301
|
+
GalileoConfig.reset();
|
|
302
|
+
process.env['GALILEO_API_KEY'] = 'env-key';
|
|
303
|
+
process.env['GALILEO_REJECT_UNAUTHORIZED'] = '';
|
|
304
|
+
const config = GalileoConfig.get({});
|
|
305
|
+
const cert = config.getCertConfig();
|
|
306
|
+
expect(cert).toBeNull();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('test empty NODE_TLS_REJECT_UNAUTHORIZED treated as undefined', () => {
|
|
310
|
+
GalileoConfig.reset();
|
|
311
|
+
process.env['GALILEO_API_KEY'] = 'env-key';
|
|
312
|
+
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '';
|
|
313
|
+
const config = GalileoConfig.get({});
|
|
314
|
+
const cert = config.getCertConfig();
|
|
315
|
+
expect(cert).toBeNull();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('test explicit rejectUnauthorized values', () => {
|
|
319
|
+
GalileoConfig.reset();
|
|
320
|
+
process.env['GALILEO_API_KEY'] = 'env-key';
|
|
321
|
+
|
|
322
|
+
// Test "true" string
|
|
323
|
+
process.env['GALILEO_REJECT_UNAUTHORIZED'] = 'true';
|
|
324
|
+
let config = GalileoConfig.get({});
|
|
325
|
+
let cert = config.getCertConfig();
|
|
326
|
+
expect(cert?.rejectUnauthorized).toBe(true);
|
|
327
|
+
|
|
328
|
+
GalileoConfig.reset();
|
|
329
|
+
process.env['GALILEO_REJECT_UNAUTHORIZED'] = '1';
|
|
330
|
+
config = GalileoConfig.get({});
|
|
331
|
+
cert = config.getCertConfig();
|
|
332
|
+
expect(cert?.rejectUnauthorized).toBe(true);
|
|
333
|
+
|
|
334
|
+
GalileoConfig.reset();
|
|
335
|
+
process.env['GALILEO_REJECT_UNAUTHORIZED'] = 'false';
|
|
336
|
+
config = GalileoConfig.get({});
|
|
337
|
+
cert = config.getCertConfig();
|
|
338
|
+
expect(cert?.rejectUnauthorized).toBe(false);
|
|
339
|
+
|
|
340
|
+
GalileoConfig.reset();
|
|
341
|
+
process.env['GALILEO_REJECT_UNAUTHORIZED'] = '0';
|
|
342
|
+
config = GalileoConfig.get({});
|
|
343
|
+
cert = config.getCertConfig();
|
|
344
|
+
expect(cert?.rejectUnauthorized).toBe(false);
|
|
345
|
+
});
|
|
236
346
|
});
|