@bigfootai/sdk 1.18.0 → 1.20.0
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/configuration.d.ts +114 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +210 -0
- package/dist/configuration.js.map +1 -0
- package/dist/configuration.test.d.ts +2 -0
- package/dist/configuration.test.d.ts.map +1 -0
- package/dist/configuration.test.js +187 -0
- package/dist/configuration.test.js.map +1 -0
- package/dist/index.d.ts +12 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -56
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +35 -0
- package/dist/index.test.js.map +1 -1
- package/dist/logger.d.ts +12 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +57 -0
- package/dist/logger.js.map +1 -0
- package/dist/secrets.d.ts +13 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +86 -0
- package/dist/secrets.js.map +1 -0
- package/dist/secrets.test.d.ts +2 -0
- package/dist/secrets.test.d.ts.map +1 -0
- package/dist/secrets.test.js +107 -0
- package/dist/secrets.test.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type Logger } from './logger.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a provider's configuration before the HTTP server starts, whichever
|
|
4
|
+
* runtime the provider is running on.
|
|
5
|
+
*
|
|
6
|
+
* - **ECS** injects the values as environment variables through the task
|
|
7
|
+
* definition's `secrets` block. The task agent resolves the Secrets Manager
|
|
8
|
+
* reference at task start, so the value never lands in Terraform state or in
|
|
9
|
+
* the service definition. This module finds them already in `process.env`.
|
|
10
|
+
* - **Lambda** has no equivalent injection, so the image carries the AWS
|
|
11
|
+
* Parameters and Secrets Lambda Extension. It serves the secret as JSON over
|
|
12
|
+
* `http://localhost:2773` and caches it (five minutes by default). This module
|
|
13
|
+
* reads it from there and merges the keys into `process.env`.
|
|
14
|
+
*
|
|
15
|
+
* A provider therefore makes one call — `await loadConfiguration({ required })`
|
|
16
|
+
* — and does not know which runtime it is on. `SECRETS_MANAGER_SECRET_ID` names
|
|
17
|
+
* the secret to read on Lambda; it is not a secret value and may live in the
|
|
18
|
+
* function configuration.
|
|
19
|
+
*
|
|
20
|
+
* Missing values fail closed: if a required key is absent after resolution (or
|
|
21
|
+
* the secret cannot be read or parsed) startup throws, naming the key but never
|
|
22
|
+
* the value.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Names the Secrets Manager secret holding the provider's secret-shaped
|
|
26
|
+
* configuration, as a flat JSON object of string key/value pairs. Unset locally,
|
|
27
|
+
* and set on Lambda in the function configuration. On ECS the values are injected
|
|
28
|
+
* directly and this variable carries no meaning, so it may be left unset.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SECRET_ID_VAR = "SECRETS_MANAGER_SECRET_ID";
|
|
31
|
+
/** Set by the Lambda runtime. Its presence is how the SDK tells Lambda from ECS. */
|
|
32
|
+
export declare const LAMBDA_FUNCTION_NAME_VAR = "AWS_LAMBDA_FUNCTION_NAME";
|
|
33
|
+
/**
|
|
34
|
+
* The token the extension requires on every request. The Lambda runtime sets it
|
|
35
|
+
* in the execution environment; it authenticates the caller as this function and
|
|
36
|
+
* is never the secret value itself.
|
|
37
|
+
*/
|
|
38
|
+
export declare const EXTENSION_TOKEN_VAR = "AWS_SESSION_TOKEN";
|
|
39
|
+
/** Port of the extension's local HTTP server. Defaults in the extension to 2773. */
|
|
40
|
+
export declare const EXTENSION_PORT_VAR = "PARAMETERS_SECRETS_EXTENSION_HTTP_PORT";
|
|
41
|
+
export declare const DEFAULT_EXTENSION_PORT = 2773;
|
|
42
|
+
/**
|
|
43
|
+
* A configuration requirement. A bare string names one required key; an array
|
|
44
|
+
* names alternatives, and the requirement is met when any one of them is
|
|
45
|
+
* present (`['AIRTABLE_CLIENT_SECRET', 'AIRTABLE_PKCE_SECRET']`).
|
|
46
|
+
*/
|
|
47
|
+
export type ConfigurationRequirement = string | readonly string[];
|
|
48
|
+
export interface LoadConfigurationOptions {
|
|
49
|
+
/**
|
|
50
|
+
* The keys the provider cannot run without. Anything absent after resolution
|
|
51
|
+
* aborts startup. Each entry is one key, or a set of alternatives.
|
|
52
|
+
*/
|
|
53
|
+
required?: readonly ConfigurationRequirement[];
|
|
54
|
+
/**
|
|
55
|
+
* The secret to read on Lambda. Defaults to `SECRETS_MANAGER_SECRET_ID`.
|
|
56
|
+
* Exposed for tests and for a provider that reads more than one secret.
|
|
57
|
+
*/
|
|
58
|
+
secretId?: string;
|
|
59
|
+
/** Overrides the default logger. */
|
|
60
|
+
logger?: Logger;
|
|
61
|
+
/** The number of times to try the extension before giving up. Defaults to 5. */
|
|
62
|
+
attempts?: number;
|
|
63
|
+
/** Delay between extension attempts, in milliseconds. Defaults to 200. */
|
|
64
|
+
retryDelayMs?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Reads the raw `SecretString` for a secret id from the extension. Injectable
|
|
67
|
+
* so the tests exercise the resolution logic with no network and no Lambda.
|
|
68
|
+
*/
|
|
69
|
+
fetchSecret?: (secretId: string) => Promise<string>;
|
|
70
|
+
}
|
|
71
|
+
/** Reads the raw `SecretString` for a secret id from somewhere. */
|
|
72
|
+
export type SecretFetcher = (secretId: string) => Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Reads a secret from the extension, retrying the retryable failures. The
|
|
75
|
+
* extension only reports ready after the runtime bootstraps, so the first read
|
|
76
|
+
* after a cold start can race it.
|
|
77
|
+
*/
|
|
78
|
+
export declare const readSecretFromExtension: (secretId: string, { attempts, retryDelayMs }?: {
|
|
79
|
+
attempts?: number;
|
|
80
|
+
retryDelayMs?: number;
|
|
81
|
+
}) => Promise<string>;
|
|
82
|
+
/** Reads the raw `SecretString` for a secret id from the extension. */
|
|
83
|
+
export declare const fetchSecretFromExtension: SecretFetcher;
|
|
84
|
+
/**
|
|
85
|
+
* Parses the secret payload into key/value pairs, rejecting anything that is not
|
|
86
|
+
* a flat JSON object of strings. Error messages describe the shape problem only —
|
|
87
|
+
* they never quote the payload, which would put secret material into logs and
|
|
88
|
+
* stack traces.
|
|
89
|
+
*/
|
|
90
|
+
export declare const parseSecretPayload: (raw: string) => Record<string, string>;
|
|
91
|
+
/**
|
|
92
|
+
* Merges resolved values into the environment. Secrets Manager is authoritative:
|
|
93
|
+
* a stale value left behind in the task definition must never win over the
|
|
94
|
+
* managed one, so this overwrites rather than filling in gaps.
|
|
95
|
+
*/
|
|
96
|
+
export declare const applyConfiguration: (values: Record<string, string>, env?: NodeJS.ProcessEnv) => void;
|
|
97
|
+
/**
|
|
98
|
+
* The requirements still unmet, each named by its alternatives ("A or B").
|
|
99
|
+
* Names only — never values.
|
|
100
|
+
*/
|
|
101
|
+
export declare const findMissingConfiguration: (required: readonly ConfigurationRequirement[], env?: NodeJS.ProcessEnv) => string[];
|
|
102
|
+
/** True when the process is running as a Lambda function. */
|
|
103
|
+
export declare const isLambda: (env?: NodeJS.ProcessEnv) => boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Resolves the provider's configuration and fails closed when it is incomplete.
|
|
106
|
+
*
|
|
107
|
+
* On Lambda the secret named by `SECRETS_MANAGER_SECRET_ID` is read through the
|
|
108
|
+
* extension and merged into `process.env`, so every provider continues to read
|
|
109
|
+
* its settings from the environment. On ECS the values are already injected
|
|
110
|
+
* there. Either way a missing required key throws, naming the key but never the
|
|
111
|
+
* value.
|
|
112
|
+
*/
|
|
113
|
+
export declare const loadConfiguration: (options?: LoadConfigurationOptions) => Promise<void>;
|
|
114
|
+
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAuB,MAAM,aAAa,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aA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AE,MAAM,CAAC,QAAO,MAAM,CAAC,UAAU,KAAiB,IAIzG,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,aAC1B,SAAS,wBAAwB,EAAE,QACxC,MAAM,CAAC,UAAU,KACpB,MAAM,EAOR,CAAC;AAEF,6DAA6D;AAC7D,eAAO,MAAM,QAAQ,SAAS,MAAM,CAAC,UAAU,KAAiB,OACR,CAAC;AAEzD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,aAAmB,wBAAwB,KAAQ,OAAO,CAAC,IAAI,CAwC5F,CAAC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { logger as sdkLogger } from './logger.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a provider's configuration before the HTTP server starts, whichever
|
|
4
|
+
* runtime the provider is running on.
|
|
5
|
+
*
|
|
6
|
+
* - **ECS** injects the values as environment variables through the task
|
|
7
|
+
* definition's `secrets` block. The task agent resolves the Secrets Manager
|
|
8
|
+
* reference at task start, so the value never lands in Terraform state or in
|
|
9
|
+
* the service definition. This module finds them already in `process.env`.
|
|
10
|
+
* - **Lambda** has no equivalent injection, so the image carries the AWS
|
|
11
|
+
* Parameters and Secrets Lambda Extension. It serves the secret as JSON over
|
|
12
|
+
* `http://localhost:2773` and caches it (five minutes by default). This module
|
|
13
|
+
* reads it from there and merges the keys into `process.env`.
|
|
14
|
+
*
|
|
15
|
+
* A provider therefore makes one call — `await loadConfiguration({ required })`
|
|
16
|
+
* — and does not know which runtime it is on. `SECRETS_MANAGER_SECRET_ID` names
|
|
17
|
+
* the secret to read on Lambda; it is not a secret value and may live in the
|
|
18
|
+
* function configuration.
|
|
19
|
+
*
|
|
20
|
+
* Missing values fail closed: if a required key is absent after resolution (or
|
|
21
|
+
* the secret cannot be read or parsed) startup throws, naming the key but never
|
|
22
|
+
* the value.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Names the Secrets Manager secret holding the provider's secret-shaped
|
|
26
|
+
* configuration, as a flat JSON object of string key/value pairs. Unset locally,
|
|
27
|
+
* and set on Lambda in the function configuration. On ECS the values are injected
|
|
28
|
+
* directly and this variable carries no meaning, so it may be left unset.
|
|
29
|
+
*/
|
|
30
|
+
export const SECRET_ID_VAR = 'SECRETS_MANAGER_SECRET_ID';
|
|
31
|
+
/** Set by the Lambda runtime. Its presence is how the SDK tells Lambda from ECS. */
|
|
32
|
+
export const LAMBDA_FUNCTION_NAME_VAR = 'AWS_LAMBDA_FUNCTION_NAME';
|
|
33
|
+
/**
|
|
34
|
+
* The token the extension requires on every request. The Lambda runtime sets it
|
|
35
|
+
* in the execution environment; it authenticates the caller as this function and
|
|
36
|
+
* is never the secret value itself.
|
|
37
|
+
*/
|
|
38
|
+
export const EXTENSION_TOKEN_VAR = 'AWS_SESSION_TOKEN';
|
|
39
|
+
/** Port of the extension's local HTTP server. Defaults in the extension to 2773. */
|
|
40
|
+
export const EXTENSION_PORT_VAR = 'PARAMETERS_SECRETS_EXTENSION_HTTP_PORT';
|
|
41
|
+
export const DEFAULT_EXTENSION_PORT = 2773;
|
|
42
|
+
/**
|
|
43
|
+
* Raised when the extension is reachable but not yet serving — the connection
|
|
44
|
+
* was refused, or it answered as unavailable. Retried; every other failure is
|
|
45
|
+
* terminal.
|
|
46
|
+
*/
|
|
47
|
+
class ExtensionUnavailableError extends Error {
|
|
48
|
+
}
|
|
49
|
+
const isRetryableStatus = (status) => status === 429 || status >= 500;
|
|
50
|
+
/**
|
|
51
|
+
* One round trip to the extension. Distinguishes "not ready yet" (retryable)
|
|
52
|
+
* from "this request will never succeed" (terminal), and never quotes the
|
|
53
|
+
* secret or the token in a message.
|
|
54
|
+
*/
|
|
55
|
+
const readSecretOnce = async (secretId, token, port) => {
|
|
56
|
+
const url = `http://localhost:${port}/secretsmanager/get?secretId=${encodeURIComponent(secretId)}`;
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await fetch(url, {
|
|
60
|
+
headers: { 'X-Aws-Parameters-Secrets-Token': token },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
65
|
+
throw new ExtensionUnavailableError(`the extension is not reachable yet: ${reason}`);
|
|
66
|
+
}
|
|
67
|
+
if (isRetryableStatus(response.status)) {
|
|
68
|
+
throw new ExtensionUnavailableError(`the extension answered HTTP ${response.status}`);
|
|
69
|
+
}
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new Error(`the extension rejected the request for secret "${secretId}" with HTTP ${response.status}`);
|
|
72
|
+
}
|
|
73
|
+
let body;
|
|
74
|
+
try {
|
|
75
|
+
body = await response.json();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new Error('the extension returned a response that is not JSON');
|
|
79
|
+
}
|
|
80
|
+
if (typeof body !== 'object' ||
|
|
81
|
+
body === null ||
|
|
82
|
+
!('SecretString' in body) ||
|
|
83
|
+
typeof body.SecretString !== 'string') {
|
|
84
|
+
throw new Error('the secret has no SecretString value (binary secrets are not supported)');
|
|
85
|
+
}
|
|
86
|
+
return body.SecretString;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Reads a secret from the extension, retrying the retryable failures. The
|
|
90
|
+
* extension only reports ready after the runtime bootstraps, so the first read
|
|
91
|
+
* after a cold start can race it.
|
|
92
|
+
*/
|
|
93
|
+
export const readSecretFromExtension = async (secretId, { attempts = 5, retryDelayMs = 200 } = {}) => {
|
|
94
|
+
const token = process.env[EXTENSION_TOKEN_VAR];
|
|
95
|
+
if (!token || token.trim().length === 0) {
|
|
96
|
+
throw new Error(`${EXTENSION_TOKEN_VAR} is not set, so the AWS Parameters and Secrets Lambda Extension cannot be authenticated. It is set by the Lambda runtime and must not be configured by hand.`);
|
|
97
|
+
}
|
|
98
|
+
const port = Number(process.env[EXTENSION_PORT_VAR]) || DEFAULT_EXTENSION_PORT;
|
|
99
|
+
let lastError;
|
|
100
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
101
|
+
try {
|
|
102
|
+
return await readSecretOnce(secretId, token, port);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (!(error instanceof ExtensionUnavailableError) || attempt === attempts) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
lastError = error;
|
|
109
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs * attempt));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Unreachable: the loop either returns or throws. Kept for the type checker.
|
|
113
|
+
throw lastError instanceof Error ? lastError : new Error('the extension could not be read');
|
|
114
|
+
};
|
|
115
|
+
/** Reads the raw `SecretString` for a secret id from the extension. */
|
|
116
|
+
export const fetchSecretFromExtension = (secretId) => readSecretFromExtension(secretId);
|
|
117
|
+
/**
|
|
118
|
+
* Parses the secret payload into key/value pairs, rejecting anything that is not
|
|
119
|
+
* a flat JSON object of strings. Error messages describe the shape problem only —
|
|
120
|
+
* they never quote the payload, which would put secret material into logs and
|
|
121
|
+
* stack traces.
|
|
122
|
+
*/
|
|
123
|
+
export const parseSecretPayload = (raw) => {
|
|
124
|
+
let parsed;
|
|
125
|
+
try {
|
|
126
|
+
parsed = JSON.parse(raw);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
throw new Error('the secret is not valid JSON (expected a flat object, e.g. {"DATABASE_URL": "..."})');
|
|
130
|
+
}
|
|
131
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
132
|
+
throw new Error('the secret must be a flat JSON object of string key/value pairs');
|
|
133
|
+
}
|
|
134
|
+
const values = {};
|
|
135
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
136
|
+
if (typeof value !== 'string') {
|
|
137
|
+
throw new Error(`the secret value for "${key}" must be a string`);
|
|
138
|
+
}
|
|
139
|
+
values[key] = value;
|
|
140
|
+
}
|
|
141
|
+
return values;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Merges resolved values into the environment. Secrets Manager is authoritative:
|
|
145
|
+
* a stale value left behind in the task definition must never win over the
|
|
146
|
+
* managed one, so this overwrites rather than filling in gaps.
|
|
147
|
+
*/
|
|
148
|
+
export const applyConfiguration = (values, env = process.env) => {
|
|
149
|
+
for (const [key, value] of Object.entries(values)) {
|
|
150
|
+
env[key] = value;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const isPresent = (key, env) => (env[key] ?? '').trim().length > 0;
|
|
154
|
+
/**
|
|
155
|
+
* The requirements still unmet, each named by its alternatives ("A or B").
|
|
156
|
+
* Names only — never values.
|
|
157
|
+
*/
|
|
158
|
+
export const findMissingConfiguration = (required, env = process.env) => {
|
|
159
|
+
const alternativesOf = (requirement) => typeof requirement === 'string' ? [requirement] : requirement;
|
|
160
|
+
return required
|
|
161
|
+
.filter((requirement) => !alternativesOf(requirement).some((key) => isPresent(key, env)))
|
|
162
|
+
.map((requirement) => alternativesOf(requirement).join(' or '));
|
|
163
|
+
};
|
|
164
|
+
/** True when the process is running as a Lambda function. */
|
|
165
|
+
export const isLambda = (env = process.env) => (env[LAMBDA_FUNCTION_NAME_VAR] ?? '').trim().length > 0;
|
|
166
|
+
/**
|
|
167
|
+
* Resolves the provider's configuration and fails closed when it is incomplete.
|
|
168
|
+
*
|
|
169
|
+
* On Lambda the secret named by `SECRETS_MANAGER_SECRET_ID` is read through the
|
|
170
|
+
* extension and merged into `process.env`, so every provider continues to read
|
|
171
|
+
* its settings from the environment. On ECS the values are already injected
|
|
172
|
+
* there. Either way a missing required key throws, naming the key but never the
|
|
173
|
+
* value.
|
|
174
|
+
*/
|
|
175
|
+
export const loadConfiguration = async (options = {}) => {
|
|
176
|
+
const log = options.logger ?? sdkLogger;
|
|
177
|
+
const secretId = (options.secretId ?? process.env[SECRET_ID_VAR])?.trim();
|
|
178
|
+
if (secretId && isLambda()) {
|
|
179
|
+
log.info({ secretId }, 'Reading provider configuration from the AWS Parameters and Secrets Lambda Extension');
|
|
180
|
+
let raw;
|
|
181
|
+
try {
|
|
182
|
+
raw = await (options.fetchSecret
|
|
183
|
+
? options.fetchSecret(secretId)
|
|
184
|
+
: readSecretFromExtension(secretId, {
|
|
185
|
+
attempts: options.attempts,
|
|
186
|
+
retryDelayMs: options.retryDelayMs,
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
191
|
+
throw new Error(`Unable to read configuration from secret "${secretId}": ${reason}`);
|
|
192
|
+
}
|
|
193
|
+
let values;
|
|
194
|
+
try {
|
|
195
|
+
values = parseSecretPayload(raw);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
199
|
+
throw new Error(`The secret "${secretId}" could not be used: ${reason}`);
|
|
200
|
+
}
|
|
201
|
+
applyConfiguration(values);
|
|
202
|
+
// Key names only — never values.
|
|
203
|
+
log.info({ keys: Object.keys(values).sort(), secretId }, 'Loaded provider configuration');
|
|
204
|
+
}
|
|
205
|
+
const missing = findMissingConfiguration(options.required ?? []);
|
|
206
|
+
if (missing.length > 0) {
|
|
207
|
+
throw new Error(`The provider configuration is incomplete; missing: ${missing.join(', ')}. Supply these values in the environment, or on Lambda via the secret named by ${SECRET_ID_VAR}.`);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAEzD,oFAAoF;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE;;;;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CAAC;YAChB,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,eAAe,QAAQ,wBAAwB,MAAM,EAAE,CAAC,CAAC;QAC1E,CAAC;QAED,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAE3B,iCAAiC;QACjC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,+BAA+B,CAAC,CAAC;IAC3F,CAAC;IAED,MAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACjE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACd,sDAAsD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,kFAAkF,aAAa,GAAG,CAC1K,CAAC;IACH,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.test.d.ts","sourceRoot":"","sources":["../src/configuration.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { EXTENSION_PORT_VAR, EXTENSION_TOKEN_VAR, LAMBDA_FUNCTION_NAME_VAR, SECRET_ID_VAR, applyConfiguration, findMissingConfiguration, isLambda, loadConfiguration, parseSecretPayload, } from './configuration.js';
|
|
3
|
+
/** A logger that swallows output so the assertions read the behaviour, not the logs. */
|
|
4
|
+
const silentLogger = {
|
|
5
|
+
info: () => { },
|
|
6
|
+
warn: () => { },
|
|
7
|
+
error: () => { },
|
|
8
|
+
debug: () => { },
|
|
9
|
+
trace: () => { },
|
|
10
|
+
fatal: () => { },
|
|
11
|
+
};
|
|
12
|
+
const SECRET_ID = 'bigfoot-example/dev';
|
|
13
|
+
const TOKEN = 'session-token-value';
|
|
14
|
+
/** Environment keys this suite touches, cleared before and after every test. */
|
|
15
|
+
const MANAGED_VARS = [
|
|
16
|
+
SECRET_ID_VAR,
|
|
17
|
+
LAMBDA_FUNCTION_NAME_VAR,
|
|
18
|
+
EXTENSION_TOKEN_VAR,
|
|
19
|
+
EXTENSION_PORT_VAR,
|
|
20
|
+
'BIGFOOT_API_KEY',
|
|
21
|
+
'DATABASE_URL',
|
|
22
|
+
'CLIENT_SECRET',
|
|
23
|
+
'EXTRA',
|
|
24
|
+
'PRESENT',
|
|
25
|
+
'OTHER',
|
|
26
|
+
];
|
|
27
|
+
const clearEnv = () => {
|
|
28
|
+
for (const name of MANAGED_VARS) {
|
|
29
|
+
delete process.env[name];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const asLambda = () => {
|
|
33
|
+
process.env[LAMBDA_FUNCTION_NAME_VAR] = 'bigfoot-example';
|
|
34
|
+
process.env[SECRET_ID_VAR] = SECRET_ID;
|
|
35
|
+
process.env[EXTENSION_TOKEN_VAR] = TOKEN;
|
|
36
|
+
};
|
|
37
|
+
const jsonResponse = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } });
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
clearEnv();
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
clearEnv();
|
|
43
|
+
vi.unstubAllGlobals();
|
|
44
|
+
vi.restoreAllMocks();
|
|
45
|
+
});
|
|
46
|
+
describe('parseSecretPayload', () => {
|
|
47
|
+
it('parses a flat JSON object of string values', () => {
|
|
48
|
+
expect(parseSecretPayload('{"BIGFOOT_API_KEY": "abc", "DATABASE_URL": "postgres://x"}')).toEqual({
|
|
49
|
+
BIGFOOT_API_KEY: 'abc',
|
|
50
|
+
DATABASE_URL: 'postgres://x',
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('rejects a payload that is not JSON without quoting it', () => {
|
|
54
|
+
expect(() => parseSecretPayload('super-secret-not-json')).toThrow(/not valid JSON/);
|
|
55
|
+
try {
|
|
56
|
+
parseSecretPayload('super-secret-not-json');
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
expect(error.message).not.toContain('super-secret-not-json');
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
it('rejects a JSON array or a nested object', () => {
|
|
63
|
+
expect(() => parseSecretPayload('["a"]')).toThrow(/flat JSON object/);
|
|
64
|
+
expect(() => parseSecretPayload('null')).toThrow(/flat JSON object/);
|
|
65
|
+
});
|
|
66
|
+
it('rejects a non-string value and names the offending key', () => {
|
|
67
|
+
expect(() => parseSecretPayload('{"PORT": 5000}')).toThrow(/"PORT" must be a string/);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('findMissingConfiguration', () => {
|
|
71
|
+
it('treats a bare key as required', () => {
|
|
72
|
+
expect(findMissingConfiguration(['BIGFOOT_API_KEY'], {})).toEqual(['BIGFOOT_API_KEY']);
|
|
73
|
+
});
|
|
74
|
+
it('treats blank and whitespace-only values as missing', () => {
|
|
75
|
+
expect(findMissingConfiguration(['A'], { A: ' ' })).toEqual(['A']);
|
|
76
|
+
expect(findMissingConfiguration(['A'], { A: 'value' })).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
it('is satisfied when any alternative is present, and names them when none is', () => {
|
|
79
|
+
expect(findMissingConfiguration([['CLIENT_SECRET', 'PKCE_SECRET']], { PKCE_SECRET: 'x' })).toEqual([]);
|
|
80
|
+
expect(findMissingConfiguration([['CLIENT_SECRET', 'PKCE_SECRET']], {})).toEqual(['CLIENT_SECRET or PKCE_SECRET']);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('isLambda', () => {
|
|
84
|
+
it('is true only when the runtime sets its function name', () => {
|
|
85
|
+
expect(isLambda({})).toBe(false);
|
|
86
|
+
expect(isLambda({ [LAMBDA_FUNCTION_NAME_VAR]: 'bigfoot-example' })).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('applyConfiguration', () => {
|
|
90
|
+
it('overwrites existing values, because the managed secret is authoritative', () => {
|
|
91
|
+
const env = { DATABASE_URL: 'stale' };
|
|
92
|
+
applyConfiguration({ DATABASE_URL: 'fresh' }, env);
|
|
93
|
+
expect(env.DATABASE_URL).toBe('fresh');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('loadConfiguration on ECS', () => {
|
|
97
|
+
it('reads values already injected into the environment and does not call the extension', async () => {
|
|
98
|
+
const fetchMock = vi.fn();
|
|
99
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
100
|
+
process.env.BIGFOOT_API_KEY = 'from-the-task-definition';
|
|
101
|
+
await loadConfiguration({ required: ['BIGFOOT_API_KEY'], logger: silentLogger });
|
|
102
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
it('fails closed when a required key is missing, naming the key but not a value', async () => {
|
|
105
|
+
process.env.CLIENT_SECRET = 'a-value-that-must-not-be-named';
|
|
106
|
+
const error = await loadConfiguration({
|
|
107
|
+
required: ['BIGFOOT_API_KEY', 'CLIENT_SECRET'],
|
|
108
|
+
logger: silentLogger,
|
|
109
|
+
}).catch((e) => e);
|
|
110
|
+
expect(error).toBeInstanceOf(Error);
|
|
111
|
+
expect(error.message).toContain('BIGFOOT_API_KEY');
|
|
112
|
+
expect(error.message).not.toContain('CLIENT_SECRET');
|
|
113
|
+
expect(error.message).not.toContain('a-value-that-must-not-be-named');
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('loadConfiguration on Lambda', () => {
|
|
117
|
+
it('reads the secret from the extension, authenticates with the runtime token, and merges every key', async () => {
|
|
118
|
+
asLambda();
|
|
119
|
+
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({
|
|
120
|
+
SecretString: JSON.stringify({ BIGFOOT_API_KEY: 'platform-key', EXTRA: 'also-merged' }),
|
|
121
|
+
}));
|
|
122
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
123
|
+
await loadConfiguration({ required: ['BIGFOOT_API_KEY'], logger: silentLogger });
|
|
124
|
+
expect(process.env.BIGFOOT_API_KEY).toBe('platform-key');
|
|
125
|
+
expect(process.env.EXTRA).toBe('also-merged');
|
|
126
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
127
|
+
expect(url).toBe(`http://localhost:2773/secretsmanager/get?secretId=${encodeURIComponent(SECRET_ID)}`);
|
|
128
|
+
expect(init.headers['X-Aws-Parameters-Secrets-Token']).toBe(TOKEN);
|
|
129
|
+
});
|
|
130
|
+
it('honours a custom extension port', async () => {
|
|
131
|
+
asLambda();
|
|
132
|
+
process.env[EXTENSION_PORT_VAR] = '9999';
|
|
133
|
+
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ SecretString: '{}' }));
|
|
134
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
135
|
+
await loadConfiguration({ required: [], logger: silentLogger });
|
|
136
|
+
expect(fetchMock.mock.calls[0][0]).toContain('http://localhost:9999/');
|
|
137
|
+
});
|
|
138
|
+
it('retries while the extension is not yet serving, then succeeds', async () => {
|
|
139
|
+
asLambda();
|
|
140
|
+
const fetchMock = vi
|
|
141
|
+
.fn()
|
|
142
|
+
.mockRejectedValueOnce(new Error('connect ECONNREFUSED'))
|
|
143
|
+
.mockRejectedValueOnce(new Error('connect ECONNREFUSED'))
|
|
144
|
+
.mockResolvedValue(jsonResponse({ SecretString: JSON.stringify({ BIGFOOT_API_KEY: 'platform-key' }) }));
|
|
145
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
146
|
+
await loadConfiguration({ required: ['BIGFOOT_API_KEY'], retryDelayMs: 0, logger: silentLogger });
|
|
147
|
+
expect(fetchMock).toHaveBeenCalledTimes(3);
|
|
148
|
+
expect(process.env.BIGFOOT_API_KEY).toBe('platform-key');
|
|
149
|
+
});
|
|
150
|
+
it('does not retry a request the extension rejected', async () => {
|
|
151
|
+
asLambda();
|
|
152
|
+
const fetchMock = vi.fn().mockResolvedValue(new Response('not found', { status: 404 }));
|
|
153
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
154
|
+
await expect(loadConfiguration({ required: [], retryDelayMs: 0, logger: silentLogger })).rejects.toThrow(/HTTP 404/);
|
|
155
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
156
|
+
});
|
|
157
|
+
it('fails when the secret carries no SecretString', async () => {
|
|
158
|
+
asLambda();
|
|
159
|
+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({ SecretBinary: 'AAAA' })));
|
|
160
|
+
await expect(loadConfiguration({ required: [], retryDelayMs: 0, logger: silentLogger })).rejects.toThrow(/SecretString/);
|
|
161
|
+
});
|
|
162
|
+
it('fails closed when a required key is absent from the secret, naming the key but not a value', async () => {
|
|
163
|
+
asLambda();
|
|
164
|
+
vi.stubGlobal('fetch', vi
|
|
165
|
+
.fn()
|
|
166
|
+
.mockResolvedValue(jsonResponse({ SecretString: JSON.stringify({ PRESENT: 'a-value-that-must-not-be-named' }) })));
|
|
167
|
+
const error = await loadConfiguration({ required: ['BIGFOOT_API_KEY'], logger: silentLogger }).catch((e) => e);
|
|
168
|
+
expect(error.message).toContain('BIGFOOT_API_KEY');
|
|
169
|
+
expect(error.message).not.toContain('a-value-that-must-not-be-named');
|
|
170
|
+
});
|
|
171
|
+
it('accepts an injected fetcher, so the logic needs no Lambda and no network', async () => {
|
|
172
|
+
asLambda();
|
|
173
|
+
const fetchSecret = vi.fn().mockResolvedValue(JSON.stringify({ BIGFOOT_API_KEY: 'injected' }));
|
|
174
|
+
await loadConfiguration({ required: ['BIGFOOT_API_KEY'], fetchSecret, logger: silentLogger });
|
|
175
|
+
expect(fetchSecret).toHaveBeenCalledWith(SECRET_ID);
|
|
176
|
+
expect(process.env.BIGFOOT_API_KEY).toBe('injected');
|
|
177
|
+
});
|
|
178
|
+
it('does not attempt the extension when the process is not on Lambda', async () => {
|
|
179
|
+
process.env[SECRET_ID_VAR] = SECRET_ID;
|
|
180
|
+
const fetchMock = vi.fn();
|
|
181
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
182
|
+
process.env.BIGFOOT_API_KEY = 'from-the-environment';
|
|
183
|
+
await loadConfiguration({ required: ['BIGFOOT_API_KEY'], logger: silentLogger });
|
|
184
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
//# sourceMappingURL=configuration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.test.js","sourceRoot":"","sources":["../src/configuration.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EACN,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,wBAAwB,EACxB,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,GAClB,MAAM,oBAAoB,CAAC;AAG5B,wFAAwF;AACxF,MAAM,YAAY,GAAG;IACpB,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;CACM,CAAC;AAEvB,MAAM,SAAS,GAAG,qBAAqB,CAAC;AACxC,MAAM,KAAK,GAAG,qBAAqB,CAAC;AAEpC,gFAAgF;AAChF,MAAM,YAAY,GAAG;IACpB,aAAa;IACb,wBAAwB;IACxB,mBAAmB;IACnB,kBAAkB;IAClB,iBAAiB;IACjB,cAA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B,EAAE,CAAC;IAC1C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { type AuthCheckResult, type AuthRefreshProviderResponse, type Calendar, type CommentFilter, type ConnectedProvider, type ConnectedProviderRegistration, type Credential, type Email, type EmailFilter, type ExecuteFunctionProviderRequest, type ExecuteFunctionProviderResponse, type ExecuteQueryProviderRequest, type ExecuteQueryProviderResponse, type ExternalNote, type ExternalObjectWithUrl, type ExternalTagReferenceRequest, type InsightFilter, type LinkSubscriptionProviderRequest, type LinkSubscriptionProviderResponse, type ListFunctionMetadataProviderRequest, type ListFunctionMetadataProviderResponse, type Message, type ResolveFunctionInputsProviderRequest, type ResolveFunctionInputsProviderResponse, type StandardSyncResponse, type SyncCalendarProviderRequest, type SyncCommentItem, type SyncExternalIdLinksProviderRequest, type SyncInsightProviderRequest, type SyncTableMetadataProviderRequest, type SyncTableProviderRequest, type SyncThreadItem, type Table, type Tag, type TagInsightResponse, type TagType, type ThreadFilter, type Transcription, type TranscriptionFilter, type UpsertMessageProviderRequest, type UpsertNotesProviderRequest, type UpsertTableProviderRequest } from '@bigfootai/bigfoot-types';
|
|
2
2
|
import { type Express } from 'express';
|
|
3
3
|
import { CredentialsExpiredError, ValidationError } from './errors.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* shapes actually logged (`{ credential }`, `{ connectedProvider: { credential } }`,
|
|
8
|
-
* `{ req: { headers } }`). The whole `credential` object is redacted rather
|
|
9
|
-
* than its individual fields, so a credential shape that gains a new token
|
|
10
|
-
* field later is still covered.
|
|
11
|
-
*/
|
|
12
|
-
export declare const LOG_REDACT_PATHS: string[];
|
|
13
|
-
export declare const logger: import("pino").Logger<never, boolean>;
|
|
14
|
-
export type Logger = typeof logger;
|
|
4
|
+
import { type Logger } from './logger.js';
|
|
5
|
+
export { LOG_REDACT_PATHS, logger } from './logger.js';
|
|
6
|
+
export type { Logger } from './logger.js';
|
|
15
7
|
/**
|
|
16
8
|
* Drops the query string from a request URL. Used for logging: the OAuth
|
|
17
9
|
* callback carries the authorization code and state there.
|
|
@@ -328,9 +320,13 @@ interface FunctionMethods {
|
|
|
328
320
|
}
|
|
329
321
|
interface QueryMethods {
|
|
330
322
|
/**
|
|
331
|
-
* Execute a query against the provider. The platform
|
|
332
|
-
*
|
|
333
|
-
* records.
|
|
323
|
+
* Execute a query against the provider. The platform supplies search criteria, a return-field list, a page size
|
|
324
|
+
* (`limit`), and, after the first page, the `cursor` from the previous response. The provider performs the
|
|
325
|
+
* vendor-specific search and returns one page of matching records.
|
|
326
|
+
*
|
|
327
|
+
* Paging follows the sync rules: return `pagination: { hasMore, cursor, pageSize }`, include `cursor` only when
|
|
328
|
+
* `hasMore` is true, and keep the cursor opaque. The platform stops when `hasMore` is false or the cursor does not
|
|
329
|
+
* change. When the vendor search has a total cap, page up to the cap and then return `hasMore: false`.
|
|
334
330
|
*
|
|
335
331
|
* `request.connectedProvider` carries the executor's credentials;
|
|
336
332
|
* `request.templateConnectedProvider` carries the installer's credentials (useful when the query template was set
|
|
@@ -362,5 +358,7 @@ export declare function startServer(options: StartServerOptions): Promise<Expres
|
|
|
362
358
|
export { CredentialsExpiredError, ValidationError };
|
|
363
359
|
export { decodeAuthState, encodeAuthState } from './auth-state.js';
|
|
364
360
|
export type { AuthStatePayload, DecodedAuthState, EncodeAuthStateOptions } from './auth-state.js';
|
|
361
|
+
export { SECRET_ID_VAR, loadSecrets } from './secrets.js';
|
|
362
|
+
export type { LoadSecretsOptions } from './secrets.js';
|
|
365
363
|
export declare const sendCredentialsToBigfoot: (providerRegistration: ConnectedProviderRegistration) => Promise<void>;
|
|
366
364
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EA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