@nymbalhq/config 1.5.0 → 1.7.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 +440 -2486
- package/dist/index.js +337 -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,79 @@ 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 ASSISTANT_MASK_FIELDS = ["email", "phone", "address", "postcode", "name"];
|
|
676
|
+
var DEFAULT_ASSISTANT_MASK = ["email", "phone", "address", "postcode"];
|
|
677
|
+
var ACP_LINK_TYPES = [
|
|
678
|
+
"terms_of_use",
|
|
679
|
+
"privacy_policy",
|
|
680
|
+
"return_policy",
|
|
681
|
+
"shipping_policy",
|
|
682
|
+
"contact_us",
|
|
683
|
+
"about_us",
|
|
684
|
+
"faq",
|
|
685
|
+
"support"
|
|
686
|
+
];
|
|
687
|
+
var ACP_KEY_MIN_LENGTH = 32;
|
|
688
|
+
var agentsSchema = z.object({
|
|
689
|
+
mcp: z.object({
|
|
690
|
+
enabled: z.boolean().default(true),
|
|
691
|
+
writes: z.enum(MCP_WRITES, {
|
|
692
|
+
error: (issue) => issue.code === "invalid_value" ? `must be 'proposal' or 'apply', not ${JSON.stringify(issue.input)}` : void 0
|
|
693
|
+
}).default("proposal")
|
|
694
|
+
}).strict().prefault({}),
|
|
695
|
+
autoApprove: z.array(z.string().min(1)).default([]),
|
|
696
|
+
ucp: z.object({
|
|
697
|
+
enabled: z.boolean().default(true),
|
|
698
|
+
links: z.array(
|
|
699
|
+
z.object({
|
|
700
|
+
type: z.string().min(1),
|
|
701
|
+
url: z.string().url(),
|
|
702
|
+
title: z.string().optional()
|
|
703
|
+
}).strict()
|
|
704
|
+
).default([])
|
|
705
|
+
}).strict().prefault({}),
|
|
706
|
+
acp: z.object({
|
|
707
|
+
enabled: z.boolean().default(false),
|
|
708
|
+
apiKey: z.string().min(ACP_KEY_MIN_LENGTH, { error: `must be at least ${ACP_KEY_MIN_LENGTH} characters` }).optional(),
|
|
709
|
+
links: z.array(
|
|
710
|
+
z.object({
|
|
711
|
+
type: z.enum(ACP_LINK_TYPES),
|
|
712
|
+
url: z.string().url(),
|
|
713
|
+
title: z.string().optional()
|
|
714
|
+
}).strict()
|
|
715
|
+
).default([]),
|
|
716
|
+
merchantId: z.string().min(1).optional()
|
|
717
|
+
}).strict().prefault({}),
|
|
718
|
+
crawl: z.object({
|
|
719
|
+
robots: z.boolean().default(true),
|
|
720
|
+
llms: z.boolean().default(true),
|
|
721
|
+
feed: z.boolean().default(true),
|
|
722
|
+
allow: z.array(z.string().min(1)).default(() => [...DEFAULT_AGENT_CRAWLERS]),
|
|
723
|
+
others: z.enum(CRAWL_OTHERS, {
|
|
724
|
+
error: (issue) => issue.code === "invalid_value" ? `must be 'allow' or 'disallow', not ${JSON.stringify(issue.input)}` : void 0
|
|
725
|
+
}).default("allow")
|
|
726
|
+
}).strict().prefault({}),
|
|
727
|
+
assistant: z.object({
|
|
728
|
+
/** false keeps every tool that answers a customer's email, phone or address off the admin's assistant. */
|
|
729
|
+
customerData: z.boolean().default(true),
|
|
730
|
+
/** The fields sent as placeholders; [] sends them as they are. */
|
|
731
|
+
mask: z.array(z.enum(ASSISTANT_MASK_FIELDS)).transform((fields) => [...new Set(fields)]).default(() => [...DEFAULT_ASSISTANT_MASK])
|
|
732
|
+
}).strict().prefault({})
|
|
733
|
+
}).strict();
|
|
472
734
|
var nymbalConfigSchema = z.object({
|
|
473
735
|
store: storeSchema,
|
|
474
736
|
template: z.enum(["astro", "nextjs"]),
|
|
@@ -482,7 +744,8 @@ var nymbalConfigSchema = z.object({
|
|
|
482
744
|
heartbeat: false,
|
|
483
745
|
autoUpdates: false
|
|
484
746
|
}),
|
|
485
|
-
events: eventsSchema.
|
|
747
|
+
events: eventsSchema.prefault({}),
|
|
748
|
+
agents: agentsSchema.prefault({})
|
|
486
749
|
}).superRefine((cfg, ctx) => {
|
|
487
750
|
const archiveBucket = cfg.events.archive?.bucket;
|
|
488
751
|
if (archiveBucket !== void 0 && cfg.infrastructure.media.provider === "s3" && archiveBucket === cfg.infrastructure.s3?.bucket) {
|
|
@@ -517,7 +780,7 @@ function findConfigFile(startDir) {
|
|
|
517
780
|
async function loadConfig(startDir = process.cwd()) {
|
|
518
781
|
const path = findConfigFile(startDir);
|
|
519
782
|
if (!path) {
|
|
520
|
-
throw new
|
|
783
|
+
throw new ConfigError3(
|
|
521
784
|
`Could not find ${CONFIG_FILE} in ${startDir} or any parent directory.`,
|
|
522
785
|
{ context: { startDir } }
|
|
523
786
|
);
|
|
@@ -527,7 +790,7 @@ async function loadConfig(startDir = process.cwd()) {
|
|
|
527
790
|
try {
|
|
528
791
|
mod = await jiti.import(path);
|
|
529
792
|
} catch (err) {
|
|
530
|
-
throw new
|
|
793
|
+
throw new ConfigError3(`Failed to load ${path}: ${err.message}`, {
|
|
531
794
|
cause: err,
|
|
532
795
|
context: { path }
|
|
533
796
|
});
|
|
@@ -539,7 +802,7 @@ async function loadConfig(startDir = process.cwd()) {
|
|
|
539
802
|
return { config, path, projectRoot: dirname(path), ...adapters !== void 0 && { adapters } };
|
|
540
803
|
} catch (err) {
|
|
541
804
|
if (err instanceof z2.ZodError) {
|
|
542
|
-
throw new
|
|
805
|
+
throw new ConfigError3(formatZodError(err, path), {
|
|
543
806
|
cause: err,
|
|
544
807
|
context: { path, issues: err.issues }
|
|
545
808
|
});
|
|
@@ -550,7 +813,7 @@ async function loadConfig(startDir = process.cwd()) {
|
|
|
550
813
|
function adaptersExport(value, path) {
|
|
551
814
|
if (value === void 0) return void 0;
|
|
552
815
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
553
|
-
throw new
|
|
816
|
+
throw new ConfigError3(`${path}: the adapters export must be an object keyed by commerce slot`, {
|
|
554
817
|
code: "config.adapters_invalid",
|
|
555
818
|
context: { path }
|
|
556
819
|
});
|
|
@@ -558,7 +821,7 @@ function adaptersExport(value, path) {
|
|
|
558
821
|
const slots = Object.keys(KNOWN_PROVIDERS);
|
|
559
822
|
const unknown = Object.keys(value).filter((key) => !slots.includes(key));
|
|
560
823
|
if (unknown.length > 0) {
|
|
561
|
-
throw new
|
|
824
|
+
throw new ConfigError3(
|
|
562
825
|
`${path}: the adapters export names ${unknown.join(", ")}, which is no commerce slot (${slots.join(", ")})`,
|
|
563
826
|
{ code: "config.adapters_invalid", context: { path, unknown } }
|
|
564
827
|
);
|
|
@@ -573,14 +836,51 @@ function formatZodError(err, path) {
|
|
|
573
836
|
return `Invalid configuration in ${path}:
|
|
574
837
|
${lines.join("\n")}`;
|
|
575
838
|
}
|
|
839
|
+
|
|
840
|
+
// src/secure-cookies.ts
|
|
841
|
+
var PUBLIC_URL_ENV = "NYMBAL_PUBLIC_URL";
|
|
842
|
+
function secureCookies(config, env2) {
|
|
843
|
+
const fromEnv2 = env2[PUBLIC_URL_ENV]?.trim();
|
|
844
|
+
const origin = fromEnv2 !== void 0 && fromEnv2 !== "" ? fromEnv2 : config.store.url;
|
|
845
|
+
if (origin === void 0) return env2["NODE_ENV"] === "production";
|
|
846
|
+
return /^https:/i.test(origin);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
// src/origin-lock.ts
|
|
850
|
+
import { ConfigError as ConfigError4 } from "@nymbalhq/types";
|
|
851
|
+
var ORIGIN_SECRET_ENV = "NYMBAL_ORIGIN_SECRET";
|
|
852
|
+
var ENTRY = /^[A-Za-z0-9+/=_.~-]{32,256}$/;
|
|
853
|
+
function resolveOriginLock(config, env2) {
|
|
854
|
+
const secrets = (env2[ORIGIN_SECRET_ENV] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
855
|
+
if (secrets.length === 0) return void 0;
|
|
856
|
+
const invalid = secrets.findIndex((entry) => !ENTRY.test(entry));
|
|
857
|
+
if (invalid >= 0) {
|
|
858
|
+
const position = invalid + 1;
|
|
859
|
+
throw new ConfigError4(
|
|
860
|
+
`${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)`,
|
|
861
|
+
{ code: "config.origin_secret_invalid", context: { variable: ORIGIN_SECRET_ENV, position } }
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
return { header: config.security.originLock.header, secrets };
|
|
865
|
+
}
|
|
576
866
|
export {
|
|
867
|
+
ACP_KEY_MIN_LENGTH,
|
|
868
|
+
ACP_LINK_TYPES,
|
|
577
869
|
ADAPTER_CATALOGUE,
|
|
870
|
+
ASSISTANT_MASK_FIELDS,
|
|
578
871
|
BUILT_IN,
|
|
872
|
+
CLIENT_IP_HEADER_ENV,
|
|
579
873
|
COMMAND_STORES,
|
|
874
|
+
DEFAULT_AGENT_CRAWLERS,
|
|
875
|
+
DEFAULT_ASSISTANT_MASK,
|
|
580
876
|
DEFAULT_JWT_SECRET,
|
|
581
877
|
KNOWN_PROVIDERS,
|
|
878
|
+
ORIGIN_SECRET_ENV,
|
|
582
879
|
PROVIDER_NAME,
|
|
880
|
+
PUBLIC_URL_ENV,
|
|
583
881
|
REMOVED_INFRASTRUCTURE_KEYS,
|
|
882
|
+
TRUSTED_PROXIES_ENV,
|
|
883
|
+
agentsSchema,
|
|
584
884
|
commerceSchema,
|
|
585
885
|
conventionPackage,
|
|
586
886
|
defineConfig,
|
|
@@ -598,10 +898,15 @@ export {
|
|
|
598
898
|
loadConfig,
|
|
599
899
|
nymbalConfigSchema,
|
|
600
900
|
redisSchema,
|
|
901
|
+
resolveOriginLock,
|
|
902
|
+
resolveTrustedProxies,
|
|
601
903
|
s3Schema,
|
|
904
|
+
secureCookies,
|
|
602
905
|
securitySchema,
|
|
603
906
|
slotFolder,
|
|
604
907
|
storeSchema,
|
|
605
|
-
suggestProvider
|
|
908
|
+
suggestProvider,
|
|
909
|
+
trustSuggestion,
|
|
910
|
+
trustedProxyProblem
|
|
606
911
|
};
|
|
607
912
|
//# sourceMappingURL=index.js.map
|