@productcraft/auth 0.8.0 → 0.8.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.
package/dist/index.d.cts CHANGED
@@ -156,7 +156,7 @@ declare class AuthHttpError<TData = unknown> extends Error {
156
156
  */
157
157
  type AuditLogEntryDto = {
158
158
  /**
159
- * @description Canonical action string (e.g. `app.member.removed`, `role.created`).
159
+ * @description Canonical action string (e.g. `app.member.removed`, `role.created`). Account deletions: `auth.account.deleted` (one row per account, written in the deleting transaction; `resource` is `account`, `resource_id` the deleted account id, `metadata` `{ via, username, email_domain, created_at, verified }` where `via` is `platform`, `platform_bulk`, `consumer_admin` or `self`, plus `selection` (`{ mode, filter? }`) on bulk rows) and `auth.account.expired_unverified` (the unverified-account expiry job).
160
160
  * @type string
161
161
  */
162
162
  action: string;
@@ -981,6 +981,48 @@ type EndUserInviteListResponseDto = {
981
981
  * Generated by Kubb (https://kubb.dev/).
982
982
  * Do not edit manually.
983
983
  */
984
+ declare const botProtectionResponseDtoProviderEnum: {
985
+ readonly turnstile: "turnstile";
986
+ readonly hcaptcha: "hcaptcha";
987
+ };
988
+ type BotProtectionResponseDtoProviderEnumKey = (typeof botProtectionResponseDtoProviderEnum)[keyof typeof botProtectionResponseDtoProviderEnum];
989
+ type BotProtectionResponseDto = {
990
+ /**
991
+ * @description Whether sign-up requires a verified token.
992
+ * @type boolean
993
+ */
994
+ enabled: boolean;
995
+ /**
996
+ * @description Hostnames a solved challenge must come from. Empty = any.
997
+ * @type array
998
+ */
999
+ expected_hostnames: string[];
1000
+ /**
1001
+ * @type string
1002
+ */
1003
+ provider: BotProtectionResponseDtoProviderEnumKey;
1004
+ /**
1005
+ * @description Last four characters of the stored secret, so you can tell which one it is. null when none is stored.
1006
+ * @type string
1007
+ */
1008
+ secret_last4: string | null;
1009
+ /**
1010
+ * @description Whether a provider secret is stored. The secret itself is never returned.
1011
+ * @type boolean
1012
+ */
1013
+ secret_set: boolean;
1014
+ /**
1015
+ * @description Public widget site key.
1016
+ * @type string
1017
+ */
1018
+ site_key: string;
1019
+ };
1020
+
1021
+ /**
1022
+ * Generated by Kubb (https://kubb.dev/).
1023
+ * Do not edit manually.
1024
+ */
1025
+
984
1026
  declare const authConfigResponseDtoMfaEnum: {
985
1027
  readonly optional: "optional";
986
1028
  readonly required: "required";
@@ -1007,6 +1049,10 @@ type AuthConfigResponseDto = {
1007
1049
  * @type array
1008
1050
  */
1009
1051
  allowed_redirect_origins: string[];
1052
+ /**
1053
+ * @description Sign-up bot protection; null when not configured.
1054
+ */
1055
+ bot_protection: BotProtectionResponseDto | null;
1010
1056
  /**
1011
1057
  * @type boolean
1012
1058
  */
@@ -1071,6 +1117,18 @@ type AuthConfigResponseDto = {
1071
1117
  * @type boolean
1072
1118
  */
1073
1119
  signup_enabled: boolean;
1120
+ /**
1121
+ * @description When true, sign-up requires a Platform API Key from this app\'s workspace (anonymous sign-ups get 401).
1122
+ * @type boolean
1123
+ */
1124
+ signup_requires_pak: boolean;
1125
+ /**
1126
+ * @description Days an account may keep an unverified primary email before it is deleted. null = never.
1127
+ * @minLength 1
1128
+ * @maxLength 90
1129
+ * @type number
1130
+ */
1131
+ unverified_account_ttl_days: number | null;
1074
1132
  };
1075
1133
 
1076
1134
  /**
@@ -1133,6 +1191,46 @@ type UpdateAppStatusDto = {
1133
1191
  * Generated by Kubb (https://kubb.dev/).
1134
1192
  * Do not edit manually.
1135
1193
  */
1194
+ declare const updateBotProtectionDtoProviderEnum: {
1195
+ readonly turnstile: "turnstile";
1196
+ readonly hcaptcha: "hcaptcha";
1197
+ };
1198
+ type UpdateBotProtectionDtoProviderEnumKey = (typeof updateBotProtectionDtoProviderEnum)[keyof typeof updateBotProtectionDtoProviderEnum];
1199
+ type UpdateBotProtectionDto = {
1200
+ /**
1201
+ * @description When true, every sign-up on this app must carry a `bot_protection_token` the provider accepts. Needs a stored secret. Takes effect within seconds.
1202
+ * @type boolean | undefined
1203
+ */
1204
+ enabled?: boolean;
1205
+ /**
1206
+ * @description Hostnames the solved challenge must come from, as the provider reports them (exact match, no scheme, port or path). Empty (default) accepts any hostname the site key allows. Send null or [] to clear.
1207
+ * @type array
1208
+ */
1209
+ expected_hostnames?: string[] | null;
1210
+ /**
1211
+ * @description Which CAPTCHA the app\'s sign-up form renders: Cloudflare Turnstile or hCaptcha. Required the first time the block is configured. Changing it without sending a new `secret` clears the stored secret, which belonged to the other provider.
1212
+ * @type string | undefined
1213
+ */
1214
+ provider?: UpdateBotProtectionDtoProviderEnumKey;
1215
+ /**
1216
+ * @description The provider secret Auth verifies tokens with. WRITE-ONLY: no response ever returns it (GET shows `secret_set` and the last four characters). Send a string to store or replace it, null to clear it, or leave it out to keep the stored one. Stored encrypted.
1217
+ * @maxLength 512
1218
+ * @type string
1219
+ */
1220
+ secret?: string | null;
1221
+ /**
1222
+ * @description The public site key your sign-up page renders the widget with. Not a secret. Required the first time the block is configured.
1223
+ * @maxLength 256
1224
+ * @type string | undefined
1225
+ */
1226
+ site_key?: string;
1227
+ };
1228
+
1229
+ /**
1230
+ * Generated by Kubb (https://kubb.dev/).
1231
+ * Do not edit manually.
1232
+ */
1233
+
1136
1234
  declare const updateAuthConfigDtoMfaEnum: {
1137
1235
  readonly optional: "optional";
1138
1236
  readonly required: "required";
@@ -1163,6 +1261,10 @@ type UpdateAuthConfigDto = {
1163
1261
  * @type array | undefined
1164
1262
  */
1165
1263
  allowed_redirect_origins?: string[];
1264
+ /**
1265
+ * @description Sign-up bot protection (Cloudflare Turnstile or hCaptcha). Fields you send are merged onto the stored block; send null to remove the block and its secret. While `enabled`, sign-up requires a `bot_protection_token` the provider accepts, checked before anything else, and fails closed (503) when the provider cannot be reached.
1266
+ */
1267
+ bot_protection?: UpdateBotProtectionDto | null;
1166
1268
  /**
1167
1269
  * @description When true, Consumer-API routes annotated with `@RequireAppPermission(perm)` enforce the requested perm against the EndUser\'s role-resolved permission set. When false (default), permission checks are bypassed — any valid token can call any annotated route. Flip on once you\'ve authored roles + permissions for this app and want them to actually mean something.
1168
1270
  * @type boolean | undefined
@@ -1253,6 +1355,18 @@ type UpdateAuthConfigDto = {
1253
1355
  * @type boolean | undefined
1254
1356
  */
1255
1357
  signup_enabled?: boolean;
1358
+ /**
1359
+ * @description When true, sign-up only works from your backend: every `POST /{app_slug}/v1/auth/signup` must carry a Platform API Key (`Authorization: Bearer pcft_live_…`) from this app\'s workspace whose policy allows `auth.signup.create` on this app. Anonymous sign-ups get 401. Use it when your own backend gates sign-ups (CAPTCHA, invite or payment checks). Independent of `bot_protection`; an app can use both. Turning it on for an app that has no workspace is refused with 409.
1360
+ * @type boolean | undefined
1361
+ */
1362
+ signup_requires_pak?: boolean;
1363
+ /**
1364
+ * @description Delete accounts whose primary email is still unverified this many days after sign-up. Only self-sign-ups that never signed in after sign-up, hold no two-step factor, no verified contact and no social login qualify. Deletion is permanent, frees the email address and username, is audited as `auth.account.expired_unverified` and fires `user.deleted` with `reason: \"unverified_expired\"`. Send null to never delete. New apps start at 7; apps created before this setting existed start at null.
1365
+ * @minLength 1
1366
+ * @maxLength 90
1367
+ * @type number
1368
+ */
1369
+ unverified_account_ttl_days?: number | null;
1256
1370
  };
1257
1371
 
1258
1372
  /**
@@ -1306,6 +1420,13 @@ type UpdateEndUserDto = {
1306
1420
  * @type string | undefined
1307
1421
  */
1308
1422
  email?: string;
1423
+ /**
1424
+ * @description Keys to merge into the end-user\'s metadata (shallow; a key set to null is removed; at most 8 KB stored). Set `app_active: true` to mark someone who uses your app: the unverified-account expiry never deletes an account carrying it.
1425
+ * @type object | undefined
1426
+ */
1427
+ metadata?: {
1428
+ [key: string]: any;
1429
+ };
1309
1430
  };
1310
1431
 
1311
1432
  /**
@@ -2142,6 +2263,12 @@ type ConsumerAuthControllerSignin200 = ConsumerTokenResponseDto | ConsumerMfaCha
2142
2263
  * Do not edit manually.
2143
2264
  */
2144
2265
  type ConsumerSignupDto = {
2266
+ /**
2267
+ * @description The response token from the app\'s bot-protection widget (Cloudflare Turnstile or hCaptcha). Required when the app has bot protection switched on (`auth_config.bot_protection.enabled`); ignored otherwise. Auth verifies it with the provider before anything else about the sign-up is looked at. Tokens are single-use and expire after a few minutes, so render a fresh widget for every attempt. A backend that signs users up with a Platform API Key forwards the token its browser received.
2268
+ * @maxLength 2048
2269
+ * @type string | undefined
2270
+ */
2271
+ bot_protection_token?: string;
2145
2272
  /**
2146
2273
  * @description Optional display name shown back to the user.
2147
2274
  * @type string | undefined
package/dist/index.d.ts CHANGED
@@ -156,7 +156,7 @@ declare class AuthHttpError<TData = unknown> extends Error {
156
156
  */
157
157
  type AuditLogEntryDto = {
158
158
  /**
159
- * @description Canonical action string (e.g. `app.member.removed`, `role.created`).
159
+ * @description Canonical action string (e.g. `app.member.removed`, `role.created`). Account deletions: `auth.account.deleted` (one row per account, written in the deleting transaction; `resource` is `account`, `resource_id` the deleted account id, `metadata` `{ via, username, email_domain, created_at, verified }` where `via` is `platform`, `platform_bulk`, `consumer_admin` or `self`, plus `selection` (`{ mode, filter? }`) on bulk rows) and `auth.account.expired_unverified` (the unverified-account expiry job).
160
160
  * @type string
161
161
  */
162
162
  action: string;
@@ -981,6 +981,48 @@ type EndUserInviteListResponseDto = {
981
981
  * Generated by Kubb (https://kubb.dev/).
982
982
  * Do not edit manually.
983
983
  */
984
+ declare const botProtectionResponseDtoProviderEnum: {
985
+ readonly turnstile: "turnstile";
986
+ readonly hcaptcha: "hcaptcha";
987
+ };
988
+ type BotProtectionResponseDtoProviderEnumKey = (typeof botProtectionResponseDtoProviderEnum)[keyof typeof botProtectionResponseDtoProviderEnum];
989
+ type BotProtectionResponseDto = {
990
+ /**
991
+ * @description Whether sign-up requires a verified token.
992
+ * @type boolean
993
+ */
994
+ enabled: boolean;
995
+ /**
996
+ * @description Hostnames a solved challenge must come from. Empty = any.
997
+ * @type array
998
+ */
999
+ expected_hostnames: string[];
1000
+ /**
1001
+ * @type string
1002
+ */
1003
+ provider: BotProtectionResponseDtoProviderEnumKey;
1004
+ /**
1005
+ * @description Last four characters of the stored secret, so you can tell which one it is. null when none is stored.
1006
+ * @type string
1007
+ */
1008
+ secret_last4: string | null;
1009
+ /**
1010
+ * @description Whether a provider secret is stored. The secret itself is never returned.
1011
+ * @type boolean
1012
+ */
1013
+ secret_set: boolean;
1014
+ /**
1015
+ * @description Public widget site key.
1016
+ * @type string
1017
+ */
1018
+ site_key: string;
1019
+ };
1020
+
1021
+ /**
1022
+ * Generated by Kubb (https://kubb.dev/).
1023
+ * Do not edit manually.
1024
+ */
1025
+
984
1026
  declare const authConfigResponseDtoMfaEnum: {
985
1027
  readonly optional: "optional";
986
1028
  readonly required: "required";
@@ -1007,6 +1049,10 @@ type AuthConfigResponseDto = {
1007
1049
  * @type array
1008
1050
  */
1009
1051
  allowed_redirect_origins: string[];
1052
+ /**
1053
+ * @description Sign-up bot protection; null when not configured.
1054
+ */
1055
+ bot_protection: BotProtectionResponseDto | null;
1010
1056
  /**
1011
1057
  * @type boolean
1012
1058
  */
@@ -1071,6 +1117,18 @@ type AuthConfigResponseDto = {
1071
1117
  * @type boolean
1072
1118
  */
1073
1119
  signup_enabled: boolean;
1120
+ /**
1121
+ * @description When true, sign-up requires a Platform API Key from this app\'s workspace (anonymous sign-ups get 401).
1122
+ * @type boolean
1123
+ */
1124
+ signup_requires_pak: boolean;
1125
+ /**
1126
+ * @description Days an account may keep an unverified primary email before it is deleted. null = never.
1127
+ * @minLength 1
1128
+ * @maxLength 90
1129
+ * @type number
1130
+ */
1131
+ unverified_account_ttl_days: number | null;
1074
1132
  };
1075
1133
 
1076
1134
  /**
@@ -1133,6 +1191,46 @@ type UpdateAppStatusDto = {
1133
1191
  * Generated by Kubb (https://kubb.dev/).
1134
1192
  * Do not edit manually.
1135
1193
  */
1194
+ declare const updateBotProtectionDtoProviderEnum: {
1195
+ readonly turnstile: "turnstile";
1196
+ readonly hcaptcha: "hcaptcha";
1197
+ };
1198
+ type UpdateBotProtectionDtoProviderEnumKey = (typeof updateBotProtectionDtoProviderEnum)[keyof typeof updateBotProtectionDtoProviderEnum];
1199
+ type UpdateBotProtectionDto = {
1200
+ /**
1201
+ * @description When true, every sign-up on this app must carry a `bot_protection_token` the provider accepts. Needs a stored secret. Takes effect within seconds.
1202
+ * @type boolean | undefined
1203
+ */
1204
+ enabled?: boolean;
1205
+ /**
1206
+ * @description Hostnames the solved challenge must come from, as the provider reports them (exact match, no scheme, port or path). Empty (default) accepts any hostname the site key allows. Send null or [] to clear.
1207
+ * @type array
1208
+ */
1209
+ expected_hostnames?: string[] | null;
1210
+ /**
1211
+ * @description Which CAPTCHA the app\'s sign-up form renders: Cloudflare Turnstile or hCaptcha. Required the first time the block is configured. Changing it without sending a new `secret` clears the stored secret, which belonged to the other provider.
1212
+ * @type string | undefined
1213
+ */
1214
+ provider?: UpdateBotProtectionDtoProviderEnumKey;
1215
+ /**
1216
+ * @description The provider secret Auth verifies tokens with. WRITE-ONLY: no response ever returns it (GET shows `secret_set` and the last four characters). Send a string to store or replace it, null to clear it, or leave it out to keep the stored one. Stored encrypted.
1217
+ * @maxLength 512
1218
+ * @type string
1219
+ */
1220
+ secret?: string | null;
1221
+ /**
1222
+ * @description The public site key your sign-up page renders the widget with. Not a secret. Required the first time the block is configured.
1223
+ * @maxLength 256
1224
+ * @type string | undefined
1225
+ */
1226
+ site_key?: string;
1227
+ };
1228
+
1229
+ /**
1230
+ * Generated by Kubb (https://kubb.dev/).
1231
+ * Do not edit manually.
1232
+ */
1233
+
1136
1234
  declare const updateAuthConfigDtoMfaEnum: {
1137
1235
  readonly optional: "optional";
1138
1236
  readonly required: "required";
@@ -1163,6 +1261,10 @@ type UpdateAuthConfigDto = {
1163
1261
  * @type array | undefined
1164
1262
  */
1165
1263
  allowed_redirect_origins?: string[];
1264
+ /**
1265
+ * @description Sign-up bot protection (Cloudflare Turnstile or hCaptcha). Fields you send are merged onto the stored block; send null to remove the block and its secret. While `enabled`, sign-up requires a `bot_protection_token` the provider accepts, checked before anything else, and fails closed (503) when the provider cannot be reached.
1266
+ */
1267
+ bot_protection?: UpdateBotProtectionDto | null;
1166
1268
  /**
1167
1269
  * @description When true, Consumer-API routes annotated with `@RequireAppPermission(perm)` enforce the requested perm against the EndUser\'s role-resolved permission set. When false (default), permission checks are bypassed — any valid token can call any annotated route. Flip on once you\'ve authored roles + permissions for this app and want them to actually mean something.
1168
1270
  * @type boolean | undefined
@@ -1253,6 +1355,18 @@ type UpdateAuthConfigDto = {
1253
1355
  * @type boolean | undefined
1254
1356
  */
1255
1357
  signup_enabled?: boolean;
1358
+ /**
1359
+ * @description When true, sign-up only works from your backend: every `POST /{app_slug}/v1/auth/signup` must carry a Platform API Key (`Authorization: Bearer pcft_live_…`) from this app\'s workspace whose policy allows `auth.signup.create` on this app. Anonymous sign-ups get 401. Use it when your own backend gates sign-ups (CAPTCHA, invite or payment checks). Independent of `bot_protection`; an app can use both. Turning it on for an app that has no workspace is refused with 409.
1360
+ * @type boolean | undefined
1361
+ */
1362
+ signup_requires_pak?: boolean;
1363
+ /**
1364
+ * @description Delete accounts whose primary email is still unverified this many days after sign-up. Only self-sign-ups that never signed in after sign-up, hold no two-step factor, no verified contact and no social login qualify. Deletion is permanent, frees the email address and username, is audited as `auth.account.expired_unverified` and fires `user.deleted` with `reason: \"unverified_expired\"`. Send null to never delete. New apps start at 7; apps created before this setting existed start at null.
1365
+ * @minLength 1
1366
+ * @maxLength 90
1367
+ * @type number
1368
+ */
1369
+ unverified_account_ttl_days?: number | null;
1256
1370
  };
1257
1371
 
1258
1372
  /**
@@ -1306,6 +1420,13 @@ type UpdateEndUserDto = {
1306
1420
  * @type string | undefined
1307
1421
  */
1308
1422
  email?: string;
1423
+ /**
1424
+ * @description Keys to merge into the end-user\'s metadata (shallow; a key set to null is removed; at most 8 KB stored). Set `app_active: true` to mark someone who uses your app: the unverified-account expiry never deletes an account carrying it.
1425
+ * @type object | undefined
1426
+ */
1427
+ metadata?: {
1428
+ [key: string]: any;
1429
+ };
1309
1430
  };
1310
1431
 
1311
1432
  /**
@@ -2142,6 +2263,12 @@ type ConsumerAuthControllerSignin200 = ConsumerTokenResponseDto | ConsumerMfaCha
2142
2263
  * Do not edit manually.
2143
2264
  */
2144
2265
  type ConsumerSignupDto = {
2266
+ /**
2267
+ * @description The response token from the app\'s bot-protection widget (Cloudflare Turnstile or hCaptcha). Required when the app has bot protection switched on (`auth_config.bot_protection.enabled`); ignored otherwise. Auth verifies it with the provider before anything else about the sign-up is looked at. Tokens are single-use and expire after a few minutes, so render a fresh widget for every attempt. A backend that signs users up with a Platform API Key forwards the token its browser received.
2268
+ * @maxLength 2048
2269
+ * @type string | undefined
2270
+ */
2271
+ bot_protection_token?: string;
2145
2272
  /**
2146
2273
  * @description Optional display name shown back to the user.
2147
2274
  * @type string | undefined