@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,204 +0,0 @@
|
|
|
1
|
-
import { AbstractController } from "./abstract.mjs";
|
|
2
|
-
|
|
3
|
-
interface CallRecord {
|
|
4
|
-
method: string;
|
|
5
|
-
args: any;
|
|
6
|
-
timestamp: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Per-task scoped mock connector for ALOMA test workflows.
|
|
11
|
-
*
|
|
12
|
-
* State (responseMap, callLog) is keyed by ctx.taskId so concurrent
|
|
13
|
-
* test tasks against the same Testing pod do not contaminate each
|
|
14
|
-
* other's stubbed responses or recorded calls.
|
|
15
|
-
*
|
|
16
|
-
* Requires @aloma.io/integration-sdk ^3.8.67, which forwards
|
|
17
|
-
* { taskId, namespace, sticky } as the second arg to controller
|
|
18
|
-
* method handlers and to the __default fallback.
|
|
19
|
-
*
|
|
20
|
-
* Backward compatibility: when ctx is missing (legacy invocation or
|
|
21
|
-
* non-task call from admin UI), state falls into the "__no_ctx__"
|
|
22
|
-
* bucket so the connector does not crash. Isolation is NOT guaranteed
|
|
23
|
-
* in that mode — it is degraded compatibility only.
|
|
24
|
-
*/
|
|
25
|
-
export default class Controller extends AbstractController {
|
|
26
|
-
// Per-task scoped state — Maps keyed by taskId (insertion order = LRU order)
|
|
27
|
-
private responseMapByTask: Map<string, Record<string, any>> = new Map();
|
|
28
|
-
private callLogByTask: Map<string, CallRecord[]> = new Map();
|
|
29
|
-
private recording: boolean = true;
|
|
30
|
-
private defaultResponses: Record<string, any> = {};
|
|
31
|
-
// Memory cap (LRU). Configurable via config.maxTasks; default 1000.
|
|
32
|
-
private maxTasks: number = 1000;
|
|
33
|
-
|
|
34
|
-
protected async start() {
|
|
35
|
-
this.loadConfig();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private loadConfig() {
|
|
39
|
-
const config = this.config;
|
|
40
|
-
|
|
41
|
-
// Parse default responses from connector config — these seed each
|
|
42
|
-
// task's bucket when first touched.
|
|
43
|
-
if (config.responses) {
|
|
44
|
-
try {
|
|
45
|
-
this.defaultResponses =
|
|
46
|
-
typeof config.responses === "string"
|
|
47
|
-
? JSON.parse(config.responses)
|
|
48
|
-
: config.responses;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
this.defaultResponses = {};
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
this.defaultResponses = {};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.recording = config.recordCalls !== "false";
|
|
57
|
-
|
|
58
|
-
// Allow config-driven override of LRU cap. Default 1000 if not set
|
|
59
|
-
// or not a positive number.
|
|
60
|
-
const configured = Number(config.maxTasks);
|
|
61
|
-
if (Number.isFinite(configured) && configured > 0) {
|
|
62
|
-
this.maxTasks = Math.floor(configured);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Resolve the bucket key for the current invocation. When ctx is
|
|
68
|
-
* absent or lacks taskId, falls back to a single shared bucket so
|
|
69
|
-
* legacy / hand-rolled callers do not crash. Isolation is not
|
|
70
|
-
* guaranteed in that mode.
|
|
71
|
-
*/
|
|
72
|
-
private bucketKey(ctx?: { taskId?: string }): string {
|
|
73
|
-
return ctx && ctx.taskId ? ctx.taskId : "__no_ctx__";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* LRU touch — ensures the bucket exists for the given key, evicting
|
|
78
|
-
* the least-recently-used entry if the cap would be exceeded. Map
|
|
79
|
-
* iteration order is insertion order; reinserting promotes a key to
|
|
80
|
-
* "most recently used" position.
|
|
81
|
-
*/
|
|
82
|
-
private touchTask(key: string) {
|
|
83
|
-
// If not present and at cap, evict the oldest (insertion order)
|
|
84
|
-
if (!this.responseMapByTask.has(key)) {
|
|
85
|
-
if (this.responseMapByTask.size >= this.maxTasks) {
|
|
86
|
-
const firstKey = this.responseMapByTask.keys().next().value as
|
|
87
|
-
| string
|
|
88
|
-
| undefined;
|
|
89
|
-
if (firstKey !== undefined) {
|
|
90
|
-
this.responseMapByTask.delete(firstKey);
|
|
91
|
-
this.callLogByTask.delete(firstKey);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
this.responseMapByTask.set(key, { ...this.defaultResponses });
|
|
95
|
-
this.callLogByTask.set(key, []);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Catch-all handler — registered as __default by the SDK via the
|
|
101
|
-
* fallback override below. Looks up the response in the task-scoped
|
|
102
|
-
* map, records the call in the task-scoped log, and returns the
|
|
103
|
-
* configured response or a default stub acknowledgement.
|
|
104
|
-
*/
|
|
105
|
-
private async handleStubCall(
|
|
106
|
-
arg: any,
|
|
107
|
-
ctx?: { taskId?: string },
|
|
108
|
-
): Promise<any> {
|
|
109
|
-
const key = this.bucketKey(ctx);
|
|
110
|
-
this.touchTask(key);
|
|
111
|
-
|
|
112
|
-
const method = Array.isArray(arg?.__method)
|
|
113
|
-
? arg.__method.join(".")
|
|
114
|
-
: arg?.__method || "unknown";
|
|
115
|
-
|
|
116
|
-
if (this.recording) {
|
|
117
|
-
const log = this.callLogByTask.get(key)!;
|
|
118
|
-
log.push({
|
|
119
|
-
method,
|
|
120
|
-
args: { ...arg, __method: undefined },
|
|
121
|
-
timestamp: new Date().toISOString(),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const responseMap = this.responseMapByTask.get(key)!;
|
|
126
|
-
if (responseMap[method] !== undefined) {
|
|
127
|
-
return responseMap[method];
|
|
128
|
-
}
|
|
129
|
-
if (responseMap["default"] !== undefined) {
|
|
130
|
-
return responseMap["default"];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return { stubbed: true, method };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* SDK override hook — invoked by AbstractController.__default with
|
|
138
|
-
* the per-invocation ctx (taskId, namespace, sticky) as second arg.
|
|
139
|
-
*/
|
|
140
|
-
protected fallback(arg: any, ctx?: { taskId?: string }): Promise<any> {
|
|
141
|
-
return this.handleStubCall(arg, ctx);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Returns recorded calls scoped to the current task.
|
|
146
|
-
* @example
|
|
147
|
-
* ```javascript
|
|
148
|
-
* const log = await connectors.testing.getCallLog({})
|
|
149
|
-
* // log.calls = [{method, args, timestamp}, ...] for THIS task only
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
async getCallLog(_args: any, ctx?: { taskId?: string }) {
|
|
153
|
-
const key = this.bucketKey(ctx);
|
|
154
|
-
const calls = this.callLogByTask.get(key) || [];
|
|
155
|
-
return { calls: [...calls], count: calls.length };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Resets the call log for the current task only.
|
|
160
|
-
* @example
|
|
161
|
-
* ```javascript
|
|
162
|
-
* await connectors.testing.clearCallLog({})
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
async clearCallLog(_args: any, ctx?: { taskId?: string }) {
|
|
166
|
-
const key = this.bucketKey(ctx);
|
|
167
|
-
if (this.callLogByTask.has(key)) {
|
|
168
|
-
this.callLogByTask.set(key, []);
|
|
169
|
-
}
|
|
170
|
-
return { cleared: true };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Updates the response map for the current task at runtime.
|
|
175
|
-
* @example
|
|
176
|
-
* ```javascript
|
|
177
|
-
* await connectors.testing.setResponses({
|
|
178
|
-
* responses: { "someConnector.create": { id: "456" } }
|
|
179
|
-
* })
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
async setResponses(args: any, ctx?: { taskId?: string }) {
|
|
183
|
-
const key = this.bucketKey(ctx);
|
|
184
|
-
this.touchTask(key);
|
|
185
|
-
|
|
186
|
-
if (args?.responses) {
|
|
187
|
-
try {
|
|
188
|
-
const newResponses =
|
|
189
|
-
typeof args.responses === "string"
|
|
190
|
-
? JSON.parse(args.responses)
|
|
191
|
-
: args.responses;
|
|
192
|
-
const existing = this.responseMapByTask.get(key)!;
|
|
193
|
-
this.responseMapByTask.set(key, { ...existing, ...newResponses });
|
|
194
|
-
} catch (e) {
|
|
195
|
-
// ignore parse errors — leave existing map untouched
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
updated: true,
|
|
201
|
-
responseCount: Object.keys(this.responseMapByTask.get(key)!).length,
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -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 * \n *\n * \n * \n **/ \ndeclare function typed({email; count; tags; mode; either; nested}: {\n/**\n\n */\n email: string; \n/**\n\n */\n count: any; \n/**\n\n */\n tags: string[]; \n/**\n\n */\n mode: any; \n/**\n\n */\n either: any; \n/**\n\n */\n nested: any}): { ok: boolean; tags: number[]; };\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function tuple(): [string, number];\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function maybe(): string | undefined;\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"typed",
|
|
5
|
-
"tuple",
|
|
6
|
-
"maybe"
|
|
7
|
-
]
|
|
8
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
async typed({email, count, tags, mode, either, nested}: {email: string; count?: number; tags: string[]; mode: 'a' | 'b'; either: string | number; nested: {x: number}}) {
|
|
5
|
-
return {ok: true, tags: [1, 2]};
|
|
6
|
-
}
|
|
7
|
-
async tuple(): Promise<[string, number]> {
|
|
8
|
-
return ['a', 1];
|
|
9
|
-
}
|
|
10
|
-
async maybe(): Promise<string | undefined> {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"text": "\n/**\n * \n *\n * \n * \n **/ \ndeclare function visible({a}: {\n/**\n\n */\n a: string}): string;\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function quoted-name({a}: {\n/**\n\n */\n a: string}): void;\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function arrow({a}: {\n/**\n\n */\n a: string}): string;\n \n/**\n * \n *\n * \n * \n **/ \ndeclare function inheritedPublic(): void;\n ",
|
|
3
|
-
"methods": [
|
|
4
|
-
"visible",
|
|
5
|
-
"quoted-name",
|
|
6
|
-
"arrow",
|
|
7
|
-
"inheritedPublic"
|
|
8
|
-
]
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {AbstractController} from './abstract.mjs';
|
|
2
|
-
|
|
3
|
-
export default class Controller extends AbstractController {
|
|
4
|
-
async visible({a}: {a: string}) {
|
|
5
|
-
return a;
|
|
6
|
-
}
|
|
7
|
-
private async hidden({a}: {a: string}) {}
|
|
8
|
-
protected async guarded({a}: {a: string}) {}
|
|
9
|
-
static async stat({a}: {a: string}) {}
|
|
10
|
-
async _underscore({a}: {a: string}) {}
|
|
11
|
-
async 'quoted-name'({a}: {a: string}) {}
|
|
12
|
-
async '_quoted_private'({a}: {a: string}) {}
|
|
13
|
-
arrow = async ({a}: {a: string}) => a;
|
|
14
|
-
notAMethod = 5;
|
|
15
|
-
get getter() {
|
|
16
|
-
return 1;
|
|
17
|
-
}
|
|
18
|
-
override async inheritedPublic() {}
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"compilerOptions":{"target":"es2022","module":"node16","moduleResolution":"node16","skipLibCheck":true,"strict":true,"noImplicitAny":false,"experimentalDecorators":true,"esModuleInterop":true},"include":["src/**/*"]}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// Handshake smoke test: the one file a connector repo adds (see "Testing a connector" in the SDK README).
|
|
2
|
-
//
|
|
3
|
-
// In a connector repo the RuntimeContext comes from the repo's own builder after `yarn build`:
|
|
4
|
-
// const context = await new Builder().config({...}).build();
|
|
5
|
-
// Here the controller is defined inline so this file also tests the harness path used by connector repos.
|
|
6
|
-
import {describe, it, afterEach} from 'mocha';
|
|
7
|
-
import {expect} from 'chai';
|
|
8
|
-
import {AbstractController} from '../build/index.mjs';
|
|
9
|
-
import RuntimeContext from '../build/builder/runtime-context.mjs';
|
|
10
|
-
import {ConnectorHarness, connectorFromRuntimeContext} from '../build/testing/index.mjs';
|
|
11
|
-
|
|
12
|
-
const VENDOR = 'https://api.crm.example.test';
|
|
13
|
-
|
|
14
|
-
class Controller extends AbstractController {
|
|
15
|
-
async getContact({id}) {
|
|
16
|
-
return this.getClient({baseUrl: VENDOR, retry: 1, customize: (r) => {
|
|
17
|
-
r.headers = {...r.headers, Authorization: `Bearer ${this.config.apiKey}`};
|
|
18
|
-
}}).fetch(`/contacts/${id}`, {method: 'GET'});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const context = () =>
|
|
23
|
-
new RuntimeContext(new Controller(), {
|
|
24
|
-
id: 'crm-connector',
|
|
25
|
-
version: '0.0.1',
|
|
26
|
-
methods: ['getContact'],
|
|
27
|
-
types: 'type Query { getContact(id: String): String }',
|
|
28
|
-
config: {fields: {apiKey: {name: 'API Key', type: 'line'}}},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('crm-connector handshake smoke test', function () {
|
|
32
|
-
this.timeout(15000);
|
|
33
|
-
let harness;
|
|
34
|
-
|
|
35
|
-
afterEach(async () => {
|
|
36
|
-
// stop() also fails the test when the connector made a request that was not mocked
|
|
37
|
-
if (harness) await harness.stop();
|
|
38
|
-
harness = undefined;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('registers, connects, starts and reports healthy', async () => {
|
|
42
|
-
harness = await ConnectorHarness.start({
|
|
43
|
-
connector: connectorFromRuntimeContext(context()),
|
|
44
|
-
config: {apiKey: 'fake-api-key-not-real'},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(harness.aloma.registration.id).to.equal('crm-connector');
|
|
48
|
-
expect(harness.aloma.registration.schema.configSchema.fields).to.have.property('apiKey');
|
|
49
|
-
|
|
50
|
-
const health = await harness.aloma.waitForPacket('connector.health.check');
|
|
51
|
-
expect(health.a).to.deep.equal({ok: true, error: null});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('answers a method call from a recorded vendor response', async () => {
|
|
55
|
-
harness = await ConnectorHarness.start({
|
|
56
|
-
connector: connectorFromRuntimeContext(context()),
|
|
57
|
-
config: {apiKey: 'fake-api-key-not-real'},
|
|
58
|
-
});
|
|
59
|
-
harness.vendor.get(`${VENDOR}/contacts/42`, {json: {id: 42, email: 'jane@example.test'}});
|
|
60
|
-
|
|
61
|
-
expect(await harness.callOk('getContact', {id: 42})).to.deep.equal({id: 42, email: 'jane@example.test'});
|
|
62
|
-
expect(harness.vendor.requests[0].headers.authorization).to.equal('Bearer fake-api-key-not-real');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('reports a missing configuration value as unhealthy', async () => {
|
|
66
|
-
harness = await ConnectorHarness.start({connector: connectorFromRuntimeContext(context()), config: {}});
|
|
67
|
-
|
|
68
|
-
const health = await harness.aloma.waitForPacket('connector.health.check');
|
|
69
|
-
expect(health.a.ok).to.equal(false);
|
|
70
|
-
expect(health.a.error).to.match(/API Key is required/);
|
|
71
|
-
});
|
|
72
|
-
});
|