@stll/auth-model 0.2.0 → 0.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.
@@ -1,10 +1,10 @@
1
1
  //#region src/contract.d.ts
2
2
  /** Better Auth version whose logical schema this contract describes. */
3
- declare const BETTER_AUTH_CONTRACT_VERSION = "1.7.1";
4
- declare const ORGANIZATION_ROLE_NAMES: readonly ["owner", "admin", "member", "intern", "external"];
5
- type OrganizationRoleName = (typeof ORGANIZATION_ROLE_NAMES)[number];
3
+ export declare const BETTER_AUTH_CONTRACT_VERSION = "1.7.1";
4
+ export declare const ORGANIZATION_ROLE_NAMES: readonly ["owner", "admin", "member", "intern", "external"];
5
+ export type OrganizationRoleName = (typeof ORGANIZATION_ROLE_NAMES)[number];
6
6
  /** Better Auth organization resources. Hosts extend this with product grants. */
7
- declare const BETTER_AUTH_ORGANIZATION_STATEMENTS: {
7
+ export declare const BETTER_AUTH_ORGANIZATION_STATEMENTS: {
8
8
  readonly organization: readonly ["update", "delete"];
9
9
  readonly member: readonly ["create", "update", "delete"];
10
10
  readonly invitation: readonly ["create", "cancel"];
@@ -12,9 +12,9 @@ declare const BETTER_AUTH_ORGANIZATION_STATEMENTS: {
12
12
  readonly ac: readonly ["create", "read", "update", "delete"];
13
13
  };
14
14
  type OrganizationPermissionMap = { [Resource in keyof typeof BETTER_AUTH_ORGANIZATION_STATEMENTS]: (typeof BETTER_AUTH_ORGANIZATION_STATEMENTS)[Resource][number][]; };
15
- type BetterAuthOrganizationRoleGrants = Record<OrganizationRoleName, OrganizationPermissionMap>;
15
+ export type BetterAuthOrganizationRoleGrants = Record<OrganizationRoleName, OrganizationPermissionMap>;
16
16
  /** Core grants shared by every application; product grants remain host-owned. */
17
- declare const BETTER_AUTH_ORGANIZATION_ROLE_GRANTS: {
17
+ export declare const BETTER_AUTH_ORGANIZATION_ROLE_GRANTS: {
18
18
  owner: {
19
19
  organization: ("update" | "delete")[];
20
20
  member: ("update" | "delete" | "create")[];
@@ -55,24 +55,25 @@ declare const BETTER_AUTH_ORGANIZATION_ROLE_GRANTS: {
55
55
  * Values that change Better Auth's organization authorization semantics.
56
56
  * Hooks, adapters, email delivery, and product-specific options stay local.
57
57
  */
58
- declare const BETTER_AUTH_ORGANIZATION_OPTIONS: {
58
+ export declare const BETTER_AUTH_ORGANIZATION_OPTIONS: {
59
59
  readonly allowUserToCreateOrganization: true;
60
60
  readonly cancelPendingInvitationsOnReInvite: false;
61
61
  readonly creatorRole: "owner";
62
62
  readonly invitationExpiresIn: number;
63
63
  readonly membershipLimit: 500;
64
+ readonly requireEmailVerificationOnInvitation: true;
64
65
  };
65
66
  /** Adapter switches which must match in every host. */
66
- declare const BETTER_AUTH_ADAPTER_OPTIONS: {
67
+ export declare const BETTER_AUTH_ADAPTER_OPTIONS: {
67
68
  readonly camelCase: false;
68
69
  readonly provider: "pg";
69
70
  readonly transaction: true;
70
71
  readonly usePlural: false;
71
72
  };
72
- declare const BETTER_AUTH_CORE_MODEL_NAMES: readonly ["user", "session", "account", "verification", "organization", "member", "invitation"];
73
- type BetterAuthCoreModelName = (typeof BETTER_AUTH_CORE_MODEL_NAMES)[number];
74
- type BetterAuthFieldType = "boolean" | "date" | "string";
75
- type BetterAuthFieldDefault = {
73
+ export declare const BETTER_AUTH_CORE_MODEL_NAMES: readonly ["user", "session", "account", "verification", "organization", "member", "invitation"];
74
+ export type BetterAuthCoreModelName = (typeof BETTER_AUTH_CORE_MODEL_NAMES)[number];
75
+ export type BetterAuthFieldType = "boolean" | "date" | "string";
76
+ export type BetterAuthFieldDefault = {
76
77
  kind: "none";
77
78
  } | {
78
79
  kind: "runtime";
@@ -80,12 +81,12 @@ type BetterAuthFieldDefault = {
80
81
  kind: "literal";
81
82
  value: boolean | number | string;
82
83
  };
83
- type BetterAuthFieldReference = {
84
+ export type BetterAuthFieldReference = {
84
85
  field: "id";
85
86
  model: "organization" | "user";
86
87
  onDelete: "cascade" | null;
87
88
  };
88
- type BetterAuthLogicalFieldContract = {
89
+ export type BetterAuthLogicalFieldContract = {
89
90
  default: BetterAuthFieldDefault;
90
91
  indexed: boolean;
91
92
  input: "allowed" | "server-managed";
@@ -97,7 +98,7 @@ type BetterAuthLogicalFieldContract = {
97
98
  type: BetterAuthFieldType;
98
99
  unique: boolean;
99
100
  };
100
- type BetterAuthDatabaseFieldContract = {
101
+ export type BetterAuthDatabaseFieldContract = {
101
102
  columnName: string;
102
103
  columnType: "boolean" | "text" | "timestamptz";
103
104
  default: BetterAuthFieldDefault;
@@ -109,16 +110,16 @@ type BetterAuthDatabaseFieldContract = {
109
110
  unique: boolean;
110
111
  };
111
112
  /** Better Auth behavior and physical database guarantees, kept separate. */
112
- type BetterAuthFieldContract = {
113
+ export type BetterAuthFieldContract = {
113
114
  database: BetterAuthDatabaseFieldContract;
114
115
  logical: BetterAuthLogicalFieldContract;
115
116
  };
116
- type BetterAuthIndexContract = {
117
+ export type BetterAuthIndexContract = {
117
118
  fields: readonly string[];
118
119
  predicate: string | null;
119
120
  unique: boolean;
120
121
  };
121
- type BetterAuthModelContract = {
122
+ export type BetterAuthModelContract = {
122
123
  fields: Record<string, BetterAuthFieldContract>;
123
124
  indexes: readonly BetterAuthIndexContract[];
124
125
  primaryKey: readonly string[];
@@ -128,7 +129,7 @@ type BetterAuthModelContract = {
128
129
  * Normalized Better Auth core plus the organization plugin's shared models and
129
130
  * `activeOrganizationId` session extension.
130
131
  */
131
- declare const BETTER_AUTH_CORE_SCHEMA: {
132
+ export declare const BETTER_AUTH_CORE_SCHEMA: {
132
133
  readonly user: {
133
134
  readonly tableName: "user";
134
135
  readonly primaryKey: readonly ["id"];
@@ -150,7 +151,7 @@ declare const BETTER_AUTH_CORE_SCHEMA: {
150
151
  readonly primaryKey: readonly ["id"];
151
152
  readonly fields: Record<string, BetterAuthFieldContract>;
152
153
  readonly indexes: readonly [{
153
- readonly fields: readonly ["issuer", "accountId"];
154
+ readonly fields: readonly ["providerId", "accountId"];
154
155
  readonly predicate: null;
155
156
  readonly unique: true;
156
157
  }, {
@@ -212,7 +213,7 @@ declare const BETTER_AUTH_CORE_SCHEMA: {
212
213
  }];
213
214
  };
214
215
  };
215
- type BetterAuthAdapterContract = {
216
+ export type BetterAuthAdapterContract = {
216
217
  camelCase: boolean;
217
218
  dateStorage: "timestamp-with-time-zone";
218
219
  idGeneration: "application-string";
@@ -223,7 +224,7 @@ type BetterAuthAdapterContract = {
223
224
  usePlural: boolean;
224
225
  verificationStorage: "database";
225
226
  };
226
- declare const BETTER_AUTH_ADAPTER_INVARIANTS: {
227
+ export declare const BETTER_AUTH_ADAPTER_INVARIANTS: {
227
228
  readonly dateStorage: "timestamp-with-time-zone";
228
229
  readonly idGeneration: "application-string";
229
230
  readonly sessionStorage: "database";
@@ -242,21 +243,21 @@ declare const BETTER_AUTH_ADAPTER_INVARIANTS: {
242
243
  readonly transaction: true;
243
244
  readonly usePlural: false;
244
245
  };
245
- type BetterAuthSchemaCandidate = {
246
+ export type BetterAuthSchemaCandidate = {
246
247
  adapter: BetterAuthAdapterContract;
247
248
  models: Record<string, BetterAuthModelContract>;
248
249
  };
249
- type BetterAuthSchemaExtensions = {
250
+ export type BetterAuthSchemaExtensions = {
250
251
  fields?: Partial<Record<BetterAuthCoreModelName, Record<string, BetterAuthFieldContract>>>;
251
252
  indexes?: Partial<Record<BetterAuthCoreModelName, readonly BetterAuthIndexContract[]>>;
252
253
  models?: readonly string[];
253
254
  };
254
- type BetterAuthSchemaParityIssue = {
255
+ export type BetterAuthSchemaParityIssue = {
255
256
  actual: unknown;
256
257
  expected: unknown;
257
258
  path: string;
258
259
  };
259
- type BetterAuthSchemaParityResult = {
260
+ export type BetterAuthSchemaParityResult = {
260
261
  status: "compatible";
261
262
  } | {
262
263
  issues: BetterAuthSchemaParityIssue[];
@@ -266,8 +267,8 @@ type BetterAuthSchemaParityResult = {
266
267
  * Compares a normalized host schema with the complete shared core. Extensions
267
268
  * are exact allowlists: missing, stale, and undeclared additions all fail.
268
269
  */
269
- declare const compareBetterAuthSchema: (candidate: BetterAuthSchemaCandidate, extensions?: BetterAuthSchemaExtensions) => BetterAuthSchemaParityResult;
270
- declare const BETTER_AUTH_PARITY_MANIFEST: {
270
+ export declare const compareBetterAuthSchema: (candidate: BetterAuthSchemaCandidate, extensions?: BetterAuthSchemaExtensions) => BetterAuthSchemaParityResult;
271
+ export declare const BETTER_AUTH_PARITY_MANIFEST: {
271
272
  readonly adapterInvariants: {
272
273
  readonly dateStorage: "timestamp-with-time-zone";
273
274
  readonly idGeneration: "application-string";
@@ -294,6 +295,7 @@ declare const BETTER_AUTH_PARITY_MANIFEST: {
294
295
  readonly creatorRole: "owner";
295
296
  readonly invitationExpiresIn: number;
296
297
  readonly membershipLimit: 500;
298
+ readonly requireEmailVerificationOnInvitation: true;
297
299
  };
298
300
  readonly roleGrants: {
299
301
  owner: {
@@ -355,7 +357,7 @@ declare const BETTER_AUTH_PARITY_MANIFEST: {
355
357
  readonly primaryKey: readonly ["id"];
356
358
  readonly fields: Record<string, BetterAuthFieldContract>;
357
359
  readonly indexes: readonly [{
358
- readonly fields: readonly ["issuer", "accountId"];
360
+ readonly fields: readonly ["providerId", "accountId"];
359
361
  readonly predicate: null;
360
362
  readonly unique: true;
361
363
  }, {
@@ -418,5 +420,4 @@ declare const BETTER_AUTH_PARITY_MANIFEST: {
418
420
  };
419
421
  };
420
422
  };
421
- //#endregion
422
- export { BETTER_AUTH_ADAPTER_INVARIANTS, BETTER_AUTH_ADAPTER_OPTIONS, BETTER_AUTH_CONTRACT_VERSION, BETTER_AUTH_CORE_MODEL_NAMES, BETTER_AUTH_CORE_SCHEMA, BETTER_AUTH_ORGANIZATION_OPTIONS, BETTER_AUTH_ORGANIZATION_ROLE_GRANTS, BETTER_AUTH_ORGANIZATION_STATEMENTS, BETTER_AUTH_PARITY_MANIFEST, BetterAuthAdapterContract, BetterAuthCoreModelName, BetterAuthDatabaseFieldContract, BetterAuthFieldContract, BetterAuthFieldDefault, BetterAuthFieldReference, BetterAuthFieldType, BetterAuthIndexContract, BetterAuthLogicalFieldContract, BetterAuthModelContract, BetterAuthOrganizationRoleGrants, BetterAuthSchemaCandidate, BetterAuthSchemaExtensions, BetterAuthSchemaParityIssue, BetterAuthSchemaParityResult, ORGANIZATION_ROLE_NAMES, OrganizationRoleName, compareBetterAuthSchema };
423
+ //#endregion
package/dist/contract.js CHANGED
@@ -102,7 +102,8 @@ const BETTER_AUTH_ORGANIZATION_OPTIONS = {
102
102
  cancelPendingInvitationsOnReInvite: false,
103
103
  creatorRole: "owner",
104
104
  invitationExpiresIn: 172800,
105
- membershipLimit: 500
105
+ membershipLimit: 500,
106
+ requireEmailVerificationOnInvitation: true
106
107
  };
107
108
  /** Adapter switches which must match in every host. */
108
109
  const BETTER_AUTH_ADAPTER_OPTIONS = {
@@ -277,7 +278,10 @@ const BETTER_AUTH_CORE_SCHEMA = {
277
278
  primaryKey: ["id"],
278
279
  fields: withPhysicalNames({
279
280
  id: idField,
280
- issuer: field("string", { required: true }),
281
+ issuer: field("string", {
282
+ database: { notNull: false },
283
+ required: true
284
+ }),
281
285
  accountId: field("string", { required: true }),
282
286
  providerId: field("string", { required: true }),
283
287
  userId: field("string", {
@@ -296,7 +300,7 @@ const BETTER_AUTH_CORE_SCHEMA = {
296
300
  updatedAt: updatedDate
297
301
  }),
298
302
  indexes: [{
299
- fields: ["issuer", "accountId"],
303
+ fields: ["providerId", "accountId"],
300
304
  predicate: null,
301
305
  unique: true
302
306
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/auth-model",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Portable Better Auth core contract and parity checks.",
5
5
  "keywords": [
6
6
  "authentication",
@@ -42,14 +42,14 @@
42
42
  "typecheck": "bun ../../packages/scripts/src/tsc-native.ts --noEmit",
43
43
  "lint": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error --deny-warnings --type-aware packages/auth-model",
44
44
  "lint:fix": "cd ../.. && bun --bun oxlint -c oxlint.config.ts --type-aware --fix packages/auth-model",
45
- "format": "oxfmt .",
45
+ "format": "bun ../../scripts/run-oxfmt.ts .",
46
46
  "prepack": "bun run build"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@stll/typescript-config": "0.0.0",
50
50
  "better-auth": "1.7.1",
51
- "bun-types": "1.4.0",
52
- "tsdown": "0.22.14"
51
+ "bun-types": "1.4.2",
52
+ "tsdown": "0.23.0"
53
53
  },
54
54
  "main": "./dist/contract.js",
55
55
  "types": "./dist/contract.d.ts"