@nymbalhq/config 1.5.0 → 1.6.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/index.d.ts +421 -2485
- package/dist/index.js +331 -32
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -58,9 +58,9 @@ var ADAPTER_CATALOGUE = {
|
|
|
58
58
|
reviews: { native: builtIn },
|
|
59
59
|
search: { native: builtIn, algolia: {} },
|
|
60
60
|
analytics: { native: builtIn },
|
|
61
|
-
shipping: { native: builtIn, easypost: {} },
|
|
61
|
+
shipping: { native: builtIn, aftership: {}, easypost: {} },
|
|
62
62
|
tax: { native: builtIn },
|
|
63
|
-
ai: { none: builtIn, anthropic: { sdk: "@anthropic-ai/sdk" } },
|
|
63
|
+
ai: { none: builtIn, anthropic: { sdk: "@anthropic-ai/sdk" }, openai: {} },
|
|
64
64
|
documentStore: {
|
|
65
65
|
"in-memory": builtIn,
|
|
66
66
|
redis: { sdk: "ioredis" },
|
|
@@ -137,10 +137,143 @@ import { dirname, isAbsolute, resolve } from "path";
|
|
|
137
137
|
import { pathToFileURL } from "url";
|
|
138
138
|
import { createJiti } from "jiti";
|
|
139
139
|
import { z as z2 } from "zod";
|
|
140
|
-
import { ConfigError as
|
|
140
|
+
import { ConfigError as ConfigError3 } from "@nymbalhq/types";
|
|
141
141
|
|
|
142
142
|
// src/schema.ts
|
|
143
143
|
import { z } from "zod";
|
|
144
|
+
|
|
145
|
+
// src/trusted-proxies.ts
|
|
146
|
+
import { isIP } from "net";
|
|
147
|
+
import proxyAddr from "@fastify/proxy-addr";
|
|
148
|
+
import {
|
|
149
|
+
ConfigError as ConfigError2
|
|
150
|
+
} from "@nymbalhq/types";
|
|
151
|
+
var TRUSTED_PROXIES_ENV = "NYMBAL_TRUSTED_PROXIES";
|
|
152
|
+
var CLIENT_IP_HEADER_ENV = "NYMBAL_CLIENT_IP_HEADER";
|
|
153
|
+
var REMOVED_HOPS_ENV = "NYMBAL_TRUST_PROXY_HOPS";
|
|
154
|
+
var LIST_KEY = "http.trustedProxies";
|
|
155
|
+
var HEADER_KEY = "http.clientIpHeader";
|
|
156
|
+
var DEFAULT_LIST = ["loopback"];
|
|
157
|
+
var PRESETS = ["loopback", "linklocal", "uniquelocal"];
|
|
158
|
+
var PRESET_MATCHERS = PRESETS.map((preset) => [preset, proxyAddr.compile(preset)]);
|
|
159
|
+
var TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
160
|
+
var CHAIN_HEADERS = ["x-forwarded-for", "forwarded"];
|
|
161
|
+
function trustedProxyProblem(entry) {
|
|
162
|
+
if (compiles(entry)) return mappedEveryIpv4(entry) ? "everyone" : null;
|
|
163
|
+
const slash = entry.lastIndexOf("/");
|
|
164
|
+
if (slash < 0) return "invalid";
|
|
165
|
+
const prefix = entry.slice(slash + 1);
|
|
166
|
+
const zero = /^0+$/.test(prefix) || prefix === "0.0.0.0";
|
|
167
|
+
return zero && isIP(entry.slice(0, slash)) !== 0 ? "everyone" : "invalid";
|
|
168
|
+
}
|
|
169
|
+
function mappedEveryIpv4(entry) {
|
|
170
|
+
const slash = entry.lastIndexOf("/");
|
|
171
|
+
if (slash < 0 || Number(entry.slice(slash + 1)) > 96) return false;
|
|
172
|
+
const address = entry.slice(0, slash).split("%")[0];
|
|
173
|
+
if (isIP(address) !== 6) return false;
|
|
174
|
+
return /^\[::ffff:[0-9a-f]{1,4}:[0-9a-f]{1,4}\]$/.test(new URL(`http://[${address}]`).hostname);
|
|
175
|
+
}
|
|
176
|
+
function compiles(entry) {
|
|
177
|
+
try {
|
|
178
|
+
proxyAddr.compile([entry]);
|
|
179
|
+
return true;
|
|
180
|
+
} catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function trustedProxyMessage(entry, source, problem) {
|
|
185
|
+
return problem === "everyone" ? `${source} entry '${entry}' trusts every address, so any client could choose its own; list the proxies in front instead, such as loopback or uniquelocal` : `${source} entry '${entry}' is not a proxy address: list loopback, linklocal, uniquelocal, an IP address or a CIDR such as 10.0.0.0/8`;
|
|
186
|
+
}
|
|
187
|
+
function clientIpHeaderProblem(name) {
|
|
188
|
+
if (!TOKEN.test(name)) return "is not an HTTP header name";
|
|
189
|
+
if (CHAIN_HEADERS.includes(name.toLowerCase())) {
|
|
190
|
+
return "is a chain of addresses, which the trusted proxy list already reads; name a header that holds one client address, such as True-Client-IP";
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
function sourceLabel(source) {
|
|
195
|
+
return source.kind === "adapter" ? `adapter ${source.name}` : source.name;
|
|
196
|
+
}
|
|
197
|
+
function fromEnv(env2, name) {
|
|
198
|
+
const value = env2[name]?.trim();
|
|
199
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
200
|
+
}
|
|
201
|
+
function resolveList(config, env2, contribution) {
|
|
202
|
+
const variable = fromEnv(env2, TRUSTED_PROXIES_ENV)?.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
203
|
+
if (variable !== void 0 && variable.length > 0) {
|
|
204
|
+
return { list: variable, source: { kind: "env", name: TRUSTED_PROXIES_ENV } };
|
|
205
|
+
}
|
|
206
|
+
if (config.http.trustedProxies !== void 0) {
|
|
207
|
+
return { list: config.http.trustedProxies, source: { kind: "config", name: LIST_KEY } };
|
|
208
|
+
}
|
|
209
|
+
if (contribution?.network.trustedProxies !== void 0) {
|
|
210
|
+
return {
|
|
211
|
+
list: contribution.network.trustedProxies,
|
|
212
|
+
source: { kind: "adapter", name: contribution.adapter }
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return { list: [...DEFAULT_LIST], source: { kind: "default", name: "default" } };
|
|
216
|
+
}
|
|
217
|
+
function resolveHeader(config, env2, contribution) {
|
|
218
|
+
const variable = fromEnv(env2, CLIENT_IP_HEADER_ENV);
|
|
219
|
+
if (variable !== void 0) {
|
|
220
|
+
return { header: variable, source: { kind: "env", name: CLIENT_IP_HEADER_ENV } };
|
|
221
|
+
}
|
|
222
|
+
if (config.http.clientIpHeader !== void 0) {
|
|
223
|
+
return { header: config.http.clientIpHeader, source: { kind: "config", name: HEADER_KEY } };
|
|
224
|
+
}
|
|
225
|
+
if (contribution?.network.clientIpHeader !== void 0) {
|
|
226
|
+
return {
|
|
227
|
+
header: contribution.network.clientIpHeader,
|
|
228
|
+
source: { kind: "adapter", name: contribution.adapter }
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
function resolveTrustedProxies(config, env2, contribution) {
|
|
234
|
+
if (fromEnv(env2, REMOVED_HOPS_ENV) !== void 0) {
|
|
235
|
+
throw new ConfigError2(
|
|
236
|
+
`${REMOVED_HOPS_ENV} was removed: list the proxies in front in ${TRUSTED_PROXIES_ENV} instead, such as loopback or uniquelocal`,
|
|
237
|
+
{ code: "config.trust_proxy_hops_removed", context: { variable: REMOVED_HOPS_ENV } }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
const { list, source } = resolveList(config, env2, contribution);
|
|
241
|
+
for (const entry of list) {
|
|
242
|
+
const problem = trustedProxyProblem(entry);
|
|
243
|
+
if (problem === null) continue;
|
|
244
|
+
const label = sourceLabel(source);
|
|
245
|
+
throw new ConfigError2(trustedProxyMessage(entry, label, problem), {
|
|
246
|
+
code: problem === "everyone" ? "config.trusted_proxies_everyone" : "config.trusted_proxies_invalid",
|
|
247
|
+
context: { entry, source: label }
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const header = resolveHeader(config, env2, contribution);
|
|
251
|
+
if (header !== void 0) {
|
|
252
|
+
const problem = clientIpHeaderProblem(header.header);
|
|
253
|
+
if (problem !== null) {
|
|
254
|
+
const label = sourceLabel(header.source);
|
|
255
|
+
throw new ConfigError2(`${label} '${header.header}' ${problem}`, {
|
|
256
|
+
code: "config.client_ip_header_invalid",
|
|
257
|
+
context: { header: header.header, source: label }
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
trustedProxies: list,
|
|
263
|
+
trustedProxiesSource: source,
|
|
264
|
+
...header !== void 0 && {
|
|
265
|
+
clientIpHeader: header.header,
|
|
266
|
+
clientIpHeaderSource: header.source
|
|
267
|
+
},
|
|
268
|
+
clientIpRequiresLock: header?.source.kind === "adapter" && contribution?.network.clientIpRequiresLock === true
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function trustSuggestion(address) {
|
|
272
|
+
for (const [preset, holds] of PRESET_MATCHERS) if (holds(address, 0)) return preset;
|
|
273
|
+
return address;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/schema.ts
|
|
144
277
|
var rateLimitRuleSchema = z.object({
|
|
145
278
|
requests: z.number().int().positive(),
|
|
146
279
|
window: z.string().regex(/^\d+(ms|s|m|h)$/, 'window must look like "60s", "5m", "1h"'),
|
|
@@ -150,20 +283,32 @@ var rateLimitRuleSchema = z.object({
|
|
|
150
283
|
});
|
|
151
284
|
var rateLimitPathPattern = /^\/[\w\-/*:]*$/;
|
|
152
285
|
var DEFAULT_JWT_SECRET = "dev-secret-please-override-me-1234567890";
|
|
286
|
+
var shipFromSchema = z.object({
|
|
287
|
+
firstName: z.string().min(1),
|
|
288
|
+
lastName: z.string().min(1),
|
|
289
|
+
company: z.string().optional(),
|
|
290
|
+
addressLine1: z.string().min(1),
|
|
291
|
+
addressLine2: z.string().optional(),
|
|
292
|
+
city: z.string().min(1),
|
|
293
|
+
region: z.string(),
|
|
294
|
+
postalCode: z.string().min(1),
|
|
295
|
+
country: z.string().regex(/^[A-Z]{2}$/, 'country must be two upper-case letters, such as "GB"'),
|
|
296
|
+
phone: z.string().optional()
|
|
297
|
+
});
|
|
153
298
|
var storeSchema = z.object({
|
|
154
299
|
name: z.string().min(1),
|
|
155
300
|
currency: z.string().length(3),
|
|
156
301
|
locale: z.string().min(2),
|
|
157
302
|
timezone: z.string().min(1),
|
|
158
303
|
/** The storefront's public URL, which the order email links from; with none, the email has no link. */
|
|
159
|
-
url: z.string().url().transform((url) => url.replace(/\/+$/, "")).optional()
|
|
304
|
+
url: z.string().url().transform((url) => url.replace(/\/+$/, "")).optional(),
|
|
305
|
+
/** Where parcels are sent from, for shipping rates. */
|
|
306
|
+
shipFrom: shipFromSchema.optional()
|
|
160
307
|
});
|
|
161
308
|
var quotedList = (values) => values.map((v) => `'${v}'`).join(", ");
|
|
162
309
|
function infrastructureValue(slot, values) {
|
|
163
310
|
return z.enum(values, {
|
|
164
|
-
|
|
165
|
-
message: `unknown ${slot} '${String(issue.received)}'; the ${slot} values are ${quotedList(values)}`
|
|
166
|
-
} : { message: ctx.defaultError }
|
|
311
|
+
error: (issue) => issue.code === "invalid_value" ? `unknown ${slot} '${String(issue.input)}'; the ${slot} values are ${quotedList(values)}` : void 0
|
|
167
312
|
});
|
|
168
313
|
}
|
|
169
314
|
var NPM_PACKAGE_NAME = /^(?:@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/;
|
|
@@ -226,9 +371,7 @@ function infrastructureBlock(slot) {
|
|
|
226
371
|
config: z.record(z.string(), z.unknown()).optional()
|
|
227
372
|
},
|
|
228
373
|
{
|
|
229
|
-
|
|
230
|
-
message: `infrastructure.${slot} takes a block: write { provider: '${ctx.data}' }`
|
|
231
|
-
} : { message: ctx.defaultError }
|
|
374
|
+
error: (issue) => issue.code === "invalid_type" && typeof issue.input === "string" ? `infrastructure.${slot} takes a block: write { provider: '${issue.input}' }` : void 0
|
|
232
375
|
}
|
|
233
376
|
).superRefine((block, ctx) => {
|
|
234
377
|
customOutsideCommerce(slot, block.provider, ctx);
|
|
@@ -278,9 +421,7 @@ var s3Schema = z.object(
|
|
|
278
421
|
forcePathStyle: z.boolean().optional()
|
|
279
422
|
},
|
|
280
423
|
{
|
|
281
|
-
|
|
282
|
-
message: `unknown infrastructure.s3 key${issue.keys.length > 1 ? "s" : ""} ${quotedList(issue.keys)}; the s3 keys are ${quotedList(S3_KEYS)}, and credentials come from the AWS SDK (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, a profile or a role), never the config`
|
|
283
|
-
} : { message: ctx.defaultError }
|
|
424
|
+
error: (issue) => issue.code === "unrecognized_keys" ? `unknown infrastructure.s3 key${issue.keys.length > 1 ? "s" : ""} ${quotedList(issue.keys)}; the s3 keys are ${quotedList(S3_KEYS)}, and credentials come from the AWS SDK (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, a profile or a role), never the config` : void 0
|
|
284
425
|
}
|
|
285
426
|
).strict();
|
|
286
427
|
var infrastructureSchema = z.object(
|
|
@@ -293,7 +434,7 @@ var infrastructureSchema = z.object(
|
|
|
293
434
|
s3: s3Schema.optional()
|
|
294
435
|
},
|
|
295
436
|
{
|
|
296
|
-
|
|
437
|
+
error: (issue) => issue.code === "unrecognized_keys" ? unrecognizedInfrastructureKeys(issue.keys) : void 0
|
|
297
438
|
}
|
|
298
439
|
).strict().superRefine((infra, ctx) => {
|
|
299
440
|
if (infra.documentStore.provider === "postgres-jsonb" && infra.commandStore !== "postgres") {
|
|
@@ -329,6 +470,30 @@ var customRuleSchema = z.object({
|
|
|
329
470
|
expression: z.string().min(1),
|
|
330
471
|
action: z.enum(["block", "managed_challenge", "js_challenge", "log"])
|
|
331
472
|
});
|
|
473
|
+
var HEADER_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
474
|
+
var OWNED_HEADERS = [
|
|
475
|
+
"host",
|
|
476
|
+
"cookie",
|
|
477
|
+
"authorization",
|
|
478
|
+
"content-length",
|
|
479
|
+
"content-type",
|
|
480
|
+
"transfer-encoding",
|
|
481
|
+
"connection",
|
|
482
|
+
"forwarded",
|
|
483
|
+
"x-nymbal-shopper",
|
|
484
|
+
"x-correlation-id",
|
|
485
|
+
"x-real-ip"
|
|
486
|
+
];
|
|
487
|
+
var originLockHeaderSchema = z.string().superRefine((header, ctx) => {
|
|
488
|
+
const lower = header.toLowerCase();
|
|
489
|
+
const problem = !HEADER_TOKEN.test(header) ? "is not an HTTP header name" : OWNED_HEADERS.includes(lower) || lower.startsWith("x-forwarded-") || lower.startsWith("cf-") ? "is a header HTTP, a CDN or the API already uses; choose your own, such as X-Nymbal-Origin" : null;
|
|
490
|
+
if (problem !== null) {
|
|
491
|
+
ctx.addIssue({
|
|
492
|
+
code: z.ZodIssueCode.custom,
|
|
493
|
+
message: `security.originLock.header '${header}' ${problem}`
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
});
|
|
332
497
|
var securityFields = z.object({
|
|
333
498
|
/** `middleware` is the kernel's own; any other resolves as a commerce provider does, `security-<adapter>`. */
|
|
334
499
|
adapter: providerNameSchema("security.adapter"),
|
|
@@ -340,7 +505,9 @@ var securityFields = z.object({
|
|
|
340
505
|
z.string().regex(rateLimitPathPattern, {
|
|
341
506
|
message: 'rate limit keys must start with "/" and use only letters, numbers, -, _, /, *, :'
|
|
342
507
|
}),
|
|
343
|
-
rateLimitRuleSchema
|
|
508
|
+
rateLimitRuleSchema,
|
|
509
|
+
// Zod 4 reports a bad key as "Invalid key in record" and nests the key schema's message; surface that message.
|
|
510
|
+
{ error: (issue) => issue.code === "invalid_key" ? issue.issues[0]?.message : void 0 }
|
|
344
511
|
).default({}),
|
|
345
512
|
botProtection: z.object({
|
|
346
513
|
mode: z.enum(["off", "managed", "strict"]).default("off"),
|
|
@@ -351,13 +518,15 @@ var securityFields = z.object({
|
|
|
351
518
|
contentSecurityPolicy: z.union([z.enum(["strict", "relaxed", "off"]), z.string()]).default("strict"),
|
|
352
519
|
referrerPolicy: z.string().default("strict-origin-when-cross-origin"),
|
|
353
520
|
xFrameOptions: z.enum(["deny", "sameorigin"]).default("deny")
|
|
354
|
-
}).
|
|
521
|
+
}).prefault({}),
|
|
355
522
|
csrf: z.boolean().default(true),
|
|
523
|
+
/** The header a CDN proves a request crossed it in; `NYMBAL_ORIGIN_SECRET` holds the value and turns the lock on. */
|
|
524
|
+
originLock: z.object({ header: originLockHeaderSchema.default("X-Nymbal-Origin") }).prefault({}),
|
|
356
525
|
auth: z.object({
|
|
357
526
|
jwtSecret: z.string().min(16).default(DEFAULT_JWT_SECRET),
|
|
358
527
|
accessTtl: z.string().regex(/^\d+(ms|s|m|h|d)$/, 'TTL must look like "15m"').default("15m"),
|
|
359
528
|
refreshTtl: z.string().regex(/^\d+(ms|s|m|h|d)$/, 'TTL must look like "7d"').default("7d")
|
|
360
|
-
}).
|
|
529
|
+
}).prefault({}),
|
|
361
530
|
cloudflare: cloudflareSchema.optional(),
|
|
362
531
|
geo: z.object({
|
|
363
532
|
block: z.array(z.string().regex(/^[A-Z]{2}$/, 'geo.block codes are ISO 3166 alpha-2, like "RU"')).default([])
|
|
@@ -425,24 +594,44 @@ var commerceSchema = z.object({
|
|
|
425
594
|
keyLifetime: z.object({
|
|
426
595
|
checkout: z.string().regex(/^\d+(ms|s|m|h|d)$/, 'TTL must look like "48h"').default("48h"),
|
|
427
596
|
email: z.string().regex(/^\d+(ms|s|m|h|d)$/, 'TTL must look like "30d"').default("30d")
|
|
428
|
-
}).
|
|
429
|
-
}).
|
|
597
|
+
}).prefault({})
|
|
598
|
+
}).prefault({})
|
|
430
599
|
});
|
|
431
600
|
var httpSchema = z.object({
|
|
432
601
|
adapter: z.enum(["fastify", "hono"]).default("fastify"),
|
|
433
602
|
port: z.number().int().positive().default(3001),
|
|
434
603
|
host: z.string().default("0.0.0.0"),
|
|
435
604
|
/**
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
* left-most value wins: spoofable unless your proxy overwrites the header. Left at `false` (explicitly or not),
|
|
439
|
-
* NYMBAL_TRUST_PROXY_HOPS fills it at run time.
|
|
605
|
+
* The proxies in front whose `X-Forwarded-For` sets the client address the rate limiter keys on: `loopback`,
|
|
606
|
+
* `linklocal`, `uniquelocal`, an IP address or a CIDR. Unset, `loopback`; NYMBAL_TRUSTED_PROXIES replaces it.
|
|
440
607
|
*/
|
|
441
|
-
|
|
608
|
+
trustedProxies: z.array(
|
|
609
|
+
z.string().superRefine((entry, ctx) => {
|
|
610
|
+
const problem = trustedProxyProblem(entry);
|
|
611
|
+
if (problem !== null) {
|
|
612
|
+
ctx.addIssue({
|
|
613
|
+
code: z.ZodIssueCode.custom,
|
|
614
|
+
message: trustedProxyMessage(entry, "http.trustedProxies", problem)
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
})
|
|
618
|
+
).optional(),
|
|
619
|
+
/**
|
|
620
|
+
* One header a listed proxy sets to the client's address (`True-Client-IP`, `CF-Connecting-IP`), read in place of
|
|
621
|
+
* `X-Forwarded-For` and only from a listed proxy. NYMBAL_CLIENT_IP_HEADER replaces it.
|
|
622
|
+
*/
|
|
623
|
+
clientIpHeader: z.string().superRefine((name, ctx) => {
|
|
624
|
+
const problem = clientIpHeaderProblem(name);
|
|
625
|
+
if (problem !== null)
|
|
626
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `'${name}' ${problem}` });
|
|
627
|
+
}).optional(),
|
|
628
|
+
trustProxy: z.never({
|
|
629
|
+
error: "http.trustProxy was removed: list the proxies in front in http.trustedProxies (or NYMBAL_TRUSTED_PROXIES), such as ['loopback'] or ['uniquelocal']"
|
|
630
|
+
}).optional(),
|
|
442
631
|
cors: z.object({
|
|
443
632
|
allowedOrigins: z.array(z.string()).default(["http://localhost:3000", "http://localhost:4321"]),
|
|
444
633
|
credentials: z.boolean().default(true)
|
|
445
|
-
}).
|
|
634
|
+
}).prefault({})
|
|
446
635
|
});
|
|
447
636
|
var deploymentSchema = z.object({
|
|
448
637
|
strategy: z.enum(["standard", "blue-green"]).default("standard")
|
|
@@ -469,6 +658,75 @@ var eventsSchema = z.object({
|
|
|
469
658
|
retentionDays: z.number().int().min(1).default(30),
|
|
470
659
|
archive: eventArchiveSchema.optional()
|
|
471
660
|
}).strict();
|
|
661
|
+
var MCP_WRITES = ["proposal", "apply"];
|
|
662
|
+
var DEFAULT_AGENT_CRAWLERS = Object.freeze([
|
|
663
|
+
"GPTBot",
|
|
664
|
+
"OAI-SearchBot",
|
|
665
|
+
"ChatGPT-User",
|
|
666
|
+
"ClaudeBot",
|
|
667
|
+
"Claude-User",
|
|
668
|
+
"Claude-SearchBot",
|
|
669
|
+
"PerplexityBot",
|
|
670
|
+
"Perplexity-User",
|
|
671
|
+
"Google-Extended",
|
|
672
|
+
"Applebot-Extended"
|
|
673
|
+
]);
|
|
674
|
+
var CRAWL_OTHERS = ["allow", "disallow"];
|
|
675
|
+
var ACP_LINK_TYPES = [
|
|
676
|
+
"terms_of_use",
|
|
677
|
+
"privacy_policy",
|
|
678
|
+
"return_policy",
|
|
679
|
+
"shipping_policy",
|
|
680
|
+
"contact_us",
|
|
681
|
+
"about_us",
|
|
682
|
+
"faq",
|
|
683
|
+
"support"
|
|
684
|
+
];
|
|
685
|
+
var ACP_KEY_MIN_LENGTH = 32;
|
|
686
|
+
var agentsSchema = z.object({
|
|
687
|
+
mcp: z.object({
|
|
688
|
+
enabled: z.boolean().default(true),
|
|
689
|
+
writes: z.enum(MCP_WRITES, {
|
|
690
|
+
error: (issue) => issue.code === "invalid_value" ? `must be 'proposal' or 'apply', not ${JSON.stringify(issue.input)}` : void 0
|
|
691
|
+
}).default("proposal")
|
|
692
|
+
}).strict().prefault({}),
|
|
693
|
+
autoApprove: z.array(z.string().min(1)).default([]),
|
|
694
|
+
ucp: z.object({
|
|
695
|
+
enabled: z.boolean().default(true),
|
|
696
|
+
links: z.array(
|
|
697
|
+
z.object({
|
|
698
|
+
type: z.string().min(1),
|
|
699
|
+
url: z.string().url(),
|
|
700
|
+
title: z.string().optional()
|
|
701
|
+
}).strict()
|
|
702
|
+
).default([])
|
|
703
|
+
}).strict().prefault({}),
|
|
704
|
+
acp: z.object({
|
|
705
|
+
enabled: z.boolean().default(false),
|
|
706
|
+
apiKey: z.string().min(ACP_KEY_MIN_LENGTH, { error: `must be at least ${ACP_KEY_MIN_LENGTH} characters` }).optional(),
|
|
707
|
+
links: z.array(
|
|
708
|
+
z.object({
|
|
709
|
+
type: z.enum(ACP_LINK_TYPES),
|
|
710
|
+
url: z.string().url(),
|
|
711
|
+
title: z.string().optional()
|
|
712
|
+
}).strict()
|
|
713
|
+
).default([]),
|
|
714
|
+
merchantId: z.string().min(1).optional()
|
|
715
|
+
}).strict().prefault({}),
|
|
716
|
+
crawl: z.object({
|
|
717
|
+
robots: z.boolean().default(true),
|
|
718
|
+
llms: z.boolean().default(true),
|
|
719
|
+
feed: z.boolean().default(true),
|
|
720
|
+
allow: z.array(z.string().min(1)).default(() => [...DEFAULT_AGENT_CRAWLERS]),
|
|
721
|
+
others: z.enum(CRAWL_OTHERS, {
|
|
722
|
+
error: (issue) => issue.code === "invalid_value" ? `must be 'allow' or 'disallow', not ${JSON.stringify(issue.input)}` : void 0
|
|
723
|
+
}).default("allow")
|
|
724
|
+
}).strict().prefault({}),
|
|
725
|
+
assistant: z.object({
|
|
726
|
+
/** false keeps every tool that answers a customer's email, phone or address off the admin's assistant. */
|
|
727
|
+
customerData: z.boolean().default(true)
|
|
728
|
+
}).strict().prefault({})
|
|
729
|
+
}).strict();
|
|
472
730
|
var nymbalConfigSchema = z.object({
|
|
473
731
|
store: storeSchema,
|
|
474
732
|
template: z.enum(["astro", "nextjs"]),
|
|
@@ -482,7 +740,8 @@ var nymbalConfigSchema = z.object({
|
|
|
482
740
|
heartbeat: false,
|
|
483
741
|
autoUpdates: false
|
|
484
742
|
}),
|
|
485
|
-
events: eventsSchema.
|
|
743
|
+
events: eventsSchema.prefault({}),
|
|
744
|
+
agents: agentsSchema.prefault({})
|
|
486
745
|
}).superRefine((cfg, ctx) => {
|
|
487
746
|
const archiveBucket = cfg.events.archive?.bucket;
|
|
488
747
|
if (archiveBucket !== void 0 && cfg.infrastructure.media.provider === "s3" && archiveBucket === cfg.infrastructure.s3?.bucket) {
|
|
@@ -517,7 +776,7 @@ function findConfigFile(startDir) {
|
|
|
517
776
|
async function loadConfig(startDir = process.cwd()) {
|
|
518
777
|
const path = findConfigFile(startDir);
|
|
519
778
|
if (!path) {
|
|
520
|
-
throw new
|
|
779
|
+
throw new ConfigError3(
|
|
521
780
|
`Could not find ${CONFIG_FILE} in ${startDir} or any parent directory.`,
|
|
522
781
|
{ context: { startDir } }
|
|
523
782
|
);
|
|
@@ -527,7 +786,7 @@ async function loadConfig(startDir = process.cwd()) {
|
|
|
527
786
|
try {
|
|
528
787
|
mod = await jiti.import(path);
|
|
529
788
|
} catch (err) {
|
|
530
|
-
throw new
|
|
789
|
+
throw new ConfigError3(`Failed to load ${path}: ${err.message}`, {
|
|
531
790
|
cause: err,
|
|
532
791
|
context: { path }
|
|
533
792
|
});
|
|
@@ -539,7 +798,7 @@ async function loadConfig(startDir = process.cwd()) {
|
|
|
539
798
|
return { config, path, projectRoot: dirname(path), ...adapters !== void 0 && { adapters } };
|
|
540
799
|
} catch (err) {
|
|
541
800
|
if (err instanceof z2.ZodError) {
|
|
542
|
-
throw new
|
|
801
|
+
throw new ConfigError3(formatZodError(err, path), {
|
|
543
802
|
cause: err,
|
|
544
803
|
context: { path, issues: err.issues }
|
|
545
804
|
});
|
|
@@ -550,7 +809,7 @@ async function loadConfig(startDir = process.cwd()) {
|
|
|
550
809
|
function adaptersExport(value, path) {
|
|
551
810
|
if (value === void 0) return void 0;
|
|
552
811
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
553
|
-
throw new
|
|
812
|
+
throw new ConfigError3(`${path}: the adapters export must be an object keyed by commerce slot`, {
|
|
554
813
|
code: "config.adapters_invalid",
|
|
555
814
|
context: { path }
|
|
556
815
|
});
|
|
@@ -558,7 +817,7 @@ function adaptersExport(value, path) {
|
|
|
558
817
|
const slots = Object.keys(KNOWN_PROVIDERS);
|
|
559
818
|
const unknown = Object.keys(value).filter((key) => !slots.includes(key));
|
|
560
819
|
if (unknown.length > 0) {
|
|
561
|
-
throw new
|
|
820
|
+
throw new ConfigError3(
|
|
562
821
|
`${path}: the adapters export names ${unknown.join(", ")}, which is no commerce slot (${slots.join(", ")})`,
|
|
563
822
|
{ code: "config.adapters_invalid", context: { path, unknown } }
|
|
564
823
|
);
|
|
@@ -573,14 +832,49 @@ function formatZodError(err, path) {
|
|
|
573
832
|
return `Invalid configuration in ${path}:
|
|
574
833
|
${lines.join("\n")}`;
|
|
575
834
|
}
|
|
835
|
+
|
|
836
|
+
// src/secure-cookies.ts
|
|
837
|
+
var PUBLIC_URL_ENV = "NYMBAL_PUBLIC_URL";
|
|
838
|
+
function secureCookies(config, env2) {
|
|
839
|
+
const fromEnv2 = env2[PUBLIC_URL_ENV]?.trim();
|
|
840
|
+
const origin = fromEnv2 !== void 0 && fromEnv2 !== "" ? fromEnv2 : config.store.url;
|
|
841
|
+
if (origin === void 0) return env2["NODE_ENV"] === "production";
|
|
842
|
+
return /^https:/i.test(origin);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// src/origin-lock.ts
|
|
846
|
+
import { ConfigError as ConfigError4 } from "@nymbalhq/types";
|
|
847
|
+
var ORIGIN_SECRET_ENV = "NYMBAL_ORIGIN_SECRET";
|
|
848
|
+
var ENTRY = /^[A-Za-z0-9+/=_.~-]{32,256}$/;
|
|
849
|
+
function resolveOriginLock(config, env2) {
|
|
850
|
+
const secrets = (env2[ORIGIN_SECRET_ENV] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
851
|
+
if (secrets.length === 0) return void 0;
|
|
852
|
+
const invalid = secrets.findIndex((entry) => !ENTRY.test(entry));
|
|
853
|
+
if (invalid >= 0) {
|
|
854
|
+
const position = invalid + 1;
|
|
855
|
+
throw new ConfigError4(
|
|
856
|
+
`${ORIGIN_SECRET_ENV} entry ${position} is not an origin secret: each entry is 32 to 256 characters of A-Z a-z 0-9 + / = _ . ~ - (nymbal security:apply makes one)`,
|
|
857
|
+
{ code: "config.origin_secret_invalid", context: { variable: ORIGIN_SECRET_ENV, position } }
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
return { header: config.security.originLock.header, secrets };
|
|
861
|
+
}
|
|
576
862
|
export {
|
|
863
|
+
ACP_KEY_MIN_LENGTH,
|
|
864
|
+
ACP_LINK_TYPES,
|
|
577
865
|
ADAPTER_CATALOGUE,
|
|
578
866
|
BUILT_IN,
|
|
867
|
+
CLIENT_IP_HEADER_ENV,
|
|
579
868
|
COMMAND_STORES,
|
|
869
|
+
DEFAULT_AGENT_CRAWLERS,
|
|
580
870
|
DEFAULT_JWT_SECRET,
|
|
581
871
|
KNOWN_PROVIDERS,
|
|
872
|
+
ORIGIN_SECRET_ENV,
|
|
582
873
|
PROVIDER_NAME,
|
|
874
|
+
PUBLIC_URL_ENV,
|
|
583
875
|
REMOVED_INFRASTRUCTURE_KEYS,
|
|
876
|
+
TRUSTED_PROXIES_ENV,
|
|
877
|
+
agentsSchema,
|
|
584
878
|
commerceSchema,
|
|
585
879
|
conventionPackage,
|
|
586
880
|
defineConfig,
|
|
@@ -598,10 +892,15 @@ export {
|
|
|
598
892
|
loadConfig,
|
|
599
893
|
nymbalConfigSchema,
|
|
600
894
|
redisSchema,
|
|
895
|
+
resolveOriginLock,
|
|
896
|
+
resolveTrustedProxies,
|
|
601
897
|
s3Schema,
|
|
898
|
+
secureCookies,
|
|
602
899
|
securitySchema,
|
|
603
900
|
slotFolder,
|
|
604
901
|
storeSchema,
|
|
605
|
-
suggestProvider
|
|
902
|
+
suggestProvider,
|
|
903
|
+
trustSuggestion,
|
|
904
|
+
trustedProxyProblem
|
|
606
905
|
};
|
|
607
906
|
//# sourceMappingURL=index.js.map
|