@auth-gate/core 0.9.3 → 0.11.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 +14 -3
- package/dist/index.cjs +71 -81
- package/dist/index.d.cts +80 -19
- package/dist/index.d.ts +80 -19
- package/dist/index.mjs +71 -81
- package/icon.png +0 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="icon.png" alt="AuthGate" width="120" height="120" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# @auth-gate/core
|
|
2
6
|
|
|
3
|
-
Core client library for [AuthGate](https://authgate.dev) — the OAuth proxy that handles provider configuration, token exchange, and user normalization so you don't have to.
|
|
7
|
+
Core client library for [AuthGate](https://www.authgate.dev) — the OAuth proxy that handles provider configuration, token exchange, and user normalization so you don't have to.
|
|
4
8
|
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
@@ -15,7 +19,7 @@ import { createAuthGateClient } from "@auth-gate/core";
|
|
|
15
19
|
|
|
16
20
|
const client = createAuthGateClient({
|
|
17
21
|
apiKey: process.env.AUTHGATE_API_KEY!,
|
|
18
|
-
baseUrl: "https://authgate.dev", // or your self-hosted instance
|
|
22
|
+
baseUrl: "https://www.authgate.dev", // or your self-hosted instance
|
|
19
23
|
});
|
|
20
24
|
```
|
|
21
25
|
|
|
@@ -202,7 +206,14 @@ For framework-specific integrations with built-in route handlers, session helper
|
|
|
202
206
|
|
|
203
207
|
- **Next.js** — [`@auth-gate/nextjs`](https://www.npmjs.com/package/@auth-gate/nextjs)
|
|
204
208
|
- **React + Hono** — [`@auth-gate/react`](https://www.npmjs.com/package/@auth-gate/react)
|
|
205
|
-
- **
|
|
209
|
+
- **React Native / Expo** — [`@auth-gate/react-native`](https://www.npmjs.com/package/@auth-gate/react-native)
|
|
210
|
+
- **Flutter** — [`auth_gate_flutter`](https://pub.dev/packages/auth_gate_flutter)
|
|
211
|
+
|
|
212
|
+
## Add-on Packages
|
|
213
|
+
|
|
214
|
+
- **RBAC as Code** — [`@auth-gate/rbac`](https://www.npmjs.com/package/@auth-gate/rbac) — define roles and permissions in TypeScript
|
|
215
|
+
- **Billing as Code** — [`@auth-gate/billing`](https://www.npmjs.com/package/@auth-gate/billing) — define plans and prices in TypeScript
|
|
216
|
+
- **Testing** — [`@auth-gate/testing`](https://www.npmjs.com/package/@auth-gate/testing) — E2E helpers (Playwright/Cypress), billing test harness, RBAC test utilities
|
|
206
217
|
|
|
207
218
|
## License
|
|
208
219
|
|
package/dist/index.cjs
CHANGED
|
@@ -328,14 +328,14 @@ var AuthGateClient = class {
|
|
|
328
328
|
}
|
|
329
329
|
if (!config.baseUrl || typeof config.baseUrl !== "string" || config.baseUrl.trim() === "") {
|
|
330
330
|
throw new ConfigurationError(
|
|
331
|
-
'[AuthGate] Missing or empty `baseUrl`. Set this to your AuthGate service URL (e.g. "https://authgate.dev").'
|
|
331
|
+
'[AuthGate] Missing or empty `baseUrl`. Set this to your AuthGate service URL (e.g. "https://www.authgate.dev").'
|
|
332
332
|
);
|
|
333
333
|
}
|
|
334
334
|
try {
|
|
335
335
|
new URL(config.baseUrl);
|
|
336
336
|
} catch (e) {
|
|
337
337
|
throw new ConfigurationError(
|
|
338
|
-
`[AuthGate] Invalid \`baseUrl\`: "${config.baseUrl}". Must be a valid URL (e.g. "https://authgate.dev").`
|
|
338
|
+
`[AuthGate] Invalid \`baseUrl\`: "${config.baseUrl}". Must be a valid URL (e.g. "https://www.authgate.dev").`
|
|
339
339
|
);
|
|
340
340
|
}
|
|
341
341
|
if (config.callbackPath !== void 0 && !config.callbackPath.startsWith("/")) {
|
|
@@ -494,21 +494,26 @@ var AuthGateClient = class {
|
|
|
494
494
|
if (!SUPPORTED_PROVIDERS.includes(provider)) {
|
|
495
495
|
throw new AuthGateError(`Unsupported provider: ${provider}`);
|
|
496
496
|
}
|
|
497
|
-
const response = await fetch(
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
497
|
+
const response = await fetch(
|
|
498
|
+
`${this.config.baseUrl}/api/proxy/${provider}`,
|
|
499
|
+
{
|
|
500
|
+
method: "POST",
|
|
501
|
+
headers: {
|
|
502
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
503
|
+
"Content-Type": "application/json"
|
|
504
|
+
},
|
|
505
|
+
body: JSON.stringify({
|
|
506
|
+
callback_url: callbackUrl,
|
|
507
|
+
state: options == null ? void 0 : options.state,
|
|
508
|
+
link_to: options == null ? void 0 : options.linkTo
|
|
509
|
+
})
|
|
510
|
+
}
|
|
511
|
+
);
|
|
509
512
|
if (!response.ok) {
|
|
510
513
|
const error = await response.json().catch(() => ({}));
|
|
511
|
-
throw new AuthGateError(
|
|
514
|
+
throw new AuthGateError(
|
|
515
|
+
error.error || `OAuth initiation failed: ${response.status}`
|
|
516
|
+
);
|
|
512
517
|
}
|
|
513
518
|
const data = await response.json();
|
|
514
519
|
return data.redirect_url;
|
|
@@ -611,20 +616,17 @@ var AuthGateClient = class {
|
|
|
611
616
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
612
617
|
*/
|
|
613
618
|
async magicLinkSend(data) {
|
|
614
|
-
return fetch(
|
|
615
|
-
|
|
616
|
-
{
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
})
|
|
626
|
-
}
|
|
627
|
-
);
|
|
619
|
+
return fetch(`${this.config.baseUrl}/api/proxy/email/magic-link/send`, {
|
|
620
|
+
method: "POST",
|
|
621
|
+
headers: {
|
|
622
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
623
|
+
"Content-Type": "application/json"
|
|
624
|
+
},
|
|
625
|
+
body: JSON.stringify({
|
|
626
|
+
email: data.email,
|
|
627
|
+
callback_url: data.callbackUrl
|
|
628
|
+
})
|
|
629
|
+
});
|
|
628
630
|
}
|
|
629
631
|
// ---------------------------------------------------------------------------
|
|
630
632
|
// Email verification
|
|
@@ -868,17 +870,14 @@ var AuthGateClient = class {
|
|
|
868
870
|
* @returns The raw `Response` with an array of backup codes.
|
|
869
871
|
*/
|
|
870
872
|
async mfaBackupCodesGenerate(token) {
|
|
871
|
-
return fetch(
|
|
872
|
-
|
|
873
|
-
{
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
body: "{}"
|
|
880
|
-
}
|
|
881
|
-
);
|
|
873
|
+
return fetch(`${this.config.baseUrl}/api/proxy/mfa/backup-codes/generate`, {
|
|
874
|
+
method: "POST",
|
|
875
|
+
headers: {
|
|
876
|
+
Authorization: `Bearer ${token}`,
|
|
877
|
+
"Content-Type": "application/json"
|
|
878
|
+
},
|
|
879
|
+
body: "{}"
|
|
880
|
+
});
|
|
882
881
|
}
|
|
883
882
|
/**
|
|
884
883
|
* Get the current MFA enrollment status for the authenticated user.
|
|
@@ -967,23 +966,20 @@ var AuthGateClient = class {
|
|
|
967
966
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
968
967
|
*/
|
|
969
968
|
async updateOrg(orgIdOrSlug, data) {
|
|
970
|
-
return fetch(
|
|
971
|
-
|
|
972
|
-
{
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
})
|
|
985
|
-
}
|
|
986
|
-
);
|
|
969
|
+
return fetch(`${this.config.baseUrl}/api/proxy/orgs/${orgIdOrSlug}`, {
|
|
970
|
+
method: "PATCH",
|
|
971
|
+
headers: {
|
|
972
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
973
|
+
"Content-Type": "application/json"
|
|
974
|
+
},
|
|
975
|
+
body: JSON.stringify({
|
|
976
|
+
name: data.name,
|
|
977
|
+
slug: data.slug,
|
|
978
|
+
image_url: data.imageUrl,
|
|
979
|
+
max_members: data.maxMembers,
|
|
980
|
+
metadata: data.metadata
|
|
981
|
+
})
|
|
982
|
+
});
|
|
987
983
|
}
|
|
988
984
|
/**
|
|
989
985
|
* Delete an organization.
|
|
@@ -1122,19 +1118,16 @@ var AuthGateClient = class {
|
|
|
1122
1118
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
1123
1119
|
*/
|
|
1124
1120
|
async acceptOrgInvitation(data) {
|
|
1125
|
-
return fetch(
|
|
1126
|
-
|
|
1127
|
-
{
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
})
|
|
1136
|
-
}
|
|
1137
|
-
);
|
|
1121
|
+
return fetch(`${this.config.baseUrl}/api/proxy/orgs/invitations/accept`, {
|
|
1122
|
+
method: "POST",
|
|
1123
|
+
headers: {
|
|
1124
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
1125
|
+
"Content-Type": "application/json"
|
|
1126
|
+
},
|
|
1127
|
+
body: JSON.stringify({
|
|
1128
|
+
token: data.token
|
|
1129
|
+
})
|
|
1130
|
+
});
|
|
1138
1131
|
}
|
|
1139
1132
|
/**
|
|
1140
1133
|
* Leave an organization as the current user.
|
|
@@ -1143,17 +1136,14 @@ var AuthGateClient = class {
|
|
|
1143
1136
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
1144
1137
|
*/
|
|
1145
1138
|
async leaveOrg(orgIdOrSlug) {
|
|
1146
|
-
return fetch(
|
|
1147
|
-
|
|
1148
|
-
{
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
body: "{}"
|
|
1155
|
-
}
|
|
1156
|
-
);
|
|
1139
|
+
return fetch(`${this.config.baseUrl}/api/proxy/orgs/${orgIdOrSlug}/leave`, {
|
|
1140
|
+
method: "POST",
|
|
1141
|
+
headers: {
|
|
1142
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
1143
|
+
"Content-Type": "application/json"
|
|
1144
|
+
},
|
|
1145
|
+
body: "{}"
|
|
1146
|
+
});
|
|
1157
1147
|
}
|
|
1158
1148
|
// ---------------------------------------------------------------------------
|
|
1159
1149
|
// Cookie config accessors
|
package/dist/index.d.cts
CHANGED
|
@@ -47,14 +47,14 @@ interface TokenVerifyResult {
|
|
|
47
47
|
*
|
|
48
48
|
* const client = createAuthGateClient({
|
|
49
49
|
* apiKey: process.env.AUTHGATE_API_KEY!,
|
|
50
|
-
* baseUrl: "https://authgate.dev",
|
|
50
|
+
* baseUrl: "https://www.authgate.dev",
|
|
51
51
|
* });
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
interface AuthGateConfig {
|
|
55
55
|
/** Server-side API key for your AuthGate project. Found in the dashboard under API Key. */
|
|
56
56
|
apiKey: string;
|
|
57
|
-
/** Base URL of the AuthGate service (e.g. `"https://authgate.dev"`). */
|
|
57
|
+
/** Base URL of the AuthGate service (e.g. `"https://www.authgate.dev"`). */
|
|
58
58
|
baseUrl: string;
|
|
59
59
|
/**
|
|
60
60
|
* Name of the session cookie.
|
|
@@ -169,7 +169,7 @@ interface BackupCodesResponse {
|
|
|
169
169
|
* ```ts
|
|
170
170
|
* const client = new AuthGateClient({
|
|
171
171
|
* apiKey: process.env.AUTHGATE_API_KEY!,
|
|
172
|
-
* baseUrl: "https://authgate.dev",
|
|
172
|
+
* baseUrl: "https://www.authgate.dev",
|
|
173
173
|
* });
|
|
174
174
|
* ```
|
|
175
175
|
*/
|
|
@@ -690,6 +690,10 @@ declare class ConfigurationError extends AuthGateError {
|
|
|
690
690
|
|
|
691
691
|
/**
|
|
692
692
|
* Connection details for the AuthGate API.
|
|
693
|
+
*
|
|
694
|
+
* Both fields are optional at the type level because they can be provided
|
|
695
|
+
* via environment variables (`AUTHGATE_URL`, `AUTHGATE_API_KEY`). The CLI
|
|
696
|
+
* auto-loads `.env` and `.env.local` before importing the config file.
|
|
693
697
|
*/
|
|
694
698
|
type AuthGateConnection = {
|
|
695
699
|
baseUrl?: string;
|
|
@@ -697,13 +701,57 @@ type AuthGateConnection = {
|
|
|
697
701
|
};
|
|
698
702
|
/**
|
|
699
703
|
* Project-level config shape for `authgate.config.ts`.
|
|
700
|
-
*
|
|
704
|
+
*
|
|
705
|
+
* Used by both the `@auth-gate/rbac` and `@auth-gate/billing` CLIs to
|
|
706
|
+
* connect to the AuthGate API when syncing roles, permissions, plans, and
|
|
707
|
+
* features. The config file is auto-discovered in the project root.
|
|
701
708
|
*
|
|
702
709
|
* The CLI auto-loads `.env` and `.env.local` before importing this file,
|
|
703
|
-
* so you can reference `process.env`
|
|
710
|
+
* so you can reference `process.env` directly.
|
|
711
|
+
*/
|
|
712
|
+
interface AuthGateProjectConfig {
|
|
713
|
+
/**
|
|
714
|
+
* Connection details for the AuthGate API.
|
|
715
|
+
*
|
|
716
|
+
* If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
|
|
717
|
+
* environment variables.
|
|
718
|
+
*/
|
|
719
|
+
connection?: AuthGateConnection;
|
|
720
|
+
/**
|
|
721
|
+
* Path to the RBAC config file (`authgate.rbac.ts`).
|
|
722
|
+
*
|
|
723
|
+
* Overrides auto-discovery. Useful in monorepos where the RBAC config
|
|
724
|
+
* lives in a different directory than the project root.
|
|
725
|
+
*
|
|
726
|
+
* @example `"./packages/api/authgate.rbac.ts"`
|
|
727
|
+
*/
|
|
728
|
+
rbacConfig?: string;
|
|
729
|
+
/**
|
|
730
|
+
* Path to the Billing config file (`authgate.billing.ts`).
|
|
731
|
+
*
|
|
732
|
+
* Overrides auto-discovery. Useful in monorepos where the billing config
|
|
733
|
+
* lives in a different directory than the project root.
|
|
734
|
+
*
|
|
735
|
+
* @example `"./packages/api/authgate.billing.ts"`
|
|
736
|
+
*/
|
|
737
|
+
billingConfig?: string;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Define your project-level AuthGate configuration.
|
|
704
741
|
*
|
|
705
|
-
*
|
|
742
|
+
* Create an `authgate.config.ts` file in your project root and export
|
|
743
|
+
* the result of this function as the default export. This gives you
|
|
744
|
+
* type safety and IDE autocomplete for the config.
|
|
745
|
+
*
|
|
746
|
+
* The CLI auto-loads `.env` and `.env.local` before importing the
|
|
747
|
+
* config, so `process.env` values are available.
|
|
748
|
+
*
|
|
749
|
+
* @param config - The project configuration object.
|
|
750
|
+
* @returns The same config object (identity function for type inference).
|
|
751
|
+
*
|
|
752
|
+
* @example Minimal setup (env vars provide connection details)
|
|
706
753
|
* ```ts
|
|
754
|
+
* // authgate.config.ts
|
|
707
755
|
* import { defineConfig } from "@auth-gate/core";
|
|
708
756
|
*
|
|
709
757
|
* export default defineConfig({
|
|
@@ -713,20 +761,33 @@ type AuthGateConnection = {
|
|
|
713
761
|
* },
|
|
714
762
|
* });
|
|
715
763
|
* ```
|
|
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
764
|
*
|
|
728
|
-
*
|
|
729
|
-
*
|
|
765
|
+
* @example Monorepo with custom config paths
|
|
766
|
+
* ```ts
|
|
767
|
+
* // authgate.config.ts
|
|
768
|
+
* import { defineConfig } from "@auth-gate/core";
|
|
769
|
+
*
|
|
770
|
+
* export default defineConfig({
|
|
771
|
+
* connection: {
|
|
772
|
+
* baseUrl: process.env.AUTHGATE_URL,
|
|
773
|
+
* apiKey: process.env.AUTHGATE_API_KEY,
|
|
774
|
+
* },
|
|
775
|
+
* rbacConfig: "./packages/api/authgate.rbac.ts",
|
|
776
|
+
* billingConfig: "./packages/api/authgate.billing.ts",
|
|
777
|
+
* });
|
|
778
|
+
* ```
|
|
779
|
+
*
|
|
780
|
+
* @example Then sync with the CLI
|
|
781
|
+
* ```sh
|
|
782
|
+
* # Scaffold the config file
|
|
783
|
+
* npx @auth-gate/rbac init --config
|
|
784
|
+
*
|
|
785
|
+
* # Sync RBAC roles & permissions
|
|
786
|
+
* npx @auth-gate/rbac sync --apply
|
|
787
|
+
*
|
|
788
|
+
* # Sync billing plans & features
|
|
789
|
+
* npx @auth-gate/billing sync --apply
|
|
790
|
+
* ```
|
|
730
791
|
*/
|
|
731
792
|
declare function defineConfig(config: AuthGateProjectConfig): AuthGateProjectConfig;
|
|
732
793
|
|
package/dist/index.d.ts
CHANGED
|
@@ -47,14 +47,14 @@ interface TokenVerifyResult {
|
|
|
47
47
|
*
|
|
48
48
|
* const client = createAuthGateClient({
|
|
49
49
|
* apiKey: process.env.AUTHGATE_API_KEY!,
|
|
50
|
-
* baseUrl: "https://authgate.dev",
|
|
50
|
+
* baseUrl: "https://www.authgate.dev",
|
|
51
51
|
* });
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
interface AuthGateConfig {
|
|
55
55
|
/** Server-side API key for your AuthGate project. Found in the dashboard under API Key. */
|
|
56
56
|
apiKey: string;
|
|
57
|
-
/** Base URL of the AuthGate service (e.g. `"https://authgate.dev"`). */
|
|
57
|
+
/** Base URL of the AuthGate service (e.g. `"https://www.authgate.dev"`). */
|
|
58
58
|
baseUrl: string;
|
|
59
59
|
/**
|
|
60
60
|
* Name of the session cookie.
|
|
@@ -169,7 +169,7 @@ interface BackupCodesResponse {
|
|
|
169
169
|
* ```ts
|
|
170
170
|
* const client = new AuthGateClient({
|
|
171
171
|
* apiKey: process.env.AUTHGATE_API_KEY!,
|
|
172
|
-
* baseUrl: "https://authgate.dev",
|
|
172
|
+
* baseUrl: "https://www.authgate.dev",
|
|
173
173
|
* });
|
|
174
174
|
* ```
|
|
175
175
|
*/
|
|
@@ -690,6 +690,10 @@ declare class ConfigurationError extends AuthGateError {
|
|
|
690
690
|
|
|
691
691
|
/**
|
|
692
692
|
* Connection details for the AuthGate API.
|
|
693
|
+
*
|
|
694
|
+
* Both fields are optional at the type level because they can be provided
|
|
695
|
+
* via environment variables (`AUTHGATE_URL`, `AUTHGATE_API_KEY`). The CLI
|
|
696
|
+
* auto-loads `.env` and `.env.local` before importing the config file.
|
|
693
697
|
*/
|
|
694
698
|
type AuthGateConnection = {
|
|
695
699
|
baseUrl?: string;
|
|
@@ -697,13 +701,57 @@ type AuthGateConnection = {
|
|
|
697
701
|
};
|
|
698
702
|
/**
|
|
699
703
|
* Project-level config shape for `authgate.config.ts`.
|
|
700
|
-
*
|
|
704
|
+
*
|
|
705
|
+
* Used by both the `@auth-gate/rbac` and `@auth-gate/billing` CLIs to
|
|
706
|
+
* connect to the AuthGate API when syncing roles, permissions, plans, and
|
|
707
|
+
* features. The config file is auto-discovered in the project root.
|
|
701
708
|
*
|
|
702
709
|
* The CLI auto-loads `.env` and `.env.local` before importing this file,
|
|
703
|
-
* so you can reference `process.env`
|
|
710
|
+
* so you can reference `process.env` directly.
|
|
711
|
+
*/
|
|
712
|
+
interface AuthGateProjectConfig {
|
|
713
|
+
/**
|
|
714
|
+
* Connection details for the AuthGate API.
|
|
715
|
+
*
|
|
716
|
+
* If omitted, the CLI falls back to `AUTHGATE_URL` and `AUTHGATE_API_KEY`
|
|
717
|
+
* environment variables.
|
|
718
|
+
*/
|
|
719
|
+
connection?: AuthGateConnection;
|
|
720
|
+
/**
|
|
721
|
+
* Path to the RBAC config file (`authgate.rbac.ts`).
|
|
722
|
+
*
|
|
723
|
+
* Overrides auto-discovery. Useful in monorepos where the RBAC config
|
|
724
|
+
* lives in a different directory than the project root.
|
|
725
|
+
*
|
|
726
|
+
* @example `"./packages/api/authgate.rbac.ts"`
|
|
727
|
+
*/
|
|
728
|
+
rbacConfig?: string;
|
|
729
|
+
/**
|
|
730
|
+
* Path to the Billing config file (`authgate.billing.ts`).
|
|
731
|
+
*
|
|
732
|
+
* Overrides auto-discovery. Useful in monorepos where the billing config
|
|
733
|
+
* lives in a different directory than the project root.
|
|
734
|
+
*
|
|
735
|
+
* @example `"./packages/api/authgate.billing.ts"`
|
|
736
|
+
*/
|
|
737
|
+
billingConfig?: string;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Define your project-level AuthGate configuration.
|
|
704
741
|
*
|
|
705
|
-
*
|
|
742
|
+
* Create an `authgate.config.ts` file in your project root and export
|
|
743
|
+
* the result of this function as the default export. This gives you
|
|
744
|
+
* type safety and IDE autocomplete for the config.
|
|
745
|
+
*
|
|
746
|
+
* The CLI auto-loads `.env` and `.env.local` before importing the
|
|
747
|
+
* config, so `process.env` values are available.
|
|
748
|
+
*
|
|
749
|
+
* @param config - The project configuration object.
|
|
750
|
+
* @returns The same config object (identity function for type inference).
|
|
751
|
+
*
|
|
752
|
+
* @example Minimal setup (env vars provide connection details)
|
|
706
753
|
* ```ts
|
|
754
|
+
* // authgate.config.ts
|
|
707
755
|
* import { defineConfig } from "@auth-gate/core";
|
|
708
756
|
*
|
|
709
757
|
* export default defineConfig({
|
|
@@ -713,20 +761,33 @@ type AuthGateConnection = {
|
|
|
713
761
|
* },
|
|
714
762
|
* });
|
|
715
763
|
* ```
|
|
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
764
|
*
|
|
728
|
-
*
|
|
729
|
-
*
|
|
765
|
+
* @example Monorepo with custom config paths
|
|
766
|
+
* ```ts
|
|
767
|
+
* // authgate.config.ts
|
|
768
|
+
* import { defineConfig } from "@auth-gate/core";
|
|
769
|
+
*
|
|
770
|
+
* export default defineConfig({
|
|
771
|
+
* connection: {
|
|
772
|
+
* baseUrl: process.env.AUTHGATE_URL,
|
|
773
|
+
* apiKey: process.env.AUTHGATE_API_KEY,
|
|
774
|
+
* },
|
|
775
|
+
* rbacConfig: "./packages/api/authgate.rbac.ts",
|
|
776
|
+
* billingConfig: "./packages/api/authgate.billing.ts",
|
|
777
|
+
* });
|
|
778
|
+
* ```
|
|
779
|
+
*
|
|
780
|
+
* @example Then sync with the CLI
|
|
781
|
+
* ```sh
|
|
782
|
+
* # Scaffold the config file
|
|
783
|
+
* npx @auth-gate/rbac init --config
|
|
784
|
+
*
|
|
785
|
+
* # Sync RBAC roles & permissions
|
|
786
|
+
* npx @auth-gate/rbac sync --apply
|
|
787
|
+
*
|
|
788
|
+
* # Sync billing plans & features
|
|
789
|
+
* npx @auth-gate/billing sync --apply
|
|
790
|
+
* ```
|
|
730
791
|
*/
|
|
731
792
|
declare function defineConfig(config: AuthGateProjectConfig): AuthGateProjectConfig;
|
|
732
793
|
|
package/dist/index.mjs
CHANGED
|
@@ -285,14 +285,14 @@ var AuthGateClient = class {
|
|
|
285
285
|
}
|
|
286
286
|
if (!config.baseUrl || typeof config.baseUrl !== "string" || config.baseUrl.trim() === "") {
|
|
287
287
|
throw new ConfigurationError(
|
|
288
|
-
'[AuthGate] Missing or empty `baseUrl`. Set this to your AuthGate service URL (e.g. "https://authgate.dev").'
|
|
288
|
+
'[AuthGate] Missing or empty `baseUrl`. Set this to your AuthGate service URL (e.g. "https://www.authgate.dev").'
|
|
289
289
|
);
|
|
290
290
|
}
|
|
291
291
|
try {
|
|
292
292
|
new URL(config.baseUrl);
|
|
293
293
|
} catch (e) {
|
|
294
294
|
throw new ConfigurationError(
|
|
295
|
-
`[AuthGate] Invalid \`baseUrl\`: "${config.baseUrl}". Must be a valid URL (e.g. "https://authgate.dev").`
|
|
295
|
+
`[AuthGate] Invalid \`baseUrl\`: "${config.baseUrl}". Must be a valid URL (e.g. "https://www.authgate.dev").`
|
|
296
296
|
);
|
|
297
297
|
}
|
|
298
298
|
if (config.callbackPath !== void 0 && !config.callbackPath.startsWith("/")) {
|
|
@@ -451,21 +451,26 @@ var AuthGateClient = class {
|
|
|
451
451
|
if (!SUPPORTED_PROVIDERS.includes(provider)) {
|
|
452
452
|
throw new AuthGateError(`Unsupported provider: ${provider}`);
|
|
453
453
|
}
|
|
454
|
-
const response = await fetch(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
454
|
+
const response = await fetch(
|
|
455
|
+
`${this.config.baseUrl}/api/proxy/${provider}`,
|
|
456
|
+
{
|
|
457
|
+
method: "POST",
|
|
458
|
+
headers: {
|
|
459
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
460
|
+
"Content-Type": "application/json"
|
|
461
|
+
},
|
|
462
|
+
body: JSON.stringify({
|
|
463
|
+
callback_url: callbackUrl,
|
|
464
|
+
state: options == null ? void 0 : options.state,
|
|
465
|
+
link_to: options == null ? void 0 : options.linkTo
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
);
|
|
466
469
|
if (!response.ok) {
|
|
467
470
|
const error = await response.json().catch(() => ({}));
|
|
468
|
-
throw new AuthGateError(
|
|
471
|
+
throw new AuthGateError(
|
|
472
|
+
error.error || `OAuth initiation failed: ${response.status}`
|
|
473
|
+
);
|
|
469
474
|
}
|
|
470
475
|
const data = await response.json();
|
|
471
476
|
return data.redirect_url;
|
|
@@ -568,20 +573,17 @@ var AuthGateClient = class {
|
|
|
568
573
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
569
574
|
*/
|
|
570
575
|
async magicLinkSend(data) {
|
|
571
|
-
return fetch(
|
|
572
|
-
|
|
573
|
-
{
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
})
|
|
583
|
-
}
|
|
584
|
-
);
|
|
576
|
+
return fetch(`${this.config.baseUrl}/api/proxy/email/magic-link/send`, {
|
|
577
|
+
method: "POST",
|
|
578
|
+
headers: {
|
|
579
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
580
|
+
"Content-Type": "application/json"
|
|
581
|
+
},
|
|
582
|
+
body: JSON.stringify({
|
|
583
|
+
email: data.email,
|
|
584
|
+
callback_url: data.callbackUrl
|
|
585
|
+
})
|
|
586
|
+
});
|
|
585
587
|
}
|
|
586
588
|
// ---------------------------------------------------------------------------
|
|
587
589
|
// Email verification
|
|
@@ -825,17 +827,14 @@ var AuthGateClient = class {
|
|
|
825
827
|
* @returns The raw `Response` with an array of backup codes.
|
|
826
828
|
*/
|
|
827
829
|
async mfaBackupCodesGenerate(token) {
|
|
828
|
-
return fetch(
|
|
829
|
-
|
|
830
|
-
{
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
body: "{}"
|
|
837
|
-
}
|
|
838
|
-
);
|
|
830
|
+
return fetch(`${this.config.baseUrl}/api/proxy/mfa/backup-codes/generate`, {
|
|
831
|
+
method: "POST",
|
|
832
|
+
headers: {
|
|
833
|
+
Authorization: `Bearer ${token}`,
|
|
834
|
+
"Content-Type": "application/json"
|
|
835
|
+
},
|
|
836
|
+
body: "{}"
|
|
837
|
+
});
|
|
839
838
|
}
|
|
840
839
|
/**
|
|
841
840
|
* Get the current MFA enrollment status for the authenticated user.
|
|
@@ -924,23 +923,20 @@ var AuthGateClient = class {
|
|
|
924
923
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
925
924
|
*/
|
|
926
925
|
async updateOrg(orgIdOrSlug, data) {
|
|
927
|
-
return fetch(
|
|
928
|
-
|
|
929
|
-
{
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
})
|
|
942
|
-
}
|
|
943
|
-
);
|
|
926
|
+
return fetch(`${this.config.baseUrl}/api/proxy/orgs/${orgIdOrSlug}`, {
|
|
927
|
+
method: "PATCH",
|
|
928
|
+
headers: {
|
|
929
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
930
|
+
"Content-Type": "application/json"
|
|
931
|
+
},
|
|
932
|
+
body: JSON.stringify({
|
|
933
|
+
name: data.name,
|
|
934
|
+
slug: data.slug,
|
|
935
|
+
image_url: data.imageUrl,
|
|
936
|
+
max_members: data.maxMembers,
|
|
937
|
+
metadata: data.metadata
|
|
938
|
+
})
|
|
939
|
+
});
|
|
944
940
|
}
|
|
945
941
|
/**
|
|
946
942
|
* Delete an organization.
|
|
@@ -1079,19 +1075,16 @@ var AuthGateClient = class {
|
|
|
1079
1075
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
1080
1076
|
*/
|
|
1081
1077
|
async acceptOrgInvitation(data) {
|
|
1082
|
-
return fetch(
|
|
1083
|
-
|
|
1084
|
-
{
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
})
|
|
1093
|
-
}
|
|
1094
|
-
);
|
|
1078
|
+
return fetch(`${this.config.baseUrl}/api/proxy/orgs/invitations/accept`, {
|
|
1079
|
+
method: "POST",
|
|
1080
|
+
headers: {
|
|
1081
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
1082
|
+
"Content-Type": "application/json"
|
|
1083
|
+
},
|
|
1084
|
+
body: JSON.stringify({
|
|
1085
|
+
token: data.token
|
|
1086
|
+
})
|
|
1087
|
+
});
|
|
1095
1088
|
}
|
|
1096
1089
|
/**
|
|
1097
1090
|
* Leave an organization as the current user.
|
|
@@ -1100,17 +1093,14 @@ var AuthGateClient = class {
|
|
|
1100
1093
|
* @returns The raw `Response` from the AuthGate proxy.
|
|
1101
1094
|
*/
|
|
1102
1095
|
async leaveOrg(orgIdOrSlug) {
|
|
1103
|
-
return fetch(
|
|
1104
|
-
|
|
1105
|
-
{
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
body: "{}"
|
|
1112
|
-
}
|
|
1113
|
-
);
|
|
1096
|
+
return fetch(`${this.config.baseUrl}/api/proxy/orgs/${orgIdOrSlug}/leave`, {
|
|
1097
|
+
method: "POST",
|
|
1098
|
+
headers: {
|
|
1099
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
1100
|
+
"Content-Type": "application/json"
|
|
1101
|
+
},
|
|
1102
|
+
body: "{}"
|
|
1103
|
+
});
|
|
1114
1104
|
}
|
|
1115
1105
|
// ---------------------------------------------------------------------------
|
|
1116
1106
|
// Cookie config accessors
|
package/icon.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth-gate/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"module": "./dist/index.mjs",
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"icon.png"
|
|
17
18
|
],
|
|
18
19
|
"engines": {
|
|
19
20
|
"node": ">=18"
|