@omniretail/omniflags-core 1.0.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/README.md +143 -0
- package/dist/bucket.d.ts +23 -0
- package/dist/bucket.js +50 -0
- package/dist/bucket.js.map +1 -0
- package/dist/cache.d.ts +12 -0
- package/dist/cache.js +30 -0
- package/dist/cache.js.map +1 -0
- package/dist/client.d.ts +46 -0
- package/dist/client.js +265 -0
- package/dist/client.js.map +1 -0
- package/dist/context.d.ts +11 -0
- package/dist/context.js +31 -0
- package/dist/context.js.map +1 -0
- package/dist/evaluator.d.ts +6 -0
- package/dist/evaluator.js +252 -0
- package/dist/evaluator.js.map +1 -0
- package/dist/http-provider.d.ts +15 -0
- package/dist/http-provider.js +110 -0
- package/dist/http-provider.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics.d.ts +20 -0
- package/dist/metrics.js +89 -0
- package/dist/metrics.js.map +1 -0
- package/dist/types.d.ts +135 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +29 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the provider encounters a permanent, non-recoverable error
|
|
3
|
+
* (e.g. 404 — invalid SDK key). The client will stop polling on this error.
|
|
4
|
+
*/
|
|
5
|
+
export declare class PermanentProviderError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export type FlagType = "boolean" | "string" | "number" | "json";
|
|
9
|
+
export type ClauseOp = "eq" | "neq" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | "gt" | "gte" | "lt" | "lte" | "exists" | "not_exists";
|
|
10
|
+
export type EvaluationReason = "STATIC" | "DEFAULT" | "TARGETING_MATCH" | "SPLIT" | "ROLLOUT" | "PREREQUISITE_FAILED" | "ERROR" | "STALE";
|
|
11
|
+
export type ErrorCode = "FLAG_NOT_FOUND" | "TYPE_MISMATCH" | "PROVIDER_NOT_READY" | "PROVIDER_FATAL" | "MISSING_TARGETING_KEY" | "INVALID_CONTEXT" | "PARSE_ERROR" | "STALE_CONFIG" | "UNKNOWN";
|
|
12
|
+
export type ProviderEvent = "PROVIDER_READY" | "PROVIDER_ERROR" | "PROVIDER_CONFIGURATION_CHANGED" | "PROVIDER_STALE" | "PROVIDER_LOADING_STATE_CHANGED";
|
|
13
|
+
export type FlagOrigin = "NONE" | "CACHE" | "SERVER";
|
|
14
|
+
export type LoadingState = {
|
|
15
|
+
/** True while a network request is in flight. */
|
|
16
|
+
isFetching: boolean;
|
|
17
|
+
/** True until any flag data is available (cache or server). */
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
/** Where the current flags came from. */
|
|
20
|
+
origin: FlagOrigin;
|
|
21
|
+
/** Last fetch error, reset on the next successful fetch. */
|
|
22
|
+
error: Error | null;
|
|
23
|
+
};
|
|
24
|
+
export interface Clause {
|
|
25
|
+
attribute: string;
|
|
26
|
+
op: ClauseOp;
|
|
27
|
+
values: unknown[];
|
|
28
|
+
caseSensitive?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface RolloutSplit {
|
|
31
|
+
variant: string;
|
|
32
|
+
weight: number;
|
|
33
|
+
}
|
|
34
|
+
export interface RuleSchedule {
|
|
35
|
+
start?: string;
|
|
36
|
+
end?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface FlagRule {
|
|
39
|
+
ruleId: string;
|
|
40
|
+
clauses: Clause[];
|
|
41
|
+
rollout?: RolloutSplit[];
|
|
42
|
+
serve?: string;
|
|
43
|
+
schedule?: RuleSchedule;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Per-environment flag config as received from the distribution API.
|
|
47
|
+
* Matches evaluation-spec v2 §2.2.
|
|
48
|
+
*/
|
|
49
|
+
export interface FlagConfig {
|
|
50
|
+
key: string;
|
|
51
|
+
type: FlagType;
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
defaultValue: string;
|
|
54
|
+
variations: Record<string, string>;
|
|
55
|
+
rules?: FlagRule[];
|
|
56
|
+
rolloutPercentage?: number;
|
|
57
|
+
salt?: string;
|
|
58
|
+
revision?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface FlagSnapshot {
|
|
61
|
+
envKey: string;
|
|
62
|
+
revision: number;
|
|
63
|
+
generatedAt: string;
|
|
64
|
+
staleAt?: string;
|
|
65
|
+
/** Server-driven polling interval in ms. SDKs must use this value. */
|
|
66
|
+
pollingIntervalMs: number;
|
|
67
|
+
/** Server-driven metrics flush interval in ms. */
|
|
68
|
+
metricsFlushIntervalMs: number;
|
|
69
|
+
/** Server-driven max events per metrics flush payload. */
|
|
70
|
+
metricsMaxBatchSize: number;
|
|
71
|
+
flags: FlagConfig[];
|
|
72
|
+
}
|
|
73
|
+
export interface EvaluationContext {
|
|
74
|
+
agentId?: number;
|
|
75
|
+
customerId?: number;
|
|
76
|
+
country?: string;
|
|
77
|
+
lga?: string;
|
|
78
|
+
city?: string;
|
|
79
|
+
businessId?: number;
|
|
80
|
+
sourceId?: number;
|
|
81
|
+
businessBranchId?: number;
|
|
82
|
+
stockPointId?: string;
|
|
83
|
+
customerRef?: string;
|
|
84
|
+
walletId?: string;
|
|
85
|
+
omnipayId?: number;
|
|
86
|
+
terminalId?: string;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
export interface EvaluationResult<T = unknown> {
|
|
90
|
+
value: T;
|
|
91
|
+
variant: string | null;
|
|
92
|
+
reason: EvaluationReason;
|
|
93
|
+
ruleId: string | null;
|
|
94
|
+
errorCode: ErrorCode | null;
|
|
95
|
+
}
|
|
96
|
+
export interface Hook {
|
|
97
|
+
before?(flagKey: string, context: EvaluationContext): void;
|
|
98
|
+
after?(flagKey: string, result: EvaluationResult): void;
|
|
99
|
+
error?(flagKey: string, error: unknown): void;
|
|
100
|
+
}
|
|
101
|
+
export interface CacheAdapter {
|
|
102
|
+
get(key: string): Promise<string | null>;
|
|
103
|
+
set(key: string, value: string): Promise<void>;
|
|
104
|
+
remove(key: string): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
export type ProviderStatus = "not_ready" | "ready" | "error" | "stale";
|
|
107
|
+
export interface FlagProvider {
|
|
108
|
+
readonly status: ProviderStatus;
|
|
109
|
+
/** Initialize and return the first snapshot. sdkKey is the only credential needed. */
|
|
110
|
+
initialize(sdkKey: string): Promise<FlagSnapshot>;
|
|
111
|
+
refresh?(sdkKey: string): Promise<FlagSnapshot | null>;
|
|
112
|
+
shutdown?(): Promise<void>;
|
|
113
|
+
onEvent?(handler: (event: ProviderEvent, detail?: unknown) => void): void;
|
|
114
|
+
}
|
|
115
|
+
export interface OmniFlagsOptions {
|
|
116
|
+
/** The SDK key issued for your application and environment. */
|
|
117
|
+
sdkKey: string;
|
|
118
|
+
/** Evaluation lifecycle hooks. */
|
|
119
|
+
hooks?: Hook[];
|
|
120
|
+
/**
|
|
121
|
+
* Custom provider — for testing or advanced use cases only.
|
|
122
|
+
* In production the SDK uses its built-in CDN-backed provider.
|
|
123
|
+
*/
|
|
124
|
+
provider?: FlagProvider;
|
|
125
|
+
}
|
|
126
|
+
export interface MetricEvent {
|
|
127
|
+
flagKey: string;
|
|
128
|
+
variant: string;
|
|
129
|
+
count: number;
|
|
130
|
+
windowStart?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface MetricsPayload {
|
|
133
|
+
envKey: string;
|
|
134
|
+
events: MetricEvent[];
|
|
135
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// ── Errors ───────────────────────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when the provider encounters a permanent, non-recoverable error
|
|
4
|
+
* (e.g. 404 — invalid SDK key). The client will stop polling on this error.
|
|
5
|
+
*/
|
|
6
|
+
export class PermanentProviderError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "PermanentProviderError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omniretail/omniflags-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OmniFlags feature flag SDK — core evaluator, cache, and transport",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"keywords": ["feature-flags", "omniflags"],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.4.0",
|
|
27
|
+
"vitest": "^2.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|