@revenexx/integrations-node-devkit 0.2.0 → 0.2.2
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-2GVOKLIW.js +1273 -0
- package/dist/chunk-2GVOKLIW.js.map +1 -0
- package/dist/cli.cjs +2049 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +799 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1341 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +379 -0
- package/dist/index.d.ts +379 -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,379 @@
|
|
|
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
|
+
* Exactly one file is ever loaded: `.env` by default, or the one named by
|
|
16
|
+
* `--env`, which *replaces* the default rather than layering on top of it.
|
|
17
|
+
* "Use this env file" is what the flag reads like, so leaving `.env` in play
|
|
18
|
+
* would be the surprise. `--no-env` loads none.
|
|
19
|
+
*
|
|
20
|
+
* `process.loadEnvFile` deliberately does not overwrite variables that are
|
|
21
|
+
* already set, so a shell-provided value always beats the file:
|
|
22
|
+
*
|
|
23
|
+
* REVENEXX_DEV_API_KEY=… npm run preview
|
|
24
|
+
*
|
|
25
|
+
* The flag is `--env`, *not* `--env-file`: Node reserves `--env-file` and
|
|
26
|
+
* `--env-file-if-exists` and acts on them wherever they appear, including after
|
|
27
|
+
* the script path. `node cli.js --env-file missing` therefore dies inside Node
|
|
28
|
+
* with exit code 9 before this module is ever reached, so the devkit cannot own
|
|
29
|
+
* that name. {@link nodeOwnedEnvFlag} spots the mistake and explains it.
|
|
30
|
+
*
|
|
31
|
+
* `--env` takes a path rather than Laravel's bare environment name, because it
|
|
32
|
+
* mirrors Node's flag and because a path can point outside the package. A value
|
|
33
|
+
* that looks like it was meant as a name still gets a pointed error — see
|
|
34
|
+
* {@link missingFileMessage}.
|
|
35
|
+
*/
|
|
36
|
+
/** Minimum Node version shipping `process.loadEnvFile`. */
|
|
37
|
+
declare const ENV_FILE_MIN_NODE = "20.12";
|
|
38
|
+
interface EnvFileChoice {
|
|
39
|
+
/** Absolute path to load, or `null` when `--no-env` disabled loading. */
|
|
40
|
+
path: string | null;
|
|
41
|
+
/** True when the file was named with `--env` rather than defaulted to. */
|
|
42
|
+
explicit: boolean;
|
|
43
|
+
/** The `--env` value exactly as typed, kept for {@link missingFileMessage}. */
|
|
44
|
+
raw?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the Node-owned env flag present in `argv`, if any. Node has already
|
|
48
|
+
* acted on it by the time the CLI runs — this exists only so the CLI can say so
|
|
49
|
+
* instead of leaving the user wondering why `--env-file` behaved oddly.
|
|
50
|
+
*/
|
|
51
|
+
declare function nodeOwnedEnvFlag(argv: string[]): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Decides which env file to load. Pure — touches neither disk nor `process.env`.
|
|
54
|
+
*
|
|
55
|
+
* A repeated `--env` resolves to the last one, matching every other option in
|
|
56
|
+
* the CLI, whose parse loop simply overwrites. Every occurrence is still
|
|
57
|
+
* validated, so a malformed earlier one is reported rather than skipped.
|
|
58
|
+
*/
|
|
59
|
+
declare function resolveEnvFile(argv: string[], cwd?: string): EnvFileChoice;
|
|
60
|
+
interface LoadEnvFileOptions {
|
|
61
|
+
cwd?: string;
|
|
62
|
+
warn?: (message: string) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Loads the env file chosen by {@link resolveEnvFile} into `process.env` and
|
|
66
|
+
* returns its path, or `null` when nothing was loaded.
|
|
67
|
+
*
|
|
68
|
+
* A missing *default* `.env` is fine — most packages do not have one. A file
|
|
69
|
+
* asked for by name and missing is an error: ignoring it would hide a typo and
|
|
70
|
+
* resurface much later as a puzzling `Seed references ${X}` failure. There is no
|
|
71
|
+
* fallback to `.env` in that case, since naming a file replaces the default.
|
|
72
|
+
*/
|
|
73
|
+
declare function loadEnvFile(argv: string[], options?: LoadEnvFileOptions): string | null;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* An error that maps to an HTTP status + JSON body in the mock API, mirroring
|
|
77
|
+
* Laravel's `{message}` / `{message, errors}` envelopes.
|
|
78
|
+
*/
|
|
79
|
+
declare class DevApiError extends Error {
|
|
80
|
+
readonly status: number;
|
|
81
|
+
readonly errors?: Record<string, string[]> | undefined;
|
|
82
|
+
constructor(status: number, message: string, errors?: Record<string, string[]> | undefined);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A node package loaded into the dev process: its live `NODES` / `CREDENTIALS`
|
|
87
|
+
* / `TEMPLATES` instances (so author-time resolvers, `test`, and `resolve` can
|
|
88
|
+
* be invoked in-process — no bundle, no sandbox) plus the derived manifest the
|
|
89
|
+
* mock API serves.
|
|
90
|
+
*/
|
|
91
|
+
interface LoadedPackage {
|
|
92
|
+
nodes: INode[];
|
|
93
|
+
credentials: ICredential[];
|
|
94
|
+
templates: ITemplateDescription[];
|
|
95
|
+
manifest: NodeManifest;
|
|
96
|
+
}
|
|
97
|
+
interface PackageExports {
|
|
98
|
+
NODES?: unknown;
|
|
99
|
+
CREDENTIALS?: unknown;
|
|
100
|
+
TEMPLATES?: unknown;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Validates a package's module exports and builds a {@link LoadedPackage}.
|
|
104
|
+
* Mirrors the checks in the SDK's `rvnxx-nodes manifest` CLI so the dev loop
|
|
105
|
+
* and the build produce identical manifests.
|
|
106
|
+
*/
|
|
107
|
+
declare function resolveExports(mod: PackageExports): LoadedPackage;
|
|
108
|
+
/**
|
|
109
|
+
* Registers the `tsx` ESM loader once per process so `import()` can load
|
|
110
|
+
* TypeScript sources directly. Idempotent.
|
|
111
|
+
*/
|
|
112
|
+
declare function ensureTsxRegistered(): Promise<void>;
|
|
113
|
+
/** Imports a module by path, registering tsx first for TypeScript sources. */
|
|
114
|
+
declare function importFresh<T = unknown>(entryPath: string): Promise<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Imports a package entry and resolves its exports. Supports TypeScript
|
|
117
|
+
* sources directly (via `tsx`) so the preview runs against the developer's
|
|
118
|
+
* live `src/`, not a built artifact. A cache-busting query is appended so
|
|
119
|
+
* repeated calls (hot-reload) re-evaluate the module.
|
|
120
|
+
*/
|
|
121
|
+
declare function loadPackageFromEntry(entryPath: string): Promise<LoadedPackage>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* In-memory data store backing the mock Integrations API. Holds the tenant-
|
|
125
|
+
* scoped resources a developer creates in the preview (credentials, secrets,
|
|
126
|
+
* workflows, triggers). Serializable so a session can be persisted to and
|
|
127
|
+
* rehydrated from `.revenexx-dev/state.json`.
|
|
128
|
+
*/
|
|
129
|
+
declare const DEV_TENANT_ID = "dev-tenant";
|
|
130
|
+
interface CredentialRecord {
|
|
131
|
+
id: string;
|
|
132
|
+
tenantId: string;
|
|
133
|
+
credentialTypeSlug: string;
|
|
134
|
+
name: string;
|
|
135
|
+
status: string;
|
|
136
|
+
/** Full user-entered config, including secret fields (never sent to the UI verbatim). */
|
|
137
|
+
config: Record<string, unknown>;
|
|
138
|
+
/** System-managed long-lived secrets (e.g. an OAuth refresh token). */
|
|
139
|
+
durableCreds: Record<string, unknown> | null;
|
|
140
|
+
createdAt: string;
|
|
141
|
+
updatedAt: string;
|
|
142
|
+
}
|
|
143
|
+
interface SecretRecord {
|
|
144
|
+
key: string;
|
|
145
|
+
value: string;
|
|
146
|
+
createdAt: string;
|
|
147
|
+
updatedAt: string;
|
|
148
|
+
}
|
|
149
|
+
interface WorkflowRecord {
|
|
150
|
+
id: number;
|
|
151
|
+
name: string;
|
|
152
|
+
definition: Record<string, unknown>;
|
|
153
|
+
buildStatus: string;
|
|
154
|
+
createdAt: string;
|
|
155
|
+
updatedAt: string;
|
|
156
|
+
}
|
|
157
|
+
interface TriggerRecord {
|
|
158
|
+
id: string;
|
|
159
|
+
workflowId: number;
|
|
160
|
+
type: string;
|
|
161
|
+
name: string | null;
|
|
162
|
+
config: Record<string, unknown>;
|
|
163
|
+
active: boolean;
|
|
164
|
+
createdAt: string;
|
|
165
|
+
updatedAt: string;
|
|
166
|
+
}
|
|
167
|
+
interface DevStoreSnapshot {
|
|
168
|
+
schemaVersion: number;
|
|
169
|
+
credentials: CredentialRecord[];
|
|
170
|
+
secrets: SecretRecord[];
|
|
171
|
+
workflows: WorkflowRecord[];
|
|
172
|
+
triggers: TriggerRecord[];
|
|
173
|
+
nextWorkflowId: number;
|
|
174
|
+
}
|
|
175
|
+
declare const STORE_SCHEMA_VERSION = 1;
|
|
176
|
+
declare class DevStore {
|
|
177
|
+
private onChange?;
|
|
178
|
+
private credentials;
|
|
179
|
+
private secrets;
|
|
180
|
+
private workflows;
|
|
181
|
+
private triggers;
|
|
182
|
+
private nextWorkflowId;
|
|
183
|
+
/**
|
|
184
|
+
* @param onChange fired after any mutation so a caller (the CLI) can persist
|
|
185
|
+
* the session to `.revenexx-dev/state.json`.
|
|
186
|
+
*/
|
|
187
|
+
constructor(onChange?: (() => void) | undefined);
|
|
188
|
+
/** (Re)wire the post-mutation callback — e.g. attach it only after seeding. */
|
|
189
|
+
setOnMutation(onChange: (() => void) | undefined): void;
|
|
190
|
+
private touch;
|
|
191
|
+
listCredentials(typeSlug?: string): CredentialRecord[];
|
|
192
|
+
getCredential(id: string): CredentialRecord | undefined;
|
|
193
|
+
createCredential(input: {
|
|
194
|
+
credentialTypeSlug: string;
|
|
195
|
+
name: string;
|
|
196
|
+
config: Record<string, unknown>;
|
|
197
|
+
status?: string;
|
|
198
|
+
/** Stable id — pass to keep a seeded credential's id fixed across restarts. */
|
|
199
|
+
id?: string;
|
|
200
|
+
durableCreds?: Record<string, unknown> | null;
|
|
201
|
+
}): CredentialRecord;
|
|
202
|
+
updateCredential(id: string, patch: Partial<Pick<CredentialRecord, 'name' | 'config' | 'status' | 'durableCreds'>>): CredentialRecord | undefined;
|
|
203
|
+
deleteCredential(id: string): boolean;
|
|
204
|
+
listSecrets(): SecretRecord[];
|
|
205
|
+
getSecret(key: string): SecretRecord | undefined;
|
|
206
|
+
setSecret(key: string, value: string): SecretRecord;
|
|
207
|
+
deleteSecret(key: string): boolean;
|
|
208
|
+
listWorkflows(): WorkflowRecord[];
|
|
209
|
+
getWorkflow(id: number): WorkflowRecord | undefined;
|
|
210
|
+
createWorkflow(input: {
|
|
211
|
+
name: string;
|
|
212
|
+
definition: Record<string, unknown>;
|
|
213
|
+
}): WorkflowRecord;
|
|
214
|
+
updateWorkflow(id: number, patch: Partial<Pick<WorkflowRecord, 'name' | 'definition' | 'buildStatus'>>): WorkflowRecord | undefined;
|
|
215
|
+
deleteWorkflow(id: number): boolean;
|
|
216
|
+
listTriggers(workflowId: number): TriggerRecord[];
|
|
217
|
+
getTrigger(id: string): TriggerRecord | undefined;
|
|
218
|
+
createTrigger(input: {
|
|
219
|
+
workflowId: number;
|
|
220
|
+
type: string;
|
|
221
|
+
name?: string | null;
|
|
222
|
+
config?: Record<string, unknown>;
|
|
223
|
+
active?: boolean;
|
|
224
|
+
id?: string;
|
|
225
|
+
}): TriggerRecord;
|
|
226
|
+
replaceTrigger(id: string, input: {
|
|
227
|
+
type: string;
|
|
228
|
+
name?: string | null;
|
|
229
|
+
config?: Record<string, unknown>;
|
|
230
|
+
active?: boolean;
|
|
231
|
+
}): TriggerRecord | undefined;
|
|
232
|
+
deleteTrigger(id: string): boolean;
|
|
233
|
+
toSnapshot(): DevStoreSnapshot;
|
|
234
|
+
loadSnapshot(snapshot: DevStoreSnapshot): void;
|
|
235
|
+
/**
|
|
236
|
+
* Overlays a snapshot on top of the current contents (upsert by id/key), used
|
|
237
|
+
* to layer the persisted `.revenexx-dev/state.json` session over the freshly
|
|
238
|
+
* applied committed seeds. State entries win over seed entries with the same
|
|
239
|
+
* id/key; seed-only entries are preserved.
|
|
240
|
+
*/
|
|
241
|
+
mergeSnapshot(snapshot: DevStoreSnapshot): void;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Layered persistence for the preview session:
|
|
246
|
+
* 1. committed seeds (this module's {@link applySeeds}) — the durable base,
|
|
247
|
+
* with `${ENV_VAR}` references interpolated from the environment;
|
|
248
|
+
* 2. `.revenexx-dev/state.json` overlay ({@link loadState}/{@link saveState}) —
|
|
249
|
+
* interactive session state, versioned and disposable.
|
|
250
|
+
*/
|
|
251
|
+
interface CredentialSeed {
|
|
252
|
+
credentialTypeSlug: string;
|
|
253
|
+
name: string;
|
|
254
|
+
config: Record<string, unknown>;
|
|
255
|
+
/** Stable id so workflows can reference the credential across restarts. */
|
|
256
|
+
id?: string;
|
|
257
|
+
status?: string;
|
|
258
|
+
durableCreds?: Record<string, unknown> | null;
|
|
259
|
+
}
|
|
260
|
+
interface SecretSeed {
|
|
261
|
+
key: string;
|
|
262
|
+
value: string;
|
|
263
|
+
}
|
|
264
|
+
interface WorkflowSeed {
|
|
265
|
+
name: string;
|
|
266
|
+
definition: Record<string, unknown>;
|
|
267
|
+
}
|
|
268
|
+
interface DevSeeds {
|
|
269
|
+
credentials?: CredentialSeed[];
|
|
270
|
+
secrets?: SecretSeed[];
|
|
271
|
+
workflows?: WorkflowSeed[];
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Recursively replaces `${ENV_VAR}` references in string values from `env`.
|
|
275
|
+
* Throws a clear error when a referenced variable is unset so a developer
|
|
276
|
+
* knows to add it to their `.env` — keeping secrets out of committed seeds.
|
|
277
|
+
*/
|
|
278
|
+
declare function interpolateEnv<T>(value: T, env?: NodeJS.ProcessEnv): T;
|
|
279
|
+
/** Applies committed seeds to the store (env-interpolated). */
|
|
280
|
+
declare function applySeeds(store: DevStore, seeds: DevSeeds, env?: NodeJS.ProcessEnv): void;
|
|
281
|
+
/**
|
|
282
|
+
* Reads a persisted session snapshot. Returns `null` (and warns) when the file
|
|
283
|
+
* is absent or its `schemaVersion` no longer matches — the overlay is
|
|
284
|
+
* disposable, so a mismatch is discarded rather than migrated.
|
|
285
|
+
*/
|
|
286
|
+
declare function loadState(file: string, log?: (msg: string) => void): DevStoreSnapshot | null;
|
|
287
|
+
declare function saveState(file: string, snapshot: DevStoreSnapshot): void;
|
|
288
|
+
/**
|
|
289
|
+
* Loads committed seeds from a directory (default `dev/seeds`). Resolves the
|
|
290
|
+
* first present entry file and reads its `default` or named `seeds` export.
|
|
291
|
+
* Returns empty seeds when no seed directory/entry exists.
|
|
292
|
+
*/
|
|
293
|
+
declare function loadSeedsFromDir(dir: string): Promise<DevSeeds>;
|
|
294
|
+
|
|
295
|
+
declare function nodeVersions(loaded: LoadedPackage, slug: string): string[];
|
|
296
|
+
declare function findNode(loaded: LoadedPackage, slug: string, version?: string): INode;
|
|
297
|
+
declare function findCredential(loaded: LoadedPackage, slug: string): ICredential;
|
|
298
|
+
declare function findCredentialType(loaded: LoadedPackage, slug: string): ICredentialDescription;
|
|
299
|
+
/** Resolves a credential instance's access data by running its real `resolve`. */
|
|
300
|
+
declare function resolveCredentialInstance(loaded: LoadedPackage, store: DevStore, credentialId: string): Promise<ICredentialResolveResult>;
|
|
301
|
+
interface ResolveNodeConfigInput {
|
|
302
|
+
slug: string;
|
|
303
|
+
version?: string;
|
|
304
|
+
/** `"*"` (all), `"outputs"`, or a specific config field key. */
|
|
305
|
+
target: string;
|
|
306
|
+
config: Record<string, unknown>;
|
|
307
|
+
locale?: string;
|
|
308
|
+
}
|
|
309
|
+
interface ResolveNodeConfigResult {
|
|
310
|
+
options?: IConfigOption[];
|
|
311
|
+
fields?: IConfigField[];
|
|
312
|
+
outputs?: IOutputPort[];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Runs a node's author-time resolvers for the requested `target`, mirroring
|
|
316
|
+
* the server's `config:resolve` semantics.
|
|
317
|
+
*/
|
|
318
|
+
declare function resolveNodeConfig(loaded: LoadedPackage, store: DevStore, input: ResolveNodeConfigInput): Promise<ResolveNodeConfigResult>;
|
|
319
|
+
interface ValidateNodeConfigInput {
|
|
320
|
+
slug: string;
|
|
321
|
+
version?: string;
|
|
322
|
+
config: Record<string, unknown>;
|
|
323
|
+
locale?: string;
|
|
324
|
+
}
|
|
325
|
+
interface ValidateNodeConfigResult {
|
|
326
|
+
valid: boolean;
|
|
327
|
+
/** Config field key → human-readable messages. Empty object when valid. */
|
|
328
|
+
errors: Record<string, string[]>;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Validates a submitted node `config` against the field rules in its manifest
|
|
332
|
+
* (`required`, `IConfigValidation`, types, static options). For `dynamic-schema`
|
|
333
|
+
* fields the resolved child schema is fetched and its rules applied to the
|
|
334
|
+
* flattened keys. Deep cross-field validation is intentionally out of scope
|
|
335
|
+
* (the production service does that on save); this mirrors the mock's
|
|
336
|
+
* "light, schema-based" fidelity. Unknown extra keys are ignored.
|
|
337
|
+
*/
|
|
338
|
+
declare function validateNodeConfig(loaded: LoadedPackage, store: DevStore, input: ValidateNodeConfigInput): Promise<ValidateNodeConfigResult>;
|
|
339
|
+
/** Runs a credential type's `test` against inline (unsaved) config. */
|
|
340
|
+
declare function testCredentialConfig(loaded: LoadedPackage, store: DevStore, typeSlug: string, config: Record<string, unknown>): Promise<ICredentialTestResult>;
|
|
341
|
+
/** Runs `test` against a saved credential instance's stored config. */
|
|
342
|
+
declare function testCredentialInstance(loaded: LoadedPackage, store: DevStore, credentialId: string): Promise<ICredentialTestResult>;
|
|
343
|
+
declare function buildOAuthAuthorizeUrl(loaded: LoadedPackage, store: DevStore, credentialId: string, params: {
|
|
344
|
+
redirectUri: string;
|
|
345
|
+
state: string;
|
|
346
|
+
}): Promise<{
|
|
347
|
+
authorizeUrl: string;
|
|
348
|
+
codeVerifier?: string;
|
|
349
|
+
}>;
|
|
350
|
+
declare function exchangeOAuthCode(loaded: LoadedPackage, store: DevStore, credentialId: string, params: {
|
|
351
|
+
code: string;
|
|
352
|
+
redirectUri: string;
|
|
353
|
+
codeVerifier?: string;
|
|
354
|
+
}): Promise<{
|
|
355
|
+
durableCreds: Record<string, unknown>;
|
|
356
|
+
}>;
|
|
357
|
+
|
|
358
|
+
interface DevServerDeps {
|
|
359
|
+
/** Returns the currently-loaded package; a function so hot-reload can swap it. */
|
|
360
|
+
getPackage(): LoadedPackage;
|
|
361
|
+
store: DevStore;
|
|
362
|
+
/** JSON schemas served at `/schemas/{domain}[/{version}]`, keyed by `domain` and `domain/version`. */
|
|
363
|
+
schemas?: Record<string, unknown>;
|
|
364
|
+
}
|
|
365
|
+
/** Builds the `(req, res)` request listener implementing the mock `/api/v1` surface. */
|
|
366
|
+
declare function createRequestListener(deps: DevServerDeps): http.RequestListener;
|
|
367
|
+
declare function createDevServer(deps: DevServerDeps): http.Server;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* `@revenexx/integrations-node-devkit` — local development kit for Revenexx
|
|
371
|
+
* integration node packages. Dev/CI only; never bundled into a node package.
|
|
372
|
+
*
|
|
373
|
+
* Two surfaces:
|
|
374
|
+
* - `@revenexx/integrations-node-devkit` → the mock-API preview server (this entry)
|
|
375
|
+
* - `@revenexx/integrations-node-devkit/testing` → the unit-testing harness
|
|
376
|
+
*/
|
|
377
|
+
declare const DEVKIT_VERSION: string;
|
|
378
|
+
|
|
379
|
+
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-2GVOKLIW.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
|