@railflag/sdk-node 0.0.0-stage → 0.1.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 +39 -2
- package/dist/index.cjs +515 -0
- package/dist/index.d.cts +170 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +494 -0
- package/package.json +56 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Provider, OpenFeatureEventEmitter, EvaluationContext, ResolutionDetails, JsonValue } from '@openfeature/server-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const snapshot: z.ZodObject<{
|
|
5
|
+
env: z.ZodString;
|
|
6
|
+
version: z.ZodNumber;
|
|
7
|
+
generatedAt: z.ZodString;
|
|
8
|
+
flags: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
9
|
+
enabled: z.ZodBoolean;
|
|
10
|
+
offVariation: z.ZodNumber;
|
|
11
|
+
fallthrough: z.ZodUnion<readonly [z.ZodObject<{
|
|
12
|
+
variation: z.ZodNumber;
|
|
13
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
14
|
+
rollout: z.ZodObject<{
|
|
15
|
+
bucketBy: z.ZodOptional<z.ZodString>;
|
|
16
|
+
weights: z.ZodArray<z.ZodNumber>;
|
|
17
|
+
bucketing: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
algorithm: z.ZodEnum<{
|
|
19
|
+
murmur3: "murmur3";
|
|
20
|
+
abtasty: "abtasty";
|
|
21
|
+
}>;
|
|
22
|
+
seed: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
}, z.core.$strip>]>;
|
|
26
|
+
targets: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
27
|
+
variation: z.ZodNumber;
|
|
28
|
+
values: z.ZodArray<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>>>;
|
|
30
|
+
rules: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
name: z.ZodOptional<z.ZodString>;
|
|
33
|
+
clauses: z.ZodArray<z.ZodObject<{
|
|
34
|
+
attr: z.ZodString;
|
|
35
|
+
op: z.ZodEnum<{
|
|
36
|
+
in: "in";
|
|
37
|
+
exists: "exists";
|
|
38
|
+
startsWith: "startsWith";
|
|
39
|
+
endsWith: "endsWith";
|
|
40
|
+
contains: "contains";
|
|
41
|
+
matches: "matches";
|
|
42
|
+
lt: "lt";
|
|
43
|
+
lte: "lte";
|
|
44
|
+
gt: "gt";
|
|
45
|
+
gte: "gte";
|
|
46
|
+
semverEq: "semverEq";
|
|
47
|
+
semverLt: "semverLt";
|
|
48
|
+
semverGt: "semverGt";
|
|
49
|
+
before: "before";
|
|
50
|
+
after: "after";
|
|
51
|
+
segmentMatch: "segmentMatch";
|
|
52
|
+
}>;
|
|
53
|
+
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
54
|
+
negate: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
serve: z.ZodUnion<readonly [z.ZodObject<{
|
|
57
|
+
variation: z.ZodNumber;
|
|
58
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
59
|
+
rollout: z.ZodObject<{
|
|
60
|
+
bucketBy: z.ZodOptional<z.ZodString>;
|
|
61
|
+
weights: z.ZodArray<z.ZodNumber>;
|
|
62
|
+
bucketing: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
algorithm: z.ZodEnum<{
|
|
64
|
+
murmur3: "murmur3";
|
|
65
|
+
abtasty: "abtasty";
|
|
66
|
+
}>;
|
|
67
|
+
seed: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
}, z.core.$strip>]>;
|
|
71
|
+
}, z.core.$strip>>>;
|
|
72
|
+
prerequisites: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
73
|
+
key: z.ZodString;
|
|
74
|
+
variation: z.ZodNumber;
|
|
75
|
+
}, z.core.$strip>>>;
|
|
76
|
+
key: z.ZodString;
|
|
77
|
+
type: z.ZodEnum<{
|
|
78
|
+
string: "string";
|
|
79
|
+
number: "number";
|
|
80
|
+
boolean: "boolean";
|
|
81
|
+
json: "json";
|
|
82
|
+
}>;
|
|
83
|
+
variations: z.ZodArray<z.ZodUnknown>;
|
|
84
|
+
salt: z.ZodString;
|
|
85
|
+
version: z.ZodNumber;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
segments: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
88
|
+
included: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
89
|
+
excluded: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
90
|
+
rules: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
91
|
+
clauses: z.ZodArray<z.ZodObject<{
|
|
92
|
+
attr: z.ZodString;
|
|
93
|
+
op: z.ZodEnum<{
|
|
94
|
+
in: "in";
|
|
95
|
+
exists: "exists";
|
|
96
|
+
startsWith: "startsWith";
|
|
97
|
+
endsWith: "endsWith";
|
|
98
|
+
contains: "contains";
|
|
99
|
+
matches: "matches";
|
|
100
|
+
lt: "lt";
|
|
101
|
+
lte: "lte";
|
|
102
|
+
gt: "gt";
|
|
103
|
+
gte: "gte";
|
|
104
|
+
semverEq: "semverEq";
|
|
105
|
+
semverLt: "semverLt";
|
|
106
|
+
semverGt: "semverGt";
|
|
107
|
+
before: "before";
|
|
108
|
+
after: "after";
|
|
109
|
+
segmentMatch: "segmentMatch";
|
|
110
|
+
}>;
|
|
111
|
+
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
112
|
+
negate: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
}, z.core.$strip>>;
|
|
114
|
+
}, z.core.$strip>>>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
type Snapshot = z.infer<typeof snapshot>;
|
|
118
|
+
|
|
119
|
+
interface SourceOptions {
|
|
120
|
+
sdkKey: string;
|
|
121
|
+
/** Your Railflag relay, like https://relay.example.com. Required: there is no default host. */
|
|
122
|
+
baseUrl: string;
|
|
123
|
+
/** Stream updates over SSE (default true). Polling still runs as a safety net. */
|
|
124
|
+
stream?: boolean;
|
|
125
|
+
pollIntervalMs?: number;
|
|
126
|
+
fetch?: typeof fetch;
|
|
127
|
+
logger?: {
|
|
128
|
+
warn: (...a: unknown[]) => void;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Keeps the latest environment snapshot in memory. Flag checks never wait on the network:
|
|
133
|
+
* if we can't reach Railflag, the last config we had keeps serving.
|
|
134
|
+
*/
|
|
135
|
+
declare class ConfigSource {
|
|
136
|
+
snapshot: Snapshot | null;
|
|
137
|
+
private etag;
|
|
138
|
+
private opts;
|
|
139
|
+
private f;
|
|
140
|
+
private abort;
|
|
141
|
+
private pollTimer?;
|
|
142
|
+
private listeners;
|
|
143
|
+
streaming: boolean;
|
|
144
|
+
constructor(o: SourceOptions);
|
|
145
|
+
onChange(l: (s: Snapshot) => void): () => boolean;
|
|
146
|
+
start(): Promise<void>;
|
|
147
|
+
stop(): void;
|
|
148
|
+
fetchConfig(): Promise<void>;
|
|
149
|
+
private streamLoop;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** OpenFeature provider for Node.js. Evaluates in process; no network call per flag check. */
|
|
153
|
+
declare class RailflagProvider implements Provider {
|
|
154
|
+
readonly metadata: {
|
|
155
|
+
readonly name: "railflag";
|
|
156
|
+
};
|
|
157
|
+
readonly runsOn: "server";
|
|
158
|
+
readonly events: OpenFeatureEventEmitter;
|
|
159
|
+
readonly source: ConfigSource;
|
|
160
|
+
constructor(opts: SourceOptions);
|
|
161
|
+
initialize(): Promise<void>;
|
|
162
|
+
onClose(): Promise<void>;
|
|
163
|
+
private resolve;
|
|
164
|
+
resolveBooleanEvaluation(k: string, d: boolean, c: EvaluationContext): Promise<ResolutionDetails<boolean>>;
|
|
165
|
+
resolveStringEvaluation(k: string, d: string, c: EvaluationContext): Promise<ResolutionDetails<string>>;
|
|
166
|
+
resolveNumberEvaluation(k: string, d: number, c: EvaluationContext): Promise<ResolutionDetails<number>>;
|
|
167
|
+
resolveObjectEvaluation<T extends JsonValue>(k: string, d: T, c: EvaluationContext): Promise<ResolutionDetails<T>>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { ConfigSource, RailflagProvider, type SourceOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Provider, OpenFeatureEventEmitter, EvaluationContext, ResolutionDetails, JsonValue } from '@openfeature/server-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const snapshot: z.ZodObject<{
|
|
5
|
+
env: z.ZodString;
|
|
6
|
+
version: z.ZodNumber;
|
|
7
|
+
generatedAt: z.ZodString;
|
|
8
|
+
flags: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
9
|
+
enabled: z.ZodBoolean;
|
|
10
|
+
offVariation: z.ZodNumber;
|
|
11
|
+
fallthrough: z.ZodUnion<readonly [z.ZodObject<{
|
|
12
|
+
variation: z.ZodNumber;
|
|
13
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
14
|
+
rollout: z.ZodObject<{
|
|
15
|
+
bucketBy: z.ZodOptional<z.ZodString>;
|
|
16
|
+
weights: z.ZodArray<z.ZodNumber>;
|
|
17
|
+
bucketing: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
algorithm: z.ZodEnum<{
|
|
19
|
+
murmur3: "murmur3";
|
|
20
|
+
abtasty: "abtasty";
|
|
21
|
+
}>;
|
|
22
|
+
seed: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
}, z.core.$strip>]>;
|
|
26
|
+
targets: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
27
|
+
variation: z.ZodNumber;
|
|
28
|
+
values: z.ZodArray<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>>>;
|
|
30
|
+
rules: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
name: z.ZodOptional<z.ZodString>;
|
|
33
|
+
clauses: z.ZodArray<z.ZodObject<{
|
|
34
|
+
attr: z.ZodString;
|
|
35
|
+
op: z.ZodEnum<{
|
|
36
|
+
in: "in";
|
|
37
|
+
exists: "exists";
|
|
38
|
+
startsWith: "startsWith";
|
|
39
|
+
endsWith: "endsWith";
|
|
40
|
+
contains: "contains";
|
|
41
|
+
matches: "matches";
|
|
42
|
+
lt: "lt";
|
|
43
|
+
lte: "lte";
|
|
44
|
+
gt: "gt";
|
|
45
|
+
gte: "gte";
|
|
46
|
+
semverEq: "semverEq";
|
|
47
|
+
semverLt: "semverLt";
|
|
48
|
+
semverGt: "semverGt";
|
|
49
|
+
before: "before";
|
|
50
|
+
after: "after";
|
|
51
|
+
segmentMatch: "segmentMatch";
|
|
52
|
+
}>;
|
|
53
|
+
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
54
|
+
negate: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
serve: z.ZodUnion<readonly [z.ZodObject<{
|
|
57
|
+
variation: z.ZodNumber;
|
|
58
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
59
|
+
rollout: z.ZodObject<{
|
|
60
|
+
bucketBy: z.ZodOptional<z.ZodString>;
|
|
61
|
+
weights: z.ZodArray<z.ZodNumber>;
|
|
62
|
+
bucketing: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
algorithm: z.ZodEnum<{
|
|
64
|
+
murmur3: "murmur3";
|
|
65
|
+
abtasty: "abtasty";
|
|
66
|
+
}>;
|
|
67
|
+
seed: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
}, z.core.$strip>]>;
|
|
71
|
+
}, z.core.$strip>>>;
|
|
72
|
+
prerequisites: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
73
|
+
key: z.ZodString;
|
|
74
|
+
variation: z.ZodNumber;
|
|
75
|
+
}, z.core.$strip>>>;
|
|
76
|
+
key: z.ZodString;
|
|
77
|
+
type: z.ZodEnum<{
|
|
78
|
+
string: "string";
|
|
79
|
+
number: "number";
|
|
80
|
+
boolean: "boolean";
|
|
81
|
+
json: "json";
|
|
82
|
+
}>;
|
|
83
|
+
variations: z.ZodArray<z.ZodUnknown>;
|
|
84
|
+
salt: z.ZodString;
|
|
85
|
+
version: z.ZodNumber;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
segments: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
88
|
+
included: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
89
|
+
excluded: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
90
|
+
rules: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
91
|
+
clauses: z.ZodArray<z.ZodObject<{
|
|
92
|
+
attr: z.ZodString;
|
|
93
|
+
op: z.ZodEnum<{
|
|
94
|
+
in: "in";
|
|
95
|
+
exists: "exists";
|
|
96
|
+
startsWith: "startsWith";
|
|
97
|
+
endsWith: "endsWith";
|
|
98
|
+
contains: "contains";
|
|
99
|
+
matches: "matches";
|
|
100
|
+
lt: "lt";
|
|
101
|
+
lte: "lte";
|
|
102
|
+
gt: "gt";
|
|
103
|
+
gte: "gte";
|
|
104
|
+
semverEq: "semverEq";
|
|
105
|
+
semverLt: "semverLt";
|
|
106
|
+
semverGt: "semverGt";
|
|
107
|
+
before: "before";
|
|
108
|
+
after: "after";
|
|
109
|
+
segmentMatch: "segmentMatch";
|
|
110
|
+
}>;
|
|
111
|
+
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
112
|
+
negate: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
}, z.core.$strip>>;
|
|
114
|
+
}, z.core.$strip>>>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
type Snapshot = z.infer<typeof snapshot>;
|
|
118
|
+
|
|
119
|
+
interface SourceOptions {
|
|
120
|
+
sdkKey: string;
|
|
121
|
+
/** Your Railflag relay, like https://relay.example.com. Required: there is no default host. */
|
|
122
|
+
baseUrl: string;
|
|
123
|
+
/** Stream updates over SSE (default true). Polling still runs as a safety net. */
|
|
124
|
+
stream?: boolean;
|
|
125
|
+
pollIntervalMs?: number;
|
|
126
|
+
fetch?: typeof fetch;
|
|
127
|
+
logger?: {
|
|
128
|
+
warn: (...a: unknown[]) => void;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Keeps the latest environment snapshot in memory. Flag checks never wait on the network:
|
|
133
|
+
* if we can't reach Railflag, the last config we had keeps serving.
|
|
134
|
+
*/
|
|
135
|
+
declare class ConfigSource {
|
|
136
|
+
snapshot: Snapshot | null;
|
|
137
|
+
private etag;
|
|
138
|
+
private opts;
|
|
139
|
+
private f;
|
|
140
|
+
private abort;
|
|
141
|
+
private pollTimer?;
|
|
142
|
+
private listeners;
|
|
143
|
+
streaming: boolean;
|
|
144
|
+
constructor(o: SourceOptions);
|
|
145
|
+
onChange(l: (s: Snapshot) => void): () => boolean;
|
|
146
|
+
start(): Promise<void>;
|
|
147
|
+
stop(): void;
|
|
148
|
+
fetchConfig(): Promise<void>;
|
|
149
|
+
private streamLoop;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** OpenFeature provider for Node.js. Evaluates in process; no network call per flag check. */
|
|
153
|
+
declare class RailflagProvider implements Provider {
|
|
154
|
+
readonly metadata: {
|
|
155
|
+
readonly name: "railflag";
|
|
156
|
+
};
|
|
157
|
+
readonly runsOn: "server";
|
|
158
|
+
readonly events: OpenFeatureEventEmitter;
|
|
159
|
+
readonly source: ConfigSource;
|
|
160
|
+
constructor(opts: SourceOptions);
|
|
161
|
+
initialize(): Promise<void>;
|
|
162
|
+
onClose(): Promise<void>;
|
|
163
|
+
private resolve;
|
|
164
|
+
resolveBooleanEvaluation(k: string, d: boolean, c: EvaluationContext): Promise<ResolutionDetails<boolean>>;
|
|
165
|
+
resolveStringEvaluation(k: string, d: string, c: EvaluationContext): Promise<ResolutionDetails<string>>;
|
|
166
|
+
resolveNumberEvaluation(k: string, d: number, c: EvaluationContext): Promise<ResolutionDetails<number>>;
|
|
167
|
+
resolveObjectEvaluation<T extends JsonValue>(k: string, d: T, c: EvaluationContext): Promise<ResolutionDetails<T>>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { ConfigSource, RailflagProvider, type SourceOptions };
|