@digitalpresence/cliclaw-auth 0.1.0 → 0.2.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.
Files changed (39) hide show
  1. package/dist/agent-store.d.ts +6 -9
  2. package/dist/agent-store.d.ts.map +1 -1
  3. package/dist/agent-store.js +26 -38
  4. package/dist/agent-store.js.map +1 -1
  5. package/dist/claude-md-generator.d.ts +10 -1
  6. package/dist/claude-md-generator.d.ts.map +1 -1
  7. package/dist/claude-md-generator.js +49 -24
  8. package/dist/claude-md-generator.js.map +1 -1
  9. package/dist/config.d.ts +1 -0
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/config.js +3 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/index.d.ts +3 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +3 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/instance-store.d.ts +24 -0
  18. package/dist/instance-store.d.ts.map +1 -0
  19. package/dist/instance-store.js +118 -0
  20. package/dist/instance-store.js.map +1 -0
  21. package/dist/oauth-client-manager.d.ts.map +1 -1
  22. package/dist/oauth-client-manager.js +10 -1
  23. package/dist/oauth-client-manager.js.map +1 -1
  24. package/dist/scoped-client-manager.d.ts +2 -3
  25. package/dist/scoped-client-manager.d.ts.map +1 -1
  26. package/dist/scoped-client-manager.js +9 -9
  27. package/dist/scoped-client-manager.js.map +1 -1
  28. package/dist/token-store.d.ts.map +1 -1
  29. package/dist/token-store.js +25 -6
  30. package/dist/token-store.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/agent-store.ts +26 -48
  33. package/src/claude-md-generator.ts +57 -29
  34. package/src/config.ts +4 -0
  35. package/src/index.ts +3 -1
  36. package/src/instance-store.ts +149 -0
  37. package/src/oauth-client-manager.ts +10 -1
  38. package/src/scoped-client-manager.ts +7 -10
  39. package/src/token-store.ts +24 -5
@@ -58,6 +58,15 @@ export class OAuthClientManager {
58
58
  }
59
59
 
60
60
  listAccounts(): string[] {
61
- return this.tokenStore.list();
61
+ const keys = this.tokenStore.list();
62
+ // Include both raw keys and bare account names (from integration:account format)
63
+ const accounts = new Set(keys);
64
+ for (const key of keys) {
65
+ const colonIdx = key.indexOf(":");
66
+ if (colonIdx !== -1) {
67
+ accounts.add(key.slice(colonIdx + 1));
68
+ }
69
+ }
70
+ return [...accounts];
62
71
  }
63
72
  }
@@ -1,7 +1,6 @@
1
1
  import { google } from "googleapis";
2
2
  import { OAuthClientManager } from "./oauth-client-manager.js";
3
3
  import { TokenStore } from "./token-store.js";
4
- import type { AgentPermission } from "./agent-store.js";
5
4
 
6
5
  type OAuth2Client = InstanceType<typeof google.auth.OAuth2>;
7
6
 
@@ -23,18 +22,16 @@ function parseAccountKey(key: string): { integration: string; account: string }
23
22
  export class ScopedClientManager {
24
23
  constructor(
25
24
  private inner: OAuthClientManager,
26
- private permissions: AgentPermission[],
25
+ private integrations: string[],
27
26
  ) {}
28
27
 
29
- private hasPermission(integration: string, account: string): boolean {
30
- return this.permissions.some(
31
- (p) => p.integration === integration && p.account === account,
32
- );
28
+ private hasPermission(integration: string): boolean {
29
+ return this.integrations.includes(integration);
33
30
  }
34
31
 
35
32
  getClient(accountKey: string): OAuth2Client {
36
33
  const { integration, account } = parseAccountKey(accountKey);
37
- if (!this.hasPermission(integration, account)) {
34
+ if (!this.hasPermission(integration)) {
38
35
  throw new PermissionDeniedError(integration, account);
39
36
  }
40
37
  return this.inner.getClient(accountKey);
@@ -42,8 +39,8 @@ export class ScopedClientManager {
42
39
 
43
40
  listAccounts(): string[] {
44
41
  return this.inner.listAccounts().filter((key) => {
45
- const { integration, account } = parseAccountKey(key);
46
- return this.hasPermission(integration, account);
42
+ const { integration } = parseAccountKey(key);
43
+ return this.hasPermission(integration);
47
44
  });
48
45
  }
49
46
 
@@ -57,7 +54,7 @@ export class ScopedClientManager {
57
54
 
58
55
  setCredentials(account: string, tokens: Parameters<OAuth2Client["setCredentials"]>[0]): OAuth2Client {
59
56
  const { integration, account: acct } = parseAccountKey(account);
60
- if (!this.hasPermission(integration, acct)) {
57
+ if (!this.hasPermission(integration)) {
61
58
  throw new PermissionDeniedError(integration, acct);
62
59
  }
63
60
  return this.inner.setCredentials(account, tokens);
@@ -30,7 +30,15 @@ export class TokenStore {
30
30
 
31
31
  get(account: string): Credentials | null {
32
32
  const data = this.load();
33
- return data[account] ?? null;
33
+ if (data[account]) return data[account];
34
+ // Fall back to integration:account key format (portal token injection)
35
+ for (const key of Object.keys(data)) {
36
+ const colonIdx = key.indexOf(":");
37
+ if (colonIdx !== -1 && key.slice(colonIdx + 1) === account) {
38
+ return data[key];
39
+ }
40
+ }
41
+ return null;
34
42
  }
35
43
 
36
44
  set(account: string, tokens: Credentials): void {
@@ -45,10 +53,21 @@ export class TokenStore {
45
53
 
46
54
  delete(account: string): boolean {
47
55
  const data = this.load();
48
- if (!(account in data)) return false;
49
- delete data[account];
50
- this.save(data);
51
- return true;
56
+ if (account in data) {
57
+ delete data[account];
58
+ this.save(data);
59
+ return true;
60
+ }
61
+ // Try integration:account key format
62
+ for (const key of Object.keys(data)) {
63
+ const colonIdx = key.indexOf(":");
64
+ if (colonIdx !== -1 && key.slice(colonIdx + 1) === account) {
65
+ delete data[key];
66
+ this.save(data);
67
+ return true;
68
+ }
69
+ }
70
+ return false;
52
71
  }
53
72
 
54
73
  list(): string[] {