@project-ajax/create 0.0.23 → 0.0.25
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/package.json +1 -1
- package/template/.examples/oauth-example.ts +44 -0
- package/template/README.md +14 -32
- package/template/src/index.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { oauth } from "@project-ajax/sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OAuth capabilities let your worker access third-party APIs.
|
|
5
|
+
*
|
|
6
|
+
* After deploying your worker, start OAuth from the CLI:
|
|
7
|
+
*
|
|
8
|
+
* npx workers oauth start <capabilityKey>
|
|
9
|
+
*
|
|
10
|
+
* Where `capabilityKey` is the OAuth capability’s key (see `npx workers capabilities list`).
|
|
11
|
+
* Once OAuth completes, the worker runtime exposes the access token via an
|
|
12
|
+
* environment variable and `accessToken()` reads it for you.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Option 1: Notion-managed provider (recommended when available).
|
|
16
|
+
// Notion owns the OAuth app credentials and the backend has pre-configured provider settings.
|
|
17
|
+
export const googleAuth = oauth({
|
|
18
|
+
name: "google-calendar",
|
|
19
|
+
provider: "google",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Option 2: User-managed provider (you own the OAuth app credentials).
|
|
23
|
+
// Keep client credentials in worker secrets and read them from `process.env`.
|
|
24
|
+
export const myCustomAuth = oauth({
|
|
25
|
+
name: "my-custom-provider",
|
|
26
|
+
authorizationEndpoint: "https://provider.example.com/oauth/authorize",
|
|
27
|
+
tokenEndpoint: "https://provider.example.com/oauth/token",
|
|
28
|
+
scope: "read write",
|
|
29
|
+
clientId: requireEnv("MY_CUSTOM_OAUTH_CLIENT_ID"),
|
|
30
|
+
clientSecret: requireEnv("MY_CUSTOM_OAUTH_CLIENT_SECRET"),
|
|
31
|
+
authorizationParams: {
|
|
32
|
+
access_type: "offline",
|
|
33
|
+
prompt: "consent",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function requireEnv(key: string): string {
|
|
38
|
+
const value = process.env[key];
|
|
39
|
+
if (value) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
throw new Error(`Missing environment variable "${key}"`);
|
|
44
|
+
}
|
package/template/README.md
CHANGED
|
@@ -177,7 +177,7 @@ At the moment, syncs do not run automatically. Use **`exec`** to run a sync.
|
|
|
177
177
|
|
|
178
178
|
- **`primaryKeyProperty`** (string, required): The name of the property that serves as the unique identifier for each entry in the collection (e.g. `"id"`). This property must also be defined in the schema.
|
|
179
179
|
- **`schema`** (object, required): Defines the structure of the Notion collection.
|
|
180
|
-
- **`
|
|
180
|
+
- **`defaultName`** (string, required): The default name for the database when it is first created in Notion. The database will be a new private page. Changing this property after the database has been created will not update the database name.
|
|
181
181
|
- **`properties`** (object, required): An object mapping property names to their schema definitions. Use functions from `@project-ajax/sdk/schema` to define property types (e.g., `Schema.title()`, `Schema.richText()`).
|
|
182
182
|
- **`execute`** (function, required): Async function that fetches and returns data to sync.
|
|
183
183
|
- **Parameters**: None (but can access `process.env` for secrets).
|
|
@@ -475,46 +475,28 @@ Remove a secret from your worker.
|
|
|
475
475
|
npx workers secrets rm API_KEY
|
|
476
476
|
```
|
|
477
477
|
|
|
478
|
-
### `npx workers
|
|
478
|
+
### `npx workers oauth`
|
|
479
479
|
|
|
480
|
-
Commands for managing OAuth
|
|
481
|
-
secrets. Connections appear in your runtime as environment variables (e.g.,
|
|
482
|
-
`process.env.NOTION_OAUTH_GOOGLE`).
|
|
480
|
+
Commands for managing OAuth flows for your worker.
|
|
483
481
|
|
|
484
|
-
#### `npx workers
|
|
482
|
+
#### `npx workers oauth start [capabilityKey]`
|
|
485
483
|
|
|
486
|
-
|
|
484
|
+
Start an OAuth flow for an OAuth capability in your worker. The command opens
|
|
485
|
+
your browser and prints a fallback link if it can’t open automatically.
|
|
487
486
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
#### `npx workers connect add <provider>`
|
|
493
|
-
|
|
494
|
-
Start the OAuth flow in your browser for the specified provider. The command
|
|
495
|
-
opens your default browser and also prints a fallback link.
|
|
487
|
+
If `capabilityKey` is omitted, the CLI will list OAuth capabilities for your
|
|
488
|
+
deployed worker and prompt you to select one (TTY only). In non-interactive
|
|
489
|
+
contexts, pass the key explicitly.
|
|
496
490
|
|
|
497
491
|
```shell
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
#### `npx workers connect list`
|
|
492
|
+
# Start OAuth (interactive picker if capabilityKey is omitted)
|
|
493
|
+
npx workers oauth start
|
|
502
494
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
when the connection was created.
|
|
506
|
-
|
|
507
|
-
```shell
|
|
508
|
-
npx workers connect list
|
|
495
|
+
# Start OAuth for a specific OAuth capability
|
|
496
|
+
npx workers oauth start <capabilityKey>
|
|
509
497
|
```
|
|
510
498
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
Remove an OAuth connection (and the stored tokens) for the specified provider.
|
|
514
|
-
|
|
515
|
-
```shell
|
|
516
|
-
npx workers connect rm google
|
|
517
|
-
```
|
|
499
|
+
See the [OAuth example](./.examples/oauth-example.ts) for a complete example.
|
|
518
500
|
|
|
519
501
|
### Configuration file
|
|
520
502
|
|
package/template/src/index.ts
CHANGED