@smartcrab/contracts-public 0.3.2 → 0.4.0-next-20261017141739
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/adaptive.d.ts +36 -0
- package/dist/adaptive.js +28 -0
- package/dist/email.d.ts +2 -0
- package/dist/email.js +3 -0
- package/dist/identity-linking.d.ts +13 -0
- package/dist/identity-linking.js +12 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/me.d.ts +5 -4
- package/dist/me.js +6 -4
- package/dist/passkeys.d.ts +1 -0
- package/dist/passkeys.js +2 -0
- package/dist/recovery.d.ts +12 -0
- package/dist/recovery.js +10 -0
- package/dist/social.d.ts +5 -3
- package/dist/social.js +6 -3
- package/package.json +3 -3
- package/src/adaptive.test.ts +63 -0
- package/src/adaptive.ts +39 -0
- package/src/email.ts +3 -0
- package/src/identity-linking.ts +17 -0
- package/src/index.ts +3 -0
- package/src/me.ts +6 -4
- package/src/passkeys.ts +2 -0
- package/src/recovery.ts +14 -0
- package/src/social.ts +6 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Turnstile proof is accepted only on the same factor-initiation request that received a challenge. */
|
|
3
|
+
export declare const adaptiveChallengeTokenSchema: z.ZodString;
|
|
4
|
+
export declare const adaptiveChallengeActionSchema: z.ZodEnum<{
|
|
5
|
+
email_start: "email_start";
|
|
6
|
+
email_resend: "email_resend";
|
|
7
|
+
passkey_auth_options: "passkey_auth_options";
|
|
8
|
+
social_start: "social_start";
|
|
9
|
+
}>;
|
|
10
|
+
export type AdaptiveChallengeAction = z.infer<typeof adaptiveChallengeActionSchema>;
|
|
11
|
+
/** RFC 9457 Problem Details returned before a factor-initiation side effect. */
|
|
12
|
+
export declare const adaptiveChallengeRequiredResponseSchema: z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-required">;
|
|
14
|
+
title: z.ZodLiteral<"Forbidden">;
|
|
15
|
+
status: z.ZodLiteral<403>;
|
|
16
|
+
code: z.ZodLiteral<"adaptive_challenge_required">;
|
|
17
|
+
request_id: z.ZodOptional<z.ZodString>;
|
|
18
|
+
challenge_id: z.ZodString;
|
|
19
|
+
site_key: z.ZodString;
|
|
20
|
+
action: z.ZodEnum<{
|
|
21
|
+
email_start: "email_start";
|
|
22
|
+
email_resend: "email_resend";
|
|
23
|
+
passkey_auth_options: "passkey_auth_options";
|
|
24
|
+
social_start: "social_start";
|
|
25
|
+
}>;
|
|
26
|
+
transaction_id: z.ZodString;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export type AdaptiveChallengeRequiredResponse = z.infer<typeof adaptiveChallengeRequiredResponseSchema>;
|
|
29
|
+
export declare const adaptiveChallengeUnavailableResponseSchema: z.ZodObject<{
|
|
30
|
+
type: z.ZodLiteral<"https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-unavailable">;
|
|
31
|
+
title: z.ZodLiteral<"Service Unavailable">;
|
|
32
|
+
status: z.ZodLiteral<503>;
|
|
33
|
+
code: z.ZodLiteral<"adaptive_challenge_unavailable">;
|
|
34
|
+
request_id: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export type AdaptiveChallengeUnavailableResponse = z.infer<typeof adaptiveChallengeUnavailableResponseSchema>;
|
package/dist/adaptive.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Turnstile proof is accepted only on the same factor-initiation request that received a challenge. */
|
|
3
|
+
export const adaptiveChallengeTokenSchema = z.string().min(1).max(2048);
|
|
4
|
+
export const adaptiveChallengeActionSchema = z.enum([
|
|
5
|
+
"email_start",
|
|
6
|
+
"email_resend",
|
|
7
|
+
"passkey_auth_options",
|
|
8
|
+
"social_start",
|
|
9
|
+
]);
|
|
10
|
+
/** RFC 9457 Problem Details returned before a factor-initiation side effect. */
|
|
11
|
+
export const adaptiveChallengeRequiredResponseSchema = z.strictObject({
|
|
12
|
+
type: z.literal("https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-required"),
|
|
13
|
+
title: z.literal("Forbidden"),
|
|
14
|
+
status: z.literal(403),
|
|
15
|
+
code: z.literal("adaptive_challenge_required"),
|
|
16
|
+
request_id: z.string().optional(),
|
|
17
|
+
challenge_id: z.string().min(1),
|
|
18
|
+
site_key: z.string().min(1),
|
|
19
|
+
action: adaptiveChallengeActionSchema,
|
|
20
|
+
transaction_id: z.string().min(1),
|
|
21
|
+
});
|
|
22
|
+
export const adaptiveChallengeUnavailableResponseSchema = z.strictObject({
|
|
23
|
+
type: z.literal("https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-unavailable"),
|
|
24
|
+
title: z.literal("Service Unavailable"),
|
|
25
|
+
status: z.literal(503),
|
|
26
|
+
code: z.literal("adaptive_challenge_unavailable"),
|
|
27
|
+
request_id: z.string().optional(),
|
|
28
|
+
});
|
package/dist/email.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { z } from "zod";
|
|
|
16
16
|
*/
|
|
17
17
|
export declare const emailStartRequestSchema: z.ZodObject<{
|
|
18
18
|
email: z.ZodEmail;
|
|
19
|
+
challenge_token: z.ZodOptional<z.ZodString>;
|
|
19
20
|
}, z.core.$strict>;
|
|
20
21
|
export type EmailStartRequest = z.infer<typeof emailStartRequestSchema>;
|
|
21
22
|
export declare const emailChallengeResponseSchema: z.ZodObject<{
|
|
@@ -26,6 +27,7 @@ export type EmailChallengeResponse = z.infer<typeof emailChallengeResponseSchema
|
|
|
26
27
|
/** design.md §18.2: resend increments the generation and invalidates the prior code. */
|
|
27
28
|
export declare const emailResendRequestSchema: z.ZodObject<{
|
|
28
29
|
challenge_id: z.ZodString;
|
|
30
|
+
challenge_token: z.ZodOptional<z.ZodString>;
|
|
29
31
|
}, z.core.$strict>;
|
|
30
32
|
export type EmailResendRequest = z.infer<typeof emailResendRequestSchema>;
|
|
31
33
|
export declare const emailVerifyRequestSchema: z.ZodObject<{
|
package/dist/email.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { emailOtpCodeSchema, isoDateTimeSchema } from "./primitives.js";
|
|
3
|
+
import { adaptiveChallengeTokenSchema } from "./adaptive.js";
|
|
3
4
|
import { transactionAuthResultResponseSchema } from "./transaction-status.js";
|
|
4
5
|
/**
|
|
5
6
|
* Email OTP within an auth transaction (design.md §18).
|
|
@@ -18,6 +19,7 @@ import { transactionAuthResultResponseSchema } from "./transaction-status.js";
|
|
|
18
19
|
*/
|
|
19
20
|
export const emailStartRequestSchema = z.strictObject({
|
|
20
21
|
email: z.email(),
|
|
22
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
21
23
|
});
|
|
22
24
|
export const emailChallengeResponseSchema = z.strictObject({
|
|
23
25
|
challenge_id: z.string().min(1),
|
|
@@ -26,6 +28,7 @@ export const emailChallengeResponseSchema = z.strictObject({
|
|
|
26
28
|
/** design.md §18.2: resend increments the generation and invalidates the prior code. */
|
|
27
29
|
export const emailResendRequestSchema = z.strictObject({
|
|
28
30
|
challenge_id: z.string().min(1),
|
|
31
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
29
32
|
});
|
|
30
33
|
export const emailVerifyRequestSchema = z.strictObject({
|
|
31
34
|
challenge_id: z.string().min(1),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const identityLinkCodeChallengeSchema: z.ZodString;
|
|
3
|
+
export declare const identityLinkCodeVerifierSchema: z.ZodString;
|
|
4
|
+
export declare const identityLinkStateSchema: z.ZodString;
|
|
5
|
+
export declare const meIdentityLinkCompleteRequestSchema: z.ZodObject<{
|
|
6
|
+
code: z.ZodString;
|
|
7
|
+
code_verifier: z.ZodString;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
export type MeIdentityLinkCompleteRequest = z.infer<typeof meIdentityLinkCompleteRequestSchema>;
|
|
10
|
+
export declare const meIdentityLinkCompleteResponseSchema: z.ZodObject<{
|
|
11
|
+
identity_id: z.ZodString;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export type MeIdentityLinkCompleteResponse = z.infer<typeof meIdentityLinkCompleteResponseSchema>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { identityIdSchema } from "./primitives.js";
|
|
3
|
+
export const identityLinkCodeChallengeSchema = z.string().regex(/^[A-Za-z0-9_-]{43}$/);
|
|
4
|
+
export const identityLinkCodeVerifierSchema = z.string().regex(/^[A-Za-z0-9._~-]{43,128}$/);
|
|
5
|
+
export const identityLinkStateSchema = z.string().min(1).max(256);
|
|
6
|
+
export const meIdentityLinkCompleteRequestSchema = z.strictObject({
|
|
7
|
+
code: z.string().min(1).max(256),
|
|
8
|
+
code_verifier: identityLinkCodeVerifierSchema,
|
|
9
|
+
});
|
|
10
|
+
export const meIdentityLinkCompleteResponseSchema = z.strictObject({
|
|
11
|
+
identity_id: identityIdSchema,
|
|
12
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -19,5 +19,8 @@ export * from "./transactions.js";
|
|
|
19
19
|
export * from "./email.js";
|
|
20
20
|
export * from "./passkeys.js";
|
|
21
21
|
export * from "./social.js";
|
|
22
|
+
export * from "./adaptive.js";
|
|
23
|
+
export * from "./identity-linking.js";
|
|
24
|
+
export * from "./recovery.js";
|
|
22
25
|
export * from "./me.js";
|
|
23
26
|
export * from "./association-files.js";
|
package/dist/index.js
CHANGED
|
@@ -19,5 +19,8 @@ export * from "./transactions.js";
|
|
|
19
19
|
export * from "./email.js";
|
|
20
20
|
export * from "./passkeys.js";
|
|
21
21
|
export * from "./social.js";
|
|
22
|
+
export * from "./adaptive.js";
|
|
23
|
+
export * from "./identity-linking.js";
|
|
24
|
+
export * from "./recovery.js";
|
|
22
25
|
export * from "./me.js";
|
|
23
26
|
export * from "./association-files.js";
|
package/dist/me.d.ts
CHANGED
|
@@ -208,13 +208,14 @@ export declare const meIdentitiesListResponseSchema: z.ZodObject<{
|
|
|
208
208
|
}, z.core.$strict>;
|
|
209
209
|
export type MeIdentitiesListResponse = z.infer<typeof meIdentitiesListResponseSchema>;
|
|
210
210
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* link, not a public auth transaction, so it carries its own return
|
|
214
|
-
* target rather than one fixed at transaction-create time).
|
|
211
|
+
* The app-held verifier stays in the client. The server stores only its S256
|
|
212
|
+
* challenge, app state, and the exact registered return URI.
|
|
215
213
|
*/
|
|
216
214
|
export declare const meIdentityLinkRequestSchema: z.ZodObject<{
|
|
217
215
|
redirect_uri: z.ZodString;
|
|
216
|
+
code_challenge: z.ZodString;
|
|
217
|
+
code_challenge_method: z.ZodLiteral<"S256">;
|
|
218
|
+
state: z.ZodString;
|
|
218
219
|
}, z.core.$strict>;
|
|
219
220
|
export type MeIdentityLinkRequest = z.infer<typeof meIdentityLinkRequestSchema>;
|
|
220
221
|
/** Same shape as the transaction-scoped social start: a URL to open in the system browser. */
|
package/dist/me.js
CHANGED
|
@@ -3,6 +3,7 @@ import { emailChallengeResponseSchema } from "./email.js";
|
|
|
3
3
|
import { passkeyRegistrationOptionsRequestSchema, passkeyRegistrationOptionsResponseSchema, passkeyRegistrationVerifyRequestSchema, passkeySummarySchema, } from "./passkeys.js";
|
|
4
4
|
import { clientIdSchema, emailOtpCodeSchema, identityIdSchema, isoDateTimeSchema, passkeyIdSchema, redirectUriSchema, sessionIdSchema, userIdSchema, } from "./primitives.js";
|
|
5
5
|
import { socialProviderSchema, socialStartResponseSchema } from "./social.js";
|
|
6
|
+
import { identityLinkCodeChallengeSchema, identityLinkStateSchema } from "./identity-linking.js";
|
|
6
7
|
/**
|
|
7
8
|
* The authenticated self-service surface (design.md §16.2 route list). All
|
|
8
9
|
* responses here project persisted rows (design.md §12.1-§12.5) minus
|
|
@@ -71,13 +72,14 @@ export const meIdentitiesListResponseSchema = z.strictObject({
|
|
|
71
72
|
identities: z.array(meIdentitySummarySchema),
|
|
72
73
|
});
|
|
73
74
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* link, not a public auth transaction, so it carries its own return
|
|
77
|
-
* target rather than one fixed at transaction-create time).
|
|
75
|
+
* The app-held verifier stays in the client. The server stores only its S256
|
|
76
|
+
* challenge, app state, and the exact registered return URI.
|
|
78
77
|
*/
|
|
79
78
|
export const meIdentityLinkRequestSchema = z.strictObject({
|
|
80
79
|
redirect_uri: redirectUriSchema,
|
|
80
|
+
code_challenge: identityLinkCodeChallengeSchema,
|
|
81
|
+
code_challenge_method: z.literal("S256"),
|
|
82
|
+
state: identityLinkStateSchema,
|
|
81
83
|
});
|
|
82
84
|
/** Same shape as the transaction-scoped social start: a URL to open in the system browser. */
|
|
83
85
|
export const meIdentityLinkResponseSchema = socialStartResponseSchema;
|
package/dist/passkeys.d.ts
CHANGED
|
@@ -180,6 +180,7 @@ export declare const passkeyAuthenticationOptionsRequestSchema: z.ZodObject<{
|
|
|
180
180
|
legacy: "legacy";
|
|
181
181
|
}>>;
|
|
182
182
|
rp_id: z.ZodOptional<z.ZodString>;
|
|
183
|
+
challenge_token: z.ZodOptional<z.ZodString>;
|
|
183
184
|
}, z.core.$strict>;
|
|
184
185
|
export type PasskeyAuthenticationOptionsRequest = z.input<typeof passkeyAuthenticationOptionsRequestSchema>;
|
|
185
186
|
export declare const passkeyAuthenticationOptionsResponseSchema: z.ZodObject<{
|
package/dist/passkeys.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { adaptiveChallengeTokenSchema } from "./adaptive.js";
|
|
2
3
|
import { isoDateTimeSchema, passkeyIdSchema } from "./primitives.js";
|
|
3
4
|
import { transactionAuthResultResponseSchema } from "./transaction-status.js";
|
|
4
5
|
/**
|
|
@@ -125,6 +126,7 @@ export const passkeyAuthenticationOptionsRequestSchema = z
|
|
|
125
126
|
rp: passkeyAuthenticationRpSchema.optional(),
|
|
126
127
|
/** design.md §8.3: explicit RP ID; mutually exclusive with `rp`. */
|
|
127
128
|
rp_id: passkeyRpIdSchema.optional(),
|
|
129
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
128
130
|
})
|
|
129
131
|
.refine((body) => body.rp === undefined || body.rp_id === undefined, {
|
|
130
132
|
message: "rp and rp_id are mutually exclusive",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Explicit authenticated account recovery completion (design.md §25). */
|
|
3
|
+
export declare const meRecoveryCompleteRequestSchema: z.ZodObject<{
|
|
4
|
+
confirmed: z.ZodLiteral<true>;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
export type MeRecoveryCompleteRequest = z.infer<typeof meRecoveryCompleteRequestSchema>;
|
|
7
|
+
/** Recovery revokes every session; the caller must authenticate again. */
|
|
8
|
+
export declare const meRecoveryCompleteResponseSchema: z.ZodObject<{
|
|
9
|
+
recovered: z.ZodLiteral<true>;
|
|
10
|
+
reauthentication_required: z.ZodLiteral<true>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type MeRecoveryCompleteResponse = z.infer<typeof meRecoveryCompleteResponseSchema>;
|
package/dist/recovery.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Explicit authenticated account recovery completion (design.md §25). */
|
|
3
|
+
export const meRecoveryCompleteRequestSchema = z.strictObject({
|
|
4
|
+
confirmed: z.literal(true),
|
|
5
|
+
});
|
|
6
|
+
/** Recovery revokes every session; the caller must authenticate again. */
|
|
7
|
+
export const meRecoveryCompleteResponseSchema = z.strictObject({
|
|
8
|
+
recovered: z.literal(true),
|
|
9
|
+
reauthentication_required: z.literal(true),
|
|
10
|
+
});
|
package/dist/social.d.ts
CHANGED
|
@@ -16,11 +16,13 @@ export declare const socialProviderSchema: z.ZodEnum<{
|
|
|
16
16
|
}>;
|
|
17
17
|
export type SocialProvider = (typeof SOCIAL_PROVIDERS)[number];
|
|
18
18
|
/**
|
|
19
|
-
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` —
|
|
20
|
-
*
|
|
19
|
+
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` — an optional
|
|
20
|
+
* challenge proof; the transaction (scope, resource, redirect_uri) is already
|
|
21
21
|
* fixed by `POST /v1/auth/transactions`.
|
|
22
22
|
*/
|
|
23
|
-
export declare const socialStartRequestSchema: z.ZodObject<{
|
|
23
|
+
export declare const socialStartRequestSchema: z.ZodObject<{
|
|
24
|
+
challenge_token: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strict>;
|
|
24
26
|
export type SocialStartRequest = z.infer<typeof socialStartRequestSchema>;
|
|
25
27
|
/** The URL the client must navigate the system browser to (design.md §20.6: no embedded WebViews). */
|
|
26
28
|
export declare const socialStartResponseSchema: z.ZodObject<{
|
package/dist/social.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { adaptiveChallengeTokenSchema } from "./adaptive.js";
|
|
2
3
|
import { httpsUrlSchema, opaqueClientValueSchema } from "./primitives.js";
|
|
3
4
|
/**
|
|
4
5
|
* Social login providers (design.md §20.1). `passkey`/`email_otp` are the
|
|
@@ -10,11 +11,13 @@ import { httpsUrlSchema, opaqueClientValueSchema } from "./primitives.js";
|
|
|
10
11
|
export const SOCIAL_PROVIDERS = ["google", "apple", "github", "microsoft", "generic_oidc"];
|
|
11
12
|
export const socialProviderSchema = z.enum(SOCIAL_PROVIDERS);
|
|
12
13
|
/**
|
|
13
|
-
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` —
|
|
14
|
-
*
|
|
14
|
+
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` — an optional
|
|
15
|
+
* challenge proof; the transaction (scope, resource, redirect_uri) is already
|
|
15
16
|
* fixed by `POST /v1/auth/transactions`.
|
|
16
17
|
*/
|
|
17
|
-
export const socialStartRequestSchema = z.strictObject({
|
|
18
|
+
export const socialStartRequestSchema = z.strictObject({
|
|
19
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
20
|
+
});
|
|
18
21
|
/** The URL the client must navigate the system browser to (design.md §20.6: no embedded WebViews). */
|
|
19
22
|
export const socialStartResponseSchema = z.strictObject({
|
|
20
23
|
authorization_url: httpsUrlSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcrab/contracts-public",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-next-20261017141739",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"zod": "4.6.5",
|
|
31
|
-
"@smartcrab/
|
|
32
|
-
"@smartcrab/
|
|
31
|
+
"@smartcrab/tenant-context": "0.4.0-next-20261017141739",
|
|
32
|
+
"@smartcrab/identifiers": "0.4.0-next-20261017141739"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"typescript": "5.9.3",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
adaptiveChallengeRequiredResponseSchema,
|
|
4
|
+
adaptiveChallengeUnavailableResponseSchema,
|
|
5
|
+
} from "./adaptive.js";
|
|
6
|
+
import { emailResendRequestSchema, emailStartRequestSchema } from "./email.js";
|
|
7
|
+
import { passkeyAuthenticationOptionsRequestSchema } from "./passkeys.js";
|
|
8
|
+
import { socialStartRequestSchema } from "./social.js";
|
|
9
|
+
|
|
10
|
+
describe("adaptive challenge public contracts", () => {
|
|
11
|
+
it("accepts the typed 403 challenge response and rejects private risk fields", () => {
|
|
12
|
+
const response = {
|
|
13
|
+
type: "https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-required",
|
|
14
|
+
title: "Forbidden",
|
|
15
|
+
status: 403,
|
|
16
|
+
code: "adaptive_challenge_required",
|
|
17
|
+
request_id: "req_123",
|
|
18
|
+
challenge_id: "7ab4c7b5-fd31-4767-a2eb-7826f10f4c11",
|
|
19
|
+
site_key: "public-site-key",
|
|
20
|
+
action: "email_start",
|
|
21
|
+
transaction_id: "txn_123",
|
|
22
|
+
};
|
|
23
|
+
expect(adaptiveChallengeRequiredResponseSchema.safeParse(response).success).toBe(true);
|
|
24
|
+
expect(
|
|
25
|
+
adaptiveChallengeRequiredResponseSchema.safeParse({ ...response, risk_score: 0.99 }).success,
|
|
26
|
+
).toBe(false);
|
|
27
|
+
expect(
|
|
28
|
+
adaptiveChallengeUnavailableResponseSchema.safeParse({
|
|
29
|
+
type: "https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-unavailable",
|
|
30
|
+
title: "Service Unavailable",
|
|
31
|
+
status: 503,
|
|
32
|
+
code: "adaptive_challenge_unavailable",
|
|
33
|
+
}).success,
|
|
34
|
+
).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("allows a proof only as an optional field on the four initiation requests", () => {
|
|
38
|
+
expect(emailStartRequestSchema.safeParse({ email: "user@example.com" }).success).toBe(true);
|
|
39
|
+
expect(
|
|
40
|
+
emailStartRequestSchema.safeParse({
|
|
41
|
+
email: "user@example.com",
|
|
42
|
+
challenge_token: "turnstile-proof",
|
|
43
|
+
}).success,
|
|
44
|
+
).toBe(true);
|
|
45
|
+
expect(
|
|
46
|
+
emailResendRequestSchema.safeParse({
|
|
47
|
+
challenge_id: "challenge-123",
|
|
48
|
+
challenge_token: "turnstile-proof",
|
|
49
|
+
}).success,
|
|
50
|
+
).toBe(true);
|
|
51
|
+
expect(
|
|
52
|
+
passkeyAuthenticationOptionsRequestSchema.safeParse({
|
|
53
|
+
rp: "active",
|
|
54
|
+
challenge_token: "turnstile-proof",
|
|
55
|
+
}).success,
|
|
56
|
+
).toBe(true);
|
|
57
|
+
expect(socialStartRequestSchema.safeParse({}).success).toBe(true);
|
|
58
|
+
expect(socialStartRequestSchema.safeParse({ challenge_token: "turnstile-proof" }).success).toBe(
|
|
59
|
+
true,
|
|
60
|
+
);
|
|
61
|
+
expect(socialStartRequestSchema.safeParse({ action: "social_start" }).success).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
package/src/adaptive.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/** Turnstile proof is accepted only on the same factor-initiation request that received a challenge. */
|
|
4
|
+
export const adaptiveChallengeTokenSchema = z.string().min(1).max(2048);
|
|
5
|
+
|
|
6
|
+
export const adaptiveChallengeActionSchema = z.enum([
|
|
7
|
+
"email_start",
|
|
8
|
+
"email_resend",
|
|
9
|
+
"passkey_auth_options",
|
|
10
|
+
"social_start",
|
|
11
|
+
]);
|
|
12
|
+
export type AdaptiveChallengeAction = z.infer<typeof adaptiveChallengeActionSchema>;
|
|
13
|
+
|
|
14
|
+
/** RFC 9457 Problem Details returned before a factor-initiation side effect. */
|
|
15
|
+
export const adaptiveChallengeRequiredResponseSchema = z.strictObject({
|
|
16
|
+
type: z.literal("https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-required"),
|
|
17
|
+
title: z.literal("Forbidden"),
|
|
18
|
+
status: z.literal(403),
|
|
19
|
+
code: z.literal("adaptive_challenge_required"),
|
|
20
|
+
request_id: z.string().optional(),
|
|
21
|
+
challenge_id: z.string().min(1),
|
|
22
|
+
site_key: z.string().min(1),
|
|
23
|
+
action: adaptiveChallengeActionSchema,
|
|
24
|
+
transaction_id: z.string().min(1),
|
|
25
|
+
});
|
|
26
|
+
export type AdaptiveChallengeRequiredResponse = z.infer<
|
|
27
|
+
typeof adaptiveChallengeRequiredResponseSchema
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export const adaptiveChallengeUnavailableResponseSchema = z.strictObject({
|
|
31
|
+
type: z.literal("https://docs.zeroword.smartcrab.ai/errors/adaptive-challenge-unavailable"),
|
|
32
|
+
title: z.literal("Service Unavailable"),
|
|
33
|
+
status: z.literal(503),
|
|
34
|
+
code: z.literal("adaptive_challenge_unavailable"),
|
|
35
|
+
request_id: z.string().optional(),
|
|
36
|
+
});
|
|
37
|
+
export type AdaptiveChallengeUnavailableResponse = z.infer<
|
|
38
|
+
typeof adaptiveChallengeUnavailableResponseSchema
|
|
39
|
+
>;
|
package/src/email.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { emailOtpCodeSchema, isoDateTimeSchema } from "./primitives.js";
|
|
3
|
+
import { adaptiveChallengeTokenSchema } from "./adaptive.js";
|
|
3
4
|
import { transactionAuthResultResponseSchema } from "./transaction-status.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -20,6 +21,7 @@ import { transactionAuthResultResponseSchema } from "./transaction-status.js";
|
|
|
20
21
|
|
|
21
22
|
export const emailStartRequestSchema = z.strictObject({
|
|
22
23
|
email: z.email(),
|
|
24
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
23
25
|
});
|
|
24
26
|
export type EmailStartRequest = z.infer<typeof emailStartRequestSchema>;
|
|
25
27
|
|
|
@@ -32,6 +34,7 @@ export type EmailChallengeResponse = z.infer<typeof emailChallengeResponseSchema
|
|
|
32
34
|
/** design.md §18.2: resend increments the generation and invalidates the prior code. */
|
|
33
35
|
export const emailResendRequestSchema = z.strictObject({
|
|
34
36
|
challenge_id: z.string().min(1),
|
|
37
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
35
38
|
});
|
|
36
39
|
export type EmailResendRequest = z.infer<typeof emailResendRequestSchema>;
|
|
37
40
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { identityIdSchema } from "./primitives.js";
|
|
3
|
+
|
|
4
|
+
export const identityLinkCodeChallengeSchema = z.string().regex(/^[A-Za-z0-9_-]{43}$/);
|
|
5
|
+
export const identityLinkCodeVerifierSchema = z.string().regex(/^[A-Za-z0-9._~-]{43,128}$/);
|
|
6
|
+
export const identityLinkStateSchema = z.string().min(1).max(256);
|
|
7
|
+
|
|
8
|
+
export const meIdentityLinkCompleteRequestSchema = z.strictObject({
|
|
9
|
+
code: z.string().min(1).max(256),
|
|
10
|
+
code_verifier: identityLinkCodeVerifierSchema,
|
|
11
|
+
});
|
|
12
|
+
export type MeIdentityLinkCompleteRequest = z.infer<typeof meIdentityLinkCompleteRequestSchema>;
|
|
13
|
+
|
|
14
|
+
export const meIdentityLinkCompleteResponseSchema = z.strictObject({
|
|
15
|
+
identity_id: identityIdSchema,
|
|
16
|
+
});
|
|
17
|
+
export type MeIdentityLinkCompleteResponse = z.infer<typeof meIdentityLinkCompleteResponseSchema>;
|
package/src/index.ts
CHANGED
|
@@ -19,5 +19,8 @@ export * from "./transactions.js";
|
|
|
19
19
|
export * from "./email.js";
|
|
20
20
|
export * from "./passkeys.js";
|
|
21
21
|
export * from "./social.js";
|
|
22
|
+
export * from "./adaptive.js";
|
|
23
|
+
export * from "./identity-linking.js";
|
|
24
|
+
export * from "./recovery.js";
|
|
22
25
|
export * from "./me.js";
|
|
23
26
|
export * from "./association-files.js";
|
package/src/me.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
userIdSchema,
|
|
18
18
|
} from "./primitives.js";
|
|
19
19
|
import { socialProviderSchema, socialStartResponseSchema } from "./social.js";
|
|
20
|
+
import { identityLinkCodeChallengeSchema, identityLinkStateSchema } from "./identity-linking.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* The authenticated self-service surface (design.md §16.2 route list). All
|
|
@@ -122,13 +123,14 @@ export const meIdentitiesListResponseSchema = z.strictObject({
|
|
|
122
123
|
export type MeIdentitiesListResponse = z.infer<typeof meIdentitiesListResponseSchema>;
|
|
123
124
|
|
|
124
125
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* link, not a public auth transaction, so it carries its own return
|
|
128
|
-
* target rather than one fixed at transaction-create time).
|
|
126
|
+
* The app-held verifier stays in the client. The server stores only its S256
|
|
127
|
+
* challenge, app state, and the exact registered return URI.
|
|
129
128
|
*/
|
|
130
129
|
export const meIdentityLinkRequestSchema = z.strictObject({
|
|
131
130
|
redirect_uri: redirectUriSchema,
|
|
131
|
+
code_challenge: identityLinkCodeChallengeSchema,
|
|
132
|
+
code_challenge_method: z.literal("S256"),
|
|
133
|
+
state: identityLinkStateSchema,
|
|
132
134
|
});
|
|
133
135
|
export type MeIdentityLinkRequest = z.infer<typeof meIdentityLinkRequestSchema>;
|
|
134
136
|
|
package/src/passkeys.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { adaptiveChallengeTokenSchema } from "./adaptive.js";
|
|
2
3
|
import { isoDateTimeSchema, passkeyIdSchema } from "./primitives.js";
|
|
3
4
|
import { transactionAuthResultResponseSchema } from "./transaction-status.js";
|
|
4
5
|
|
|
@@ -163,6 +164,7 @@ export const passkeyAuthenticationOptionsRequestSchema = z
|
|
|
163
164
|
rp: passkeyAuthenticationRpSchema.optional(),
|
|
164
165
|
/** design.md §8.3: explicit RP ID; mutually exclusive with `rp`. */
|
|
165
166
|
rp_id: passkeyRpIdSchema.optional(),
|
|
167
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
166
168
|
})
|
|
167
169
|
.refine((body) => body.rp === undefined || body.rp_id === undefined, {
|
|
168
170
|
message: "rp and rp_id are mutually exclusive",
|
package/src/recovery.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/** Explicit authenticated account recovery completion (design.md §25). */
|
|
4
|
+
export const meRecoveryCompleteRequestSchema = z.strictObject({
|
|
5
|
+
confirmed: z.literal(true),
|
|
6
|
+
});
|
|
7
|
+
export type MeRecoveryCompleteRequest = z.infer<typeof meRecoveryCompleteRequestSchema>;
|
|
8
|
+
|
|
9
|
+
/** Recovery revokes every session; the caller must authenticate again. */
|
|
10
|
+
export const meRecoveryCompleteResponseSchema = z.strictObject({
|
|
11
|
+
recovered: z.literal(true),
|
|
12
|
+
reauthentication_required: z.literal(true),
|
|
13
|
+
});
|
|
14
|
+
export type MeRecoveryCompleteResponse = z.infer<typeof meRecoveryCompleteResponseSchema>;
|
package/src/social.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { adaptiveChallengeTokenSchema } from "./adaptive.js";
|
|
2
3
|
import { httpsUrlSchema, opaqueClientValueSchema } from "./primitives.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -13,11 +14,13 @@ export const socialProviderSchema = z.enum(SOCIAL_PROVIDERS);
|
|
|
13
14
|
export type SocialProvider = (typeof SOCIAL_PROVIDERS)[number];
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` —
|
|
17
|
-
*
|
|
17
|
+
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` — an optional
|
|
18
|
+
* challenge proof; the transaction (scope, resource, redirect_uri) is already
|
|
18
19
|
* fixed by `POST /v1/auth/transactions`.
|
|
19
20
|
*/
|
|
20
|
-
export const socialStartRequestSchema = z.strictObject({
|
|
21
|
+
export const socialStartRequestSchema = z.strictObject({
|
|
22
|
+
challenge_token: adaptiveChallengeTokenSchema.optional(),
|
|
23
|
+
});
|
|
21
24
|
export type SocialStartRequest = z.infer<typeof socialStartRequestSchema>;
|
|
22
25
|
|
|
23
26
|
/** The URL the client must navigate the system browser to (design.md §20.6: no embedded WebViews). */
|