@revenexx/integrations-node-devkit 0.2.0 → 0.2.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/dist/chunk-UBYGZFB7.js +1263 -0
- package/dist/chunk-UBYGZFB7.js.map +1 -0
- package/dist/cli.cjs +2038 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +798 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1331 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +360 -0
- package/dist/index.d.ts +360 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/testing/index.cjs +215 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +194 -0
- package/dist/testing/index.d.ts +194 -0
- package/dist/testing/index.js +179 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +2 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { INode, ICredential, ITemplateDescription, NodeManifest, IConfigOption, IConfigField, IOutputPort, ICredentialDescription, ICredentialResolveResult, ICredentialTestResult } from '@revenexx/integrations-node-sdk';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `.env` loading for the CLI.
|
|
6
|
+
*
|
|
7
|
+
* Seeds reference secrets as `${VAR}` and {@link interpolateEnv} resolves those
|
|
8
|
+
* from `process.env`, so without this the documented workflow — commit the
|
|
9
|
+
* reference, keep the value in `.env` — only worked if the developer exported
|
|
10
|
+
* the variables by hand.
|
|
11
|
+
*
|
|
12
|
+
* Loading happens before option parsing, because the CLI reads `PORT` for its
|
|
13
|
+
* default port; a `.env` that sets `PORT` would otherwise be read too late.
|
|
14
|
+
*
|
|
15
|
+
* `process.loadEnvFile` deliberately does not overwrite variables that are
|
|
16
|
+
* already set, so a shell-provided value always beats the file:
|
|
17
|
+
*
|
|
18
|
+
* REVENEXX_DEV_API_KEY=… npm run preview
|
|
19
|
+
*
|
|
20
|
+
* The flag is `--env`, *not* `--env-file`: Node reserves `--env-file` and
|
|
21
|
+
* `--env-file-if-exists` and acts on them wherever they appear, including after
|
|
22
|
+
* the script path. `node cli.js --env-file missing` therefore dies inside Node
|
|
23
|
+
* with exit code 9 before this module is ever reached, so the devkit cannot own
|
|
24
|
+
* that name. {@link nodeOwnedEnvFlag} spots the mistake and explains it.
|
|
25
|
+
*/
|
|
26
|
+
/** Minimum Node version shipping `process.loadEnvFile`. */
|
|
27
|
+
declare const ENV_FILE_MIN_NODE = "20.12";
|
|
28
|
+
interface EnvFileChoice {
|
|
29
|
+
/** Absolute path to load, or `null` when `--no-env` disabled loading. */
|
|
30
|
+
path: string | null;
|
|
31
|
+
/** True when the file was named with `--env` rather than defaulted to. */
|
|
32
|
+
explicit: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the Node-owned env flag present in `argv`, if any. Node has already
|
|
36
|
+
* acted on it by the time the CLI runs — this exists only so the CLI can say so
|
|
37
|
+
* instead of leaving the user wondering why `--env-file` behaved oddly.
|
|
38
|
+
*/
|
|
39
|
+
declare function nodeOwnedEnvFlag(argv: string[]): string | null;
|
|
40
|
+
/** Decides which env file to load. Pure — touches neither disk nor `process.env`. */
|
|
41
|
+
declare function resolveEnvFile(argv: string[], cwd?: string): EnvFileChoice;
|
|
42
|
+
interface LoadEnvFileOptions {
|
|
43
|
+
cwd?: string;
|
|
44
|
+
warn?: (message: string) => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Loads the env file chosen by {@link resolveEnvFile} into `process.env` and
|
|
48
|
+
* returns its path, or `null` when nothing was loaded.
|
|
49
|
+
*
|
|
50
|
+
* A missing *default* `.env` is fine — most packages do not have one. A file
|
|
51
|
+
* asked for by name and missing is an error: ignoring it would hide a typo and
|
|
52
|
+
* resurface much later as a puzzling `Seed references ${X}` failure.
|
|
53
|
+
*/
|
|
54
|
+
declare function loadEnvFile(argv: string[], options?: LoadEnvFileOptions): string | null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* An error that maps to an HTTP status + JSON body in the mock API, mirroring
|
|
58
|
+
* Laravel's `{message}` / `{message, errors}` envelopes.
|
|
59
|
+
*/
|
|
60
|
+
declare class DevApiError extends Error {
|
|
61
|
+
readonly status: number;
|
|
62
|
+
readonly errors?: Record<string, string[]> | undefined;
|
|
63
|
+
constructor(status: number, message: string, errors?: Record<string, string[]> | undefined);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A node package loaded into the dev process: its live `NODES` / `CREDENTIALS`
|
|
68
|
+
* / `TEMPLATES` instances (so author-time resolvers, `test`, and `resolve` can
|
|
69
|
+
* be invoked in-process — no bundle, no sandbox) plus the derived manifest the
|
|
70
|
+
* mock API serves.
|
|
71
|
+
*/
|
|
72
|
+
interface LoadedPackage {
|
|
73
|
+
nodes: INode[];
|
|
74
|
+
credentials: ICredential[];
|
|
75
|
+
templates: ITemplateDescription[];
|
|
76
|
+
manifest: NodeManifest;
|
|
77
|
+
}
|
|
78
|
+
interface PackageExports {
|
|
79
|
+
NODES?: unknown;
|
|
80
|
+
CREDENTIALS?: unknown;
|
|
81
|
+
TEMPLATES?: unknown;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validates a package's module exports and builds a {@link LoadedPackage}.
|
|
85
|
+
* Mirrors the checks in the SDK's `rvnxx-nodes manifest` CLI so the dev loop
|
|
86
|
+
* and the build produce identical manifests.
|
|
87
|
+
*/
|
|
88
|
+
declare function resolveExports(mod: PackageExports): LoadedPackage;
|
|
89
|
+
/**
|
|
90
|
+
* Registers the `tsx` ESM loader once per process so `import()` can load
|
|
91
|
+
* TypeScript sources directly. Idempotent.
|
|
92
|
+
*/
|
|
93
|
+
declare function ensureTsxRegistered(): Promise<void>;
|
|
94
|
+
/** Imports a module by path, registering tsx first for TypeScript sources. */
|
|
95
|
+
declare function importFresh<T = unknown>(entryPath: string): Promise<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Imports a package entry and resolves its exports. Supports TypeScript
|
|
98
|
+
* sources directly (via `tsx`) so the preview runs against the developer's
|
|
99
|
+
* live `src/`, not a built artifact. A cache-busting query is appended so
|
|
100
|
+
* repeated calls (hot-reload) re-evaluate the module.
|
|
101
|
+
*/
|
|
102
|
+
declare function loadPackageFromEntry(entryPath: string): Promise<LoadedPackage>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* In-memory data store backing the mock Integrations API. Holds the tenant-
|
|
106
|
+
* scoped resources a developer creates in the preview (credentials, secrets,
|
|
107
|
+
* workflows, triggers). Serializable so a session can be persisted to and
|
|
108
|
+
* rehydrated from `.revenexx-dev/state.json`.
|
|
109
|
+
*/
|
|
110
|
+
declare const DEV_TENANT_ID = "dev-tenant";
|
|
111
|
+
interface CredentialRecord {
|
|
112
|
+
id: string;
|
|
113
|
+
tenantId: string;
|
|
114
|
+
credentialTypeSlug: string;
|
|
115
|
+
name: string;
|
|
116
|
+
status: string;
|
|
117
|
+
/** Full user-entered config, including secret fields (never sent to the UI verbatim). */
|
|
118
|
+
config: Record<string, unknown>;
|
|
119
|
+
/** System-managed long-lived secrets (e.g. an OAuth refresh token). */
|
|
120
|
+
durableCreds: Record<string, unknown> | null;
|
|
121
|
+
createdAt: string;
|
|
122
|
+
updatedAt: string;
|
|
123
|
+
}
|
|
124
|
+
interface SecretRecord {
|
|
125
|
+
key: string;
|
|
126
|
+
value: string;
|
|
127
|
+
createdAt: string;
|
|
128
|
+
updatedAt: string;
|
|
129
|
+
}
|
|
130
|
+
interface WorkflowRecord {
|
|
131
|
+
id: number;
|
|
132
|
+
name: string;
|
|
133
|
+
definition: Record<string, unknown>;
|
|
134
|
+
buildStatus: string;
|
|
135
|
+
createdAt: string;
|
|
136
|
+
updatedAt: string;
|
|
137
|
+
}
|
|
138
|
+
interface TriggerRecord {
|
|
139
|
+
id: string;
|
|
140
|
+
workflowId: number;
|
|
141
|
+
type: string;
|
|
142
|
+
name: string | null;
|
|
143
|
+
config: Record<string, unknown>;
|
|
144
|
+
active: boolean;
|
|
145
|
+
createdAt: string;
|
|
146
|
+
updatedAt: string;
|
|
147
|
+
}
|
|
148
|
+
interface DevStoreSnapshot {
|
|
149
|
+
schemaVersion: number;
|
|
150
|
+
credentials: CredentialRecord[];
|
|
151
|
+
secrets: SecretRecord[];
|
|
152
|
+
workflows: WorkflowRecord[];
|
|
153
|
+
triggers: TriggerRecord[];
|
|
154
|
+
nextWorkflowId: number;
|
|
155
|
+
}
|
|
156
|
+
declare const STORE_SCHEMA_VERSION = 1;
|
|
157
|
+
declare class DevStore {
|
|
158
|
+
private onChange?;
|
|
159
|
+
private credentials;
|
|
160
|
+
private secrets;
|
|
161
|
+
private workflows;
|
|
162
|
+
private triggers;
|
|
163
|
+
private nextWorkflowId;
|
|
164
|
+
/**
|
|
165
|
+
* @param onChange fired after any mutation so a caller (the CLI) can persist
|
|
166
|
+
* the session to `.revenexx-dev/state.json`.
|
|
167
|
+
*/
|
|
168
|
+
constructor(onChange?: (() => void) | undefined);
|
|
169
|
+
/** (Re)wire the post-mutation callback — e.g. attach it only after seeding. */
|
|
170
|
+
setOnMutation(onChange: (() => void) | undefined): void;
|
|
171
|
+
private touch;
|
|
172
|
+
listCredentials(typeSlug?: string): CredentialRecord[];
|
|
173
|
+
getCredential(id: string): CredentialRecord | undefined;
|
|
174
|
+
createCredential(input: {
|
|
175
|
+
credentialTypeSlug: string;
|
|
176
|
+
name: string;
|
|
177
|
+
config: Record<string, unknown>;
|
|
178
|
+
status?: string;
|
|
179
|
+
/** Stable id — pass to keep a seeded credential's id fixed across restarts. */
|
|
180
|
+
id?: string;
|
|
181
|
+
durableCreds?: Record<string, unknown> | null;
|
|
182
|
+
}): CredentialRecord;
|
|
183
|
+
updateCredential(id: string, patch: Partial<Pick<CredentialRecord, 'name' | 'config' | 'status' | 'durableCreds'>>): CredentialRecord | undefined;
|
|
184
|
+
deleteCredential(id: string): boolean;
|
|
185
|
+
listSecrets(): SecretRecord[];
|
|
186
|
+
getSecret(key: string): SecretRecord | undefined;
|
|
187
|
+
setSecret(key: string, value: string): SecretRecord;
|
|
188
|
+
deleteSecret(key: string): boolean;
|
|
189
|
+
listWorkflows(): WorkflowRecord[];
|
|
190
|
+
getWorkflow(id: number): WorkflowRecord | undefined;
|
|
191
|
+
createWorkflow(input: {
|
|
192
|
+
name: string;
|
|
193
|
+
definition: Record<string, unknown>;
|
|
194
|
+
}): WorkflowRecord;
|
|
195
|
+
updateWorkflow(id: number, patch: Partial<Pick<WorkflowRecord, 'name' | 'definition' | 'buildStatus'>>): WorkflowRecord | undefined;
|
|
196
|
+
deleteWorkflow(id: number): boolean;
|
|
197
|
+
listTriggers(workflowId: number): TriggerRecord[];
|
|
198
|
+
getTrigger(id: string): TriggerRecord | undefined;
|
|
199
|
+
createTrigger(input: {
|
|
200
|
+
workflowId: number;
|
|
201
|
+
type: string;
|
|
202
|
+
name?: string | null;
|
|
203
|
+
config?: Record<string, unknown>;
|
|
204
|
+
active?: boolean;
|
|
205
|
+
id?: string;
|
|
206
|
+
}): TriggerRecord;
|
|
207
|
+
replaceTrigger(id: string, input: {
|
|
208
|
+
type: string;
|
|
209
|
+
name?: string | null;
|
|
210
|
+
config?: Record<string, unknown>;
|
|
211
|
+
active?: boolean;
|
|
212
|
+
}): TriggerRecord | undefined;
|
|
213
|
+
deleteTrigger(id: string): boolean;
|
|
214
|
+
toSnapshot(): DevStoreSnapshot;
|
|
215
|
+
loadSnapshot(snapshot: DevStoreSnapshot): void;
|
|
216
|
+
/**
|
|
217
|
+
* Overlays a snapshot on top of the current contents (upsert by id/key), used
|
|
218
|
+
* to layer the persisted `.revenexx-dev/state.json` session over the freshly
|
|
219
|
+
* applied committed seeds. State entries win over seed entries with the same
|
|
220
|
+
* id/key; seed-only entries are preserved.
|
|
221
|
+
*/
|
|
222
|
+
mergeSnapshot(snapshot: DevStoreSnapshot): void;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Layered persistence for the preview session:
|
|
227
|
+
* 1. committed seeds (this module's {@link applySeeds}) — the durable base,
|
|
228
|
+
* with `${ENV_VAR}` references interpolated from the environment;
|
|
229
|
+
* 2. `.revenexx-dev/state.json` overlay ({@link loadState}/{@link saveState}) —
|
|
230
|
+
* interactive session state, versioned and disposable.
|
|
231
|
+
*/
|
|
232
|
+
interface CredentialSeed {
|
|
233
|
+
credentialTypeSlug: string;
|
|
234
|
+
name: string;
|
|
235
|
+
config: Record<string, unknown>;
|
|
236
|
+
/** Stable id so workflows can reference the credential across restarts. */
|
|
237
|
+
id?: string;
|
|
238
|
+
status?: string;
|
|
239
|
+
durableCreds?: Record<string, unknown> | null;
|
|
240
|
+
}
|
|
241
|
+
interface SecretSeed {
|
|
242
|
+
key: string;
|
|
243
|
+
value: string;
|
|
244
|
+
}
|
|
245
|
+
interface WorkflowSeed {
|
|
246
|
+
name: string;
|
|
247
|
+
definition: Record<string, unknown>;
|
|
248
|
+
}
|
|
249
|
+
interface DevSeeds {
|
|
250
|
+
credentials?: CredentialSeed[];
|
|
251
|
+
secrets?: SecretSeed[];
|
|
252
|
+
workflows?: WorkflowSeed[];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Recursively replaces `${ENV_VAR}` references in string values from `env`.
|
|
256
|
+
* Throws a clear error when a referenced variable is unset so a developer
|
|
257
|
+
* knows to add it to their `.env` — keeping secrets out of committed seeds.
|
|
258
|
+
*/
|
|
259
|
+
declare function interpolateEnv<T>(value: T, env?: NodeJS.ProcessEnv): T;
|
|
260
|
+
/** Applies committed seeds to the store (env-interpolated). */
|
|
261
|
+
declare function applySeeds(store: DevStore, seeds: DevSeeds, env?: NodeJS.ProcessEnv): void;
|
|
262
|
+
/**
|
|
263
|
+
* Reads a persisted session snapshot. Returns `null` (and warns) when the file
|
|
264
|
+
* is absent or its `schemaVersion` no longer matches — the overlay is
|
|
265
|
+
* disposable, so a mismatch is discarded rather than migrated.
|
|
266
|
+
*/
|
|
267
|
+
declare function loadState(file: string, log?: (msg: string) => void): DevStoreSnapshot | null;
|
|
268
|
+
declare function saveState(file: string, snapshot: DevStoreSnapshot): void;
|
|
269
|
+
/**
|
|
270
|
+
* Loads committed seeds from a directory (default `dev/seeds`). Resolves the
|
|
271
|
+
* first present entry file and reads its `default` or named `seeds` export.
|
|
272
|
+
* Returns empty seeds when no seed directory/entry exists.
|
|
273
|
+
*/
|
|
274
|
+
declare function loadSeedsFromDir(dir: string): Promise<DevSeeds>;
|
|
275
|
+
|
|
276
|
+
declare function nodeVersions(loaded: LoadedPackage, slug: string): string[];
|
|
277
|
+
declare function findNode(loaded: LoadedPackage, slug: string, version?: string): INode;
|
|
278
|
+
declare function findCredential(loaded: LoadedPackage, slug: string): ICredential;
|
|
279
|
+
declare function findCredentialType(loaded: LoadedPackage, slug: string): ICredentialDescription;
|
|
280
|
+
/** Resolves a credential instance's access data by running its real `resolve`. */
|
|
281
|
+
declare function resolveCredentialInstance(loaded: LoadedPackage, store: DevStore, credentialId: string): Promise<ICredentialResolveResult>;
|
|
282
|
+
interface ResolveNodeConfigInput {
|
|
283
|
+
slug: string;
|
|
284
|
+
version?: string;
|
|
285
|
+
/** `"*"` (all), `"outputs"`, or a specific config field key. */
|
|
286
|
+
target: string;
|
|
287
|
+
config: Record<string, unknown>;
|
|
288
|
+
locale?: string;
|
|
289
|
+
}
|
|
290
|
+
interface ResolveNodeConfigResult {
|
|
291
|
+
options?: IConfigOption[];
|
|
292
|
+
fields?: IConfigField[];
|
|
293
|
+
outputs?: IOutputPort[];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Runs a node's author-time resolvers for the requested `target`, mirroring
|
|
297
|
+
* the server's `config:resolve` semantics.
|
|
298
|
+
*/
|
|
299
|
+
declare function resolveNodeConfig(loaded: LoadedPackage, store: DevStore, input: ResolveNodeConfigInput): Promise<ResolveNodeConfigResult>;
|
|
300
|
+
interface ValidateNodeConfigInput {
|
|
301
|
+
slug: string;
|
|
302
|
+
version?: string;
|
|
303
|
+
config: Record<string, unknown>;
|
|
304
|
+
locale?: string;
|
|
305
|
+
}
|
|
306
|
+
interface ValidateNodeConfigResult {
|
|
307
|
+
valid: boolean;
|
|
308
|
+
/** Config field key → human-readable messages. Empty object when valid. */
|
|
309
|
+
errors: Record<string, string[]>;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Validates a submitted node `config` against the field rules in its manifest
|
|
313
|
+
* (`required`, `IConfigValidation`, types, static options). For `dynamic-schema`
|
|
314
|
+
* fields the resolved child schema is fetched and its rules applied to the
|
|
315
|
+
* flattened keys. Deep cross-field validation is intentionally out of scope
|
|
316
|
+
* (the production service does that on save); this mirrors the mock's
|
|
317
|
+
* "light, schema-based" fidelity. Unknown extra keys are ignored.
|
|
318
|
+
*/
|
|
319
|
+
declare function validateNodeConfig(loaded: LoadedPackage, store: DevStore, input: ValidateNodeConfigInput): Promise<ValidateNodeConfigResult>;
|
|
320
|
+
/** Runs a credential type's `test` against inline (unsaved) config. */
|
|
321
|
+
declare function testCredentialConfig(loaded: LoadedPackage, store: DevStore, typeSlug: string, config: Record<string, unknown>): Promise<ICredentialTestResult>;
|
|
322
|
+
/** Runs `test` against a saved credential instance's stored config. */
|
|
323
|
+
declare function testCredentialInstance(loaded: LoadedPackage, store: DevStore, credentialId: string): Promise<ICredentialTestResult>;
|
|
324
|
+
declare function buildOAuthAuthorizeUrl(loaded: LoadedPackage, store: DevStore, credentialId: string, params: {
|
|
325
|
+
redirectUri: string;
|
|
326
|
+
state: string;
|
|
327
|
+
}): Promise<{
|
|
328
|
+
authorizeUrl: string;
|
|
329
|
+
codeVerifier?: string;
|
|
330
|
+
}>;
|
|
331
|
+
declare function exchangeOAuthCode(loaded: LoadedPackage, store: DevStore, credentialId: string, params: {
|
|
332
|
+
code: string;
|
|
333
|
+
redirectUri: string;
|
|
334
|
+
codeVerifier?: string;
|
|
335
|
+
}): Promise<{
|
|
336
|
+
durableCreds: Record<string, unknown>;
|
|
337
|
+
}>;
|
|
338
|
+
|
|
339
|
+
interface DevServerDeps {
|
|
340
|
+
/** Returns the currently-loaded package; a function so hot-reload can swap it. */
|
|
341
|
+
getPackage(): LoadedPackage;
|
|
342
|
+
store: DevStore;
|
|
343
|
+
/** JSON schemas served at `/schemas/{domain}[/{version}]`, keyed by `domain` and `domain/version`. */
|
|
344
|
+
schemas?: Record<string, unknown>;
|
|
345
|
+
}
|
|
346
|
+
/** Builds the `(req, res)` request listener implementing the mock `/api/v1` surface. */
|
|
347
|
+
declare function createRequestListener(deps: DevServerDeps): http.RequestListener;
|
|
348
|
+
declare function createDevServer(deps: DevServerDeps): http.Server;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* `@revenexx/integrations-node-devkit` — local development kit for Revenexx
|
|
352
|
+
* integration node packages. Dev/CI only; never bundled into a node package.
|
|
353
|
+
*
|
|
354
|
+
* Two surfaces:
|
|
355
|
+
* - `@revenexx/integrations-node-devkit` → the mock-API preview server (this entry)
|
|
356
|
+
* - `@revenexx/integrations-node-devkit/testing` → the unit-testing harness
|
|
357
|
+
*/
|
|
358
|
+
declare const DEVKIT_VERSION: string;
|
|
359
|
+
|
|
360
|
+
export { type CredentialRecord, type CredentialSeed, DEVKIT_VERSION, DEV_TENANT_ID, DevApiError, type DevSeeds, type DevServerDeps, DevStore, type DevStoreSnapshot, ENV_FILE_MIN_NODE, type EnvFileChoice, type LoadEnvFileOptions, type LoadedPackage, type ResolveNodeConfigInput, type ResolveNodeConfigResult, STORE_SCHEMA_VERSION, type SecretRecord, type SecretSeed, type TriggerRecord, type ValidateNodeConfigInput, type ValidateNodeConfigResult, type WorkflowRecord, type WorkflowSeed, applySeeds, buildOAuthAuthorizeUrl, createDevServer, createRequestListener, ensureTsxRegistered, exchangeOAuthCode, findCredential, findCredentialType, findNode, importFresh, interpolateEnv, loadEnvFile, loadPackageFromEntry, loadSeedsFromDir, loadState, nodeOwnedEnvFlag, nodeVersions, resolveCredentialInstance, resolveEnvFile, resolveExports, resolveNodeConfig, saveState, testCredentialConfig, testCredentialInstance, validateNodeConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEVKIT_VERSION,
|
|
3
|
+
DEV_TENANT_ID,
|
|
4
|
+
DevApiError,
|
|
5
|
+
DevStore,
|
|
6
|
+
ENV_FILE_MIN_NODE,
|
|
7
|
+
STORE_SCHEMA_VERSION,
|
|
8
|
+
applySeeds,
|
|
9
|
+
buildOAuthAuthorizeUrl,
|
|
10
|
+
createDevServer,
|
|
11
|
+
createRequestListener,
|
|
12
|
+
ensureTsxRegistered,
|
|
13
|
+
exchangeOAuthCode,
|
|
14
|
+
findCredential,
|
|
15
|
+
findCredentialType,
|
|
16
|
+
findNode,
|
|
17
|
+
importFresh,
|
|
18
|
+
interpolateEnv,
|
|
19
|
+
loadEnvFile,
|
|
20
|
+
loadPackageFromEntry,
|
|
21
|
+
loadSeedsFromDir,
|
|
22
|
+
loadState,
|
|
23
|
+
nodeOwnedEnvFlag,
|
|
24
|
+
nodeVersions,
|
|
25
|
+
resolveCredentialInstance,
|
|
26
|
+
resolveEnvFile,
|
|
27
|
+
resolveExports,
|
|
28
|
+
resolveNodeConfig,
|
|
29
|
+
saveState,
|
|
30
|
+
testCredentialConfig,
|
|
31
|
+
testCredentialInstance,
|
|
32
|
+
validateNodeConfig
|
|
33
|
+
} from "./chunk-UBYGZFB7.js";
|
|
34
|
+
export {
|
|
35
|
+
DEVKIT_VERSION,
|
|
36
|
+
DEV_TENANT_ID,
|
|
37
|
+
DevApiError,
|
|
38
|
+
DevStore,
|
|
39
|
+
ENV_FILE_MIN_NODE,
|
|
40
|
+
STORE_SCHEMA_VERSION,
|
|
41
|
+
applySeeds,
|
|
42
|
+
buildOAuthAuthorizeUrl,
|
|
43
|
+
createDevServer,
|
|
44
|
+
createRequestListener,
|
|
45
|
+
ensureTsxRegistered,
|
|
46
|
+
exchangeOAuthCode,
|
|
47
|
+
findCredential,
|
|
48
|
+
findCredentialType,
|
|
49
|
+
findNode,
|
|
50
|
+
importFresh,
|
|
51
|
+
interpolateEnv,
|
|
52
|
+
loadEnvFile,
|
|
53
|
+
loadPackageFromEntry,
|
|
54
|
+
loadSeedsFromDir,
|
|
55
|
+
loadState,
|
|
56
|
+
nodeOwnedEnvFlag,
|
|
57
|
+
nodeVersions,
|
|
58
|
+
resolveCredentialInstance,
|
|
59
|
+
resolveEnvFile,
|
|
60
|
+
resolveExports,
|
|
61
|
+
resolveNodeConfig,
|
|
62
|
+
saveState,
|
|
63
|
+
testCredentialConfig,
|
|
64
|
+
testCredentialInstance,
|
|
65
|
+
validateNodeConfig
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/testing/index.ts
|
|
21
|
+
var testing_exports = {};
|
|
22
|
+
__export(testing_exports, {
|
|
23
|
+
buildResponse: () => buildResponse,
|
|
24
|
+
createAuthorContext: () => createAuthorContext,
|
|
25
|
+
createCredentialContext: () => createCredentialContext,
|
|
26
|
+
createMockContext: () => createMockContext,
|
|
27
|
+
fakeTokenEndpoint: () => fakeTokenEndpoint,
|
|
28
|
+
runCredentialResolve: () => runCredentialResolve,
|
|
29
|
+
runCredentialTest: () => runCredentialTest,
|
|
30
|
+
runOAuthAuthorizeUrl: () => runOAuthAuthorizeUrl,
|
|
31
|
+
runOAuthExchangeCode: () => runOAuthExchangeCode,
|
|
32
|
+
stubFetch: () => stubFetch
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(testing_exports);
|
|
35
|
+
|
|
36
|
+
// src/testing/context.ts
|
|
37
|
+
var import_vitest = require("vitest");
|
|
38
|
+
function createMockContext(options = {}) {
|
|
39
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
40
|
+
const secretsGet = options.secretsError ? import_vitest.vi.fn(async () => {
|
|
41
|
+
throw options.secretsError;
|
|
42
|
+
}) : import_vitest.vi.fn(async (key) => {
|
|
43
|
+
if (options.secrets && key in options.secrets) {
|
|
44
|
+
return options.secrets[key];
|
|
45
|
+
}
|
|
46
|
+
return `secret-value-for-${key}`;
|
|
47
|
+
});
|
|
48
|
+
const credentialsGet = options.credentialsError ? import_vitest.vi.fn(async () => {
|
|
49
|
+
throw options.credentialsError;
|
|
50
|
+
}) : import_vitest.vi.fn(async (id) => {
|
|
51
|
+
if (options.credentials && id in options.credentials) {
|
|
52
|
+
return options.credentials[id];
|
|
53
|
+
}
|
|
54
|
+
return {};
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
signal,
|
|
58
|
+
logger: {
|
|
59
|
+
info: import_vitest.vi.fn(),
|
|
60
|
+
warn: import_vitest.vi.fn(),
|
|
61
|
+
error: import_vitest.vi.fn()
|
|
62
|
+
},
|
|
63
|
+
secrets: {
|
|
64
|
+
get: secretsGet
|
|
65
|
+
},
|
|
66
|
+
credentials: {
|
|
67
|
+
get: credentialsGet
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/testing/author.ts
|
|
73
|
+
var import_vitest2 = require("vitest");
|
|
74
|
+
function createAuthorContext(config = {}, options = {}) {
|
|
75
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
76
|
+
const secretsGet = options.secretsError ? import_vitest2.vi.fn(async () => {
|
|
77
|
+
throw options.secretsError;
|
|
78
|
+
}) : import_vitest2.vi.fn(async (key) => {
|
|
79
|
+
if (options.secrets && key in options.secrets) {
|
|
80
|
+
return options.secrets[key];
|
|
81
|
+
}
|
|
82
|
+
return `secret-value-for-${key}`;
|
|
83
|
+
});
|
|
84
|
+
const credentialsGet = options.credentialsError ? import_vitest2.vi.fn(async () => {
|
|
85
|
+
throw options.credentialsError;
|
|
86
|
+
}) : import_vitest2.vi.fn(async (id) => {
|
|
87
|
+
if (options.credentials && id in options.credentials) {
|
|
88
|
+
return options.credentials[id];
|
|
89
|
+
}
|
|
90
|
+
return {};
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
signal,
|
|
94
|
+
logger: {
|
|
95
|
+
info: import_vitest2.vi.fn(),
|
|
96
|
+
warn: import_vitest2.vi.fn(),
|
|
97
|
+
error: import_vitest2.vi.fn()
|
|
98
|
+
},
|
|
99
|
+
config,
|
|
100
|
+
secrets: { get: secretsGet },
|
|
101
|
+
credentials: { get: credentialsGet },
|
|
102
|
+
locale: options.locale
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/testing/fetch.ts
|
|
107
|
+
var import_vitest3 = require("vitest");
|
|
108
|
+
function buildResponse(init) {
|
|
109
|
+
const headers = new Headers(init.headers ?? {});
|
|
110
|
+
let body;
|
|
111
|
+
if (init.body !== void 0) {
|
|
112
|
+
body = init.body;
|
|
113
|
+
} else if (init.json !== void 0) {
|
|
114
|
+
body = JSON.stringify(init.json);
|
|
115
|
+
if (!headers.has("content-type")) {
|
|
116
|
+
headers.set("content-type", "application/json");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return new Response(body, { status: init.status ?? 200, headers });
|
|
120
|
+
}
|
|
121
|
+
function stubFetch(handler) {
|
|
122
|
+
const previous = globalThis.fetch;
|
|
123
|
+
const resolveInit = typeof handler === "function" ? handler : () => handler;
|
|
124
|
+
const fetchMock = import_vitest3.vi.fn(async (input, init) => {
|
|
125
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
126
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
127
|
+
const out = await resolveInit({ url, method, init });
|
|
128
|
+
return out instanceof Response ? out : buildResponse(out);
|
|
129
|
+
});
|
|
130
|
+
globalThis.fetch = fetchMock;
|
|
131
|
+
return {
|
|
132
|
+
fetchMock,
|
|
133
|
+
restore() {
|
|
134
|
+
globalThis.fetch = previous;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function fakeTokenEndpoint(options = {}) {
|
|
139
|
+
const { tokenUrl, accessToken = "fake-access-token", tokenType = "Bearer", expiresIn = 3600, refreshToken, extra } = options;
|
|
140
|
+
return ({ url }) => {
|
|
141
|
+
if (tokenUrl && url !== tokenUrl) {
|
|
142
|
+
return { status: 404, json: { error: `no stub for ${url}` } };
|
|
143
|
+
}
|
|
144
|
+
const json = {
|
|
145
|
+
access_token: accessToken,
|
|
146
|
+
token_type: tokenType,
|
|
147
|
+
...expiresIn !== null ? { expires_in: expiresIn } : {},
|
|
148
|
+
...refreshToken !== void 0 ? { refresh_token: refreshToken } : {},
|
|
149
|
+
...extra
|
|
150
|
+
};
|
|
151
|
+
return { status: 200, json };
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/testing/credentials.ts
|
|
156
|
+
var import_integrations_node_sdk = require("@revenexx/integrations-node-sdk");
|
|
157
|
+
var import_vitest4 = require("vitest");
|
|
158
|
+
function createCredentialContext(options = {}) {
|
|
159
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
160
|
+
const persistDurableCreds = import_vitest4.vi.fn(async (_durableCreds) => {
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
signal,
|
|
164
|
+
logger: {
|
|
165
|
+
info: import_vitest4.vi.fn(),
|
|
166
|
+
warn: import_vitest4.vi.fn(),
|
|
167
|
+
error: import_vitest4.vi.fn()
|
|
168
|
+
},
|
|
169
|
+
persistDurableCreds
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function runCredentialTest(credential, options) {
|
|
173
|
+
const ctx = createCredentialContext({ signal: options.signal });
|
|
174
|
+
return credential.test(ctx, options.config);
|
|
175
|
+
}
|
|
176
|
+
async function runCredentialResolve(credential, options) {
|
|
177
|
+
const ctx = createCredentialContext({ signal: options.signal });
|
|
178
|
+
const result = await credential.resolve(ctx, options.config, options.durableCreds ?? null);
|
|
179
|
+
return { result, persistDurableCreds: ctx.persistDurableCreds, ctx };
|
|
180
|
+
}
|
|
181
|
+
async function runOAuthAuthorizeUrl(credential, options) {
|
|
182
|
+
if (!(0, import_integrations_node_sdk.isOAuthAuthorizeCredential)(credential)) {
|
|
183
|
+
throw new Error(`${credential.description.slug} is not a 3-legged OAuth credential`);
|
|
184
|
+
}
|
|
185
|
+
const ctx = createCredentialContext({ signal: options.signal });
|
|
186
|
+
return credential.buildAuthorizeUrl(ctx, options.config, {
|
|
187
|
+
redirectUri: options.redirectUri,
|
|
188
|
+
state: options.state
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async function runOAuthExchangeCode(credential, options) {
|
|
192
|
+
if (!(0, import_integrations_node_sdk.isOAuthAuthorizeCredential)(credential)) {
|
|
193
|
+
throw new Error(`${credential.description.slug} is not a 3-legged OAuth credential`);
|
|
194
|
+
}
|
|
195
|
+
const ctx = createCredentialContext({ signal: options.signal });
|
|
196
|
+
return credential.exchangeCode(ctx, options.config, {
|
|
197
|
+
code: options.code,
|
|
198
|
+
redirectUri: options.redirectUri,
|
|
199
|
+
codeVerifier: options.codeVerifier
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
203
|
+
0 && (module.exports = {
|
|
204
|
+
buildResponse,
|
|
205
|
+
createAuthorContext,
|
|
206
|
+
createCredentialContext,
|
|
207
|
+
createMockContext,
|
|
208
|
+
fakeTokenEndpoint,
|
|
209
|
+
runCredentialResolve,
|
|
210
|
+
runCredentialTest,
|
|
211
|
+
runOAuthAuthorizeUrl,
|
|
212
|
+
runOAuthExchangeCode,
|
|
213
|
+
stubFetch
|
|
214
|
+
});
|
|
215
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/testing/index.ts","../../src/testing/context.ts","../../src/testing/author.ts","../../src/testing/fetch.ts","../../src/testing/credentials.ts"],"sourcesContent":["export * from './context.js';\nexport * from './author.js';\nexport * from './fetch.js';\nexport * from './credentials.js';\n","import type { INodeContext } from '@revenexx/integrations-node-sdk';\nimport { vi } from 'vitest';\n\n/**\n * Drop-in replacement for the `createMockContext` helper that was, until this\n * package existed, copy-pasted byte-for-byte into every node repo's\n * `tests/helpers/context.ts`. Builds a full {@link INodeContext} with\n * `vi.fn()`-backed `logger`, `secrets.get`, and `credentials.get` so a node's\n * `execute` can be unit-tested in isolation.\n */\n\nexport type MockLogger = {\n info: ReturnType<typeof vi.fn>;\n warn: ReturnType<typeof vi.fn>;\n error: ReturnType<typeof vi.fn>;\n};\n\nexport type MockSecrets = {\n get: ReturnType<typeof vi.fn>;\n};\n\nexport type MockCredentials = {\n get: ReturnType<typeof vi.fn>;\n};\n\nexport type MockContext = INodeContext & {\n logger: MockLogger;\n secrets: MockSecrets;\n credentials: MockCredentials;\n};\n\nexport interface CreateMockContextOptions {\n signal?: AbortSignal;\n /** Secret key -> value returned by `secrets.get`. Unknown keys fall back to a deterministic stub. */\n secrets?: Record<string, string>;\n /** When set, `secrets.get` rejects with this error instead of resolving. */\n secretsError?: Error;\n /** Credential instance id -> resolved access data returned by `credentials.get`. */\n credentials?: Record<string, Record<string, unknown>>;\n /** When set, `credentials.get` rejects with this error instead of resolving. */\n credentialsError?: Error;\n}\n\nexport function createMockContext(options: CreateMockContextOptions = {}): MockContext {\n const signal = options.signal ?? new AbortController().signal;\n\n const secretsGet = options.secretsError\n ? vi.fn(async () => {\n throw options.secretsError;\n })\n : vi.fn(async (key: string) => {\n if (options.secrets && key in options.secrets) {\n return options.secrets[key];\n }\n return `secret-value-for-${key}`;\n });\n\n const credentialsGet = options.credentialsError\n ? vi.fn(async () => {\n throw options.credentialsError;\n })\n : vi.fn(async (id: string) => {\n if (options.credentials && id in options.credentials) {\n return options.credentials[id];\n }\n return {};\n });\n\n return {\n signal,\n logger: {\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n },\n secrets: {\n get: secretsGet,\n },\n credentials: {\n get: credentialsGet,\n },\n };\n}\n","import type { INodeAuthorContext } from '@revenexx/integrations-node-sdk';\nimport { vi } from 'vitest';\n\n/**\n * Builds an {@link INodeAuthorContext} for unit-testing a node's *author-time*\n * resolvers (`loadOptions`, `resolveConfigSchema`, `resolveOutputs`). Until this\n * package existed, this factory was reinvented inline in each repo's resolver\n * tests. Mirrors {@link createMockContext}: `secrets.get` / `credentials.get`\n * are `vi.fn()`-backed and seedable.\n */\n\nexport type MockAuthorLogger = {\n info: ReturnType<typeof vi.fn>;\n warn: ReturnType<typeof vi.fn>;\n error: ReturnType<typeof vi.fn>;\n};\n\nexport type MockAuthorContext = INodeAuthorContext & {\n logger: MockAuthorLogger;\n secrets: { get: ReturnType<typeof vi.fn> };\n credentials: { get: ReturnType<typeof vi.fn> };\n};\n\nexport interface CreateAuthorContextOptions {\n signal?: AbortSignal;\n /** Preferred locale for resolved labels. */\n locale?: string;\n secrets?: Record<string, string>;\n secretsError?: Error;\n credentials?: Record<string, Record<string, unknown>>;\n credentialsError?: Error;\n}\n\nexport function createAuthorContext(config: Record<string, unknown> = {}, options: CreateAuthorContextOptions = {}): MockAuthorContext {\n const signal = options.signal ?? new AbortController().signal;\n\n const secretsGet = options.secretsError\n ? vi.fn(async () => {\n throw options.secretsError;\n })\n : vi.fn(async (key: string) => {\n if (options.secrets && key in options.secrets) {\n return options.secrets[key];\n }\n return `secret-value-for-${key}`;\n });\n\n const credentialsGet = options.credentialsError\n ? vi.fn(async () => {\n throw options.credentialsError;\n })\n : vi.fn(async (id: string) => {\n if (options.credentials && id in options.credentials) {\n return options.credentials[id];\n }\n return {};\n });\n\n return {\n signal,\n logger: {\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n },\n config,\n secrets: { get: secretsGet },\n credentials: { get: credentialsGet },\n locale: options.locale,\n };\n}\n","import { vi } from 'vitest';\n\n/**\n * Utilities for stubbing the global `fetch` so a credential's `resolve` /\n * `test` (which reach an OAuth token endpoint via the SDK's `postForm`) or a\n * node's `execute` (which uses `safeFetch` → global `fetch`) can be\n * unit-tested without touching the network. Builds real `Response` objects so\n * `res.ok` / `res.status` / `res.text()` / `res.json()` all behave exactly as\n * in production.\n */\n\nexport interface StubResponseInit {\n status?: number;\n headers?: Record<string, string>;\n /** JSON body — serialized and served as `application/json` unless `body` is set. */\n json?: unknown;\n /** Raw string body. Takes precedence over `json`. */\n body?: string;\n}\n\nexport interface StubbedRequest {\n url: string;\n method: string;\n init?: RequestInit;\n}\n\nexport type FetchHandler = (request: StubbedRequest) => StubResponseInit | Response | Promise<StubResponseInit | Response>;\n\n/** Builds a real `Response` from a {@link StubResponseInit}. */\nexport function buildResponse(init: StubResponseInit): Response {\n const headers = new Headers(init.headers ?? {});\n let body: string | undefined;\n if (init.body !== undefined) {\n body = init.body;\n } else if (init.json !== undefined) {\n body = JSON.stringify(init.json);\n if (!headers.has('content-type')) {\n headers.set('content-type', 'application/json');\n }\n }\n return new Response(body, { status: init.status ?? 200, headers });\n}\n\nexport interface StubFetchResult {\n /** The `vi.fn()` installed as `globalThis.fetch` — assert calls on it. */\n fetchMock: ReturnType<typeof vi.fn>;\n /** Restores the previous `globalThis.fetch`. */\n restore(): void;\n}\n\n/**\n * Replaces `globalThis.fetch` with a `vi.fn()` driven by `handler`. Pass a\n * static {@link StubResponseInit} to answer every request identically, or a\n * {@link FetchHandler} to branch on url/method. Call `restore()` when done\n * (e.g. in `afterEach`).\n */\nexport function stubFetch(handler: FetchHandler | StubResponseInit): StubFetchResult {\n const previous = globalThis.fetch;\n const resolveInit: FetchHandler = typeof handler === 'function' ? handler : () => handler;\n\n const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {\n const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;\n const method = (init?.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase();\n const out = await resolveInit({ url, method, init });\n return out instanceof Response ? out : buildResponse(out);\n });\n\n globalThis.fetch = fetchMock as unknown as typeof fetch;\n return {\n fetchMock,\n restore() {\n globalThis.fetch = previous;\n },\n };\n}\n\nexport interface FakeTokenEndpointOptions {\n /** Only answer requests to this exact URL; other requests 404. Omit to answer any URL. */\n tokenUrl?: string;\n accessToken?: string;\n tokenType?: string;\n /** Seconds until expiry (OAuth `expires_in`). Set `null` to omit the field. */\n expiresIn?: number | null;\n /** Included as `refresh_token` when set (e.g. to assert rotation). */\n refreshToken?: string;\n /** Extra fields merged into the token response body. */\n extra?: Record<string, unknown>;\n}\n\n/**\n * A {@link FetchHandler} that emulates an OAuth token endpoint, returning\n * `{ access_token, token_type, expires_in, refresh_token? }`. Compose with\n * {@link stubFetch} to unit-test `oauth2-*` credentials' `resolve` / OAuth\n * `exchangeCode`.\n */\nexport function fakeTokenEndpoint(options: FakeTokenEndpointOptions = {}): FetchHandler {\n const { tokenUrl, accessToken = 'fake-access-token', tokenType = 'Bearer', expiresIn = 3600, refreshToken, extra } = options;\n\n return ({ url }) => {\n if (tokenUrl && url !== tokenUrl) {\n return { status: 404, json: { error: `no stub for ${url}` } };\n }\n const json: Record<string, unknown> = {\n access_token: accessToken,\n token_type: tokenType,\n ...(expiresIn !== null ? { expires_in: expiresIn } : {}),\n ...(refreshToken !== undefined ? { refresh_token: refreshToken } : {}),\n ...extra,\n };\n return { status: 200, json };\n };\n}\n","import type { ICredential, ICredentialContext, ICredentialResolveResult, ICredentialTestResult } from '@revenexx/integrations-node-sdk';\nimport { isOAuthAuthorizeCredential } from '@revenexx/integrations-node-sdk';\nimport { vi } from 'vitest';\n\n/**\n * Harness for unit-testing a credential type's `test` / `resolve` / 3-legged\n * OAuth without the credentials broker or a real provider. Combine with\n * {@link stubFetch} / {@link fakeTokenEndpoint} to drive the token endpoint,\n * and inspect the returned `persistDurableCreds` spy to assert refresh-token\n * rotation.\n */\n\nexport type MockCredentialLogger = {\n info: ReturnType<typeof vi.fn>;\n warn: ReturnType<typeof vi.fn>;\n error: ReturnType<typeof vi.fn>;\n};\n\nexport type MockCredentialContext = ICredentialContext & {\n logger: MockCredentialLogger;\n /** Spy wired to `ctx.persistDurableCreds`; assert `.toHaveBeenCalledWith(...)`. */\n persistDurableCreds: ReturnType<typeof vi.fn>;\n};\n\nexport interface CreateCredentialContextOptions {\n signal?: AbortSignal;\n}\n\nexport function createCredentialContext(options: CreateCredentialContextOptions = {}): MockCredentialContext {\n const signal = options.signal ?? new AbortController().signal;\n const persistDurableCreds = vi.fn(async (_durableCreds: Record<string, unknown>) => {});\n return {\n signal,\n logger: {\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n },\n persistDurableCreds,\n };\n}\n\nexport interface RunCredentialTestOptions {\n config: Record<string, unknown>;\n signal?: AbortSignal;\n}\n\n/** Runs a credential's `test(ctx, config)` and returns its result. */\nexport async function runCredentialTest(credential: ICredential, options: RunCredentialTestOptions): Promise<ICredentialTestResult> {\n const ctx = createCredentialContext({ signal: options.signal });\n return credential.test(ctx, options.config);\n}\n\nexport interface RunCredentialResolveOptions {\n config: Record<string, unknown>;\n /** System-managed long-lived secrets (e.g. an OAuth `refresh_token`). */\n durableCreds?: Record<string, unknown> | null;\n signal?: AbortSignal;\n}\n\nexport interface RunCredentialResolveResult {\n result: ICredentialResolveResult;\n /** Spy wired to `ctx.persistDurableCreds` — assert rotation happened. */\n persistDurableCreds: ReturnType<typeof vi.fn>;\n /** The context used, for further assertions (logger calls, etc.). */\n ctx: MockCredentialContext;\n}\n\n/** Runs a credential's `resolve(ctx, config, durableCreds)` and captures rotation. */\nexport async function runCredentialResolve(credential: ICredential, options: RunCredentialResolveOptions): Promise<RunCredentialResolveResult> {\n const ctx = createCredentialContext({ signal: options.signal });\n const result = await credential.resolve(ctx, options.config, options.durableCreds ?? null);\n return { result, persistDurableCreds: ctx.persistDurableCreds, ctx };\n}\n\nexport interface RunOAuthAuthorizeUrlOptions {\n config: Record<string, unknown>;\n redirectUri: string;\n state: string;\n signal?: AbortSignal;\n}\n\n/** Runs `buildAuthorizeUrl` on a 3-legged OAuth credential; throws if unsupported. */\nexport async function runOAuthAuthorizeUrl(credential: ICredential, options: RunOAuthAuthorizeUrlOptions): Promise<{ authorizeUrl: string; codeVerifier?: string }> {\n if (!isOAuthAuthorizeCredential(credential)) {\n throw new Error(`${credential.description.slug} is not a 3-legged OAuth credential`);\n }\n const ctx = createCredentialContext({ signal: options.signal });\n return credential.buildAuthorizeUrl(ctx, options.config, {\n redirectUri: options.redirectUri,\n state: options.state,\n });\n}\n\nexport interface RunOAuthExchangeCodeOptions {\n config: Record<string, unknown>;\n code: string;\n redirectUri: string;\n codeVerifier?: string;\n signal?: AbortSignal;\n}\n\n/** Runs `exchangeCode` on a 3-legged OAuth credential; throws if unsupported. */\nexport async function runOAuthExchangeCode(credential: ICredential, options: RunOAuthExchangeCodeOptions): Promise<{ durableCreds: Record<string, unknown> }> {\n if (!isOAuthAuthorizeCredential(credential)) {\n throw new Error(`${credential.description.slug} is not a 3-legged OAuth credential`);\n }\n const ctx = createCredentialContext({ signal: options.signal });\n return credential.exchangeCode(ctx, options.config, {\n code: options.code,\n redirectUri: options.redirectUri,\n codeVerifier: options.codeVerifier,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,oBAAmB;AA0CZ,SAAS,kBAAkB,UAAoC,CAAC,GAAgB;AACrF,QAAM,SAAS,QAAQ,UAAU,IAAI,gBAAgB,EAAE;AAEvD,QAAM,aAAa,QAAQ,eACvB,iBAAG,GAAG,YAAY;AAChB,UAAM,QAAQ;AAAA,EAChB,CAAC,IACD,iBAAG,GAAG,OAAO,QAAgB;AAC3B,QAAI,QAAQ,WAAW,OAAO,QAAQ,SAAS;AAC7C,aAAO,QAAQ,QAAQ,GAAG;AAAA,IAC5B;AACA,WAAO,oBAAoB,GAAG;AAAA,EAChC,CAAC;AAEL,QAAM,iBAAiB,QAAQ,mBAC3B,iBAAG,GAAG,YAAY;AAChB,UAAM,QAAQ;AAAA,EAChB,CAAC,IACD,iBAAG,GAAG,OAAO,OAAe;AAC1B,QAAI,QAAQ,eAAe,MAAM,QAAQ,aAAa;AACpD,aAAO,QAAQ,YAAY,EAAE;AAAA,IAC/B;AACA,WAAO,CAAC;AAAA,EACV,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,MACN,MAAM,iBAAG,GAAG;AAAA,MACZ,MAAM,iBAAG,GAAG;AAAA,MACZ,OAAO,iBAAG,GAAG;AAAA,IACf;AAAA,IACA,SAAS;AAAA,MACP,KAAK;AAAA,IACP;AAAA,IACA,aAAa;AAAA,MACX,KAAK;AAAA,IACP;AAAA,EACF;AACF;;;ACjFA,IAAAA,iBAAmB;AAgCZ,SAAS,oBAAoB,SAAkC,CAAC,GAAG,UAAsC,CAAC,GAAsB;AACrI,QAAM,SAAS,QAAQ,UAAU,IAAI,gBA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