@project-ajax/create 0.0.23 → 0.0.24
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 +13 -31
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
|
@@ -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
|
|