@hanzo/iam 0.9.0 → 0.9.2

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 (74) hide show
  1. package/dist/auth.cjs +111 -0
  2. package/dist/auth.cjs.map +1 -0
  3. package/dist/auth.d.cts +19 -0
  4. package/dist/auth.d.ts +7 -4
  5. package/dist/auth.js +94 -121
  6. package/dist/auth.js.map +1 -1
  7. package/dist/betterauth.cjs +34 -0
  8. package/dist/betterauth.cjs.map +1 -0
  9. package/dist/betterauth.d.cts +64 -0
  10. package/dist/betterauth.d.ts +8 -11
  11. package/dist/betterauth.js +28 -62
  12. package/dist/betterauth.js.map +1 -1
  13. package/dist/billing.cjs +8 -0
  14. package/dist/billing.cjs.map +1 -0
  15. package/dist/billing.d.cts +2 -0
  16. package/dist/billing.d.ts +2 -16
  17. package/dist/billing.js +5 -17
  18. package/dist/billing.js.map +1 -1
  19. package/dist/browser.cjs +680 -0
  20. package/dist/browser.cjs.map +1 -0
  21. package/dist/browser.d.cts +217 -0
  22. package/dist/browser.d.ts +10 -7
  23. package/dist/browser.js +645 -663
  24. package/dist/browser.js.map +1 -1
  25. package/dist/index.cjs +1087 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/{client.d.ts → index.d.cts} +23 -4
  28. package/dist/index.d.ts +86 -23
  29. package/dist/index.js +1077 -29
  30. package/dist/index.js.map +1 -1
  31. package/dist/nextauth.cjs +35 -0
  32. package/dist/nextauth.cjs.map +1 -0
  33. package/dist/nextauth.d.cts +55 -0
  34. package/dist/nextauth.d.ts +5 -8
  35. package/dist/nextauth.js +30 -66
  36. package/dist/nextauth.js.map +1 -1
  37. package/dist/passport.cjs +47 -0
  38. package/dist/passport.cjs.map +1 -0
  39. package/dist/passport.d.cts +50 -0
  40. package/dist/passport.d.ts +13 -7
  41. package/dist/passport.js +39 -65
  42. package/dist/passport.js.map +1 -1
  43. package/dist/react.cjs +1434 -0
  44. package/dist/react.cjs.map +1 -0
  45. package/dist/react.d.cts +133 -0
  46. package/dist/react.d.ts +18 -50
  47. package/dist/react.js +1399 -494
  48. package/dist/react.js.map +1 -1
  49. package/dist/types.cjs +4 -0
  50. package/dist/types.cjs.map +1 -0
  51. package/dist/types.d.cts +219 -0
  52. package/dist/types.d.ts +25 -24
  53. package/dist/types.js +2 -5
  54. package/dist/types.js.map +1 -1
  55. package/package.json +28 -15
  56. package/src/betterauth.ts +1 -1
  57. package/src/nextauth.ts +1 -1
  58. package/src/passport.ts +7 -10
  59. package/dist/auth.d.ts.map +0 -1
  60. package/dist/betterauth.d.ts.map +0 -1
  61. package/dist/billing.d.ts.map +0 -1
  62. package/dist/browser.d.ts.map +0 -1
  63. package/dist/client.d.ts.map +0 -1
  64. package/dist/client.js +0 -292
  65. package/dist/client.js.map +0 -1
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/nextauth.d.ts.map +0 -1
  68. package/dist/passport.d.ts.map +0 -1
  69. package/dist/pkce.d.ts +0 -13
  70. package/dist/pkce.d.ts.map +0 -1
  71. package/dist/pkce.js +0 -36
  72. package/dist/pkce.js.map +0 -1
  73. package/dist/react.d.ts.map +0 -1
  74. package/dist/types.d.ts.map +0 -1
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Core types for the Hanzo IAM SDK.
3
3
  * Hanzo IAM data models.
4
4
  */
5
- export type IamConfig = {
5
+ type IamConfig = {
6
6
  /** IAM server base URL (e.g. "https://iam.hanzo.ai"). */
7
7
  serverUrl: string;
8
8
  /** OAuth2 client ID. */
@@ -14,7 +14,7 @@ export type IamConfig = {
14
14
  /** Application name. */
15
15
  appName?: string;
16
16
  };
17
- export type OidcDiscovery = {
17
+ type OidcDiscovery = {
18
18
  issuer: string;
19
19
  authorization_endpoint: string;
20
20
  token_endpoint: string;
@@ -24,7 +24,7 @@ export type OidcDiscovery = {
24
24
  response_types_supported?: string[];
25
25
  grant_types_supported?: string[];
26
26
  };
27
- export type TokenResponse = {
27
+ type TokenResponse = {
28
28
  access_token: string;
29
29
  token_type: string;
30
30
  expires_in?: number;
@@ -32,7 +32,7 @@ export type TokenResponse = {
32
32
  id_token?: string;
33
33
  scope?: string;
34
34
  };
35
- export type IamJwtClaims = {
35
+ type IamJwtClaims = {
36
36
  /** Subject (user ID in format "org/username"). */
37
37
  sub: string;
38
38
  /** Issuer URL. */
@@ -58,7 +58,7 @@ export type IamJwtClaims = {
58
58
  /** Arbitrary extra claims. */
59
59
  [key: string]: unknown;
60
60
  };
61
- export type IamUser = {
61
+ type IamUser = {
62
62
  owner: string;
63
63
  name: string;
64
64
  id?: string;
@@ -72,7 +72,7 @@ export type IamUser = {
72
72
  createdTime?: string;
73
73
  signupApplication?: string;
74
74
  };
75
- export type IamOrganization = {
75
+ type IamOrganization = {
76
76
  owner: string;
77
77
  name: string;
78
78
  displayName?: string;
@@ -87,7 +87,7 @@ export type IamOrganization = {
87
87
  balanceCredit?: number;
88
88
  balanceCurrency?: string;
89
89
  };
90
- export type Subscription = {
90
+ type Subscription = {
91
91
  owner: string;
92
92
  name: string;
93
93
  displayName?: string;
@@ -101,7 +101,7 @@ export type Subscription = {
101
101
  state?: "Active" | "Inactive" | "Expired" | "Cancelled" | string;
102
102
  description?: string;
103
103
  };
104
- export type Plan = {
104
+ type Plan = {
105
105
  owner: string;
106
106
  name: string;
107
107
  displayName?: string;
@@ -114,7 +114,7 @@ export type Plan = {
114
114
  isEnabled?: boolean;
115
115
  role?: string;
116
116
  };
117
- export type Pricing = {
117
+ type Pricing = {
118
118
  owner: string;
119
119
  name: string;
120
120
  displayName?: string;
@@ -125,7 +125,7 @@ export type Pricing = {
125
125
  application?: string;
126
126
  trialDuration?: number;
127
127
  };
128
- export type Payment = {
128
+ type Payment = {
129
129
  owner: string;
130
130
  name: string;
131
131
  displayName?: string;
@@ -138,7 +138,7 @@ export type Payment = {
138
138
  state?: string;
139
139
  message?: string;
140
140
  };
141
- export type Order = {
141
+ type Order = {
142
142
  owner: string;
143
143
  name: string;
144
144
  displayName?: string;
@@ -150,7 +150,7 @@ export type Order = {
150
150
  state?: string;
151
151
  message?: string;
152
152
  };
153
- export type UsageRecord = {
153
+ type UsageRecord = {
154
154
  owner: string;
155
155
  name: string;
156
156
  user?: string;
@@ -172,21 +172,21 @@ export type UsageRecord = {
172
172
  requestId?: string;
173
173
  createdTime?: string;
174
174
  };
175
- export type UsageSummary = {
175
+ type UsageSummary = {
176
176
  totalRequests: number;
177
177
  totalTokens: number;
178
178
  totalCost: number;
179
179
  promptTokens: number;
180
180
  completionTokens: number;
181
181
  };
182
- export type IamSubscription = Subscription;
183
- export type IamPlan = Plan;
184
- export type IamPricing = Pricing;
185
- export type IamPayment = Payment;
186
- export type IamOrder = Order;
187
- export type IamUsageRecord = UsageRecord;
188
- export type IamUsageSummary = UsageSummary;
189
- export type IamProject = {
182
+ type IamSubscription = Subscription;
183
+ type IamPlan = Plan;
184
+ type IamPricing = Pricing;
185
+ type IamPayment = Payment;
186
+ type IamOrder = Order;
187
+ type IamUsageRecord = UsageRecord;
188
+ type IamUsageSummary = UsageSummary;
189
+ type IamProject = {
190
190
  owner: string;
191
191
  name: string;
192
192
  displayName?: string;
@@ -197,7 +197,7 @@ export type IamProject = {
197
197
  isDefault?: boolean;
198
198
  createdTime?: string;
199
199
  };
200
- export type IamAuthResult = {
200
+ type IamAuthResult = {
201
201
  ok: true;
202
202
  userId: string;
203
203
  email?: string;
@@ -209,10 +209,11 @@ export type IamAuthResult = {
209
209
  ok: false;
210
210
  reason: string;
211
211
  };
212
- export type IamApiResponse<T> = {
212
+ type IamApiResponse<T> = {
213
213
  status: "ok" | "error";
214
214
  msg?: string;
215
215
  data?: T;
216
216
  data2?: unknown;
217
217
  };
218
- //# sourceMappingURL=types.d.ts.map
218
+
219
+ export type { IamApiResponse, IamAuthResult, IamConfig, IamJwtClaims, IamOrder, IamOrganization, IamPayment, IamPlan, IamPricing, IamProject, IamSubscription, IamUsageRecord, IamUsageSummary, IamUser, OidcDiscovery, Order, Payment, Plan, Pricing, Subscription, TokenResponse, UsageRecord, UsageSummary };
package/dist/types.js CHANGED
@@ -1,6 +1,3 @@
1
- /**
2
- * Core types for the Hanzo IAM SDK.
3
- * Hanzo IAM data models.
4
- */
5
- export {};
1
+
2
+ //# sourceMappingURL=types.js.map
6
3
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
package/package.json CHANGED
@@ -1,48 +1,58 @@
1
1
  {
2
2
  "name": "@hanzo/iam",
3
- "version": "0.9.0",
4
- "description": "TypeScript SDK for Hanzo IAM \u2014 OIDC auth, JWT validation, OAuth2 PKCE, user/org/project APIs",
3
+ "version": "0.9.2",
4
+ "description": "TypeScript SDK for Hanzo IAM OIDC auth, JWT validation, OAuth2 PKCE, user/org/project APIs",
5
5
  "type": "module",
6
- "main": "dist/index.js",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
11
  "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs",
12
14
  "default": "./dist/index.js"
13
15
  },
14
16
  "./auth": {
15
17
  "types": "./dist/auth.d.ts",
16
18
  "import": "./dist/auth.js",
19
+ "require": "./dist/auth.cjs",
17
20
  "default": "./dist/auth.js"
18
21
  },
19
22
  "./browser": {
20
23
  "types": "./dist/browser.d.ts",
21
- "import": "./dist/browser.js"
24
+ "import": "./dist/browser.js",
25
+ "require": "./dist/browser.cjs"
22
26
  },
23
27
  "./billing": {
24
28
  "types": "./dist/billing.d.ts",
25
- "import": "./dist/billing.js"
29
+ "import": "./dist/billing.js",
30
+ "require": "./dist/billing.cjs"
26
31
  },
27
32
  "./types": {
28
33
  "types": "./dist/types.d.ts",
29
- "import": "./dist/types.js"
34
+ "import": "./dist/types.js",
35
+ "require": "./dist/types.cjs"
30
36
  },
31
37
  "./react": {
32
38
  "types": "./dist/react.d.ts",
33
- "import": "./dist/react.js"
39
+ "import": "./dist/react.js",
40
+ "require": "./dist/react.cjs"
34
41
  },
35
42
  "./nextauth": {
36
43
  "types": "./dist/nextauth.d.ts",
37
- "import": "./dist/nextauth.js"
44
+ "import": "./dist/nextauth.js",
45
+ "require": "./dist/nextauth.cjs"
38
46
  },
39
47
  "./passport": {
40
48
  "types": "./dist/passport.d.ts",
41
- "import": "./dist/passport.js"
49
+ "import": "./dist/passport.js",
50
+ "require": "./dist/passport.cjs"
42
51
  },
43
52
  "./betterauth": {
44
53
  "types": "./dist/betterauth.d.ts",
45
- "import": "./dist/betterauth.js"
54
+ "import": "./dist/betterauth.js",
55
+ "require": "./dist/betterauth.cjs"
46
56
  }
47
57
  },
48
58
  "files": [
@@ -52,15 +62,16 @@
52
62
  "LICENSE"
53
63
  ],
54
64
  "scripts": {
55
- "build": "tsc",
56
- "dev": "tsc --watch",
65
+ "build": "tsup",
66
+ "dev": "tsup --watch",
57
67
  "clean": "rm -rf dist",
58
- "prepare": "pnpm clean && pnpm build",
59
- "prepublishOnly": "pnpm clean && pnpm build",
68
+ "prepare": "node -e \"if (!require('fs').existsSync('dist')) { require('child_process').execSync('tsup', { stdio: 'inherit' }) }\"",
69
+ "prepublishOnly": "rm -rf dist && tsup",
60
70
  "test": "node --test --import tsx src/**/*.test.ts"
61
71
  },
62
72
  "dependencies": {
63
- "jose": "^6.1.0"
73
+ "jose": "^6.1.0",
74
+ "passport-oauth2": "^1.8.0"
64
75
  },
65
76
  "peerDependencies": {
66
77
  "react": ">=17"
@@ -72,7 +83,9 @@
72
83
  },
73
84
  "devDependencies": {
74
85
  "@types/node": "^22.19.11",
86
+ "@types/passport-oauth2": "^1.8.0",
75
87
  "@types/react": "^19.0.0",
88
+ "tsup": "^8.5.0",
76
89
  "typescript": "^5.5.0"
77
90
  },
78
91
  "keywords": [
package/src/betterauth.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * export const auth = betterAuth({
13
13
  * socialProviders: [
14
14
  * iamProvider({
15
- * serverUrl: process.env.IAM_SERVER_URL!,
15
+ * serverUrl: process.env.IAM_ENDPOINT!,
16
16
  * clientId: process.env.IAM_CLIENT_ID!,
17
17
  * clientSecret: process.env.IAM_CLIENT_SECRET!,
18
18
  * }),
package/src/nextauth.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * export default NextAuth({
13
13
  * providers: [
14
14
  * IamProvider({
15
- * serverUrl: process.env.IAM_SERVER_URL!,
15
+ * serverUrl: process.env.IAM_ENDPOINT!,
16
16
  * clientId: process.env.IAM_CLIENT_ID!,
17
17
  * clientSecret: process.env.IAM_CLIENT_SECRET!,
18
18
  * }),
package/src/passport.ts CHANGED
@@ -20,6 +20,8 @@
20
20
  * @packageDocumentation
21
21
  */
22
22
 
23
+ import OAuth2Strategy from "passport-oauth2";
24
+
23
25
  import type { IamConfig } from "./types.js";
24
26
 
25
27
  export interface IamPassportConfig extends IamConfig {
@@ -38,23 +40,18 @@ export interface IamPassportUser {
38
40
  /**
39
41
  * Create a Passport OAuth2 strategy for Hanzo IAM.
40
42
  *
41
- * Requires `passport-oauth2` as a peer dependency.
42
43
  * Returns an OAuth2Strategy instance ready to pass to `passport.use()`.
43
- *
44
44
  * The verify callback fetches userinfo from the IAM server and passes
45
45
  * `{ accessToken, refreshToken, userinfo }` as the user object.
46
+ *
47
+ * `passport-oauth2` is a runtime dependency of this entry — using a
48
+ * static import lets downstream bundlers (esbuild, webpack, etc.)
49
+ * statically resolve and bundle it. Consumers who don't need passport
50
+ * can import from `@hanzo/iam` directly to avoid pulling it in.
46
51
  */
47
52
  export function createIamPassportStrategy(
48
53
  config: IamPassportConfig,
49
54
  ): unknown {
50
- // Dynamic import to keep passport-oauth2 as optional peer dep.
51
- // eslint-disable-next-line @typescript-eslint/no-require-imports
52
- const { Strategy: OAuth2Strategy } = require("passport-oauth2") as {
53
- Strategy: new (
54
- options: Record<string, unknown>,
55
- verify: (...args: unknown[]) => void,
56
- ) => unknown;
57
- };
58
55
 
59
56
  const baseUrl = config.serverUrl.replace(/\/+$/, "");
60
57
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAgB,MAAM,YAAY,CAAC;AAiBzE,uEAAuE;AACvE,wBAAgB,cAAc,IAAI,IAAI,CAErC;AA4CD;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,aAAa,CAAC,CA6ExB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"betterauth.d.ts","sourceRoot":"","sources":["../src/betterauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC1D,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK;QAC7C,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;KACtB,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,iBAAiB,CA6BnB;AAGD,0CAA0C;AAC1C,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,CAAC;AAC3C,0CAA0C;AAC1C,OAAO,EAAE,WAAW,IAAI,sBAAsB,EAAE,CAAC;AACjD,gDAAgD;AAChD,YAAY,EAAE,iBAAiB,IAAI,sBAAsB,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAmB1E,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG;IAClC,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,qBAAa,GAAG;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,cAAc,CAA8B;gBAExC,MAAM,EAAE,SAAS;YASf,YAAY;IAqC1B;;;;;OAKG;IACG,cAAc,CAAC,MAAM,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,M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C,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAC1F,OAAO,CAAC,CAAC,CAAC;CAGd;AAMD,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK5C"}
package/dist/client.js DELETED
@@ -1,292 +0,0 @@
1
- /**
2
- * Core HTTP client for Hanzo IAM API.
3
- */
4
- const DEFAULT_TIMEOUT_MS = 10_000;
5
- export class IamClient {
6
- baseUrl;
7
- clientId;
8
- clientSecret;
9
- orgName;
10
- appName;
11
- discoveryCache = null;
12
- constructor(config) {
13
- this.baseUrl = config.serverUrl.replace(/\/+$/, "");
14
- this.clientId = config.clientId;
15
- this.clientSecret = config.clientSecret;
16
- this.orgName = config.orgName;
17
- this.appName = config.appName;
18
- }
19
- // -----------------------------------------------------------------------
20
- // Internal HTTP helpers
21
- // -----------------------------------------------------------------------
22
- async request(path, opts) {
23
- const url = new URL(path, this.baseUrl);
24
- if (opts?.params) {
25
- for (const [k, v] of Object.entries(opts.params)) {
26
- url.searchParams.set(k, v);
27
- }
28
- }
29
- const controller = new AbortController();
30
- const timer = setTimeout(() => controller.abort(), opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS);
31
- const headers = {
32
- Accept: "application/json",
33
- };
34
- if (opts?.token) {
35
- headers.Authorization = `Bearer ${opts.token}`;
36
- }
37
- if (opts?.body) {
38
- headers["Content-Type"] = "application/json";
39
- }
40
- // Server-side basic auth for confidential client operations
41
- if (this.clientSecret && !opts?.token) {
42
- const credentials = `${this.clientId}:${this.clientSecret}`;
43
- const basic = typeof Buffer !== "undefined"
44
- ? Buffer.from(credentials).toString("base64")
45
- : btoa(credentials);
46
- headers.Authorization = `Basic ${basic}`;
47
- }
48
- try {
49
- const res = await fetch(url.toString(), {
50
- method: opts?.method ?? "GET",
51
- headers,
52
- body: opts?.body ? JSON.stringify(opts.body) : undefined,
53
- signal: controller.signal,
54
- });
55
- if (!res.ok) {
56
- const text = await res.text().catch(() => "");
57
- throw new IamApiError(res.status, `${res.statusText}: ${text}`.trim());
58
- }
59
- return (await res.json());
60
- }
61
- finally {
62
- clearTimeout(timer);
63
- }
64
- }
65
- // -----------------------------------------------------------------------
66
- // OIDC Discovery
67
- // -----------------------------------------------------------------------
68
- async getDiscovery() {
69
- const CACHE_TTL_MS = 5 * 60 * 1000;
70
- if (this.discoveryCache && Date.now() - this.discoveryCache.fetchedAt < CACHE_TTL_MS) {
71
- return this.discoveryCache.data;
72
- }
73
- const data = await this.request("/.well-known/openid-configuration");
74
- this.discoveryCache = { data, fetchedAt: Date.now() };
75
- return data;
76
- }
77
- /** Get JWKS URI from OIDC discovery (cached). */
78
- async getJwksUri() {
79
- const discovery = await this.getDiscovery();
80
- return discovery.jwks_uri;
81
- }
82
- // -----------------------------------------------------------------------
83
- // OAuth2 / Token
84
- // -----------------------------------------------------------------------
85
- /** Build the authorization URL for user login redirect. */
86
- async getAuthorizationUrl(params) {
87
- const discovery = await this.getDiscovery();
88
- const url = new URL(discovery.authorization_endpoint);
89
- url.searchParams.set("client_id", this.clientId);
90
- url.searchParams.set("response_type", "code");
91
- url.searchParams.set("redirect_uri", params.redirectUri);
92
- url.searchParams.set("state", params.state);
93
- url.searchParams.set("scope", params.scope ?? "openid profile email");
94
- if (params.codeChallenge) {
95
- url.searchParams.set("code_challenge", params.codeChallenge);
96
- url.searchParams.set("code_challenge_method", params.codeChallengeMethod ?? "S256");
97
- }
98
- return url.toString();
99
- }
100
- /** Exchange authorization code for tokens. */
101
- async exchangeCode(params) {
102
- const discovery = await this.getDiscovery();
103
- const body = new URLSearchParams({
104
- grant_type: "authorization_code",
105
- client_id: this.clientId,
106
- code: params.code,
107
- redirect_uri: params.redirectUri,
108
- });
109
- if (this.clientSecret) {
110
- body.set("client_secret", this.clientSecret);
111
- }
112
- if (params.codeVerifier) {
113
- body.set("code_verifier", params.codeVerifier);
114
- }
115
- const controller = new AbortController();
116
- const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
117
- try {
118
- const res = await fetch(discovery.token_endpoint, {
119
- method: "POST",
120
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
121
- body: body.toString(),
122
- signal: controller.signal,
123
- });
124
- if (!res.ok) {
125
- const text = await res.text().catch(() => "");
126
- throw new IamApiError(res.status, `Token exchange failed: ${text}`);
127
- }
128
- return (await res.json());
129
- }
130
- finally {
131
- clearTimeout(timer);
132
- }
133
- }
134
- /**
135
- * Resource Owner Password Credentials grant.
136
- * Used for service-to-service auth, CLI login, and e2e tests.
137
- */
138
- async passwordGrant(params) {
139
- const discovery = await this.getDiscovery();
140
- const body = new URLSearchParams({
141
- grant_type: "password",
142
- client_id: this.clientId,
143
- username: params.username,
144
- password: params.password,
145
- scope: params.scope ?? "openid profile email phone",
146
- });
147
- if (this.clientSecret) {
148
- body.set("client_secret", this.clientSecret);
149
- }
150
- const controller = new AbortController();
151
- const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
152
- try {
153
- const res = await fetch(discovery.token_endpoint, {
154
- method: "POST",
155
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
156
- body: body.toString(),
157
- signal: controller.signal,
158
- });
159
- if (!res.ok) {
160
- const text = await res.text().catch(() => "");
161
- throw new IamApiError(res.status, `Password grant failed: ${text}`);
162
- }
163
- return (await res.json());
164
- }
165
- finally {
166
- clearTimeout(timer);
167
- }
168
- }
169
- /** Refresh an access token. */
170
- async refreshToken(refreshToken) {
171
- const discovery = await this.getDiscovery();
172
- const body = new URLSearchParams({
173
- grant_type: "refresh_token",
174
- client_id: this.clientId,
175
- refresh_token: refreshToken,
176
- });
177
- if (this.clientSecret) {
178
- body.set("client_secret", this.clientSecret);
179
- }
180
- const controller = new AbortController();
181
- const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
182
- try {
183
- const res = await fetch(discovery.token_endpoint, {
184
- method: "POST",
185
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
186
- body: body.toString(),
187
- signal: controller.signal,
188
- });
189
- if (!res.ok) {
190
- const text = await res.text().catch(() => "");
191
- throw new IamApiError(res.status, `Token refresh failed: ${text}`);
192
- }
193
- return (await res.json());
194
- }
195
- finally {
196
- clearTimeout(timer);
197
- }
198
- }
199
- // -----------------------------------------------------------------------
200
- // User
201
- // -----------------------------------------------------------------------
202
- /** Get user info from access token (OIDC userinfo endpoint). */
203
- async getUserInfo(accessToken) {
204
- const discovery = await this.getDiscovery();
205
- const controller = new AbortController();
206
- const timer = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
207
- try {
208
- const res = await fetch(discovery.userinfo_endpoint, {
209
- headers: { Authorization: `Bearer ${accessToken}` },
210
- signal: controller.signal,
211
- });
212
- if (!res.ok) {
213
- throw new IamApiError(res.status, "Failed to fetch userinfo");
214
- }
215
- return (await res.json());
216
- }
217
- finally {
218
- clearTimeout(timer);
219
- }
220
- }
221
- /** Get a user by ID ("org/username" format). */
222
- async getUser(userId, token) {
223
- const resp = await this.request("/api/get-user", {
224
- params: { id: userId },
225
- token,
226
- });
227
- return resp.data ?? null;
228
- }
229
- // -----------------------------------------------------------------------
230
- // Organization
231
- // -----------------------------------------------------------------------
232
- /** List organizations (for the configured owner). */
233
- async getOrganizations(token) {
234
- const owner = this.orgName ?? "admin";
235
- const resp = await this.request("/api/get-organizations", { params: { owner }, token });
236
- return resp.data ?? [];
237
- }
238
- /** Get a specific organization. */
239
- async getOrganization(id, token) {
240
- const resp = await this.request("/api/get-organization", { params: { id }, token });
241
- return resp.data ?? null;
242
- }
243
- /** Get organizations a user belongs to. */
244
- async getUserOrganizations(userId, token) {
245
- // IAM returns orgs the user is a member of via the user's properties.
246
- // We can also query via get-user and read their signupApplication/org.
247
- const user = await this.getUser(userId, token);
248
- if (!user)
249
- return [];
250
- // The owner field on a user is their org
251
- const org = await this.getOrganization(`admin/${user.owner}`, token);
252
- return org ? [org] : [];
253
- }
254
- // -----------------------------------------------------------------------
255
- // Project
256
- // -----------------------------------------------------------------------
257
- /** List projects (for the configured owner). */
258
- async getProjects(token) {
259
- const owner = this.orgName ?? "admin";
260
- const resp = await this.request("/api/get-projects", { params: { owner }, token });
261
- return resp.data ?? [];
262
- }
263
- /** Get a specific project by ID ("owner/name" format). */
264
- async getProject(id, token) {
265
- const resp = await this.request("/api/get-project", { params: { id }, token });
266
- return resp.data ?? null;
267
- }
268
- /** Get all projects for an organization. */
269
- async getOrganizationProjects(organization, token) {
270
- const resp = await this.request("/api/get-organization-projects", { params: { organization }, token });
271
- return resp.data ?? [];
272
- }
273
- // -----------------------------------------------------------------------
274
- // Raw request (for extending)
275
- // -----------------------------------------------------------------------
276
- /** Make an arbitrary authenticated request to the IAM API. */
277
- async apiRequest(path, opts) {
278
- return this.request(path, opts);
279
- }
280
- }
281
- // ---------------------------------------------------------------------------
282
- // Error
283
- // ---------------------------------------------------------------------------
284
- export class IamApiError extends Error {
285
- status;
286
- constructor(status, message) {
287
- super(message);
288
- this.name = "IamApiError";
289
- this.status = status;
290
- }
291
- }
292
- //# sourceMappingURL=client.js.map