@vectoriox/iox-ui 5.98.0 → 5.99.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/fesm2022/vectoriox-iox-ui-identity-core.mjs +535 -0
- package/fesm2022/vectoriox-iox-ui-identity-core.mjs.map +1 -0
- package/identity-core/index.d.ts +364 -0
- package/identity-core/package.json +3 -0
- package/package.json +5 -1
- package/src/identity-core/guards.ts +87 -0
- package/src/identity-core/public-api.ts +13 -0
- package/src/identity-core/sign-in.ts +223 -0
- package/src/identity-core/site-auth.ts +172 -0
- package/src/identity-core/words.ts +194 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who signs in, with what, and the broker's two faces (commerce plan §3c "The broker, step by step", C-D6, C-D22).
|
|
3
|
+
* The broker (iox-control-plane, `auth.iox.studio`) and the studios (iox-cms) speak THESE shapes; a provider is one
|
|
4
|
+
* adapter on the broker and one `customerIdentities.provider` value in a studio. Email codes never touch the broker.
|
|
5
|
+
*/
|
|
6
|
+
/** Who the sign-in is for. */
|
|
7
|
+
var SignInPurpose;
|
|
8
|
+
(function (SignInPurpose) {
|
|
9
|
+
/** A buyer on a studio's site. */
|
|
10
|
+
SignInPurpose["Site"] = "site";
|
|
11
|
+
/** A studio's team member — existing users only (wave 2). */
|
|
12
|
+
SignInPurpose["Admin"] = "admin";
|
|
13
|
+
/** portal.iox.studio. */
|
|
14
|
+
SignInPurpose["Portal"] = "portal";
|
|
15
|
+
})(SignInPurpose || (SignInPurpose = {}));
|
|
16
|
+
/** A provider the broker runs. Google is live; the rest join one adapter at a time (board 18). */
|
|
17
|
+
var SignInProvider;
|
|
18
|
+
(function (SignInProvider) {
|
|
19
|
+
SignInProvider["Google"] = "google";
|
|
20
|
+
SignInProvider["Meta"] = "meta";
|
|
21
|
+
SignInProvider["GitHub"] = "github";
|
|
22
|
+
SignInProvider["LinkedIn"] = "linkedin";
|
|
23
|
+
})(SignInProvider || (SignInProvider = {}));
|
|
24
|
+
/** How a provider answers (board 18): OpenID Connect gives a SIGNED ID token; OAuth 2 needs a profile call. */
|
|
25
|
+
var SignInProtocol;
|
|
26
|
+
(function (SignInProtocol) {
|
|
27
|
+
SignInProtocol["Oidc"] = "oidc";
|
|
28
|
+
SignInProtocol["OAuth2"] = "oauth2";
|
|
29
|
+
})(SignInProtocol || (SignInProtocol = {}));
|
|
30
|
+
const SIGN_IN_PROVIDER_SPECS = Object.freeze({
|
|
31
|
+
[SignInProvider.Google]: { protocol: SignInProtocol.Oidc, signedAnswer: true, live: true },
|
|
32
|
+
[SignInProvider.LinkedIn]: { protocol: SignInProtocol.Oidc, signedAnswer: true, live: false },
|
|
33
|
+
[SignInProvider.Meta]: { protocol: SignInProtocol.OAuth2, signedAnswer: false, live: false },
|
|
34
|
+
[SignInProvider.GitHub]: { protocol: SignInProtocol.OAuth2, signedAnswer: false, live: false },
|
|
35
|
+
});
|
|
36
|
+
function isSignInProvider(value) {
|
|
37
|
+
return typeof value === 'string' && Object.values(SignInProvider).includes(value);
|
|
38
|
+
}
|
|
39
|
+
function isSignInPurpose(value) {
|
|
40
|
+
return typeof value === 'string' && Object.values(SignInPurpose).includes(value);
|
|
41
|
+
}
|
|
42
|
+
/** May `provider` serve `purpose`? Buyers and the portal take any provider; a team member only a signed answer (C-D6). */
|
|
43
|
+
function providerServes(provider, purpose) {
|
|
44
|
+
const spec = SIGN_IN_PROVIDER_SPECS[provider];
|
|
45
|
+
if (!spec)
|
|
46
|
+
return false;
|
|
47
|
+
return purpose === SignInPurpose.Admin ? spec.signedAnswer : true;
|
|
48
|
+
}
|
|
49
|
+
// ── the broker ──────────────────────────────────────────────────────────────────────────────────
|
|
50
|
+
/** The broker's public host (its own ingress; ops.iox.studio is unchanged). */
|
|
51
|
+
const BROKER_HOST = 'auth.iox.studio';
|
|
52
|
+
const BROKER_ORIGIN = `https://${BROKER_HOST}`;
|
|
53
|
+
/** A ticket lives 60 s and is used once; so does a hand-off code. */
|
|
54
|
+
const SIGN_IN_TICKET_TTL_SECONDS = 60;
|
|
55
|
+
const SIGN_IN_HANDOFF_TTL_SECONDS = 60;
|
|
56
|
+
/** The server-to-server routes on the control plane's API host (bearer: the studio's INSTANCE_TOKEN). */
|
|
57
|
+
var BrokerApiRoute;
|
|
58
|
+
(function (BrokerApiRoute) {
|
|
59
|
+
BrokerApiRoute["Tickets"] = "instances/me/sign-in/tickets";
|
|
60
|
+
BrokerApiRoute["Redeem"] = "instances/me/sign-in/redeem";
|
|
61
|
+
})(BrokerApiRoute || (BrokerApiRoute = {}));
|
|
62
|
+
/** The browser's routes on `auth.iox.studio`, one pair per provider. */
|
|
63
|
+
var BrokerBrowserRoute;
|
|
64
|
+
(function (BrokerBrowserRoute) {
|
|
65
|
+
BrokerBrowserRoute["Start"] = "start";
|
|
66
|
+
BrokerBrowserRoute["Callback"] = "callback";
|
|
67
|
+
})(BrokerBrowserRoute || (BrokerBrowserRoute = {}));
|
|
68
|
+
/** `/<route>` on the control plane's API host, root-relative. */
|
|
69
|
+
function brokerApiPath(route) {
|
|
70
|
+
return `/${route}`;
|
|
71
|
+
}
|
|
72
|
+
/** `https://auth.iox.studio/<provider>/<route>`. */
|
|
73
|
+
function brokerBrowserUrl(provider, route, origin = BROKER_ORIGIN) {
|
|
74
|
+
return `${origin.replace(/\/+$/, '')}/${encodeURIComponent(provider)}/${route}`;
|
|
75
|
+
}
|
|
76
|
+
/** Where the browser goes to begin: `https://auth.iox.studio/<provider>/start?ticket=<ticket>`. */
|
|
77
|
+
function brokerStartUrl(provider, ticket, origin = BROKER_ORIGIN) {
|
|
78
|
+
return `${brokerBrowserUrl(provider, BrokerBrowserRoute.Start, origin)}?${BROKER_TICKET_PARAM}=${encodeURIComponent(ticket)}`;
|
|
79
|
+
}
|
|
80
|
+
/** The ONE address registered with each provider: `https://auth.iox.studio/<provider>/callback`. */
|
|
81
|
+
function brokerCallbackUrl(provider, origin = BROKER_ORIGIN) {
|
|
82
|
+
return brokerBrowserUrl(provider, BrokerBrowserRoute.Callback, origin);
|
|
83
|
+
}
|
|
84
|
+
const BROKER_TICKET_PARAM = 'ticket';
|
|
85
|
+
/** What the broker refuses, in its answer body `{ code }`. */
|
|
86
|
+
var BrokerRefusalCode;
|
|
87
|
+
(function (BrokerRefusalCode) {
|
|
88
|
+
/** 403 — the return address is not one of this tenant's hosts. */
|
|
89
|
+
BrokerRefusalCode["ReturnHostRefused"] = "return-host-refused";
|
|
90
|
+
/** 400 */
|
|
91
|
+
BrokerRefusalCode["UnknownProvider"] = "unknown-provider";
|
|
92
|
+
/** 503 — no client id/secret for the provider in the broker's environment. */
|
|
93
|
+
BrokerRefusalCode["ProviderNotConfigured"] = "provider-not-configured";
|
|
94
|
+
/** 404 */
|
|
95
|
+
BrokerRefusalCode["CodeUnknown"] = "code-unknown";
|
|
96
|
+
/** 410 */
|
|
97
|
+
BrokerRefusalCode["CodeUsedOrExpired"] = "code-used-or-expired";
|
|
98
|
+
/** 403 — another tenant's code. */
|
|
99
|
+
BrokerRefusalCode["NotYours"] = "not-yours";
|
|
100
|
+
})(BrokerRefusalCode || (BrokerRefusalCode = {}));
|
|
101
|
+
const BROKER_REFUSAL_STATUS = Object.freeze({
|
|
102
|
+
[BrokerRefusalCode.ReturnHostRefused]: 403,
|
|
103
|
+
[BrokerRefusalCode.UnknownProvider]: 400,
|
|
104
|
+
[BrokerRefusalCode.ProviderNotConfigured]: 503,
|
|
105
|
+
[BrokerRefusalCode.CodeUnknown]: 404,
|
|
106
|
+
[BrokerRefusalCode.CodeUsedOrExpired]: 410,
|
|
107
|
+
[BrokerRefusalCode.NotYours]: 403,
|
|
108
|
+
});
|
|
109
|
+
function isBrokerRefusalCode(value) {
|
|
110
|
+
return typeof value === 'string' && Object.values(BrokerRefusalCode).includes(value);
|
|
111
|
+
}
|
|
112
|
+
// ── back from the broker ───────────────────────────────────────────────────────────────────────
|
|
113
|
+
/** The hand-off code's query parameter on the return address. Never a name or an email in an address. */
|
|
114
|
+
const SIGN_IN_HANDOFF_PARAM = 'iox_signin';
|
|
115
|
+
/** The failure's query parameter on the return address. */
|
|
116
|
+
const SIGN_IN_ERROR_PARAM = 'iox_signin_error';
|
|
117
|
+
/** Why the browser came back without a person. */
|
|
118
|
+
var SignInReturnError;
|
|
119
|
+
(function (SignInReturnError) {
|
|
120
|
+
/** The person pressed Cancel on the provider's screen. */
|
|
121
|
+
SignInReturnError["Cancelled"] = "cancelled";
|
|
122
|
+
/** The provider's answer failed a check (issuer, audience, nonce, an unverified email). */
|
|
123
|
+
SignInReturnError["Refused"] = "refused";
|
|
124
|
+
/** The ticket or the provider's state had expired. */
|
|
125
|
+
SignInReturnError["Expired"] = "expired";
|
|
126
|
+
SignInReturnError["Failed"] = "failed";
|
|
127
|
+
})(SignInReturnError || (SignInReturnError = {}));
|
|
128
|
+
function isSignInReturnError(value) {
|
|
129
|
+
return typeof value === 'string' && Object.values(SignInReturnError).includes(value);
|
|
130
|
+
}
|
|
131
|
+
/** The return address with `?iox_signin=<code>` added (its own query, `next`, kept). */
|
|
132
|
+
function withSignInHandoff(returnUrl, code) {
|
|
133
|
+
return withParam(returnUrl, SIGN_IN_HANDOFF_PARAM, code);
|
|
134
|
+
}
|
|
135
|
+
/** The return address with `?iox_signin_error=<error>` added. */
|
|
136
|
+
function withSignInError(returnUrl, error) {
|
|
137
|
+
return withParam(returnUrl, SIGN_IN_ERROR_PARAM, error);
|
|
138
|
+
}
|
|
139
|
+
function withParam(address, name, value) {
|
|
140
|
+
const url = new URL(address);
|
|
141
|
+
url.searchParams.delete(SIGN_IN_HANDOFF_PARAM);
|
|
142
|
+
url.searchParams.delete(SIGN_IN_ERROR_PARAM);
|
|
143
|
+
url.searchParams.set(name, value);
|
|
144
|
+
return url.toString();
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* What came back on a return address's query (`?iox_signin=` or `?iox_signin_error=`), or null when neither did. An
|
|
148
|
+
* error wins over a code; an unknown error reads `failed`; an empty code is no code.
|
|
149
|
+
*/
|
|
150
|
+
function readSignInReturn(search) {
|
|
151
|
+
const params = typeof search === 'string' ? new URLSearchParams(search.startsWith('?') ? search.slice(1) : search) : search;
|
|
152
|
+
if (!params)
|
|
153
|
+
return null;
|
|
154
|
+
const error = params.get(SIGN_IN_ERROR_PARAM);
|
|
155
|
+
if (error !== null)
|
|
156
|
+
return { error: isSignInReturnError(error) ? error : SignInReturnError.Failed };
|
|
157
|
+
const code = params.get(SIGN_IN_HANDOFF_PARAM)?.trim();
|
|
158
|
+
return code ? { code } : null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The two address checks every sign-in step leans on. Both REFUSE when in doubt: a sign-in that sends a person to the
|
|
163
|
+
* wrong place is worse than one that sends them home.
|
|
164
|
+
*/
|
|
165
|
+
/** Longer than any page path a site has; a longer `next` is refused. */
|
|
166
|
+
const NEXT_PATH_MAX_LENGTH = 2048;
|
|
167
|
+
const PROBE_ORIGIN = 'https://same-origin.invalid';
|
|
168
|
+
// Tab, newline and other control characters are stripped by browsers from a URL, so `/\t/evil` becomes `//evil`.
|
|
169
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
170
|
+
function decodedOnce(value) {
|
|
171
|
+
try {
|
|
172
|
+
return decodeURIComponent(value);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* True only for a path on THIS site — the `next` a sign-in returns to (the open-redirect guard). It must start with ONE
|
|
180
|
+
* `/`, hold no backslash and no control character (raw or percent-encoded), and stay on the origin when a browser
|
|
181
|
+
* resolves it. `//evil.com`, `/\evil.com`, `/%2F%2Fevil.com`, `https://evil.com`, `javascript:` — all refused.
|
|
182
|
+
*/
|
|
183
|
+
function isSameOriginPath(next) {
|
|
184
|
+
if (typeof next !== 'string' || !next || next.length > NEXT_PATH_MAX_LENGTH)
|
|
185
|
+
return false;
|
|
186
|
+
if (next[0] !== '/')
|
|
187
|
+
return false;
|
|
188
|
+
if (CONTROL.test(next) || next.includes('\\'))
|
|
189
|
+
return false;
|
|
190
|
+
const decoded = decodedOnce(next);
|
|
191
|
+
if (decoded === null)
|
|
192
|
+
return false;
|
|
193
|
+
if (CONTROL.test(decoded) || decoded.includes('\\') || decoded.startsWith('//'))
|
|
194
|
+
return false;
|
|
195
|
+
if (next.startsWith('//'))
|
|
196
|
+
return false;
|
|
197
|
+
try {
|
|
198
|
+
const url = new URL(next, PROBE_ORIGIN);
|
|
199
|
+
return url.origin === PROBE_ORIGIN;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** `next` when it is a same-origin path, else `fallback` (the site's home). */
|
|
206
|
+
function safeNextPath(next, fallback = '/') {
|
|
207
|
+
return isSameOriginPath(next) ? next : fallback;
|
|
208
|
+
}
|
|
209
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
210
|
+
function isLoopbackHost(hostname) {
|
|
211
|
+
return LOOPBACK_HOSTS.has(hostname.toLowerCase());
|
|
212
|
+
}
|
|
213
|
+
/** A host as `URL` normalises it (lower case, punycode, the default port dropped), or null when it is not one. */
|
|
214
|
+
function normalizeHost(host) {
|
|
215
|
+
const value = String(host ?? '').trim();
|
|
216
|
+
if (!value || /[\s/\\?#@]/.test(value))
|
|
217
|
+
return null;
|
|
218
|
+
try {
|
|
219
|
+
return new URL(`https://${value}`).host;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* True when `url` returns to one of `hosts` EXACTLY (the broker's return-host check, C-D22): `https:` only (`http:` on a
|
|
227
|
+
* loopback host when asked), no user or password in it, and its host — punycode, with any non-default port — equal to
|
|
228
|
+
* one allowed host. Never a suffix or a prefix: `evil.idos.iox.studio` and `idos.iox.studio.evil.com` are other hosts.
|
|
229
|
+
*/
|
|
230
|
+
function isAllowedReturnHost(url, hosts, options = {}) {
|
|
231
|
+
if (typeof url !== 'string' || !url || CONTROL.test(url) || url.includes('\\'))
|
|
232
|
+
return false;
|
|
233
|
+
let parsed;
|
|
234
|
+
try {
|
|
235
|
+
parsed = new URL(url);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
if (parsed.username || parsed.password)
|
|
241
|
+
return false;
|
|
242
|
+
const loopback = isLoopbackHost(parsed.hostname);
|
|
243
|
+
if (parsed.protocol !== 'https:' && !(parsed.protocol === 'http:' && loopback && options.allowLoopbackHttp))
|
|
244
|
+
return false;
|
|
245
|
+
const host = parsed.host.toLowerCase();
|
|
246
|
+
return hosts.some(allowed => normalizeHost(allowed) === host);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* A buyer's sign-in on a studio's site (commerce plan §3c, C-D5): iox-cms's public routes under `api/site/:orgId/`, the
|
|
251
|
+
* session it issues, and the cookies it sets. A customer is not a user — its token has its OWN secret and audience and
|
|
252
|
+
* every admin route refuses it (trap T3).
|
|
253
|
+
*/
|
|
254
|
+
var SiteAuthRoute;
|
|
255
|
+
(function (SiteAuthRoute) {
|
|
256
|
+
/** `POST { email }` → 202 always (never says whether the email is known). */
|
|
257
|
+
SiteAuthRoute["Code"] = "auth/code";
|
|
258
|
+
/** `POST { email, code }` → the session. */
|
|
259
|
+
SiteAuthRoute["CodeVerify"] = "auth/code/verify";
|
|
260
|
+
SiteAuthRoute["Refresh"] = "auth/refresh";
|
|
261
|
+
SiteAuthRoute["SignOut"] = "auth/signout";
|
|
262
|
+
/** `GET` → `{ customer }` (null when signed out). */
|
|
263
|
+
SiteAuthRoute["Me"] = "me";
|
|
264
|
+
SiteAuthRoute["MyOrders"] = "me/orders";
|
|
265
|
+
})(SiteAuthRoute || (SiteAuthRoute = {}));
|
|
266
|
+
/** Every route a site's sign-in calls, by name (the provider pair is per provider — `siteProviderPath`). */
|
|
267
|
+
const SITE_AUTH_ROUTES = Object.freeze({ ...SiteAuthRoute });
|
|
268
|
+
/** A provider's two routes on the studio: start (`POST { returnPath }` → `{ startUrl }`) and return (the broker's GET). */
|
|
269
|
+
var SiteProviderRoute;
|
|
270
|
+
(function (SiteProviderRoute) {
|
|
271
|
+
SiteProviderRoute["Start"] = "start";
|
|
272
|
+
SiteProviderRoute["Return"] = "return";
|
|
273
|
+
})(SiteProviderRoute || (SiteProviderRoute = {}));
|
|
274
|
+
function siteBase(orgId) {
|
|
275
|
+
return `/api/site/${encodeURIComponent(orgId)}`;
|
|
276
|
+
}
|
|
277
|
+
/** A sign-in route of one org, ROOT-relative: `/api/site/<org>/<route>`. */
|
|
278
|
+
function siteAuthPath(orgId, route) {
|
|
279
|
+
return `${siteBase(orgId)}/${route}`;
|
|
280
|
+
}
|
|
281
|
+
/** `/api/site/<org>/auth/<provider>/<start|return>`. */
|
|
282
|
+
function siteProviderPath(orgId, provider, route) {
|
|
283
|
+
return `${siteBase(orgId)}/auth/${encodeURIComponent(provider)}/${route}`;
|
|
284
|
+
}
|
|
285
|
+
/** The `next` query parameter of the return route — where the buyer lands after signing in. */
|
|
286
|
+
const SIGN_IN_NEXT_PARAM = 'next';
|
|
287
|
+
/**
|
|
288
|
+
* The address the studio asks the broker to send the browser back to:
|
|
289
|
+
* `https://<host>/api/site/<org>/auth/<provider>/return?next=<path>`. `origin` is the studio's own (`https://<host>`);
|
|
290
|
+
* a `next` that is not a same-origin path becomes `/`.
|
|
291
|
+
*/
|
|
292
|
+
function siteProviderReturnUrl(origin, orgId, provider, next) {
|
|
293
|
+
const path = siteProviderPath(orgId, provider, SiteProviderRoute.Return);
|
|
294
|
+
return `${origin.replace(/\/+$/, '')}${path}?${SIGN_IN_NEXT_PARAM}=${encodeURIComponent(safeNextPath(next))}`;
|
|
295
|
+
}
|
|
296
|
+
// ── the session ────────────────────────────────────────────────────────────────────────────────
|
|
297
|
+
/** The buyer token's audience — never an admin token's. */
|
|
298
|
+
const SITE_AUDIENCE = 'site';
|
|
299
|
+
/** True when `claims` carry the site audience and both ids — the shape `CustomerGuard` accepts (it checks the signature). */
|
|
300
|
+
function isSiteSessionClaims(claims) {
|
|
301
|
+
if (!claims || typeof claims !== 'object')
|
|
302
|
+
return false;
|
|
303
|
+
const c = claims;
|
|
304
|
+
const aud = Array.isArray(c['aud']) ? c['aud'] : [c['aud']];
|
|
305
|
+
return aud.includes(SITE_AUDIENCE) && typeof c['sub'] === 'string' && !!c['sub'] && typeof c['org'] === 'string' && !!c['org'];
|
|
306
|
+
}
|
|
307
|
+
/** True when a token's claims carry the site audience at all — what the admin guard refuses (T3). */
|
|
308
|
+
function hasSiteAudience(claims) {
|
|
309
|
+
if (!claims || typeof claims !== 'object')
|
|
310
|
+
return false;
|
|
311
|
+
const aud = claims['aud'];
|
|
312
|
+
return Array.isArray(aud) ? aud.includes(SITE_AUDIENCE) : aud === SITE_AUDIENCE;
|
|
313
|
+
}
|
|
314
|
+
// ── the cookies (per org: many orgs share one host — trap T10) ────────────────────────────────
|
|
315
|
+
/** The buyer session: httpOnly, `Path=/` (the site's SSR reads it — the cart cookie's reason), SameSite=Lax. */
|
|
316
|
+
const CUSTOMER_COOKIE_PREFIX = 'iox_c_';
|
|
317
|
+
/** A Google sign-in in flight: httpOnly, short, holds a hash binding the ticket — a forged return fails without it. */
|
|
318
|
+
const SIGN_IN_STATE_COOKIE_PREFIX = 'iox_si_';
|
|
319
|
+
const SITE_COOKIE_PATH = '/';
|
|
320
|
+
/** Long enough for a person on the provider's screen; the ticket inside expires long before. */
|
|
321
|
+
const SIGN_IN_STATE_MAX_AGE_SECONDS = 600;
|
|
322
|
+
function customerCookieName(orgId) {
|
|
323
|
+
return `${CUSTOMER_COOKIE_PREFIX}${orgId}`;
|
|
324
|
+
}
|
|
325
|
+
function signInStateCookieName(orgId) {
|
|
326
|
+
return `${SIGN_IN_STATE_COOKIE_PREFIX}${orgId}`;
|
|
327
|
+
}
|
|
328
|
+
// ── the email code ─────────────────────────────────────────────────────────────────────────────
|
|
329
|
+
const EMAIL_CODE_LENGTH = 6;
|
|
330
|
+
const EMAIL_CODE_TTL_MINUTES = 10;
|
|
331
|
+
const EMAIL_CODE_TTL_MS = EMAIL_CODE_TTL_MINUTES * 60_000;
|
|
332
|
+
/** Wrong codes before the code is spent and a new one must be sent. */
|
|
333
|
+
const EMAIL_CODE_MAX_TRIES = 5;
|
|
334
|
+
const EMAIL_CODE = new RegExp(`^\\d{${EMAIL_CODE_LENGTH}}$`);
|
|
335
|
+
/** A typed or pasted code as digits only ("481 203", "481-203" → "481203"); anything else is kept, to be refused. */
|
|
336
|
+
function normalizeEmailCode(input) {
|
|
337
|
+
return String(input ?? '').replace(/[\s-]/g, '');
|
|
338
|
+
}
|
|
339
|
+
/** Exactly six ASCII digits. */
|
|
340
|
+
function isEmailCodeShape(code) {
|
|
341
|
+
return typeof code === 'string' && EMAIL_CODE.test(code);
|
|
342
|
+
}
|
|
343
|
+
/** An email as a studio keys its customers by (unique per org): trimmed, lower case. */
|
|
344
|
+
function normalizeSignInEmail(email) {
|
|
345
|
+
return String(email ?? '').trim().toLowerCase();
|
|
346
|
+
}
|
|
347
|
+
/** Has the code outlived its ten minutes? `now` is the caller's — the core reads no clock. */
|
|
348
|
+
function emailCodeExpired(sentAt, now) {
|
|
349
|
+
return +now - +sentAt >= EMAIL_CODE_TTL_MS;
|
|
350
|
+
}
|
|
351
|
+
/** How many more codes may be tried after `wrongTries` wrong ones (0 = the code is spent). */
|
|
352
|
+
function emailCodeTriesLeft(wrongTries) {
|
|
353
|
+
return Math.max(0, EMAIL_CODE_MAX_TRIES - Math.max(0, Math.floor(wrongTries || 0)));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
var SignInLanguage;
|
|
357
|
+
(function (SignInLanguage) {
|
|
358
|
+
SignInLanguage["En"] = "en";
|
|
359
|
+
SignInLanguage["He"] = "he";
|
|
360
|
+
})(SignInLanguage || (SignInLanguage = {}));
|
|
361
|
+
function signInLanguage(lang) {
|
|
362
|
+
const primary = String(lang ?? '').trim().toLowerCase().split(/[-_]/)[0];
|
|
363
|
+
return primary === 'he' || primary === 'iw' ? SignInLanguage.He : SignInLanguage.En;
|
|
364
|
+
}
|
|
365
|
+
function fillIn(words, fill) {
|
|
366
|
+
return words.replace(/\{(\w+)\}/g, (all, key) => (key in fill ? String(fill[key]) : all));
|
|
367
|
+
}
|
|
368
|
+
var SignInWord;
|
|
369
|
+
(function (SignInWord) {
|
|
370
|
+
SignInWord["SignIn"] = "signIn";
|
|
371
|
+
SignInWord["SignInTo"] = "signInTo";
|
|
372
|
+
SignInWord["Why"] = "why";
|
|
373
|
+
SignInWord["ContinueWithGoogle"] = "continueWithGoogle";
|
|
374
|
+
SignInWord["Or"] = "or";
|
|
375
|
+
SignInWord["Email"] = "email";
|
|
376
|
+
SignInWord["EmailPlaceholder"] = "emailPlaceholder";
|
|
377
|
+
SignInWord["SendCode"] = "sendCode";
|
|
378
|
+
SignInWord["CodeSent"] = "codeSent";
|
|
379
|
+
SignInWord["Code"] = "code";
|
|
380
|
+
SignInWord["CodeValid"] = "codeValid";
|
|
381
|
+
SignInWord["SendAgain"] = "sendAgain";
|
|
382
|
+
SignInWord["Verify"] = "verify";
|
|
383
|
+
SignInWord["OtherEmail"] = "otherEmail";
|
|
384
|
+
SignInWord["Working"] = "working";
|
|
385
|
+
SignInWord["Close"] = "close";
|
|
386
|
+
SignInWord["SignOut"] = "signOut";
|
|
387
|
+
SignInWord["Account"] = "account";
|
|
388
|
+
SignInWord["YourOrders"] = "yourOrders";
|
|
389
|
+
SignInWord["Hello"] = "hello";
|
|
390
|
+
SignInWord["SignedIn"] = "signedIn";
|
|
391
|
+
SignInWord["SignedOut"] = "signedOut";
|
|
392
|
+
SignInWord["NoPassword"] = "noPassword";
|
|
393
|
+
})(SignInWord || (SignInWord = {}));
|
|
394
|
+
/** `{site}`, `{email}`, `{name}`, `{minutes}` are filled by `signInWord`. */
|
|
395
|
+
const SIGN_IN_WORDS = Object.freeze({
|
|
396
|
+
[SignInWord.SignIn]: { en: 'Sign in', he: 'התחברות' },
|
|
397
|
+
[SignInWord.SignInTo]: { en: 'Sign in to {site}', he: 'התחברות ל־{site}' },
|
|
398
|
+
[SignInWord.Why]: { en: 'See your orders and check out faster.', he: 'לראות את ההזמנות שלך ולשלם מהר יותר.' },
|
|
399
|
+
[SignInWord.ContinueWithGoogle]: { en: 'Continue with Google', he: 'המשך עם Google' },
|
|
400
|
+
[SignInWord.Or]: { en: 'or', he: 'או' },
|
|
401
|
+
[SignInWord.Email]: { en: 'Email', he: 'אימייל' },
|
|
402
|
+
[SignInWord.EmailPlaceholder]: { en: 'name@example.com', he: 'name@example.com' },
|
|
403
|
+
[SignInWord.SendCode]: { en: 'Send me a code', he: 'שלחו לי קוד' },
|
|
404
|
+
[SignInWord.CodeSent]: { en: 'We sent a 6-digit code to {email}', he: 'שלחנו קוד בן 6 ספרות אל {email}' },
|
|
405
|
+
[SignInWord.Code]: { en: 'Code', he: 'קוד' },
|
|
406
|
+
[SignInWord.CodeValid]: { en: 'Valid for {minutes} minutes', he: 'בתוקף ל־{minutes} דקות' },
|
|
407
|
+
[SignInWord.SendAgain]: { en: 'Send again', he: 'שליחה חוזרת' },
|
|
408
|
+
[SignInWord.Verify]: { en: 'Sign in', he: 'התחברות' },
|
|
409
|
+
[SignInWord.OtherEmail]: { en: 'Use another email', he: 'אימייל אחר' },
|
|
410
|
+
[SignInWord.Working]: { en: 'One moment…', he: 'רגע…' },
|
|
411
|
+
[SignInWord.Close]: { en: 'Close', he: 'סגירה' },
|
|
412
|
+
[SignInWord.SignOut]: { en: 'Sign out', he: 'התנתקות' },
|
|
413
|
+
[SignInWord.Account]: { en: 'Account', he: 'החשבון שלי' },
|
|
414
|
+
[SignInWord.YourOrders]: { en: 'Your orders', he: 'ההזמנות שלך' },
|
|
415
|
+
[SignInWord.Hello]: { en: 'Hello, {name}', he: 'שלום, {name}' },
|
|
416
|
+
[SignInWord.SignedIn]: { en: 'You are signed in.', he: 'התחברת.' },
|
|
417
|
+
[SignInWord.SignedOut]: { en: 'You are signed out.', he: 'התנתקת.' },
|
|
418
|
+
[SignInWord.NoPassword]: { en: 'No password — we email you a code.', he: 'בלי סיסמה — נשלח לך קוד במייל.' },
|
|
419
|
+
});
|
|
420
|
+
function signInWord(word, lang, fill = {}) {
|
|
421
|
+
return fillIn(SIGN_IN_WORDS[word][signInLanguage(lang)], fill);
|
|
422
|
+
}
|
|
423
|
+
// ── a refusal, said on its field ─────────────────────────────────────────────────────────────
|
|
424
|
+
/** Where in the sign-in dialog a refusal is said. */
|
|
425
|
+
var SignInSlot;
|
|
426
|
+
(function (SignInSlot) {
|
|
427
|
+
SignInSlot["Email"] = "email";
|
|
428
|
+
SignInSlot["Code"] = "code";
|
|
429
|
+
/** Under "Continue with Google". */
|
|
430
|
+
SignInSlot["Provider"] = "provider";
|
|
431
|
+
/** The dialog as a whole. */
|
|
432
|
+
SignInSlot["Dialog"] = "dialog";
|
|
433
|
+
})(SignInSlot || (SignInSlot = {}));
|
|
434
|
+
/**
|
|
435
|
+
* Every code a site's sign-in can hear: iox-cms's answers, the broker's return errors (`?iox_signin_error=`), and
|
|
436
|
+
* `network` for no answer at all.
|
|
437
|
+
*/
|
|
438
|
+
var SiteSignInRefusalCode;
|
|
439
|
+
(function (SiteSignInRefusalCode) {
|
|
440
|
+
SiteSignInRefusalCode["InvalidEmail"] = "invalid-email";
|
|
441
|
+
SiteSignInRefusalCode["CodeWrong"] = "code-wrong";
|
|
442
|
+
SiteSignInRefusalCode["CodeExpired"] = "code-expired";
|
|
443
|
+
SiteSignInRefusalCode["TooManyTries"] = "too-many-tries";
|
|
444
|
+
SiteSignInRefusalCode["RateLimited"] = "rate-limited";
|
|
445
|
+
/** The broker cannot run the provider (down, not configured, the host refused). */
|
|
446
|
+
SiteSignInRefusalCode["ProviderUnavailable"] = "provider-unavailable";
|
|
447
|
+
SiteSignInRefusalCode["Cancelled"] = "cancelled";
|
|
448
|
+
SiteSignInRefusalCode["Refused"] = "refused";
|
|
449
|
+
SiteSignInRefusalCode["Expired"] = "expired";
|
|
450
|
+
SiteSignInRefusalCode["Failed"] = "failed";
|
|
451
|
+
/** The return came back without this browser's sign-in cookie — a forged or stale return. */
|
|
452
|
+
SiteSignInRefusalCode["StateMismatch"] = "state-mismatch";
|
|
453
|
+
SiteSignInRefusalCode["Blocked"] = "blocked";
|
|
454
|
+
SiteSignInRefusalCode["NotSignedIn"] = "not-signed-in";
|
|
455
|
+
SiteSignInRefusalCode["Network"] = "network";
|
|
456
|
+
})(SiteSignInRefusalCode || (SiteSignInRefusalCode = {}));
|
|
457
|
+
const TRY_GOOGLE_AGAIN = { en: 'Google sign-in did not work. Try again, or use an email code.', he: 'ההתחברות עם Google לא הצליחה. נסו שוב, או התחברו עם קוד במייל.' };
|
|
458
|
+
const SEND_NEW_CODE = { en: 'This code has expired. Send a new one.', he: 'תוקף הקוד פג. שלחו קוד חדש.' };
|
|
459
|
+
const SIGN_IN_REFUSALS = Object.freeze({
|
|
460
|
+
[SiteSignInRefusalCode.InvalidEmail]: { slot: SignInSlot.Email, label: { en: 'Enter an email address, like name@example.com.', he: 'הקלידו כתובת אימייל, למשל name@example.com.' } },
|
|
461
|
+
[SiteSignInRefusalCode.CodeWrong]: { slot: SignInSlot.Code, label: { en: 'That code is not right. Check it and try again.', he: 'הקוד לא נכון. בדקו ונסו שוב.' } },
|
|
462
|
+
[SiteSignInRefusalCode.CodeExpired]: { slot: SignInSlot.Code, label: SEND_NEW_CODE },
|
|
463
|
+
[SiteSignInRefusalCode.TooManyTries]: { slot: SignInSlot.Code, label: { en: 'Too many wrong codes. Send a new one.', he: 'יותר מדי קודים שגויים. שלחו קוד חדש.' } },
|
|
464
|
+
[SiteSignInRefusalCode.RateLimited]: { slot: SignInSlot.Dialog, label: { en: 'Too many tries. Wait a minute and try again.', he: 'יותר מדי ניסיונות. המתינו דקה ונסו שוב.' } },
|
|
465
|
+
[SiteSignInRefusalCode.ProviderUnavailable]: { slot: SignInSlot.Provider, label: { en: 'Google sign-in is not available right now. Use an email code.', he: 'ההתחברות עם Google לא זמינה כרגע. התחברו עם קוד במייל.' } },
|
|
466
|
+
[SiteSignInRefusalCode.Cancelled]: { slot: SignInSlot.Provider, label: { en: 'Google sign-in was cancelled.', he: 'ההתחברות עם Google בוטלה.' } },
|
|
467
|
+
[SiteSignInRefusalCode.Refused]: { slot: SignInSlot.Provider, label: { en: 'Google could not confirm this account. Use an email code.', he: 'Google לא אישר את החשבון הזה. התחברו עם קוד במייל.' } },
|
|
468
|
+
[SiteSignInRefusalCode.Expired]: { slot: SignInSlot.Provider, label: { en: 'The sign-in took too long. Try again.', he: 'ההתחברות ארכה יותר מדי. נסו שוב.' } },
|
|
469
|
+
[SiteSignInRefusalCode.Failed]: { slot: SignInSlot.Provider, label: TRY_GOOGLE_AGAIN },
|
|
470
|
+
[SiteSignInRefusalCode.StateMismatch]: { slot: SignInSlot.Provider, label: TRY_GOOGLE_AGAIN },
|
|
471
|
+
[SiteSignInRefusalCode.Blocked]: { slot: SignInSlot.Dialog, label: { en: 'This account cannot sign in here. Contact the business.', he: 'החשבון הזה לא יכול להתחבר כאן. פנו לעסק.' } },
|
|
472
|
+
[SiteSignInRefusalCode.NotSignedIn]: { slot: SignInSlot.Dialog, label: { en: 'You are signed out. Sign in again.', he: 'התנתקת. התחברו שוב.' } },
|
|
473
|
+
[SiteSignInRefusalCode.Network]: { slot: SignInSlot.Dialog, label: { en: 'We could not reach the site. Try again.', he: 'לא הצלחנו להגיע לאתר. נסו שוב.' } },
|
|
474
|
+
});
|
|
475
|
+
function isSiteSignInRefusalCode(code) {
|
|
476
|
+
return typeof code === 'string' && Object.values(SiteSignInRefusalCode).includes(code);
|
|
477
|
+
}
|
|
478
|
+
/** A broker refusal as the site says it: a person never hears "return-host-refused". */
|
|
479
|
+
const FROM_BROKER = Object.freeze({
|
|
480
|
+
[BrokerRefusalCode.ReturnHostRefused]: SiteSignInRefusalCode.ProviderUnavailable,
|
|
481
|
+
[BrokerRefusalCode.UnknownProvider]: SiteSignInRefusalCode.ProviderUnavailable,
|
|
482
|
+
[BrokerRefusalCode.ProviderNotConfigured]: SiteSignInRefusalCode.ProviderUnavailable,
|
|
483
|
+
[BrokerRefusalCode.CodeUnknown]: SiteSignInRefusalCode.Expired,
|
|
484
|
+
[BrokerRefusalCode.CodeUsedOrExpired]: SiteSignInRefusalCode.Expired,
|
|
485
|
+
[BrokerRefusalCode.NotYours]: SiteSignInRefusalCode.Failed,
|
|
486
|
+
});
|
|
487
|
+
const FROM_RETURN = Object.freeze({
|
|
488
|
+
[SignInReturnError.Cancelled]: SiteSignInRefusalCode.Cancelled,
|
|
489
|
+
[SignInReturnError.Refused]: SiteSignInRefusalCode.Refused,
|
|
490
|
+
[SignInReturnError.Expired]: SiteSignInRefusalCode.Expired,
|
|
491
|
+
[SignInReturnError.Failed]: SiteSignInRefusalCode.Failed,
|
|
492
|
+
});
|
|
493
|
+
/** Any code a sign-in heard, as the site's own: a site code as is, a broker code or a return error mapped, else `failed`. */
|
|
494
|
+
function siteSignInCodeOf(code) {
|
|
495
|
+
if (isSiteSignInRefusalCode(code))
|
|
496
|
+
return code;
|
|
497
|
+
if (typeof code === 'string' && code in FROM_BROKER)
|
|
498
|
+
return FROM_BROKER[code];
|
|
499
|
+
if (typeof code === 'string' && code in FROM_RETURN)
|
|
500
|
+
return FROM_RETURN[code];
|
|
501
|
+
return SiteSignInRefusalCode.Failed;
|
|
502
|
+
}
|
|
503
|
+
/** One refusal, on its slot, in the visitor's words. */
|
|
504
|
+
function signInRefusal(code, lang) {
|
|
505
|
+
const known = siteSignInCodeOf(code);
|
|
506
|
+
const rule = SIGN_IN_REFUSALS[known];
|
|
507
|
+
return { code: known, slot: rule.slot, words: rule.label[signInLanguage(lang)] };
|
|
508
|
+
}
|
|
509
|
+
/** A refused call's body (`{ code }`) — or nothing at all (`network`) — as one refusal. The body's `message` is a log
|
|
510
|
+
* line and is never shown. A 429 with no code is `rate-limited`. */
|
|
511
|
+
function signInRefusalOf(body, lang, status) {
|
|
512
|
+
const code = body && typeof body === 'object' ? body.code : undefined;
|
|
513
|
+
if (code !== undefined)
|
|
514
|
+
return signInRefusal(code, lang);
|
|
515
|
+
if (status === 429)
|
|
516
|
+
return signInRefusal(SiteSignInRefusalCode.RateLimited, lang);
|
|
517
|
+
return signInRefusal(body === undefined || body === null ? SiteSignInRefusalCode.Network : SiteSignInRefusalCode.Failed, lang);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* @vectoriox/iox-ui/identity-core — the shared, FRAMEWORK-FREE vocabulary of signing in (commerce plan §3c, C-D5,
|
|
522
|
+
* C-D6, C-D22): who signs in and with what, the broker's ticket / redeem shapes and refusals, a studio's site sign-in
|
|
523
|
+
* routes, session claims and cookies, the email-code rules, the two address guards (open redirect, return host) and
|
|
524
|
+
* the sign-in dialog's words. The broker (iox-control-plane), the studios (iox-cms), the engine and the builder speak it.
|
|
525
|
+
* It imports nothing — a consumer maps this one entry.
|
|
526
|
+
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets,
|
|
527
|
+
* jest moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.
|
|
528
|
+
*/
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Generated bundle index. Do not edit.
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
export { BROKER_HOST, BROKER_ORIGIN, BROKER_REFUSAL_STATUS, BROKER_TICKET_PARAM, BrokerApiRoute, BrokerBrowserRoute, BrokerRefusalCode, CUSTOMER_COOKIE_PREFIX, EMAIL_CODE_LENGTH, EMAIL_CODE_MAX_TRIES, EMAIL_CODE_TTL_MINUTES, EMAIL_CODE_TTL_MS, NEXT_PATH_MAX_LENGTH, SIGN_IN_ERROR_PARAM, SIGN_IN_HANDOFF_PARAM, SIGN_IN_HANDOFF_TTL_SECONDS, SIGN_IN_NEXT_PARAM, SIGN_IN_PROVIDER_SPECS, SIGN_IN_REFUSALS, SIGN_IN_STATE_COOKIE_PREFIX, SIGN_IN_STATE_MAX_AGE_SECONDS, SIGN_IN_TICKET_TTL_SECONDS, SIGN_IN_WORDS, SITE_AUDIENCE, SITE_AUTH_ROUTES, SITE_COOKIE_PATH, SignInLanguage, SignInProtocol, SignInProvider, SignInPurpose, SignInReturnError, SignInSlot, SignInWord, SiteAuthRoute, SiteProviderRoute, SiteSignInRefusalCode, brokerApiPath, brokerBrowserUrl, brokerCallbackUrl, brokerStartUrl, customerCookieName, emailCodeExpired, emailCodeTriesLeft, hasSiteAudience, isAllowedReturnHost, isBrokerRefusalCode, isEmailCodeShape, isLoopbackHost, isSameOriginPath, isSignInProvider, isSignInPurpose, isSignInReturnError, isSiteSessionClaims, isSiteSignInRefusalCode, normalizeEmailCode, normalizeHost, normalizeSignInEmail, providerServes, readSignInReturn, safeNextPath, signInLanguage, signInRefusal, signInRefusalOf, signInStateCookieName, signInWord, siteAuthPath, siteProviderPath, siteProviderReturnUrl, siteSignInCodeOf, withSignInError, withSignInHandoff };
|
|
535
|
+
//# sourceMappingURL=vectoriox-iox-ui-identity-core.mjs.map
|