@k9o/gate 1.1.1 → 1.3.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/CHANGELOG.md +28 -0
- package/README.md +58 -19
- package/dist/{chunk-JEV37YEC.js → chunk-7EED6YWR.js} +1 -1
- package/dist/chunk-7EED6YWR.js.map +1 -0
- package/dist/{chunk-YINWOWJC.js → chunk-OJQYLAGZ.js} +42 -5
- package/dist/chunk-OJQYLAGZ.js.map +1 -0
- package/dist/{chunk-XP6U5QKF.js → chunk-RPE5N37W.js} +1 -1
- package/dist/chunk-RPE5N37W.js.map +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +149 -239
- package/dist/index.js +75 -113
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts +25 -36
- package/dist/jwt.js +4 -2
- package/dist/mode.d.ts +6 -33
- package/dist/mode.js +1 -1
- package/dist/types.d.ts +63 -99
- package/package.json +1 -1
- package/src/api-host.ts +43 -0
- package/src/client-factory.ts +2 -5
- package/src/client.ts +3 -3
- package/src/errors.ts +1 -1
- package/src/gate.ts +62 -134
- package/src/idp-providers/identity-providers.ts +8 -11
- package/src/index.ts +10 -6
- package/src/jwt.ts +63 -45
- package/src/magic-link-redirects.ts +1 -2
- package/src/mode.ts +6 -33
- package/src/paths.ts +2 -6
- package/src/region.ts +24 -24
- package/src/types.ts +60 -94
- package/dist/chunk-JEV37YEC.js.map +0 -1
- package/dist/chunk-XP6U5QKF.js.map +0 -1
- package/dist/chunk-YINWOWJC.js.map +0 -1
package/src/mode.ts
CHANGED
|
@@ -1,38 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Standalone vs Native mode wiring.
|
|
3
3
|
*
|
|
4
|
-
* The SDK surface is identical across modes; mode
|
|
5
|
-
*
|
|
6
|
-
* not SDK ergonomics. The mode boundary is a deployment-time decision
|
|
7
|
-
*; the SDK does not branch behavior at function-call time.
|
|
4
|
+
* The SDK surface is identical across modes; the mode only tells the gateway how to route consumption. The SDK
|
|
5
|
+
* records it on every request in the `X-Gate-Mode` header and does not branch on it at call time.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* - **Billing-identity routing** (commission callout):
|
|
12
|
-
* Standalone customers are billed under the partner-credentialled
|
|
13
|
-
* contract (Gate as Auth0/Clerk/Okta alternative — Trojan Horse
|
|
14
|
-
* motion); Native customers compose with the broader Kilimanjaro
|
|
15
|
-
* billing model. The SDK records the mode on every wire request via
|
|
16
|
-
* the `X-Gate-Mode` header so the gateway routes consumption to the
|
|
17
|
-
* correct billing surface without per-function branching.
|
|
18
|
-
* - **Auto-scoping expectations** in marketing copy + docs hub copy
|
|
19
|
-
* (per memory `feedback_gate_iak_brand_architecture.md` marketing-
|
|
20
|
-
* honesty discipline). Standalone mode delivers Sovereign Ingress +
|
|
21
|
-
* Hardware-Attested Identity + Forensic Attribution + Unlimited MAUs;
|
|
22
|
-
* Native mode adds Automatic Identity-Aware Scoping on top.
|
|
23
|
-
*
|
|
24
|
-
* What mode does NOT affect:
|
|
25
|
-
*
|
|
26
|
-
* - Function names + signatures (identical across modes)
|
|
27
|
-
* - Wire-envelope shape (identical)
|
|
28
|
-
* - Error taxonomy (identical)
|
|
7
|
+
* Function names, signatures, response envelope and error taxonomy are the same in both modes.
|
|
29
8
|
*/
|
|
30
9
|
|
|
31
|
-
/**
|
|
32
|
-
* Two-mode discriminant. The third candidate "Hybrid" was rejected per
|
|
33
|
-
* memory `feedback_gate_iak_brand_architecture.md` — modes are
|
|
34
|
-
* orthogonal deployment shapes, not interleaved.
|
|
35
|
-
*/
|
|
10
|
+
/** Two orthogonal deployment shapes; they are not interleaved. */
|
|
36
11
|
export type GateMode = "standalone" | "native";
|
|
37
12
|
|
|
38
13
|
/**
|
|
@@ -42,11 +17,9 @@ export type GateMode = "standalone" | "native";
|
|
|
42
17
|
*/
|
|
43
18
|
export type GateConfig = {
|
|
44
19
|
mode: GateMode;
|
|
45
|
-
/** Project slug
|
|
46
|
-
* The only customer-facing project addressing form; routes resolve to
|
|
47
|
-
* `/@<slug>/gate/...` (`feedback_slug_addressing_v2_5_68`). Required. */
|
|
20
|
+
/** Project slug (e.g. `partner-console-staging`). Routes resolve to `/@<slug>/gate/...`. Required. */
|
|
48
21
|
projectSlug: string;
|
|
49
|
-
/** Gateway base URL
|
|
22
|
+
/** Gateway base URL, e.g. `https://<orgSlug>.api.<apex>` */
|
|
50
23
|
baseUrl: string;
|
|
51
24
|
/**
|
|
52
25
|
* Optional partner-credentialled JWT for Standalone mode — used as the
|
package/src/paths.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared path-resolution helper for project-scoped routes.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* the only customer-facing form — project ids are internal-only and never
|
|
7
|
-
* appear in customer paths (`feedback_slug_addressing_v2_5_68`); the
|
|
8
|
-
* retired `/v2/projects/<bareId>/...` form was dropped at pass17
|
|
9
|
-
* (`feedback_v2_path_is_an_error`).
|
|
4
|
+
* Project-scoped resources are addressed
|
|
5
|
+
* as `/@<projectSlug>/...` against the org host. The slug is the only project addressing form.
|
|
10
6
|
*
|
|
11
7
|
* Caller is expected to validate that the config carries a `projectSlug`
|
|
12
8
|
* at construction time (see `validateGateConfig`).
|
package/src/region.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Regional host resolution.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* body, an `Authorization` header or a cookie (`400 K9O_INVALID_REQUEST_SHAPE`,
|
|
6
|
-
* so credentials must go to `<org>.api
|
|
7
|
-
* `HEAD
|
|
4
|
+
* A region-free org host `<org>.api.<rest>` (or `<org>.api-staging.<rest>`) redirects GET/HEAD only and REFUSES a
|
|
5
|
+
* request that carries a body, an `Authorization` header or a cookie (`400 K9O_INVALID_REQUEST_SHAPE`,
|
|
6
|
+
* `region_free_host_takes_no_credentials`), so credentials must go to `<org>.api-<rgn>.<rest>`. The client learns the
|
|
7
|
+
* region with ONE unauthenticated `HEAD` to the configured host, takes the `308` `Location`, and caches the regional
|
|
8
|
+
* origin.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Nothing here knows an apex. The host comes from the configured baseUrl; `<rest>` is whatever follows the second
|
|
11
|
+
* label, so a public-cloud, internal-apex, air-gapped or localhost deployment all work. Properties:
|
|
12
|
+
* - Only a host shaped `<org>.api.<rest>` / `<org>.api-staging.<rest>` is probed. A regional, single-label, IP,
|
|
13
|
+
* localhost or any other baseUrl is used exactly as given.
|
|
12
14
|
* - The probe carries NO credential and none of the configured default headers (they may hold one).
|
|
13
|
-
* - The `Location` is trusted only if it is `https`, has no userinfo/port, and its host is exactly the SAME org
|
|
14
|
-
*
|
|
15
|
-
* so a hostile redirect can never receive a credential.
|
|
16
|
-
* - Not a redirect
|
|
17
|
-
*
|
|
18
|
-
* life of the client's config; a network failure is not cached.
|
|
15
|
+
* - The `Location` is trusted only if it is `https`, has no userinfo/port, and its host is exactly the SAME org and
|
|
16
|
+
* SAME remainder with a 4-character region code appended to the second label. Anything else is ignored and the
|
|
17
|
+
* configured baseUrl stays, so a hostile redirect can never receive a credential.
|
|
18
|
+
* - Not a redirect, or any failure: the configured baseUrl stays and the server's own refusal, if any, is what the
|
|
19
|
+
* caller sees. A definite answer is cached for the life of the client's config; a network failure is not cached.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
export type RegionConfig = { baseUrl: string; fetch?: typeof globalThis.fetch | undefined };
|
|
22
|
+
import { parseApiHost } from "./api-host.ts";
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
/** The slice of a client config this module needs. */
|
|
25
|
+
export type RegionConfig = { baseUrl: string; fetch?: typeof globalThis.fetch | undefined };
|
|
26
26
|
|
|
27
27
|
const cache = new WeakMap<RegionConfig, Promise<string>>();
|
|
28
28
|
|
|
29
29
|
/** The regional origin a `Location` may name for `host`, or null if it is not exactly that. Pure. */
|
|
30
30
|
export function regionalOriginFromLocation(host: string, location: string, base: string): string | null {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
31
|
+
const from = parseApiHost(host);
|
|
32
|
+
if (from === null || from.orgSlug === null || from.region !== null) return null;
|
|
33
33
|
let u: URL;
|
|
34
34
|
try {
|
|
35
35
|
u = new URL(location, base);
|
|
@@ -37,10 +37,9 @@ export function regionalOriginFromLocation(host: string, location: string, base:
|
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
39
|
if (u.protocol !== "https:" || u.username !== "" || u.password !== "" || u.port !== "") return null;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (r === null || !REGION_CODE.test(r[1]!)) return null;
|
|
40
|
+
const to = parseApiHost(u.hostname);
|
|
41
|
+
if (to === null || to.region === null) return null;
|
|
42
|
+
if (to.orgSlug !== from.orgSlug || to.family !== from.family || to.apex !== from.apex) return null;
|
|
44
43
|
return `https://${u.hostname}`;
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -54,7 +53,8 @@ async function probe(config: RegionConfig): Promise<{ origin: string; cacheable:
|
|
|
54
53
|
} catch {
|
|
55
54
|
return { origin: configured, cacheable: true };
|
|
56
55
|
}
|
|
57
|
-
|
|
56
|
+
const parsedHost = parseApiHost(host);
|
|
57
|
+
if (parsedHost === null || parsedHost.orgSlug === null || parsedHost.region !== null) return { origin: configured, cacheable: true };
|
|
58
58
|
try {
|
|
59
59
|
const res = await fetchImpl(`${configured.replace(/\/+$/, "")}/`, {
|
|
60
60
|
method: "HEAD",
|
package/src/types.ts
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@k9o/gate`
|
|
3
|
-
*
|
|
4
|
-
* The shapes here track verbatim. End-user IDs carry the `eu_`
|
|
5
|
-
* prefix; role and group identifiers compose against the
|
|
6
|
-
* role lattice (Trust-Zone-separate `PROJECT_END_USER` for project-
|
|
7
|
-
* level end-user identities). Sessions, passkeys, MFA factors, federation
|
|
8
|
-
* links, and the rest of the Gate-managed resources receive their per-
|
|
9
|
-
* resource prefixes as the end-user table family is specified.
|
|
10
|
-
*
|
|
11
|
-
* Envelope shape (`data` + `meta`) matches; failures land via
|
|
12
|
-
* the `GateError` family per `errors.ts`, which is `KError`-compatible
|
|
13
|
-
*.
|
|
2
|
+
* `@k9o/gate` public types. They mirror what the end-user Gate routes answer; failures arrive as a `GateError`
|
|
3
|
+
* (see `errors.ts`).
|
|
14
4
|
*/
|
|
15
5
|
|
|
16
|
-
/**
|
|
17
|
-
* Standard envelope. Generic over the `data` shape per function.
|
|
18
|
-
* Returned by every successful SDK call.
|
|
19
|
-
*/
|
|
6
|
+
/** The gateway's response envelope, generic over the `data` shape. Returned by every successful SDK call. */
|
|
20
7
|
export type Envelope<T> = {
|
|
21
8
|
data: T;
|
|
22
9
|
meta: Record<string, unknown>;
|
|
23
10
|
};
|
|
24
11
|
|
|
25
|
-
/**
|
|
26
|
-
* Project-level end-user identity (the customers OF the customer as
|
|
27
|
-
* the `PROJECT_END_USER` 7th canonical role). End-user IDs carry the
|
|
28
|
-
* `eu_<base62>` prefix.
|
|
29
|
-
*/
|
|
12
|
+
/** A project end-user (the customers of the project's customer). Ids carry the `eu_` prefix. */
|
|
30
13
|
export type EndUser = {
|
|
31
|
-
/** `eu_<base62
|
|
14
|
+
/** `eu_<base62>`. */
|
|
32
15
|
id: string;
|
|
33
16
|
email: string;
|
|
34
17
|
status: "active" | "pending" | "disabled";
|
|
@@ -37,16 +20,13 @@ export type EndUser = {
|
|
|
37
20
|
lastSigninAt: string | null;
|
|
38
21
|
/** Project-level roles; `PROJECT_END_USER` is the floor membership. */
|
|
39
22
|
roles: ReadonlyArray<string>;
|
|
40
|
-
/** Project-level group memberships
|
|
23
|
+
/** Project-level group memberships. */
|
|
41
24
|
groups: ReadonlyArray<string>;
|
|
42
25
|
};
|
|
43
26
|
|
|
44
27
|
/**
|
|
45
|
-
* Session tokens returned by sign-up
|
|
46
|
-
*
|
|
47
|
-
* for downstream Gate-aware services; `refreshToken` is opaque to the
|
|
48
|
-
* SDK consumer and is presented back to `gate.refreshToken({...})` to
|
|
49
|
-
* rotate the access token.
|
|
28
|
+
* Session tokens returned by sign-up, sign-in, OTP and magic-link redemption. The access token is a JWT; the refresh
|
|
29
|
+
* token is opaque and is presented to `gate.refreshToken` and `gate.signOut`.
|
|
50
30
|
*/
|
|
51
31
|
export type Session = {
|
|
52
32
|
accessToken: string;
|
|
@@ -55,38 +35,28 @@ export type Session = {
|
|
|
55
35
|
expiresAt: string;
|
|
56
36
|
};
|
|
57
37
|
|
|
58
|
-
/**
|
|
59
|
-
* Marquee sign-up / sign-in shape:
|
|
60
|
-
* `{ user, session }`
|
|
61
|
-
*/
|
|
38
|
+
/** Sign-up and sign-in answer: `{ user, session }`. */
|
|
62
39
|
export type AuthResult = {
|
|
63
40
|
user: EndUser;
|
|
64
41
|
session: Session;
|
|
65
42
|
};
|
|
66
43
|
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
44
|
+
/** `gate.whoami()` answers the end-user record itself (no wrapper). */
|
|
45
|
+
export type WhoamiResult = EndUser;
|
|
46
|
+
|
|
47
|
+
/** `gate.refreshToken()` answers a new access token only; the refresh token in hand stays valid. */
|
|
48
|
+
export type RefreshResult = {
|
|
49
|
+
accessToken: string;
|
|
50
|
+
/** ISO 8601 instant the new access token expires. */
|
|
51
|
+
expiresAt: string;
|
|
74
52
|
};
|
|
75
53
|
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
* details if valid. Returns `{ valid: false, user: null, session: null }`
|
|
79
|
-
* when the bearer session is missing or expired (no throw on invalid;
|
|
80
|
-
* throw only on transport / upstream failures).
|
|
81
|
-
*/
|
|
82
|
-
export type VerifySessionResult =
|
|
83
|
-
| { valid: true; user: EndUser; session: Session }
|
|
84
|
-
| { valid: false; user: null; session: null };
|
|
54
|
+
/** `gate.signOut()` answer. `revoked` is false when the token was unknown or already revoked. */
|
|
55
|
+
export type SignOutResult = { revoked: boolean };
|
|
85
56
|
|
|
86
57
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* gateway with `K9O_INVALID_FIELD_VALUE` (`context.reason: "unknown_field"`), so this type has no escape hatch.
|
|
58
|
+
* `gate.signUp` takes a CLOSED body: `{ email, password, displayName? }`. `displayName` is 1 to 128 characters; any
|
|
59
|
+
* other field is refused by the gateway with `INVALID_FIELD_VALUE` (`context.reason: "unknown_field"`).
|
|
90
60
|
*/
|
|
91
61
|
export type SignUpInput = {
|
|
92
62
|
email: string;
|
|
@@ -101,40 +71,42 @@ export type SignInInput = {
|
|
|
101
71
|
};
|
|
102
72
|
|
|
103
73
|
export type SignOutInput = {
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
* the access token's bound refresh token only; explicit refresh tokens
|
|
107
|
-
* let callers revoke a specific device/session.
|
|
108
|
-
*/
|
|
109
|
-
refreshToken?: string;
|
|
74
|
+
/** The refresh token of the session to revoke (required by the route). */
|
|
75
|
+
refreshToken: string;
|
|
110
76
|
};
|
|
111
77
|
|
|
112
78
|
export type RefreshTokenInput = {
|
|
113
79
|
refreshToken: string;
|
|
114
80
|
};
|
|
115
81
|
|
|
116
|
-
/**
|
|
117
|
-
* OTP purpose — scopes the one-time code to a flow. The gateway validates
|
|
118
|
-
* against this closed set (otp.ts) and defaults to "signin" when omitted.
|
|
119
|
-
*/
|
|
82
|
+
/** OTP purpose: scopes the one-time code to a flow. The gateway defaults to `"signin"` when omitted. */
|
|
120
83
|
export type OtpPurpose = "signin" | "magic_link" | "password_reset" | "mfa_challenge";
|
|
121
84
|
|
|
122
|
-
/**
|
|
123
|
-
* `gate.passwordless.requestOtp` input — emails an OTP code to the
|
|
124
|
-
* given address. Idempotent at the per-email rate-limit ceiling per
|
|
125
|
-
* the platform anti-abuse policy.
|
|
126
|
-
*/
|
|
85
|
+
/** `gate.passwordless.requestOtp` input: emails a one-time code to the address. */
|
|
127
86
|
export type RequestOtpInput = {
|
|
128
87
|
email: string;
|
|
129
88
|
/** OTP purpose; defaults to "signin" server-side when omitted. */
|
|
130
89
|
purpose?: OtpPurpose;
|
|
131
90
|
};
|
|
132
91
|
|
|
92
|
+
/** `gate.passwordless.verifyOtp` input: the 6-character code from the email plus the address it went to. */
|
|
93
|
+
/** `gate.passwordless.requestOtp` answer. */
|
|
94
|
+
export type RequestOtpResult = {
|
|
95
|
+
otp: { id: string; expiresAt: string };
|
|
96
|
+
/** Only present on a deployment configured to return the code in the response (development). */
|
|
97
|
+
debugCode?: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
133
100
|
/**
|
|
134
|
-
* `gate.passwordless.verifyOtp`
|
|
135
|
-
*
|
|
136
|
-
* gateway can resolve the right OTP row.
|
|
101
|
+
* `gate.passwordless.verifyOtp` answer. `session` and `endUserId` are present for the `signin` purpose; other
|
|
102
|
+
* purposes only confirm the code (`endUserId` when the email belongs to an end-user).
|
|
137
103
|
*/
|
|
104
|
+
export type VerifyOtpResult = {
|
|
105
|
+
verified: true;
|
|
106
|
+
session?: Session;
|
|
107
|
+
endUserId?: string;
|
|
108
|
+
};
|
|
109
|
+
|
|
138
110
|
export type VerifyOtpInput = {
|
|
139
111
|
email: string;
|
|
140
112
|
code: string;
|
|
@@ -143,11 +115,7 @@ export type VerifyOtpInput = {
|
|
|
143
115
|
purpose?: OtpPurpose;
|
|
144
116
|
};
|
|
145
117
|
|
|
146
|
-
/**
|
|
147
|
-
* `gate.passwordless.requestMagicLink` input — emails a magic-link
|
|
148
|
-
* token to the given address; the customer's frontend handles the
|
|
149
|
-
* post-redirect exchange via `verifyMagicLink`.
|
|
150
|
-
*/
|
|
118
|
+
/** `gate.passwordless.requestMagicLink` input: emails a magic link to the address. */
|
|
151
119
|
export type RequestMagicLinkInput = {
|
|
152
120
|
email: string;
|
|
153
121
|
/**
|
|
@@ -159,10 +127,21 @@ export type RequestMagicLinkInput = {
|
|
|
159
127
|
redirectUrl?: string;
|
|
160
128
|
};
|
|
161
129
|
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
130
|
+
/** `gate.passwordless.verifyMagicLink` input: the opaque token from the magic-link query string. */
|
|
131
|
+
/** `gate.passwordless.requestMagicLink` answer. The same shape comes back for an unknown email. */
|
|
132
|
+
export type RequestMagicLinkResult = {
|
|
133
|
+
magicLink: { sent: true; expiresAt?: string };
|
|
134
|
+
/** Only present on a deployment configured to return the link in the response (development). */
|
|
135
|
+
debugLink?: string;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** `gate.passwordless.verifyMagicLink` answer: the new session and the end-user's id. */
|
|
139
|
+
export type VerifyMagicLinkResult = {
|
|
140
|
+
redeemed: true;
|
|
141
|
+
session: Session;
|
|
142
|
+
endUserId: string;
|
|
143
|
+
};
|
|
144
|
+
|
|
166
145
|
export type VerifyMagicLinkInput = {
|
|
167
146
|
token: string;
|
|
168
147
|
};
|
|
@@ -178,10 +157,8 @@ export type MagicLinkCallbackResult =
|
|
|
178
157
|
| { ok: false; error: string };
|
|
179
158
|
|
|
180
159
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* standard claims. Customer apps in Standalone mode consume this via the
|
|
184
|
-
* `verifyJwt` helper without needing the full SDK shape.
|
|
160
|
+
* Claims of a Gate access token that `verifyJwt` resolves. Custom claims arrive FLAT under keys of the form
|
|
161
|
+
* `ext.<namespace>.<name>`; they are available through the index signature.
|
|
185
162
|
*/
|
|
186
163
|
export type GateJwtClaims = {
|
|
187
164
|
/** Issuer — the Kilimanjaro gateway base URL or project-bound issuer. */
|
|
@@ -200,7 +177,7 @@ export type GateJwtClaims = {
|
|
|
200
177
|
roles?: ReadonlyArray<string>;
|
|
201
178
|
/** Project-level group memberships. */
|
|
202
179
|
groups?: ReadonlyArray<string>;
|
|
203
|
-
/**
|
|
180
|
+
/** Scope strings, when the token carries them; used by `requireScope`. */
|
|
204
181
|
scopes?: ReadonlyArray<string>;
|
|
205
182
|
/** Email of the underlying end-user; convenience copy of the database column. */
|
|
206
183
|
email?: string;
|
|
@@ -251,14 +228,3 @@ export type SignInCallbackResult =
|
|
|
251
228
|
error: string;
|
|
252
229
|
errorDescription: string;
|
|
253
230
|
};
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* The project's hosted sign-in page and WebAuthn relying party (`GET /@<projectSlug>/gate/hosted`). Both values come from the platform: an SDK never composes a Gate host from a slug (the label is a hash of
|
|
257
|
-
* ids the SDK does not hold).
|
|
258
|
-
*/
|
|
259
|
-
export type HostedGateInfo = {
|
|
260
|
-
/** Absolute hosted sign-in URL: the verified custom domain's when there is one, else the project's Gate host. */
|
|
261
|
-
signInUrl: string;
|
|
262
|
-
/** The WebAuthn relying-party id (the project's Gate host). Use it as given; never hard-code it. */
|
|
263
|
-
rpId: string;
|
|
264
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Gate error shapes. `GateError` is `KError`-compatible —\n * downstream catch blocks can `instanceof GateError`-narrow without\n * importing the gateway's `KError` class directly (the SDK is a customer-\n * facing dependency; reaching across to the gateway's internal error\n * type would be a layering violation).\n *\n * The taxonomy below is the closed set; additions follow the\n * error-catalogue freeze cycle.\n */\n\n/**\n * Closed-taxonomy error code. Strings are the wire format —\n * camelCase-cased KError families per the convention.\n */\nexport type GateErrorCode =\n | \"UNAUTHENTICATED\"\n | \"INVALID_FIELD_VALUE\"\n | \"EMAIL_ALREADY_REGISTERED\"\n | \"INVALID_CREDENTIALS\"\n | \"SESSION_EXPIRED\"\n | \"REFRESH_TOKEN_INVALID\"\n | \"TIER_FEATURE_GATED\"\n | \"RBAC_DENY\"\n // FORBIDDEN + NOT_FOUND are surfaced by the gate.idpProviders.*\n // sub-namespaces (project-membership gate + resource-existence checks).\n | \"FORBIDDEN\"\n | \"NOT_FOUND\"\n // GATE_REDIRECT_NOT_ALLOWED — magic-link `redirectUrl` not in the project's\n // redirect allowlist (open-redirect-safe exact-match, per-project\n // allowlist capability).\n | \"GATE_REDIRECT_NOT_ALLOWED\"\n | \"POLICY_AUTHORING_AUTHORITY_INSUFFICIENT\"\n | \"UPSTREAM_UNAVAILABLE\"\n | \"INTERNAL_ERROR\";\n\n/**\n * Surface error thrown by the SDK. Mirrors the gateway's `KError` shape\n * — `code` (closed taxonomy), `message` (human-readable),\n * `context` (structured per-code payload), `recommendation` (action the\n * caller can take, or null when there's no canonical recommendation).\n */\nexport class GateError extends Error {\n readonly code: GateErrorCode;\n readonly context: Readonly<Record<string, unknown>>;\n readonly recommendation: string | null;\n /** HTTP status the gateway returned (if the error came from a wire response). */\n readonly status: number | null;\n\n constructor(init: {\n code: GateErrorCode;\n message: string;\n context?: Record<string, unknown>;\n recommendation?: string | null;\n status?: number | null;\n }) {\n super(init.message);\n this.name = \"GateError\";\n this.code = init.code;\n this.context = Object.freeze({ ...(init.context ?? {}) });\n this.recommendation = init.recommendation ?? null;\n this.status = init.status ?? null;\n }\n}\n\n/**\n * Wire-shape sentinel matching the gateway's `KError` JSON payload. The\n * client uses this to recognise gateway responses and rehydrate them\n * into a `GateError` instance with the right code + context preserved.\n */\nexport type KErrorWire = {\n code: string;\n message: string;\n context?: Record<string, unknown>;\n recommendation?: string | null;\n};\n\n/**\n * Narrow a wire `KError` to a strongly-typed `GateError`. Unknown codes\n * pass through as `INTERNAL_ERROR` with the original code preserved in\n * `context.originalCode` so consumers don't lose telemetry when the\n * server-side taxonomy outpaces the SDK's bundled enum.\n */\nexport function gateErrorFromWire(wire: KErrorWire, status: number): GateError {\n const knownCodes: ReadonlyArray<GateErrorCode> = [\n \"UNAUTHENTICATED\",\n \"INVALID_FIELD_VALUE\",\n \"EMAIL_ALREADY_REGISTERED\",\n \"INVALID_CREDENTIALS\",\n \"SESSION_EXPIRED\",\n \"REFRESH_TOKEN_INVALID\",\n \"TIER_FEATURE_GATED\",\n \"RBAC_DENY\",\n \"FORBIDDEN\",\n \"NOT_FOUND\",\n \"GATE_REDIRECT_NOT_ALLOWED\",\n \"POLICY_AUTHORING_AUTHORITY_INSUFFICIENT\",\n \"UPSTREAM_UNAVAILABLE\",\n \"INTERNAL_ERROR\",\n ];\n // Wire codes are platform-namespaced (`K9O_*`);\n // strip the prefix to match the SDK's bundled bare-code enum. The full wire\n // code is always preserved in `context.originalCode` for telemetry.\n const stripped = wire.code.replace(/^K9O_/, \"\");\n const isKnown = (knownCodes as ReadonlyArray<string>).includes(stripped);\n const code: GateErrorCode = isKnown ? (stripped as GateErrorCode) : \"INTERNAL_ERROR\";\n const context = { ...(wire.context ?? {}), originalCode: wire.code };\n return new GateError({\n code,\n message: wire.message,\n context,\n recommendation: wire.recommendation ?? null,\n status,\n });\n}\n"],"mappings":";AA0CO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,MAMT;AACD,UAAM,KAAK,OAAO;AAClB,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,UAAU,OAAO,OAAO,EAAE,GAAI,KAAK,WAAW,CAAC,EAAG,CAAC;AACxD,SAAK,iBAAiB,KAAK,kBAAkB;AAC7C,SAAK,SAAS,KAAK,UAAU;AAAA,EAC/B;AACF;AAoBO,SAAS,kBAAkB,MAAkB,QAA2B;AAC7E,QAAM,aAA2C;AAAA,IAC/C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAIA,QAAM,WAAW,KAAK,KAAK,QAAQ,SAAS,EAAE;AAC9C,QAAM,UAAW,WAAqC,SAAS,QAAQ;AACvE,QAAM,OAAsB,UAAW,WAA6B;AACpE,QAAM,UAAU,EAAE,GAAI,KAAK,WAAW,CAAC,GAAI,cAAc,KAAK,KAAK;AACnE,SAAO,IAAI,UAAU;AAAA,IACnB;AAAA,IACA,SAAS,KAAK;AAAA,IACd;AAAA,IACA,gBAAgB,KAAK,kBAAkB;AAAA,IACvC;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mode.ts"],"sourcesContent":["/**\n * Standalone vs Native mode wiring.\n *\n * The SDK surface is identical across modes; mode determines gateway-\n * side behavior (whether the end-user row scope applies on read/write paths),\n * not SDK ergonomics. The mode boundary is a deployment-time decision\n *; the SDK does not branch behavior at function-call time.\n *\n * What mode affects (today + forward):\n *\n * - **Billing-identity routing** (commission callout):\n * Standalone customers are billed under the partner-credentialled\n * contract (Gate as Auth0/Clerk/Okta alternative — Trojan Horse\n * motion); Native customers compose with the broader Kilimanjaro\n * billing model. The SDK records the mode on every wire request via\n * the `X-Gate-Mode` header so the gateway routes consumption to the\n * correct billing surface without per-function branching.\n * - **Auto-scoping expectations** in marketing copy + docs hub copy\n * (per memory `feedback_gate_iak_brand_architecture.md` marketing-\n * honesty discipline). Standalone mode delivers Sovereign Ingress +\n * Hardware-Attested Identity + Forensic Attribution + Unlimited MAUs;\n * Native mode adds Automatic Identity-Aware Scoping on top.\n *\n * What mode does NOT affect:\n *\n * - Function names + signatures (identical across modes)\n * - Wire-envelope shape (identical)\n * - Error taxonomy (identical)\n */\n\n/**\n * Two-mode discriminant. The third candidate \"Hybrid\" was rejected per\n * memory `feedback_gate_iak_brand_architecture.md` — modes are\n * orthogonal deployment shapes, not interleaved.\n */\nexport type GateMode = \"standalone\" | \"native\";\n\n/**\n * Gate SDK configuration. Returned by `getGateConfig()` and consumed\n * internally by the HTTP client + JWT verifier. Set via `configureGate`\n * at process boot or per-test in unit tests.\n */\nexport type GateConfig = {\n mode: GateMode;\n /** Project slug per the URL grammar (e.g. `partner-console-staging`).\n * The only customer-facing project addressing form; routes resolve to\n * `/@<slug>/gate/...` (`feedback_slug_addressing_v2_5_68`). Required. */\n projectSlug: string;\n /** Gateway base URL — e.g. `https://<orgSlug>.api.k9o.io` per the URL grammar */\n baseUrl: string;\n /**\n * Optional partner-credentialled JWT for Standalone mode — used as the\n * default Authorization header when no per-call bearer is supplied.\n * Not required in Native mode; the gateway resolves credentials from\n * the standard project context.\n */\n partnerToken?: string;\n /**\n * Optional fetch override for testing + non-browser environments. The\n * SDK defaults to global `fetch` (available in Bun + Node 18+ +\n * browsers) when not set.\n */\n fetch?: typeof fetch;\n};\n\nlet _config: GateConfig | null = null;\n\n/**\n * Initialise the SDK. Must be called before any `gate.*` invocation.\n * Re-calling replaces the prior config wholesale (no per-field merge —\n * keeps the config-set-at-boot ergonomic clean).\n */\nexport function configureGate(config: GateConfig): void {\n validateGateConfig(config);\n _config = { ...config };\n}\n\n/**\n * Validate a config shape. Exposed for `createGateClient` so per-instance\n * configs go through identical checks as the singleton.\n */\nexport function validateGateConfig(config: GateConfig): void {\n if (config.mode !== \"standalone\" && config.mode !== \"native\") {\n throw new TypeError(\n `Invalid Gate mode \"${config.mode as string}\"; expected \"standalone\" or \"native\"`,\n );\n }\n const hasSlug = typeof config.projectSlug === \"string\" && config.projectSlug.length > 0;\n if (!hasSlug) {\n throw new TypeError(\n `Gate config missing projectSlug (required, slug grammar — project ids are internal-only and never customer-facing)`,\n );\n }\n if (typeof config.baseUrl !== \"string\" || config.baseUrl.length === 0) {\n throw new TypeError(`Invalid baseUrl \"${config.baseUrl}\"; expected non-empty string`);\n }\n}\n\n/**\n * Read the active config. Throws when called before `configureGate(...)`.\n * Tests can call `resetGateConfig()` to clear between cases.\n */\nexport function getGateConfig(): GateConfig {\n if (_config === null) {\n throw new Error(\n \"@k9o/gate: SDK is not configured. Call configureGate({ mode, projectSlug, baseUrl }) before invoking gate functions.\",\n );\n }\n return _config;\n}\n\n/** Reset the singleton — used by tests + by app-shutdown teardown paths. */\nexport function resetGateConfig(): void {\n _config = null;\n}\n"],"mappings":";AAiEA,IAAI,UAA6B;AAO1B,SAAS,cAAc,QAA0B;AACtD,qBAAmB,MAAM;AACzB,YAAU,EAAE,GAAG,OAAO;AACxB;AAMO,SAAS,mBAAmB,QAA0B;AAC3D,MAAI,OAAO,SAAS,gBAAgB,OAAO,SAAS,UAAU;AAC5D,UAAM,IAAI;AAAA,MACR,sBAAsB,OAAO,IAAc;AAAA,IAC7C;AAAA,EACF;AACA,QAAM,UAAU,OAAO,OAAO,gBAAgB,YAAY,OAAO,YAAY,SAAS;AACtF,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,OAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,WAAW,GAAG;AACrE,UAAM,IAAI,UAAU,oBAAoB,OAAO,OAAO,8BAA8B;AAAA,EACtF;AACF;AAMO,SAAS,gBAA4B;AAC1C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAwB;AACtC,YAAU;AACZ;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/jwt.ts"],"sourcesContent":["/**\n * JWT verification primitives for external-app standalone consumption.\n *\n * Standalone-mode customers consume Gate-issued JWTs in their own\n * application code without needing the full SDK shape — they just need\n * to verify the signature, extract claims, and (optionally) check\n * scopes. This module is the canonical entry for that surface.\n *\n * Backed by `jose` (already a peer dependency in the gateway via the\n * same library; chose `jose` for consistency + JWK fetch support out\n * of the box).\n *\n * Native-mode customers don't typically reach for this directly — the\n * gateway verifies project-issued tokens on every request and rehydrates\n * `subject.*` claims. But the same primitives are\n * portable: Native customers running their own services downstream of\n * the gateway can verify Gate-issued JWTs identically.\n */\n\nimport { createRemoteJWKSet, jwtVerify, errors as joseErrors } from \"jose\";\nimport type { GateJwtClaims, VerifyJwtFailure, VerifyJwtResult } from \"./types.ts\";\nimport { GateError } from \"./errors.ts\";\n\n/**\n * Configuration for `verifyJwt`. The verifier can resolve signing keys\n * via either a remote JWKS URL (the typical Gate deployment shape) or\n * an inline key set (for tests + air-gapped deployments).\n */\nexport type VerifyJwtOptions = {\n token: string;\n /**\n * JWKS endpoint URL — the gateway exposes `/@<projectSlug>/gate/.well-known/jwks.json`\n * by convention. Either `jwksUrl` or `jwks` must be set; not both.\n */\n jwksUrl?: string;\n /**\n * Inline JWK set — used by tests + integration scenarios that want to\n * avoid the network hop. The shape is the standard JWKS `{keys: [...]}`\n * envelope; pass through unchanged to `jose`.\n */\n jwks?: { keys: ReadonlyArray<Record<string, unknown>> };\n /** Expected issuer (`iss` claim). Strict comparison. */\n expectedIssuer?: string;\n /** Expected audience (`aud` claim). Accepts either string or array per RFC 7519. */\n expectedAudience?: string;\n /**\n * Allowed signing algorithms. Defaults to `[\"RS256\", \"ES256\"]` per the\n * standard Gate issuer config. Reject anything outside this set\n * (defense against alg-confusion attacks).\n */\n allowedAlgorithms?: ReadonlyArray<string>;\n /**\n * Clock-skew tolerance in seconds. Defaults to 30. Applies to both\n * `exp` and `nbf` checks.\n */\n clockToleranceSeconds?: number;\n};\n\nconst DEFAULT_ALLOWED_ALGORITHMS = [\"RS256\", \"ES256\"] as const;\nconst DEFAULT_CLOCK_TOLERANCE_SECONDS = 30;\n\n/**\n * Verify a Gate-issued JWT. Returns a typed result; does NOT throw on\n * verification failure (a `valid: false` result carries the reason).\n *\n * Throws `GateError` only when:\n * - `jwksUrl` and `jwks` are both unset or both set\n * - the JWKS fetch fails for transport reasons (UPSTREAM_UNAVAILABLE)\n */\nexport async function verifyJwt(opts: VerifyJwtOptions): Promise<VerifyJwtResult> {\n if (opts.jwksUrl !== undefined && opts.jwks !== undefined) {\n throw new GateError({\n code: \"INVALID_FIELD_VALUE\",\n message: \"verifyJwt: pass either jwksUrl OR jwks, not both\",\n context: {},\n recommendation: null,\n });\n }\n if (opts.jwksUrl === undefined && opts.jwks === undefined) {\n throw new GateError({\n code: \"INVALID_FIELD_VALUE\",\n message: \"verifyJwt: must pass exactly one of {jwksUrl, jwks}\",\n context: {},\n recommendation: null,\n });\n }\n\n const allowedAlgorithms = opts.allowedAlgorithms ?? DEFAULT_ALLOWED_ALGORITHMS;\n const clockTolerance = opts.clockToleranceSeconds ?? DEFAULT_CLOCK_TOLERANCE_SECONDS;\n\n let keyResolver: Parameters<typeof jwtVerify>[1];\n if (opts.jwksUrl !== undefined) {\n keyResolver = createRemoteJWKSet(new URL(opts.jwksUrl));\n } else {\n // Inline JWKS — implement the resolver inline since `jose`'s\n // `createLocalJWKSet` import path varies across versions.\n keyResolver = makeLocalJwksResolver(opts.jwks!);\n }\n\n try {\n const result = await jwtVerify(opts.token, keyResolver, {\n ...(opts.expectedIssuer !== undefined ? { issuer: opts.expectedIssuer } : {}),\n ...(opts.expectedAudience !== undefined ? { audience: opts.expectedAudience } : {}),\n algorithms: allowedAlgorithms as string[],\n clockTolerance,\n });\n return { valid: true, claims: result.payload as GateJwtClaims };\n } catch (e) {\n return { valid: false, reason: classifyJoseFailure(e) };\n }\n}\n\n/**\n * Extract claims from a JWT WITHOUT verifying the signature. Used by\n * SDK consumers that want to read claim data in client code where\n * signature verification has already happened at a trusted hop (e.g.,\n * a reverse proxy). Caller is responsible for confirming the upstream\n * trust path before consuming these claims for security decisions.\n *\n * Throws `GateError` on malformed input.\n */\nexport function extractClaims(token: string): GateJwtClaims {\n const parts = token.split(\".\");\n if (parts.length !== 3) {\n throw new GateError({\n code: \"INVALID_FIELD_VALUE\",\n message: `Malformed JWT: expected 3 dot-separated parts, got ${parts.length}`,\n context: {},\n recommendation: null,\n });\n }\n try {\n const payloadJson = base64UrlDecode(parts[1]!);\n return JSON.parse(payloadJson) as GateJwtClaims;\n } catch (e) {\n throw new GateError({\n code: \"INVALID_FIELD_VALUE\",\n message: `Malformed JWT payload: ${e instanceof Error ? e.message : String(e)}`,\n context: {},\n recommendation: null,\n });\n }\n}\n\n/**\n * Assert that the given claim set contains all of the required scopes.\n * Throws `GateError` with `code: \"RBAC_DENY\"` if any scope is missing.\n * Returns nothing on success — caller uses the throw-or-pass shape.\n */\nexport function requireScope(\n claims: GateJwtClaims,\n requiredScopes: ReadonlyArray<string>,\n): void {\n const present = new Set(claims.scopes ?? []);\n const missing = requiredScopes.filter((s) => !present.has(s));\n if (missing.length > 0) {\n throw new GateError({\n code: \"RBAC_DENY\",\n message: `Required scopes missing: ${missing.join(\", \")}`,\n context: { missingScopes: missing, presentScopes: Array.from(present) },\n recommendation: null,\n });\n }\n}\n\n// ----------------------------------------------------------------------\n// Internals\n// ----------------------------------------------------------------------\n\nfunction classifyJoseFailure(e: unknown): VerifyJwtFailure {\n // Map `jose`'s typed errors to our closed reason set per `VerifyJwtFailure`.\n if (e instanceof joseErrors.JWSSignatureVerificationFailed) return \"INVALID_SIGNATURE\";\n if (e instanceof joseErrors.JWTExpired) return \"EXPIRED\";\n if (e instanceof joseErrors.JWTClaimValidationFailed) {\n const claim = (e as { claim?: string }).claim;\n if (claim === \"aud\") return \"AUDIENCE_MISMATCH\";\n if (claim === \"iss\") return \"ISSUER_MISMATCH\";\n if (claim === \"nbf\") return \"NOT_YET_VALID\";\n return \"MALFORMED\";\n }\n if (e instanceof joseErrors.JOSEAlgNotAllowed) return \"ALGORITHM_NOT_ALLOWED\";\n // Fallback — `jose` raises other errors (parse failures, KID mismatches,\n // etc.) that we lump into `MALFORMED` rather than leaking the per-version\n // taxonomy.\n return \"MALFORMED\";\n}\n\nfunction base64UrlDecode(input: string): string {\n // Pad to a multiple of 4 + swap urlsafe alphabet -> standard alphabet.\n const padded = input + \"=\".repeat((4 - (input.length % 4)) % 4);\n const standard = padded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n // Bun + Node 18+ + browsers all expose `atob`.\n const binary = globalThis.atob(standard);\n // Reassemble bytes back to UTF-8 text.\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n return new TextDecoder(\"utf-8\").decode(bytes);\n}\n\n/**\n * Build a key resolver compatible with `jose.jwtVerify` from an inline\n * JWKS object. `jose` exports `createLocalJWKSet` from its main module\n * but the import path / type shape can shift across minors; reimplement\n * the minimal resolver here for stability.\n */\nfunction makeLocalJwksResolver(\n jwks: { keys: ReadonlyArray<Record<string, unknown>> },\n): Parameters<typeof jwtVerify>[1] {\n // The `jose` resolver signature is `(header, token) => Promise<KeyLike>`\n // — pull the kid from the header, match against the JWKS, and import.\n return async (header) => {\n const { importJWK } = await import(\"jose\");\n const kid = (header as { kid?: string }).kid;\n let match: Record<string, unknown> | undefined;\n if (kid !== undefined) {\n match = jwks.keys.find((k) => k[\"kid\"] === kid);\n }\n if (match === undefined && jwks.keys.length === 1) {\n // Single-key JWKS — return the only key. Tests typically ship one\n // key in the inline set and may not bother with `kid`.\n match = jwks.keys[0];\n }\n if (match === undefined) {\n throw new joseErrors.JWKSNoMatchingKey(\"No matching key in inline JWKS for kid\");\n }\n const alg = (header as { alg?: string }).alg ?? (match[\"alg\"] as string | undefined);\n return importJWK(match as unknown as Parameters<typeof importJWK>[0], alg);\n };\n}\n"],"mappings":";;;;;AAmBA,SAAS,oBAAoB,WAAW,UAAU,kBAAkB;AAuCpE,IAAM,6BAA6B,CAAC,SAAS,OAAO;AACpD,IAAM,kCAAkC;AAUxC,eAAsB,UAAU,MAAkD;AAChF,MAAI,KAAK,YAAY,UAAa,KAAK,SAAS,QAAW;AACzD,UAAM,IAAI,UAAU;AAAA,MAClB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,CAAC;AAAA,MACV,gBAAgB;AAAA,IAClB,CAAC;AAAA,EACH;AACA,MAAI,KAAK,YAAY,UAAa,KAAK,SAAS,QAAW;AACzD,UAAM,IAAI,UAAU;AAAA,MAClB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,CAAC;AAAA,MACV,gBAAgB;AAAA,IACl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