@banata-auth/convex 0.1.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/LICENSE +21 -0
- package/README.md +104 -0
- package/dist/auth-config.d.ts +22 -0
- package/dist/auth-config.d.ts.map +1 -0
- package/dist/auth-config.js +3 -0
- package/dist/auth-config.js.map +1 -0
- package/dist/auth.d.ts +462 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/component/adapter.d.ts +21 -0
- package/dist/component/adapter.d.ts.map +1 -0
- package/dist/component/adapter.js +3 -0
- package/dist/component/adapter.js.map +1 -0
- package/dist/component/schema.d.ts +1026 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/hooks.d.ts +25 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/http.d.ts +41 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +62 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9516 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +389 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +9559 -0
- package/dist/node.js.map +1 -0
- package/dist/plugins/audit.d.ts +106 -0
- package/dist/plugins/audit.d.ts.map +1 -0
- package/dist/plugins/config.d.ts +83 -0
- package/dist/plugins/config.d.ts.map +1 -0
- package/dist/plugins/domains.d.ts +3 -0
- package/dist/plugins/domains.d.ts.map +1 -0
- package/dist/plugins/email-sender.d.ts +75 -0
- package/dist/plugins/email-sender.d.ts.map +1 -0
- package/dist/plugins/email-templates.d.ts +108 -0
- package/dist/plugins/email-templates.d.ts.map +1 -0
- package/dist/plugins/email.d.ts +82 -0
- package/dist/plugins/email.d.ts.map +1 -0
- package/dist/plugins/enterprise.d.ts +3 -0
- package/dist/plugins/enterprise.d.ts.map +1 -0
- package/dist/plugins/events.d.ts +40 -0
- package/dist/plugins/events.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +18 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +9192 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/organization-rbac.d.ts +3 -0
- package/dist/plugins/organization-rbac.d.ts.map +1 -0
- package/dist/plugins/portal.d.ts +34 -0
- package/dist/plugins/portal.d.ts.map +1 -0
- package/dist/plugins/projects.d.ts +16 -0
- package/dist/plugins/projects.d.ts.map +1 -0
- package/dist/plugins/protection.d.ts +127 -0
- package/dist/plugins/protection.d.ts.map +1 -0
- package/dist/plugins/types.d.ts +508 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/user-management.d.ts +8 -0
- package/dist/plugins/user-management.d.ts.map +1 -0
- package/dist/plugins/vault.d.ts +68 -0
- package/dist/plugins/vault.d.ts.map +1 -0
- package/dist/plugins/webhook.d.ts +65 -0
- package/dist/plugins/webhook.d.ts.map +1 -0
- package/dist/triggers.d.ts +158 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js +36 -0
- package/dist/triggers.js.map +1 -0
- package/package.json +102 -0
- package/src/component/adapter.ts +21 -0
- package/src/component/convex.config.ts +15 -0
- package/src/component/schema.ts +916 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IACrE,QAAQ,CAAC,EACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,K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AAG,CAAC,MAAM,CAAC,CAAC,CAsDtB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC7C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE;IACP,EAAE,EAAE,eAAe,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,GACC,OAAO,CAAC,IAAI,CAAC,CAqBf;AAID;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;;;;;;EAE7B,CAAC;AAEH;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B;IACF,8DAA8D;IAC9D,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,2DAA2D;IAC3D,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,CAeA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BetterAuthPlugin } from "better-auth";
|
|
2
|
+
type PermissionStatements = Record<string, string[]>;
|
|
3
|
+
type PermissionCheckInput = string | string[] | PermissionStatements;
|
|
4
|
+
export declare function flattenPermissionCheckInput(input: PermissionCheckInput | undefined): string[];
|
|
5
|
+
export declare function hasRequestedPermissions(granted: Set<string>, requested: string[]): boolean;
|
|
6
|
+
export declare function userManagementPlugin(): BetterAuthPlugin;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=user-management.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-management.d.ts","sourceRoot":"","sources":["../../src/plugins/user-management.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA4HpD,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AACrD,KAAK,oBAAoB,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,oBAAoB,CAAC;AA6JrE,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,oBAAoB,GAAG,SAAS,GAAG,MAAM,EAAE,CAoB7F;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAI1F;AA2SD,wBAAgB,oBAAoB,IAAI,gBAAgB,CAmsBvD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault plugin for Banata Auth.
|
|
3
|
+
*
|
|
4
|
+
* Provides envelope encryption for secrets using AES-256-GCM via the
|
|
5
|
+
* Web Crypto API. Secrets are encrypted at rest in the `vaultSecret`
|
|
6
|
+
* table and can only be decrypted by providing the correct context.
|
|
7
|
+
*
|
|
8
|
+
* The data encryption key (DEK) is derived from `BETTER_AUTH_SECRET`
|
|
9
|
+
* using HKDF with a per-version salt, enabling key rotation without
|
|
10
|
+
* re-deploying the application.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link ../../component/schema.ts} for the vaultSecret table definition
|
|
13
|
+
* @see {@link ../../../shared/src/types.ts} for the VaultSecret SDK type
|
|
14
|
+
*/
|
|
15
|
+
import type { BetterAuthPlugin } from "better-auth";
|
|
16
|
+
export interface VaultPluginOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The master secret used to derive encryption keys.
|
|
19
|
+
* Defaults to `BETTER_AUTH_SECRET` from the environment.
|
|
20
|
+
*/
|
|
21
|
+
masterSecret?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Derive an AES-256 key from the master secret using HKDF.
|
|
25
|
+
* The version number is included in the info parameter so that
|
|
26
|
+
* key rotation produces a different DEK for each version.
|
|
27
|
+
*/
|
|
28
|
+
/** @internal Exported for testing. */
|
|
29
|
+
export declare function deriveKey(masterSecret: string, version: number): Promise<import("crypto").webcrypto.CryptoKey>;
|
|
30
|
+
/**
|
|
31
|
+
* Encrypt a plaintext string using AES-256-GCM.
|
|
32
|
+
* Returns the ciphertext and IV as base64-encoded strings.
|
|
33
|
+
*/
|
|
34
|
+
/** @internal Exported for testing. */
|
|
35
|
+
export declare function encryptValue(plaintext: string, masterSecret: string, version: number): Promise<{
|
|
36
|
+
encryptedValue: string;
|
|
37
|
+
iv: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Decrypt a ciphertext string using AES-256-GCM.
|
|
41
|
+
*/
|
|
42
|
+
/** @internal Exported for testing. */
|
|
43
|
+
export declare function decryptValue(encryptedValue: string, iv: string, masterSecret: string, version: number): Promise<string>;
|
|
44
|
+
/** @internal Exported for testing. */
|
|
45
|
+
export declare function uint8ToBase64(bytes: Uint8Array): string;
|
|
46
|
+
/** @internal Exported for testing. */
|
|
47
|
+
export declare function base64ToUint8(base64: string): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* Vault plugin for Banata Auth.
|
|
50
|
+
*
|
|
51
|
+
* Registers API endpoints under `/api/auth/banata/vault/` for
|
|
52
|
+
* encrypting, decrypting, listing, deleting, and rotating vault secrets.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Optional configuration
|
|
55
|
+
* @returns A Better Auth plugin descriptor
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { vaultPlugin } from "./plugins/vault";
|
|
60
|
+
*
|
|
61
|
+
* const plugins = [
|
|
62
|
+
* vaultPlugin(),
|
|
63
|
+
* // ... other plugins
|
|
64
|
+
* ];
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function vaultPlugin(options?: VaultPluginOptions): BetterAuthPlugin;
|
|
68
|
+
//# sourceMappingURL=vault.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../src/plugins/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAapD,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAuBD;;;;GAIG;AACH,sCAAsC;AACtC,wBAAsB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iDAqBpE;AAED;;;GAGG;AACH,sCAAsC;AACtC,wBAAsB,YAAY,CACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAejD;AAED;;GAEG;AACH,sCAAsC;AACtC,wBAAsB,YAAY,CACjC,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAWjB;AAgBD,sCAAsC;AACtC,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMvD;AAED,sCAAsC;AACtC,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAOxD;AA6CD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,gBAAgB,CAmX1E"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Banata Auth Webhook System Plugin.
|
|
3
|
+
*
|
|
4
|
+
* Provides CRUD management of webhook endpoints, HMAC-SHA256 signed payloads,
|
|
5
|
+
* retry with exponential backoff, and delivery tracking via an audit trail.
|
|
6
|
+
*
|
|
7
|
+
* Endpoints are registered under `/api/auth/banata/webhooks/` and exposed to
|
|
8
|
+
* admin consumers for configuring outbound webhook subscriptions.
|
|
9
|
+
*
|
|
10
|
+
* Other plugins (audit, lifecycle triggers) call `dispatchWebhookEvent()` to
|
|
11
|
+
* fire webhooks when auth events occur.
|
|
12
|
+
*/
|
|
13
|
+
import type { BetterAuthPlugin } from "better-auth";
|
|
14
|
+
import { type PluginDBAdapter } from "./types";
|
|
15
|
+
export interface WebhookPluginOptions {
|
|
16
|
+
/** Max retry attempts for failed deliveries. Default: 5 */
|
|
17
|
+
maxRetries?: number;
|
|
18
|
+
/** Retry delays in ms. Default: [0, 5min, 30min, 2hr, 24hr] */
|
|
19
|
+
retryDelays?: number[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Webhook system plugin for Banata Auth.
|
|
23
|
+
*
|
|
24
|
+
* Provides:
|
|
25
|
+
* - CRUD management of webhook endpoints
|
|
26
|
+
* - HMAC-SHA256 signed payloads
|
|
27
|
+
* - Retry with exponential backoff
|
|
28
|
+
* - Delivery tracking and audit trail
|
|
29
|
+
*/
|
|
30
|
+
export declare function webhookSystem(_options?: WebhookPluginOptions): BetterAuthPlugin;
|
|
31
|
+
/**
|
|
32
|
+
* Sign a webhook payload using HMAC-SHA256.
|
|
33
|
+
*
|
|
34
|
+
* @param payload - JSON stringified payload
|
|
35
|
+
* @param secret - The webhook endpoint's signing secret
|
|
36
|
+
* @param timestamp - Unix timestamp in seconds
|
|
37
|
+
* @returns The signature string in the format "v1,<hex>"
|
|
38
|
+
*/
|
|
39
|
+
export declare function signWebhookPayload(payload: string, secret: string, timestamp: number): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Verify a webhook signature.
|
|
42
|
+
*
|
|
43
|
+
* @param payload - Raw request body string
|
|
44
|
+
* @param signature - The Banata-Webhook-Signature header value (format: "t=<ts>,v1=<hex>")
|
|
45
|
+
* @param secret - The webhook endpoint's signing secret
|
|
46
|
+
* @param tolerance - Max age in seconds (default: 300 = 5 minutes)
|
|
47
|
+
* @returns true if valid
|
|
48
|
+
*/
|
|
49
|
+
export declare function verifyWebhookSignature(payload: string, signature: string, secret: string, tolerance?: number): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Dispatch a webhook event to all matching endpoints.
|
|
52
|
+
*
|
|
53
|
+
* This is a helper intended to be called from other plugins (audit, triggers)
|
|
54
|
+
* to fire webhooks when events occur. It is designed to never throw — webhook
|
|
55
|
+
* delivery failures must not break the calling flow.
|
|
56
|
+
*
|
|
57
|
+
* @param adapter - The Better Auth database adapter (subset of methods needed)
|
|
58
|
+
* @param eventType - The event type string (e.g., "user.created", "session.revoked")
|
|
59
|
+
* @param data - The event payload data
|
|
60
|
+
* @param scope - Optional project+environment scope for multi-tenant isolation
|
|
61
|
+
*/
|
|
62
|
+
export declare function dispatchWebhookEvent(adapter: Pick<PluginDBAdapter, "findMany" | "create" | "update">, eventType: string, data: Record<string, unknown>, scope?: {
|
|
63
|
+
projectId?: string;
|
|
64
|
+
}): Promise<void>;
|
|
65
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/plugins/webhook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EACN,KAAK,eAAe,EAMpB,MAAM,SAAS,CAAC;AA2BjB,MAAM,WAAW,oBAAoB;IACpC,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAyDD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,gBAAgB,CAsN/E;AAID;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACvC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,SAAS,SAAM,GACb,OAAO,CAAC,OAAO,CAAC,CA8BlB;AAID;;;;;;;;;;;GAWG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC,EAChE,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAAC,IAAI,CAAC,CA0Gf"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convex trigger system for Banata Auth lifecycle events.
|
|
3
|
+
*
|
|
4
|
+
* Triggers allow consumers to run custom logic when auth-related
|
|
5
|
+
* events occur (user created, user updated, session created, etc.).
|
|
6
|
+
* These are modeled after Convex's trigger pattern.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { defineBanataAuthTriggers } from "@banata-auth/convex/triggers";
|
|
11
|
+
*
|
|
12
|
+
* export const triggers = defineBanataAuthTriggers({
|
|
13
|
+
* onUserCreated: async (ctx, user) => {
|
|
14
|
+
* // Send welcome email, create default org, etc.
|
|
15
|
+
* console.log("New user:", user.email);
|
|
16
|
+
* },
|
|
17
|
+
* onUserUpdated: async (ctx, { oldUser, newUser }) => {
|
|
18
|
+
* // Sync user data to external systems
|
|
19
|
+
* },
|
|
20
|
+
* onSessionCreated: async (ctx, session) => {
|
|
21
|
+
* // Log sign-in event
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import type { GenericCtx } from "@convex-dev/better-auth/utils";
|
|
27
|
+
import type { FunctionReference, GenericDataModel } from "convex/server";
|
|
28
|
+
/** Structured metadata for trigger data. */
|
|
29
|
+
export type TriggerMetadata = Record<string, string | number | boolean | null>;
|
|
30
|
+
export interface TriggerUser {
|
|
31
|
+
_id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
email: string;
|
|
34
|
+
emailVerified: boolean;
|
|
35
|
+
image?: string;
|
|
36
|
+
username?: string;
|
|
37
|
+
role?: string;
|
|
38
|
+
banned?: boolean;
|
|
39
|
+
twoFactorEnabled?: boolean;
|
|
40
|
+
isAnonymous?: boolean;
|
|
41
|
+
metadata?: TriggerMetadata;
|
|
42
|
+
createdAt: number;
|
|
43
|
+
updatedAt: number;
|
|
44
|
+
}
|
|
45
|
+
export interface TriggerSession {
|
|
46
|
+
_id: string;
|
|
47
|
+
userId: string;
|
|
48
|
+
expiresAt: number;
|
|
49
|
+
ipAddress?: string;
|
|
50
|
+
userAgent?: string;
|
|
51
|
+
activeOrganizationId?: string;
|
|
52
|
+
impersonatedBy?: string;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
updatedAt: number;
|
|
55
|
+
}
|
|
56
|
+
export interface TriggerOrganization {
|
|
57
|
+
_id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
slug: string;
|
|
60
|
+
logo?: string;
|
|
61
|
+
metadata?: TriggerMetadata;
|
|
62
|
+
createdAt: number;
|
|
63
|
+
updatedAt: number;
|
|
64
|
+
}
|
|
65
|
+
export interface TriggerMember {
|
|
66
|
+
_id: string;
|
|
67
|
+
organizationId: string;
|
|
68
|
+
userId: string;
|
|
69
|
+
role: string;
|
|
70
|
+
createdAt: number;
|
|
71
|
+
updatedAt: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Context provided to trigger handlers.
|
|
75
|
+
* This is a subset of the Convex mutation context, fully typed.
|
|
76
|
+
*/
|
|
77
|
+
export interface TriggerContext {
|
|
78
|
+
/** Run a Convex query. */
|
|
79
|
+
runQuery: <Args extends Record<string, unknown>, Output>(query: FunctionReference<"query", "public" | "internal", Args, Output>, args: Args) => Promise<Output>;
|
|
80
|
+
/** Run a Convex mutation. */
|
|
81
|
+
runMutation: <Args extends Record<string, unknown>, Output>(mutation: FunctionReference<"mutation", "public" | "internal", Args, Output>, args: Args) => Promise<Output>;
|
|
82
|
+
/** Run a Convex action. */
|
|
83
|
+
runAction: <Args extends Record<string, unknown>, Output>(action: FunctionReference<"action", "public" | "internal", Args, Output>, args: Args) => Promise<Output>;
|
|
84
|
+
/** Schedule a function to run later. */
|
|
85
|
+
scheduler: {
|
|
86
|
+
runAfter: <Args extends Record<string, unknown>>(delayMs: number, fn: FunctionReference<"mutation" | "action", "public" | "internal", Args>, args: Args) => Promise<string>;
|
|
87
|
+
runAt: <Args extends Record<string, unknown>>(timestamp: number, fn: FunctionReference<"mutation" | "action", "public" | "internal", Args>, args: Args) => Promise<string>;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface BanataAuthTriggers {
|
|
91
|
+
/** Fired when a new user is created (sign-up, OAuth first login, SCIM provisioning). */
|
|
92
|
+
onUserCreated?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;
|
|
93
|
+
/** Fired when a user is updated (profile change, role change, ban/unban). */
|
|
94
|
+
onUserUpdated?: (ctx: TriggerContext, data: {
|
|
95
|
+
oldUser: TriggerUser;
|
|
96
|
+
newUser: TriggerUser;
|
|
97
|
+
}) => Promise<void>;
|
|
98
|
+
/** Fired when a user is deleted. */
|
|
99
|
+
onUserDeleted?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;
|
|
100
|
+
/** Fired when a new session is created (sign-in). */
|
|
101
|
+
onSessionCreated?: (ctx: TriggerContext, session: TriggerSession) => Promise<void>;
|
|
102
|
+
/** Fired when a session is revoked (sign-out). */
|
|
103
|
+
onSessionRevoked?: (ctx: TriggerContext, session: TriggerSession) => Promise<void>;
|
|
104
|
+
/** Fired when an organization is created. */
|
|
105
|
+
onOrganizationCreated?: (ctx: TriggerContext, org: TriggerOrganization) => Promise<void>;
|
|
106
|
+
/** Fired when an organization is updated. */
|
|
107
|
+
onOrganizationUpdated?: (ctx: TriggerContext, data: {
|
|
108
|
+
oldOrg: TriggerOrganization;
|
|
109
|
+
newOrg: TriggerOrganization;
|
|
110
|
+
}) => Promise<void>;
|
|
111
|
+
/** Fired when an organization is deleted. */
|
|
112
|
+
onOrganizationDeleted?: (ctx: TriggerContext, org: TriggerOrganization) => Promise<void>;
|
|
113
|
+
/** Fired when a member is added to an organization. */
|
|
114
|
+
onMemberAdded?: (ctx: TriggerContext, member: TriggerMember) => Promise<void>;
|
|
115
|
+
/** Fired when a member is removed from an organization. */
|
|
116
|
+
onMemberRemoved?: (ctx: TriggerContext, member: TriggerMember) => Promise<void>;
|
|
117
|
+
/** Fired when a member's role changes. */
|
|
118
|
+
onMemberRoleChanged?: (ctx: TriggerContext, data: {
|
|
119
|
+
member: TriggerMember;
|
|
120
|
+
oldRole: string;
|
|
121
|
+
newRole: string;
|
|
122
|
+
}) => Promise<void>;
|
|
123
|
+
/** Fired when email verification completes. */
|
|
124
|
+
onEmailVerified?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;
|
|
125
|
+
/** Fired when two-factor auth is enabled for a user. */
|
|
126
|
+
onTwoFactorEnabled?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;
|
|
127
|
+
/** Fired when two-factor auth is disabled for a user. */
|
|
128
|
+
onTwoFactorDisabled?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Define lifecycle triggers for Banata Auth events.
|
|
132
|
+
*
|
|
133
|
+
* This function validates and returns the trigger configuration
|
|
134
|
+
* that will be used by the Banata Auth component to fire lifecycle hooks.
|
|
135
|
+
*
|
|
136
|
+
* @param triggers - The trigger handlers to register
|
|
137
|
+
* @returns The validated trigger configuration
|
|
138
|
+
*/
|
|
139
|
+
export declare function defineBanataAuthTriggers(triggers: BanataAuthTriggers): BanataAuthTriggers;
|
|
140
|
+
/**
|
|
141
|
+
* Execute a trigger handler safely.
|
|
142
|
+
*
|
|
143
|
+
* This wraps trigger execution with error handling so that a failing
|
|
144
|
+
* trigger doesn't break the auth flow. Errors are logged but not thrown.
|
|
145
|
+
*
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
export declare function executeTrigger<T>(triggerName: string, handler: ((ctx: TriggerContext, data: T) => Promise<void>) | undefined, ctx: TriggerContext, data: T): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Create a TriggerContext from a Convex GenericCtx.
|
|
151
|
+
*
|
|
152
|
+
* This adapts the Convex function context to the trigger context shape
|
|
153
|
+
* expected by trigger handlers.
|
|
154
|
+
*
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
export declare function createTriggerContext(ctx: GenericCtx<GenericDataModel>): TriggerContext;
|
|
158
|
+
//# sourceMappingURL=triggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../src/triggers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAIzE,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AAE/E,MAAM,WAAW,WAAW;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC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
|
|
2
|
+
function defineBanataAuthTriggers(triggers) {
|
|
3
|
+
return triggers;
|
|
4
|
+
}
|
|
5
|
+
async function executeTrigger(triggerName, handler, ctx, data) {
|
|
6
|
+
if (!handler) return;
|
|
7
|
+
try {
|
|
8
|
+
await handler(ctx, data);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error(
|
|
11
|
+
`[BanataAuth] Trigger "${triggerName}" failed:`,
|
|
12
|
+
error instanceof Error ? error.message : String(error)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function createTriggerContext(ctx) {
|
|
17
|
+
const ctxRecord = ctx;
|
|
18
|
+
return {
|
|
19
|
+
runQuery: ctxRecord.runQuery ?? noop,
|
|
20
|
+
runMutation: ctxRecord.runMutation ?? noop,
|
|
21
|
+
runAction: ctxRecord.runAction ?? noop,
|
|
22
|
+
scheduler: ctxRecord.scheduler ?? {
|
|
23
|
+
runAfter: noop,
|
|
24
|
+
runAt: noop
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function noop() {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"[BanataAuth] This context method is not available in the current function type."
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { createTriggerContext, defineBanataAuthTriggers, executeTrigger };
|
|
35
|
+
//# sourceMappingURL=triggers.js.map
|
|
36
|
+
//# sourceMappingURL=triggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/triggers.ts"],"names":[],"mappings":";AAsLO,SAAS,yBAAyB,QAAA,EAAkD;AAC1F,EAAA,OAAO,QAAA;AACR;AAUA,eAAsB,cAAA,CACrB,WAAA,EACA,OAAA,EACA,GAAA,EACA,IAAA,EACgB;AAChB,EAAA,IAAI,CAAC,OAAA,EAAS;AAEd,EAAA,IAAI;AACH,IAAA,MAAM,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,EACxB,SAAS,KAAA,EAAO;AAEf,IAAA,OAAA,CAAQ,KAAA;AAAA,MACP,yBAAyB,WAAW,CAAA,SAAA,CAAA;AAAA,MACpC,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK;AAAA,KACtD;AAAA,EACD;AACD;AAUO,SAAS,qBAAqB,GAAA,EAAmD;AAIvF,EAAA,MAAM,SAAA,GAAY,GAAA;AAElB,EAAA,OAAO;AAAA,IACN,QAAA,EAAW,UAAU,QAAA,IAAY,IAAA;AAAA,IACjC,WAAA,EAAc,UAAU,WAAA,IAAe,IAAA;AAAA,IACvC,SAAA,EAAY,UAAU,SAAA,IAAa,IAAA;AAAA,IACnC,SAAA,EAAY,UAAU,SAAA,IAAa;AAAA,MAClC,QAAA,EAAU,IAAA;AAAA,MACV,KAAA,EAAO;AAAA;AACR,GACD;AACD;AAEA,eAAe,IAAA,GAAuB;AACrC,EAAA,MAAM,IAAI,KAAA;AAAA,IACT;AAAA,GACD;AACD","file":"triggers.js","sourcesContent":["/**\n * Convex trigger system for Banata Auth lifecycle events.\n *\n * Triggers allow consumers to run custom logic when auth-related\n * events occur (user created, user updated, session created, etc.).\n * These are modeled after Convex's trigger pattern.\n *\n * @example\n * ```ts\n * import { defineBanataAuthTriggers } from \"@banata-auth/convex/triggers\";\n *\n * export const triggers = defineBanataAuthTriggers({\n * onUserCreated: async (ctx, user) => {\n * // Send welcome email, create default org, etc.\n * console.log(\"New user:\", user.email);\n * },\n * onUserUpdated: async (ctx, { oldUser, newUser }) => {\n * // Sync user data to external systems\n * },\n * onSessionCreated: async (ctx, session) => {\n * // Log sign-in event\n * },\n * });\n * ```\n */\n\nimport type { GenericCtx } from \"@convex-dev/better-auth/utils\";\nimport type { FunctionReference, GenericDataModel } from \"convex/server\";\n\n// ─── Trigger Event Types ────────────────────────────────────────────\n\n/** Structured metadata for trigger data. */\nexport type TriggerMetadata = Record<string, string | number | boolean | null>;\n\nexport interface TriggerUser {\n\t_id: string;\n\tname: string;\n\temail: string;\n\temailVerified: boolean;\n\timage?: string;\n\tusername?: string;\n\trole?: string;\n\tbanned?: boolean;\n\ttwoFactorEnabled?: boolean;\n\tisAnonymous?: boolean;\n\tmetadata?: TriggerMetadata;\n\tcreatedAt: number;\n\tupdatedAt: number;\n}\n\nexport interface TriggerSession {\n\t_id: string;\n\tuserId: string;\n\texpiresAt: number;\n\tipAddress?: string;\n\tuserAgent?: string;\n\tactiveOrganizationId?: string;\n\timpersonatedBy?: string;\n\tcreatedAt: number;\n\tupdatedAt: number;\n}\n\nexport interface TriggerOrganization {\n\t_id: string;\n\tname: string;\n\tslug: string;\n\tlogo?: string;\n\tmetadata?: TriggerMetadata;\n\tcreatedAt: number;\n\tupdatedAt: number;\n}\n\nexport interface TriggerMember {\n\t_id: string;\n\torganizationId: string;\n\tuserId: string;\n\trole: string;\n\tcreatedAt: number;\n\tupdatedAt: number;\n}\n\n// ─── Trigger Handler Types ──────────────────────────────────────────\n\n/**\n * Context provided to trigger handlers.\n * This is a subset of the Convex mutation context, fully typed.\n */\nexport interface TriggerContext {\n\t/** Run a Convex query. */\n\trunQuery: <Args extends Record<string, unknown>, Output>(\n\t\tquery: FunctionReference<\"query\", \"public\" | \"internal\", Args, Output>,\n\t\targs: Args,\n\t) => Promise<Output>;\n\t/** Run a Convex mutation. */\n\trunMutation: <Args extends Record<string, unknown>, Output>(\n\t\tmutation: FunctionReference<\"mutation\", \"public\" | \"internal\", Args, Output>,\n\t\targs: Args,\n\t) => Promise<Output>;\n\t/** Run a Convex action. */\n\trunAction: <Args extends Record<string, unknown>, Output>(\n\t\taction: FunctionReference<\"action\", \"public\" | \"internal\", Args, Output>,\n\t\targs: Args,\n\t) => Promise<Output>;\n\t/** Schedule a function to run later. */\n\tscheduler: {\n\t\trunAfter: <Args extends Record<string, unknown>>(\n\t\t\tdelayMs: number,\n\t\t\tfn: FunctionReference<\"mutation\" | \"action\", \"public\" | \"internal\", Args>,\n\t\t\targs: Args,\n\t\t) => Promise<string>;\n\t\trunAt: <Args extends Record<string, unknown>>(\n\t\t\ttimestamp: number,\n\t\t\tfn: FunctionReference<\"mutation\" | \"action\", \"public\" | \"internal\", Args>,\n\t\t\targs: Args,\n\t\t) => Promise<string>;\n\t};\n}\n\nexport interface BanataAuthTriggers {\n\t/** Fired when a new user is created (sign-up, OAuth first login, SCIM provisioning). */\n\tonUserCreated?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;\n\n\t/** Fired when a user is updated (profile change, role change, ban/unban). */\n\tonUserUpdated?: (\n\t\tctx: TriggerContext,\n\t\tdata: { oldUser: TriggerUser; newUser: TriggerUser },\n\t) => Promise<void>;\n\n\t/** Fired when a user is deleted. */\n\tonUserDeleted?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;\n\n\t/** Fired when a new session is created (sign-in). */\n\tonSessionCreated?: (ctx: TriggerContext, session: TriggerSession) => Promise<void>;\n\n\t/** Fired when a session is revoked (sign-out). */\n\tonSessionRevoked?: (ctx: TriggerContext, session: TriggerSession) => Promise<void>;\n\n\t/** Fired when an organization is created. */\n\tonOrganizationCreated?: (ctx: TriggerContext, org: TriggerOrganization) => Promise<void>;\n\n\t/** Fired when an organization is updated. */\n\tonOrganizationUpdated?: (\n\t\tctx: TriggerContext,\n\t\tdata: { oldOrg: TriggerOrganization; newOrg: TriggerOrganization },\n\t) => Promise<void>;\n\n\t/** Fired when an organization is deleted. */\n\tonOrganizationDeleted?: (ctx: TriggerContext, org: TriggerOrganization) => Promise<void>;\n\n\t/** Fired when a member is added to an organization. */\n\tonMemberAdded?: (ctx: TriggerContext, member: TriggerMember) => Promise<void>;\n\n\t/** Fired when a member is removed from an organization. */\n\tonMemberRemoved?: (ctx: TriggerContext, member: TriggerMember) => Promise<void>;\n\n\t/** Fired when a member's role changes. */\n\tonMemberRoleChanged?: (\n\t\tctx: TriggerContext,\n\t\tdata: { member: TriggerMember; oldRole: string; newRole: string },\n\t) => Promise<void>;\n\n\t/** Fired when email verification completes. */\n\tonEmailVerified?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;\n\n\t/** Fired when two-factor auth is enabled for a user. */\n\tonTwoFactorEnabled?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;\n\n\t/** Fired when two-factor auth is disabled for a user. */\n\tonTwoFactorDisabled?: (ctx: TriggerContext, user: TriggerUser) => Promise<void>;\n}\n\n// ─── Trigger Registration ───────────────────────────────────────────\n\n/**\n * Define lifecycle triggers for Banata Auth events.\n *\n * This function validates and returns the trigger configuration\n * that will be used by the Banata Auth component to fire lifecycle hooks.\n *\n * @param triggers - The trigger handlers to register\n * @returns The validated trigger configuration\n */\nexport function defineBanataAuthTriggers(triggers: BanataAuthTriggers): BanataAuthTriggers {\n\treturn triggers;\n}\n\n/**\n * Execute a trigger handler safely.\n *\n * This wraps trigger execution with error handling so that a failing\n * trigger doesn't break the auth flow. Errors are logged but not thrown.\n *\n * @internal\n */\nexport async function executeTrigger<T>(\n\ttriggerName: string,\n\thandler: ((ctx: TriggerContext, data: T) => Promise<void>) | undefined,\n\tctx: TriggerContext,\n\tdata: T,\n): Promise<void> {\n\tif (!handler) return;\n\n\ttry {\n\t\tawait handler(ctx, data);\n\t} catch (error) {\n\t\t// Log but don't throw — triggers should not break auth flows\n\t\tconsole.error(\n\t\t\t`[BanataAuth] Trigger \"${triggerName}\" failed:`,\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t);\n\t}\n}\n\n/**\n * Create a TriggerContext from a Convex GenericCtx.\n *\n * This adapts the Convex function context to the trigger context shape\n * expected by trigger handlers.\n *\n * @internal\n */\nexport function createTriggerContext(ctx: GenericCtx<GenericDataModel>): TriggerContext {\n\t// The GenericCtx union (query | mutation | action) doesn't guarantee all\n\t// methods exist. We cast to the widest shape — at runtime, the actual\n\t// context will have the right methods based on the calling function type.\n\tconst ctxRecord = ctx as unknown as Record<string, unknown>;\n\n\treturn {\n\t\trunQuery: (ctxRecord.runQuery ?? noop) as TriggerContext[\"runQuery\"],\n\t\trunMutation: (ctxRecord.runMutation ?? noop) as TriggerContext[\"runMutation\"],\n\t\trunAction: (ctxRecord.runAction ?? noop) as TriggerContext[\"runAction\"],\n\t\tscheduler: (ctxRecord.scheduler ?? {\n\t\t\trunAfter: noop,\n\t\t\trunAt: noop,\n\t\t}) as TriggerContext[\"scheduler\"],\n\t};\n}\n\nasync function noop(): Promise<never> {\n\tthrow new Error(\n\t\t\"[BanataAuth] This context method is not available in the current function type.\",\n\t);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@banata-auth/convex",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"description": "Convex backend integration for Banata Auth — auth factory, plugins, triggers, and database schema",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/banata-auth/banata-auth",
|
|
11
|
+
"directory": "packages/convex"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://auth-docs.banata.dev/docs/convex",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"banata-auth",
|
|
16
|
+
"auth",
|
|
17
|
+
"convex",
|
|
18
|
+
"better-auth",
|
|
19
|
+
"plugins",
|
|
20
|
+
"sso",
|
|
21
|
+
"rbac",
|
|
22
|
+
"webhooks"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./auth-config": {
|
|
35
|
+
"types": "./dist/auth-config.d.ts",
|
|
36
|
+
"import": "./dist/auth-config.js",
|
|
37
|
+
"default": "./dist/auth-config.js"
|
|
38
|
+
},
|
|
39
|
+
"./adapter": {
|
|
40
|
+
"types": "./dist/component/adapter.d.ts",
|
|
41
|
+
"import": "./dist/component/adapter.js",
|
|
42
|
+
"default": "./dist/component/adapter.js"
|
|
43
|
+
},
|
|
44
|
+
"./http": {
|
|
45
|
+
"types": "./dist/http.d.ts",
|
|
46
|
+
"import": "./dist/http.js",
|
|
47
|
+
"default": "./dist/http.js"
|
|
48
|
+
},
|
|
49
|
+
"./node": {
|
|
50
|
+
"types": "./dist/node.d.ts",
|
|
51
|
+
"import": "./dist/node.js",
|
|
52
|
+
"default": "./dist/node.js"
|
|
53
|
+
},
|
|
54
|
+
"./triggers": {
|
|
55
|
+
"types": "./dist/triggers.d.ts",
|
|
56
|
+
"import": "./dist/triggers.js",
|
|
57
|
+
"default": "./dist/triggers.js"
|
|
58
|
+
},
|
|
59
|
+
"./plugins": {
|
|
60
|
+
"types": "./dist/plugins/index.d.ts",
|
|
61
|
+
"import": "./dist/plugins/index.js",
|
|
62
|
+
"default": "./dist/plugins/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./convex.config": {
|
|
65
|
+
"import": "./src/component/convex.config.ts"
|
|
66
|
+
},
|
|
67
|
+
"./schema": {
|
|
68
|
+
"import": "./src/component/schema.ts"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"main": "./dist/index.js",
|
|
72
|
+
"module": "./dist/index.js",
|
|
73
|
+
"types": "./dist/index.d.ts",
|
|
74
|
+
"files": ["dist", "src/component"],
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "tsup && tsc",
|
|
77
|
+
"dev": "tsup --watch",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"test": "vitest run --passWithNoTests",
|
|
80
|
+
"prepublishOnly": "bun run build",
|
|
81
|
+
"clean": "rm -rf dist .turbo"
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@better-auth/passkey": "^1.4.9",
|
|
85
|
+
"@better-auth/scim": "^1.4.20",
|
|
86
|
+
"@better-auth/sso": "^1.4.20",
|
|
87
|
+
"@convex-dev/better-auth": "^0.10.13",
|
|
88
|
+
"@banata-auth/shared": "workspace:*",
|
|
89
|
+
"zod": "^3.23.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"better-auth": ">=1.4.9 <2.0.0",
|
|
93
|
+
"convex": "^1.25.0"
|
|
94
|
+
},
|
|
95
|
+
"devDependencies": {
|
|
96
|
+
"better-auth": "^1.4.9",
|
|
97
|
+
"convex": "^1.25.0",
|
|
98
|
+
"tsup": "^8.3.0",
|
|
99
|
+
"typescript": "^5.7.0",
|
|
100
|
+
"vitest": "^3.0.0"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export `createApi` from @convex-dev/better-auth for consumers.
|
|
3
|
+
*
|
|
4
|
+
* Per the Convex component pattern, consumers call `createApi` directly
|
|
5
|
+
* in their local `convex/banataAuth/adapter.ts` to generate the CRUD
|
|
6
|
+
* functions (create, findOne, findMany, updateOne, updateMany, deleteOne,
|
|
7
|
+
* deleteMany) needed by the component adapter.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // convex/banataAuth/adapter.ts
|
|
12
|
+
* import { createApi } from "@banata-auth/convex/adapter";
|
|
13
|
+
* import { createAuthOptions } from "./auth";
|
|
14
|
+
* import schema from "./schema";
|
|
15
|
+
*
|
|
16
|
+
* export const { create, findOne, findMany, updateOne, updateMany, deleteOne, deleteMany }
|
|
17
|
+
* = createApi(schema, createAuthOptions);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export { createApi } from "@convex-dev/better-auth";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineComponent } from "convex/server";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Banata Auth Convex component definition.
|
|
5
|
+
*
|
|
6
|
+
* This creates an isolated namespace within Convex for all auth tables.
|
|
7
|
+
* The component is registered in the consumer's convex.config.ts via:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import banataAuth from "@banata-auth/convex/convex.config";
|
|
11
|
+
* app.use(banataAuth);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
const component = defineComponent("banataAuth");
|
|
15
|
+
export default component;
|