@authhero/drizzle 0.65.0 → 1.0.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.
@@ -160,7 +160,6 @@ var Ce = Object.defineProperty, we = (e, t) => {
160
160
  name: "users_tenants"
161
161
  }),
162
162
  E("unique_email_provider").on(e.email, e.provider, e.tenant_id),
163
- E("unique_phone_provider").on(e.phone_number, e.provider, e.tenant_id),
164
163
  E("unique_username_provider").on(e.username, e.provider, e.tenant_id),
165
164
  x("users_email_index").on(e.email),
166
165
  x("users_linked_to_index").on(e.linked_to),
@@ -2245,7 +2244,7 @@ function Xt(e) {
2245
2244
  async create(n, r) {
2246
2245
  let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.scope ?? [], s = r.audience ?? "", c = await e.select().from(B).where(t(a(B.tenant_id, n), a(B.user_id, r.user_id), a(B.client_id, r.clientID), a(B.audience, s))).get();
2247
2246
  if (c) {
2248
- let r = Q(c.scope, []) ?? [], s = Array.from(/* @__PURE__ */ new Set([...r, ...o]));
2247
+ let r = Q(c.scope, []) ?? [], s = Array.from(new Set([...r, ...o]));
2249
2248
  return await e.update(B).set({
2250
2249
  scope: JSON.stringify(s),
2251
2250
  updated_at: i
@@ -2561,7 +2560,7 @@ var fn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", pn = 32;
2561
2560
  function mn() {
2562
2561
  let e = Date.now(), t = "";
2563
2562
  for (let n = 10; n > 0; n--) t = fn.charAt(e % pn) + t, e = Math.floor(e / pn);
2564
- let n = /* @__PURE__ */ new Uint8Array(16);
2563
+ let n = new Uint8Array(16);
2565
2564
  crypto.getRandomValues(n);
2566
2565
  for (let e = 0; e < 16; e++) t += fn.charAt(n[e] % pn);
2567
2566
  return t;
@@ -2740,7 +2739,7 @@ var yn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", bn = 32;
2740
2739
  function xn() {
2741
2740
  let e = Date.now(), t = "";
2742
2741
  for (let n = 10; n > 0; n--) t = yn.charAt(e % bn) + t, e = Math.floor(e / bn);
2743
- let n = /* @__PURE__ */ new Uint8Array(16);
2742
+ let n = new Uint8Array(16);
2744
2743
  crypto.getRandomValues(n);
2745
2744
  for (let e = 0; e < 16; e++) t += yn.charAt(n[e] % bn);
2746
2745
  return t;
@@ -3181,7 +3180,7 @@ var Bn = [
3181
3180
  "skip_consent_for_verifiable_first_party_clients",
3182
3181
  "allow_offline_access",
3183
3182
  "is_system"
3184
- ], Vn = /* @__PURE__ */ new Set([
3183
+ ], Vn = new Set([
3185
3184
  "id",
3186
3185
  "tenant_id",
3187
3186
  "identifier",
@@ -3834,7 +3833,7 @@ var mr = [
3834
3833
  "name",
3835
3834
  "phone_number",
3836
3835
  "user_id"
3837
- ], gr = /* @__PURE__ */ new Set([
3836
+ ], gr = new Set([
3838
3837
  "last_login",
3839
3838
  "last_ip",
3840
3839
  "login_count"
@@ -4072,7 +4071,7 @@ function Tr(e) {
4072
4071
  },
4073
4072
  async list(n, r, i, o) {
4074
4073
  let s = [a(K.tenant_id, n), a(K.user_id, r)];
4075
- o && s.push(a(K.organization_id, o));
4074
+ o !== void 0 && s.push(a(K.organization_id, o));
4076
4075
  let c = await e.select({ role_id: K.role_id }).from(K).where(t(...s)).all();
4077
4076
  return c.length === 0 ? [] : (await Promise.all(c.map(async (r) => {
4078
4077
  let i = await e.select().from(G).where(t(a(G.tenant_id, n), a(G.id, r.role_id))).get();
@@ -4375,7 +4374,7 @@ function Ir(e) {
4375
4374
  });
4376
4375
  let g = e.select(f).from(Y).where(t(...d));
4377
4376
  p.length > 0 && (g = g.groupBy(...p));
4378
- let _ = /* @__PURE__ */ new Set([...Object.keys(f)]);
4377
+ let _ = new Set([...Object.keys(f)]);
4379
4378
  if (i.order_by) {
4380
4379
  let e = i.order_by.startsWith("-"), t = e ? i.order_by.slice(1) : i.order_by;
4381
4380
  if (!_.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
@@ -158,7 +158,6 @@ CREATE TABLE `users` (
158
158
  );
159
159
  --> statement-breakpoint
160
160
  CREATE UNIQUE INDEX `unique_email_provider` ON `users` (`email`,`provider`,`tenant_id`);--> statement-breakpoint
161
- CREATE UNIQUE INDEX `unique_phone_provider` ON `users` (`phone_number`,`provider`,`tenant_id`);--> statement-breakpoint
162
161
  CREATE UNIQUE INDEX `unique_username_provider` ON `users` (`username`,`provider`,`tenant_id`);--> statement-breakpoint
163
162
  CREATE INDEX `users_email_index` ON `users` (`email`);--> statement-breakpoint
164
163
  CREATE INDEX `users_linked_to_index` ON `users` (`linked_to`);--> statement-breakpoint
@@ -433,6 +432,21 @@ CREATE TABLE `clients` (
433
432
  );
434
433
  --> statement-breakpoint
435
434
  CREATE INDEX `idx_clients_owner_user_id` ON `clients` (`tenant_id`,`owner_user_id`);--> statement-breakpoint
435
+ CREATE TABLE `grants` (
436
+ `id` text(21) PRIMARY KEY NOT NULL,
437
+ `tenant_id` text(255) NOT NULL,
438
+ `user_id` text(255) NOT NULL,
439
+ `client_id` text(100) NOT NULL,
440
+ `audience` text(100) DEFAULT '' NOT NULL,
441
+ `scope` text DEFAULT '[]' NOT NULL,
442
+ `created_at` text(35) NOT NULL,
443
+ `updated_at` text(35) NOT NULL,
444
+ FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON UPDATE no action ON DELETE cascade,
445
+ FOREIGN KEY (`user_id`,`tenant_id`) REFERENCES `users`(`user_id`,`tenant_id`) ON UPDATE no action ON DELETE cascade
446
+ );
447
+ --> statement-breakpoint
448
+ CREATE UNIQUE INDEX `grants_natural_key_idx` ON `grants` (`tenant_id`,`user_id`,`client_id`,`audience`);--> statement-breakpoint
449
+ CREATE INDEX `grants_tenant_user_idx` ON `grants` (`tenant_id`,`user_id`);--> statement-breakpoint
436
450
  CREATE TABLE `connections` (
437
451
  `id` text(255) NOT NULL,
438
452
  `tenant_id` text(191) NOT NULL,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "6",
3
3
  "dialect": "sqlite",
4
- "id": "f5a5b35e-cf8e-4fe4-afe9-ec2d33b03c33",
4
+ "id": "f612da20-cbcd-43bf-819f-2d1d5a3beb5e",
5
5
  "prevId": "00000000-0000-0000-0000-000000000000",
6
6
  "tables": {
7
7
  "tenants": {
@@ -1084,15 +1084,6 @@
1084
1084
  ],
1085
1085
  "isUnique": true
1086
1086
  },
1087
- "unique_phone_provider": {
1088
- "name": "unique_phone_provider",
1089
- "columns": [
1090
- "phone_number",
1091
- "provider",
1092
- "tenant_id"
1093
- ],
1094
- "isUnique": true
1095
- },
1096
1087
  "unique_username_provider": {
1097
1088
  "name": "unique_username_provider",
1098
1089
  "columns": [
@@ -3048,6 +3039,122 @@
3048
3039
  "uniqueConstraints": {},
3049
3040
  "checkConstraints": {}
3050
3041
  },
3042
+ "grants": {
3043
+ "name": "grants",
3044
+ "columns": {
3045
+ "id": {
3046
+ "name": "id",
3047
+ "type": "text(21)",
3048
+ "primaryKey": true,
3049
+ "notNull": true,
3050
+ "autoincrement": false
3051
+ },
3052
+ "tenant_id": {
3053
+ "name": "tenant_id",
3054
+ "type": "text(255)",
3055
+ "primaryKey": false,
3056
+ "notNull": true,
3057
+ "autoincrement": false
3058
+ },
3059
+ "user_id": {
3060
+ "name": "user_id",
3061
+ "type": "text(255)",
3062
+ "primaryKey": false,
3063
+ "notNull": true,
3064
+ "autoincrement": false
3065
+ },
3066
+ "client_id": {
3067
+ "name": "client_id",
3068
+ "type": "text(100)",
3069
+ "primaryKey": false,
3070
+ "notNull": true,
3071
+ "autoincrement": false
3072
+ },
3073
+ "audience": {
3074
+ "name": "audience",
3075
+ "type": "text(100)",
3076
+ "primaryKey": false,
3077
+ "notNull": true,
3078
+ "autoincrement": false,
3079
+ "default": "''"
3080
+ },
3081
+ "scope": {
3082
+ "name": "scope",
3083
+ "type": "text",
3084
+ "primaryKey": false,
3085
+ "notNull": true,
3086
+ "autoincrement": false,
3087
+ "default": "'[]'"
3088
+ },
3089
+ "created_at": {
3090
+ "name": "created_at",
3091
+ "type": "text(35)",
3092
+ "primaryKey": false,
3093
+ "notNull": true,
3094
+ "autoincrement": false
3095
+ },
3096
+ "updated_at": {
3097
+ "name": "updated_at",
3098
+ "type": "text(35)",
3099
+ "primaryKey": false,
3100
+ "notNull": true,
3101
+ "autoincrement": false
3102
+ }
3103
+ },
3104
+ "indexes": {
3105
+ "grants_natural_key_idx": {
3106
+ "name": "grants_natural_key_idx",
3107
+ "columns": [
3108
+ "tenant_id",
3109
+ "user_id",
3110
+ "client_id",
3111
+ "audience"
3112
+ ],
3113
+ "isUnique": true
3114
+ },
3115
+ "grants_tenant_user_idx": {
3116
+ "name": "grants_tenant_user_idx",
3117
+ "columns": [
3118
+ "tenant_id",
3119
+ "user_id"
3120
+ ],
3121
+ "isUnique": false
3122
+ }
3123
+ },
3124
+ "foreignKeys": {
3125
+ "grants_tenant_id_tenants_id_fk": {
3126
+ "name": "grants_tenant_id_tenants_id_fk",
3127
+ "tableFrom": "grants",
3128
+ "tableTo": "tenants",
3129
+ "columnsFrom": [
3130
+ "tenant_id"
3131
+ ],
3132
+ "columnsTo": [
3133
+ "id"
3134
+ ],
3135
+ "onDelete": "cascade",
3136
+ "onUpdate": "no action"
3137
+ },
3138
+ "grants_user_id_constraint": {
3139
+ "name": "grants_user_id_constraint",
3140
+ "tableFrom": "grants",
3141
+ "tableTo": "users",
3142
+ "columnsFrom": [
3143
+ "user_id",
3144
+ "tenant_id"
3145
+ ],
3146
+ "columnsTo": [
3147
+ "user_id",
3148
+ "tenant_id"
3149
+ ],
3150
+ "onDelete": "cascade",
3151
+ "onUpdate": "no action"
3152
+ }
3153
+ },
3154
+ "compositePrimaryKeys": {},
3155
+ "uniqueConstraints": {},
3156
+ "checkConstraints": {}
3157
+ },
3051
3158
  "connections": {
3052
3159
  "name": "connections",
3053
3160
  "columns": {
@@ -5,16 +5,9 @@
5
5
  {
6
6
  "idx": 0,
7
7
  "version": "6",
8
- "when": 1783004771436,
8
+ "when": 1784301636273,
9
9
  "tag": "0000_init",
10
10
  "breakpoints": true
11
- },
12
- {
13
- "idx": 1,
14
- "version": "6",
15
- "when": 1783242650985,
16
- "tag": "0001_next_young_avengers",
17
- "breakpoints": true
18
11
  }
19
12
  ]
20
13
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/markusahlstrand/authhero"
13
13
  },
14
- "version": "0.65.0",
14
+ "version": "1.0.0",
15
15
  "files": [
16
16
  "dist",
17
17
  "src/schema",
@@ -35,8 +35,8 @@
35
35
  "dependencies": {
36
36
  "drizzle-orm": "^0.45.2",
37
37
  "nanoid": "^5.1.11",
38
- "@authhero/adapter-interfaces": "4.2.0",
39
- "@authhero/proxy": "0.9.5"
38
+ "@authhero/adapter-interfaces": "4.3.0",
39
+ "@authhero/proxy": "0.10.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@hono/zod-openapi": "^1.4.0",
@@ -54,6 +54,7 @@
54
54
  "peerDependencies": {
55
55
  "hono": "^4.6.8"
56
56
  },
57
+ "license": "AGPL-3.0-only",
57
58
  "scripts": {
58
59
  "build": "tsc && vite build",
59
60
  "test": "vitest run",
@@ -69,10 +69,7 @@ export const actionVersions = sqliteTable(
69
69
  table.action_id,
70
70
  table.number,
71
71
  ),
72
- index("idx_action_versions_action_id").on(
73
- table.tenant_id,
74
- table.action_id,
75
- ),
72
+ index("idx_action_versions_action_id").on(table.tenant_id, table.action_id),
76
73
  ],
77
74
  );
78
75
 
@@ -64,11 +64,13 @@ export const users = sqliteTable(
64
64
  table.provider,
65
65
  table.tenant_id,
66
66
  ),
67
- uniqueIndex("unique_phone_provider").on(
68
- table.phone_number,
69
- table.provider,
70
- table.tenant_id,
71
- ),
67
+ // No unique index on phone_number: a phone only *identifies* a user on the
68
+ // passwordless `sms` connection; for every other provider it is ordinary
69
+ // profile data that people legitimately share (placeholder / switchboard /
70
+ // family numbers). sms-phone uniqueness is enforced at the application
71
+ // layer (Auth0-style, at lookup), not by a database constraint. This
72
+ // mirrors the kysely baseline, which carries no phone unique index either.
73
+ // See #1162. The non-unique lookup index below remains.
72
74
  uniqueIndex("unique_username_provider").on(
73
75
  table.username,
74
76
  table.provider,
@@ -1,15 +0,0 @@
1
- CREATE TABLE `grants` (
2
- `id` text(21) PRIMARY KEY NOT NULL,
3
- `tenant_id` text(255) NOT NULL,
4
- `user_id` text(255) NOT NULL,
5
- `client_id` text(100) NOT NULL,
6
- `audience` text(100) DEFAULT '' NOT NULL,
7
- `scope` text DEFAULT '[]' NOT NULL,
8
- `created_at` text(35) NOT NULL,
9
- `updated_at` text(35) NOT NULL,
10
- FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON UPDATE no action ON DELETE cascade,
11
- FOREIGN KEY (`user_id`,`tenant_id`) REFERENCES `users`(`user_id`,`tenant_id`) ON UPDATE no action ON DELETE cascade
12
- );
13
- --> statement-breakpoint
14
- CREATE UNIQUE INDEX `grants_natural_key_idx` ON `grants` (`tenant_id`,`user_id`,`client_id`,`audience`);--> statement-breakpoint
15
- CREATE INDEX `grants_tenant_user_idx` ON `grants` (`tenant_id`,`user_id`);