@withone/connect 0.17.2 → 0.18.0

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/README.md CHANGED
@@ -302,6 +302,21 @@ await oneConnect.runAction(userId, {
302
302
 
303
303
  `listActions(userId, platform)` lists everything a platform can do, and `runAction` takes `method` and `path` from it if you'd rather pass them yourself. `oneConnect.fetch(userId, path, init)` sends any other request to One's `/v1` API with the headers handled.
304
304
 
305
+ ### Who connected
306
+
307
+ You can also read who the user is on One: their name and email. Use it if you want to, for example to show which One account is connected.
308
+
309
+ ```ts
310
+ // Key mode
311
+ const res = await oneConnect.fetch(userId, "/users/whoami");
312
+ const { user } = await res.json(); // { id, name, email }
313
+
314
+ // Token mode
315
+ const me = await (await oneConnect.fetch(userId, "/users/me")).json(); // { firstName, lastName, email, … }
316
+ ```
317
+
318
+ Users who connected with a version before 0.18.0 did not grant this, so the call returns `403` until they connect again.
319
+
305
320
  You never set an auth header: the client adds the connect key and the user's id to every call it makes.
306
321
 
307
322
  ## 6 · Errors
@@ -429,7 +444,7 @@ The job renews both tokens when either is within 3 days of expiring. Without it,
429
444
  | `mode` | `"key"` or `"token"`, to state the mode explicitly. |
430
445
  | `permissionSet` | The Permission set ID to ask for. |
431
446
  | `returnTo` | Where the callback sends the browser afterwards. `/` by default. |
432
- | `scopes` | OAuth scopes. All three spaces (personal, organization, project) by default, so the user may grant from any. |
447
+ | `scopes` | OAuth scopes. By default `user:profile:read` (who connected) and the connections scopes of all three spaces (personal, organization, project), so the user may grant from any. |
433
448
  | `oneApiUrl` | One's API origin. Production by default. |
434
449
 
435
450
  | Method | Mode | |
@@ -20,7 +20,10 @@ const TX_COOKIE_PREFIX = "one_tx_";
20
20
  * legitimate callback can arrive up to twenty minutes after the start.
21
21
  * Thirty minutes leaves a margin. */
22
22
  const TX_COOKIE_MAX_AGE_SECONDS = 1800;
23
- const DEFAULT_SCOPES = ["user:connections:read", "user:connections:write", "org:connections:read", "org:connections:write", "project:connections:read", "project:connections:write"];
23
+ const DEFAULT_SCOPES = [
24
+ // Who connected: lets the app read the user's name and email from
25
+ // /v1/users/whoami (key mode) or /v1/users/me (token mode).
26
+ "user:profile:read", "user:connections:read", "user:connections:write", "org:connections:read", "org:connections:write", "project:connections:read", "project:connections:write"];
24
27
  function createState() {
25
28
  return node_crypto.randomBytes(16).toString("hex");
26
29
  }
@@ -18,7 +18,10 @@ const TX_COOKIE_PREFIX = "one_tx_";
18
18
  * legitimate callback can arrive up to twenty minutes after the start.
19
19
  * Thirty minutes leaves a margin. */
20
20
  const TX_COOKIE_MAX_AGE_SECONDS = 1800;
21
- const DEFAULT_SCOPES = ["user:connections:read", "user:connections:write", "org:connections:read", "org:connections:write", "project:connections:read", "project:connections:write"];
21
+ const DEFAULT_SCOPES = [
22
+ // Who connected: lets the app read the user's name and email from
23
+ // /v1/users/whoami (key mode) or /v1/users/me (token mode).
24
+ "user:profile:read", "user:connections:read", "user:connections:write", "org:connections:read", "org:connections:write", "project:connections:read", "project:connections:write"];
22
25
  function createState() {
23
26
  return randomBytes(16).toString("hex");
24
27
  }
@@ -102,7 +102,8 @@ export interface OneConnectBaseConfig {
102
102
  /** Where the callback sends the browser afterwards. "/" when omitted;
103
103
  * the outcome is appended as `?one_connect=…`. */
104
104
  returnTo?: string;
105
- /** OAuth scopes. All three tenancy tiers when omitted, so the user may
105
+ /** OAuth scopes. When omitted: `user:profile:read` (who connected) and
106
+ * the connections scopes of all three tenancy tiers, so the user may
106
107
  * grant from any space. */
107
108
  scopes?: string[];
108
109
  }
package/dist/types.d.ts CHANGED
@@ -77,9 +77,9 @@ export interface ConnectButtonLogo {
77
77
  name: string;
78
78
  imageUrl: string;
79
79
  }
80
- /** @deprecated Renamed to `ConnectButtonLogoInput`; removed in 0.18.0. */
80
+ /** @deprecated Renamed to `ConnectButtonLogoInput`; removed in 0.19.0. */
81
81
  export type ConnectButtonPlatformInput = ConnectButtonLogoInput;
82
- /** @deprecated Renamed to `ConnectButtonLogo`; removed in 0.18.0. */
82
+ /** @deprecated Renamed to `ConnectButtonLogo`; removed in 0.19.0. */
83
83
  export type ConnectButtonPlatform = ConnectButtonLogo;
84
84
  export type ConnectButtonVariant = "default" | "accent" | "block";
85
85
  export type ConnectButtonSize = "sm" | "md" | "lg";
@@ -94,7 +94,7 @@ export interface ConnectButtonProps {
94
94
  * into a "+N" chip. Decoration only; the permission set decides what
95
95
  * One asks for. */
96
96
  logos?: ConnectButtonLogoInput[];
97
- /** @deprecated Renamed to `logos`; removed in 0.18.0. */
97
+ /** @deprecated Renamed to `logos`; removed in 0.19.0. */
98
98
  platforms?: ConnectButtonLogoInput[];
99
99
  /** Whether this user has a live grant, from your server. When set, it
100
100
  * decides the Connected state. When omitted, the button shows
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/connect",
3
- "version": "0.17.2",
3
+ "version": "0.18.0",
4
4
  "description": "One Connect for your app: the button your users press, the two backend routes as one import, and a server client that calls One with the grant. Users keep their connections in One; your app holds only what they granted.",
5
5
  "files": [
6
6
  "dist",
@@ -225,6 +225,15 @@ itself (tag `custom`), and encodes the body as asked. `listActions(userId,
225
225
  platform)` lists a whole catalog when search is not enough;
226
226
  `oneConnect.fetch(userId, path, init)` reaches any other `/v1` endpoint.
227
227
 
228
+ **Who connected.** The app can also read who the user is on One, their
229
+ name and email, if it wants to (for example to show which One account is
230
+ connected). Key mode: `oneConnect.fetch(userId, "/users/whoami")` returns
231
+ `{ user: { id, name, email }, organization, project }`. Token mode:
232
+ `oneConnect.fetch(userId, "/users/me")` returns `{ firstName, lastName,
233
+ email, … }`. A user who connected before 0.18.0 gets `403` until they
234
+ connect again. Mention this to the human as something available; whether
235
+ and where to show it is their choice.
236
+
228
237
  Do not set any auth header. The package adds the connect key and the
229
238
  user's id to every call it makes.
230
239
 
@@ -12,6 +12,9 @@ export const TX_COOKIE_PREFIX = "one_tx_";
12
12
  export const TX_COOKIE_MAX_AGE_SECONDS = 1800;
13
13
 
14
14
  export const DEFAULT_SCOPES = [
15
+ // Who connected: lets the app read the user's name and email from
16
+ // /v1/users/whoami (key mode) or /v1/users/me (token mode).
17
+ "user:profile:read",
15
18
  "user:connections:read",
16
19
  "user:connections:write",
17
20
  "org:connections:read",
@@ -109,7 +109,8 @@ export interface OneConnectBaseConfig {
109
109
  /** Where the callback sends the browser afterwards. "/" when omitted;
110
110
  * the outcome is appended as `?one_connect=…`. */
111
111
  returnTo?: string;
112
- /** OAuth scopes. All three tenancy tiers when omitted, so the user may
112
+ /** OAuth scopes. When omitted: `user:profile:read` (who connected) and
113
+ * the connections scopes of all three tenancy tiers, so the user may
113
114
  * grant from any space. */
114
115
  scopes?: string[];
115
116
  }
package/src/types.ts CHANGED
@@ -83,9 +83,9 @@ export interface ConnectButtonLogo {
83
83
  imageUrl: string;
84
84
  }
85
85
 
86
- /** @deprecated Renamed to `ConnectButtonLogoInput`; removed in 0.18.0. */
86
+ /** @deprecated Renamed to `ConnectButtonLogoInput`; removed in 0.19.0. */
87
87
  export type ConnectButtonPlatformInput = ConnectButtonLogoInput;
88
- /** @deprecated Renamed to `ConnectButtonLogo`; removed in 0.18.0. */
88
+ /** @deprecated Renamed to `ConnectButtonLogo`; removed in 0.19.0. */
89
89
  export type ConnectButtonPlatform = ConnectButtonLogo;
90
90
 
91
91
  export type ConnectButtonVariant = "default" | "accent" | "block";
@@ -102,7 +102,7 @@ export interface ConnectButtonProps {
102
102
  * into a "+N" chip. Decoration only; the permission set decides what
103
103
  * One asks for. */
104
104
  logos?: ConnectButtonLogoInput[];
105
- /** @deprecated Renamed to `logos`; removed in 0.18.0. */
105
+ /** @deprecated Renamed to `logos`; removed in 0.19.0. */
106
106
  platforms?: ConnectButtonLogoInput[];
107
107
  /** Whether this user has a live grant, from your server. When set, it
108
108
  * decides the Connected state. When omitted, the button shows