@spfn/auth 0.1.0-alpha.0 → 0.1.0-alpha.1
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 +70 -12
- package/dist/api-BcQM4WKb.d.ts +45 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +8966 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/contracts/auth.d.ts +262 -0
- package/dist/lib/contracts/auth.js +2923 -0
- package/dist/lib/contracts/auth.js.map +1 -0
- package/dist/lib/contracts/index.d.ts +3 -0
- package/dist/lib/contracts/index.js +3162 -0
- package/dist/lib/contracts/index.js.map +1 -0
- package/dist/lib/contracts/invitation.d.ts +243 -0
- package/dist/lib/contracts/invitation.js +2883 -0
- package/dist/lib/contracts/invitation.js.map +1 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +8949 -0
- package/dist/plugin.js.map +1 -0
- package/dist/server/entities/index.d.ts +10 -0
- package/dist/server/entities/index.js +399 -0
- package/dist/server/entities/index.js.map +1 -0
- package/dist/server/entities/invitations.d.ts +241 -0
- package/dist/server/entities/invitations.js +181 -0
- package/dist/server/entities/invitations.js.map +1 -0
- package/dist/server/entities/permissions.d.ts +196 -0
- package/dist/server/entities/permissions.js +44 -0
- package/dist/server/entities/permissions.js.map +1 -0
- package/dist/server/entities/role-permissions.d.ts +107 -0
- package/dist/server/entities/role-permissions.js +112 -0
- package/dist/server/entities/role-permissions.js.map +1 -0
- package/dist/server/entities/roles.d.ts +196 -0
- package/dist/server/entities/roles.js +45 -0
- package/dist/server/entities/roles.js.map +1 -0
- package/dist/server/entities/user-permissions.d.ts +163 -0
- package/dist/server/entities/user-permissions.js +191 -0
- package/dist/server/entities/user-permissions.js.map +1 -0
- package/dist/server/entities/user-public-keys.d.ts +227 -0
- package/dist/server/entities/user-public-keys.js +153 -0
- package/dist/server/entities/user-public-keys.js.map +1 -0
- package/dist/server/entities/user-social-accounts.d.ts +189 -0
- package/dist/server/entities/user-social-accounts.js +146 -0
- package/dist/server/entities/user-social-accounts.js.map +1 -0
- package/dist/server/entities/users.d.ts +235 -0
- package/dist/server/entities/users.js +113 -0
- package/dist/server/entities/users.js.map +1 -0
- package/dist/server/entities/verification-codes.d.ts +191 -0
- package/dist/server/entities/verification-codes.js +44 -0
- package/dist/server/entities/verification-codes.js.map +1 -0
- package/dist/server/routes/auth/index.d.ts +10 -0
- package/dist/server/routes/auth/index.js +4475 -0
- package/dist/server/routes/auth/index.js.map +1 -0
- package/dist/server/routes/index.d.ts +6 -0
- package/dist/server/routes/index.js +6352 -0
- package/dist/server/routes/index.js.map +1 -0
- package/dist/server/routes/invitations/index.d.ts +10 -0
- package/dist/server/routes/invitations/index.js +4209 -0
- package/dist/server/routes/invitations/index.js.map +1 -0
- package/dist/server.d.ts +1243 -0
- package/dist/server.js +2281 -0
- package/dist/server.js.map +1 -0
- package/migrations/0000_tired_gambit.sql +165 -0
- package/migrations/meta/0000_snapshot.json +1395 -0
- package/migrations/meta/_journal.json +13 -0
- package/package.json +32 -24
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
CREATE TABLE "spfn_auth"."users" (
|
|
2
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
3
|
+
"email" text,
|
|
4
|
+
"phone" text,
|
|
5
|
+
"password_hash" text,
|
|
6
|
+
"password_change_required" boolean DEFAULT false NOT NULL,
|
|
7
|
+
"role_id" bigint NOT NULL,
|
|
8
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
9
|
+
"email_verified_at" timestamp with time zone,
|
|
10
|
+
"phone_verified_at" timestamp with time zone,
|
|
11
|
+
"last_login_at" timestamp with time zone,
|
|
12
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
13
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
14
|
+
CONSTRAINT "users_email_unique" UNIQUE("email"),
|
|
15
|
+
CONSTRAINT "users_phone_unique" UNIQUE("phone"),
|
|
16
|
+
CONSTRAINT "email_or_phone_check" CHECK ("spfn_auth"."users"."email" IS NOT NULL OR "spfn_auth"."users"."phone" IS NOT NULL)
|
|
17
|
+
);
|
|
18
|
+
--> statement-breakpoint
|
|
19
|
+
CREATE TABLE "spfn_auth"."user_social_accounts" (
|
|
20
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
21
|
+
"user_id" bigserial NOT NULL,
|
|
22
|
+
"provider" text NOT NULL,
|
|
23
|
+
"provider_user_id" text NOT NULL,
|
|
24
|
+
"provider_email" text,
|
|
25
|
+
"access_token" text,
|
|
26
|
+
"refresh_token" text,
|
|
27
|
+
"token_expires_at" timestamp with time zone,
|
|
28
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
29
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
30
|
+
);
|
|
31
|
+
--> statement-breakpoint
|
|
32
|
+
CREATE TABLE "spfn_auth"."user_public_keys" (
|
|
33
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
34
|
+
"user_id" bigserial NOT NULL,
|
|
35
|
+
"key_id" text NOT NULL,
|
|
36
|
+
"public_key" text NOT NULL,
|
|
37
|
+
"algorithm" text DEFAULT 'ES256' NOT NULL,
|
|
38
|
+
"fingerprint" text NOT NULL,
|
|
39
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
40
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
41
|
+
"last_used_at" timestamp with time zone,
|
|
42
|
+
"expires_at" timestamp with time zone,
|
|
43
|
+
"revoked_at" timestamp with time zone,
|
|
44
|
+
"revoked_reason" text,
|
|
45
|
+
CONSTRAINT "user_public_keys_key_id_unique" UNIQUE("key_id")
|
|
46
|
+
);
|
|
47
|
+
--> statement-breakpoint
|
|
48
|
+
CREATE TABLE "spfn_auth"."verification_codes" (
|
|
49
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
50
|
+
"target" text NOT NULL,
|
|
51
|
+
"target_type" text NOT NULL,
|
|
52
|
+
"code" text NOT NULL,
|
|
53
|
+
"purpose" text NOT NULL,
|
|
54
|
+
"expires_at" timestamp with time zone NOT NULL,
|
|
55
|
+
"used_at" timestamp with time zone,
|
|
56
|
+
"attempts" text DEFAULT '0' NOT NULL,
|
|
57
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
58
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
59
|
+
);
|
|
60
|
+
--> statement-breakpoint
|
|
61
|
+
CREATE TABLE "spfn_auth"."user_invitations" (
|
|
62
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
63
|
+
"email" text NOT NULL,
|
|
64
|
+
"token" text NOT NULL,
|
|
65
|
+
"role_id" bigint NOT NULL,
|
|
66
|
+
"invited_by" bigint NOT NULL,
|
|
67
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
68
|
+
"expires_at" timestamp with time zone NOT NULL,
|
|
69
|
+
"accepted_at" timestamp with time zone,
|
|
70
|
+
"cancelled_at" timestamp with time zone,
|
|
71
|
+
"metadata" jsonb,
|
|
72
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
73
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
74
|
+
CONSTRAINT "user_invitations_token_unique" UNIQUE("token")
|
|
75
|
+
);
|
|
76
|
+
--> statement-breakpoint
|
|
77
|
+
CREATE TABLE "spfn_auth"."roles" (
|
|
78
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
79
|
+
"name" text NOT NULL,
|
|
80
|
+
"display_name" text NOT NULL,
|
|
81
|
+
"description" text,
|
|
82
|
+
"is_builtin" boolean DEFAULT false NOT NULL,
|
|
83
|
+
"is_system" boolean DEFAULT false NOT NULL,
|
|
84
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
85
|
+
"priority" integer DEFAULT 10 NOT NULL,
|
|
86
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
87
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
88
|
+
CONSTRAINT "roles_name_unique" UNIQUE("name")
|
|
89
|
+
);
|
|
90
|
+
--> statement-breakpoint
|
|
91
|
+
CREATE TABLE "spfn_auth"."permissions" (
|
|
92
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
93
|
+
"name" text NOT NULL,
|
|
94
|
+
"display_name" text NOT NULL,
|
|
95
|
+
"description" text,
|
|
96
|
+
"category" text,
|
|
97
|
+
"is_builtin" boolean DEFAULT false NOT NULL,
|
|
98
|
+
"is_system" boolean DEFAULT false NOT NULL,
|
|
99
|
+
"is_active" boolean DEFAULT true NOT NULL,
|
|
100
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
101
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
102
|
+
CONSTRAINT "permissions_name_unique" UNIQUE("name")
|
|
103
|
+
);
|
|
104
|
+
--> statement-breakpoint
|
|
105
|
+
CREATE TABLE "spfn_auth"."role_permissions" (
|
|
106
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
107
|
+
"role_id" bigint NOT NULL,
|
|
108
|
+
"permission_id" bigint NOT NULL,
|
|
109
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
110
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
111
|
+
CONSTRAINT "role_permissions_unique" UNIQUE("role_id","permission_id")
|
|
112
|
+
);
|
|
113
|
+
--> statement-breakpoint
|
|
114
|
+
CREATE TABLE "spfn_auth"."user_permissions" (
|
|
115
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
116
|
+
"user_id" bigint NOT NULL,
|
|
117
|
+
"permission_id" bigint NOT NULL,
|
|
118
|
+
"granted" boolean DEFAULT true NOT NULL,
|
|
119
|
+
"reason" text,
|
|
120
|
+
"expires_at" timestamp with time zone,
|
|
121
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
122
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
123
|
+
CONSTRAINT "user_permissions_unique" UNIQUE("user_id","permission_id")
|
|
124
|
+
);
|
|
125
|
+
--> statement-breakpoint
|
|
126
|
+
ALTER TABLE "spfn_auth"."users" ADD CONSTRAINT "users_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
127
|
+
ALTER TABLE "spfn_auth"."user_social_accounts" ADD CONSTRAINT "user_social_accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
128
|
+
ALTER TABLE "spfn_auth"."user_public_keys" ADD CONSTRAINT "user_public_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
129
|
+
ALTER TABLE "spfn_auth"."user_invitations" ADD CONSTRAINT "user_invitations_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
130
|
+
ALTER TABLE "spfn_auth"."user_invitations" ADD CONSTRAINT "user_invitations_invited_by_users_id_fk" FOREIGN KEY ("invited_by") REFERENCES "spfn_auth"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
131
|
+
ALTER TABLE "spfn_auth"."role_permissions" ADD CONSTRAINT "role_permissions_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
132
|
+
ALTER TABLE "spfn_auth"."role_permissions" ADD CONSTRAINT "role_permissions_permission_id_permissions_id_fk" FOREIGN KEY ("permission_id") REFERENCES "spfn_auth"."permissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
133
|
+
ALTER TABLE "spfn_auth"."user_permissions" ADD CONSTRAINT "user_permissions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
134
|
+
ALTER TABLE "spfn_auth"."user_permissions" ADD CONSTRAINT "user_permissions_permission_id_permissions_id_fk" FOREIGN KEY ("permission_id") REFERENCES "spfn_auth"."permissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
135
|
+
CREATE INDEX "users_email_idx" ON "spfn_auth"."users" USING btree ("email");--> statement-breakpoint
|
|
136
|
+
CREATE INDEX "users_phone_idx" ON "spfn_auth"."users" USING btree ("phone");--> statement-breakpoint
|
|
137
|
+
CREATE INDEX "users_status_idx" ON "spfn_auth"."users" USING btree ("status");--> statement-breakpoint
|
|
138
|
+
CREATE INDEX "users_role_id_idx" ON "spfn_auth"."users" USING btree ("role_id");--> statement-breakpoint
|
|
139
|
+
CREATE UNIQUE INDEX "provider_user_unique_idx" ON "spfn_auth"."user_social_accounts" USING btree ("provider","provider_user_id");--> statement-breakpoint
|
|
140
|
+
CREATE INDEX "user_public_keys_user_id_idx" ON "spfn_auth"."user_public_keys" USING btree ("user_id");--> statement-breakpoint
|
|
141
|
+
CREATE INDEX "user_public_keys_key_id_idx" ON "spfn_auth"."user_public_keys" USING btree ("key_id");--> statement-breakpoint
|
|
142
|
+
CREATE INDEX "user_public_keys_active_idx" ON "spfn_auth"."user_public_keys" USING btree ("is_active");--> statement-breakpoint
|
|
143
|
+
CREATE INDEX "user_public_keys_fingerprint_idx" ON "spfn_auth"."user_public_keys" USING btree ("fingerprint");--> statement-breakpoint
|
|
144
|
+
CREATE INDEX "target_purpose_idx" ON "spfn_auth"."verification_codes" USING btree ("target","purpose","expires_at");--> statement-breakpoint
|
|
145
|
+
CREATE INDEX "invitations_token_idx" ON "spfn_auth"."user_invitations" USING btree ("token");--> statement-breakpoint
|
|
146
|
+
CREATE INDEX "invitations_email_idx" ON "spfn_auth"."user_invitations" USING btree ("email");--> statement-breakpoint
|
|
147
|
+
CREATE INDEX "invitations_status_idx" ON "spfn_auth"."user_invitations" USING btree ("status");--> statement-breakpoint
|
|
148
|
+
CREATE INDEX "invitations_invited_by_idx" ON "spfn_auth"."user_invitations" USING btree ("invited_by");--> statement-breakpoint
|
|
149
|
+
CREATE INDEX "invitations_expires_at_idx" ON "spfn_auth"."user_invitations" USING btree ("expires_at");--> statement-breakpoint
|
|
150
|
+
CREATE INDEX "invitations_role_id_idx" ON "spfn_auth"."user_invitations" USING btree ("role_id");--> statement-breakpoint
|
|
151
|
+
CREATE INDEX "roles_name_idx" ON "spfn_auth"."roles" USING btree ("name");--> statement-breakpoint
|
|
152
|
+
CREATE INDEX "roles_is_system_idx" ON "spfn_auth"."roles" USING btree ("is_system");--> statement-breakpoint
|
|
153
|
+
CREATE INDEX "roles_is_active_idx" ON "spfn_auth"."roles" USING btree ("is_active");--> statement-breakpoint
|
|
154
|
+
CREATE INDEX "roles_is_builtin_idx" ON "spfn_auth"."roles" USING btree ("is_builtin");--> statement-breakpoint
|
|
155
|
+
CREATE INDEX "roles_priority_idx" ON "spfn_auth"."roles" USING btree ("priority");--> statement-breakpoint
|
|
156
|
+
CREATE INDEX "permissions_name_idx" ON "spfn_auth"."permissions" USING btree ("name");--> statement-breakpoint
|
|
157
|
+
CREATE INDEX "permissions_category_idx" ON "spfn_auth"."permissions" USING btree ("category");--> statement-breakpoint
|
|
158
|
+
CREATE INDEX "permissions_is_system_idx" ON "spfn_auth"."permissions" USING btree ("is_system");--> statement-breakpoint
|
|
159
|
+
CREATE INDEX "permissions_is_active_idx" ON "spfn_auth"."permissions" USING btree ("is_active");--> statement-breakpoint
|
|
160
|
+
CREATE INDEX "permissions_is_builtin_idx" ON "spfn_auth"."permissions" USING btree ("is_builtin");--> statement-breakpoint
|
|
161
|
+
CREATE INDEX "role_permissions_role_id_idx" ON "spfn_auth"."role_permissions" USING btree ("role_id");--> statement-breakpoint
|
|
162
|
+
CREATE INDEX "role_permissions_permission_id_idx" ON "spfn_auth"."role_permissions" USING btree ("permission_id");--> statement-breakpoint
|
|
163
|
+
CREATE INDEX "user_permissions_user_id_idx" ON "spfn_auth"."user_permissions" USING btree ("user_id");--> statement-breakpoint
|
|
164
|
+
CREATE INDEX "user_permissions_permission_id_idx" ON "spfn_auth"."user_permissions" USING btree ("permission_id");--> statement-breakpoint
|
|
165
|
+
CREATE INDEX "user_permissions_expires_at_idx" ON "spfn_auth"."user_permissions" USING btree ("expires_at");
|