attio 0.0.1-experimental.20250425 → 0.0.1-experimental.20250506
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/lib/auth/auth.js +6 -6
- package/lib/auth/keychain.js +7 -1
- package/lib/commands/logout.js +2 -2
- package/lib/commands/whoami.js +2 -2
- package/package.json +1 -1
- package/schema.graphql +7 -0
package/lib/auth/auth.js
CHANGED
|
@@ -4,7 +4,7 @@ import { randomBytes, createHash } from "crypto";
|
|
|
4
4
|
import open from "open";
|
|
5
5
|
import { APP } from "../env.js";
|
|
6
6
|
import { findAvailablePort } from "../util/find-available-port.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getKeychain } from "./keychain.js";
|
|
8
8
|
import { api } from "../api/api.js";
|
|
9
9
|
import { isErrored, complete, errored } from "@attio/fetchable";
|
|
10
10
|
import { printFetcherError, printKeychainError } from "../print-errors.js";
|
|
@@ -12,7 +12,7 @@ class AuthenticatorImpl {
|
|
|
12
12
|
clientId = "f881c6f1-82d7-48a5-a581-649596167845";
|
|
13
13
|
refreshTimeout = null;
|
|
14
14
|
async ensureAuthed() {
|
|
15
|
-
const existingTokenResult = await
|
|
15
|
+
const existingTokenResult = await getKeychain().load();
|
|
16
16
|
if (isErrored(existingTokenResult)) {
|
|
17
17
|
return this.promptToAuthenticate();
|
|
18
18
|
}
|
|
@@ -31,7 +31,7 @@ class AuthenticatorImpl {
|
|
|
31
31
|
return this.authenticate();
|
|
32
32
|
}
|
|
33
33
|
async authenticate() {
|
|
34
|
-
const existingTokenResult = await
|
|
34
|
+
const existingTokenResult = await getKeychain().load();
|
|
35
35
|
if (isErrored(existingTokenResult)) {
|
|
36
36
|
return existingTokenResult;
|
|
37
37
|
}
|
|
@@ -108,7 +108,7 @@ class AuthenticatorImpl {
|
|
|
108
108
|
token_type: token.token_type,
|
|
109
109
|
expires_at: Date.now() + token.expires_in * 1000,
|
|
110
110
|
};
|
|
111
|
-
const saveResult = await
|
|
111
|
+
const saveResult = await getKeychain().save(keychainToken);
|
|
112
112
|
if (isErrored(saveResult)) {
|
|
113
113
|
return saveResult;
|
|
114
114
|
}
|
|
@@ -141,7 +141,7 @@ class AuthenticatorImpl {
|
|
|
141
141
|
token_type: refreshedToken.token_type,
|
|
142
142
|
expires_at: Date.now() + refreshedToken.expires_in * 1000,
|
|
143
143
|
};
|
|
144
|
-
const saveResult = await
|
|
144
|
+
const saveResult = await getKeychain().save(keychainToken);
|
|
145
145
|
if (isErrored(saveResult)) {
|
|
146
146
|
printKeychainError(saveResult.error);
|
|
147
147
|
return;
|
|
@@ -153,7 +153,7 @@ class AuthenticatorImpl {
|
|
|
153
153
|
clearTimeout(this.refreshTimeout);
|
|
154
154
|
this.refreshTimeout = null;
|
|
155
155
|
}
|
|
156
|
-
await
|
|
156
|
+
await getKeychain().delete();
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
export const authenticator = new AuthenticatorImpl();
|
package/lib/auth/keychain.js
CHANGED
|
@@ -99,4 +99,10 @@ class TestKeychain {
|
|
|
99
99
|
return complete(undefined);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
let keychain = null;
|
|
103
|
+
export const getKeychain = () => {
|
|
104
|
+
if (keychain === null) {
|
|
105
|
+
keychain = process.env.NODE_ENV === "test" ? new TestKeychain() : new KeytarKeychain();
|
|
106
|
+
}
|
|
107
|
+
return keychain;
|
|
108
|
+
};
|
package/lib/commands/logout.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import {
|
|
2
|
+
import { getKeychain } from "../auth/keychain.js";
|
|
3
3
|
import { printKeychainError } from "../print-errors.js";
|
|
4
4
|
import { isErrored } from "@attio/fetchable";
|
|
5
5
|
export const logout = new Command("logout").description("Log out from Attio").action(async () => {
|
|
6
|
-
const result = await
|
|
6
|
+
const result = await getKeychain().delete();
|
|
7
7
|
if (isErrored(result)) {
|
|
8
8
|
printKeychainError(result.error);
|
|
9
9
|
process.exit(1);
|
package/lib/commands/whoami.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import {
|
|
2
|
+
import { getKeychain } from "../auth/keychain.js";
|
|
3
3
|
import { api } from "../api/api.js";
|
|
4
4
|
import { isErrored } from "@attio/fetchable";
|
|
5
5
|
import { printFetcherError } from "../print-errors.js";
|
|
@@ -7,7 +7,7 @@ export const whoami = new Command()
|
|
|
7
7
|
.name("whoami")
|
|
8
8
|
.description("Identify the current user")
|
|
9
9
|
.action(async () => {
|
|
10
|
-
const tokenResult = await
|
|
10
|
+
const tokenResult = await getKeychain().load();
|
|
11
11
|
if (isErrored(tokenResult) || tokenResult.value === null) {
|
|
12
12
|
process.stdout.write("🔒 Not logged in.\n");
|
|
13
13
|
process.exit(0);
|
package/package.json
CHANGED
package/schema.graphql
CHANGED
|
@@ -254,6 +254,7 @@ type Query {
|
|
|
254
254
|
object: String!
|
|
255
255
|
): Record
|
|
256
256
|
currentUser: User!
|
|
257
|
+
currentWorkspace: Workspace!
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
"""The person object in the workspace."""
|
|
@@ -477,4 +478,10 @@ type users implements IObject {
|
|
|
477
478
|
"""ID of the user record."""
|
|
478
479
|
id: String!
|
|
479
480
|
): UserRecord!
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
type Workspace {
|
|
484
|
+
id: String!
|
|
485
|
+
name: String!
|
|
486
|
+
slug: String!
|
|
480
487
|
}
|