@grow-codes/aws-secrets-manager 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +115 -0
- package/README.md +33 -2
- package/lib/base-ClUDmFU5.d.cts +213 -0
- package/lib/base-ClUDmFU5.d.ts +213 -0
- package/lib/chunk-FGY6NSRU.js +822 -0
- package/lib/chunk-FGY6NSRU.js.map +1 -0
- package/lib/chunk-ZLYHN4AI.cjs +868 -0
- package/lib/chunk-ZLYHN4AI.cjs.map +1 -0
- package/lib/index.cjs +2964 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +1424 -0
- package/lib/index.d.ts +1424 -0
- package/lib/index.js +2721 -0
- package/lib/index.js.map +1 -0
- package/lib/testing/index.cjs +678 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +265 -0
- package/lib/testing/index.d.ts +265 -0
- package/lib/testing/index.js +655 -0
- package/lib/testing/index.js.map +1 -0
- package/package.json +100 -4
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { HealthStatus, BaseSecretsProvider, GetOptions, SecretValue, SignalOptions, SecretMetadata, SetOptions, DeleteOptions, SecretsProvider } from '../index.js';
|
|
2
|
+
|
|
3
|
+
/** Step expectations (SPEC §6). Every listed key must hold. */
|
|
4
|
+
interface Expectation {
|
|
5
|
+
reveal?: string;
|
|
6
|
+
equals?: unknown;
|
|
7
|
+
null?: boolean;
|
|
8
|
+
notNull?: boolean;
|
|
9
|
+
true?: boolean;
|
|
10
|
+
false?: boolean;
|
|
11
|
+
error?: string;
|
|
12
|
+
contains?: unknown;
|
|
13
|
+
notContains?: unknown;
|
|
14
|
+
count?: number;
|
|
15
|
+
minCount?: number;
|
|
16
|
+
sorted?: boolean;
|
|
17
|
+
type?: "string" | "number" | "boolean" | "object" | "array";
|
|
18
|
+
stringForm?: {
|
|
19
|
+
contains?: string;
|
|
20
|
+
notContains?: string;
|
|
21
|
+
};
|
|
22
|
+
tree?: Record<string, string[]>;
|
|
23
|
+
}
|
|
24
|
+
/** Converts Maps (recursively) to plain objects for comparisons. */
|
|
25
|
+
declare function toPlain(value: unknown): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Subset equality: objects in `expected` compare only the listed keys (recursively); arrays
|
|
28
|
+
* must have the same length with element-wise subset equality; other values use strict equality.
|
|
29
|
+
*/
|
|
30
|
+
declare function subsetEquals(actual: unknown, expected: unknown): boolean;
|
|
31
|
+
/** Size used by `count`/`minCount`: arrays, maps, sets, traces (`spans`), results (`records`), objects, strings. */
|
|
32
|
+
declare function sizeOf(value: unknown): number;
|
|
33
|
+
/** The language string forms checked by `stringForm`: `String()`, JSON and `util.inspect`. */
|
|
34
|
+
declare function stringForms(value: unknown): string[];
|
|
35
|
+
/** Throws an Error describing the first expectation that does not hold. */
|
|
36
|
+
declare function checkExpectations(value: unknown, expect: Expectation): void;
|
|
37
|
+
/** Options of {@link pollForExpectation}. */
|
|
38
|
+
interface PollForExpectationOptions {
|
|
39
|
+
/** Name used in the timeout message (default `"poll"`). */
|
|
40
|
+
operation?: string;
|
|
41
|
+
/** Default timeout when the step has no `timeoutMs` arg (default 60000 ms). */
|
|
42
|
+
defaultTimeoutMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* For op handlers of eventually consistent reads: calls `fn` until the step's expectation passes
|
|
46
|
+
* or `args.timeoutMs` (default 60000; poll every `args.intervalMs`, default 1000) runs out, then
|
|
47
|
+
* returns the last value so the runner reports the shortfall. Backends such as Tempo or
|
|
48
|
+
* SkyWalking list a new service tens of seconds late. Steps without an expectation (or with
|
|
49
|
+
* `expect.error`) call `fn` once; errors from `fn` are thrown at once.
|
|
50
|
+
*/
|
|
51
|
+
declare function pollForExpectation<T>(fn: () => Promise<T>, args: Readonly<Record<string, unknown>>, context: Pick<OpContext, "step" | "substitute">, options?: PollForExpectationOptions): Promise<T>;
|
|
52
|
+
|
|
53
|
+
/** Scenario categories. */
|
|
54
|
+
type Category = "core" | "secrets" | "logging" | "tracing";
|
|
55
|
+
/** One step of a scenario file. */
|
|
56
|
+
interface ScenarioStep {
|
|
57
|
+
op: string;
|
|
58
|
+
args?: Record<string, unknown>;
|
|
59
|
+
expect?: Expectation;
|
|
60
|
+
save?: string;
|
|
61
|
+
requires?: string[];
|
|
62
|
+
}
|
|
63
|
+
/** A scenario file (`spec/schemas/scenario.schema.json`). */
|
|
64
|
+
interface Scenario {
|
|
65
|
+
id: string;
|
|
66
|
+
category: Category;
|
|
67
|
+
description?: string;
|
|
68
|
+
requires?: string[];
|
|
69
|
+
batchOptions?: Record<string, unknown>;
|
|
70
|
+
steps: ScenarioStep[];
|
|
71
|
+
}
|
|
72
|
+
/** Context passed to factories (one target per scenario). */
|
|
73
|
+
interface FactoryContext {
|
|
74
|
+
scenario: Scenario;
|
|
75
|
+
/** Random 8-char lowercase run id (`${run}`). */
|
|
76
|
+
run: string;
|
|
77
|
+
/** Resolved provider prefix (`${prefix}`). */
|
|
78
|
+
prefix: string;
|
|
79
|
+
/** Scenario `batchOptions` (logging) for the factory to apply. */
|
|
80
|
+
batchOptions?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
/** Builds a target for one scenario. */
|
|
83
|
+
type Factory<T> = (context: FactoryContext) => T | Promise<T>;
|
|
84
|
+
/** Context passed to op handlers. */
|
|
85
|
+
interface OpContext {
|
|
86
|
+
readonly scenario: Scenario;
|
|
87
|
+
readonly step: ScenarioStep;
|
|
88
|
+
/** `${run}`. */
|
|
89
|
+
readonly run: string;
|
|
90
|
+
/** `${prefix}`. */
|
|
91
|
+
readonly prefix: string;
|
|
92
|
+
/** Variables (`${name}`): run, prefix, saved results, and values set by handlers. */
|
|
93
|
+
readonly vars: Record<string, unknown>;
|
|
94
|
+
/** Capabilities declared for this category. */
|
|
95
|
+
readonly capabilities: ReadonlySet<string>;
|
|
96
|
+
/** Replaces `${var}` placeholders in strings, recursively. */
|
|
97
|
+
substitute<T>(value: T): T;
|
|
98
|
+
/** Registers cleanup run after the scenario (in reverse order), even when it fails. */
|
|
99
|
+
onCleanup(fn: () => unknown): void;
|
|
100
|
+
}
|
|
101
|
+
/** One op handler. */
|
|
102
|
+
type OpHandler<T> = (target: T, args: Record<string, unknown>, context: OpContext) => unknown;
|
|
103
|
+
/** Handlers by op name. */
|
|
104
|
+
type OpHandlers<T> = Readonly<Record<string, OpHandler<T>>>;
|
|
105
|
+
/** Everything the runner needs for one category. */
|
|
106
|
+
interface CategoryOps<T> {
|
|
107
|
+
ops: OpHandlers<T>;
|
|
108
|
+
/** Called after each scenario (e.g. close the client). */
|
|
109
|
+
dispose?: (target: T, context: OpContext) => unknown;
|
|
110
|
+
/** Extra variables derived from the target (e.g. tracing `serviceName`). */
|
|
111
|
+
variables?: (target: T) => Record<string, unknown>;
|
|
112
|
+
}
|
|
113
|
+
/** {@link CategoryOps} of any target type. */
|
|
114
|
+
type AnyOps = CategoryOps<any>;
|
|
115
|
+
/**
|
|
116
|
+
* Adds or overrides op handlers for a category (merged over the built-in ones). Pass a
|
|
117
|
+
* {@link CategoryOps} or plain handlers.
|
|
118
|
+
*/
|
|
119
|
+
declare function registerOps<T>(category: string, ops: CategoryOps<T> | OpHandlers<T>): void;
|
|
120
|
+
/** Removes run-time registrations (tests). */
|
|
121
|
+
declare function resetRegisteredOps(): void;
|
|
122
|
+
/** Op handlers in effect for a category: built-ins, run-time registrations, then `extra`. */
|
|
123
|
+
declare function resolveOps(category: string, extra?: Readonly<Record<string, AnyOps | OpHandlers<unknown>>>): AnyOps | undefined;
|
|
124
|
+
/** Factories by category (`core → client`, `secrets → SecretsProvider`, …). */
|
|
125
|
+
type ConformanceFactories = Partial<Record<Category, Factory<any>>>;
|
|
126
|
+
/** Options of {@link runConformance}. */
|
|
127
|
+
interface ConformanceOptions {
|
|
128
|
+
/** Directory with the scenario JSON files (`<repo>/conformance/scenarios`). */
|
|
129
|
+
scenariosDir: string;
|
|
130
|
+
/** Categories to run (default: every category with a factory). */
|
|
131
|
+
categories?: readonly Category[];
|
|
132
|
+
/** Target factories. */
|
|
133
|
+
factories: ConformanceFactories;
|
|
134
|
+
/** Declared capabilities: one list for all categories, or per category. */
|
|
135
|
+
capabilities?: readonly string[] | Partial<Record<Category, readonly string[]>>;
|
|
136
|
+
/** Provider prefix (default `grow-conformance/${run}/`; may contain `${run}`). */
|
|
137
|
+
prefix?: string;
|
|
138
|
+
/** Extra variables. */
|
|
139
|
+
variables?: Record<string, unknown>;
|
|
140
|
+
/** Run only these scenario ids. */
|
|
141
|
+
only?: readonly string[];
|
|
142
|
+
/** Extra op handlers by category. */
|
|
143
|
+
ops?: Readonly<Record<string, AnyOps | OpHandlers<unknown>>>;
|
|
144
|
+
/** Run-id generator (default: random 8 lowercase alphanumerics). */
|
|
145
|
+
runId?: () => string;
|
|
146
|
+
}
|
|
147
|
+
/** Outcome of one step. */
|
|
148
|
+
interface StepResult {
|
|
149
|
+
index: number;
|
|
150
|
+
op: string;
|
|
151
|
+
status: "passed" | "failed" | "skipped";
|
|
152
|
+
error?: string;
|
|
153
|
+
skipReason?: string;
|
|
154
|
+
durationMs: number;
|
|
155
|
+
}
|
|
156
|
+
/** Outcome of one scenario. */
|
|
157
|
+
interface ScenarioResult {
|
|
158
|
+
id: string;
|
|
159
|
+
category: Category;
|
|
160
|
+
status: "passed" | "failed" | "skipped";
|
|
161
|
+
skipReason?: string;
|
|
162
|
+
error?: string;
|
|
163
|
+
steps: StepResult[];
|
|
164
|
+
durationMs: number;
|
|
165
|
+
}
|
|
166
|
+
/** Report returned by {@link runConformance}. */
|
|
167
|
+
interface ConformanceReport {
|
|
168
|
+
ok: boolean;
|
|
169
|
+
passed: number;
|
|
170
|
+
failed: number;
|
|
171
|
+
skipped: number;
|
|
172
|
+
results: ScenarioResult[];
|
|
173
|
+
}
|
|
174
|
+
/** Random 8-char lowercase id. */
|
|
175
|
+
declare function randomRunId(): string;
|
|
176
|
+
/** Loads and sorts (by id) every scenario file in a directory. */
|
|
177
|
+
declare function loadScenarios(scenariosDir: string): Scenario[];
|
|
178
|
+
/** Replaces `${name}` placeholders recursively. Unknown variables throw. */
|
|
179
|
+
declare function substitute<T>(value: T, vars: Readonly<Record<string, unknown>>): T;
|
|
180
|
+
/** Selected scenarios plus the reason a scenario is skipped up front (if any). */
|
|
181
|
+
declare function planScenarios(options: ConformanceOptions): {
|
|
182
|
+
scenario: Scenario;
|
|
183
|
+
skipReason?: string;
|
|
184
|
+
}[];
|
|
185
|
+
/** Runs one scenario. */
|
|
186
|
+
declare function runScenario(scenario: Scenario, options: ConformanceOptions): Promise<ScenarioResult>;
|
|
187
|
+
/** Runs every selected scenario sequentially and returns the report. */
|
|
188
|
+
declare function runConformance(options: ConformanceOptions): Promise<ConformanceReport>;
|
|
189
|
+
/** Human-readable report (one line per scenario, failures with their error). */
|
|
190
|
+
declare function formatReport(report: ConformanceReport): string;
|
|
191
|
+
/** Throws when the report has failures. */
|
|
192
|
+
declare function assertConformance(report: ConformanceReport): void;
|
|
193
|
+
/** One scenario as a test case (see {@link conformanceCases}). */
|
|
194
|
+
interface ConformanceCase {
|
|
195
|
+
id: string;
|
|
196
|
+
category: Category;
|
|
197
|
+
/** Set when the scenario is skipped (missing capabilities). */
|
|
198
|
+
skip?: string;
|
|
199
|
+
/** Runs the scenario; throws on failure. */
|
|
200
|
+
run(): Promise<ScenarioResult>;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Test-framework helper: one case per selected scenario, loaded synchronously.
|
|
204
|
+
*
|
|
205
|
+
* ```ts
|
|
206
|
+
* for (const c of conformanceCases(options)) it.skipIf(c.skip !== undefined)(c.id, () => c.run());
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare function conformanceCases(options: ConformanceOptions): ConformanceCase[];
|
|
210
|
+
|
|
211
|
+
/** What the `core` scenarios need from a client (`<Service>Client` satisfies it). */
|
|
212
|
+
interface CoreTarget {
|
|
213
|
+
health(options?: {
|
|
214
|
+
signal?: AbortSignal;
|
|
215
|
+
}): Promise<HealthStatus>;
|
|
216
|
+
ping(options?: {
|
|
217
|
+
signal?: AbortSignal;
|
|
218
|
+
}): Promise<number>;
|
|
219
|
+
serverVersion(options?: {
|
|
220
|
+
signal?: AbortSignal;
|
|
221
|
+
}): Promise<string>;
|
|
222
|
+
close(): Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
/** `core` ops: `health ping serverVersion close`. The client is closed after each scenario. */
|
|
225
|
+
declare const coreOps: CategoryOps<CoreTarget>;
|
|
226
|
+
|
|
227
|
+
/** Built-in handlers: `core` always, plus the service's categories. */
|
|
228
|
+
declare const builtinOps: Readonly<Record<string, CategoryOps<any>>>;
|
|
229
|
+
|
|
230
|
+
/** Options of {@link InMemorySecretsProvider}. */
|
|
231
|
+
interface InMemorySecretsOptions {
|
|
232
|
+
/** Initial secrets (name → text). */
|
|
233
|
+
initial?: Record<string, string>;
|
|
234
|
+
/** Clock (default `() => new Date()`). */
|
|
235
|
+
now?: () => Date;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Versioned in-memory {@link BaseSecretsProvider} for tests and the conformance suite.
|
|
239
|
+
* Versions are `"1"`, `"2"`, …; `cas` is the expected current version (`0` = must not
|
|
240
|
+
* exist); names are flat strings where `/` separates paths. Capabilities: `write`,
|
|
241
|
+
* `versions`, `delete`.
|
|
242
|
+
*/
|
|
243
|
+
declare class InMemorySecretsProvider extends BaseSecretsProvider {
|
|
244
|
+
#private;
|
|
245
|
+
/** Capabilities to declare to the conformance runner. */
|
|
246
|
+
static readonly capabilities: readonly string[];
|
|
247
|
+
/** Number of primitive calls by name (`fetchSecret`, `putSecret`, …), for tests. */
|
|
248
|
+
readonly calls: Record<string, number>;
|
|
249
|
+
constructor(options?: InMemorySecretsOptions);
|
|
250
|
+
/** Full name for a name and optional path. */
|
|
251
|
+
static fullName(name: string, path?: string): string;
|
|
252
|
+
protected fetchSecret(name: string, options: GetOptions): Promise<SecretValue | null>;
|
|
253
|
+
protected listSecrets(prefixOrPath: string | undefined, _options: SignalOptions): Promise<SecretMetadata[]>;
|
|
254
|
+
protected putSecret(name: string, value: Uint8Array, options: SetOptions): Promise<string>;
|
|
255
|
+
protected removeSecret(name: string, options: DeleteOptions): Promise<void>;
|
|
256
|
+
protected fetchMetadata(name: string, options: GetOptions): Promise<SecretMetadata | null>;
|
|
257
|
+
/** Number of stored secrets (tests). */
|
|
258
|
+
get size(): number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** `secrets` ops (SPEC §6) against a {@link SecretsProvider}. */
|
|
262
|
+
declare const secretsOps: CategoryOps<SecretsProvider>;
|
|
263
|
+
|
|
264
|
+
export { InMemorySecretsProvider, assertConformance, builtinOps, checkExpectations, conformanceCases, coreOps, formatReport, loadScenarios, planScenarios, pollForExpectation, randomRunId, registerOps, resetRegisteredOps, resolveOps, runConformance, runScenario, secretsOps, sizeOf, stringForms, subsetEquals, substitute, toPlain };
|
|
265
|
+
export type { AnyOps, Category, CategoryOps, ConformanceCase, ConformanceFactories, ConformanceOptions, ConformanceReport, CoreTarget, Expectation, Factory, FactoryContext, InMemorySecretsOptions, OpContext, OpHandler, OpHandlers, PollForExpectationOptions, Scenario, ScenarioResult, ScenarioStep, StepResult };
|