@posthog/convex 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.
Files changed (47) hide show
  1. package/LICENSE +299 -0
  2. package/README.md +237 -29
  3. package/dist/client/index.d.ts +126 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +213 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/component/_generated/api.d.ts +34 -0
  8. package/dist/component/_generated/api.d.ts.map +1 -0
  9. package/dist/component/_generated/api.js +31 -0
  10. package/dist/component/_generated/api.js.map +1 -0
  11. package/dist/component/_generated/component.d.ts +134 -0
  12. package/dist/component/_generated/component.d.ts.map +1 -0
  13. package/dist/component/_generated/component.js +11 -0
  14. package/dist/component/_generated/component.js.map +1 -0
  15. package/dist/component/_generated/dataModel.d.ts +46 -0
  16. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  17. package/dist/component/_generated/dataModel.js +11 -0
  18. package/dist/component/_generated/dataModel.js.map +1 -0
  19. package/dist/component/_generated/server.d.ts +121 -0
  20. package/dist/component/_generated/server.d.ts.map +1 -0
  21. package/dist/component/_generated/server.js +78 -0
  22. package/dist/component/_generated/server.js.map +1 -0
  23. package/dist/component/convex.config.d.ts +3 -0
  24. package/dist/component/convex.config.d.ts.map +1 -0
  25. package/dist/component/convex.config.js +3 -0
  26. package/dist/component/convex.config.js.map +1 -0
  27. package/dist/component/lib.d.ts +119 -0
  28. package/dist/component/lib.d.ts.map +1 -0
  29. package/dist/component/lib.js +221 -0
  30. package/dist/component/lib.js.map +1 -0
  31. package/dist/component/schema.d.ts +3 -0
  32. package/dist/component/schema.d.ts.map +1 -0
  33. package/dist/component/schema.js +3 -0
  34. package/dist/component/schema.js.map +1 -0
  35. package/package.json +78 -7
  36. package/src/client/index.test.ts +505 -0
  37. package/src/client/index.ts +363 -0
  38. package/src/client/setup.test.ts +20 -0
  39. package/src/component/_generated/api.ts +50 -0
  40. package/src/component/_generated/component.ts +203 -0
  41. package/src/component/_generated/dataModel.ts +60 -0
  42. package/src/component/_generated/server.ts +156 -0
  43. package/src/component/convex.config.ts +3 -0
  44. package/src/component/lib.ts +259 -0
  45. package/src/component/schema.ts +3 -0
  46. package/src/component/setup.test.ts +11 -0
  47. package/src/test.ts +15 -0
package/LICENSE ADDED
@@ -0,0 +1,299 @@
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 or getsentry/sentry-react-native by Software, Inc. dba Sentry.
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 facebook/metro by Meta Platforms, Inc. and affiliates.
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
+ MIT License
253
+
254
+ Copyright (c) Meta Platforms, Inc. and affiliates.
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 expo/expo by 650 Industries, Inc. (aka Expo).
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
+ The MIT License (MIT)
280
+
281
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
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.
package/README.md CHANGED
@@ -1,45 +1,253 @@
1
- # @posthog/convex
1
+ <p align="center">
2
+ <img alt="@posthog/convex" src="https://raw.githubusercontent.com/PostHog/posthog/master/frontend/public/hedgehog/heart-hog.png" width="200">
3
+ </p>
2
4
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
5
+ <h1 align="center">@posthog/convex</h1>
4
6
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
7
+ <p align="center">
8
+ PostHog analytics and feature flags for your Convex backend.
9
+ </p>
6
10
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@posthog/convex"><img src="https://badge.fury.io/js/@posthog%2Fconvex.svg" alt="npm version"></a>
13
+ </p>
8
14
 
9
- ## Purpose
15
+ > [!WARNING]
16
+ > This package is in alpha and under active development. APIs may change between releases.
10
17
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@posthog/convex`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
18
+ ## 🦔 What is this?
15
19
 
16
- ## What is OIDC Trusted Publishing?
20
+ The official [PostHog](https://posthog.com) component for [Convex](https://convex.dev). Capture events, identify users, manage groups, and evaluate feature flags — all from your mutations and actions.
17
21
 
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.
22
+ Found a bug? Feature request? [File it here](https://github.com/PostHog/posthog-js/issues).
19
23
 
20
- ## Setup Instructions
24
+ ## 🚀 Quick Start
21
25
 
22
- To properly configure OIDC trusted publishing for this package:
26
+ Install the package:
23
27
 
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
+ ```sh
29
+ pnpm add @posthog/convex
30
+ ```
28
31
 
29
- ## DO NOT USE THIS PACKAGE
32
+ Register the component in your `convex/convex.config.ts`:
30
33
 
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
34
+ ```ts
35
+ // convex/convex.config.ts
36
+ import { defineApp } from "convex/server";
37
+ import posthog from "@posthog/convex/convex.config.js";
36
38
 
37
- ## More Information
39
+ const app = defineApp();
40
+ app.use(posthog);
38
41
 
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
+ export default app;
43
+ ```
42
44
 
43
- ---
45
+ Set your PostHog API key and host:
44
46
 
45
- **Maintained for OIDC setup purposes only**
47
+ ```sh
48
+ npx convex env set POSTHOG_API_KEY phc_your_project_api_key
49
+ npx convex env set POSTHOG_HOST https://us.i.posthog.com
50
+ ```
51
+
52
+ Create a `convex/posthog.ts` file to initialize the client:
53
+
54
+ ```ts
55
+ // convex/posthog.ts
56
+ import { PostHog } from "@posthog/convex";
57
+ import { components } from "./_generated/api";
58
+
59
+ export const posthog = new PostHog(components.posthog);
60
+ ```
61
+
62
+ You can also pass the API key and host explicitly:
63
+
64
+ ```ts
65
+ export const posthog = new PostHog(components.posthog, {
66
+ apiKey: "phc_...",
67
+ host: "https://eu.i.posthog.com",
68
+ });
69
+ ```
70
+
71
+ ## 📊 Capturing Events
72
+
73
+ Import `posthog` from your setup file and call methods directly:
74
+
75
+ ```ts
76
+ // convex/myFunctions.ts
77
+ import { posthog } from "./posthog";
78
+ import { mutation } from "./_generated/server";
79
+ import { v } from "convex/values";
80
+
81
+ export const createUser = mutation({
82
+ args: { email: v.string() },
83
+ handler: async (ctx, args) => {
84
+ const userId = await ctx.db.insert("users", { email: args.email });
85
+
86
+ await posthog.capture(ctx, {
87
+ distinctId: userId,
88
+ event: "user_created",
89
+ properties: { email: args.email },
90
+ });
91
+
92
+ return userId;
93
+ },
94
+ });
95
+ ```
96
+
97
+ ### capture
98
+
99
+ Capture an event. Works in mutations and actions.
100
+
101
+ ```ts
102
+ await posthog.capture(ctx, {
103
+ distinctId: "user_123",
104
+ event: "purchase_completed",
105
+ properties: { amount: 99.99, currency: "USD" },
106
+ groups: { company: "acme-corp" },
107
+ });
108
+ ```
109
+
110
+ Options: `distinctId`, `event`, `properties`, `groups`, `sendFeatureFlags`, `timestamp`, `uuid`, `disableGeoip`.
111
+
112
+ ### identify
113
+
114
+ Set user properties.
115
+
116
+ ```ts
117
+ await posthog.identify(ctx, {
118
+ distinctId: "user_123",
119
+ properties: { name: "Jane Doe", plan: "pro" },
120
+ });
121
+ ```
122
+
123
+ ### groupIdentify
124
+
125
+ Set group properties.
126
+
127
+ ```ts
128
+ await posthog.groupIdentify(ctx, {
129
+ groupType: "company",
130
+ groupKey: "acme-corp",
131
+ properties: { industry: "Technology", employees: 500 },
132
+ });
133
+ ```
134
+
135
+ ### alias
136
+
137
+ Link two distinct IDs.
138
+
139
+ ```ts
140
+ await posthog.alias(ctx, {
141
+ distinctId: "user_123",
142
+ alias: "anonymous_456",
143
+ });
144
+ ```
145
+
146
+ All of the above methods schedule the PostHog API call asynchronously via `ctx.scheduler.runAfter`, so they return immediately without blocking your mutation or action.
147
+
148
+ ## 🚩 Feature Flags
149
+
150
+ Feature flag methods evaluate flags by calling the PostHog API and returning the result. They require an **action** context (they use `ctx.runAction` internally).
151
+
152
+ ### getFeatureFlag
153
+
154
+ Get a flag's value.
155
+
156
+ ```ts
157
+ import { posthog } from "./posthog";
158
+ import { action } from "./_generated/server";
159
+ import { v } from "convex/values";
160
+
161
+ export const getDiscount = action({
162
+ args: { userId: v.string() },
163
+ handler: async (ctx, args) => {
164
+ const flag = await posthog.getFeatureFlag(ctx, {
165
+ key: "discount-campaign",
166
+ distinctId: args.userId,
167
+ });
168
+
169
+ if (flag === "variant-a") {
170
+ return { discount: 20 };
171
+ }
172
+ return { discount: 0 };
173
+ },
174
+ });
175
+ ```
176
+
177
+ ### isFeatureEnabled
178
+
179
+ Check if a flag is enabled.
180
+
181
+ ```ts
182
+ const enabled = await posthog.isFeatureEnabled(ctx, {
183
+ key: "new-onboarding",
184
+ distinctId: "user_123",
185
+ });
186
+ ```
187
+
188
+ ### getFeatureFlagPayload
189
+
190
+ Get a flag's JSON payload.
191
+
192
+ ```ts
193
+ const payload = await posthog.getFeatureFlagPayload(ctx, {
194
+ key: "pricing-config",
195
+ distinctId: "user_123",
196
+ });
197
+ ```
198
+
199
+ ### getFeatureFlagResult
200
+
201
+ Get a flag's value and payload in one call.
202
+
203
+ ```ts
204
+ const result = await posthog.getFeatureFlagResult(ctx, {
205
+ key: "experiment-flag",
206
+ distinctId: "user_123",
207
+ });
208
+ if (result) {
209
+ console.log(result.enabled, result.variant, result.payload);
210
+ }
211
+ ```
212
+
213
+ ### getAllFlags
214
+
215
+ Get all flag values for a user.
216
+
217
+ ```ts
218
+ const flags = await posthog.getAllFlags(ctx, {
219
+ distinctId: "user_123",
220
+ });
221
+ ```
222
+
223
+ ### getAllFlagsAndPayloads
224
+
225
+ Get all flags and their payloads.
226
+
227
+ ```ts
228
+ const { featureFlags, featureFlagPayloads } =
229
+ await posthog.getAllFlagsAndPayloads(ctx, {
230
+ distinctId: "user_123",
231
+ });
232
+ ```
233
+
234
+ All feature flag methods accept optional `groups`, `personProperties`, `groupProperties`, `sendFeatureFlagEvents`, and `disableGeoip` options. `getAllFlags` and `getAllFlagsAndPayloads` also accept `flagKeys` to filter which flags to evaluate.
235
+
236
+ ## 📦 Example
237
+
238
+ See the [example app](../../examples/example-convex/) for a working demo.
239
+
240
+ ## 🛠️ Development
241
+
242
+ ```sh
243
+ pnpm i
244
+ pnpm dev
245
+ ```
246
+
247
+ ## 🤝 Contributing
248
+
249
+ PRs welcome. See [PostHog's contributing guide](https://posthog.com/docs/contribute) for general guidelines.
250
+
251
+ ## 📄 License
252
+
253
+ MIT