@featureflip/edge 0.0.0-stage → 2.14.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.
Files changed (37) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +88 -2
  3. package/dist/edge-sdk/src/client.d.ts +35 -0
  4. package/dist/edge-sdk/src/client.d.ts.map +1 -0
  5. package/dist/edge-sdk/src/config.d.ts +42 -0
  6. package/dist/edge-sdk/src/config.d.ts.map +1 -0
  7. package/dist/edge-sdk/src/index.d.ts +7 -0
  8. package/dist/edge-sdk/src/index.d.ts.map +1 -0
  9. package/dist/edge-sdk/src/snapshot.d.ts +61 -0
  10. package/dist/edge-sdk/src/snapshot.d.ts.map +1 -0
  11. package/dist/edge-sdk/src/store.d.ts +21 -0
  12. package/dist/edge-sdk/src/store.d.ts.map +1 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.mjs +947 -0
  15. package/dist/js-sdk/src/core/evaluator.d.ts +37 -0
  16. package/dist/js-sdk/src/core/evaluator.d.ts.map +1 -0
  17. package/dist/js-sdk/src/core/events.d.ts +77 -0
  18. package/dist/js-sdk/src/core/events.d.ts.map +1 -0
  19. package/dist/js-sdk/src/core/identity.d.ts +13 -0
  20. package/dist/js-sdk/src/core/identity.d.ts.map +1 -0
  21. package/dist/js-sdk/src/core/resolve-detail.d.ts +42 -0
  22. package/dist/js-sdk/src/core/resolve-detail.d.ts.map +1 -0
  23. package/dist/js-sdk/src/core/shared-core.d.ts +170 -0
  24. package/dist/js-sdk/src/core/shared-core.d.ts.map +1 -0
  25. package/dist/js-sdk/src/core/store.d.ts +94 -0
  26. package/dist/js-sdk/src/core/store.d.ts.map +1 -0
  27. package/dist/js-sdk/src/core/types.d.ts +128 -0
  28. package/dist/js-sdk/src/core/types.d.ts.map +1 -0
  29. package/dist/js-sdk/src/core/unevaluable.d.ts +28 -0
  30. package/dist/js-sdk/src/core/unevaluable.d.ts.map +1 -0
  31. package/dist/js-sdk/src/core/validate-snapshot.d.ts +38 -0
  32. package/dist/js-sdk/src/core/validate-snapshot.d.ts.map +1 -0
  33. package/dist/js-sdk/src/platform/browser.d.ts +5 -0
  34. package/dist/js-sdk/src/platform/browser.d.ts.map +1 -0
  35. package/dist/js-sdk/src/platform/types.d.ts +31 -0
  36. package/dist/js-sdk/src/platform/types.d.ts.map +1 -0
  37. package/package.json +56 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Canopy Labs LLC
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # @featureflip/edge
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Featureflip SDK for Cloudflare Workers. It evaluates flags locally inside your Worker from a cached copy of your environment's flag config, so a request that finds a warm copy makes no network call to evaluate a flag.
4
+
5
+ Cloudflare Workers is the only supported runtime.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @featureflip/edge
11
+ ```
12
+
13
+ ## Quickstart
14
+
15
+ ```ts
16
+ import { createEdgeClient } from '@featureflip/edge';
17
+
18
+ type Env = { FEATUREFLIP_SERVER_KEY: string };
19
+
20
+ // Config only at module scope: Workers forbid I/O there, and the key lives in `env`.
21
+ let flags: ReturnType<typeof createEdgeClient> | undefined;
22
+
23
+ export default {
24
+ async fetch(request: Request, env: Env, ctx: ExecutionContext) {
25
+ flags ??= createEdgeClient({ sdkKey: env.FEATUREFLIP_SERVER_KEY });
26
+
27
+ const snapshot = await flags.load(ctx);
28
+ const context = { user_id: 'user-123' };
29
+
30
+ const enabled = snapshot.boolVariation('new-checkout', context, false);
31
+ const detail = snapshot.variationDetail('checkout-copy', context, 'control');
32
+ const bootstrap = snapshot.bootstrapValues(context);
33
+
34
+ return new Response(JSON.stringify({ enabled, detail, bootstrap }));
35
+ },
36
+ };
37
+ ```
38
+
39
+ Call `load(ctx)` once per request. After it resolves, every variation call is synchronous.
40
+
41
+ ## Options
42
+
43
+ `sdkKey` is the only required option. Use a server SDK key, not a client key.
44
+
45
+ | Option | Default | Description |
46
+ | --- | --- | --- |
47
+ | `sdkKey` | none (required) | Server SDK key. Sent as `Authorization` and never logged. |
48
+ | `baseUrl` | `https://eval.featureflip.io` | Evaluation API origin. |
49
+ | `ttlSeconds` | `60` | Age after which a copy is refreshed in the background. |
50
+ | `maxStaleSeconds` | `86400` | Age after which a copy is no longer served at all. |
51
+ | `loadTimeoutMs` | `1000` | How long a load with no cached copy waits for the origin. |
52
+ | `store` | Workers Cache API | Where fetched config is shared between isolates. |
53
+ | `wrappers` | `[]` | `name/version` tokens for libraries that wrap this SDK. |
54
+ | `flushBatchSize` | `100` | Events sent per `POST /v1/sdk/events` request. |
55
+ | `fetch` | global `fetch` | `fetch` implementation, mainly for tests. |
56
+
57
+ ## Freshness
58
+
59
+ Flag changes reach edge traffic within `ttlSeconds` (60 seconds by default). This is not the near-instant push that the server SDKs get over a streaming connection.
60
+
61
+ A copy older than `ttlSeconds` is still served while a background refresh runs. So after an idle spell, the first request in gets the older copy once, because the refresh it started hasn't finished. A copy older than `maxStaleSeconds` is not served. If a config fetch fails, the SDK backs off for 15 seconds before trying the origin again, and keeps serving any copy it has.
62
+
63
+ ## Pass `ctx`
64
+
65
+ Pass the Workers `ExecutionContext` to `load(ctx)`. It registers the background refresh and the event flush with `waitUntil`, so both finish after the response is sent.
66
+
67
+ Without `ctx`, await `flush()` yourself before responding, and the background refresh may be cut off when the request ends. The SDK logs a one-time warning when it runs without `ctx`.
68
+
69
+ ## Cold start
70
+
71
+ With no cached copy, `load` waits up to `loadTimeoutMs` for the origin. If the origin is slower, `load` resolves a snapshot with `ready === false` that serves your default values. The fetch keeps going in the background and fills the cache for the next request.
72
+
73
+ ## Bootstrapping the browser SDK
74
+
75
+ `snapshot.bootstrapValues(context)` returns the values of client-visible flags only, for the `bootstrap` option of `@featureflip/browser`. If the server does not send the client-visibility field, it returns nothing, so no flag is exposed by mistake.
76
+
77
+ ## Events
78
+
79
+ Evaluations are queued as events and sent with `waitUntil` when you pass `ctx`. A request's flush sends only if a batch is full or 10 seconds have passed since the last send, so a busy isolate stops posting once per request. After a `429`, a `5xx` or a network error nothing is sent for 30 seconds, and outside that window `flush()` sends straight away, capped at 5 requests a call.
80
+
81
+ Delivery is best effort. The queue lives in the isolate's memory, so events still queued when Cloudflare evicts the isolate are lost.
82
+
83
+ ## Logging
84
+
85
+ Messages go to `console.warn`. The SDK's own start with `[featureflip-edge]`, and the few from the shared evaluation core (rejected or dropped events, an ignored `wrappers` token) start with `[featureflip]`.
86
+
87
+ ## License
88
+
89
+ Apache-2.0
@@ -0,0 +1,35 @@
1
+ import { EdgeConfig } from './config.js';
2
+ import { EdgeSnapshot } from './snapshot.js';
3
+ /** The part of a Workers `ExecutionContext` the client uses. */
4
+ export interface WaitUntilContext {
5
+ waitUntil(promise: Promise<unknown>): void;
6
+ }
7
+ export interface EdgeClient {
8
+ /**
9
+ * The snapshot to evaluate this request against. Never rejects: with no usable
10
+ * config it resolves to a snapshot that serves defaults (`ready === false`).
11
+ *
12
+ * Pass the request's `ctx` so the background refresh and the event flush run
13
+ * in `waitUntil`. As it resolves, `load(ctx)` hands `waitUntil` a flush that
14
+ * runs once the handler's code following `await load(ctx)` yields. That flush
15
+ * sends only when a batch is full or 10 s have passed since the last send, so
16
+ * events from busy traffic go out together rather than one POST per request.
17
+ * Events are best effort: anything still queued when the isolate is evicted
18
+ * is lost.
19
+ */
20
+ load(ctx?: WaitUntilContext): Promise<EdgeSnapshot>;
21
+ /**
22
+ * Sends queued evaluation events now, up to 5 batches. Never rejects. Await it
23
+ * when there is no `ctx`. Within 30 s of a failed send it resolves without
24
+ * sending, and the events stay queued.
25
+ */
26
+ flush(): Promise<void>;
27
+ }
28
+ /**
29
+ * A Featureflip client for Cloudflare Workers. Construct it at module scope: it
30
+ * does no I/O until the first `load`.
31
+ *
32
+ * @throws {Error} only when `sdkKey` is missing.
33
+ */
34
+ export declare function createEdgeClient(config: EdgeConfig): EdgeClient;
35
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAK7C,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,UAAU;IACzB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,GAAG,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACpD;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA4ED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE/D"}
@@ -0,0 +1,42 @@
1
+ import { ConfigStore } from './store.js';
2
+ export interface EdgeConfig {
3
+ /** A server-side SDK key. It is sent as `Authorization` and never logged. */
4
+ sdkKey: string;
5
+ /** Evaluation API origin. Default `https://eval.featureflip.io`. */
6
+ baseUrl?: string;
7
+ /** Age after which a served copy is refreshed in the background. Default 60. */
8
+ ttlSeconds?: number;
9
+ /** Age after which a copy is no longer served at all. Default 86400 (one day). */
10
+ maxStaleSeconds?: number;
11
+ /** How long a load with no usable copy waits for the origin before serving defaults. Default 1000. */
12
+ loadTimeoutMs?: number;
13
+ /** Where fetched config is shared between isolates. Default: the Workers Cache API. */
14
+ store?: ConfigStore;
15
+ /** `name/version` tokens for libraries wrapping this SDK, sent after the SDK's own. */
16
+ wrappers?: string[];
17
+ /** Events per `POST /v1/sdk/events` request. Default 100. */
18
+ flushBatchSize?: number;
19
+ /** `fetch` implementation. Default: the global `fetch`. */
20
+ fetch?: typeof fetch;
21
+ }
22
+ export interface ResolvedEdgeConfig {
23
+ sdkKey: string;
24
+ baseUrl: string;
25
+ ttlSeconds: number;
26
+ maxStaleSeconds: number;
27
+ loadTimeoutMs: number;
28
+ store: ConfigStore | undefined;
29
+ wrappers: string[];
30
+ flushBatchSize: number;
31
+ fetch: typeof fetch;
32
+ }
33
+ export declare const DEFAULTS: {
34
+ readonly baseUrl: "https://eval.featureflip.io";
35
+ readonly ttlSeconds: 60;
36
+ readonly maxStaleSeconds: 86400;
37
+ readonly loadTimeoutMs: 1000;
38
+ readonly flushBatchSize: 100;
39
+ };
40
+ /** Throws only on a missing `sdkKey`; does no I/O. */
41
+ export declare function resolveEdgeConfig(config: EdgeConfig): ResolvedEdgeConfig;
42
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,UAAU;IACzB,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sGAAsG;IACtG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uFAAuF;IACvF,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,eAAO,MAAM,QAAQ;;;;;;CAMX,CAAC;AAEX,sDAAsD;AACtD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,kBAAkB,CAiBxE"}
@@ -0,0 +1,7 @@
1
+ export { createEdgeClient } from './client.js';
2
+ export type { EdgeClient, WaitUntilContext } from './client.js';
3
+ export type { EdgeConfig } from './config.js';
4
+ export type { EdgeSnapshot } from './snapshot.js';
5
+ export type { ConfigStore, StoredConfig } from './store.js';
6
+ export type { EvaluationContext, EvaluationDetail, EvaluationReason, FlagType, GetFlagsResponse, } from '../../js-sdk/src/core/types.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,GACjB,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { EvaluationContext, EvaluationDetail, GetFlagsResponse } from '../../js-sdk/src/core/types.js';
2
+ /**
3
+ * Called once per variation call with the detail it resolved to. The edge client
4
+ * uses it to queue evaluation events; `bootstrapValues` never calls it.
5
+ */
6
+ export type EvaluationRecorder = (flagKey: string, context: EvaluationContext, detail: EvaluationDetail) => void;
7
+ /**
8
+ * An immutable, evaluable view of one `GET /v1/sdk/flags` payload.
9
+ *
10
+ * Built once per fetched config and then read by every request the Worker
11
+ * serves, so all the indexing happens at construction. Evaluation goes through
12
+ * the same `resolveDetail` the JS core uses, so a flag resolves identically
13
+ * here and in `@featureflip/js`, reasons included.
14
+ */
15
+ export declare class EdgeSnapshot {
16
+ /** False only for `empty()`: no config has been loaded. */
17
+ readonly ready: boolean;
18
+ /** The environment config version the snapshot was built from. */
19
+ readonly version: number | undefined;
20
+ private readonly flags;
21
+ private readonly flagList;
22
+ private readonly deps;
23
+ private readonly record;
24
+ private constructor();
25
+ /**
26
+ * Build a snapshot from a fetched config.
27
+ *
28
+ * An unevaluable flag or segment (an enum value this SDK version does not know)
29
+ * is dropped with a warning and the rest of the config still serves, as in the
30
+ * JS core (#2402).
31
+ *
32
+ * @throws {MalformedPayloadError} when the payload violates the wire contract.
33
+ * The caller decides what to fall back to.
34
+ */
35
+ static fromResponse(data: GetFlagsResponse, record: EvaluationRecorder): EdgeSnapshot;
36
+ /** A snapshot with no flags: every read serves its default with `FlagNotFound`. */
37
+ static empty(record: EvaluationRecorder): EdgeSnapshot;
38
+ boolVariation(key: string, context: EvaluationContext, defaultValue: boolean): boolean;
39
+ stringVariation(key: string, context: EvaluationContext, defaultValue: string): string;
40
+ numberVariation(key: string, context: EvaluationContext, defaultValue: number): number;
41
+ /** Untyped: the served value is returned whatever its JSON type. */
42
+ jsonVariation<T>(key: string, context: EvaluationContext, defaultValue: T): T;
43
+ /** Untyped, like `jsonVariation`, with the reason and variation attached. */
44
+ variationDetail<T>(key: string, context: EvaluationContext, defaultValue: T): EvaluationDetail<T>;
45
+ /**
46
+ * The served value of every flag marked `clientSideVisible: true`, for handing
47
+ * to a browser SDK as bootstrap data. A flag without the field is treated as
48
+ * not visible, because a server that predates it cannot vouch for it.
49
+ *
50
+ * Prerequisites still resolve against the whole config, server-only flags
51
+ * included, through one memo shared across the sweep. Records nothing: these
52
+ * values are not reads by the Worker's own code.
53
+ *
54
+ * A flag whose evaluation resolves to reason `Error` is omitted.
55
+ */
56
+ bootstrapValues(context: EvaluationContext): Record<string, unknown>;
57
+ /** The shared deps plus an error hook that names the flag being read. */
58
+ private depsFor;
59
+ private evaluate;
60
+ }
61
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/snapshot.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAEhB,gBAAgB,EAEjB,MAAM,gCAAgC,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,gBAAgB,KACrB,IAAI,CAAC;AAEV;;;;;;;GAOG;AACH,qBAAa,YAAY;IACvB,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAc;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAE5C,OAAO;IAyBP;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,GAAG,YAAY;IAarF,mFAAmF;IACnF,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY;IAItD,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO;IAItF,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAItF,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAItF,oEAAoE;IACpE,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC;IAI7E,6EAA6E;IAC7E,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAIjG;;;;;;;;;;OAUG;IACH,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAyBpE,yEAAyE;IACzE,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,QAAQ;CAgBjB"}
@@ -0,0 +1,21 @@
1
+ import { GetFlagsResponse } from '../../js-sdk/src/core/types.js';
2
+ export interface StoredConfig {
3
+ data: GetFlagsResponse;
4
+ /** Epoch milliseconds at which `data` was fetched from the evaluation API. */
5
+ fetchedAt: number;
6
+ }
7
+ export interface ConfigStore {
8
+ /** Never throws: any failure is a miss (and warns). */
9
+ get(): Promise<StoredConfig | undefined>;
10
+ /** Never throws: any failure warns. */
11
+ put(config: StoredConfig, maxStaleSeconds: number): Promise<void>;
12
+ }
13
+ export declare const FETCHED_AT_HEADER = "x-featureflip-fetched-at";
14
+ /**
15
+ * Cache API key for one (base URL, SDK key) pair. The cache namespace is shared
16
+ * across every hostname on the zone, so the hashed SDK key is the only tenant
17
+ * isolation: the key is a SHA-256 of both inputs and the raw key never appears.
18
+ */
19
+ export declare function configCacheKey(baseUrl: string, sdkKey: string): Promise<string>;
20
+ export declare function createCacheApiStore(cacheKey: string, cache?: Cache): ConfigStore;
21
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,GAAG,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IACzC,uCAAuC;IACvC,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnE;AAED,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAI5D;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKrF;AASD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,WAAW,CA6ChF"}
@@ -0,0 +1,2 @@
1
+ export * from './edge-sdk/src/index.js'
2
+ export {}