@revenexx/integrations-node-devkit 0.7.0 → 0.8.1
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 +39 -10
- package/dist/{chunk-4QB5F7RT.js → chunk-YUUW37NC.js} +68 -9
- package/dist/chunk-YUUW37NC.js.map +1 -0
- package/dist/cli-args.d.ts +33 -0
- package/dist/cli.cjs +66 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/env.d.ts +70 -0
- package/dist/errors.d.ts +21 -0
- package/dist/http.d.ts +23 -0
- package/dist/index.cjs +68 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -458
- package/dist/index.js +3 -1
- package/dist/loader.d.ts +57 -0
- package/dist/persistence.d.ts +60 -0
- package/dist/ports.d.ts +24 -0
- package/dist/preview/child-env.d.ts +32 -0
- package/dist/preview/host.d.ts +147 -0
- package/dist/preview/pid.d.ts +14 -0
- package/dist/preview/registry.d.ts +40 -0
- package/dist/projections.d.ts +29 -0
- package/dist/resolve.d.ts +125 -0
- package/dist/server.d.ts +13 -0
- package/dist/state-rules.d.ts +32 -0
- package/dist/store.d.ts +184 -0
- package/dist/testing/author.d.ts +33 -0
- package/dist/testing/context.d.ts +96 -0
- package/dist/testing/credentials.d.ts +66 -0
- package/dist/testing/fetch.d.ts +57 -0
- package/dist/testing/index.d.ts +4 -253
- package/package.json +7 -7
- package/preview-host/package.json +3 -3
- package/preview-host/pages/nodes.vue +29 -0
- package/dist/chunk-4QB5F7RT.js.map +0 -1
- package/dist/index.d.cts +0 -466
- package/dist/testing/index.d.cts +0 -253
package/dist/testing/index.d.cts
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { INodeContext, INodeAuthorContext, ICredentialContext, ICredentialResolveResult, ICredential, ICredentialTestResult } from '@revenexx/integrations-node-sdk';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Drop-in replacement for the `createMockContext` helper that was, until this
|
|
6
|
-
* package existed, copy-pasted byte-for-byte into every node repo's
|
|
7
|
-
* `tests/helpers/context.ts`. Builds a full {@link INodeContext} with
|
|
8
|
-
* `vi.fn()`-backed `logger`, `secrets.get`, `credentials.get` and `state` so a
|
|
9
|
-
* node's `execute` can be unit-tested in isolation.
|
|
10
|
-
*
|
|
11
|
-
* The state mock is **stateful on purpose**: what the node writes, it reads
|
|
12
|
-
* back. A node's interesting behaviour is precisely the second run — the one
|
|
13
|
-
* that finds the mapping it created the first time — and a mock that forgets
|
|
14
|
-
* would only ever exercise the create branch. It is the one place an author can
|
|
15
|
-
* test writes at all: in the real product, author-time execution is read-only.
|
|
16
|
-
*
|
|
17
|
-
* It reads back *when the store would let it*, which is not the same for all
|
|
18
|
-
* four roles (SDK 1.0.0, `specs/workflow-state.md`): a mapping and a claim take
|
|
19
|
-
* effect immediately, a cursor and a digest are staged and adopted only once the
|
|
20
|
-
* run completes. So `cursor.get` after `cursor.set` still answers what the last
|
|
21
|
-
* completed run left — call {@link MockContext.completeRun} between two
|
|
22
|
-
* `execute` calls to play the second run, and leave it uncalled to play the run
|
|
23
|
-
* that failed and left the watermark where it was.
|
|
24
|
-
*/
|
|
25
|
-
type MockLogger = {
|
|
26
|
-
info: ReturnType<typeof vi.fn>;
|
|
27
|
-
warn: ReturnType<typeof vi.fn>;
|
|
28
|
-
error: ReturnType<typeof vi.fn>;
|
|
29
|
-
};
|
|
30
|
-
type MockSecrets = {
|
|
31
|
-
get: ReturnType<typeof vi.fn>;
|
|
32
|
-
};
|
|
33
|
-
type MockCredentials = {
|
|
34
|
-
get: ReturnType<typeof vi.fn>;
|
|
35
|
-
};
|
|
36
|
-
/** Every state operation is a `vi.fn()`, so calls can be asserted on. */
|
|
37
|
-
type MockState = {
|
|
38
|
-
mapping: {
|
|
39
|
-
get: ReturnType<typeof vi.fn>;
|
|
40
|
-
put: ReturnType<typeof vi.fn>;
|
|
41
|
-
};
|
|
42
|
-
cursor: {
|
|
43
|
-
get: ReturnType<typeof vi.fn>;
|
|
44
|
-
set: ReturnType<typeof vi.fn>;
|
|
45
|
-
};
|
|
46
|
-
claim: ReturnType<typeof vi.fn>;
|
|
47
|
-
digest: {
|
|
48
|
-
unchanged: ReturnType<typeof vi.fn>;
|
|
49
|
-
set: ReturnType<typeof vi.fn>;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* What the store already knows when the node starts — the "this ran before"
|
|
54
|
-
* half of any sync test.
|
|
55
|
-
*/
|
|
56
|
-
interface MockStateSeed {
|
|
57
|
-
/** namespace -> { leftKey: rightKey }; readable from either side. */
|
|
58
|
-
mappings?: Record<string, Record<string, string>>;
|
|
59
|
-
/** namespace -> partitionKey ('' for the unpartitioned one) -> watermark. */
|
|
60
|
-
cursors?: Record<string, Record<string, unknown>>;
|
|
61
|
-
/** namespace -> keys already claimed, so `claim` returns false for them. */
|
|
62
|
-
claims?: Record<string, string[]>;
|
|
63
|
-
/** namespace -> { entityKey: digest }. */
|
|
64
|
-
digests?: Record<string, Record<string, string>>;
|
|
65
|
-
}
|
|
66
|
-
type MockContext = INodeContext & {
|
|
67
|
-
logger: MockLogger;
|
|
68
|
-
secrets: MockSecrets;
|
|
69
|
-
credentials: MockCredentials;
|
|
70
|
-
state: MockState;
|
|
71
|
-
/**
|
|
72
|
-
* Adopts what this run staged — the cursors and digests it set — the way the
|
|
73
|
-
* engine does when a run completes. Not part of {@link INodeContext}: it is
|
|
74
|
-
* the harness standing in for the run's own ending, and a node can never call
|
|
75
|
-
* it. A test that never calls it has played a run that did not complete.
|
|
76
|
-
*/
|
|
77
|
-
completeRun: () => void;
|
|
78
|
-
};
|
|
79
|
-
interface CreateMockContextOptions {
|
|
80
|
-
signal?: AbortSignal;
|
|
81
|
-
/** Secret key -> value returned by `secrets.get`. Unknown keys fall back to a deterministic stub. */
|
|
82
|
-
secrets?: Record<string, string>;
|
|
83
|
-
/** When set, `secrets.get` rejects with this error instead of resolving. */
|
|
84
|
-
secretsError?: Error;
|
|
85
|
-
/** Credential instance id -> resolved access data returned by `credentials.get`. */
|
|
86
|
-
credentials?: Record<string, Record<string, unknown>>;
|
|
87
|
-
/** When set, `credentials.get` rejects with this error instead of resolving. */
|
|
88
|
-
credentialsError?: Error;
|
|
89
|
-
/** What the state store already holds when the node starts. */
|
|
90
|
-
state?: MockStateSeed;
|
|
91
|
-
/**
|
|
92
|
-
* When set, every state call rejects with this error — the shape of the
|
|
93
|
-
* engine refusing a namespace the workflow never declared.
|
|
94
|
-
*/
|
|
95
|
-
stateError?: Error;
|
|
96
|
-
}
|
|
97
|
-
declare function createMockContext(options?: CreateMockContextOptions): MockContext;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Builds an {@link INodeAuthorContext} for unit-testing a node's *author-time*
|
|
101
|
-
* resolvers (`loadOptions`, `resolveConfigSchema`, `resolveOutputs`). Until this
|
|
102
|
-
* package existed, this factory was reinvented inline in each repo's resolver
|
|
103
|
-
* tests. Mirrors {@link createMockContext}: `secrets.get` / `credentials.get`
|
|
104
|
-
* are `vi.fn()`-backed and seedable.
|
|
105
|
-
*/
|
|
106
|
-
type MockAuthorLogger = {
|
|
107
|
-
info: ReturnType<typeof vi.fn>;
|
|
108
|
-
warn: ReturnType<typeof vi.fn>;
|
|
109
|
-
error: ReturnType<typeof vi.fn>;
|
|
110
|
-
};
|
|
111
|
-
type MockAuthorContext = INodeAuthorContext & {
|
|
112
|
-
logger: MockAuthorLogger;
|
|
113
|
-
secrets: {
|
|
114
|
-
get: ReturnType<typeof vi.fn>;
|
|
115
|
-
};
|
|
116
|
-
credentials: {
|
|
117
|
-
get: ReturnType<typeof vi.fn>;
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
interface CreateAuthorContextOptions {
|
|
121
|
-
signal?: AbortSignal;
|
|
122
|
-
/** Preferred locale for resolved labels. */
|
|
123
|
-
locale?: string;
|
|
124
|
-
secrets?: Record<string, string>;
|
|
125
|
-
secretsError?: Error;
|
|
126
|
-
credentials?: Record<string, Record<string, unknown>>;
|
|
127
|
-
credentialsError?: Error;
|
|
128
|
-
}
|
|
129
|
-
declare function createAuthorContext(config?: Record<string, unknown>, options?: CreateAuthorContextOptions): MockAuthorContext;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Utilities for stubbing the global `fetch` so a credential's `resolve` /
|
|
133
|
-
* `test` (which reach an OAuth token endpoint via the SDK's `postForm`) or a
|
|
134
|
-
* node's `execute` (which uses `safeFetch` → global `fetch`) can be
|
|
135
|
-
* unit-tested without touching the network. Builds real `Response` objects so
|
|
136
|
-
* `res.ok` / `res.status` / `res.text()` / `res.json()` all behave exactly as
|
|
137
|
-
* in production.
|
|
138
|
-
*/
|
|
139
|
-
interface StubResponseInit {
|
|
140
|
-
status?: number;
|
|
141
|
-
headers?: Record<string, string>;
|
|
142
|
-
/** JSON body — serialized and served as `application/json` unless `body` is set. */
|
|
143
|
-
json?: unknown;
|
|
144
|
-
/** Raw string body. Takes precedence over `json`. */
|
|
145
|
-
body?: string;
|
|
146
|
-
}
|
|
147
|
-
interface StubbedRequest {
|
|
148
|
-
url: string;
|
|
149
|
-
method: string;
|
|
150
|
-
init?: RequestInit;
|
|
151
|
-
}
|
|
152
|
-
type FetchHandler = (request: StubbedRequest) => StubResponseInit | Response | Promise<StubResponseInit | Response>;
|
|
153
|
-
/** Builds a real `Response` from a {@link StubResponseInit}. */
|
|
154
|
-
declare function buildResponse(init: StubResponseInit): Response;
|
|
155
|
-
interface StubFetchResult {
|
|
156
|
-
/** The `vi.fn()` installed as `globalThis.fetch` — assert calls on it. */
|
|
157
|
-
fetchMock: ReturnType<typeof vi.fn>;
|
|
158
|
-
/** Restores the previous `globalThis.fetch`. */
|
|
159
|
-
restore(): void;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Replaces `globalThis.fetch` with a `vi.fn()` driven by `handler`. Pass a
|
|
163
|
-
* static {@link StubResponseInit} to answer every request identically, or a
|
|
164
|
-
* {@link FetchHandler} to branch on url/method. Call `restore()` when done
|
|
165
|
-
* (e.g. in `afterEach`).
|
|
166
|
-
*/
|
|
167
|
-
declare function stubFetch(handler: FetchHandler | StubResponseInit): StubFetchResult;
|
|
168
|
-
interface FakeTokenEndpointOptions {
|
|
169
|
-
/** Only answer requests to this exact URL; other requests 404. Omit to answer any URL. */
|
|
170
|
-
tokenUrl?: string;
|
|
171
|
-
accessToken?: string;
|
|
172
|
-
tokenType?: string;
|
|
173
|
-
/** Seconds until expiry (OAuth `expires_in`). Set `null` to omit the field. */
|
|
174
|
-
expiresIn?: number | null;
|
|
175
|
-
/** Included as `refresh_token` when set (e.g. to assert rotation). */
|
|
176
|
-
refreshToken?: string;
|
|
177
|
-
/** Extra fields merged into the token response body. */
|
|
178
|
-
extra?: Record<string, unknown>;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* A {@link FetchHandler} that emulates an OAuth token endpoint, returning
|
|
182
|
-
* `{ access_token, token_type, expires_in, refresh_token? }`. Compose with
|
|
183
|
-
* {@link stubFetch} to unit-test `oauth2-*` credentials' `resolve` / OAuth
|
|
184
|
-
* `exchangeCode`.
|
|
185
|
-
*/
|
|
186
|
-
declare function fakeTokenEndpoint(options?: FakeTokenEndpointOptions): FetchHandler;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Harness for unit-testing a credential type's `test` / `resolve` / 3-legged
|
|
190
|
-
* OAuth without the credentials broker or a real provider. Combine with
|
|
191
|
-
* {@link stubFetch} / {@link fakeTokenEndpoint} to drive the token endpoint,
|
|
192
|
-
* and inspect the returned `persistDurableCreds` spy to assert refresh-token
|
|
193
|
-
* rotation.
|
|
194
|
-
*/
|
|
195
|
-
type MockCredentialLogger = {
|
|
196
|
-
info: ReturnType<typeof vi.fn>;
|
|
197
|
-
warn: ReturnType<typeof vi.fn>;
|
|
198
|
-
error: ReturnType<typeof vi.fn>;
|
|
199
|
-
};
|
|
200
|
-
type MockCredentialContext = ICredentialContext & {
|
|
201
|
-
logger: MockCredentialLogger;
|
|
202
|
-
/** Spy wired to `ctx.persistDurableCreds`; assert `.toHaveBeenCalledWith(...)`. */
|
|
203
|
-
persistDurableCreds: ReturnType<typeof vi.fn>;
|
|
204
|
-
};
|
|
205
|
-
interface CreateCredentialContextOptions {
|
|
206
|
-
signal?: AbortSignal;
|
|
207
|
-
}
|
|
208
|
-
declare function createCredentialContext(options?: CreateCredentialContextOptions): MockCredentialContext;
|
|
209
|
-
interface RunCredentialTestOptions {
|
|
210
|
-
config: Record<string, unknown>;
|
|
211
|
-
signal?: AbortSignal;
|
|
212
|
-
}
|
|
213
|
-
/** Runs a credential's `test(ctx, config)` and returns its result. */
|
|
214
|
-
declare function runCredentialTest(credential: ICredential, options: RunCredentialTestOptions): Promise<ICredentialTestResult>;
|
|
215
|
-
interface RunCredentialResolveOptions {
|
|
216
|
-
config: Record<string, unknown>;
|
|
217
|
-
/** System-managed long-lived secrets (e.g. an OAuth `refresh_token`). */
|
|
218
|
-
durableCreds?: Record<string, unknown> | null;
|
|
219
|
-
signal?: AbortSignal;
|
|
220
|
-
}
|
|
221
|
-
interface RunCredentialResolveResult {
|
|
222
|
-
result: ICredentialResolveResult;
|
|
223
|
-
/** Spy wired to `ctx.persistDurableCreds` — assert rotation happened. */
|
|
224
|
-
persistDurableCreds: ReturnType<typeof vi.fn>;
|
|
225
|
-
/** The context used, for further assertions (logger calls, etc.). */
|
|
226
|
-
ctx: MockCredentialContext;
|
|
227
|
-
}
|
|
228
|
-
/** Runs a credential's `resolve(ctx, config, durableCreds)` and captures rotation. */
|
|
229
|
-
declare function runCredentialResolve(credential: ICredential, options: RunCredentialResolveOptions): Promise<RunCredentialResolveResult>;
|
|
230
|
-
interface RunOAuthAuthorizeUrlOptions {
|
|
231
|
-
config: Record<string, unknown>;
|
|
232
|
-
redirectUri: string;
|
|
233
|
-
state: string;
|
|
234
|
-
signal?: AbortSignal;
|
|
235
|
-
}
|
|
236
|
-
/** Runs `buildAuthorizeUrl` on a 3-legged OAuth credential; throws if unsupported. */
|
|
237
|
-
declare function runOAuthAuthorizeUrl(credential: ICredential, options: RunOAuthAuthorizeUrlOptions): Promise<{
|
|
238
|
-
authorizeUrl: string;
|
|
239
|
-
codeVerifier?: string;
|
|
240
|
-
}>;
|
|
241
|
-
interface RunOAuthExchangeCodeOptions {
|
|
242
|
-
config: Record<string, unknown>;
|
|
243
|
-
code: string;
|
|
244
|
-
redirectUri: string;
|
|
245
|
-
codeVerifier?: string;
|
|
246
|
-
signal?: AbortSignal;
|
|
247
|
-
}
|
|
248
|
-
/** Runs `exchangeCode` on a 3-legged OAuth credential; throws if unsupported. */
|
|
249
|
-
declare function runOAuthExchangeCode(credential: ICredential, options: RunOAuthExchangeCodeOptions): Promise<{
|
|
250
|
-
durableCreds: Record<string, unknown>;
|
|
251
|
-
}>;
|
|
252
|
-
|
|
253
|
-
export { type CreateAuthorContextOptions, type CreateCredentialContextOptions, type CreateMockContextOptions, type FakeTokenEndpointOptions, type FetchHandler, type MockAuthorContext, type MockAuthorLogger, type MockContext, type MockCredentialContext, type MockCredentialLogger, type MockCredentials, type MockLogger, type MockSecrets, type MockState, type MockStateSeed, type RunCredentialResolveOptions, type RunCredentialResolveResult, type RunCredentialTestOptions, type RunOAuthAuthorizeUrlOptions, type RunOAuthExchangeCodeOptions, type StubFetchResult, type StubResponseInit, type StubbedRequest, buildResponse, createAuthorContext, createCredentialContext, createMockContext, fakeTokenEndpoint, runCredentialResolve, runCredentialTest, runOAuthAuthorizeUrl, runOAuthExchangeCode, stubFetch };
|