@blimu/backend 1.2.0 → 1.2.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 (88) hide show
  1. package/README.md +67 -58
  2. package/dist/client.cjs +164 -14
  3. package/dist/client.cjs.map +1 -1
  4. package/dist/client.d.mts +36 -2
  5. package/dist/client.d.ts +36 -2
  6. package/dist/client.mjs +161 -11
  7. package/dist/client.mjs.map +1 -1
  8. package/dist/index.cjs +530 -236
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.mts +265 -108
  11. package/dist/index.d.ts +265 -108
  12. package/dist/index.mjs +518 -226
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/{schema-BbKn_i-U.d.mts → schema-CdEZKE7E.d.mts} +162 -39
  15. package/dist/{schema-BbKn_i-U.d.ts → schema-CdEZKE7E.d.ts} +162 -39
  16. package/dist/schema.cjs.map +1 -1
  17. package/dist/schema.d.mts +2 -1
  18. package/dist/schema.d.ts +2 -1
  19. package/dist/services/auth_jwks.cjs +69 -0
  20. package/dist/services/auth_jwks.cjs.map +1 -0
  21. package/dist/services/auth_jwks.d.mts +13 -0
  22. package/dist/services/auth_jwks.d.ts +13 -0
  23. package/dist/services/auth_jwks.mjs +44 -0
  24. package/dist/services/auth_jwks.mjs.map +1 -0
  25. package/dist/services/bulk_resources.cjs +47 -0
  26. package/dist/services/bulk_resources.cjs.map +1 -0
  27. package/dist/services/bulk_resources.d.mts +11 -0
  28. package/dist/services/bulk_resources.d.ts +11 -0
  29. package/dist/services/bulk_resources.mjs +22 -0
  30. package/dist/services/bulk_resources.mjs.map +1 -0
  31. package/dist/services/bulk_roles.cjs +47 -0
  32. package/dist/services/bulk_roles.cjs.map +1 -0
  33. package/dist/services/bulk_roles.d.mts +11 -0
  34. package/dist/services/bulk_roles.d.ts +11 -0
  35. package/dist/services/bulk_roles.mjs +22 -0
  36. package/dist/services/bulk_roles.mjs.map +1 -0
  37. package/dist/services/entitlements.cjs +71 -0
  38. package/dist/services/entitlements.cjs.map +1 -0
  39. package/dist/services/entitlements.d.mts +13 -0
  40. package/dist/services/entitlements.d.ts +13 -0
  41. package/dist/services/entitlements.mjs +46 -0
  42. package/dist/services/entitlements.mjs.map +1 -0
  43. package/dist/services/oauth.cjs +142 -0
  44. package/dist/services/oauth.cjs.map +1 -0
  45. package/dist/services/oauth.d.mts +19 -0
  46. package/dist/services/oauth.d.ts +19 -0
  47. package/dist/services/oauth.mjs +117 -0
  48. package/dist/services/oauth.mjs.map +1 -0
  49. package/dist/services/plans.cjs +69 -0
  50. package/dist/services/plans.cjs.map +1 -0
  51. package/dist/services/plans.d.mts +13 -0
  52. package/dist/services/plans.d.ts +13 -0
  53. package/dist/services/plans.mjs +44 -0
  54. package/dist/services/plans.mjs.map +1 -0
  55. package/dist/services/resource_members.cjs +47 -0
  56. package/dist/services/resource_members.cjs.map +1 -0
  57. package/dist/services/resource_members.d.mts +11 -0
  58. package/dist/services/resource_members.d.ts +11 -0
  59. package/dist/services/resource_members.mjs +22 -0
  60. package/dist/services/resource_members.mjs.map +1 -0
  61. package/dist/services/resources.cjs +93 -0
  62. package/dist/services/resources.cjs.map +1 -0
  63. package/dist/services/resources.d.mts +15 -0
  64. package/dist/services/resources.d.ts +15 -0
  65. package/dist/services/resources.mjs +68 -0
  66. package/dist/services/resources.mjs.map +1 -0
  67. package/dist/services/roles.cjs +70 -0
  68. package/dist/services/roles.cjs.map +1 -0
  69. package/dist/services/roles.d.mts +13 -0
  70. package/dist/services/roles.d.ts +13 -0
  71. package/dist/services/roles.mjs +45 -0
  72. package/dist/services/roles.mjs.map +1 -0
  73. package/dist/services/usage.cjs +95 -0
  74. package/dist/services/usage.cjs.map +1 -0
  75. package/dist/services/usage.d.mts +15 -0
  76. package/dist/services/usage.d.ts +15 -0
  77. package/dist/services/usage.mjs +70 -0
  78. package/dist/services/usage.mjs.map +1 -0
  79. package/dist/services/users.cjs +104 -0
  80. package/dist/services/users.cjs.map +1 -0
  81. package/dist/services/users.d.mts +16 -0
  82. package/dist/services/users.d.ts +16 -0
  83. package/dist/services/users.mjs +79 -0
  84. package/dist/services/users.mjs.map +1 -0
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +5 -4
  87. package/dist/client-B-ZYoU15.d.mts +0 -95
  88. package/dist/client-GKBT3WCg.d.ts +0 -95
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/client.ts
8
- import { FetchClient as FetchClient10, FetchError } from "@blimu/fetch";
8
+ import { FetchClient, FetchError } from "@blimu/fetch";
9
9
  import "@blimu/fetch";
10
10
 
11
11
  // src/auth-strategies.ts
@@ -22,11 +22,46 @@ function buildAuthStrategies(cfg) {
22
22
  return authStrategies;
23
23
  }
24
24
 
25
- // src/services/bulk_resources.ts
26
- import "@blimu/fetch";
27
-
28
- // src/schema.ts
29
- var schema_exports = {};
25
+ // src/services/auth_jwks.ts
26
+ var AuthJwksService = class {
27
+ constructor(core) {
28
+ this.core = core;
29
+ }
30
+ /**
31
+ * GET /v1/auth/.well-known/jwks.json*
32
+ * @summary Get JSON Web Key Set for environment (Public)*
33
+ * @description Returns the public keys used to verify JWT tokens issued by this environment. Authenticate using either x-api-key header (secretKey) or x-blimu-publishable-key header (publishableKey).*/
34
+ getJwks(init) {
35
+ return this.core.request({
36
+ method: "GET",
37
+ path: `/v1/auth/.well-known/jwks.json`,
38
+ ...init ?? {}
39
+ });
40
+ }
41
+ /**
42
+ * GET /v1/auth/.well-known/public-key.pem*
43
+ * @summary Get environment public key (PEM)*
44
+ * @description Returns the public key in PEM format for verifying JWT tokens. Authenticate with x-api-key or x-blimu-publishable-key.*/
45
+ getPublicKeyPem(init) {
46
+ return this.core.request({
47
+ method: "GET",
48
+ path: `/v1/auth/.well-known/public-key.pem`,
49
+ ...init ?? {}
50
+ });
51
+ }
52
+ /**
53
+ * GET /v1/auth/oauth/.well-known/jwks.json*
54
+ * @summary Get JSON Web Key Set for OAuth app (Public)*
55
+ * @description Returns the public key for a specific OAuth app to verify JWT tokens. This is a public endpoint following OAuth2/OIDC standards. Provide client_id to get keys for a specific OAuth app, or use authenticated endpoint for environment keys.*/
56
+ getOAuthAppJwks(query, init) {
57
+ return this.core.request({
58
+ method: "GET",
59
+ path: `/v1/auth/oauth/.well-known/jwks.json`,
60
+ query,
61
+ ...init ?? {}
62
+ });
63
+ }
64
+ };
30
65
 
31
66
  // src/services/bulk_resources.ts
32
67
  var BulkResourcesService = class {
@@ -48,7 +83,6 @@ var BulkResourcesService = class {
48
83
  };
49
84
 
50
85
  // src/services/bulk_roles.ts
51
- import "@blimu/fetch";
52
86
  var BulkRolesService = class {
53
87
  constructor(core) {
54
88
  this.core = core;
@@ -68,7 +102,6 @@ var BulkRolesService = class {
68
102
  };
69
103
 
70
104
  // src/services/entitlements.ts
71
- import "@blimu/fetch";
72
105
  var EntitlementsService = class {
73
106
  constructor(core) {
74
107
  this.core = core;
@@ -111,8 +144,121 @@ var EntitlementsService = class {
111
144
  }
112
145
  };
113
146
 
147
+ // src/services/oauth.ts
148
+ var OauthService = class {
149
+ constructor(core) {
150
+ this.core = core;
151
+ }
152
+ /**
153
+ * GET /v1/oauth/authorize*
154
+ * @summary Check consent requirement*
155
+ * @description Checks if user consent is required for the OAuth2 app and requested scopes.*/
156
+ checkConsentRequired(query, init) {
157
+ return this.core.request({
158
+ method: "GET",
159
+ path: `/v1/oauth/authorize`,
160
+ query,
161
+ ...init ?? {}
162
+ });
163
+ }
164
+ /**
165
+ * POST /v1/oauth/authorize*
166
+ * @summary Authorize OAuth2 application*
167
+ * @description Handles user consent approval/denial. Validates auto_approved flag against consent requirements.*/
168
+ authorize(body, init) {
169
+ return this.core.request({
170
+ method: "POST",
171
+ path: `/v1/oauth/authorize`,
172
+ body,
173
+ ...init ?? {}
174
+ });
175
+ }
176
+ /**
177
+ * POST /v1/oauth/device/authorize*
178
+ * @summary Authorize or deny device code*
179
+ * @description Allows an authenticated user to authorize or deny a device code request. Requires valid user session.*/
180
+ authorizeDeviceCode(body, init) {
181
+ return this.core.request({
182
+ method: "POST",
183
+ path: `/v1/oauth/device/authorize`,
184
+ body,
185
+ ...init ?? {}
186
+ });
187
+ }
188
+ /**
189
+ * POST /v1/oauth/device/code*
190
+ * @summary Request device authorization codes*
191
+ * @description Initiates device authorization flow. Returns device_code (for polling) and user_code (for user entry).*/
192
+ requestDeviceCode(body, init) {
193
+ return this.core.request({
194
+ method: "POST",
195
+ path: `/v1/oauth/device/code`,
196
+ body,
197
+ ...init ?? {}
198
+ });
199
+ }
200
+ /**
201
+ * GET /v1/oauth/device/code/{user_code}*
202
+ * @summary Get device code information*
203
+ * @description Returns device code information including app name, scopes, and consent requirement status.*/
204
+ getDeviceCodeInfo(user_code, init) {
205
+ return this.core.request({
206
+ method: "GET",
207
+ path: `/v1/oauth/device/code/${encodeURIComponent(user_code)}`,
208
+ ...init ?? {}
209
+ });
210
+ }
211
+ /**
212
+ * POST /v1/oauth/device/token*
213
+ * @summary Poll for device authorization tokens*
214
+ * @description Client polls this endpoint to exchange device_code for tokens once user has authorized.*/
215
+ exchangeDeviceCode(body, init) {
216
+ return this.core.request({
217
+ method: "POST",
218
+ path: `/v1/oauth/device/token`,
219
+ body,
220
+ ...init ?? {}
221
+ });
222
+ }
223
+ /**
224
+ * POST /v1/oauth/introspect*
225
+ * @summary Introspect token*
226
+ * @description Validates a token and returns metadata. Requires client authentication.*/
227
+ introspect(body, init) {
228
+ return this.core.request({
229
+ method: "POST",
230
+ path: `/v1/oauth/introspect`,
231
+ body,
232
+ ...init ?? {}
233
+ });
234
+ }
235
+ /**
236
+ * POST /v1/oauth/revoke*
237
+ * @summary Revoke token*
238
+ * @description Revokes an access or refresh token. Requires client authentication.*/
239
+ revoke(body, init) {
240
+ return this.core.request({
241
+ method: "POST",
242
+ path: `/v1/oauth/revoke`,
243
+ body,
244
+ ...init ?? {}
245
+ });
246
+ }
247
+ /**
248
+ * POST /v1/oauth/token*
249
+ * @summary Token endpoint*
250
+ * @description Issues access and refresh tokens. Supports authorization_code and refresh_token (always available per OAuth2 spec).*/
251
+ token(body, init) {
252
+ return this.core.request({
253
+ method: "POST",
254
+ path: `/v1/oauth/token`,
255
+ body,
256
+ ...init ?? {}
257
+ });
258
+ }
259
+ };
260
+
114
261
  // src/services/plans.ts
115
- import "@blimu/fetch";
116
262
  var PlansService = class {
117
263
  constructor(core) {
118
264
  this.core = core;
@@ -154,7 +300,6 @@ var PlansService = class {
154
300
  };
155
301
 
156
302
  // src/services/resource_members.ts
157
- import "@blimu/fetch";
158
303
  var ResourceMembersService = class {
159
304
  constructor(core) {
160
305
  this.core = core;
@@ -174,7 +319,6 @@ var ResourceMembersService = class {
174
319
  };
175
320
 
176
321
  // src/services/resources.ts
177
- import "@blimu/fetch";
178
322
  var ResourcesService = class {
179
323
  constructor(core) {
180
324
  this.core = core;
@@ -240,7 +384,6 @@ var ResourcesService = class {
240
384
  };
241
385
 
242
386
  // src/services/roles.ts
243
- import "@blimu/fetch";
244
387
  var RolesService = class {
245
388
  constructor(core) {
246
389
  this.core = core;
@@ -283,7 +426,6 @@ var RolesService = class {
283
426
  };
284
427
 
285
428
  // src/services/usage.ts
286
- import "@blimu/fetch";
287
429
  var UsageService = class {
288
430
  constructor(core) {
289
431
  this.core = core;
@@ -351,7 +493,6 @@ var UsageService = class {
351
493
  };
352
494
 
353
495
  // src/services/users.ts
354
- import "@blimu/fetch";
355
496
  var UsersService = class {
356
497
  constructor(core) {
357
498
  this.core = core;
@@ -429,9 +570,11 @@ var UsersService = class {
429
570
 
430
571
  // src/client.ts
431
572
  var Blimu = class {
573
+ authJwks;
432
574
  bulkResources;
433
575
  bulkRoles;
434
576
  entitlements;
577
+ oauth;
435
578
  plans;
436
579
  resourceMembers;
437
580
  resources;
@@ -442,14 +585,16 @@ var Blimu = class {
442
585
  const restCfg = { ...options ?? {} };
443
586
  delete restCfg.apiKey;
444
587
  const authStrategies = buildAuthStrategies(options ?? {});
445
- const core = new FetchClient10({
588
+ const core = new FetchClient({
446
589
  ...restCfg,
447
590
  baseURL: options?.baseURL ?? "https://api.blimu.dev",
448
591
  ...authStrategies.length > 0 ? { authStrategies } : {}
449
592
  });
593
+ this.authJwks = new AuthJwksService(core);
450
594
  this.bulkResources = new BulkResourcesService(core);
451
595
  this.bulkRoles = new BulkRolesService(core);
452
596
  this.entitlements = new EntitlementsService(core);
597
+ this.oauth = new OauthService(core);
453
598
  this.plans = new PlansService(core);
454
599
  this.resourceMembers = new ResourceMembersService(core);
455
600
  this.resources = new ResourcesService(core);
@@ -490,19 +635,37 @@ function isNotUndefined(arr) {
490
635
  );
491
636
  }
492
637
 
638
+ // src/schema.ts
639
+ var schema_exports = {};
640
+
493
641
  // src/schema.zod.ts
494
642
  var schema_zod_exports = {};
495
643
  __export(schema_zod_exports, {
644
+ AuthJwksGetOAuthAppJwksQuerySchema: () => AuthJwksGetOAuthAppJwksQuerySchema,
645
+ AuthorizeRequestSchema: () => AuthorizeRequestSchema,
496
646
  BalanceResponseSchema: () => BalanceResponseSchema,
497
647
  CheckLimitResponseSchema: () => CheckLimitResponseSchema,
648
+ ConsentCheckResponseSchema: () => ConsentCheckResponseSchema,
649
+ DeviceAuthorizeRequestSchema: () => DeviceAuthorizeRequestSchema,
650
+ DeviceAuthorizeResponseSchema: () => DeviceAuthorizeResponseSchema,
651
+ DeviceCodeInfoResponseSchema: () => DeviceCodeInfoResponseSchema,
652
+ DeviceCodeRequestSchema: () => DeviceCodeRequestSchema,
653
+ DeviceCodeResponseSchema: () => DeviceCodeResponseSchema,
654
+ DeviceTokenRequestSchema: () => DeviceTokenRequestSchema,
498
655
  EntitlementCheckBodySchema: () => EntitlementCheckBodySchema,
499
656
  EntitlementCheckResultSchema: () => EntitlementCheckResultSchema,
657
+ EntitlementTypeSchema: () => EntitlementTypeSchema,
500
658
  EntitlementsListForResourceQuerySchema: () => EntitlementsListForResourceQuerySchema,
501
659
  EntitlementsListForTenantQuerySchema: () => EntitlementsListForTenantQuerySchema,
502
660
  EntitlementsListResultSchema: () => EntitlementsListResultSchema,
661
+ IntrospectionRequestSchema: () => IntrospectionRequestSchema,
662
+ IntrospectionResponseSchema: () => IntrospectionResponseSchema,
663
+ JWKSchema: () => JWKSchema,
664
+ OauthCheckConsentRequiredQuerySchema: () => OauthCheckConsentRequiredQuerySchema,
503
665
  PlanAssignBodySchema: () => PlanAssignBodySchema,
504
666
  PlanDeleteResponseSchema: () => PlanDeleteResponseSchema,
505
667
  PlanResponseSchema: () => PlanResponseSchema,
668
+ PlanTypeSchema: () => PlanTypeSchema,
506
669
  ResourceBulkCreateBodySchema: () => ResourceBulkCreateBodySchema,
507
670
  ResourceBulkResultSchema: () => ResourceBulkResultSchema,
508
671
  ResourceCreateBodySchema: () => ResourceCreateBodySchema,
@@ -510,20 +673,25 @@ __export(schema_zod_exports, {
510
673
  ResourceMemberListSchema: () => ResourceMemberListSchema,
511
674
  ResourceMembersListQuerySchema: () => ResourceMembersListQuerySchema,
512
675
  ResourceSchema: () => ResourceSchema,
676
+ ResourceTypeSchema: () => ResourceTypeSchema,
513
677
  ResourceUpdateBodySchema: () => ResourceUpdateBodySchema,
514
678
  ResourcesListQuerySchema: () => ResourcesListQuerySchema,
679
+ RevocationRequestSchema: () => RevocationRequestSchema,
515
680
  RoleBulkCreateBodySchema: () => RoleBulkCreateBodySchema,
516
681
  RoleBulkResultSchema: () => RoleBulkResultSchema,
517
682
  RoleCreateBodySchema: () => RoleCreateBodySchema,
518
683
  RoleListSchema: () => RoleListSchema,
519
684
  RoleSchema: () => RoleSchema,
520
685
  RolesListQuerySchema: () => RolesListQuerySchema,
686
+ TokenRequestSchema: () => TokenRequestSchema,
687
+ TokenResponseSchema: () => TokenResponseSchema,
521
688
  TransactionHistoryResponseSchema: () => TransactionHistoryResponseSchema,
522
689
  UsageCheckBodySchema: () => UsageCheckBodySchema,
523
690
  UsageConsumeBodySchema: () => UsageConsumeBodySchema,
524
691
  UsageCreditBodySchema: () => UsageCreditBodySchema,
525
692
  UsageGetBalanceQuerySchema: () => UsageGetBalanceQuerySchema,
526
693
  UsageGetTransactionHistoryQuerySchema: () => UsageGetTransactionHistoryQuerySchema,
694
+ UsageLimitTypeSchema: () => UsageLimitTypeSchema,
527
695
  UsageWalletResponseSchema: () => UsageWalletResponseSchema,
528
696
  UserCreateBodySchema: () => UserCreateBodySchema,
529
697
  UserListSchema: () => UserListSchema,
@@ -533,6 +701,32 @@ __export(schema_zod_exports, {
533
701
  UsersListQuerySchema: () => UsersListQuerySchema
534
702
  });
535
703
  import { z } from "zod";
704
+ var EntitlementTypeSchema = z.string();
705
+ var PlanTypeSchema = z.string();
706
+ var ResourceTypeSchema = z.string();
707
+ var UsageLimitTypeSchema = z.string();
708
+ var AuthorizeRequestSchema = z.object({
709
+ /** Action to take: allow or deny */
710
+ action: z.enum(["allow", "deny"]),
711
+ /** True if consent was auto-approved (not required or previously granted) */
712
+ auto_approved: z.boolean().optional(),
713
+ /** OAuth2 client ID */
714
+ client_id: z.string(),
715
+ /** PKCE code challenge */
716
+ code_challenge: z.string().optional(),
717
+ /** PKCE code challenge method */
718
+ code_challenge_method: z.string().optional(),
719
+ /** Redirect URI */
720
+ redirect_uri: z.string(),
721
+ /** Response type (typically "code") */
722
+ response_type: z.string(),
723
+ /** Space-separated list of scopes */
724
+ scope: z.string().optional(),
725
+ /** State parameter for CSRF protection */
726
+ state: z.string().optional(),
727
+ /** True if user explicitly clicked Allow, false if auto-approved */
728
+ user_action: z.boolean().optional()
729
+ });
536
730
  var BalanceResponseSchema = z.object({ balance: z.number() });
537
731
  var CheckLimitResponseSchema = z.object({
538
732
  allowed: z.boolean(),
@@ -540,9 +734,216 @@ var CheckLimitResponseSchema = z.object({
540
734
  remaining: z.number().optional(),
541
735
  requested: z.number()
542
736
  });
737
+ var ConsentCheckResponseSchema = z.object({
738
+ /** Whether user consent is required */
739
+ consent_required: z.boolean(),
740
+ /** Whether consent was previously granted for this app and scopes */
741
+ previously_granted: z.boolean()
742
+ });
743
+ var DeviceAuthorizeRequestSchema = z.object({
744
+ /** Action to take: allow or deny */
745
+ action: z.enum(["allow", "deny"]),
746
+ /** True if consent was auto-approved (not required or previously granted) */
747
+ auto_approved: z.boolean().optional(),
748
+ /** True if user explicitly clicked Allow, false if auto-approved */
749
+ user_action: z.boolean().optional(),
750
+ /** The user code displayed to the user */
751
+ user_code: z.string()
752
+ });
753
+ var DeviceAuthorizeResponseSchema = z.object({
754
+ /** Whether the authorization was successful */
755
+ success: z.boolean()
756
+ });
757
+ var DeviceCodeInfoResponseSchema = z.object({
758
+ /** The name of the OAuth2 application */
759
+ appName: z.string(),
760
+ /** Whether the user has already granted consent for this app and scopes */
761
+ previouslyGranted: z.boolean(),
762
+ /** Whether the app requires user consent */
763
+ requireConsent: z.boolean(),
764
+ /** The scopes requested by the device code */
765
+ scopes: z.string().array()
766
+ });
767
+ var DeviceCodeRequestSchema = z.object({
768
+ /** OAuth2 client ID */
769
+ client_id: z.string(),
770
+ /** PKCE code challenge (base64url encoded SHA256 hash) */
771
+ code_challenge: z.string().optional(),
772
+ /** PKCE code challenge method */
773
+ code_challenge_method: z.enum(["S256", "plain"]).optional(),
774
+ /** Space-separated list of scopes */
775
+ scope: z.string().optional()
776
+ });
777
+ var DeviceCodeResponseSchema = z.object({
778
+ /** Device verification code (for polling) */
779
+ device_code: z.string(),
780
+ /** Device code expiration time in seconds */
781
+ expires_in: z.number(),
782
+ /** Minimum polling interval in seconds */
783
+ interval: z.number(),
784
+ /** User verification code (short, human-readable) */
785
+ user_code: z.string(),
786
+ /** Verification URI for user */
787
+ verification_uri: z.string(),
788
+ /** Complete verification URI with user code */
789
+ verification_uri_complete: z.string()
790
+ });
791
+ var DeviceTokenRequestSchema = z.object({
792
+ /** OAuth2 client ID */
793
+ client_id: z.string(),
794
+ /** PKCE code verifier (if challenge was provided) */
795
+ code_verifier: z.string().optional(),
796
+ /** Device code from authorization response */
797
+ device_code: z.string(),
798
+ /** Grant type (must be device_code) */
799
+ grant_type: z.enum([
800
+ "urn:ietf:params:oauth:grant-type:device_code"
801
+ ])
802
+ });
803
+ var IntrospectionRequestSchema = z.object({
804
+ /** The token to introspect */
805
+ token: z.string(),
806
+ /** Hint about token type */
807
+ token_type_hint: z.enum(["access_token", "refresh_token"]).optional()
808
+ });
809
+ var IntrospectionResponseSchema = z.object({
810
+ /** Whether the token is active */
811
+ active: z.boolean(),
812
+ /** Client ID */
813
+ client_id: z.string().optional(),
814
+ /** Environment ID */
815
+ environment_id: z.string().optional(),
816
+ /** Token expiration timestamp */
817
+ exp: z.number().optional(),
818
+ /** Token issued at timestamp */
819
+ iat: z.number().optional(),
820
+ /** Space-separated list of scopes */
821
+ scope: z.string().optional(),
822
+ /** Subject (user ID) */
823
+ sub: z.string().optional(),
824
+ /** Token type */
825
+ token_type: z.string().optional(),
826
+ /** Username or user ID */
827
+ username: z.string().optional()
828
+ });
829
+ var JWKSchema = z.object({
830
+ keys: z.object({
831
+ alg: z.string(),
832
+ e: z.string(),
833
+ kid: z.string(),
834
+ kty: z.string(),
835
+ n: z.string(),
836
+ use: z.string()
837
+ }).array()
838
+ });
839
+ var PlanDeleteResponseSchema = z.object({ success: z.boolean() });
840
+ var ResourceMemberListSchema = z.object({
841
+ items: z.object({
842
+ inherited: z.boolean(),
843
+ role: z.string(),
844
+ user: z.object({
845
+ avatarUrl: z.string().nullable(),
846
+ createdAt: z.iso.datetime(),
847
+ email: z.email(),
848
+ emailVerified: z.boolean(),
849
+ firstName: z.string().nullable(),
850
+ id: z.string(),
851
+ lastLoginAt: z.iso.datetime().nullable(),
852
+ lastName: z.string().nullable(),
853
+ lookupKey: z.string().nullable(),
854
+ updatedAt: z.iso.datetime()
855
+ }),
856
+ userId: z.string()
857
+ }).array(),
858
+ limit: z.number(),
859
+ page: z.number(),
860
+ total: z.number()
861
+ });
862
+ var RevocationRequestSchema = z.object({
863
+ /** The token to revoke */
864
+ token: z.string(),
865
+ /** Hint about token type */
866
+ token_type_hint: z.enum(["access_token", "refresh_token"]).optional()
867
+ });
868
+ var TokenRequestSchema = z.object({
869
+ /** OAuth2 client ID */
870
+ client_id: z.string(),
871
+ /** OAuth2 client secret (required for confidential clients) */
872
+ client_secret: z.string().optional(),
873
+ /** Authorization code (required for authorization_code grant) */
874
+ code: z.string().optional(),
875
+ /** PKCE code verifier (if challenge was provided) */
876
+ code_verifier: z.string().optional(),
877
+ /** OAuth2 grant type */
878
+ grant_type: z.enum(["authorization_code", "refresh_token"]),
879
+ /** Redirect URI (required for authorization_code grant) */
880
+ redirect_uri: z.string().optional(),
881
+ /** Refresh token (required for refresh_token grant) */
882
+ refresh_token: z.string().optional(),
883
+ /** Space-separated list of scopes (optional for refresh) */
884
+ scope: z.string().optional()
885
+ });
886
+ var TokenResponseSchema = z.object({
887
+ /** Access token (JWT) */
888
+ access_token: z.string(),
889
+ /** Access token expiration time in seconds */
890
+ expires_in: z.number(),
891
+ /** Refresh token (for obtaining new access tokens) */
892
+ refresh_token: z.string(),
893
+ /** Space-separated list of granted scopes */
894
+ scope: z.string().optional(),
895
+ /** Token type */
896
+ token_type: z.string()
897
+ });
898
+ var UserSchema = z.object({
899
+ avatarUrl: z.string().nullable(),
900
+ createdAt: z.iso.datetime(),
901
+ email: z.email(),
902
+ emailVerified: z.boolean(),
903
+ firstName: z.string().nullable(),
904
+ id: z.string(),
905
+ lastLoginAt: z.iso.datetime().nullable(),
906
+ lastName: z.string().nullable(),
907
+ lookupKey: z.string().nullable(),
908
+ updatedAt: z.iso.datetime()
909
+ });
910
+ var UserCreateBodySchema = z.object({
911
+ avatarUrl: z.url().optional(),
912
+ email: z.email(),
913
+ firstName: z.string().nullable().optional(),
914
+ lastName: z.string().nullable().optional(),
915
+ lookupKey: z.string(),
916
+ newUser: z.boolean().nullable().optional(),
917
+ password: z.string().nullable().optional()
918
+ });
919
+ var UserListSchema = z.object({
920
+ items: z.object({
921
+ avatarUrl: z.string().nullable(),
922
+ createdAt: z.iso.datetime(),
923
+ email: z.email(),
924
+ emailVerified: z.boolean(),
925
+ firstName: z.string().nullable(),
926
+ id: z.string(),
927
+ lastLoginAt: z.iso.datetime().nullable(),
928
+ lastName: z.string().nullable(),
929
+ lookupKey: z.string().nullable(),
930
+ updatedAt: z.iso.datetime()
931
+ }).array(),
932
+ limit: z.number(),
933
+ page: z.number(),
934
+ total: z.number()
935
+ });
936
+ var UserUpdateBodySchema = z.object({
937
+ avatarUrl: z.url().nullable().optional(),
938
+ email: z.email().optional(),
939
+ firstName: z.string().nullable().optional(),
940
+ lastName: z.string().nullable().optional(),
941
+ lookupKey: z.string().optional(),
942
+ password: z.string().optional()
943
+ });
543
944
  var EntitlementCheckBodySchema = z.object({
544
945
  amount: z.number().int().optional(),
545
- entitlement: z.string(),
946
+ entitlement: EntitlementTypeSchema,
546
947
  resourceId: z.string(),
547
948
  userId: z.string()
548
949
  });
@@ -552,15 +953,15 @@ var EntitlementCheckResultSchema = z.object({
552
953
  allowed: z.boolean(),
553
954
  current: z.number().optional(),
554
955
  limit: z.number().optional(),
555
- plan: z.string().nullable().optional(),
956
+ plan: PlanTypeSchema.optional(),
556
957
  reason: z.string().optional(),
557
958
  remaining: z.number().optional(),
558
959
  scope: z.string().optional()
559
960
  }).nullable().optional(),
560
961
  plans: z.object({
561
962
  allowed: z.boolean(),
562
- allowedPlans: z.string().array().optional(),
563
- plan: z.string().nullable().optional(),
963
+ allowedPlans: PlanTypeSchema.array().optional(),
964
+ plan: PlanTypeSchema.optional(),
564
965
  reason: z.string().optional()
565
966
  }).nullable().optional(),
566
967
  roles: z.object({
@@ -570,30 +971,29 @@ var EntitlementCheckResultSchema = z.object({
570
971
  userRoles: z.string().array().optional()
571
972
  }).nullable().optional()
572
973
  });
974
+ var PlanAssignBodySchema = z.object({ planKey: PlanTypeSchema });
573
975
  var EntitlementsListResultSchema = z.object({
574
976
  results: z.object({
575
977
  entitlements: z.object({
576
978
  allowed: z.boolean(),
577
979
  allowedByPlan: z.boolean(),
578
980
  allowedByRole: z.boolean(),
579
- allowedPlans: z.string().array().optional(),
981
+ allowedPlans: PlanTypeSchema.array().optional(),
580
982
  allowedRoles: z.string().array(),
581
- currentPlan: z.string().optional(),
983
+ currentPlan: PlanTypeSchema.optional(),
582
984
  currentRole: z.string().optional(),
583
- entitlement: z.string()
985
+ entitlement: EntitlementTypeSchema
584
986
  }).array(),
585
987
  resourceId: z.string(),
586
- resourceType: z.string()
988
+ resourceType: ResourceTypeSchema
587
989
  }).array()
588
990
  });
589
- var PlanAssignBodySchema = z.object({ planKey: z.string() });
590
- var PlanDeleteResponseSchema = z.object({ success: z.boolean() });
591
991
  var PlanResponseSchema = z.object({
592
992
  createdAt: z.iso.datetime(),
593
993
  environmentId: z.string(),
594
- planKey: z.string(),
994
+ planKey: PlanTypeSchema,
595
995
  resourceId: z.string(),
596
- resourceType: z.string(),
996
+ resourceType: ResourceTypeSchema,
597
997
  updatedAt: z.iso.datetime()
598
998
  });
599
999
  var ResourceSchema = z.object({
@@ -602,9 +1002,9 @@ var ResourceSchema = z.object({
602
1002
  name: z.string().nullable(),
603
1003
  parents: z.object({
604
1004
  id: z.string(),
605
- type: z.string()
1005
+ type: ResourceTypeSchema
606
1006
  }).array().optional(),
607
- type: z.string()
1007
+ type: ResourceTypeSchema
608
1008
  });
609
1009
  var ResourceBulkCreateBodySchema = z.object({
610
1010
  resources: z.object({
@@ -612,7 +1012,7 @@ var ResourceBulkCreateBodySchema = z.object({
612
1012
  name: z.string().optional(),
613
1013
  parents: z.object({
614
1014
  id: z.string(),
615
- type: z.string()
1015
+ type: ResourceTypeSchema
616
1016
  }).array().optional(),
617
1017
  roles: z.object({
618
1018
  role: z.string(),
@@ -624,7 +1024,7 @@ var ResourceBulkResultSchema = z.object({
624
1024
  created: z.object({
625
1025
  environmentId: z.string(),
626
1026
  id: z.string(),
627
- type: z.string()
1027
+ type: ResourceTypeSchema
628
1028
  }).array(),
629
1029
  errors: z.object({
630
1030
  error: z.string(),
@@ -634,7 +1034,7 @@ var ResourceBulkResultSchema = z.object({
634
1034
  name: z.string().optional(),
635
1035
  parents: z.object({
636
1036
  id: z.string(),
637
- type: z.string()
1037
+ type: ResourceTypeSchema
638
1038
  }).array().optional(),
639
1039
  roles: z.object({
640
1040
  role: z.string(),
@@ -654,55 +1054,33 @@ var ResourceCreateBodySchema = z.object({
654
1054
  name: z.string().optional(),
655
1055
  parents: z.object({
656
1056
  id: z.string(),
657
- type: z.string()
1057
+ type: ResourceTypeSchema
658
1058
  }).array().optional(),
659
1059
  roles: z.object({
660
1060
  role: z.string(),
661
1061
  userId: z.string()
662
1062
  }).array().optional()
663
1063
  });
664
- var ResourceMemberListSchema = z.object({
665
- items: z.object({
666
- inherited: z.boolean(),
667
- role: z.string(),
668
- user: z.object({
669
- avatarUrl: z.string().nullable(),
670
- createdAt: z.iso.datetime(),
671
- email: z.email(),
672
- emailVerified: z.boolean(),
673
- firstName: z.string().nullable(),
674
- id: z.string(),
675
- lastLoginAt: z.iso.datetime().nullable(),
676
- lastName: z.string().nullable(),
677
- lookupKey: z.string().nullable(),
678
- updatedAt: z.iso.datetime()
679
- }),
680
- userId: z.string()
681
- }).array(),
682
- limit: z.number(),
683
- page: z.number(),
684
- total: z.number()
685
- });
686
1064
  var ResourceUpdateBodySchema = z.object({
687
1065
  name: z.string().optional(),
688
1066
  /** Creates relationships with other resources. Parent resources must already exist. */
689
1067
  parents: z.object({
690
1068
  id: z.string(),
691
- type: z.string()
1069
+ type: ResourceTypeSchema
692
1070
  }).array().optional()
693
1071
  });
694
1072
  var RoleSchema = z.object({
695
1073
  createdAt: z.string(),
696
1074
  environmentId: z.string(),
697
1075
  resourceId: z.string(),
698
- resourceType: z.string(),
1076
+ resourceType: ResourceTypeSchema,
699
1077
  role: z.string(),
700
1078
  userId: z.string()
701
1079
  });
702
1080
  var RoleBulkCreateBodySchema = z.object({
703
1081
  roles: z.object({
704
1082
  resourceId: z.string(),
705
- resourceType: z.string(),
1083
+ resourceType: ResourceTypeSchema,
706
1084
  role: z.string(),
707
1085
  userId: z.string()
708
1086
  }).array()
@@ -712,7 +1090,7 @@ var RoleBulkResultSchema = z.object({
712
1090
  createdAt: z.string(),
713
1091
  environmentId: z.string(),
714
1092
  resourceId: z.string(),
715
- resourceType: z.string(),
1093
+ resourceType: ResourceTypeSchema,
716
1094
  role: z.string(),
717
1095
  userId: z.string()
718
1096
  }).array(),
@@ -721,7 +1099,7 @@ var RoleBulkResultSchema = z.object({
721
1099
  index: z.number(),
722
1100
  role: z.object({
723
1101
  resourceId: z.string(),
724
- resourceType: z.string(),
1102
+ resourceType: ResourceTypeSchema,
725
1103
  role: z.string(),
726
1104
  userId: z.string()
727
1105
  })
@@ -735,7 +1113,7 @@ var RoleBulkResultSchema = z.object({
735
1113
  });
736
1114
  var RoleCreateBodySchema = z.object({
737
1115
  resourceId: z.string(),
738
- resourceType: z.string(),
1116
+ resourceType: ResourceTypeSchema,
739
1117
  role: z.string()
740
1118
  });
741
1119
  var RoleListSchema = z.object({
@@ -745,43 +1123,58 @@ var RoleListSchema = z.object({
745
1123
  createdAt: z.string(),
746
1124
  environmentId: z.string(),
747
1125
  resourceId: z.string(),
748
- resourceType: z.string(),
1126
+ resourceType: ResourceTypeSchema,
749
1127
  role: z.string(),
750
1128
  userId: z.string()
751
1129
  }).array(),
752
1130
  total: z.number()
753
1131
  });
1132
+ var UserResourceListSchema = z.array(
1133
+ z.object({
1134
+ inherited: z.boolean(),
1135
+ resource: z.object({
1136
+ id: z.string(),
1137
+ name: z.string(),
1138
+ parents: z.object({
1139
+ id: z.string(),
1140
+ type: ResourceTypeSchema
1141
+ }).array(),
1142
+ type: ResourceTypeSchema
1143
+ }).catchall(z.unknown()),
1144
+ role: z.string()
1145
+ })
1146
+ );
754
1147
  var TransactionHistoryResponseSchema = z.object({
755
1148
  items: z.object({
756
1149
  amount: z.number().int(),
757
1150
  createdAt: z.iso.datetime(),
758
1151
  environmentId: z.string(),
759
1152
  id: z.string(),
760
- limitType: z.string(),
1153
+ limitType: UsageLimitTypeSchema,
761
1154
  resourceId: z.string(),
762
- resourceType: z.string(),
1155
+ resourceType: ResourceTypeSchema,
763
1156
  tags: z.record(z.string(), z.unknown()).nullable()
764
1157
  }).array()
765
1158
  });
766
1159
  var UsageCheckBodySchema = z.object({
767
1160
  amount: z.number().int(),
768
- limitType: z.string(),
1161
+ limitType: UsageLimitTypeSchema,
769
1162
  period: z.enum(["monthly", "yearly", "lifetime"]),
770
1163
  resourceId: z.string(),
771
- resourceType: z.string()
1164
+ resourceType: ResourceTypeSchema
772
1165
  });
773
1166
  var UsageConsumeBodySchema = z.object({
774
1167
  amount: z.number().int(),
775
- limitType: z.string(),
1168
+ limitType: UsageLimitTypeSchema,
776
1169
  resourceId: z.string(),
777
- resourceType: z.string(),
1170
+ resourceType: ResourceTypeSchema,
778
1171
  tags: z.record(z.string(), z.unknown()).optional()
779
1172
  });
780
1173
  var UsageCreditBodySchema = z.object({
781
1174
  amount: z.number().int(),
782
- limitType: z.string(),
1175
+ limitType: UsageLimitTypeSchema,
783
1176
  resourceId: z.string(),
784
- resourceType: z.string(),
1177
+ resourceType: ResourceTypeSchema,
785
1178
  tags: z.record(z.string(), z.unknown()).optional()
786
1179
  });
787
1180
  var UsageWalletResponseSchema = z.object({
@@ -789,78 +1182,21 @@ var UsageWalletResponseSchema = z.object({
789
1182
  createdAt: z.iso.datetime(),
790
1183
  environmentId: z.string(),
791
1184
  id: z.string(),
792
- limitType: z.string(),
1185
+ limitType: UsageLimitTypeSchema,
793
1186
  resourceId: z.string(),
794
- resourceType: z.string(),
1187
+ resourceType: ResourceTypeSchema,
795
1188
  tags: z.record(z.string(), z.unknown()).nullable()
796
1189
  });
797
- var UserSchema = z.object({
798
- avatarUrl: z.string().nullable(),
799
- createdAt: z.iso.datetime(),
800
- email: z.email(),
801
- emailVerified: z.boolean(),
802
- firstName: z.string().nullable(),
803
- id: z.string(),
804
- lastLoginAt: z.iso.datetime().nullable(),
805
- lastName: z.string().nullable(),
806
- lookupKey: z.string().nullable(),
807
- updatedAt: z.iso.datetime()
808
- });
809
- var UserCreateBodySchema = z.object({
810
- avatarUrl: z.url().optional(),
811
- email: z.email(),
812
- firstName: z.string().nullable().optional(),
813
- lastName: z.string().nullable().optional(),
814
- lookupKey: z.string(),
815
- newUser: z.boolean().nullable().optional(),
816
- password: z.string().nullable().optional()
817
- });
818
- var UserListSchema = z.object({
819
- items: z.object({
820
- avatarUrl: z.string().nullable(),
821
- createdAt: z.iso.datetime(),
822
- email: z.email(),
823
- emailVerified: z.boolean(),
824
- firstName: z.string().nullable(),
825
- id: z.string(),
826
- lastLoginAt: z.iso.datetime().nullable(),
827
- lastName: z.string().nullable(),
828
- lookupKey: z.string().nullable(),
829
- updatedAt: z.iso.datetime()
830
- }).array(),
831
- limit: z.number(),
832
- page: z.number(),
833
- total: z.number()
834
- });
835
- var UserResourceListSchema = z.array(
836
- z.object({
837
- inherited: z.boolean(),
838
- resource: z.object({
839
- id: z.string(),
840
- name: z.string(),
841
- parents: z.object({
842
- id: z.string(),
843
- type: z.string()
844
- }).array(),
845
- type: z.string()
846
- }).catchall(z.unknown()),
847
- role: z.string()
848
- })
849
- );
850
- var UserUpdateBodySchema = z.object({
851
- avatarUrl: z.url().nullable().optional(),
852
- email: z.email().optional(),
853
- firstName: z.string().nullable().optional(),
854
- lastName: z.string().nullable().optional(),
855
- lookupKey: z.string().optional(),
856
- password: z.string().optional()
857
- });
858
1190
  var ResourceListSchema = z.object({
859
1191
  items: ResourceSchema.array(),
860
1192
  limit: z.number(),
861
1193
  page: z.number(),
862
1194
  total: z.number()
863
1195
  });
1196
+ var AuthJwksGetOAuthAppJwksQuerySchema = z.object({
1197
+ /** OAuth app client ID to get public keys for */
1198
+ client_id: z.string().optional()
1199
+ });
864
1200
  var EntitlementsListForResourceQuerySchema = z.object({
865
1201
  /** The unique identifier of the user */
866
1202
  userId: z.string()
@@ -869,6 +1205,14 @@ var EntitlementsListForTenantQuerySchema = z.object({
869
1205
  /** The unique identifier of the user */
870
1206
  userId: z.string()
871
1207
  });
1208
+ var OauthCheckConsentRequiredQuerySchema = z.object({
1209
+ /** OAuth2 client ID */
1210
+ client_id: z.string(),
1211
+ /** Redirect URI */
1212
+ redirect_uri: z.string().optional(),
1213
+ /** Space-separated list of scopes */
1214
+ scope: z.string().optional()
1215
+ });
872
1216
  var ResourceMembersListQuerySchema = z.object({
873
1217
  /** Number of items per page (minimum: 1, maximum: 100) */
874
1218
  limit: z.number().optional(),
@@ -893,7 +1237,7 @@ var RolesListQuerySchema = z.object({
893
1237
  /** Filter roles by specific resource ID */
894
1238
  resourceId: z.string().optional(),
895
1239
  /** Filter roles by resource type */
896
- resourceType: z.string().optional(),
1240
+ resourceType: ResourceTypeSchema.optional(),
897
1241
  /** Filter by role name */
898
1242
  role: z.string().optional()
899
1243
  });
@@ -921,40 +1265,14 @@ var UsersListQuerySchema = z.object({
921
1265
  // src/token-verifier.ts
922
1266
  import * as crypto from "crypto";
923
1267
  import * as jwt from "jsonwebtoken";
1268
+ import { FetchClient as FetchClient2 } from "@blimu/fetch";
924
1269
  var TokenVerifier = class {
925
1270
  cache = /* @__PURE__ */ new Map();
926
1271
  cacheTTL;
927
- runtimeApiUrl;
1272
+ baseURL;
928
1273
  constructor(options) {
929
1274
  this.cacheTTL = options?.cacheTTL ?? 60 * 60 * 1e3;
930
- this.runtimeApiUrl = options?.runtimeApiUrl ?? "https://api.blimu.dev";
931
- }
932
- /**
933
- * Fetch JWK Set from runtime-api
934
- */
935
- async fetchJWKSet(endpoint, headers) {
936
- console.log(`[TokenVerifier] \u{1F4E1} Fetching JWK Set from: ${endpoint}`);
937
- if (headers) {
938
- console.log(
939
- `[TokenVerifier] \u{1F4E1} Request headers: ${JSON.stringify(Object.keys(headers).map((k) => `${k}: ${k === "x-api-key" ? "***" : headers[k]}`))}`
940
- );
941
- }
942
- const response = await fetch(endpoint, {
943
- method: "GET",
944
- headers: {
945
- "Content-Type": "application/json",
946
- ...headers
947
- }
948
- });
949
- console.log(`[TokenVerifier] \u{1F4E1} Response status: ${response.status} ${response.statusText}`);
950
- if (!response.ok) {
951
- const errorText = await response.text();
952
- console.error(`[TokenVerifier] \u274C Failed to fetch JWKs: ${response.status} ${errorText}`);
953
- throw new FetchError("Failed to fetch JWKs", response.status, errorText);
954
- }
955
- const jwkSet = await response.json();
956
- console.log(`[TokenVerifier] \u2705 Successfully fetched JWK Set with ${jwkSet.keys.length} keys`);
957
- return jwkSet;
1275
+ this.baseURL = options?.runtimeApiUrl ?? "https://api.blimu.dev";
958
1276
  }
959
1277
  /**
960
1278
  * Convert JWK to KeyObject
@@ -973,25 +1291,19 @@ var TokenVerifier = class {
973
1291
  /**
974
1292
  * Get public key for a specific key ID
975
1293
  */
976
- async getPublicKey(kid, cacheKey, endpoint, headers) {
1294
+ async getPublicKey(kid, cacheKey, fetchJwks) {
977
1295
  const cached = this.cache.get(cacheKey);
978
1296
  if (cached && cached.expiresAt > Date.now()) {
979
- console.log(`[TokenVerifier] \u2705 Using cached key for kid: ${kid}`);
980
1297
  return cached.key;
981
1298
  }
982
- console.log(`[TokenVerifier] \u{1F50D} Cache miss or expired. Fetching new key for kid: ${kid}`);
983
- const jwkSet = await this.fetchJWKSet(endpoint, headers);
1299
+ const jwkSet = await fetchJwks();
984
1300
  const jwk = jwkSet.keys.find((k) => k.kid === kid);
985
1301
  if (!jwk) {
986
1302
  const availableKids = jwkSet.keys.map((k) => k.kid).join(", ");
987
- console.error(
988
- `[TokenVerifier] \u274C Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`
989
- );
990
1303
  throw new Error(
991
1304
  `Key with kid '${kid}' not found in JWK Set. Available kids: ${availableKids}`
992
1305
  );
993
1306
  }
994
- console.log(`[TokenVerifier] \u2705 Found key with kid: ${kid}`);
995
1307
  const keyObject = this.jwkToKeyObject(jwk);
996
1308
  this.cache.set(cacheKey, {
997
1309
  key: keyObject,
@@ -1001,15 +1313,16 @@ var TokenVerifier = class {
1001
1313
  return keyObject;
1002
1314
  }
1003
1315
  /**
1004
- * Verify JWT token using JWKs from runtime-api
1316
+ * Verify JWT token using JWKs from Blimu runtime API.
1317
+ * Supports: environment/session tokens (secretKey) or OAuth app tokens (clientId).
1005
1318
  */
1006
1319
  async verifyToken(options) {
1007
- const { url, secretKey, token, runtimeApiUrl } = options;
1008
- if (!url && !secretKey) {
1009
- throw new Error("Either url or secretKey must be provided");
1010
- }
1011
- if (url && secretKey) {
1012
- throw new Error("Cannot provide both url and secretKey");
1320
+ const { secretKey, clientId, token, runtimeApiUrl } = options;
1321
+ const provided = [secretKey, clientId].filter(Boolean);
1322
+ if (provided.length !== 1) {
1323
+ throw new Error(
1324
+ "Exactly one of secretKey or clientId must be provided. Use secretKey for environment/session tokens, clientId for OAuth app access tokens."
1325
+ );
1013
1326
  }
1014
1327
  const decoded = jwt.decode(token, { complete: true });
1015
1328
  if (!decoded || typeof decoded === "string") {
@@ -1019,67 +1332,38 @@ var TokenVerifier = class {
1019
1332
  if (!header.kid) {
1020
1333
  throw new Error("Token missing kid in header");
1021
1334
  }
1022
- let endpoint;
1335
+ const baseURL = runtimeApiUrl ?? this.baseURL;
1023
1336
  let cacheKey;
1024
- let headers;
1337
+ let fetchJwks;
1025
1338
  if (secretKey) {
1026
- const apiUrl = runtimeApiUrl ?? this.runtimeApiUrl;
1027
- endpoint = `${apiUrl}/v1/auth/.well-known/jwks.json`;
1028
1339
  cacheKey = secretKey;
1029
- headers = {
1030
- "x-api-key": secretKey
1031
- };
1032
- console.log(
1033
- `[TokenVerifier] \u{1F50D} Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`
1034
- );
1340
+ const core = new FetchClient2({
1341
+ baseURL,
1342
+ authStrategies: buildAuthStrategies({ apiKey: secretKey, baseURL })
1343
+ });
1344
+ const authJwks = new AuthJwksService(core);
1345
+ fetchJwks = () => authJwks.getJwks();
1035
1346
  } else {
1036
- endpoint = url;
1037
- cacheKey = url;
1038
- console.log(
1039
- `[TokenVerifier] \u{1F50D} Verifying token with kid: ${header.kid}, endpoint: ${endpoint}`
1040
- );
1347
+ cacheKey = `oauth:${clientId}`;
1348
+ const core = new FetchClient2({ baseURL });
1349
+ const authJwks = new AuthJwksService(core);
1350
+ fetchJwks = () => authJwks.getOAuthAppJwks({ client_id: clientId });
1041
1351
  }
1042
1352
  let publicKey;
1043
1353
  try {
1044
- publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);
1045
- console.log(`[TokenVerifier] \u2705 Successfully retrieved public key for kid: ${header.kid}`);
1046
- } catch (error) {
1047
- console.error(
1048
- `[TokenVerifier] \u274C Failed to get public key (first attempt): ${error instanceof Error ? error.message : String(error)}`
1049
- );
1354
+ publicKey = await this.getPublicKey(header.kid, cacheKey, fetchJwks);
1355
+ } catch {
1050
1356
  this.clearCache(cacheKey);
1051
- console.log(`[TokenVerifier] \u{1F504} Retrying after cache clear...`);
1052
- try {
1053
- publicKey = await this.getPublicKey(header.kid, cacheKey, endpoint, headers);
1054
- console.log(
1055
- `[TokenVerifier] \u2705 Successfully retrieved public key for kid: ${header.kid} (retry)`
1056
- );
1057
- } catch (retryError) {
1058
- console.error(
1059
- `[TokenVerifier] \u274C Failed to get public key (retry): ${retryError instanceof Error ? retryError.message : String(retryError)}`
1060
- );
1061
- throw retryError;
1062
- }
1063
- }
1064
- try {
1065
- const payload = jwt.verify(token, publicKey, {
1066
- algorithms: ["RS256"]
1067
- });
1068
- console.log(`[TokenVerifier] \u2705 Token verified successfully`);
1069
- return payload;
1070
- } catch (error) {
1071
- console.error(
1072
- `[TokenVerifier] \u274C JWT verification failed: ${error instanceof Error ? error.message : String(error)}`
1073
- );
1074
- throw error;
1357
+ publicKey = await this.getPublicKey(header.kid, cacheKey, fetchJwks);
1075
1358
  }
1359
+ return jwt.verify(token, publicKey, { algorithms: ["RS256"] });
1076
1360
  }
1077
1361
  /**
1078
1362
  * Clear cache (useful for testing or key rotation)
1079
1363
  */
1080
- clearCache(secretKeyOrUrl) {
1081
- if (secretKeyOrUrl) {
1082
- this.cache.delete(secretKeyOrUrl);
1364
+ clearCache(cacheKey) {
1365
+ if (cacheKey) {
1366
+ this.cache.delete(cacheKey);
1083
1367
  } else {
1084
1368
  this.cache.clear();
1085
1369
  }
@@ -1089,7 +1373,14 @@ async function verifyToken(options) {
1089
1373
  const verifier = new TokenVerifier();
1090
1374
  return verifier.verifyToken(options);
1091
1375
  }
1376
+ async function verifyOAuthToken(options) {
1377
+ return verifyToken({
1378
+ ...options,
1379
+ clientId: options.clientId
1380
+ });
1381
+ }
1092
1382
  export {
1383
+ AuthJwksService,
1093
1384
  Blimu,
1094
1385
  BlimuError,
1095
1386
  BulkResourcesService,
@@ -1110,6 +1401,7 @@ export {
1110
1401
  paginate,
1111
1402
  parseNDJSONStream,
1112
1403
  parseSSEStream,
1404
+ verifyOAuthToken,
1113
1405
  verifyToken
1114
1406
  };
1115
1407
  //# sourceMappingURL=index.mjs.map