@spfn/auth 0.2.0-beta.90 → 0.2.0-beta.91

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.
@@ -1,4 +1,4 @@
1
- import { K as KeyAlgorithmType } from './types-CD95yudz.js';
1
+ import { K as KeyAlgorithmType } from './types-DYyhze28.js';
2
2
 
3
3
  /**
4
4
  * @spfn/auth - Client Session Management
@@ -95,4 +95,4 @@ declare const PURGE_STRATEGIES: readonly ["anonymize", "hard-delete"];
95
95
  */
96
96
  type PurgeStrategy = typeof PURGE_STRATEGIES[number];
97
97
 
98
- export { ACCOUNT_DELETION_REQUEST_STATUSES as A, INVITATION_STATUSES as I, type KeyAlgorithmType as K, PURGE_STRATEGIES as P, SOCIAL_PROVIDERS as S, USER_STATUSES as U, KEY_ALGORITHM as a, ACCOUNT_DELETION_REQUESTED_BY as b, KEY_PLATFORM as c, type KeyPlatformType as d, KEY_DEVICE_NAME_MAX_LENGTH as e, type InvitationStatus as f, type UserStatus as g, type SocialProvider as h, type AccountDeletionRequestStatus as i, type AccountDeletionRequestedBy as j, type PurgeStrategy as k };
98
+ export { ACCOUNT_DELETION_REQUESTED_BY as A, INVITATION_STATUSES as I, type KeyAlgorithmType as K, PURGE_STRATEGIES as P, SOCIAL_PROVIDERS as S, USER_STATUSES as U, ACCOUNT_DELETION_REQUEST_STATUSES as a, type AccountDeletionRequestStatus as b, type AccountDeletionRequestedBy as c, type InvitationStatus as d, KEY_ALGORITHM as e, KEY_DEVICE_NAME_MAX_LENGTH as f, KEY_PLATFORM as g, type KeyPlatformType as h, type PurgeStrategy as i, type SocialProvider as j, type UserStatus as k };
@@ -0,0 +1,134 @@
1
+ /** The six wire codes. The SDKs classify by code, never HTTP status. */
2
+ type ClientProofErrorCode = 'PROOF_INVALID' | 'PROOF_REPLAYED' | 'PROOF_EXPIRED' | 'SESSION_REVOKED' | 'PROFILE_REJECTED' | 'CONTRACT_UNSUPPORTED';
3
+ /** 128 random bits as lowercase base16 — request ids and control tokens. */
4
+ declare function newHexId(): string;
5
+ declare class ClientProofRefusal {
6
+ readonly code: ClientProofErrorCode;
7
+ readonly message: string;
8
+ constructor(code: ClientProofErrorCode, message: string);
9
+ get httpStatus(): number;
10
+ /** The canonical bytes of `{"error":{"code":…,"message":…,"requestId":…}}`. */
11
+ envelopeBytes(requestId: string): Uint8Array;
12
+ /** Nothing request-derived reaches a log through this. */
13
+ toString(): string;
14
+ static unroutable(): ClientProofRefusal;
15
+ static malformedHeaders(): ClientProofRefusal;
16
+ static missingContentType(): ClientProofRefusal;
17
+ static bodyTooLarge(): ClientProofRefusal;
18
+ /**
19
+ * The body parsed but its bytes are not the canonical form of what it
20
+ * parsed to. Not PROOF_INVALID even though it is discovered next to the
21
+ * proof: the proof over these bytes verifies perfectly well, and an
22
+ * auth-family answer would tell the client to re-handshake and send the
23
+ * same non-canonical bytes again.
24
+ */
25
+ static bodyNotCanonical(): ClientProofRefusal;
26
+ static bodyNotTheDeclaredType(): ClientProofRefusal;
27
+ static sessionHeaderMisplaced(): ClientProofRefusal;
28
+ static unprocessable(): ClientProofRefusal;
29
+ /**
30
+ * A client that ships separately from the server said nothing about which
31
+ * contract it was built against. Without it the server cannot tell whether
32
+ * the two ends agree, and answering as though they do is what produces the
33
+ * undecodable body this check exists to replace.
34
+ */
35
+ static contractVersionMissing(): ClientProofRefusal;
36
+ static contractVersionUnsupported(): ClientProofRefusal;
37
+ static profileRejected(): ClientProofRefusal;
38
+ /**
39
+ * A request that names a profile and presents Bearer credentials as well.
40
+ * The profile named is a real one, so this is not a shape the two ends
41
+ * disagree about: the request asked to be authenticated two ways at once
42
+ * and the profile it named is the one refused.
43
+ */
44
+ static credentialsMixed(): ClientProofRefusal;
45
+ static sessionRevoked(): ClientProofRefusal;
46
+ static proofExpired(): ClientProofRefusal;
47
+ static proofReplayed(): ClientProofRefusal;
48
+ static proofInvalid(): ClientProofRefusal;
49
+ }
50
+
51
+ /**
52
+ * The header names each end announces itself under.
53
+ *
54
+ * Separated from the logic that reads them so the contract bundle can name them
55
+ * without importing the version comparison, which reads the bundle back. These
56
+ * are declarations and depend on nothing.
57
+ *
58
+ * @module server/client-proof/wire-headers
59
+ */
60
+ /** What a client says about itself, one header each. */
61
+ declare const CLIENT_IDENTITY_HEADERS: {
62
+ readonly kind: "x-spfn-client-kind";
63
+ readonly version: "x-spfn-client-version";
64
+ readonly contractVersion: "x-spfn-client-contract-version";
65
+ };
66
+ /**
67
+ * What the server says about itself, on every response.
68
+ *
69
+ * Distinct names from the request headers on purpose: a proxy that echoes a
70
+ * request header into the response would otherwise make the client's own
71
+ * version look like the server's.
72
+ */
73
+ declare const SERVER_CONTRACT_HEADERS: {
74
+ readonly version: "x-spfn-server-contract-version";
75
+ readonly supportedRange: "x-spfn-supported-contract-range";
76
+ };
77
+ /**
78
+ * The client kinds the server distinguishes.
79
+ *
80
+ * `web` is separated from the two app kinds because it carries no contract
81
+ * version: a browser bundle is deployed with the server that serves it, so
82
+ * there is no second version to reconcile.
83
+ */
84
+ declare const CLIENT_KINDS: readonly ["web", "ios", "android"];
85
+ type ClientKind = typeof CLIENT_KINDS[number];
86
+ /** A kind that ships independently of the server, so its contract version matters. */
87
+ declare function isAppKind(kind: ClientKind): boolean;
88
+
89
+ /** What one request announced about the client that sent it. */
90
+ interface ClientIdentity {
91
+ kind: ClientKind;
92
+ /** The client's own release — a store version, or a bundle build. */
93
+ version: string | null;
94
+ /** The contract version the client was generated from. Never set for `web`. */
95
+ contractVersion: string | null;
96
+ }
97
+ /**
98
+ * Reads the identity headers, or null when the kind is absent or unrecognised.
99
+ *
100
+ * Null is not by itself a refusal — a request from something that predates
101
+ * these headers reaches here too. `judgeClientIdentity` decides.
102
+ */
103
+ declare function readClientIdentity(headers: Headers): ClientIdentity | null;
104
+ /**
105
+ * Whether the server serves what the client was generated against.
106
+ *
107
+ * Under 0.x the minor carries breaking changes, so a supported client agrees on
108
+ * major and minor. From 1.0.0 the major alone decides. This is the rule
109
+ * `CONTRACT_SUPPORTED_RANGE` spells out; keeping it as a comparison rather than
110
+ * parsing that string leaves one place to change when the line reaches 1.0.0.
111
+ */
112
+ declare function isContractVersionSupported(clientVersion: string): boolean;
113
+ /**
114
+ * The refusal a request's announced identity earns, or null to let it through.
115
+ *
116
+ * An app kind must state a contract version this server serves. A version it
117
+ * does not serve, and the absence of one, are the same answer: the two ends do
118
+ * not agree on what the contract is, which is what CONTRACT_UNSUPPORTED means.
119
+ * The response carries the server's version and range, so the client can say
120
+ * which way the gap runs.
121
+ *
122
+ * `web` is exempt from the contract check by construction, not by leniency.
123
+ *
124
+ * A request with no recognised kind passes. The check is on what a client says
125
+ * about itself, and a caller that says nothing — a curl, a health probe, a
126
+ * server-to-server call — is not a deployed client this rule is about.
127
+ */
128
+ declare function judgeClientIdentity(identity: ClientIdentity | null): ClientProofRefusal | null;
129
+ /** Writes the server's own announcement onto a response's headers. */
130
+ declare function applyServerContractHeaders(headers: Headers): void;
131
+ /** The same announcement as a plain object, for a response built from one. */
132
+ declare function serverContractHeaders(): Record<string, string>;
133
+
134
+ export { ClientProofRefusal as C, SERVER_CONTRACT_HEADERS as S, CLIENT_IDENTITY_HEADERS as a, CLIENT_KINDS as b, type ClientIdentity as c, type ClientKind as d, type ClientProofErrorCode as e, applyServerContractHeaders as f, isContractVersionSupported as g, isAppKind as i, judgeClientIdentity as j, newHexId as n, readClientIdentity as r, serverContractHeaders as s };
@@ -0,0 +1,4 @@
1
+ ALTER TABLE "spfn_auth"."user_public_keys" ADD COLUMN "client_kind" text;--> statement-breakpoint
2
+ ALTER TABLE "spfn_auth"."user_public_keys" ADD COLUMN "client_version" text;--> statement-breakpoint
3
+ ALTER TABLE "spfn_auth"."user_public_keys" ADD COLUMN "client_contract_version" text;--> statement-breakpoint
4
+ ALTER TABLE "spfn_auth"."user_public_keys" ADD COLUMN "client_seen_at" timestamp with time zone;