@auth-gate/core 0.10.0 → 0.12.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
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="icon.png" alt="AuthGate" width="120" height="120" />
2
+ <img src="https://raw.githubusercontent.com/f-starace/authgate/main/packages/core/icon.png" alt="AuthGate" width="120" height="120" />
3
3
  </p>
4
4
 
5
5
  # @auth-gate/core
package/dist/index.cjs CHANGED
@@ -502,11 +502,11 @@ var AuthGateClient = class {
502
502
  Authorization: `Bearer ${this.config.apiKey}`,
503
503
  "Content-Type": "application/json"
504
504
  },
505
- body: JSON.stringify({
505
+ body: JSON.stringify(__spreadValues({
506
506
  callback_url: callbackUrl,
507
507
  state: options == null ? void 0 : options.state,
508
508
  link_to: options == null ? void 0 : options.linkTo
509
- })
509
+ }, (options == null ? void 0 : options.locale) && { locale: options.locale }))
510
510
  }
511
511
  );
512
512
  if (!response.ok) {
@@ -534,12 +534,12 @@ var AuthGateClient = class {
534
534
  Authorization: `Bearer ${this.config.apiKey}`,
535
535
  "Content-Type": "application/json"
536
536
  },
537
- body: JSON.stringify({
537
+ body: JSON.stringify(__spreadValues({
538
538
  email: data.email,
539
539
  password: data.password,
540
540
  name: data.name,
541
541
  callback_url: data.callbackUrl
542
- })
542
+ }, data.locale && { locale: data.locale }))
543
543
  });
544
544
  }
545
545
  /**
@@ -558,11 +558,11 @@ var AuthGateClient = class {
558
558
  Authorization: `Bearer ${this.config.apiKey}`,
559
559
  "Content-Type": "application/json"
560
560
  },
561
- body: JSON.stringify({
561
+ body: JSON.stringify(__spreadValues({
562
562
  email: data.email,
563
563
  password: data.password,
564
564
  callback_url: data.callbackUrl
565
- })
565
+ }, data.locale && { locale: data.locale }))
566
566
  });
567
567
  }
568
568
  /**
@@ -578,10 +578,10 @@ var AuthGateClient = class {
578
578
  Authorization: `Bearer ${this.config.apiKey}`,
579
579
  "Content-Type": "application/json"
580
580
  },
581
- body: JSON.stringify({
581
+ body: JSON.stringify(__spreadValues({
582
582
  email: data.email,
583
583
  callback_url: data.callbackUrl
584
- })
584
+ }, data.locale && { locale: data.locale }))
585
585
  });
586
586
  }
587
587
  /**
@@ -599,10 +599,10 @@ var AuthGateClient = class {
599
599
  Authorization: `Bearer ${this.config.apiKey}`,
600
600
  "Content-Type": "application/json"
601
601
  },
602
- body: JSON.stringify({
602
+ body: JSON.stringify(__spreadValues({
603
603
  token: data.token,
604
604
  password: data.password
605
- })
605
+ }, data.locale && { locale: data.locale }))
606
606
  }
607
607
  );
608
608
  }
@@ -622,10 +622,10 @@ var AuthGateClient = class {
622
622
  Authorization: `Bearer ${this.config.apiKey}`,
623
623
  "Content-Type": "application/json"
624
624
  },
625
- body: JSON.stringify({
625
+ body: JSON.stringify(__spreadValues({
626
626
  email: data.email,
627
627
  callback_url: data.callbackUrl
628
- })
628
+ }, data.locale && { locale: data.locale }))
629
629
  });
630
630
  }
631
631
  // ---------------------------------------------------------------------------
@@ -644,10 +644,10 @@ var AuthGateClient = class {
644
644
  Authorization: `Bearer ${this.config.apiKey}`,
645
645
  "Content-Type": "application/json"
646
646
  },
647
- body: JSON.stringify({
647
+ body: JSON.stringify(__spreadValues({
648
648
  email: data.email,
649
649
  code: data.code
650
- })
650
+ }, data.locale && { locale: data.locale }))
651
651
  });
652
652
  }
653
653
  // ---------------------------------------------------------------------------
package/dist/index.d.cts CHANGED
@@ -260,6 +260,7 @@ declare class AuthGateClient {
260
260
  getOAuthUrl(provider: OAuthProvider, callbackUrl: string, options?: {
261
261
  state?: string;
262
262
  linkTo?: string;
263
+ locale?: string;
263
264
  }): Promise<string>;
264
265
  /**
265
266
  * Register a new user with email and password.
@@ -272,6 +273,7 @@ declare class AuthGateClient {
272
273
  password: string;
273
274
  name?: string;
274
275
  callbackUrl: string;
276
+ locale?: string;
275
277
  }): Promise<Response>;
276
278
  /**
277
279
  * Sign in an existing user with email and password.
@@ -286,6 +288,7 @@ declare class AuthGateClient {
286
288
  email: string;
287
289
  password: string;
288
290
  callbackUrl: string;
291
+ locale?: string;
289
292
  }): Promise<Response>;
290
293
  /**
291
294
  * Send a password reset email to the user.
@@ -296,6 +299,7 @@ declare class AuthGateClient {
296
299
  emailForgotPassword(data: {
297
300
  email: string;
298
301
  callbackUrl: string;
302
+ locale?: string;
299
303
  }): Promise<Response>;
300
304
  /**
301
305
  * Confirm a password reset with the token from the reset email.
@@ -306,6 +310,7 @@ declare class AuthGateClient {
306
310
  emailResetPassword(data: {
307
311
  token: string;
308
312
  password: string;
313
+ locale?: string;
309
314
  }): Promise<Response>;
310
315
  /**
311
316
  * Send a magic link email for passwordless authentication.
@@ -316,6 +321,7 @@ declare class AuthGateClient {
316
321
  magicLinkSend(data: {
317
322
  email: string;
318
323
  callbackUrl: string;
324
+ locale?: string;
319
325
  }): Promise<Response>;
320
326
  /**
321
327
  * Verify an email address using a one-time code.
@@ -326,6 +332,7 @@ declare class AuthGateClient {
326
332
  emailVerifyCode(data: {
327
333
  email: string;
328
334
  code: string;
335
+ locale?: string;
329
336
  }): Promise<Response>;
330
337
  /**
331
338
  * Send an SMS verification code to the user's phone number.
@@ -690,6 +697,10 @@ declare class ConfigurationError extends AuthGateError {
690
697
 
691
698
  /**
692
699
  * Connection details for the AuthGate API.
700
+ *
701
+ * Both fields are optional at the type level because they can be provided
702
+ * via environment variables (`AUTHGATE_URL`, `AUTHGATE_API_KEY`). The CLI
703
+ * auto-loads `.env` and `.env.local` before importing the config file.
693
704
  */
694
705
  type AuthGateConnection = {
695
706
  baseUrl?: string;
@@ -697,13 +708,57 @@ type AuthGateConnection = {
697
708
  };
698
709
  /**
699
710
  * Project-level config shape for `authgate.config.ts`.
700
- * Used by both `@auth-gate/rbac` and `@auth-gate/billing` CLIs.
711
+ *
712
+ * Used by both the `@auth-gate/rbac` and `@auth-gate/billing` CLIs to
713
+ * connect to the AuthGate API when syncing roles, permissions, plans, and
714
+ * features. The config file is auto-discovered in the project root.
701
715
  *
702
716
  * The CLI auto-loads `.env` and `.env.local` before importing this file,
703
- * so you can reference `process.env` or use a typed env module directly.
717
+ * so you can reference `process.env` directly.
718
+ */
719
+ interface AuthGateProjectConfig {
720
+ /**
721
+ * Connection details for the AuthGate API.
722
+ *
723
+ * If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
724
+ * environment variables.
725
+ */
726
+ connection?: AuthGateConnection;
727
+ /**
728
+ * Path to the RBAC config file (`authgate.rbac.ts`).
729
+ *
730
+ * Overrides auto-discovery. Useful in monorepos where the RBAC config
731
+ * lives in a different directory than the project root.
732
+ *
733
+ * @example `"./packages/api/authgate.rbac.ts"`
734
+ */
735
+ rbacConfig?: string;
736
+ /**
737
+ * Path to the Billing config file (`authgate.billing.ts`).
738
+ *
739
+ * Overrides auto-discovery. Useful in monorepos where the billing config
740
+ * lives in a different directory than the project root.
741
+ *
742
+ * @example `"./packages/api/authgate.billing.ts"`
743
+ */
744
+ billingConfig?: string;
745
+ }
746
+ /**
747
+ * Define your project-level AuthGate configuration.
704
748
  *
705
- * @example
749
+ * Create an `authgate.config.ts` file in your project root and export
750
+ * the result of this function as the default export. This gives you
751
+ * type safety and IDE autocomplete for the config.
752
+ *
753
+ * The CLI auto-loads `.env` and `.env.local` before importing the
754
+ * config, so `process.env` values are available.
755
+ *
756
+ * @param config - The project configuration object.
757
+ * @returns The same config object (identity function for type inference).
758
+ *
759
+ * @example Minimal setup (env vars provide connection details)
706
760
  * ```ts
761
+ * // authgate.config.ts
707
762
  * import { defineConfig } from "@auth-gate/core";
708
763
  *
709
764
  * export default defineConfig({
@@ -713,20 +768,33 @@ type AuthGateConnection = {
713
768
  * },
714
769
  * });
715
770
  * ```
716
- */
717
- interface AuthGateProjectConfig {
718
- /** Connection details for the AuthGate API. */
719
- connection?: AuthGateConnection;
720
- /** Path to the RBAC config file (overrides auto-discovery). */
721
- rbacConfig?: string;
722
- /** Path to the Billing config file (overrides auto-discovery). */
723
- billingConfig?: string;
724
- }
725
- /**
726
- * Define your project-level AuthGate config. Use this in `authgate.config.ts`.
727
771
  *
728
- * Provides type safety and IDE autocomplete for the config file.
729
- * This is an identity function — it returns the config as-is.
772
+ * @example Monorepo with custom config paths
773
+ * ```ts
774
+ * // authgate.config.ts
775
+ * import { defineConfig } from "@auth-gate/core";
776
+ *
777
+ * export default defineConfig({
778
+ * connection: {
779
+ * baseUrl: process.env.AUTHGATE_URL,
780
+ * apiKey: process.env.AUTHGATE_API_KEY,
781
+ * },
782
+ * rbacConfig: "./packages/api/authgate.rbac.ts",
783
+ * billingConfig: "./packages/api/authgate.billing.ts",
784
+ * });
785
+ * ```
786
+ *
787
+ * @example Then sync with the CLI
788
+ * ```sh
789
+ * # Scaffold the config file
790
+ * npx @auth-gate/rbac init --config
791
+ *
792
+ * # Sync RBAC roles & permissions
793
+ * npx @auth-gate/rbac sync --apply
794
+ *
795
+ * # Sync billing plans & features
796
+ * npx @auth-gate/billing sync --apply
797
+ * ```
730
798
  */
731
799
  declare function defineConfig(config: AuthGateProjectConfig): AuthGateProjectConfig;
732
800
 
package/dist/index.d.ts CHANGED
@@ -260,6 +260,7 @@ declare class AuthGateClient {
260
260
  getOAuthUrl(provider: OAuthProvider, callbackUrl: string, options?: {
261
261
  state?: string;
262
262
  linkTo?: string;
263
+ locale?: string;
263
264
  }): Promise<string>;
264
265
  /**
265
266
  * Register a new user with email and password.
@@ -272,6 +273,7 @@ declare class AuthGateClient {
272
273
  password: string;
273
274
  name?: string;
274
275
  callbackUrl: string;
276
+ locale?: string;
275
277
  }): Promise<Response>;
276
278
  /**
277
279
  * Sign in an existing user with email and password.
@@ -286,6 +288,7 @@ declare class AuthGateClient {
286
288
  email: string;
287
289
  password: string;
288
290
  callbackUrl: string;
291
+ locale?: string;
289
292
  }): Promise<Response>;
290
293
  /**
291
294
  * Send a password reset email to the user.
@@ -296,6 +299,7 @@ declare class AuthGateClient {
296
299
  emailForgotPassword(data: {
297
300
  email: string;
298
301
  callbackUrl: string;
302
+ locale?: string;
299
303
  }): Promise<Response>;
300
304
  /**
301
305
  * Confirm a password reset with the token from the reset email.
@@ -306,6 +310,7 @@ declare class AuthGateClient {
306
310
  emailResetPassword(data: {
307
311
  token: string;
308
312
  password: string;
313
+ locale?: string;
309
314
  }): Promise<Response>;
310
315
  /**
311
316
  * Send a magic link email for passwordless authentication.
@@ -316,6 +321,7 @@ declare class AuthGateClient {
316
321
  magicLinkSend(data: {
317
322
  email: string;
318
323
  callbackUrl: string;
324
+ locale?: string;
319
325
  }): Promise<Response>;
320
326
  /**
321
327
  * Verify an email address using a one-time code.
@@ -326,6 +332,7 @@ declare class AuthGateClient {
326
332
  emailVerifyCode(data: {
327
333
  email: string;
328
334
  code: string;
335
+ locale?: string;
329
336
  }): Promise<Response>;
330
337
  /**
331
338
  * Send an SMS verification code to the user's phone number.
@@ -690,6 +697,10 @@ declare class ConfigurationError extends AuthGateError {
690
697
 
691
698
  /**
692
699
  * Connection details for the AuthGate API.
700
+ *
701
+ * Both fields are optional at the type level because they can be provided
702
+ * via environment variables (`AUTHGATE_URL`, `AUTHGATE_API_KEY`). The CLI
703
+ * auto-loads `.env` and `.env.local` before importing the config file.
693
704
  */
694
705
  type AuthGateConnection = {
695
706
  baseUrl?: string;
@@ -697,13 +708,57 @@ type AuthGateConnection = {
697
708
  };
698
709
  /**
699
710
  * Project-level config shape for `authgate.config.ts`.
700
- * Used by both `@auth-gate/rbac` and `@auth-gate/billing` CLIs.
711
+ *
712
+ * Used by both the `@auth-gate/rbac` and `@auth-gate/billing` CLIs to
713
+ * connect to the AuthGate API when syncing roles, permissions, plans, and
714
+ * features. The config file is auto-discovered in the project root.
701
715
  *
702
716
  * The CLI auto-loads `.env` and `.env.local` before importing this file,
703
- * so you can reference `process.env` or use a typed env module directly.
717
+ * so you can reference `process.env` directly.
718
+ */
719
+ interface AuthGateProjectConfig {
720
+ /**
721
+ * Connection details for the AuthGate API.
722
+ *
723
+ * If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
724
+ * environment variables.
725
+ */
726
+ connection?: AuthGateConnection;
727
+ /**
728
+ * Path to the RBAC config file (`authgate.rbac.ts`).
729
+ *
730
+ * Overrides auto-discovery. Useful in monorepos where the RBAC config
731
+ * lives in a different directory than the project root.
732
+ *
733
+ * @example `"./packages/api/authgate.rbac.ts"`
734
+ */
735
+ rbacConfig?: string;
736
+ /**
737
+ * Path to the Billing config file (`authgate.billing.ts`).
738
+ *
739
+ * Overrides auto-discovery. Useful in monorepos where the billing config
740
+ * lives in a different directory than the project root.
741
+ *
742
+ * @example `"./packages/api/authgate.billing.ts"`
743
+ */
744
+ billingConfig?: string;
745
+ }
746
+ /**
747
+ * Define your project-level AuthGate configuration.
704
748
  *
705
- * @example
749
+ * Create an `authgate.config.ts` file in your project root and export
750
+ * the result of this function as the default export. This gives you
751
+ * type safety and IDE autocomplete for the config.
752
+ *
753
+ * The CLI auto-loads `.env` and `.env.local` before importing the
754
+ * config, so `process.env` values are available.
755
+ *
756
+ * @param config - The project configuration object.
757
+ * @returns The same config object (identity function for type inference).
758
+ *
759
+ * @example Minimal setup (env vars provide connection details)
706
760
  * ```ts
761
+ * // authgate.config.ts
707
762
  * import { defineConfig } from "@auth-gate/core";
708
763
  *
709
764
  * export default defineConfig({
@@ -713,20 +768,33 @@ type AuthGateConnection = {
713
768
  * },
714
769
  * });
715
770
  * ```
716
- */
717
- interface AuthGateProjectConfig {
718
- /** Connection details for the AuthGate API. */
719
- connection?: AuthGateConnection;
720
- /** Path to the RBAC config file (overrides auto-discovery). */
721
- rbacConfig?: string;
722
- /** Path to the Billing config file (overrides auto-discovery). */
723
- billingConfig?: string;
724
- }
725
- /**
726
- * Define your project-level AuthGate config. Use this in `authgate.config.ts`.
727
771
  *
728
- * Provides type safety and IDE autocomplete for the config file.
729
- * This is an identity function — it returns the config as-is.
772
+ * @example Monorepo with custom config paths
773
+ * ```ts
774
+ * // authgate.config.ts
775
+ * import { defineConfig } from "@auth-gate/core";
776
+ *
777
+ * export default defineConfig({
778
+ * connection: {
779
+ * baseUrl: process.env.AUTHGATE_URL,
780
+ * apiKey: process.env.AUTHGATE_API_KEY,
781
+ * },
782
+ * rbacConfig: "./packages/api/authgate.rbac.ts",
783
+ * billingConfig: "./packages/api/authgate.billing.ts",
784
+ * });
785
+ * ```
786
+ *
787
+ * @example Then sync with the CLI
788
+ * ```sh
789
+ * # Scaffold the config file
790
+ * npx @auth-gate/rbac init --config
791
+ *
792
+ * # Sync RBAC roles & permissions
793
+ * npx @auth-gate/rbac sync --apply
794
+ *
795
+ * # Sync billing plans & features
796
+ * npx @auth-gate/billing sync --apply
797
+ * ```
730
798
  */
731
799
  declare function defineConfig(config: AuthGateProjectConfig): AuthGateProjectConfig;
732
800
 
package/dist/index.mjs CHANGED
@@ -459,11 +459,11 @@ var AuthGateClient = class {
459
459
  Authorization: `Bearer ${this.config.apiKey}`,
460
460
  "Content-Type": "application/json"
461
461
  },
462
- body: JSON.stringify({
462
+ body: JSON.stringify(__spreadValues({
463
463
  callback_url: callbackUrl,
464
464
  state: options == null ? void 0 : options.state,
465
465
  link_to: options == null ? void 0 : options.linkTo
466
- })
466
+ }, (options == null ? void 0 : options.locale) && { locale: options.locale }))
467
467
  }
468
468
  );
469
469
  if (!response.ok) {
@@ -491,12 +491,12 @@ var AuthGateClient = class {
491
491
  Authorization: `Bearer ${this.config.apiKey}`,
492
492
  "Content-Type": "application/json"
493
493
  },
494
- body: JSON.stringify({
494
+ body: JSON.stringify(__spreadValues({
495
495
  email: data.email,
496
496
  password: data.password,
497
497
  name: data.name,
498
498
  callback_url: data.callbackUrl
499
- })
499
+ }, data.locale && { locale: data.locale }))
500
500
  });
501
501
  }
502
502
  /**
@@ -515,11 +515,11 @@ var AuthGateClient = class {
515
515
  Authorization: `Bearer ${this.config.apiKey}`,
516
516
  "Content-Type": "application/json"
517
517
  },
518
- body: JSON.stringify({
518
+ body: JSON.stringify(__spreadValues({
519
519
  email: data.email,
520
520
  password: data.password,
521
521
  callback_url: data.callbackUrl
522
- })
522
+ }, data.locale && { locale: data.locale }))
523
523
  });
524
524
  }
525
525
  /**
@@ -535,10 +535,10 @@ var AuthGateClient = class {
535
535
  Authorization: `Bearer ${this.config.apiKey}`,
536
536
  "Content-Type": "application/json"
537
537
  },
538
- body: JSON.stringify({
538
+ body: JSON.stringify(__spreadValues({
539
539
  email: data.email,
540
540
  callback_url: data.callbackUrl
541
- })
541
+ }, data.locale && { locale: data.locale }))
542
542
  });
543
543
  }
544
544
  /**
@@ -556,10 +556,10 @@ var AuthGateClient = class {
556
556
  Authorization: `Bearer ${this.config.apiKey}`,
557
557
  "Content-Type": "application/json"
558
558
  },
559
- body: JSON.stringify({
559
+ body: JSON.stringify(__spreadValues({
560
560
  token: data.token,
561
561
  password: data.password
562
- })
562
+ }, data.locale && { locale: data.locale }))
563
563
  }
564
564
  );
565
565
  }
@@ -579,10 +579,10 @@ var AuthGateClient = class {
579
579
  Authorization: `Bearer ${this.config.apiKey}`,
580
580
  "Content-Type": "application/json"
581
581
  },
582
- body: JSON.stringify({
582
+ body: JSON.stringify(__spreadValues({
583
583
  email: data.email,
584
584
  callback_url: data.callbackUrl
585
- })
585
+ }, data.locale && { locale: data.locale }))
586
586
  });
587
587
  }
588
588
  // ---------------------------------------------------------------------------
@@ -601,10 +601,10 @@ var AuthGateClient = class {
601
601
  Authorization: `Bearer ${this.config.apiKey}`,
602
602
  "Content-Type": "application/json"
603
603
  },
604
- body: JSON.stringify({
604
+ body: JSON.stringify(__spreadValues({
605
605
  email: data.email,
606
606
  code: data.code
607
- })
607
+ }, data.locale && { locale: data.locale }))
608
608
  });
609
609
  }
610
610
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@auth-gate/core",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
+ "description": "Core client library for AuthGate — the OAuth proxy that handles provider configuration, token exchange, and user normalization so you don't have to.",
4
5
  "type": "module",
5
6
  "exports": {
6
7
  ".": {