@fireweaveai/server-sdk 2.2.1-staging.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +263 -0
  2. package/dist/application/client.d.ts +92 -0
  3. package/dist/application/client.d.ts.map +1 -0
  4. package/dist/application/client.js +156 -0
  5. package/dist/application/client.js.map +1 -0
  6. package/dist/application/mode.d.ts +71 -0
  7. package/dist/application/mode.d.ts.map +1 -0
  8. package/dist/application/mode.js +72 -0
  9. package/dist/application/mode.js.map +1 -0
  10. package/dist/application/ports.d.ts +95 -0
  11. package/dist/application/ports.d.ts.map +1 -0
  12. package/dist/application/ports.js +2 -0
  13. package/dist/application/ports.js.map +1 -0
  14. package/dist/application/runtime.d.ts +102 -0
  15. package/dist/application/runtime.d.ts.map +1 -0
  16. package/dist/application/runtime.js +342 -0
  17. package/dist/application/runtime.js.map +1 -0
  18. package/dist/domain/context.d.ts +68 -0
  19. package/dist/domain/context.d.ts.map +1 -0
  20. package/dist/domain/context.js +85 -0
  21. package/dist/domain/context.js.map +1 -0
  22. package/dist/domain/errors.d.ts +43 -0
  23. package/dist/domain/errors.d.ts.map +1 -0
  24. package/dist/domain/errors.js +64 -0
  25. package/dist/domain/errors.js.map +1 -0
  26. package/dist/domain/target.d.ts +3 -0
  27. package/dist/domain/target.d.ts.map +1 -0
  28. package/dist/domain/target.js +2 -0
  29. package/dist/domain/target.js.map +1 -0
  30. package/dist/domain/types.d.ts +108 -0
  31. package/dist/domain/types.d.ts.map +1 -0
  32. package/dist/domain/types.js +2 -0
  33. package/dist/domain/types.js.map +1 -0
  34. package/dist/domain/validation.d.ts +125 -0
  35. package/dist/domain/validation.d.ts.map +1 -0
  36. package/dist/domain/validation.js +347 -0
  37. package/dist/domain/validation.js.map +1 -0
  38. package/dist/index.d.ts +35 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +23 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/infrastructure/adapters/inmemory.d.ts +78 -0
  43. package/dist/infrastructure/adapters/inmemory.d.ts.map +1 -0
  44. package/dist/infrastructure/adapters/inmemory.js +148 -0
  45. package/dist/infrastructure/adapters/inmemory.js.map +1 -0
  46. package/dist/infrastructure/adapters/local.d.ts +109 -0
  47. package/dist/infrastructure/adapters/local.d.ts.map +1 -0
  48. package/dist/infrastructure/adapters/local.js +102 -0
  49. package/dist/infrastructure/adapters/local.js.map +1 -0
  50. package/dist/infrastructure/adapters/remote.d.ts +75 -0
  51. package/dist/infrastructure/adapters/remote.d.ts.map +1 -0
  52. package/dist/infrastructure/adapters/remote.js +361 -0
  53. package/dist/infrastructure/adapters/remote.js.map +1 -0
  54. package/dist/infrastructure/hosts.d.ts +19 -0
  55. package/dist/infrastructure/hosts.d.ts.map +1 -0
  56. package/dist/infrastructure/hosts.js +68 -0
  57. package/dist/infrastructure/hosts.js.map +1 -0
  58. package/package.json +56 -0
@@ -0,0 +1,361 @@
1
+ /**
2
+ * Fireweave remote backend adapter (ADR-0005) — **default production path**.
3
+ *
4
+ * Speaks only the vendor-neutral Fireweave remote protocol to fw-server:
5
+ * POST /v1/flags/evaluate
6
+ * POST /v1/capture
7
+ * POST /v1/targets/register
8
+ *
9
+ * Auth: Authorization: Bearer <FW_PROJECT_API_KEY> (project-api-key_…).
10
+ * Which backend fw-server forwards to is fw-server's concern: no vendor SDK,
11
+ * key, or host ever enters the application process.
12
+ *
13
+ * See spec/remote-protocol.md.
14
+ */
15
+ import { FireweaveError } from '../../domain/errors.js';
16
+ import { assertHostAllowed, isLoopbackHostname } from '../hosts.js';
17
+ import { validateTargetingKey } from '../../domain/validation.js';
18
+ const DEFAULT_ADAPTER_SHUTDOWN_TIMEOUT_MS = 10000;
19
+ const DEFAULT_REQUEST_TIMEOUT_MS = 3000;
20
+ const EVALUATE_PATH = '/v1/flags/evaluate';
21
+ const CAPTURE_PATH = '/v1/capture';
22
+ const REGISTER_TARGET_PATH = '/v1/targets/register';
23
+ function mapHttpStatus(status) {
24
+ if (status === 401)
25
+ return new FireweaveError('Authentication');
26
+ if (status === 403)
27
+ return new FireweaveError('Authorization');
28
+ if (status === 429)
29
+ return new FireweaveError('RateLimited');
30
+ if (status >= 500)
31
+ return new FireweaveError('BackendUnavailable');
32
+ return new FireweaveError('BackendUnavailable');
33
+ }
34
+ /**
35
+ * `apiUrl`/`apiKey` come from `options` only — never the environment
36
+ * (spec/modes.md "The SDK reads no environment variables. Credentials
37
+ * arrive as explicit options.", unscoped).
38
+ */
39
+ function resolveCredentials(options) {
40
+ const apiUrl = (options.apiUrl ?? '').replace(/\/+$/, '');
41
+ const apiKey = options.apiKey ?? '';
42
+ return { apiUrl, apiKey };
43
+ }
44
+ function defaultAllowedHostsFor(apiUrl) {
45
+ try {
46
+ const hostname = new URL(apiUrl).hostname;
47
+ const hosts = [hostname, 'localhost', '127.0.0.1', '::1'];
48
+ if (hostname === '[::1]')
49
+ hosts.push('::1');
50
+ return hosts;
51
+ }
52
+ catch {
53
+ return ['localhost', '127.0.0.1', '::1'];
54
+ }
55
+ }
56
+ function reasonToAdapter(reason) {
57
+ const allowed = new Set([
58
+ 'STATIC',
59
+ 'DEFAULT',
60
+ 'TARGETING_MATCH',
61
+ 'SPLIT',
62
+ 'CACHED',
63
+ 'STALE',
64
+ 'DISABLED',
65
+ 'UNKNOWN',
66
+ 'ERROR',
67
+ ]);
68
+ return allowed.has(reason) ? reason : undefined;
69
+ }
70
+ export class FireweaveRemoteAdapter {
71
+ name = 'fireweave';
72
+ options;
73
+ apiUrl = '';
74
+ apiKey = '';
75
+ closed = false;
76
+ ready = false;
77
+ pending = [];
78
+ fetchImpl;
79
+ constructor(options = {}) {
80
+ this.options = { ...options };
81
+ this.fetchImpl = options.fetch ?? globalThis.fetch;
82
+ }
83
+ async initialize(_signal) {
84
+ if (this.closed)
85
+ throw new FireweaveError('AlreadyClosed');
86
+ const { apiUrl, apiKey } = resolveCredentials(this.options);
87
+ if (!apiUrl || !apiKey) {
88
+ throw new FireweaveError('Configuration');
89
+ }
90
+ let url;
91
+ try {
92
+ url = new URL(apiUrl);
93
+ }
94
+ catch {
95
+ throw new FireweaveError('Configuration');
96
+ }
97
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
98
+ throw new FireweaveError('Configuration');
99
+ }
100
+ if (url.protocol === 'http:' && !isLoopbackHostname(url.hostname)) {
101
+ throw new FireweaveError('Configuration');
102
+ }
103
+ const allow = this.options.allowedHosts !== undefined && this.options.allowedHosts.length > 0
104
+ ? this.options.allowedHosts
105
+ : defaultAllowedHostsFor(apiUrl);
106
+ assertHostAllowed(apiUrl, allow);
107
+ this.apiUrl = apiUrl.replace(/\/+$/, '');
108
+ this.apiKey = apiKey;
109
+ this.ready = true;
110
+ }
111
+ async resolve(flagKey, context, options) {
112
+ if (this.closed)
113
+ throw new FireweaveError('AlreadyClosed');
114
+ if (!this.ready)
115
+ throw new FireweaveError('NotReady');
116
+ const targetingKeyResult = validateTargetingKey(context.targetingKey, true);
117
+ if (!targetingKeyResult.ok)
118
+ throw targetingKeyResult.error;
119
+ const targetingKey = targetingKeyResult.value ?? '';
120
+ const attributes = {};
121
+ for (const [k, v] of Object.entries(context.attributes)) {
122
+ if (k === 'groups' || k === 'groupProperties' || k.startsWith('$') || k.startsWith('fireweave.')) {
123
+ continue;
124
+ }
125
+ attributes[k] = v;
126
+ }
127
+ const body = {
128
+ targetingKey,
129
+ flagKeys: [flagKey],
130
+ };
131
+ if (Object.keys(attributes).length > 0)
132
+ body['attributes'] = attributes;
133
+ if (context.groups !== undefined)
134
+ body['groups'] = context.groups;
135
+ if (context.groupProperties !== undefined)
136
+ body['groupProperties'] = context.groupProperties;
137
+ const response = await this.requestJson(EVALUATE_PATH, body, options?.signal);
138
+ const item = response.decisions?.find((d) => d.flagKey === flagKey);
139
+ if (item === undefined) {
140
+ const missing = { found: false };
141
+ if (response.quotaLimited === true)
142
+ missing.quotaLimited = true;
143
+ return missing;
144
+ }
145
+ return this.toResolution(item, response.quotaLimited === true);
146
+ }
147
+ /**
148
+ * Register a user or device so flag rules can target its DURABLE properties.
149
+ *
150
+ * Call once per login / device provisioning, then send the same
151
+ * `targetingKey` on evaluate. Per-request `attributes` still override the
152
+ * stored properties for a single evaluation — the two identity paths compose
153
+ * (see spec/remote-protocol.md § Two identity paths).
154
+ *
155
+ * Never throws for transport failures: registration sits in login paths, and
156
+ * an analytics call must not break sign-in. Retried ONCE when the error
157
+ * taxonomy marks the failure retryable (network / timeout / backend); a
158
+ * rejected payload or bad key is not retried, since it would be rejected
159
+ * identically. The result object reports what happened for callers that
160
+ * want to log it.
161
+ */
162
+ async registerTarget(targetingKey, options = {}) {
163
+ if (this.closed)
164
+ return { ok: false, error: new FireweaveError('AlreadyClosed') };
165
+ if (!this.ready)
166
+ return { ok: false, error: new FireweaveError('NotReady') };
167
+ const targetingKeyResult = validateTargetingKey(targetingKey, true);
168
+ if (!targetingKeyResult.ok)
169
+ return { ok: false, error: targetingKeyResult.error };
170
+ const body = { targetingKey };
171
+ if (options.kind !== undefined)
172
+ body['kind'] = options.kind;
173
+ if (options.environment !== undefined)
174
+ body['environment'] = options.environment;
175
+ if (options.properties !== undefined && Object.keys(options.properties).length > 0) {
176
+ body['properties'] = options.properties;
177
+ }
178
+ let lastError;
179
+ for (let attempt = 0; attempt < 2; attempt += 1) {
180
+ try {
181
+ await this.requestJson(REGISTER_TARGET_PATH, body, options.signal);
182
+ return { ok: true };
183
+ }
184
+ catch (err) {
185
+ lastError =
186
+ err instanceof FireweaveError ? err : new FireweaveError('BackendUnavailable');
187
+ if (!lastError.retryable)
188
+ break;
189
+ }
190
+ }
191
+ return { ok: false, ...(lastError !== undefined ? { error: lastError } : {}) };
192
+ }
193
+ recordExposure(exposure) {
194
+ if (this.closed || !this.ready)
195
+ return;
196
+ const event = {
197
+ type: 'exposure',
198
+ targetingKey: exposure.targetingKey,
199
+ flagKey: exposure.flagKey,
200
+ value: exposure.value,
201
+ };
202
+ if (exposure.variant !== undefined)
203
+ event.variant = exposure.variant;
204
+ if (exposure.rolloutId !== undefined)
205
+ event.rolloutId = exposure.rolloutId;
206
+ if (exposure.changeId !== undefined)
207
+ event.changeId = exposure.changeId;
208
+ if (exposure.stampId !== undefined)
209
+ event.stampId = exposure.stampId;
210
+ this.pending.push(event);
211
+ }
212
+ recordSignal(signal) {
213
+ if (this.closed || !this.ready)
214
+ return;
215
+ const event = {
216
+ type: 'signal',
217
+ targetingKey: signal.targetingKey ?? signal.rolloutId ?? 'fireweave-sdk',
218
+ name: signal.name,
219
+ properties: {
220
+ kind: signal.kind,
221
+ ...(signal.status !== undefined ? { status: signal.status } : {}),
222
+ ...(signal.errorKind !== undefined ? { errorKind: signal.errorKind } : {}),
223
+ ...(signal.message !== undefined ? { message: signal.message } : {}),
224
+ ...(signal.value !== undefined ? { value: signal.value } : {}),
225
+ },
226
+ };
227
+ if (signal.flagKey !== undefined)
228
+ event.flagKey = signal.flagKey;
229
+ if (signal.variant !== undefined)
230
+ event.variant = signal.variant;
231
+ if (signal.rolloutId !== undefined)
232
+ event.rolloutId = signal.rolloutId;
233
+ if (signal.changeId !== undefined)
234
+ event.changeId = signal.changeId;
235
+ if (signal.stampId !== undefined)
236
+ event.stampId = signal.stampId;
237
+ if (signal.timestamp !== undefined)
238
+ event.timestamp = signal.timestamp;
239
+ this.pending.push(event);
240
+ }
241
+ async flush() {
242
+ if (this.closed || !this.ready || this.pending.length === 0)
243
+ return;
244
+ const batch = this.pending.splice(0, this.pending.length);
245
+ try {
246
+ await this.requestJson(CAPTURE_PATH, { events: batch });
247
+ }
248
+ catch {
249
+ // flush failures must not throw into shutdown paths; re-queue best-effort
250
+ this.pending.unshift(...batch);
251
+ }
252
+ }
253
+ async shutdown() {
254
+ if (this.closed)
255
+ return;
256
+ this.closed = true;
257
+ try {
258
+ const timeout = this.options.shutdownTimeoutMs ?? DEFAULT_ADAPTER_SHUTDOWN_TIMEOUT_MS;
259
+ await Promise.race([
260
+ this.flush(),
261
+ new Promise((resolve) => setTimeout(resolve, timeout)),
262
+ ]);
263
+ }
264
+ catch {
265
+ // never throw from shutdown
266
+ }
267
+ this.ready = false;
268
+ }
269
+ features() {
270
+ return {
271
+ remoteEvaluation: true,
272
+ localEvaluation: false,
273
+ localOnly: false,
274
+ exposureEmission: true,
275
+ sideEffectFreeReads: true,
276
+ groupAnalytics: true,
277
+ };
278
+ }
279
+ toResolution(item, quotaLimited) {
280
+ if (item.found === false) {
281
+ const missing = { found: false };
282
+ if (quotaLimited)
283
+ missing.quotaLimited = true;
284
+ return missing;
285
+ }
286
+ const resolution = {
287
+ found: true,
288
+ value: item.value,
289
+ enabled: item.enabled ?? true,
290
+ };
291
+ if (item.variant != null)
292
+ resolution.variant = item.variant;
293
+ const reason = reasonToAdapter(item.reason);
294
+ if (reason !== undefined)
295
+ resolution.reason = reason;
296
+ if (item.payload !== undefined)
297
+ resolution.payload = item.payload;
298
+ const meta = item.flagMetadata ?? {};
299
+ if (typeof meta['fireweave.flagVersion'] === 'number') {
300
+ resolution.version = meta['fireweave.flagVersion'];
301
+ }
302
+ if (typeof meta['fireweave.vendorFlagId'] === 'number') {
303
+ resolution.vendorFlagId = meta['fireweave.vendorFlagId'];
304
+ }
305
+ if (typeof meta['fireweave.reasonCode'] === 'string') {
306
+ resolution.reasonCode = meta['fireweave.reasonCode'];
307
+ }
308
+ if (quotaLimited || meta['fireweave.quotaLimited'] === true) {
309
+ resolution.quotaLimited = true;
310
+ }
311
+ return resolution;
312
+ }
313
+ async requestJson(path, body, outerSignal) {
314
+ const timeoutMs = this.options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
315
+ const controller = new AbortController();
316
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
317
+ const onOuterAbort = () => controller.abort();
318
+ if (outerSignal !== undefined) {
319
+ if (outerSignal.aborted)
320
+ controller.abort();
321
+ else
322
+ outerSignal.addEventListener('abort', onOuterAbort, { once: true });
323
+ }
324
+ try {
325
+ let response;
326
+ try {
327
+ response = await this.fetchImpl(`${this.apiUrl}${path}`, {
328
+ method: 'POST',
329
+ headers: {
330
+ 'content-type': 'application/json',
331
+ authorization: `Bearer ${this.apiKey}`,
332
+ },
333
+ body: JSON.stringify(body),
334
+ signal: controller.signal,
335
+ });
336
+ }
337
+ catch (err) {
338
+ const aborted = err instanceof Error && err.name === 'AbortError';
339
+ throw aborted ? new FireweaveError('Timeout') : new FireweaveError('Network');
340
+ }
341
+ if (response.status >= 400) {
342
+ throw mapHttpStatus(response.status);
343
+ }
344
+ let parsed;
345
+ try {
346
+ parsed = await response.json();
347
+ }
348
+ catch {
349
+ throw new FireweaveError('MalformedResponse');
350
+ }
351
+ return parsed;
352
+ }
353
+ finally {
354
+ clearTimeout(timer);
355
+ if (outerSignal !== undefined) {
356
+ outerSignal.removeEventListener('abort', onOuterAbort);
357
+ }
358
+ }
359
+ }
360
+ }
361
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../../../src/infrastructure/adapters/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAWlE,MAAM,mCAAmC,GAAG,KAAK,CAAC;AAClD,MAAM,0BAA0B,GAAG,IAAI,CAAC;AACxC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAC3C,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAyEpD,SAAS,aAAa,CAAC,MAAc;IACnC,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC,CAAC;IAChE,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,IAAI,cAAc,CAAC,eAAe,CAAC,C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AAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC;gBAClE,MAAM,OAAO,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;YAChF,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;gBAC3B,MAAM,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACvC,CAAC;YACD,IAAI,MAAe,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACjC,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,cAAc,CAAC,mBAAmB,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,MAAW,CAAC;QACrB,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Canonical default host allowlist.
3
+ *
4
+ * v3 replaced the third-party analytics hostnames this list used to carry
5
+ * (ADR-0006) with Fireweave's own fw-server hostnames. The security property is
6
+ * unchanged — an unconfigured allowlist still denies everything it does not name
7
+ * — but the *contents* changed: code doing
8
+ * `allowedHosts: [...DEFAULT_ALLOWED_HOSTS, …]` no longer reaches the former
9
+ * vendor endpoints, which is the intent.
10
+ */
11
+ export declare const DEFAULT_ALLOWED_HOSTS: readonly string[];
12
+ /** True for loopback hostnames (http and test stubs are permitted here). */
13
+ export declare function isLoopbackHostname(hostname: string): boolean;
14
+ /**
15
+ * Validate a backend host URL against the allowlist.
16
+ * Throws FireweaveError('Configuration') — fixed message, no host echo.
17
+ */
18
+ export declare function assertHostAllowed(host: string, allowedHosts?: readonly string[]): void;
19
+ //# sourceMappingURL=hosts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosts.d.ts","sourceRoot":"","sources":["../../src/infrastructure/hosts.ts"],"names":[],"mappings":"AAcA;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAMjD,CAAC;AAEH,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO5D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CA2BtF"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Backend host allowlist (SSRF guard, release-blockers H-1).
3
+ *
4
+ * The allowlist is ON by default: when no explicit `allowedHosts` is
5
+ * configured, only the canonical Fireweave hosts plus loopback are permitted,
6
+ * so a typo'd or tampered `host` cannot be aimed at cloud metadata endpoints.
7
+ * Custom / self-hosted deployments require an explicit `allowedHosts` entry;
8
+ * `['*']` opts out entirely.
9
+ *
10
+ * Scheme policy: https is required for non-loopback hosts; plain http is
11
+ * permitted on loopback only (the repo's test-server stub).
12
+ */
13
+ import { FireweaveError } from '../domain/errors.js';
14
+ /**
15
+ * Canonical default host allowlist.
16
+ *
17
+ * v3 replaced the third-party analytics hostnames this list used to carry
18
+ * (ADR-0006) with Fireweave's own fw-server hostnames. The security property is
19
+ * unchanged — an unconfigured allowlist still denies everything it does not name
20
+ * — but the *contents* changed: code doing
21
+ * `allowedHosts: [...DEFAULT_ALLOWED_HOSTS, …]` no longer reaches the former
22
+ * vendor endpoints, which is the intent.
23
+ */
24
+ export const DEFAULT_ALLOWED_HOSTS = Object.freeze([
25
+ 'app-server.fireweave.ai',
26
+ 'staging-app-server.fireweave.ai',
27
+ 'localhost',
28
+ '127.0.0.1',
29
+ '::1',
30
+ ]);
31
+ /** True for loopback hostnames (http and test stubs are permitted here). */
32
+ export function isLoopbackHostname(hostname) {
33
+ return (hostname === 'localhost' ||
34
+ hostname === '127.0.0.1' ||
35
+ hostname === '::1' ||
36
+ hostname === '[::1]');
37
+ }
38
+ /**
39
+ * Validate a backend host URL against the allowlist.
40
+ * Throws FireweaveError('Configuration') — fixed message, no host echo.
41
+ */
42
+ export function assertHostAllowed(host, allowedHosts) {
43
+ let url;
44
+ try {
45
+ url = new URL(host);
46
+ }
47
+ catch {
48
+ throw new FireweaveError('Configuration');
49
+ }
50
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
51
+ throw new FireweaveError('Configuration');
52
+ }
53
+ const loopback = isLoopbackHostname(url.hostname);
54
+ if (url.protocol === 'http:' && !loopback) {
55
+ // https required for anything that leaves the machine.
56
+ throw new FireweaveError('Configuration');
57
+ }
58
+ const list = allowedHosts !== undefined && allowedHosts.length > 0 ? allowedHosts : DEFAULT_ALLOWED_HOSTS;
59
+ if (list.includes('*'))
60
+ return; // explicit opt-out
61
+ const allowed = list.some((h) => url.hostname === h ||
62
+ (h === 'localhost' && loopback) ||
63
+ (h === '::1' && url.hostname === '[::1]'));
64
+ if (!allowed) {
65
+ throw new FireweaveError('Configuration');
66
+ }
67
+ }
68
+ //# sourceMappingURL=hosts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosts.js","sourceRoot":"","sources":["../../src/infrastructure/hosts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACpE,yBAAyB;IACzB,iCAAiC;IACjC,WAAW;IACX,WAAW;IACX,KAAK;CACN,CAAC,CAAC;AAEH,4EAA4E;AAC5E,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,O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O,EAAE,CAAC;QACb,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@fireweaveai/server-sdk",
3
+ "version": "2.2.1-staging.1",
4
+ "description": "Fireweave release-engineering SDK for server runtimes (Node, Bun, Deno): control points and target registration. Zero runtime dependencies (spec v0.1.0).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=20.20"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/FireWeave-HQ/fireweave-sdk.git",
13
+ "directory": "sdks/node"
14
+ },
15
+ "homepage": "https://github.com/FireWeave-HQ/fireweave-sdk/tree/master/sdks/node#readme",
16
+ "bugs": "https://github.com/FireWeave-HQ/fireweave-sdk/issues",
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "clean": "rm -rf dist",
30
+ "build": "npm run clean && tsc -p tsconfig.json",
31
+ "typecheck": "npm run build && tsc -p tsconfig.json --noEmit && tsc -p test/tsconfig.json --noEmit",
32
+ "test": "npm run test:unit && npm run test:integration && npm run test:compat",
33
+ "test:unit": "npm run build && tsx --test test/unit/*.test.ts",
34
+ "test:integration": "npm run build && tsx --test test/integration/*.test.ts",
35
+ "test:compat": "npm run build && tsx --test test/compat/*.compat.test.ts",
36
+ "conformance": "npm run build && tsx test/conformance/run.ts",
37
+ "smoke": "npm run build && node scripts/smoke-runtimes.mjs",
38
+ "verify": "npm run typecheck && npm run test && npm run conformance && npm run smoke"
39
+ },
40
+ "devDependencies": {
41
+ "@openfeature/server-sdk": "1.22.0",
42
+ "@types/node": "^24.0.0",
43
+ "tsx": "^4.20.3",
44
+ "typescript": "^5.6.0"
45
+ },
46
+ "keywords": [
47
+ "fireweave",
48
+ "release-engineering",
49
+ "progressive-delivery",
50
+ "control-points",
51
+ "feature-flags",
52
+ "server",
53
+ "bun",
54
+ "deno"
55
+ ]
56
+ }