@smartcrab/contracts-public 0.1.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.
- package/LICENSE +202 -0
- package/dist/association-files.d.ts +46 -0
- package/dist/association-files.js +32 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.js +38 -0
- package/dist/email.d.ts +55 -0
- package/dist/email.js +39 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/me.d.ts +297 -0
- package/dist/me.js +140 -0
- package/dist/oidc.d.ts +239 -0
- package/dist/oidc.js +230 -0
- package/dist/outcome.d.ts +19 -0
- package/dist/outcome.js +2 -0
- package/dist/passkeys.d.ts +257 -0
- package/dist/passkeys.js +162 -0
- package/dist/primitives.d.ts +60 -0
- package/dist/primitives.js +52 -0
- package/dist/redirect-uri.d.ts +25 -0
- package/dist/redirect-uri.js +39 -0
- package/dist/scopes.d.ts +30 -0
- package/dist/scopes.js +46 -0
- package/dist/social.d.ts +44 -0
- package/dist/social.js +35 -0
- package/dist/transaction-status.d.ts +53 -0
- package/dist/transaction-status.js +37 -0
- package/dist/transactions.d.ts +144 -0
- package/dist/transactions.js +103 -0
- package/package.json +43 -0
- package/src/association-files.test.ts +71 -0
- package/src/association-files.ts +46 -0
- package/src/config.test.ts +66 -0
- package/src/config.ts +62 -0
- package/src/email.test.ts +40 -0
- package/src/email.ts +50 -0
- package/src/index.ts +23 -0
- package/src/me.test.ts +116 -0
- package/src/me.ts +223 -0
- package/src/oidc.test.ts +224 -0
- package/src/oidc.ts +296 -0
- package/src/outcome.ts +17 -0
- package/src/passkeys.test.ts +80 -0
- package/src/passkeys.ts +218 -0
- package/src/primitives.ts +79 -0
- package/src/redirect-uri.test.ts +118 -0
- package/src/redirect-uri.ts +86 -0
- package/src/scopes.test.ts +51 -0
- package/src/scopes.ts +63 -0
- package/src/social.test.ts +34 -0
- package/src/social.ts +43 -0
- package/src/transaction-status.ts +44 -0
- package/src/transactions.test.ts +153 -0
- package/src/transactions.ts +129 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Shared primitives for the public authentication API (design.md §16, §15).
|
|
4
|
+
*
|
|
5
|
+
* Resource IDs reuse the exact `<prefix>_<32 base32url chars>` patterns from
|
|
6
|
+
* `@smartcrab/identifiers` (design.md §7.5) so this package never
|
|
7
|
+
* hand-rolls a competing regex.
|
|
8
|
+
*/
|
|
9
|
+
export declare const clientIdSchema: z.ZodString;
|
|
10
|
+
export type ClientId = z.infer<typeof clientIdSchema>;
|
|
11
|
+
export declare const transactionIdSchema: z.ZodString;
|
|
12
|
+
export type TransactionId = z.infer<typeof transactionIdSchema>;
|
|
13
|
+
export declare const userIdSchema: z.ZodString;
|
|
14
|
+
export type UserId = z.infer<typeof userIdSchema>;
|
|
15
|
+
export declare const sessionIdSchema: z.ZodString;
|
|
16
|
+
export type SessionId = z.infer<typeof sessionIdSchema>;
|
|
17
|
+
export declare const passkeyIdSchema: z.ZodString;
|
|
18
|
+
export type PasskeyId = z.infer<typeof passkeyIdSchema>;
|
|
19
|
+
export declare const identityIdSchema: z.ZodString;
|
|
20
|
+
export type IdentityId = z.infer<typeof identityIdSchema>;
|
|
21
|
+
export declare const webhookIdSchema: z.ZodString;
|
|
22
|
+
export type WebhookId = z.infer<typeof webhookIdSchema>;
|
|
23
|
+
/** `ac_...` — one-time authorization code (design.md §16.3 example). */
|
|
24
|
+
export declare const authorizationCodeSchema: z.ZodString;
|
|
25
|
+
export type AuthorizationCode = z.infer<typeof authorizationCodeSchema>;
|
|
26
|
+
/** `jti_...` — JWT ID, used by the introspection response (design.md §15.6 example). */
|
|
27
|
+
export declare const jtiSchema: z.ZodString;
|
|
28
|
+
export type Jti = z.infer<typeof jtiSchema>;
|
|
29
|
+
/** Issuer/endpoint URLs are always `https://` (design.md §8). */
|
|
30
|
+
export declare const httpsUrlSchema: z.ZodURL;
|
|
31
|
+
/**
|
|
32
|
+
* Redirect URIs are opaque, byte-for-byte compared strings (design.md §15.9):
|
|
33
|
+
* they may be `https://...` (web, Universal/App Links) or a non-http(s)
|
|
34
|
+
* custom scheme (React Native, e.g. `com.customer.app:/oauth/callback`).
|
|
35
|
+
* Structural/scheme rules are enforced by `validateRedirectUri`
|
|
36
|
+
* (./redirect-uri.js) against the client's registered list, not by this
|
|
37
|
+
* shape check alone.
|
|
38
|
+
*/
|
|
39
|
+
export declare const redirectUriSchema: z.ZodString;
|
|
40
|
+
/**
|
|
41
|
+
* Opaque values the client supplies and the server stores only as a MAC
|
|
42
|
+
* (design.md §16.1: "`state`と`nonce`はMACのみ保存する。"). Bounded to keep
|
|
43
|
+
* request bodies small; the value itself carries no semantics for us.
|
|
44
|
+
*/
|
|
45
|
+
export declare const opaqueClientValueSchema: z.ZodString;
|
|
46
|
+
/** RFC 7636 §4.2: 43-char base64url(SHA-256(verifier)) — always 43 chars, never padded. */
|
|
47
|
+
export declare const codeChallengeSchema: z.ZodString;
|
|
48
|
+
/** RFC 7636 §4.1: 43-128 unreserved characters. */
|
|
49
|
+
export declare const codeVerifierSchema: z.ZodString;
|
|
50
|
+
/** ISO 8601 UTC timestamp, e.g. `2026-08-02T08:10:00Z` (design.md §16.1 example). */
|
|
51
|
+
export declare const isoDateTimeSchema: z.ZodISODateTime;
|
|
52
|
+
/** Email OTP is always 6 numeric digits (design.md §18.2). */
|
|
53
|
+
export declare const emailOtpCodeSchema: z.ZodString;
|
|
54
|
+
/**
|
|
55
|
+
* Resource indicators (RFC 8707) this platform issues bindings for are
|
|
56
|
+
* always HTTPS APIs (design.md §16.1 example: `https://api.customer.example`).
|
|
57
|
+
* Capped defensively; the platform does not document an upper bound but an
|
|
58
|
+
* unbounded array is an abuse vector in a public, unauthenticated endpoint.
|
|
59
|
+
*/
|
|
60
|
+
export declare const resourceListSchema: z.ZodArray<z.ZodURL>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { idPattern } from "@smartcrab/identifiers";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* Shared primitives for the public authentication API (design.md §16, §15).
|
|
5
|
+
*
|
|
6
|
+
* Resource IDs reuse the exact `<prefix>_<32 base32url chars>` patterns from
|
|
7
|
+
* `@smartcrab/identifiers` (design.md §7.5) so this package never
|
|
8
|
+
* hand-rolls a competing regex.
|
|
9
|
+
*/
|
|
10
|
+
export const clientIdSchema = z.string().regex(idPattern("client"));
|
|
11
|
+
export const transactionIdSchema = z.string().regex(idPattern("transaction"));
|
|
12
|
+
export const userIdSchema = z.string().regex(idPattern("user"));
|
|
13
|
+
export const sessionIdSchema = z.string().regex(idPattern("session"));
|
|
14
|
+
export const passkeyIdSchema = z.string().regex(idPattern("passkey"));
|
|
15
|
+
export const identityIdSchema = z.string().regex(idPattern("identity"));
|
|
16
|
+
export const webhookIdSchema = z.string().regex(idPattern("webhook"));
|
|
17
|
+
/** `ac_...` — one-time authorization code (design.md §16.3 example). */
|
|
18
|
+
export const authorizationCodeSchema = z.string().regex(idPattern("authorizationCode"));
|
|
19
|
+
/** `jti_...` — JWT ID, used by the introspection response (design.md §15.6 example). */
|
|
20
|
+
export const jtiSchema = z.string().regex(idPattern("jti"));
|
|
21
|
+
/** Issuer/endpoint URLs are always `https://` (design.md §8). */
|
|
22
|
+
export const httpsUrlSchema = z.url({ protocol: /^https$/ });
|
|
23
|
+
/**
|
|
24
|
+
* Redirect URIs are opaque, byte-for-byte compared strings (design.md §15.9):
|
|
25
|
+
* they may be `https://...` (web, Universal/App Links) or a non-http(s)
|
|
26
|
+
* custom scheme (React Native, e.g. `com.customer.app:/oauth/callback`).
|
|
27
|
+
* Structural/scheme rules are enforced by `validateRedirectUri`
|
|
28
|
+
* (./redirect-uri.js) against the client's registered list, not by this
|
|
29
|
+
* shape check alone.
|
|
30
|
+
*/
|
|
31
|
+
export const redirectUriSchema = z.string().min(1).max(2048);
|
|
32
|
+
/**
|
|
33
|
+
* Opaque values the client supplies and the server stores only as a MAC
|
|
34
|
+
* (design.md §16.1: "`state`と`nonce`はMACのみ保存する。"). Bounded to keep
|
|
35
|
+
* request bodies small; the value itself carries no semantics for us.
|
|
36
|
+
*/
|
|
37
|
+
export const opaqueClientValueSchema = z.string().min(1).max(512);
|
|
38
|
+
/** RFC 7636 §4.2: 43-char base64url(SHA-256(verifier)) — always 43 chars, never padded. */
|
|
39
|
+
export const codeChallengeSchema = z.string().regex(/^[A-Za-z0-9_-]{43}$/);
|
|
40
|
+
/** RFC 7636 §4.1: 43-128 unreserved characters. */
|
|
41
|
+
export const codeVerifierSchema = z.string().regex(/^[A-Za-z0-9._~-]{43,128}$/);
|
|
42
|
+
/** ISO 8601 UTC timestamp, e.g. `2026-08-02T08:10:00Z` (design.md §16.1 example). */
|
|
43
|
+
export const isoDateTimeSchema = z.iso.datetime();
|
|
44
|
+
/** Email OTP is always 6 numeric digits (design.md §18.2). */
|
|
45
|
+
export const emailOtpCodeSchema = z.string().regex(/^[0-9]{6}$/);
|
|
46
|
+
/**
|
|
47
|
+
* Resource indicators (RFC 8707) this platform issues bindings for are
|
|
48
|
+
* always HTTPS APIs (design.md §16.1 example: `https://api.customer.example`).
|
|
49
|
+
* Capped defensively; the platform does not document an upper bound but an
|
|
50
|
+
* unbounded array is an abuse vector in a public, unauthenticated endpoint.
|
|
51
|
+
*/
|
|
52
|
+
export const resourceListSchema = z.array(httpsUrlSchema).max(20);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ClientType } from "@smartcrab/tenant-context";
|
|
2
|
+
import type { Outcome } from "./outcome.js";
|
|
3
|
+
/**
|
|
4
|
+
* Redirect URI validation (design.md §15.9):
|
|
5
|
+
*
|
|
6
|
+
* - byte-for-byte exact match against the client's registered list (no
|
|
7
|
+
* normalization: a trailing-slash difference is a mismatch)
|
|
8
|
+
* - a fragment anywhere in the candidate URI is forbidden
|
|
9
|
+
* - `web_bff` / `web_spa` require `https://`; `http://` is allowed only for
|
|
10
|
+
* `localhost` / `127.0.0.1`
|
|
11
|
+
* - `react_native` allows `https://` (Universal Link / App Link) or a
|
|
12
|
+
* non-http(s) custom scheme, which must be reverse-DNS
|
|
13
|
+
* (e.g. `com.customer.app`)
|
|
14
|
+
* - a literal wildcard character is always rejected, even if (erroneously)
|
|
15
|
+
* present in the registered list or byte-identical to the candidate
|
|
16
|
+
*/
|
|
17
|
+
export type RedirectUriRejectionReason = "wildcard_forbidden" | "contains_fragment" | "malformed" | "scheme_not_allowed_for_client_type" | "invalid_custom_scheme" | "not_registered";
|
|
18
|
+
export interface RedirectUriRejected {
|
|
19
|
+
readonly type: "invalid_redirect_uri";
|
|
20
|
+
readonly reason: RedirectUriRejectionReason;
|
|
21
|
+
}
|
|
22
|
+
export type ValidateRedirectUriResult = Outcome<{
|
|
23
|
+
readonly redirectUri: string;
|
|
24
|
+
}, RedirectUriRejected>;
|
|
25
|
+
export declare const validateRedirectUri: (uri: string, registered: readonly string[], clientType: ClientType) => ValidateRedirectUriResult;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { err, ok } from "./outcome.js";
|
|
2
|
+
const LOCALHOST_HOSTNAMES = new Set(["localhost", "127.0.0.1"]);
|
|
3
|
+
/** Reverse-DNS scheme, e.g. `com.customer.app` (design.md §15.9, §21.5 example). */
|
|
4
|
+
const REVERSE_DNS_SCHEME_PATTERN = /^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/;
|
|
5
|
+
const reject = (reason) => err({ type: "invalid_redirect_uri", reason });
|
|
6
|
+
export const validateRedirectUri = (uri, registered, clientType) => {
|
|
7
|
+
if (uri.includes("*")) {
|
|
8
|
+
return reject("wildcard_forbidden");
|
|
9
|
+
}
|
|
10
|
+
if (uri.includes("#")) {
|
|
11
|
+
return reject("contains_fragment");
|
|
12
|
+
}
|
|
13
|
+
if (!URL.canParse(uri)) {
|
|
14
|
+
return reject("malformed");
|
|
15
|
+
}
|
|
16
|
+
const parsed = new URL(uri);
|
|
17
|
+
// WHATWG URL parsing lowercases the scheme; `protocol` retains the trailing `:`.
|
|
18
|
+
const scheme = parsed.protocol.slice(0, -1);
|
|
19
|
+
if (clientType === "web_bff" || clientType === "web_spa") {
|
|
20
|
+
const isHttps = scheme === "https";
|
|
21
|
+
const isLocalhostHttp = scheme === "http" && LOCALHOST_HOSTNAMES.has(parsed.hostname);
|
|
22
|
+
if (!isHttps && !isLocalhostHttp) {
|
|
23
|
+
return reject("scheme_not_allowed_for_client_type");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// react_native
|
|
28
|
+
if (scheme === "http") {
|
|
29
|
+
return reject("scheme_not_allowed_for_client_type");
|
|
30
|
+
}
|
|
31
|
+
if (scheme !== "https" && !REVERSE_DNS_SCHEME_PATTERN.test(scheme)) {
|
|
32
|
+
return reject("invalid_custom_scheme");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!registered.includes(uri)) {
|
|
36
|
+
return reject("not_registered");
|
|
37
|
+
}
|
|
38
|
+
return ok({ redirectUri: uri });
|
|
39
|
+
};
|
package/dist/scopes.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Outcome } from "./outcome.js";
|
|
3
|
+
/** OIDC scopes this platform issues (design.md §16.1, §21.8 example). */
|
|
4
|
+
export declare const SCOPES: readonly ["openid", "profile", "email", "offline_access"];
|
|
5
|
+
export declare const scopeSchema: z.ZodEnum<{
|
|
6
|
+
email: "email";
|
|
7
|
+
openid: "openid";
|
|
8
|
+
profile: "profile";
|
|
9
|
+
offline_access: "offline_access";
|
|
10
|
+
}>;
|
|
11
|
+
export type Scope = (typeof SCOPES)[number];
|
|
12
|
+
export interface InvalidScopeError {
|
|
13
|
+
readonly type: "invalid_scope";
|
|
14
|
+
readonly invalidTokens: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parses a space-delimited scope string (`"openid profile email"`) into known
|
|
18
|
+
* `Scope` tokens. Never throws; unknown tokens are reported, not silently
|
|
19
|
+
* dropped, so callers can produce an `invalid_scope` OAuth error
|
|
20
|
+
* (design.md §15's OAuth error codes).
|
|
21
|
+
*/
|
|
22
|
+
export declare const parseScopeString: (scopeString: string) => Outcome<readonly Scope[], InvalidScopeError>;
|
|
23
|
+
/** Formats scopes back into the wire's space-delimited string form. */
|
|
24
|
+
export declare const formatScopeList: (scopes: readonly Scope[]) => string;
|
|
25
|
+
/**
|
|
26
|
+
* A `scope` wire field: a non-empty space-delimited string containing only
|
|
27
|
+
* known scope tokens. Used by the authorize request, transaction create
|
|
28
|
+
* request, refresh token grant, and token response.
|
|
29
|
+
*/
|
|
30
|
+
export declare const scopeStringSchema: z.ZodString;
|
package/dist/scopes.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { err, ok } from "./outcome.js";
|
|
3
|
+
/** OIDC scopes this platform issues (design.md §16.1, §21.8 example). */
|
|
4
|
+
export const SCOPES = ["openid", "profile", "email", "offline_access"];
|
|
5
|
+
export const scopeSchema = z.enum(SCOPES);
|
|
6
|
+
const isScope = (value) => SCOPES.includes(value);
|
|
7
|
+
/**
|
|
8
|
+
* Parses a space-delimited scope string (`"openid profile email"`) into known
|
|
9
|
+
* `Scope` tokens. Never throws; unknown tokens are reported, not silently
|
|
10
|
+
* dropped, so callers can produce an `invalid_scope` OAuth error
|
|
11
|
+
* (design.md §15's OAuth error codes).
|
|
12
|
+
*/
|
|
13
|
+
export const parseScopeString = (scopeString) => {
|
|
14
|
+
const tokens = scopeString
|
|
15
|
+
.trim()
|
|
16
|
+
.split(/\s+/)
|
|
17
|
+
.filter((token) => token.length > 0);
|
|
18
|
+
const scopes = [];
|
|
19
|
+
const invalidTokens = [];
|
|
20
|
+
for (const token of tokens) {
|
|
21
|
+
if (isScope(token)) {
|
|
22
|
+
scopes.push(token);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
invalidTokens.push(token);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (invalidTokens.length > 0) {
|
|
29
|
+
return err({ type: "invalid_scope", invalidTokens });
|
|
30
|
+
}
|
|
31
|
+
return ok(scopes);
|
|
32
|
+
};
|
|
33
|
+
/** Formats scopes back into the wire's space-delimited string form. */
|
|
34
|
+
export const formatScopeList = (scopes) => scopes.join(" ");
|
|
35
|
+
/**
|
|
36
|
+
* A `scope` wire field: a non-empty space-delimited string containing only
|
|
37
|
+
* known scope tokens. Used by the authorize request, transaction create
|
|
38
|
+
* request, refresh token grant, and token response.
|
|
39
|
+
*/
|
|
40
|
+
export const scopeStringSchema = z
|
|
41
|
+
.string()
|
|
42
|
+
.min(1)
|
|
43
|
+
.refine((value) => {
|
|
44
|
+
const parsed = parseScopeString(value);
|
|
45
|
+
return parsed.ok && parsed.value.length > 0;
|
|
46
|
+
}, `scope must be a space-delimited list of: ${SCOPES.join(", ")}`);
|
package/dist/social.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Social login providers (design.md §20.1). `passkey`/`email_otp` are the
|
|
4
|
+
* two non-social `AuthMethod`s from `@smartcrab/tenant-context`; this is
|
|
5
|
+
* the strict subset that is a valid `:provider` path segment for
|
|
6
|
+
* `/v1/auth/transactions/:transactionId/social/:provider/start` and
|
|
7
|
+
* `/v1/auth/social/:provider/callback`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SOCIAL_PROVIDERS: readonly ["google", "apple", "github", "microsoft", "generic_oidc"];
|
|
10
|
+
export declare const socialProviderSchema: z.ZodEnum<{
|
|
11
|
+
google: "google";
|
|
12
|
+
apple: "apple";
|
|
13
|
+
github: "github";
|
|
14
|
+
microsoft: "microsoft";
|
|
15
|
+
generic_oidc: "generic_oidc";
|
|
16
|
+
}>;
|
|
17
|
+
export type SocialProvider = (typeof SOCIAL_PROVIDERS)[number];
|
|
18
|
+
/**
|
|
19
|
+
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` — no
|
|
20
|
+
* request body; the transaction (scope, resource, redirect_uri) is already
|
|
21
|
+
* fixed by `POST /v1/auth/transactions`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const socialStartRequestSchema: z.ZodObject<{}, z.core.$strict>;
|
|
24
|
+
export type SocialStartRequest = z.infer<typeof socialStartRequestSchema>;
|
|
25
|
+
/** The URL the client must navigate the system browser to (design.md §20.6: no embedded WebViews). */
|
|
26
|
+
export declare const socialStartResponseSchema: z.ZodObject<{
|
|
27
|
+
authorization_url: z.ZodURL;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export type SocialStartResponse = z.infer<typeof socialStartResponseSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* `GET /v1/auth/social/:provider/callback` — the provider's own OAuth2
|
|
32
|
+
* redirect back to us. Note this route carries no `:transactionId`: the
|
|
33
|
+
* signed `state` value is how the callback recovers which transaction is
|
|
34
|
+
* being resumed (design.md §20.2 "署名済みtransaction IDからEnvironmentへ
|
|
35
|
+
* 戻す"). Lenient (`z.object`, not `z.strictObject`): this is a query string
|
|
36
|
+
* from a third party we do not control the shape of beyond the OAuth2 base.
|
|
37
|
+
*/
|
|
38
|
+
export declare const socialCallbackQuerySchema: z.ZodObject<{
|
|
39
|
+
state: z.ZodString;
|
|
40
|
+
code: z.ZodOptional<z.ZodString>;
|
|
41
|
+
error: z.ZodOptional<z.ZodString>;
|
|
42
|
+
error_description: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type SocialCallbackQuery = z.infer<typeof socialCallbackQuerySchema>;
|
package/dist/social.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { httpsUrlSchema, opaqueClientValueSchema } from "./primitives.js";
|
|
3
|
+
/**
|
|
4
|
+
* Social login providers (design.md §20.1). `passkey`/`email_otp` are the
|
|
5
|
+
* two non-social `AuthMethod`s from `@smartcrab/tenant-context`; this is
|
|
6
|
+
* the strict subset that is a valid `:provider` path segment for
|
|
7
|
+
* `/v1/auth/transactions/:transactionId/social/:provider/start` and
|
|
8
|
+
* `/v1/auth/social/:provider/callback`.
|
|
9
|
+
*/
|
|
10
|
+
export const SOCIAL_PROVIDERS = ["google", "apple", "github", "microsoft", "generic_oidc"];
|
|
11
|
+
export const socialProviderSchema = z.enum(SOCIAL_PROVIDERS);
|
|
12
|
+
/**
|
|
13
|
+
* `POST /v1/auth/transactions/:transactionId/social/:provider/start` — no
|
|
14
|
+
* request body; the transaction (scope, resource, redirect_uri) is already
|
|
15
|
+
* fixed by `POST /v1/auth/transactions`.
|
|
16
|
+
*/
|
|
17
|
+
export const socialStartRequestSchema = z.strictObject({});
|
|
18
|
+
/** The URL the client must navigate the system browser to (design.md §20.6: no embedded WebViews). */
|
|
19
|
+
export const socialStartResponseSchema = z.strictObject({
|
|
20
|
+
authorization_url: httpsUrlSchema,
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* `GET /v1/auth/social/:provider/callback` — the provider's own OAuth2
|
|
24
|
+
* redirect back to us. Note this route carries no `:transactionId`: the
|
|
25
|
+
* signed `state` value is how the callback recovers which transaction is
|
|
26
|
+
* being resumed (design.md §20.2 "署名済みtransaction IDからEnvironmentへ
|
|
27
|
+
* 戻す"). Lenient (`z.object`, not `z.strictObject`): this is a query string
|
|
28
|
+
* from a third party we do not control the shape of beyond the OAuth2 base.
|
|
29
|
+
*/
|
|
30
|
+
export const socialCallbackQuerySchema = z.object({
|
|
31
|
+
state: opaqueClientValueSchema,
|
|
32
|
+
code: z.string().min(1).optional(),
|
|
33
|
+
error: z.string().min(1).optional(),
|
|
34
|
+
error_description: z.string().optional(),
|
|
35
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* `AuthTransactionDO` lifecycle states (design.md §14.2 `AuthTransactionState.status`).
|
|
4
|
+
* The public API surfaces this verbatim on transaction get/cancel and on the
|
|
5
|
+
* ack returned by each verify step so Hosted UI / React Native can drive a
|
|
6
|
+
* state machine without guessing.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TRANSACTION_STATUSES: readonly ["created", "interaction_started", "challenge_issued", "link_required", "authenticated", "code_issued", "consumed", "failed", "expired"];
|
|
9
|
+
export declare const transactionStatusSchema: z.ZodEnum<{
|
|
10
|
+
created: "created";
|
|
11
|
+
interaction_started: "interaction_started";
|
|
12
|
+
challenge_issued: "challenge_issued";
|
|
13
|
+
link_required: "link_required";
|
|
14
|
+
authenticated: "authenticated";
|
|
15
|
+
code_issued: "code_issued";
|
|
16
|
+
consumed: "consumed";
|
|
17
|
+
failed: "failed";
|
|
18
|
+
expired: "expired";
|
|
19
|
+
}>;
|
|
20
|
+
export type TransactionStatus = (typeof TRANSACTION_STATUSES)[number];
|
|
21
|
+
/**
|
|
22
|
+
* Method that most recently advanced a transaction to `authenticated`
|
|
23
|
+
* (design.md §14.2 `AuthTransactionState.method`).
|
|
24
|
+
*/
|
|
25
|
+
export declare const TRANSACTION_AUTH_METHODS: readonly ["passkey", "email_otp", "social"];
|
|
26
|
+
export declare const transactionAuthMethodSchema: z.ZodEnum<{
|
|
27
|
+
passkey: "passkey";
|
|
28
|
+
email_otp: "email_otp";
|
|
29
|
+
social: "social";
|
|
30
|
+
}>;
|
|
31
|
+
export type TransactionAuthMethod = (typeof TRANSACTION_AUTH_METHODS)[number];
|
|
32
|
+
/**
|
|
33
|
+
* Common ack shape returned by every "verify" step
|
|
34
|
+
* (email/verify, passkeys/authentication/verify). Design.md §16.3 forbids
|
|
35
|
+
* these steps from returning access/refresh tokens directly ("OTP verifyや
|
|
36
|
+
* Passkey verifyが直接access/refresh tokenを返すことは禁止する"); only
|
|
37
|
+
* `POST .../complete` returns the one-time authorization code.
|
|
38
|
+
*/
|
|
39
|
+
export declare const transactionAuthResultResponseSchema: z.ZodObject<{
|
|
40
|
+
transaction_id: z.ZodString;
|
|
41
|
+
status: z.ZodEnum<{
|
|
42
|
+
created: "created";
|
|
43
|
+
interaction_started: "interaction_started";
|
|
44
|
+
challenge_issued: "challenge_issued";
|
|
45
|
+
link_required: "link_required";
|
|
46
|
+
authenticated: "authenticated";
|
|
47
|
+
code_issued: "code_issued";
|
|
48
|
+
consumed: "consumed";
|
|
49
|
+
failed: "failed";
|
|
50
|
+
expired: "expired";
|
|
51
|
+
}>;
|
|
52
|
+
}, z.core.$strict>;
|
|
53
|
+
export type TransactionAuthResultResponse = z.infer<typeof transactionAuthResultResponseSchema>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { transactionIdSchema } from "./primitives.js";
|
|
3
|
+
/**
|
|
4
|
+
* `AuthTransactionDO` lifecycle states (design.md §14.2 `AuthTransactionState.status`).
|
|
5
|
+
* The public API surfaces this verbatim on transaction get/cancel and on the
|
|
6
|
+
* ack returned by each verify step so Hosted UI / React Native can drive a
|
|
7
|
+
* state machine without guessing.
|
|
8
|
+
*/
|
|
9
|
+
export const TRANSACTION_STATUSES = [
|
|
10
|
+
"created",
|
|
11
|
+
"interaction_started",
|
|
12
|
+
"challenge_issued",
|
|
13
|
+
"link_required",
|
|
14
|
+
"authenticated",
|
|
15
|
+
"code_issued",
|
|
16
|
+
"consumed",
|
|
17
|
+
"failed",
|
|
18
|
+
"expired",
|
|
19
|
+
];
|
|
20
|
+
export const transactionStatusSchema = z.enum(TRANSACTION_STATUSES);
|
|
21
|
+
/**
|
|
22
|
+
* Method that most recently advanced a transaction to `authenticated`
|
|
23
|
+
* (design.md §14.2 `AuthTransactionState.method`).
|
|
24
|
+
*/
|
|
25
|
+
export const TRANSACTION_AUTH_METHODS = ["passkey", "email_otp", "social"];
|
|
26
|
+
export const transactionAuthMethodSchema = z.enum(TRANSACTION_AUTH_METHODS);
|
|
27
|
+
/**
|
|
28
|
+
* Common ack shape returned by every "verify" step
|
|
29
|
+
* (email/verify, passkeys/authentication/verify). Design.md §16.3 forbids
|
|
30
|
+
* these steps from returning access/refresh tokens directly ("OTP verifyや
|
|
31
|
+
* Passkey verifyが直接access/refresh tokenを返すことは禁止する"); only
|
|
32
|
+
* `POST .../complete` returns the one-time authorization code.
|
|
33
|
+
*/
|
|
34
|
+
export const transactionAuthResultResponseSchema = z.strictObject({
|
|
35
|
+
transaction_id: transactionIdSchema,
|
|
36
|
+
status: transactionStatusSchema,
|
|
37
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* `POST /v1/auth/transactions` (design.md §16.1, exact example):
|
|
4
|
+
*
|
|
5
|
+
* ```json
|
|
6
|
+
* {
|
|
7
|
+
* "client_id": "cli_xxx",
|
|
8
|
+
* "redirect_uri": "com.customer.app:/oauth/callback",
|
|
9
|
+
* "code_challenge": "...",
|
|
10
|
+
* "code_challenge_method": "S256",
|
|
11
|
+
* "state": "...",
|
|
12
|
+
* "nonce": "...",
|
|
13
|
+
* "scope": "openid profile email offline_access",
|
|
14
|
+
* "resource": ["https://api.customer.example"],
|
|
15
|
+
* "response_mode": "native_return"
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const RESPONSE_MODES: readonly ["redirect", "native_return"];
|
|
20
|
+
export declare const responseModeSchema: z.ZodEnum<{
|
|
21
|
+
redirect: "redirect";
|
|
22
|
+
native_return: "native_return";
|
|
23
|
+
}>;
|
|
24
|
+
export type ResponseMode = (typeof RESPONSE_MODES)[number];
|
|
25
|
+
/** `plain` is rejected: only `S256` is a valid literal (design.md §15.3). */
|
|
26
|
+
export declare const transactionCodeChallengeMethodSchema: z.ZodLiteral<"S256">;
|
|
27
|
+
export declare const transactionCreateRequestSchema: z.ZodObject<{
|
|
28
|
+
client_id: z.ZodString;
|
|
29
|
+
redirect_uri: z.ZodString;
|
|
30
|
+
code_challenge: z.ZodString;
|
|
31
|
+
code_challenge_method: z.ZodLiteral<"S256">;
|
|
32
|
+
state: z.ZodString;
|
|
33
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
34
|
+
scope: z.ZodString;
|
|
35
|
+
resource: z.ZodOptional<z.ZodArray<z.ZodURL>>;
|
|
36
|
+
response_mode: z.ZodOptional<z.ZodEnum<{
|
|
37
|
+
redirect: "redirect";
|
|
38
|
+
native_return: "native_return";
|
|
39
|
+
}>>;
|
|
40
|
+
}, z.core.$strict>;
|
|
41
|
+
export type TransactionCreateRequest = z.infer<typeof transactionCreateRequestSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* ```json
|
|
44
|
+
* {
|
|
45
|
+
* "transaction_id": "txn_xxx",
|
|
46
|
+
* "expires_at": "2026-08-02T08:10:00Z",
|
|
47
|
+
* "available_methods": ["passkey", "google", "apple", "email_otp"]
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const transactionCreateResponseSchema: z.ZodObject<{
|
|
52
|
+
transaction_id: z.ZodString;
|
|
53
|
+
expires_at: z.ZodISODateTime;
|
|
54
|
+
available_methods: z.ZodArray<z.ZodEnum<{
|
|
55
|
+
passkey: "passkey";
|
|
56
|
+
email_otp: "email_otp";
|
|
57
|
+
google: "google";
|
|
58
|
+
apple: "apple";
|
|
59
|
+
github: "github";
|
|
60
|
+
microsoft: "microsoft";
|
|
61
|
+
generic_oidc: "generic_oidc";
|
|
62
|
+
}>>;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
export type TransactionCreateResponse = z.infer<typeof transactionCreateResponseSchema>;
|
|
65
|
+
/**
|
|
66
|
+
* `GET /v1/auth/transactions/:transactionId` — status polling for Hosted UI /
|
|
67
|
+
* React Native (design.md §16.2 lists the route; §14.2 defines the status
|
|
68
|
+
* machine this projects).
|
|
69
|
+
*/
|
|
70
|
+
export declare const transactionGetResponseSchema: z.ZodObject<{
|
|
71
|
+
transaction_id: z.ZodString;
|
|
72
|
+
status: z.ZodEnum<{
|
|
73
|
+
created: "created";
|
|
74
|
+
interaction_started: "interaction_started";
|
|
75
|
+
challenge_issued: "challenge_issued";
|
|
76
|
+
link_required: "link_required";
|
|
77
|
+
authenticated: "authenticated";
|
|
78
|
+
code_issued: "code_issued";
|
|
79
|
+
consumed: "consumed";
|
|
80
|
+
failed: "failed";
|
|
81
|
+
expired: "expired";
|
|
82
|
+
}>;
|
|
83
|
+
expires_at: z.ZodISODateTime;
|
|
84
|
+
available_methods: z.ZodArray<z.ZodEnum<{
|
|
85
|
+
passkey: "passkey";
|
|
86
|
+
email_otp: "email_otp";
|
|
87
|
+
google: "google";
|
|
88
|
+
apple: "apple";
|
|
89
|
+
github: "github";
|
|
90
|
+
microsoft: "microsoft";
|
|
91
|
+
generic_oidc: "generic_oidc";
|
|
92
|
+
}>>;
|
|
93
|
+
method: z.ZodOptional<z.ZodEnum<{
|
|
94
|
+
passkey: "passkey";
|
|
95
|
+
email_otp: "email_otp";
|
|
96
|
+
social: "social";
|
|
97
|
+
}>>;
|
|
98
|
+
pending_link: z.ZodNullable<z.ZodObject<{
|
|
99
|
+
provider: z.ZodEnum<{
|
|
100
|
+
google: "google";
|
|
101
|
+
apple: "apple";
|
|
102
|
+
github: "github";
|
|
103
|
+
microsoft: "microsoft";
|
|
104
|
+
generic_oidc: "generic_oidc";
|
|
105
|
+
}>;
|
|
106
|
+
}, z.core.$strict>>;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
export type TransactionGetResponse = z.infer<typeof transactionGetResponseSchema>;
|
|
109
|
+
/** `POST /v1/auth/transactions/:transactionId/cancel` — no request body. */
|
|
110
|
+
export declare const transactionCancelRequestSchema: z.ZodObject<{}, z.core.$strict>;
|
|
111
|
+
export type TransactionCancelRequest = z.infer<typeof transactionCancelRequestSchema>;
|
|
112
|
+
/**
|
|
113
|
+
* A cancelled transaction moves to `failed` (design.md §14.2's status
|
|
114
|
+
* machine has no separate `canceled` state); the client only needs to know
|
|
115
|
+
* it can no longer be resumed.
|
|
116
|
+
*/
|
|
117
|
+
export declare const transactionCancelResponseSchema: z.ZodObject<{
|
|
118
|
+
transaction_id: z.ZodString;
|
|
119
|
+
status: z.ZodLiteral<"failed">;
|
|
120
|
+
}, z.core.$strict>;
|
|
121
|
+
export type TransactionCancelResponse = z.infer<typeof transactionCancelResponseSchema>;
|
|
122
|
+
/**
|
|
123
|
+
* `POST /v1/auth/transactions/:transactionId/complete` (design.md §16.3,
|
|
124
|
+
* exact example):
|
|
125
|
+
*
|
|
126
|
+
* ```json
|
|
127
|
+
* {
|
|
128
|
+
* "authorization_code": "ac_xxx",
|
|
129
|
+
* "state": "original-state",
|
|
130
|
+
* "redirect_uri": "com.customer.app:/oauth/callback"
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* No request body: the transaction must already be `authenticated` via one
|
|
135
|
+
* of the verify endpoints.
|
|
136
|
+
*/
|
|
137
|
+
export declare const transactionCompleteRequestSchema: z.ZodObject<{}, z.core.$strict>;
|
|
138
|
+
export type TransactionCompleteRequest = z.infer<typeof transactionCompleteRequestSchema>;
|
|
139
|
+
export declare const transactionCompleteResponseSchema: z.ZodObject<{
|
|
140
|
+
authorization_code: z.ZodString;
|
|
141
|
+
state: z.ZodString;
|
|
142
|
+
redirect_uri: z.ZodString;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
export type TransactionCompleteResponse = z.infer<typeof transactionCompleteResponseSchema>;
|