@aloma.io/integration-sdk 3.8.70 → 3.8.71
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 +15 -2
- package/build/internal/connector/server/on-connect/make-oauth.mjs +27 -6
- package/build/internal/fetcher/fetcher.d.mts +14 -1
- package/build/internal/fetcher/fetcher.mjs +52 -11
- package/build/internal/fetcher/oauth-fetcher.d.mts +15 -2
- package/build/internal/fetcher/oauth-fetcher.mjs +72 -27
- package/build/internal/util/index.d.mts +8 -0
- package/build/internal/util/index.mjs +13 -1
- package/build/internal/util/jwe/index.mjs +3 -1
- package/package.json +8 -3
- package/.prettierrc.cjs +0 -8
- package/FINDINGS-PLAT-47.md +0 -253
- package/MULTI_RESOURCE_GUIDE.md +0 -220
- package/OPENAPI_TO_CONNECTOR.md +0 -349
- package/examples/hello-world/package.json +0 -25
- package/examples/hello-world/src/controller/index.mts +0 -12
- package/examples/hello-world/src/index.mts +0 -6
- package/examples/hello-world/tsconfig.json +0 -27
- package/examples/sample-api.json +0 -325
- package/examples/sample-api.yaml +0 -222
- package/examples/simple-api.json +0 -39
- package/index.js +0 -4
- package/src/builder/index.mts +0 -274
- package/src/builder/runtime-context.mts +0 -129
- package/src/cli.mts +0 -533
- package/src/controller/index.mts +0 -278
- package/src/index.mts +0 -2
- package/src/internal/connector/config.mts +0 -59
- package/src/internal/connector/index.mts +0 -53
- package/src/internal/connector/metrics.mts +0 -34
- package/src/internal/connector/server/index.mts +0 -51
- package/src/internal/connector/server/on-connect/decrypt-config.mts +0 -27
- package/src/internal/connector/server/on-connect/finish-oauth.mts +0 -109
- package/src/internal/connector/server/on-connect/index.mts +0 -162
- package/src/internal/connector/server/on-connect/make-oauth.mts +0 -97
- package/src/internal/connector/server/on-connect/start-oauth.mts +0 -24
- package/src/internal/connector/server/on-message.mts +0 -13
- package/src/internal/dispatcher/index.mts +0 -231
- package/src/internal/fetcher/fetcher.mts +0 -215
- package/src/internal/fetcher/oauth-fetcher.mts +0 -153
- package/src/internal/index.mts +0 -3
- package/src/internal/util/index.mts +0 -52
- package/src/internal/util/jwe/cli.mts +0 -12
- package/src/internal/util/jwe/index.mts +0 -72
- package/src/internal/websocket/config.mjs +0 -109
- package/src/internal/websocket/connection/constants.mjs +0 -25
- package/src/internal/websocket/connection/index.mjs +0 -71
- package/src/internal/websocket/connection/registration.mjs +0 -42
- package/src/internal/websocket/index.mjs +0 -46
- package/src/internal/websocket/transport/durable.mjs +0 -71
- package/src/internal/websocket/transport/index.mjs +0 -194
- package/src/internal/websocket/transport/packet.mjs +0 -54
- package/src/internal/websocket/transport/processor.mjs +0 -66
- package/src/openapi-to-connector.mts +0 -1648
- package/src/testing/fake-aloma.mts +0 -306
- package/src/testing/harness.mts +0 -172
- package/src/testing/index.mts +0 -15
- package/src/testing/keys.mts +0 -19
- package/src/testing/network-guard.mts +0 -57
- package/src/testing/runtime-connector.mts +0 -50
- package/src/testing/vendor-mock.mts +0 -166
- package/src/transform/index.mts +0 -544
- package/test/MUTATION-entry.md +0 -21
- package/test/MUTATION.md +0 -43
- package/test/dispatcher-ctx-forwarding.test.mjs +0 -161
- package/test/fetcher-query-params.test.mjs +0 -294
- package/test/fixtures/transform/basic/expected.json +0 -9
- package/test/fixtures/transform/basic/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/basic/src/controller/index.mts +0 -30
- package/test/fixtures/transform/basic/tsconfig.json +0 -1
- package/test/fixtures/transform/interface-param/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/interface-param/src/controller/index.mts +0 -12
- package/test/fixtures/transform/interface-param/tsconfig.json +0 -1
- package/test/fixtures/transform/overloads/expected.json +0 -6
- package/test/fixtures/transform/overloads/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/overloads/src/controller/index.mts +0 -11
- package/test/fixtures/transform/overloads/tsconfig.json +0 -1
- package/test/fixtures/transform/tdd-stub/expected.json +0 -8
- package/test/fixtures/transform/tdd-stub/src/controller/abstract.mts +0 -6
- package/test/fixtures/transform/tdd-stub/src/controller/index.mts +0 -204
- package/test/fixtures/transform/tdd-stub/tsconfig.json +0 -1
- package/test/fixtures/transform/two-exports/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/two-exports/src/controller/index.mts +0 -9
- package/test/fixtures/transform/two-exports/tsconfig.json +0 -1
- package/test/fixtures/transform/type-error/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/type-error/src/controller/index.mts +0 -7
- package/test/fixtures/transform/type-error/tsconfig.json +0 -1
- package/test/fixtures/transform/typed/expected.json +0 -8
- package/test/fixtures/transform/typed/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/typed/src/controller/index.mts +0 -13
- package/test/fixtures/transform/typed/tsconfig.json +0 -1
- package/test/fixtures/transform/visibility/expected.json +0 -9
- package/test/fixtures/transform/visibility/src/controller/abstract.mts +0 -5
- package/test/fixtures/transform/visibility/src/controller/index.mts +0 -19
- package/test/fixtures/transform/visibility/tsconfig.json +0 -1
- package/test/harness-connector-smoke.test.mjs +0 -72
- package/test/harness.test.mjs +0 -375
- package/test/nested-resolver.test.mjs +0 -184
- package/test/openapi-generator-bugs.test.mjs +0 -248
- package/test/openapi-identifier-sanitise.test.mjs +0 -69
- package/test/openapi-nested-paths.test.mjs +0 -100
- package/test/openapi-to-connector.test.mts +0 -232
- package/test/openapi-ts-compilation.test.mjs +0 -178
- package/test/scenarios/README.md +0 -148
- package/test/scenarios/complex/expected/controller.mts +0 -271
- package/test/scenarios/complex/expected/orders-resource.mts +0 -262
- package/test/scenarios/complex/expected/products-resource.mts +0 -237
- package/test/scenarios/complex/specs/orders.json +0 -362
- package/test/scenarios/complex/specs/products.json +0 -308
- package/test/scenarios/simple/expected-controller.mts +0 -60
- package/test/scenarios/simple/simple-api.json +0 -39
- package/test/scenarios.test.mts +0 -294
- package/test/transform.test.mjs +0 -68
- package/test/verify-scenarios.mjs +0 -298
- package/tools/mutation-run-entry.mjs +0 -52
- package/tools/mutation-run.mjs +0 -138
- package/tools/run-tests.mjs +0 -64
- package/tsconfig.json +0 -27
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { Dispatcher } from '../build/internal/dispatcher/index.mjs';
|
|
2
|
-
import { buildResolvers } from '../build/builder/runtime-context.mjs';
|
|
3
|
-
|
|
4
|
-
// Simple test framework matching project convention
|
|
5
|
-
const colors = {
|
|
6
|
-
green: '\x1b[32m',
|
|
7
|
-
red: '\x1b[31m',
|
|
8
|
-
yellow: '\x1b[33m',
|
|
9
|
-
reset: '\x1b[0m',
|
|
10
|
-
cyan: '\x1b[36m'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
let passed = 0;
|
|
14
|
-
let failed = 0;
|
|
15
|
-
|
|
16
|
-
async function test(name, fn) {
|
|
17
|
-
try {
|
|
18
|
-
console.log(`${colors.cyan}Running: ${name}${colors.reset}`);
|
|
19
|
-
await fn();
|
|
20
|
-
console.log(`${colors.green}✓ PASS: ${name}${colors.reset}\n`);
|
|
21
|
-
passed++;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.log(`${colors.red}✗ FAIL: ${name}${colors.reset}`);
|
|
24
|
-
console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`);
|
|
25
|
-
failed++;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function assert(condition, message) {
|
|
30
|
-
if (!condition) throw new Error(message || 'Assertion failed');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function assertEqual(actual, expected, message) {
|
|
34
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
35
|
-
throw new Error(message || `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Helper: build a dispatcher with given resolvers and execute a query+envelope.
|
|
40
|
-
// IMPORTANT: this test passes taskId/namespace/sticky in the envelope to verify the
|
|
41
|
-
// dispatcher destructures them and forwards them as a ctx object to handlers.
|
|
42
|
-
async function buildAndExecute(resolvers, envelope) {
|
|
43
|
-
const dispatcher = new Dispatcher();
|
|
44
|
-
dispatcher.types({ fields: {} });
|
|
45
|
-
dispatcher.resolvers(resolvers);
|
|
46
|
-
dispatcher.main(async () => {});
|
|
47
|
-
const built = dispatcher.build();
|
|
48
|
-
return built.execute(envelope);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// --- RED TESTS for ctx forwarding (SDK v3.8.67 additive change) ---
|
|
52
|
-
|
|
53
|
-
// Test 1: dispatcher.execute forwards ctx (taskId, namespace, sticky) to a NAMED METHOD handler
|
|
54
|
-
// as the second argument. Currently the dispatcher only passes `variables` — so the second
|
|
55
|
-
// arg is undefined and this test must FAIL (red) until the SDK is patched.
|
|
56
|
-
await test('dispatcher forwards ctx as second arg to named-method handler', async () => {
|
|
57
|
-
let receivedArgs;
|
|
58
|
-
let receivedCtx;
|
|
59
|
-
|
|
60
|
-
// Use buildResolvers so the wrapper is exercised exactly as it is in production.
|
|
61
|
-
const mockController = {
|
|
62
|
-
myMethod: async (args, ctx) => {
|
|
63
|
-
receivedArgs = args;
|
|
64
|
-
receivedCtx = ctx;
|
|
65
|
-
return { ok: true };
|
|
66
|
-
},
|
|
67
|
-
'__autocomplete': async () => ({}),
|
|
68
|
-
'__endpoint': async () => ({}),
|
|
69
|
-
'__default': async () => ({}),
|
|
70
|
-
};
|
|
71
|
-
const methods = ['myMethod', '__autocomplete', '__endpoint', '__default'];
|
|
72
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
73
|
-
|
|
74
|
-
await buildAndExecute(resolvers, {
|
|
75
|
-
query: ['myMethod'],
|
|
76
|
-
variables: { foo: 'bar' },
|
|
77
|
-
taskId: 'task-123',
|
|
78
|
-
namespace: 'testing',
|
|
79
|
-
sticky: 'sticky-abc',
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
assertEqual(receivedArgs, { foo: 'bar' }, 'args should be forwarded unchanged');
|
|
83
|
-
assert(receivedCtx !== undefined, 'ctx should be defined as second argument');
|
|
84
|
-
assertEqual(receivedCtx.taskId, 'task-123', `ctx.taskId should be "task-123", got ${JSON.stringify(receivedCtx)}`);
|
|
85
|
-
assertEqual(receivedCtx.namespace, 'testing', `ctx.namespace should be "testing", got ${JSON.stringify(receivedCtx)}`);
|
|
86
|
-
assertEqual(receivedCtx.sticky, 'sticky-abc', `ctx.sticky should be "sticky-abc", got ${JSON.stringify(receivedCtx)}`);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Test 2: dispatcher.execute forwards ctx to the __default (fallback) handler as second arg
|
|
90
|
-
// when the named method is not found. Currently the __default invocation only receives the
|
|
91
|
-
// merged variables — so ctx is undefined and this test must FAIL (red) until patched.
|
|
92
|
-
await test('dispatcher forwards ctx as second arg to __default fallback handler', async () => {
|
|
93
|
-
let receivedArg;
|
|
94
|
-
let receivedCtx;
|
|
95
|
-
|
|
96
|
-
// Resolvers map with ONLY __default — no named methods, so dispatcher falls back.
|
|
97
|
-
const resolvers = {
|
|
98
|
-
__default: async (arg, ctx) => {
|
|
99
|
-
receivedArg = arg;
|
|
100
|
-
receivedCtx = ctx;
|
|
101
|
-
return { fallback: true };
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
await buildAndExecute(resolvers, {
|
|
106
|
-
query: ['someUnknownMethod'],
|
|
107
|
-
variables: { hello: 'world' },
|
|
108
|
-
taskId: 'task-456',
|
|
109
|
-
namespace: 'testing',
|
|
110
|
-
sticky: 'sticky-def',
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
assert(receivedArg !== undefined, '__default should receive arg');
|
|
114
|
-
assertEqual(receivedArg.hello, 'world', 'variables should be merged into arg');
|
|
115
|
-
assertEqual(receivedArg.__method, ['someUnknownMethod'], '__method should be in arg');
|
|
116
|
-
assert(receivedCtx !== undefined, 'ctx should be defined as second argument to __default');
|
|
117
|
-
assertEqual(receivedCtx.taskId, 'task-456', `ctx.taskId should be "task-456", got ${JSON.stringify(receivedCtx)}`);
|
|
118
|
-
assertEqual(receivedCtx.namespace, 'testing', `ctx.namespace should be "testing"`);
|
|
119
|
-
assertEqual(receivedCtx.sticky, 'sticky-def', `ctx.sticky should be "sticky-def"`);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Test 3: BACKWARD COMPATIBILITY. A controller method with the old 1-arg signature
|
|
123
|
-
// `async myMethod(args)` continues to work when called via the new dispatcher path.
|
|
124
|
-
// The second argument exists but is ignored. This test MUST PASS even in the red phase —
|
|
125
|
-
// if it fails red, the test setup is broken (not the implementation).
|
|
126
|
-
await test('one-arg handler still works (backward compatibility)', async () => {
|
|
127
|
-
let receivedArgs;
|
|
128
|
-
|
|
129
|
-
const mockController = {
|
|
130
|
-
// Note: only one parameter. Second arg, if any, must be silently ignored.
|
|
131
|
-
legacyMethod: async (args) => {
|
|
132
|
-
receivedArgs = args;
|
|
133
|
-
return { legacy: true, ...args };
|
|
134
|
-
},
|
|
135
|
-
'__autocomplete': async () => ({}),
|
|
136
|
-
'__endpoint': async () => ({}),
|
|
137
|
-
'__default': async () => ({}),
|
|
138
|
-
};
|
|
139
|
-
const methods = ['legacyMethod', '__autocomplete', '__endpoint', '__default'];
|
|
140
|
-
const resolvers = buildResolvers(methods, mockController);
|
|
141
|
-
|
|
142
|
-
const result = await buildAndExecute(resolvers, {
|
|
143
|
-
query: ['legacyMethod'],
|
|
144
|
-
variables: { id: 7 },
|
|
145
|
-
taskId: 'task-789',
|
|
146
|
-
namespace: 'testing',
|
|
147
|
-
sticky: 'sticky-ghi',
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
assertEqual(receivedArgs, { id: 7 }, 'legacy handler should receive args unchanged');
|
|
151
|
-
assertEqual(result, { legacy: true, id: 7 }, 'legacy handler should return correct result');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// --- Results ---
|
|
155
|
-
console.log(`\n${colors.yellow}--- Dispatcher ctx forwarding test results ---${colors.reset}`);
|
|
156
|
-
console.log(`${colors.green}Passed: ${passed}${colors.reset}`);
|
|
157
|
-
console.log(`${colors.red}Failed: ${failed}${colors.reset}`);
|
|
158
|
-
|
|
159
|
-
if (failed > 0) {
|
|
160
|
-
process.exit(1);
|
|
161
|
-
}
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
// PLAT-47: the Fetcher sends fetchOptions.params as the query string.
|
|
2
|
-
// Standalone script (no mocha). Global fetch is stubbed in this process, except one test that uses a local
|
|
3
|
-
// HTTP server on 127.0.0.1. No request leaves the test process.
|
|
4
|
-
import http from 'node:http';
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
import Fetcher from '../build/internal/fetcher/fetcher.mjs';
|
|
7
|
-
import {OAuth} from '../build/internal/fetcher/oauth-fetcher.mjs';
|
|
8
|
-
|
|
9
|
-
const colors = {green: '\x1b[32m', red: '\x1b[31m', yellow: '\x1b[33m', reset: '\x1b[0m', cyan: '\x1b[36m'};
|
|
10
|
-
|
|
11
|
-
let passed = 0;
|
|
12
|
-
let failed = 0;
|
|
13
|
-
|
|
14
|
-
async function test(name, fn) {
|
|
15
|
-
try {
|
|
16
|
-
console.log(`${colors.cyan}Running: ${name}${colors.reset}`);
|
|
17
|
-
await fn();
|
|
18
|
-
console.log(`${colors.green}✓ PASS: ${name}${colors.reset}\n`);
|
|
19
|
-
passed++;
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.log(`${colors.red}✗ FAIL: ${name}${colors.reset}`);
|
|
22
|
-
console.log(`${colors.red} Error: ${error.message}${colors.reset}\n`);
|
|
23
|
-
failed++;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function assert(condition, message) {
|
|
28
|
-
if (!condition) throw new Error(message || 'Assertion failed');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function assertEqual(actual, expected, message) {
|
|
32
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
33
|
-
throw new Error(`${message || 'not equal'}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const BASE = 'https://api.vendor.example.test';
|
|
38
|
-
// Fetcher collapses every run of slashes in baseUrl + url, so the scheme loses one slash (today's behaviour).
|
|
39
|
-
const RAW = 'https:/api.vendor.example.test';
|
|
40
|
-
|
|
41
|
-
// Replace global fetch with a recorder. `replies` is a list of statuses; the last one repeats.
|
|
42
|
-
function stubFetch(replies = [200]) {
|
|
43
|
-
const calls = [];
|
|
44
|
-
const realFetch = globalThis.fetch;
|
|
45
|
-
globalThis.fetch = async (url, init) => {
|
|
46
|
-
calls.push({url, init});
|
|
47
|
-
const status = replies[Math.min(calls.length - 1, replies.length - 1)];
|
|
48
|
-
return new Response(status === 204 ? null : JSON.stringify({ok: status < 400}), {
|
|
49
|
-
status,
|
|
50
|
-
headers: {'content-type': 'application/json'},
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
return {calls, restore: () => (globalThis.fetch = realFetch)};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function send(path, options, fetcherOptions = {}, replies) {
|
|
57
|
-
const stub = stubFetch(replies);
|
|
58
|
-
try {
|
|
59
|
-
const fetcher = new Fetcher({baseUrl: BASE, retry: 1, ...fetcherOptions});
|
|
60
|
-
let error;
|
|
61
|
-
try {
|
|
62
|
-
await fetcher.fetch(path, options);
|
|
63
|
-
} catch (e) {
|
|
64
|
-
error = e;
|
|
65
|
-
}
|
|
66
|
-
return {calls: stub.calls, error};
|
|
67
|
-
} finally {
|
|
68
|
-
stub.restore();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function initWithoutSignal(init) {
|
|
73
|
-
const {signal, ...rest} = init;
|
|
74
|
-
return rest;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// --- Rule 1: params become the query string ---
|
|
78
|
-
|
|
79
|
-
await test('numbers, strings and booleans are stringified into the query string', async () => {
|
|
80
|
-
const {calls} = await send('/crm/v3/objects/contacts', {
|
|
81
|
-
method: 'GET',
|
|
82
|
-
params: {limit: 10, after: 'abc', archived: false},
|
|
83
|
-
});
|
|
84
|
-
assertEqual(calls.length, 1, 'one request');
|
|
85
|
-
assertEqual(calls[0].url, `${RAW}/crm/v3/objects/contacts?limit=10&after=abc&archived=false`, 'url');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await test('query parameters already in the url are kept', async () => {
|
|
89
|
-
const {calls} = await send('/items?foo=1', {method: 'GET', params: {bar: 2}});
|
|
90
|
-
assertEqual(calls[0].url, `${RAW}/items?foo=1&bar=2`, 'url');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
await test('undefined and null values are skipped', async () => {
|
|
94
|
-
const {calls} = await send('/items', {method: 'GET', params: {a: undefined, b: null, c: 'x', d: 0, e: ''}});
|
|
95
|
-
assertEqual(calls[0].url, `${RAW}/items?c=x&d=0&e=`, 'url');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
await test('arrays become repeated keys', async () => {
|
|
99
|
-
const {calls} = await send('/crm/v3/objects/contacts', {
|
|
100
|
-
method: 'GET',
|
|
101
|
-
params: {properties: ['firstname', 'lastname'], limit: 1},
|
|
102
|
-
});
|
|
103
|
-
assertEqual(calls[0].url, `${RAW}/crm/v3/objects/contacts?properties=firstname&properties=lastname&limit=1`, 'url');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
await test('undefined and null array items are skipped, other items stringified', async () => {
|
|
107
|
-
const {calls} = await send('/items', {method: 'GET', params: {ids: [1, undefined, null, true, 'x']}});
|
|
108
|
-
assertEqual(calls[0].url, `${RAW}/items?ids=1&ids=true&ids=x`, 'url');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await test('nested objects are refused with a clear error and nothing is sent', async () => {
|
|
112
|
-
const started = Date.now();
|
|
113
|
-
const {calls, error} = await send('/items', {method: 'GET', params: {filter: {a: 1}}}, {retry: 3});
|
|
114
|
-
assert(error, 'fetch must reject');
|
|
115
|
-
assert(/params\.filter/.test(error.message) && /object/.test(error.message), `error message: ${error.message}`);
|
|
116
|
-
assertEqual(calls.length, 0, 'no request sent');
|
|
117
|
-
assert(Date.now() - started < 400, 'refused at once, not retried');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
await test('objects inside arrays are refused too', async () => {
|
|
121
|
-
const {calls, error} = await send('/items', {method: 'GET', params: {ids: [{a: 1}]}});
|
|
122
|
-
assert(error && /params\.ids/.test(error.message), `error: ${error && error.message}`);
|
|
123
|
-
assertEqual(calls.length, 0, 'no request sent');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
await test('values are encoded by URLSearchParams and a "//" inside a value is not collapsed', async () => {
|
|
127
|
-
const value = 'a b&c=d/é https://x.test//y';
|
|
128
|
-
const {calls} = await send('/items', {method: 'GET', params: {q: value}});
|
|
129
|
-
assertEqual(calls[0].url, `${RAW}/items?${new URLSearchParams({q: value})}`, 'url');
|
|
130
|
-
assertEqual(new URL(calls[0].url).searchParams.get('q'), value, 'decoded value round-trips');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
await test('a URLSearchParams instance is sent as it is', async () => {
|
|
134
|
-
const {calls} = await send('/items', {
|
|
135
|
-
method: 'GET',
|
|
136
|
-
params: new URLSearchParams([
|
|
137
|
-
['a', '1'],
|
|
138
|
-
['a', '2'],
|
|
139
|
-
]),
|
|
140
|
-
});
|
|
141
|
-
assertEqual(calls[0].url, `${RAW}/items?a=1&a=2`, 'url');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
await test('without baseUrl the query is appended to the url as given', async () => {
|
|
145
|
-
const {calls} = await send('https://other.example.test/x', {method: 'GET', params: {a: 1}}, {baseUrl: undefined});
|
|
146
|
-
assertEqual(calls[0].url, 'https://other.example.test/x?a=1', 'url');
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// --- Rule 2: nothing else changes ---
|
|
150
|
-
|
|
151
|
-
await test('params is not passed on to global fetch; headers, body and method are unchanged', async () => {
|
|
152
|
-
const options = {method: 'POST', headers: {'X-Custom': '1'}, body: {name: 'n'}};
|
|
153
|
-
const plain = await send('/items', {...options});
|
|
154
|
-
const withParams = await send('/items', {...options, params: {a: 1}});
|
|
155
|
-
assert(!('params' in withParams.calls[0].init), 'params must not reach native fetch');
|
|
156
|
-
assertEqual(initWithoutSignal(withParams.calls[0].init), initWithoutSignal(plain.calls[0].init), 'init');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
await test('the caller options and params objects are not mutated', async () => {
|
|
160
|
-
const params = {a: 1, list: ['x', 'y'], skip: undefined};
|
|
161
|
-
const options = {method: 'GET', params};
|
|
162
|
-
await send('/items', options);
|
|
163
|
-
assertEqual(Object.keys(options), ['method', 'params'], 'options keys');
|
|
164
|
-
assert(options.params === params, 'same params object');
|
|
165
|
-
assertEqual(Object.keys(params), ['a', 'list', 'skip'], 'params keys');
|
|
166
|
-
assertEqual(params.list, ['x', 'y'], 'array untouched');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
await test('customize runs as before and can change url and params', async () => {
|
|
170
|
-
let seen;
|
|
171
|
-
const {calls} = await send(
|
|
172
|
-
'/items',
|
|
173
|
-
{method: 'GET', params: {a: 1}},
|
|
174
|
-
{
|
|
175
|
-
customize: (o) => {
|
|
176
|
-
seen = {url: o.url, params: {...o.params}};
|
|
177
|
-
o.url = '/v2' + o.url;
|
|
178
|
-
o.params = {...o.params, key: 'k'};
|
|
179
|
-
o.headers = {...o.headers, Authorization: 'Bearer t'};
|
|
180
|
-
},
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
assertEqual(seen, {url: '/items', params: {a: 1}}, 'customize input');
|
|
184
|
-
assertEqual(calls[0].url, `${RAW}/v2/items?a=1&key=k`, 'url');
|
|
185
|
-
assertEqual(calls[0].init.headers.Authorization, 'Bearer t', 'customize header');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
await test('a retried request sends the same url with the query string exactly once', async () => {
|
|
189
|
-
const {calls, error} = await send(
|
|
190
|
-
'/items',
|
|
191
|
-
{method: 'GET', params: {a: 1, list: ['x', 'y']}},
|
|
192
|
-
{retry: 2},
|
|
193
|
-
[500, 200]
|
|
194
|
-
);
|
|
195
|
-
assert(!error, `no error expected, got ${error && error.message}`);
|
|
196
|
-
assertEqual(calls.length, 2, 'first try + one retry');
|
|
197
|
-
assertEqual(calls[0].url, `${RAW}/items?a=1&list=x&list=y`, 'first url');
|
|
198
|
-
assertEqual(calls[1].url, calls[0].url, 'retry url');
|
|
199
|
-
assert(!('params' in calls[1].init), 'params must not reach native fetch on retry');
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
await test('a failed attempt logs the url without its query string', async () => {
|
|
203
|
-
const logged = [];
|
|
204
|
-
const realLog = console.log;
|
|
205
|
-
console.log = (...args) => logged.push(args.map(String).join(' '));
|
|
206
|
-
let calls;
|
|
207
|
-
try {
|
|
208
|
-
({calls} = await send('/items?id=user42', {method: 'GET', params: {email: 'person@example.test'}}, {retry: 1}, [
|
|
209
|
-
500,
|
|
210
|
-
]));
|
|
211
|
-
} finally {
|
|
212
|
-
console.log = realLog;
|
|
213
|
-
}
|
|
214
|
-
assertEqual(calls[0].url, `${RAW}/items?id=user42&email=person%40example.test`, 'the query is sent');
|
|
215
|
-
assert(logged.length > 0, 'the failure is logged');
|
|
216
|
-
assert(
|
|
217
|
-
!logged.some((l) => l.includes('person') || l.includes('user42')),
|
|
218
|
-
`query value leaked into the log: ${logged.join(' | ')}`
|
|
219
|
-
);
|
|
220
|
-
assert(
|
|
221
|
-
logged.some((l) => l.includes(`${RAW}/items`)),
|
|
222
|
-
'the path is still logged'
|
|
223
|
-
);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// --- Rule 3: no params gives exactly today's URL ---
|
|
227
|
-
|
|
228
|
-
await test('no params, empty params or all-undefined params give exactly the old url', async () => {
|
|
229
|
-
for (const options of [
|
|
230
|
-
{method: 'GET'},
|
|
231
|
-
{method: 'GET', params: {}},
|
|
232
|
-
{method: 'GET', params: {a: undefined, b: null}},
|
|
233
|
-
{method: 'GET', params: undefined},
|
|
234
|
-
]) {
|
|
235
|
-
const {calls} = await send('/items/1', options);
|
|
236
|
-
assertEqual(calls[0].url, `${RAW}/items/1`, `url for ${JSON.stringify(options)}`);
|
|
237
|
-
}
|
|
238
|
-
const {calls} = await send('/items/1?x=1', {method: 'GET', params: {}});
|
|
239
|
-
assertEqual(calls[0].url, `${RAW}/items/1?x=1`, 'existing query alone is untouched');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// --- OAuth fetcher inherits the behaviour ---
|
|
243
|
-
|
|
244
|
-
await test('the OAuth fetcher sends the query string and its Bearer token', async () => {
|
|
245
|
-
const stub = stubFetch();
|
|
246
|
-
try {
|
|
247
|
-
const client = new OAuth({access_token: 'tok'}).getClient({baseUrl: BASE, retry: 1});
|
|
248
|
-
await client.fetch('/crm/v3/objects/contacts', {method: 'GET', params: {properties: ['a', 'b'], archived: true}});
|
|
249
|
-
assertEqual(stub.calls[0].url, `${RAW}/crm/v3/objects/contacts?properties=a&properties=b&archived=true`, 'url');
|
|
250
|
-
assertEqual(stub.calls[0].init.headers.Authorization, 'Bearer tok', 'auth header');
|
|
251
|
-
assert(!('params' in stub.calls[0].init), 'params must not reach native fetch');
|
|
252
|
-
} finally {
|
|
253
|
-
stub.restore();
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// --- End to end over a local socket ---
|
|
258
|
-
|
|
259
|
-
await test('a local HTTP server receives the query string through the real global fetch', async () => {
|
|
260
|
-
const seen = [];
|
|
261
|
-
const server = http.createServer((req, res) => {
|
|
262
|
-
seen.push(req.url);
|
|
263
|
-
res.writeHead(200, {'content-type': 'application/json'});
|
|
264
|
-
res.end('{"ok":true}');
|
|
265
|
-
});
|
|
266
|
-
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
267
|
-
try {
|
|
268
|
-
const {port} = server.address();
|
|
269
|
-
const fetcher = new Fetcher({baseUrl: `http://127.0.0.1:${port}`, retry: 1});
|
|
270
|
-
const ret = await fetcher.fetch('/crm/v3/objects/contacts', {
|
|
271
|
-
method: 'GET',
|
|
272
|
-
params: {limit: 2, properties: ['a', 'b']},
|
|
273
|
-
});
|
|
274
|
-
assertEqual(ret, {ok: true}, 'response');
|
|
275
|
-
assertEqual(seen, ['/crm/v3/objects/contacts?limit=2&properties=a&properties=b'], 'request line');
|
|
276
|
-
} finally {
|
|
277
|
-
await new Promise((resolve) => server.close(resolve));
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
// --- Typing for hand-written connectors ---
|
|
282
|
-
|
|
283
|
-
await test('params is part of the typed fetch options', async () => {
|
|
284
|
-
const dts = fs.readFileSync(new URL('../build/internal/fetcher/fetcher.d.mts', import.meta.url), 'utf8');
|
|
285
|
-
assert(/params\?:/.test(dts), 'fetcher.d.mts declares params?');
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
console.log(`\n${colors.yellow}--- Fetcher query params test results ---${colors.reset}`);
|
|
289
|
-
console.log(`${colors.green}Passed: ${passed}${colors.reset}`);
|
|
290
|
-
console.log(`${colors.red}Failed: ${failed}${colors.reset}`);
|
|
291
|
-
|
|
292
|
-
if (failed > 0) {
|
|
293
|
-
process.exit(1);
|
|
294
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * greet somebody\n *\n * @namespace demo\n * @example usage\n```javascript\ngreet({name: 'Ann'})\n```\n **/ \ndeclare function greet({name; times = 2; loud = false; label = 'x'; neg = -1; nothing}: {\n/**\nwho to greet, e.g. Ann\n */\n name: any; \n/**\nhow often\n */\n times: any; \n/**\n\n */\n loud: any; \n/**\n\n */\n label: any; \n/**\n\n */\n neg: any; \n/**\n\n */\n nothing: any}): { ok: boolean; greeting: any; };\n \n/**\n * no params\n *\n * \n * \n **/ \ndeclare function ping(): { ok: boolean; };\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function list(): string[];\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function nothing(): void;\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"greet",
|
|
5
|
-
"ping",
|
|
6
|
-
"list",
|
|
7
|
-
"nothing"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
/**
|
|
5
|
-
* greet somebody
|
|
6
|
-
* @param name - who to greet, e.g. Ann
|
|
7
|
-
* @param times - how often
|
|
8
|
-
* @param opts - extra \@options
|
|
9
|
-
* @namespace demo
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```javascript
|
|
13
|
-
* greet({name: 'Ann'})
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
async greet({name, times = 2, loud = false, label = 'x', neg = -1, nothing = null}, other = 1) {
|
|
17
|
-
return {ok: true, greeting: name + times};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** no params */
|
|
21
|
-
async ping() {
|
|
22
|
-
return {ok: true};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async list(): Promise<string[]> {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async nothing(): Promise<void> {}
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
interface Opts {
|
|
4
|
-
id: string;
|
|
5
|
-
n?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default class Controller extends AbstractController {
|
|
9
|
-
async viaInterface({id, n}: Opts): Promise<{id: string; n: number | undefined}> {
|
|
10
|
-
return {id, n};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
/** first form */
|
|
5
|
-
async over({a}: {a: string}): Promise<string>;
|
|
6
|
-
/** second form */
|
|
7
|
-
async over({b}: {b: number}): Promise<number>;
|
|
8
|
-
async over(args: any): Promise<any> {
|
|
9
|
-
return args;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * Returns recorded calls scoped to the current task.\n *\n * \n * @example usage\n```javascript\nconst log = await connectors.testing.getCallLog({})\n// log.calls = [{method, args, timestamp}, ...] for THIS task only\n```\n **/ \ndeclare function getCallLog(): { calls: CallRecord[]; count: number; };\n \n/**\n * Resets the call log for the current task only.\n *\n * \n * @example usage\n```javascript\nawait connectors.testing.clearCallLog({})\n```\n **/ \ndeclare function clearCallLog(): { cleared: boolean; };\n \n/**\n * Updates the response map for the current task at runtime.\n *\n * \n * @example usage\n```javascript\nawait connectors.testing.setResponses({\n responses: { \"someConnector.create\": { id: \"456\" } }\n})\n```\n **/ \ndeclare function setResponses(): { updated: boolean; responseCount: number; };\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"getCallLog",
|
|
5
|
-
"clearCallLog",
|
|
6
|
-
"setResponses"
|
|
7
|
-
]
|
|
8
|
-
}
|