Skip to content

Commit ebb7ad6

Browse files
committed
Merge branch 'component-api'
2 parents fb96c4a + 2b503fc commit ebb7ad6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+20312
-1221
lines changed

.expo/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
> Why do I have a folder named ".expo" in my project?
2-
The ".expo" folder is created when an Expo project is started using "expo start" command.
3-
> What do the files contain?
4-
- "devices.json": contains information about devices that have recently opened this project. This is used to populate the "Development sessions" list in your development builds.
5-
- "settings.json": contains the server configuration that is used to serve the application manifest.
6-
> Should I commit the ".expo" folder?
7-
No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine.
8-
Upon project creation, the ".expo" folder is already added to your ".gitignore" file.
1+
> Why do I have a folder named ".expo" in my project? The ".expo" folder is
2+
> created when an Expo project is started using "expo start" command. What do
3+
> the files contain?
4+
5+
- "devices.json": contains information about devices that have recently opened
6+
this project. This is used to populate the "Development sessions" list in your
7+
development builds.
8+
- "settings.json": contains the server configuration that is used to serve the
9+
application manifest.
10+
> Should I commit the ".expo" folder? No, you should not share the ".expo"
11+
> folder. It does not contain any information that is relevant for other
12+
> developers working on the project, it is specific to your machine. Upon
13+
> project creation, the ".expo" folder is already added to your ".gitignore"
14+
> file.

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test and lint
2+
concurrency:
3+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
4+
cancel-in-progress: true
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: ["**"]
11+
12+
jobs:
13+
check:
14+
name: Test and lint
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 30
17+
18+
steps:
19+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
20+
21+
- name: Node setup
22+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
23+
with:
24+
cache-dependency-path: |
25+
package.json
26+
example/package.json
27+
node-version: "20.x"
28+
cache: "npm"
29+
30+
- name: Install and build
31+
run: |
32+
npm i
33+
npm run build
34+
cd example && npm install
35+
- name: Publish package for testing branch
36+
run: npx pkg-pr-new publish || echo "Have you set up pkg-pr-new for this repo?"
37+
- name: Test
38+
run: |
39+
npm run test
40+
npm run typecheck
41+
npm run lint

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ dist-ssr
99
explorations
1010
node_modules
1111
.eslintcache
12-
# components are libraries!
13-
package-lock.json
14-
15-
# this is a package-json-redirect stub dir, see https://github.com/andrewbranch/example-subpath-exports-ts-compat?tab=readme-ov-file
16-
frontend/package.json
12+
**/.expo
13+
**/expo-env.d.ts
1714
# npm pack output
1815
*.tgz
16+
*.tsbuildinfo
1917
.claude

.prettierrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"trailingComma": "all",
3+
"proseWrap": "always"
4+
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## 0.3.0
4+
5+
- Adds /test and /\_generated/component.js entrypoints
6+
- Drops commonjs support
7+
- Improves source mapping for generated files
8+
- Changes to a statically generated component API

CLAUDE.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Claude Development Notes
22

33
## Codegen Command
4+
45
After making changes to component functions, run codegen with:
6+
57
```bash
68
cd example/ && npm run dev -- --once
79
```
@@ -10,18 +12,23 @@ cd example/ && npm run dev -- --once
1012

1113
When adding new functions to this Convex component:
1214

13-
1. **Client function** (`src/client/index.ts`):
14-
- Add method to `PushNotifications` class that calls `ctx.runMutation(this.component.public.functionName, { ...args, logLevel: this.config.logLevel })`
15+
1. **Client function** (`src/client/index.ts`):
16+
17+
- Add method to `PushNotifications` class that calls
18+
`ctx.runMutation(this.component.public.functionName, { ...args, logLevel: this.config.logLevel })`
1519
- Follow existing patterns for argument types and return types
1620

1721
2. **Component function** (`src/component/public.ts`):
22+
1823
- Define args schema using `v.object()`
1924
- Export mutation/query with proper return type
2025
- Call `ensureCoordinator(ctx)` after processing for coordination
2126

2227
3. **Batch functions**:
23-
- Use existing handler functions (like `sendPushNotificationHandler`) in loops
28+
29+
- Use existing handler functions (like `sendPushNotificationHandler`) in
30+
loops
2431
- Call `ensureCoordinator` once after all processing
2532
- Return array of results matching individual function return types
2633

27-
4. **Always run codegen** after changes to regenerate types
34+
4. **Always run codegen** after changes to regenerate types

CONTRIBUTING.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Developing guide
2+
3+
## Running locally
4+
5+
```sh
6+
npm run setup
7+
npm run dev
8+
```
9+
10+
Setup should:
11+
12+
1. Install dependencies in the root and example directories
13+
1. Build the component
14+
1. Create a Convex project if not already connected, and deploy to it once.
15+
1. Set the `EXPO_PUBLIC_CONVEX_URL` environment variable for the example expo
16+
app (needs to be set in the example expo app's `.env.local` file)
17+
18+
## Testing
19+
20+
```sh
21+
npm run clean
22+
npm run build
23+
npm run typecheck
24+
npm run lint
25+
npm run test
26+
```
27+
28+
## Deploying
29+
30+
### Building a one-off package
31+
32+
```sh
33+
npm run clean
34+
npm ci
35+
npm pack
36+
```
37+
38+
### Deploying a new version
39+
40+
```sh
41+
npm run release
42+
```
43+
44+
or for alpha release:
45+
46+
```sh
47+
npm run alpha
48+
```

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
<!-- START: Include on https://convex.dev/components -->
66

7-
This is a Convex component that integrates with [Expo's push notification API](https://docs.expo.dev/push-notifications/overview/)
8-
to allow sending mobile push notifications to users of your app. It will batch calls to Expo's API and handle retrying delivery.
7+
This is a Convex component that integrates with
8+
[Expo's push notification API](https://docs.expo.dev/push-notifications/overview/)
9+
to allow sending mobile push notifications to users of your app. It will batch
10+
calls to Expo's API and handle retrying delivery.
911

1012
<details>
1113
<summary>Demo GIF</summary>
@@ -51,11 +53,12 @@ export const sendPushNotification = mutation({
5153

5254
## Pre-requisite: Convex
5355

54-
You'll need an existing Convex project to use the component.
55-
Convex is a hosted backend platform, including a database, serverless functions,
56-
and a ton more you can learn about [here](https://docs.convex.dev/get-started).
56+
You'll need an existing Convex project to use the component. Convex is a hosted
57+
backend platform, including a database, serverless functions, and a ton more you
58+
can learn about [here](https://docs.convex.dev/get-started).
5759

58-
Run `npm create convex` or follow any of the [quickstarts](https://docs.convex.dev/home) to set one up.
60+
Run `npm create convex` or follow any of the
61+
[quickstarts](https://docs.convex.dev/home) to set one up.
5962

6063
## Installation
6164

@@ -65,12 +68,13 @@ Install the component package:
6568
npm i @convex-dev/expo-push-notifications
6669
```
6770

68-
Create a `convex.config.ts` file in your app's `convex/` folder and install the component by calling `use`:
71+
Create a `convex.config.ts` file in your app's `convex/` folder and install the
72+
component by calling `use`:
6973

7074
```ts
7175
// convex/convex.config.ts
7276
import { defineApp } from "convex/server";
73-
import pushNotifications from "@convex-dev/expo-push-notifications/convex.config";
77+
import pushNotifications from "@convex-dev/expo-push-notifications/convex.config.js";
7478

7579
const app = defineApp();
7680
app.use(pushNotifications);
@@ -88,21 +92,24 @@ import { PushNotifications } from "@convex-dev/expo-push-notifications";
8892
const pushNotifications = new PushNotifications(components.pushNotifications);
8993
```
9094

91-
It takes in an optional type parameter (defaulting to `Id<"users">`) for the type to use as a unique identifier for push notification recipients:
95+
It takes in an optional type parameter (defaulting to `Id<"users">`) for the
96+
type to use as a unique identifier for push notification recipients:
9297

9398
```ts
9499
import { PushNotifications } from "@convex-dev/expo-push-notifications";
95100

96101
export type Email = string & { __isEmail: true };
97102

98103
const pushNotifications = new PushNotifications<Email>(
99-
components.pushNotifications
104+
components.pushNotifications,
100105
);
101106
```
102107

103108
## Registering a user for push notifications
104109

105-
Get a user's push notification token following the Expo documentation [here](https://docs.expo.dev/push-notifications/push-notifications-setup/#registering-for-push-notifications), and record it using a Convex mutation:
110+
Get a user's push notification token following the Expo documentation
111+
[here](https://docs.expo.dev/push-notifications/push-notifications-setup/#registering-for-push-notifications),
112+
and record it using a Convex mutation:
106113

107114
```ts
108115
// convex/example.ts
@@ -118,9 +125,11 @@ export const recordPushNotificationToken = mutation({
118125
});
119126
```
120127

121-
You can pause and resume push notification sending for a user using the `pausePushNotifications` and `resumePushNotifications` methods.
128+
You can pause and resume push notification sending for a user using the
129+
`pausePushNotifications` and `resumePushNotifications` methods.
122130

123-
To determine if a user has a token and their pause status, you can use `getStatusForUser`.
131+
To determine if a user has a token and their pause status, you can use
132+
`getStatusForUser`.
124133

125134
## Send notifications
126135

@@ -139,21 +148,24 @@ export const sendPushNotification = mutation({
139148
});
140149
```
141150

142-
You can use the ID returned from `sendPushNotifications` to query the status of the notification using `getNotification`.
143-
Using this in a query allows you to subscribe to the status of a notification.
151+
You can use the ID returned from `sendPushNotifications` to query the status of
152+
the notification using `getNotification`. Using this in a query allows you to
153+
subscribe to the status of a notification.
144154

145155
You can also view all notifications for a user with `getNotificationsForUser`.
146156

147157
## Troubleshooting
148158

149-
To add more logging, provide `PushNotifications` with a `logLevel` in the constructor:
159+
To add more logging, provide `PushNotifications` with a `logLevel` in the
160+
constructor:
150161

151162
```ts
152163
const pushNotifications = new PushNotifications(components.pushNotifications, {
153164
logLevel: "DEBUG",
154165
});
155166
```
156167

157-
The push notification sender can be shutdown gracefully, and then restarted using the `shutdown` and `restart` methods.
168+
The push notification sender can be shutdown gracefully, and then restarted
169+
using the `shutdown` and `restart` methods.
158170

159171
<!-- END: Include on https://convex.dev/components -->

commonjs.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

convex.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/convex/schemas/convex.schema.json",
3+
"functions": "example/convex",
4+
"codegen": {
5+
"legacyComponentApi": false
6+
}
7+
}

0 commit comments

Comments
 (0)