@fireweaveai/web-sdk-cjs 0.0.0-reserve.0 → 0.0.0-stage
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/README.md +2 -51
- package/package.json +4 -66
- package/LICENSE +0 -21
- package/dist/application/client.d.ts +0 -104
- package/dist/application/client.js +0 -147
- package/dist/application/mode.d.ts +0 -99
- package/dist/application/mode.js +0 -101
- package/dist/application/ports.d.ts +0 -101
- package/dist/application/ports.js +0 -2
- package/dist/application/runtime.d.ts +0 -70
- package/dist/application/runtime.js +0 -348
- package/dist/build/node/define.d.ts +0 -14
- package/dist/build/node/define.js +0 -38
- package/dist/build/node/shared.d.ts +0 -19
- package/dist/build/node/shared.js +0 -39
- package/dist/build/node/vite.d.ts +0 -53
- package/dist/build/node/vite.js +0 -106
- package/dist/build/src/start/build-info.d.ts +0 -2
- package/dist/build/src/start/build-info.js +0 -9
- package/dist/build/src/start/names.d.ts +0 -38
- package/dist/build/src/start/names.js +0 -41
- package/dist/build/src/start/policy.d.ts +0 -70
- package/dist/build/src/start/policy.js +0 -128
- package/dist/domain/context.d.ts +0 -51
- package/dist/domain/context.js +0 -72
- package/dist/domain/errors.d.ts +0 -36
- package/dist/domain/errors.js +0 -97
- package/dist/domain/target.d.ts +0 -2
- package/dist/domain/target.js +0 -2
- package/dist/domain/types.d.ts +0 -89
- package/dist/domain/types.js +0 -10
- package/dist/domain/validation.d.ts +0 -128
- package/dist/domain/validation.js +0 -358
- package/dist/index.d.ts +0 -50
- package/dist/index.js +0 -66
- package/dist/infrastructure/adapters/inmemory.d.ts +0 -50
- package/dist/infrastructure/adapters/inmemory.js +0 -94
- package/dist/infrastructure/adapters/local.d.ts +0 -79
- package/dist/infrastructure/adapters/local.js +0 -98
- package/dist/infrastructure/adapters/remote.d.ts +0 -44
- package/dist/infrastructure/adapters/remote.js +0 -329
- package/dist/infrastructure/hosts.d.ts +0 -10
- package/dist/infrastructure/hosts.js +0 -84
- package/dist/start/build-info.d.ts +0 -2
- package/dist/start/build-info.js +0 -9
- package/dist/start/control-points.d.ts +0 -24
- package/dist/start/control-points.js +0 -61
- package/dist/start/fw.d.ts +0 -42
- package/dist/start/fw.js +0 -137
- package/dist/start/identity.d.ts +0 -19
- package/dist/start/identity.js +0 -93
- package/dist/start/index.d.ts +0 -34
- package/dist/start/index.js +0 -38
- package/dist/start/names.d.ts +0 -38
- package/dist/start/names.js +0 -41
- package/dist/start/policy.d.ts +0 -70
- package/dist/start/policy.js +0 -128
- package/dist/start/state.d.ts +0 -103
- package/dist/start/state.js +0 -375
package/dist/domain/errors.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Error taxonomy for the browser SDK.
|
|
4
|
-
*
|
|
5
|
-
* Same kinds and same OpenFeature mapping as the server SDK, because the wire
|
|
6
|
-
* protocol and the failure modes are the same — a 401 is a 401 whether it is a
|
|
7
|
-
* server or a browser asking. Reimplemented here rather than shared so the
|
|
8
|
-
* browser package keeps zero cross-package coupling and can be audited on its
|
|
9
|
-
* own; `spec/errors.schema.json` is the source both follow.
|
|
10
|
-
*
|
|
11
|
-
* Messages are FIXED per kind. A browser error is visible in a devtools console
|
|
12
|
-
* on a machine we do not control, so nothing host-, key-, or response-derived
|
|
13
|
-
* is ever interpolated into one.
|
|
14
|
-
*/
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.FireweaveError = exports.ERROR_TAXONOMY = void 0;
|
|
17
|
-
exports.isFireweaveError = isFireweaveError;
|
|
18
|
-
exports.ERROR_TAXONOMY = Object.freeze({
|
|
19
|
-
Configuration: {
|
|
20
|
-
message: 'invalid configuration',
|
|
21
|
-
openFeatureErrorCode: 'PROVIDER_FATAL',
|
|
22
|
-
retryable: false,
|
|
23
|
-
},
|
|
24
|
-
Authentication: {
|
|
25
|
-
message: 'authentication failed',
|
|
26
|
-
openFeatureErrorCode: 'PROVIDER_FATAL',
|
|
27
|
-
retryable: false,
|
|
28
|
-
},
|
|
29
|
-
Authorization: {
|
|
30
|
-
message: 'not authorized',
|
|
31
|
-
openFeatureErrorCode: 'PROVIDER_FATAL',
|
|
32
|
-
retryable: false,
|
|
33
|
-
},
|
|
34
|
-
Network: { message: 'network error', openFeatureErrorCode: 'GENERAL', retryable: true },
|
|
35
|
-
Timeout: { message: 'request timed out', openFeatureErrorCode: 'GENERAL', retryable: true },
|
|
36
|
-
RateLimited: { message: 'rate limited', openFeatureErrorCode: 'GENERAL', retryable: true },
|
|
37
|
-
BackendUnavailable: {
|
|
38
|
-
message: 'backend unavailable',
|
|
39
|
-
openFeatureErrorCode: 'GENERAL',
|
|
40
|
-
retryable: true,
|
|
41
|
-
},
|
|
42
|
-
MalformedResponse: {
|
|
43
|
-
message: 'malformed response',
|
|
44
|
-
openFeatureErrorCode: 'PARSE_ERROR',
|
|
45
|
-
retryable: false,
|
|
46
|
-
},
|
|
47
|
-
InvalidContext: {
|
|
48
|
-
message: 'invalid evaluation context',
|
|
49
|
-
openFeatureErrorCode: 'INVALID_CONTEXT',
|
|
50
|
-
retryable: false,
|
|
51
|
-
},
|
|
52
|
-
ControlPointNotFound: {
|
|
53
|
-
message: 'flag not found',
|
|
54
|
-
openFeatureErrorCode: 'FLAG_NOT_FOUND',
|
|
55
|
-
retryable: false,
|
|
56
|
-
},
|
|
57
|
-
TypeMismatch: {
|
|
58
|
-
message: 'type mismatch',
|
|
59
|
-
openFeatureErrorCode: 'TYPE_MISMATCH',
|
|
60
|
-
retryable: false,
|
|
61
|
-
},
|
|
62
|
-
NotReady: {
|
|
63
|
-
message: 'provider not ready',
|
|
64
|
-
openFeatureErrorCode: 'PROVIDER_NOT_READY',
|
|
65
|
-
retryable: true,
|
|
66
|
-
},
|
|
67
|
-
AlreadyClosed: {
|
|
68
|
-
message: 'provider already closed',
|
|
69
|
-
openFeatureErrorCode: 'PROVIDER_FATAL',
|
|
70
|
-
retryable: false,
|
|
71
|
-
},
|
|
72
|
-
UnsupportedCapability: {
|
|
73
|
-
message: 'unsupported capability',
|
|
74
|
-
openFeatureErrorCode: 'GENERAL',
|
|
75
|
-
retryable: false,
|
|
76
|
-
},
|
|
77
|
-
Internal: { message: 'internal error', openFeatureErrorCode: 'GENERAL', retryable: false },
|
|
78
|
-
});
|
|
79
|
-
class FireweaveError extends Error {
|
|
80
|
-
kind;
|
|
81
|
-
openFeatureErrorCode;
|
|
82
|
-
retryable;
|
|
83
|
-
metadata;
|
|
84
|
-
constructor(kind, options = {}) {
|
|
85
|
-
const spec = exports.ERROR_TAXONOMY[kind];
|
|
86
|
-
super(spec.message, options.cause !== undefined ? { cause: options.cause } : undefined);
|
|
87
|
-
this.name = 'FireweaveError';
|
|
88
|
-
this.kind = kind;
|
|
89
|
-
this.openFeatureErrorCode = options.openFeatureErrorCode ?? spec.openFeatureErrorCode;
|
|
90
|
-
this.retryable = spec.retryable;
|
|
91
|
-
this.metadata = { ...(options.metadata ?? {}) };
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.FireweaveError = FireweaveError;
|
|
95
|
-
function isFireweaveError(value) {
|
|
96
|
-
return value instanceof FireweaveError;
|
|
97
|
-
}
|
package/dist/domain/target.d.ts
DELETED
package/dist/domain/target.js
DELETED
package/dist/domain/types.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical data shapes, mirroring `spec/decision.schema.json`,
|
|
3
|
-
* `spec/signal.schema.json`, and `spec/release-context.schema.json`.
|
|
4
|
-
*
|
|
5
|
-
* Identical in meaning to the server SDK's `types.ts`. Duplicated rather than
|
|
6
|
-
* shared so the browser package has no cross-package dependency to audit; the
|
|
7
|
-
* JSON Schemas in `spec/` are what keep the two honest.
|
|
8
|
-
*/
|
|
9
|
-
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
10
|
-
[key: string]: JsonValue;
|
|
11
|
-
};
|
|
12
|
-
export type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
|
|
13
|
-
export type DecisionReason = 'STATIC' | 'DEFAULT' | 'TARGETING_MATCH' | 'SPLIT' | 'CACHED' | 'STALE' | 'DISABLED' | 'UNKNOWN' | 'ERROR';
|
|
14
|
-
export interface Decision {
|
|
15
|
-
readonly controlPointKey: string;
|
|
16
|
-
readonly value: JsonValue;
|
|
17
|
-
readonly reason: DecisionReason;
|
|
18
|
-
readonly variant?: string;
|
|
19
|
-
readonly errorCode?: string;
|
|
20
|
-
readonly errorKind?: string;
|
|
21
|
-
readonly errorMessage?: string;
|
|
22
|
-
readonly metadata?: Record<string, string | number | boolean>;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A browser lifecycle has one state the server does not: STALE.
|
|
26
|
-
*
|
|
27
|
-
* It means "initialize completed, but the prefetch did not, so reads are being
|
|
28
|
-
* served from an empty or outdated cache". Collapsing it into READY would make
|
|
29
|
-
* a failed boot indistinguishable from a successful one — which is the specific
|
|
30
|
-
* failure this SDK is written to avoid.
|
|
31
|
-
*/
|
|
32
|
-
export type LifecycleState = 'UNINITIALIZED' | 'INITIALIZING' | 'READY' | 'STALE' | 'ERROR' | 'SHUTDOWN';
|
|
33
|
-
export interface CanonicalContext {
|
|
34
|
-
readonly targetingKey?: string;
|
|
35
|
-
readonly attributes: Record<string, JsonValue>;
|
|
36
|
-
readonly groups?: Record<string, string>;
|
|
37
|
-
readonly groupProperties?: Record<string, Record<string, JsonValue>>;
|
|
38
|
-
}
|
|
39
|
-
export type SignalKind = 'health' | 'error' | 'metric' | 'outcome';
|
|
40
|
-
export interface Signal {
|
|
41
|
-
readonly kind: SignalKind;
|
|
42
|
-
readonly name: string;
|
|
43
|
-
readonly targetingKey?: string;
|
|
44
|
-
readonly controlPointKey?: string;
|
|
45
|
-
readonly variant?: string;
|
|
46
|
-
readonly status?: string;
|
|
47
|
-
readonly errorKind?: string;
|
|
48
|
-
readonly message?: string;
|
|
49
|
-
readonly value?: number;
|
|
50
|
-
readonly rolloutId?: string;
|
|
51
|
-
readonly changeId?: string;
|
|
52
|
-
readonly stampId?: string;
|
|
53
|
-
readonly timestamp?: string;
|
|
54
|
-
}
|
|
55
|
-
export interface Exposure {
|
|
56
|
-
readonly controlPointKey: string;
|
|
57
|
-
readonly targetingKey: string;
|
|
58
|
-
readonly value: JsonValue;
|
|
59
|
-
readonly variant?: string;
|
|
60
|
-
readonly rolloutId?: string;
|
|
61
|
-
readonly changeId?: string;
|
|
62
|
-
readonly stampId?: string;
|
|
63
|
-
}
|
|
64
|
-
export type ReleaseState = 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED';
|
|
65
|
-
export interface ReleaseContext {
|
|
66
|
-
readonly rolloutId?: string;
|
|
67
|
-
readonly changeId?: string;
|
|
68
|
-
readonly stampId?: string;
|
|
69
|
-
readonly environment?: string;
|
|
70
|
-
}
|
|
71
|
-
export interface Capabilities {
|
|
72
|
-
readonly static: {
|
|
73
|
-
readonly language: 'web';
|
|
74
|
-
readonly sdkVersion: string;
|
|
75
|
-
readonly specVersion: string;
|
|
76
|
-
readonly openFeature: {
|
|
77
|
-
readonly specFloor: string;
|
|
78
|
-
readonly providerName: string;
|
|
79
|
-
readonly serverOnly: boolean;
|
|
80
|
-
};
|
|
81
|
-
readonly features: Record<string, boolean>;
|
|
82
|
-
};
|
|
83
|
-
readonly runtime: {
|
|
84
|
-
readonly backend: 'fireweave' | 'inmemory' | 'none' | 'other';
|
|
85
|
-
readonly lifecycle: LifecycleState;
|
|
86
|
-
readonly features: Record<string, boolean>;
|
|
87
|
-
readonly limits: Record<string, number>;
|
|
88
|
-
};
|
|
89
|
-
}
|
package/dist/domain/types.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Canonical data shapes, mirroring `spec/decision.schema.json`,
|
|
4
|
-
* `spec/signal.schema.json`, and `spec/release-context.schema.json`.
|
|
5
|
-
*
|
|
6
|
-
* Identical in meaning to the server SDK's `types.ts`. Duplicated rather than
|
|
7
|
-
* shared so the browser package has no cross-package dependency to audit; the
|
|
8
|
-
* JSON Schemas in `spec/` are what keep the two honest.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fireweave web SDK validation — pure, total functions per
|
|
3
|
-
* spec/control-points.md "Validation, before any I/O" and spec/modes.md
|
|
4
|
-
* "Initialisation validation".
|
|
5
|
-
*
|
|
6
|
-
* Ported from sdks/node/src/domain/validation.ts (the reference
|
|
7
|
-
* implementation) — same five validators, same `Validated<T>` discipline,
|
|
8
|
-
* same malformed-key → ControlPointNotFound mapping. Reimplemented here rather than
|
|
9
|
-
* shared so the browser package keeps zero cross-package dependency to
|
|
10
|
-
* audit — the same reasoning ADR-0009 gives for duplicating types.ts/errors.ts
|
|
11
|
-
* extends to this module.
|
|
12
|
-
*
|
|
13
|
-
* Every read-path validator here (`validateControlPointKey`,
|
|
14
|
-
* `validateDefaultValue`, `validateContext`) returns `Validated<T>` instead
|
|
15
|
-
* of throwing. `FireweaveWebRuntime.evaluateSync` runs them, in the fixed
|
|
16
|
-
* order the spec names — key, default-vs-type, context, lifecycle — and
|
|
17
|
-
* degrades to the caller's default on the first failure; it NEVER throws
|
|
18
|
-
* (spec/control-points.md "Return discipline — never throw into a read
|
|
19
|
-
* path"). `validateInitOptions` is the one exception (spec/modes.md
|
|
20
|
-
* "Initialisation validation"): it still returns `Validated<T>` — mode.ts is
|
|
21
|
-
* what converts a failed result into the throw spec/modes.md requires.
|
|
22
|
-
*
|
|
23
|
-
* Note: unlike node, web's `FireweaveError` has no custom-message support —
|
|
24
|
-
* messages are FIXED per kind by design, because a browser error is visible
|
|
25
|
-
* in a devtools console on a machine this package does not control
|
|
26
|
-
* (errors.ts's own doc comment). So every branch below that would carry a
|
|
27
|
-
* distinct node message instead just uses the taxonomy's fixed message for
|
|
28
|
-
* its kind.
|
|
29
|
-
*/
|
|
30
|
-
import { FireweaveError } from './errors.js';
|
|
31
|
-
import type { ContextPolicy } from './context.js';
|
|
32
|
-
import type { CanonicalContext, JsonValue } from './types.js';
|
|
33
|
-
/** Result of a pure validator: success carries the validated value, failure the canonical error. */
|
|
34
|
-
export type Validated<T> = {
|
|
35
|
-
ok: true;
|
|
36
|
-
value: T;
|
|
37
|
-
} | {
|
|
38
|
-
ok: false;
|
|
39
|
-
error: FireweaveError;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* key — non-empty, ≤256 characters, no control characters
|
|
43
|
-
* (spec/control-points.md rule 1, the first check in the fixed order).
|
|
44
|
-
*
|
|
45
|
-
* No taxonomy kind names "malformed key" explicitly (the return-discipline
|
|
46
|
-
* table's closest row is "key unknown to the backend" → ControlPointNotFound):
|
|
47
|
-
* controller-ruled interim mapping (mirrors node's domain/validation.ts
|
|
48
|
-
* verbatim) — the 15-kind taxonomy in errors.schema.json is frozen at
|
|
49
|
-
* exactly 15 entries, `InvalidContext` is textually scoped to the evaluation
|
|
50
|
-
* *context* (not the key), and the schema already maps another non-literal
|
|
51
|
-
* case — quota-limited responses — onto `ControlPointNotFound` rather than adding a
|
|
52
|
-
* kind for it. `ControlPointNotFound` is therefore the least-wrong existing kind,
|
|
53
|
-
* not a literal fit. Other-language implementations copying node as the
|
|
54
|
-
* reference SHOULD use the same mapping rather than each independently
|
|
55
|
-
* guessing a different one.
|
|
56
|
-
*/
|
|
57
|
-
export declare function validateControlPointKey(key: string): Validated<string>;
|
|
58
|
-
export type ExpectedFlagType = 'boolean' | 'string' | 'number' | 'object';
|
|
59
|
-
/**
|
|
60
|
-
* Whether `value` matches the shape `expected` names. Shared by
|
|
61
|
-
* {@link validateDefaultValue} (the caller's default, before any read) and
|
|
62
|
-
* `FireweaveWebRuntime.evaluateSync`'s post-cache-lookup check (the backend's
|
|
63
|
-
* resolved value, from the prefetched cache) — same predicate, two different
|
|
64
|
-
* inputs.
|
|
65
|
-
*/
|
|
66
|
-
export declare function matchesExpectedType(value: JsonValue | undefined, expected: ExpectedFlagType): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* default vs type — e.g. `getBooleanValue` with a non-boolean default is
|
|
69
|
-
* TypeMismatch (spec/control-points.md rule 2, checked before any read).
|
|
70
|
-
*/
|
|
71
|
-
export declare function validateDefaultValue(expectedType: ExpectedFlagType, defaultValue: JsonValue): Validated<JsonValue>;
|
|
72
|
-
/**
|
|
73
|
-
* targetingKey: "An SDK MUST NOT invent one: a missing targeting key is
|
|
74
|
-
* InvalidContext where the evaluation needs it, never a generated anonymous
|
|
75
|
-
* id" (spec/control-points.md "Context"). `required` is call-site policy —
|
|
76
|
-
* the remote adapter always requires one for `prefetch`/`registerTarget`; the
|
|
77
|
-
* generic context pipeline ({@link validateContext}) only does when
|
|
78
|
-
* `ContextPolicy.requireTargetingKey` opts in (unset by default here — web's
|
|
79
|
-
* targetingKey requirement is enforced at the remote adapter, not the
|
|
80
|
-
* general-purpose context validator every read runs).
|
|
81
|
-
*/
|
|
82
|
-
export declare function validateTargetingKey(targetingKey: string | undefined, required: boolean): Validated<string | undefined>;
|
|
83
|
-
/**
|
|
84
|
-
* context — depth, key count, value size, reserved keys
|
|
85
|
-
* (evaluation-context.schema.json) (spec/control-points.md rule 3). Also
|
|
86
|
-
* enforces `policy.requireTargetingKey` via {@link validateTargetingKey}, and
|
|
87
|
-
* — on success — extracts `groups`/`groupProperties` the same way the former
|
|
88
|
-
* `canonicalizeContext` did.
|
|
89
|
-
*
|
|
90
|
-
* `groups`/`groupProperties` (and their `fireweave.*` aliases) are pulled out
|
|
91
|
-
* BEFORE the attribute-count/size limit checks run, matching the pre-existing
|
|
92
|
-
* behaviour this module replaces: they are not ordinary attributes and were
|
|
93
|
-
* never counted against those limits.
|
|
94
|
-
*
|
|
95
|
-
* `merged` is the already-merged (global → invocation) raw input; merging
|
|
96
|
-
* itself (`mergeContexts`) lives in context.ts and carries no validation
|
|
97
|
-
* concerns of its own.
|
|
98
|
-
*/
|
|
99
|
-
export declare function validateContext(merged: {
|
|
100
|
-
targetingKey?: string;
|
|
101
|
-
attributes: Record<string, unknown>;
|
|
102
|
-
}, policy: ContextPolicy): Validated<CanonicalContext>;
|
|
103
|
-
/**
|
|
104
|
-
* Throwing wrapper around {@link validateContext}, kept for callers that
|
|
105
|
-
* genuinely want a throw (`FireweaveWebRuntime.refresh`, which is already
|
|
106
|
-
* inside its own try/catch feeding lifecycle state — see runtime.ts). Read
|
|
107
|
-
* paths do not use this — they call {@link validateContext} directly so a
|
|
108
|
-
* failure degrades instead of throwing.
|
|
109
|
-
*/
|
|
110
|
-
export declare function canonicalizeContext(merged: {
|
|
111
|
-
targetingKey?: string;
|
|
112
|
-
attributes: Record<string, unknown>;
|
|
113
|
-
}, policy: ContextPolicy): CanonicalContext;
|
|
114
|
-
/**
|
|
115
|
-
* Initialisation-validation table (spec/modes.md), rows 1, 2 and 4:
|
|
116
|
-
* - `mode` absent or unrecognised
|
|
117
|
-
* - `mode: 'remote'` with `apiKey` or `apiUrl` missing/blank
|
|
118
|
-
* - `mode: 'local'` with credentials supplied (a config half-migrated from
|
|
119
|
-
* remote to local reads as neither, silently — reject it instead)
|
|
120
|
-
*
|
|
121
|
-
* Row 3 ("apiUrl fails the host allowlist") is intentionally NOT checked
|
|
122
|
-
* here — mode.ts validates it directly via `assertHostAllowed` before
|
|
123
|
-
* calling into the (deliberately non-throwing) runtime; see mode.ts's module
|
|
124
|
-
* doc comment for why web cannot rely on the runtime the way node does.
|
|
125
|
-
*/
|
|
126
|
-
export declare function validateInitOptions<T extends {
|
|
127
|
-
readonly mode?: unknown;
|
|
128
|
-
}>(options: T): Validated<T>;
|