@posthog/openfeature-node-provider 0.0.1 → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,353 @@
1
+ Copyright 2020 Posthog / Hiberly, Inc.
2
+
3
+ Copyright 2015 Mixpanel, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this work except in compliance with the License.
7
+ You may obtain a copy of the License below, or at:
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ Apache License
18
+ Version 2.0, January 2004
19
+ http://www.apache.org/licenses/
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
193
+
194
+ APPENDIX: How to apply the Apache License to your work.
195
+
196
+ To apply the Apache License to your work, attach the following
197
+ boilerplate notice, with the fields enclosed by brackets "[]"
198
+ replaced with your own identifying information. (Don't include
199
+ the brackets!) The text should be enclosed in the appropriate
200
+ comment syntax for the file format. We also recommend that a
201
+ file or class name and description of purpose be included on the
202
+ same "printed page" as the copyright notice for easier
203
+ identification within third-party archives.
204
+
205
+ Copyright [yyyy] [name of copyright owner]
206
+
207
+ Licensed under the Apache License, Version 2.0 (the "License");
208
+ you may not use this file except in compliance with the License.
209
+ You may obtain a copy of the License at
210
+
211
+ http://www.apache.org/licenses/LICENSE-2.0
212
+
213
+ Unless required by applicable law or agreed to in writing, software
214
+ distributed under the License is distributed on an "AS IS" BASIS,
215
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
216
+ See the License for the specific language governing permissions and
217
+ limitations under the License.
218
+
219
+
220
+ ---
221
+
222
+ Some files in this codebase contain code from getsentry/sentry-javascript.
223
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
224
+
225
+ MIT License
226
+
227
+ Copyright (c) 2012 Functional Software, Inc. dba Sentry
228
+
229
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
230
+ this software and associated documentation files (the "Software"), to deal in
231
+ the Software without restriction, including without limitation the rights to
232
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
233
+ of the Software, and to permit persons to whom the Software is furnished to do
234
+ so, subject to the following conditions:
235
+
236
+ The above copyright notice and this permission notice shall be included in all
237
+ copies or substantial portions of the Software.
238
+
239
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245
+ SOFTWARE.
246
+
247
+ ---
248
+
249
+ Some files in this codebase contain code from getsentry/sentry-react-native.
250
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
251
+
252
+ The MIT License (MIT)
253
+
254
+ Copyright (c) 2017 Sentry
255
+
256
+ Permission is hereby granted, free of charge, to any person obtaining a copy
257
+ of this software and associated documentation files (the "Software"), to deal
258
+ in the Software without restriction, including without limitation the rights
259
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
260
+ copies of the Software, and to permit persons to whom the Software is
261
+ furnished to do so, subject to the following conditions:
262
+
263
+ The above copyright notice and this permission notice shall be included in all
264
+ copies or substantial portions of the Software.
265
+
266
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
267
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
268
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
269
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
270
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
271
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
272
+ SOFTWARE.
273
+
274
+ ---
275
+
276
+ Some files in this codebase contain code from facebook/metro by Meta Platforms, Inc. and affiliates.
277
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
278
+
279
+ MIT License
280
+
281
+ Copyright (c) Meta Platforms, Inc. and affiliates.
282
+
283
+ Permission is hereby granted, free of charge, to any person obtaining a copy
284
+ of this software and associated documentation files (the "Software"), to deal
285
+ in the Software without restriction, including without limitation the rights
286
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
287
+ copies of the Software, and to permit persons to whom the Software is
288
+ furnished to do so, subject to the following conditions:
289
+
290
+ The above copyright notice and this permission notice shall be included in all
291
+ copies or substantial portions of the Software.
292
+
293
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
294
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
295
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
296
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
297
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
298
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
299
+ SOFTWARE.
300
+
301
+ ---
302
+
303
+ Some files in this codebase contain code from expo/expo by 650 Industries, Inc. (aka Expo).
304
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
305
+
306
+ The MIT License (MIT)
307
+
308
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
309
+
310
+ Permission is hereby granted, free of charge, to any person obtaining a copy
311
+ of this software and associated documentation files (the "Software"), to deal
312
+ in the Software without restriction, including without limitation the rights
313
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
314
+ copies of the Software, and to permit persons to whom the Software is
315
+ furnished to do so, subject to the following conditions:
316
+
317
+ The above copyright notice and this permission notice shall be included in all
318
+ copies or substantial portions of the Software.
319
+
320
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
321
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
322
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
323
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
324
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
325
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
326
+ SOFTWARE.
327
+
328
+ ---
329
+
330
+ Some files in this codebase contain code from agentcathq/agentcat-typescript-sdk (formerly MCPCat/mcpcat-typescript-sdk).
331
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
332
+
333
+ MIT License
334
+
335
+ Copyright (c) 2025 AgentCat, Inc. (formerly MCPcat)
336
+
337
+ Permission is hereby granted, free of charge, to any person obtaining a copy
338
+ of this software and associated documentation files (the "Software"), to deal
339
+ in the Software without restriction, including without limitation the rights
340
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
341
+ copies of the Software, and to permit persons to whom the Software is
342
+ furnished to do so, subject to the following conditions:
343
+
344
+ The above copyright notice and this permission notice shall be included in all
345
+ copies or substantial portions of the Software.
346
+
347
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
348
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
349
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
350
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
351
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
352
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
353
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,13 @@
1
1
  # @posthog/openfeature-node-provider
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ Official [PostHog](https://posthog.com) provider for the [OpenFeature](https://openfeature.dev) **server**
4
+ SDK ([`@openfeature/server-sdk`](https://openfeature.dev/docs/reference/technologies/server/javascript)),
5
+ backed by [`posthog-node`](https://posthog.com/docs/libraries/node).
4
6
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
7
+ For the browser, use [`@posthog/openfeature-web-provider`](../openfeature-web-provider).
6
8
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
9
+ ## Documentation
8
10
 
9
- ## Purpose
11
+ Installation and usage instructions live in the PostHog docs, so they stay in one place and don't drift:
10
12
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@posthog/openfeature-node-provider`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
13
+ **https://posthog.com/docs/feature-flags/installation/openfeature-js**
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Official PostHog provider for the OpenFeature **server** SDK
3
+ * (`@openfeature/server-sdk`), backed by `posthog-node`.
4
+ *
5
+ * import { PostHogServerProvider } from '@posthog/openfeature-node-provider'
6
+ */
7
+ export { PostHogServerProvider, type PostHogServerProviderOptions } from './provider';
8
+ export { GROUPS_KEY, GROUP_PROPERTIES_KEY, type PostHogFlagResult, type SplitContext } from './mapping';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ GROUPS_KEY: ()=>external_mapping_js_namespaceObject.GROUPS_KEY,
32
+ GROUP_PROPERTIES_KEY: ()=>external_mapping_js_namespaceObject.GROUP_PROPERTIES_KEY,
33
+ PostHogServerProvider: ()=>external_provider_js_namespaceObject.PostHogServerProvider
34
+ });
35
+ const external_provider_js_namespaceObject = require("./provider.js");
36
+ const external_mapping_js_namespaceObject = require("./mapping.js");
37
+ exports.GROUPS_KEY = __webpack_exports__.GROUPS_KEY;
38
+ exports.GROUP_PROPERTIES_KEY = __webpack_exports__.GROUP_PROPERTIES_KEY;
39
+ exports.PostHogServerProvider = __webpack_exports__.PostHogServerProvider;
40
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
41
+ "GROUPS_KEY",
42
+ "GROUP_PROPERTIES_KEY",
43
+ "PostHogServerProvider"
44
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
45
+ Object.defineProperty(exports, '__esModule', {
46
+ value: true
47
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { PostHogServerProvider } from "./provider.mjs";
2
+ export { GROUPS_KEY, GROUP_PROPERTIES_KEY } from "./mapping.mjs";
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Mapping between PostHog feature flag results and OpenFeature resolution
3
+ * details for the **server** provider.
4
+ *
5
+ * `posthog-node`'s `getFeatureFlagResult` returns `{ key, enabled, variant?,
6
+ * payload? }`, and this module turns that into the OpenFeature
7
+ * `ResolutionDetails` shape (and the reserved-attribute context split).
8
+ *
9
+ * Everything is imported from `@openfeature/core` (a peer dependency shared by
10
+ * the server SDK) so the error classes thrown here are the same identities the
11
+ * active SDK catches.
12
+ */
13
+ import { type EvaluationContext, type JsonValue, type ResolutionDetails } from '@openfeature/core';
14
+ /**
15
+ * The minimal flag-result shape returned by `posthog-node`'s
16
+ * `getFeatureFlagResult`. The client's result structurally satisfies this, so
17
+ * the SDK does not need to be imported here.
18
+ */
19
+ export interface PostHogFlagResult {
20
+ readonly key: string;
21
+ readonly enabled: boolean;
22
+ readonly variant?: string;
23
+ readonly payload?: unknown;
24
+ }
25
+ /**
26
+ * Reserved evaluation-context attribute keys. Every other attribute (besides
27
+ * the standard `targetingKey`) is forwarded to PostHog as a person property.
28
+ */
29
+ export declare const GROUPS_KEY = "groups";
30
+ export declare const GROUP_PROPERTIES_KEY = "groupProperties";
31
+ /** PostHog evaluation inputs derived from an OpenFeature evaluation context. */
32
+ export interface SplitContext {
33
+ personProperties: Record<string, unknown>;
34
+ groups: Record<string, string>;
35
+ groupProperties: Record<string, Record<string, unknown>>;
36
+ }
37
+ /**
38
+ * Split an OpenFeature evaluation context into PostHog's evaluation inputs:
39
+ * - reserved `groups` -> PostHog `groups`
40
+ * - reserved `groupProperties` -> PostHog `groupProperties`
41
+ * - every other attribute -> PostHog `personProperties`
42
+ *
43
+ * `targetingKey` is consumed separately (as the distinct id) and never becomes
44
+ * a person property.
45
+ */
46
+ export declare function splitContext(context?: EvaluationContext): SplitContext;
47
+ export declare function resolveBooleanDetails(result: PostHogFlagResult | undefined, flagKey: string): ResolutionDetails<boolean>;
48
+ export declare function resolveStringDetails(result: PostHogFlagResult | undefined, flagKey: string, defaultValue: string): ResolutionDetails<string>;
49
+ export declare function resolveNumberDetails(result: PostHogFlagResult | undefined, flagKey: string, defaultValue: number): ResolutionDetails<number>;
50
+ export declare function resolveObjectDetails<T extends JsonValue>(result: PostHogFlagResult | undefined, flagKey: string, defaultValue: T): ResolutionDetails<T>;
51
+ //# sourceMappingURL=mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEvB,MAAM,mBAAmB,CAAA;AAE1B;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,WAAW,CAAA;AAClC,eAAO,MAAM,oBAAoB,oBAAoB,CAAA;AAErD,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACzD;AAMD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,YAAY,CAiBtE;AAyBD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACrC,OAAO,EAAE,MAAM,GACd,iBAAiB,CAAC,OAAO,CAAC,CAG5B;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACrC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,GACnB,iBAAiB,CAAC,MAAM,CAAC,CAc3B;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACrC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,GACnB,iBAAiB,CAAC,MAAM,CAAC,CAe3B;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,EACtD,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACrC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,GACd,iBAAiB,CAAC,CAAC,CAAC,CAUtB"}
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ GROUPS_KEY: ()=>GROUPS_KEY,
32
+ GROUP_PROPERTIES_KEY: ()=>GROUP_PROPERTIES_KEY,
33
+ resolveBooleanDetails: ()=>resolveBooleanDetails,
34
+ resolveNumberDetails: ()=>resolveNumberDetails,
35
+ resolveObjectDetails: ()=>resolveObjectDetails,
36
+ resolveStringDetails: ()=>resolveStringDetails,
37
+ splitContext: ()=>splitContext
38
+ });
39
+ const core_namespaceObject = require("@openfeature/core");
40
+ const GROUPS_KEY = 'groups';
41
+ const GROUP_PROPERTIES_KEY = 'groupProperties';
42
+ function isRecord(value) {
43
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
44
+ }
45
+ function splitContext(context) {
46
+ if (!context) return {
47
+ personProperties: {},
48
+ groups: {},
49
+ groupProperties: {}
50
+ };
51
+ const { targetingKey: _targetingKey, [GROUPS_KEY]: rawGroups, [GROUP_PROPERTIES_KEY]: rawGroupProperties, ...rest } = context;
52
+ return {
53
+ personProperties: rest,
54
+ groups: isRecord(rawGroups) ? rawGroups : {},
55
+ groupProperties: isRecord(rawGroupProperties) ? rawGroupProperties : {}
56
+ };
57
+ }
58
+ function reasonFor(result) {
59
+ return result.enabled ? core_namespaceObject.StandardResolutionReasons.TARGETING_MATCH : core_namespaceObject.StandardResolutionReasons.DEFAULT;
60
+ }
61
+ function ensureResolved(result, flagKey) {
62
+ if (null == result) throw new core_namespaceObject.FlagNotFoundError(`Flag '${flagKey}' not found.`);
63
+ return result;
64
+ }
65
+ function resolveBooleanDetails(result, flagKey) {
66
+ const resolved = ensureResolved(result, flagKey);
67
+ return {
68
+ value: resolved.enabled,
69
+ variant: resolved.variant,
70
+ reason: reasonFor(resolved)
71
+ };
72
+ }
73
+ function resolveStringDetails(result, flagKey, defaultValue) {
74
+ const resolved = ensureResolved(result, flagKey);
75
+ if (void 0 === resolved.variant) {
76
+ if (!resolved.enabled) return {
77
+ value: defaultValue,
78
+ reason: core_namespaceObject.StandardResolutionReasons.DEFAULT
79
+ };
80
+ throw new core_namespaceObject.TypeMismatchError(`Flag '${flagKey}' has no string variant (boolean flag).`);
81
+ }
82
+ return {
83
+ value: resolved.variant,
84
+ variant: resolved.variant,
85
+ reason: reasonFor(resolved)
86
+ };
87
+ }
88
+ function resolveNumberDetails(result, flagKey, defaultValue) {
89
+ const resolved = ensureResolved(result, flagKey);
90
+ if (void 0 === resolved.variant) {
91
+ if (!resolved.enabled) return {
92
+ value: defaultValue,
93
+ reason: core_namespaceObject.StandardResolutionReasons.DEFAULT
94
+ };
95
+ throw new core_namespaceObject.TypeMismatchError(`Flag '${flagKey}' has no variant to parse as a number.`);
96
+ }
97
+ const value = Number(resolved.variant);
98
+ if ('' === resolved.variant.trim() || !Number.isFinite(value)) throw new core_namespaceObject.TypeMismatchError(`Flag '${flagKey}' variant '${resolved.variant}' is not a valid number.`);
99
+ return {
100
+ value,
101
+ variant: resolved.variant,
102
+ reason: reasonFor(resolved)
103
+ };
104
+ }
105
+ function resolveObjectDetails(result, flagKey, defaultValue) {
106
+ const resolved = ensureResolved(result, flagKey);
107
+ const payload = resolved.payload;
108
+ if ('object' != typeof payload || null === payload) {
109
+ if (!resolved.enabled) return {
110
+ value: defaultValue,
111
+ reason: core_namespaceObject.StandardResolutionReasons.DEFAULT
112
+ };
113
+ throw new core_namespaceObject.TypeMismatchError(`Flag '${flagKey}' has no object/JSON payload.`);
114
+ }
115
+ return {
116
+ value: payload,
117
+ variant: resolved.variant,
118
+ reason: reasonFor(resolved)
119
+ };
120
+ }
121
+ exports.GROUPS_KEY = __webpack_exports__.GROUPS_KEY;
122
+ exports.GROUP_PROPERTIES_KEY = __webpack_exports__.GROUP_PROPERTIES_KEY;
123
+ exports.resolveBooleanDetails = __webpack_exports__.resolveBooleanDetails;
124
+ exports.resolveNumberDetails = __webpack_exports__.resolveNumberDetails;
125
+ exports.resolveObjectDetails = __webpack_exports__.resolveObjectDetails;
126
+ exports.resolveStringDetails = __webpack_exports__.resolveStringDetails;
127
+ exports.splitContext = __webpack_exports__.splitContext;
128
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
129
+ "GROUPS_KEY",
130
+ "GROUP_PROPERTIES_KEY",
131
+ "resolveBooleanDetails",
132
+ "resolveNumberDetails",
133
+ "resolveObjectDetails",
134
+ "resolveStringDetails",
135
+ "splitContext"
136
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
137
+ Object.defineProperty(exports, '__esModule', {
138
+ value: true
139
+ });
@@ -0,0 +1,83 @@
1
+ import { FlagNotFoundError, StandardResolutionReasons, TypeMismatchError } from "@openfeature/core";
2
+ const GROUPS_KEY = 'groups';
3
+ const GROUP_PROPERTIES_KEY = 'groupProperties';
4
+ function isRecord(value) {
5
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
6
+ }
7
+ function splitContext(context) {
8
+ if (!context) return {
9
+ personProperties: {},
10
+ groups: {},
11
+ groupProperties: {}
12
+ };
13
+ const { targetingKey: _targetingKey, [GROUPS_KEY]: rawGroups, [GROUP_PROPERTIES_KEY]: rawGroupProperties, ...rest } = context;
14
+ return {
15
+ personProperties: rest,
16
+ groups: isRecord(rawGroups) ? rawGroups : {},
17
+ groupProperties: isRecord(rawGroupProperties) ? rawGroupProperties : {}
18
+ };
19
+ }
20
+ function reasonFor(result) {
21
+ return result.enabled ? StandardResolutionReasons.TARGETING_MATCH : StandardResolutionReasons.DEFAULT;
22
+ }
23
+ function ensureResolved(result, flagKey) {
24
+ if (null == result) throw new FlagNotFoundError(`Flag '${flagKey}' not found.`);
25
+ return result;
26
+ }
27
+ function resolveBooleanDetails(result, flagKey) {
28
+ const resolved = ensureResolved(result, flagKey);
29
+ return {
30
+ value: resolved.enabled,
31
+ variant: resolved.variant,
32
+ reason: reasonFor(resolved)
33
+ };
34
+ }
35
+ function resolveStringDetails(result, flagKey, defaultValue) {
36
+ const resolved = ensureResolved(result, flagKey);
37
+ if (void 0 === resolved.variant) {
38
+ if (!resolved.enabled) return {
39
+ value: defaultValue,
40
+ reason: StandardResolutionReasons.DEFAULT
41
+ };
42
+ throw new TypeMismatchError(`Flag '${flagKey}' has no string variant (boolean flag).`);
43
+ }
44
+ return {
45
+ value: resolved.variant,
46
+ variant: resolved.variant,
47
+ reason: reasonFor(resolved)
48
+ };
49
+ }
50
+ function resolveNumberDetails(result, flagKey, defaultValue) {
51
+ const resolved = ensureResolved(result, flagKey);
52
+ if (void 0 === resolved.variant) {
53
+ if (!resolved.enabled) return {
54
+ value: defaultValue,
55
+ reason: StandardResolutionReasons.DEFAULT
56
+ };
57
+ throw new TypeMismatchError(`Flag '${flagKey}' has no variant to parse as a number.`);
58
+ }
59
+ const value = Number(resolved.variant);
60
+ if ('' === resolved.variant.trim() || !Number.isFinite(value)) throw new TypeMismatchError(`Flag '${flagKey}' variant '${resolved.variant}' is not a valid number.`);
61
+ return {
62
+ value,
63
+ variant: resolved.variant,
64
+ reason: reasonFor(resolved)
65
+ };
66
+ }
67
+ function resolveObjectDetails(result, flagKey, defaultValue) {
68
+ const resolved = ensureResolved(result, flagKey);
69
+ const payload = resolved.payload;
70
+ if ('object' != typeof payload || null === payload) {
71
+ if (!resolved.enabled) return {
72
+ value: defaultValue,
73
+ reason: StandardResolutionReasons.DEFAULT
74
+ };
75
+ throw new TypeMismatchError(`Flag '${flagKey}' has no object/JSON payload.`);
76
+ }
77
+ return {
78
+ value: payload,
79
+ variant: resolved.variant,
80
+ reason: reasonFor(resolved)
81
+ };
82
+ }
83
+ export { GROUPS_KEY, GROUP_PROPERTIES_KEY, resolveBooleanDetails, resolveNumberDetails, resolveObjectDetails, resolveStringDetails, splitContext };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Official PostHog provider for the OpenFeature **server** SDK
3
+ * (`@openfeature/server-sdk`), backed by a configured `posthog-node` client.
4
+ *
5
+ * This is the JS counterpart of the Python `PostHogProvider`: the server model
6
+ * is stateless and multi-user, so the distinct id arrives per evaluation (from
7
+ * the context's `targetingKey`) and resolution is asynchronous.
8
+ */
9
+ import { type EvaluationContext, type JsonValue, type Provider, type ResolutionDetails } from '@openfeature/server-sdk';
10
+ import type { PostHog } from 'posthog-node';
11
+ export interface PostHogServerProviderOptions {
12
+ /**
13
+ * Distinct id to use when the evaluation context has no `targetingKey`. When
14
+ * omitted, a missing targeting key raises `TargetingKeyMissingError` (the
15
+ * OpenFeature-idiomatic behaviour). Set a value (e.g. `'anonymous'`) to opt
16
+ * into anonymous evaluation.
17
+ */
18
+ defaultDistinctId?: string;
19
+ /**
20
+ * Forwarded to `getFeatureFlagResult` to control `$feature_flag_called`
21
+ * capture. Defaults to `true` so PostHog flag analytics (and experiments)
22
+ * keep working.
23
+ */
24
+ sendFeatureFlagEvents?: boolean;
25
+ }
26
+ /**
27
+ * OpenFeature server provider backed by a configured `posthog-node` client.
28
+ *
29
+ * The caller owns the PostHog client lifecycle: construct and configure the
30
+ * client yourself (project key, `personalApiKey` for local evaluation, `host`,
31
+ * ...), then hand it to this provider.
32
+ *
33
+ * Evaluation-context mapping:
34
+ * - `targetingKey` -> PostHog `distinctId`
35
+ * - reserved `groups` -> PostHog `groups`
36
+ * - reserved `groupProperties` -> PostHog `groupProperties`
37
+ * - every other attribute -> PostHog `personProperties`
38
+ *
39
+ * Flag-type mapping (all via `getFeatureFlagResult`):
40
+ * - boolean -> `enabled`
41
+ * - string -> the multivariate `variant` key
42
+ * - number -> the `variant` parsed as a number
43
+ * - object -> the flag's JSON `payload`
44
+ */
45
+ export declare class PostHogServerProvider implements Provider {
46
+ readonly runsOn = "server";
47
+ readonly metadata: {
48
+ readonly name: "PostHogServerProvider";
49
+ };
50
+ private readonly _client;
51
+ private readonly _defaultDistinctId?;
52
+ private readonly _sendFeatureFlagEvents;
53
+ constructor(client: PostHog, options?: PostHogServerProviderOptions);
54
+ initialize(): Promise<void>;
55
+ resolveBooleanEvaluation(flagKey: string, _defaultValue: boolean, context: EvaluationContext): Promise<ResolutionDetails<boolean>>;
56
+ resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): Promise<ResolutionDetails<string>>;
57
+ resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): Promise<ResolutionDetails<number>>;
58
+ resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext): Promise<ResolutionDetails<T>>;
59
+ private _evaluate;
60
+ private _resolveDistinctId;
61
+ }
62
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAW3C,MAAM,WAAW,4BAA4B;IAC3C;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,qBAAsB,YAAW,QAAQ;IACpD,SAAgB,MAAM,YAAW;IACjC,SAAgB,QAAQ;;MAA6C;IAErE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;gBAEpC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAE,4BAAiC;IAMjE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B3B,wBAAwB,CAC5B,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,OAAO,EACtB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAIhC,uBAAuB,CAC3B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAI/B,uBAAuB,CAC3B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAI/B,uBAAuB,CAAC,CAAC,SAAS,SAAS,EAC/C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;YAIlB,SAAS;IAiBvB,OAAO,CAAC,kBAAkB;CAS3B"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ PostHogServerProvider: ()=>PostHogServerProvider
32
+ });
33
+ const server_sdk_namespaceObject = require("@openfeature/server-sdk");
34
+ const external_mapping_js_namespaceObject = require("./mapping.js");
35
+ class PostHogServerProvider {
36
+ constructor(client, options = {}){
37
+ this.runsOn = 'server';
38
+ this.metadata = {
39
+ name: 'PostHogServerProvider'
40
+ };
41
+ this._client = client;
42
+ this._defaultDistinctId = options.defaultDistinctId;
43
+ this._sendFeatureFlagEvents = options.sendFeatureFlagEvents ?? true;
44
+ }
45
+ async initialize() {
46
+ let preloadError;
47
+ const unsubscribe = this._client.on('error', (err)=>{
48
+ preloadError = err;
49
+ });
50
+ try {
51
+ await this._client.reloadFeatureFlags();
52
+ } finally{
53
+ unsubscribe();
54
+ }
55
+ if (preloadError) console.warn('[PostHogServerProvider] initialize() flag preload failed; remote evaluation still available.', preloadError);
56
+ }
57
+ async resolveBooleanEvaluation(flagKey, _defaultValue, context) {
58
+ return (0, external_mapping_js_namespaceObject.resolveBooleanDetails)(await this._evaluate(flagKey, context), flagKey);
59
+ }
60
+ async resolveStringEvaluation(flagKey, defaultValue, context) {
61
+ return (0, external_mapping_js_namespaceObject.resolveStringDetails)(await this._evaluate(flagKey, context), flagKey, defaultValue);
62
+ }
63
+ async resolveNumberEvaluation(flagKey, defaultValue, context) {
64
+ return (0, external_mapping_js_namespaceObject.resolveNumberDetails)(await this._evaluate(flagKey, context), flagKey, defaultValue);
65
+ }
66
+ async resolveObjectEvaluation(flagKey, defaultValue, context) {
67
+ return (0, external_mapping_js_namespaceObject.resolveObjectDetails)(await this._evaluate(flagKey, context), flagKey, defaultValue);
68
+ }
69
+ async _evaluate(flagKey, context) {
70
+ const distinctId = this._resolveDistinctId(context);
71
+ const { personProperties, groups, groupProperties } = (0, external_mapping_js_namespaceObject.splitContext)(context);
72
+ return this._client.getFeatureFlagResult(flagKey, distinctId, {
73
+ groups: nonEmpty(groups),
74
+ personProperties: nonEmpty(personProperties),
75
+ groupProperties: nonEmpty(groupProperties),
76
+ sendFeatureFlagEvents: this._sendFeatureFlagEvents
77
+ });
78
+ }
79
+ _resolveDistinctId(context) {
80
+ if (context?.targetingKey) return context.targetingKey;
81
+ if (void 0 !== this._defaultDistinctId) return this._defaultDistinctId;
82
+ throw new server_sdk_namespaceObject.TargetingKeyMissingError('No targetingKey in evaluation context and no defaultDistinctId configured.');
83
+ }
84
+ }
85
+ function nonEmpty(value) {
86
+ return Object.keys(value).length > 0 ? value : void 0;
87
+ }
88
+ exports.PostHogServerProvider = __webpack_exports__.PostHogServerProvider;
89
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
90
+ "PostHogServerProvider"
91
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
92
+ Object.defineProperty(exports, '__esModule', {
93
+ value: true
94
+ });
@@ -0,0 +1,56 @@
1
+ import { TargetingKeyMissingError } from "@openfeature/server-sdk";
2
+ import { resolveBooleanDetails, resolveNumberDetails, resolveObjectDetails, resolveStringDetails, splitContext } from "./mapping.mjs";
3
+ class PostHogServerProvider {
4
+ constructor(client, options = {}){
5
+ this.runsOn = 'server';
6
+ this.metadata = {
7
+ name: 'PostHogServerProvider'
8
+ };
9
+ this._client = client;
10
+ this._defaultDistinctId = options.defaultDistinctId;
11
+ this._sendFeatureFlagEvents = options.sendFeatureFlagEvents ?? true;
12
+ }
13
+ async initialize() {
14
+ let preloadError;
15
+ const unsubscribe = this._client.on('error', (err)=>{
16
+ preloadError = err;
17
+ });
18
+ try {
19
+ await this._client.reloadFeatureFlags();
20
+ } finally{
21
+ unsubscribe();
22
+ }
23
+ if (preloadError) console.warn('[PostHogServerProvider] initialize() flag preload failed; remote evaluation still available.', preloadError);
24
+ }
25
+ async resolveBooleanEvaluation(flagKey, _defaultValue, context) {
26
+ return resolveBooleanDetails(await this._evaluate(flagKey, context), flagKey);
27
+ }
28
+ async resolveStringEvaluation(flagKey, defaultValue, context) {
29
+ return resolveStringDetails(await this._evaluate(flagKey, context), flagKey, defaultValue);
30
+ }
31
+ async resolveNumberEvaluation(flagKey, defaultValue, context) {
32
+ return resolveNumberDetails(await this._evaluate(flagKey, context), flagKey, defaultValue);
33
+ }
34
+ async resolveObjectEvaluation(flagKey, defaultValue, context) {
35
+ return resolveObjectDetails(await this._evaluate(flagKey, context), flagKey, defaultValue);
36
+ }
37
+ async _evaluate(flagKey, context) {
38
+ const distinctId = this._resolveDistinctId(context);
39
+ const { personProperties, groups, groupProperties } = splitContext(context);
40
+ return this._client.getFeatureFlagResult(flagKey, distinctId, {
41
+ groups: nonEmpty(groups),
42
+ personProperties: nonEmpty(personProperties),
43
+ groupProperties: nonEmpty(groupProperties),
44
+ sendFeatureFlagEvents: this._sendFeatureFlagEvents
45
+ });
46
+ }
47
+ _resolveDistinctId(context) {
48
+ if (context?.targetingKey) return context.targetingKey;
49
+ if (void 0 !== this._defaultDistinctId) return this._defaultDistinctId;
50
+ throw new TargetingKeyMissingError('No targetingKey in evaluation context and no defaultDistinctId configured.');
51
+ }
52
+ }
53
+ function nonEmpty(value) {
54
+ return Object.keys(value).length > 0 ? value : void 0;
55
+ }
56
+ export { PostHogServerProvider };
package/package.json CHANGED
@@ -1,10 +1,71 @@
1
1
  {
2
2
  "name": "@posthog/openfeature-node-provider",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for @posthog/openfeature-node-provider",
3
+ "version": "0.1.1",
4
+ "bugs": {
5
+ "url": "https://github.com/PostHog/posthog-js/issues"
6
+ },
7
+ "description": "Official PostHog provider for the OpenFeature server SDK (Node), backed by posthog-node",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/PostHog/posthog-js.git",
11
+ "directory": "packages/openfeature-node-provider"
12
+ },
13
+ "homepage": "https://github.com/PostHog/posthog-js/tree/main/packages/openfeature-node-provider#readme",
14
+ "author": {
15
+ "name": "PostHog",
16
+ "email": "engineering@posthog.com",
17
+ "url": "https://posthog.com"
18
+ },
19
+ "license": "MIT",
20
+ "main": "./dist/index.js",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ }
34
+ },
35
+ "engines": {
36
+ "node": "^20.20.0 || >=22.22.0"
37
+ },
38
+ "files": [
39
+ "dist/"
40
+ ],
5
41
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
42
+ "posthog",
43
+ "openfeature",
44
+ "feature-flags",
45
+ "node",
46
+ "server"
47
+ ],
48
+ "peerDependencies": {
49
+ "@openfeature/core": "^1.11.0",
50
+ "@openfeature/server-sdk": "^1.17.0",
51
+ "posthog-node": ">=5.21.2"
52
+ },
53
+ "devDependencies": {
54
+ "@openfeature/core": "^1.11.0",
55
+ "@openfeature/server-sdk": "^1.22.0",
56
+ "@rslib/core": "0.23.2",
57
+ "@types/node": "^22.15.23",
58
+ "vitest": "^1.6.1",
59
+ "@posthog-tooling/tsconfig-base": "1.1.1",
60
+ "posthog-node": "5.51.7"
61
+ },
62
+ "scripts": {
63
+ "clean": "rimraf dist",
64
+ "lint": "oxlint --report-unused-disable-directives-severity error src",
65
+ "lint:fix": "oxlint --report-unused-disable-directives-severity error src --fix",
66
+ "build": "rslib build",
67
+ "dev": "rslib build --watch",
68
+ "test:unit": "vitest run",
69
+ "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
70
+ }
71
+ }