@alepha/react 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.cjs +118 -86
- package/dist/index.d.ts +70 -44
- package/dist/index.js +120 -88
- package/dist/{useAuth-DOVx2kqa.cjs → useAuth-B9ypF48n.cjs} +112 -44
- package/dist/{useAuth-i7wbKVrt.js → useAuth-Ps01oe8e.js} +113 -45
- package/package.json +13 -12
package/dist/index.browser.cjs
CHANGED
package/dist/index.browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { autoInject, $inject, Alepha } from '@alepha/core';
|
|
2
|
-
import { a as $page, P as PageDescriptorProvider, l as ReactBrowserProvider, A as Auth } from './useAuth-
|
|
3
|
-
export { $ as $auth, L as Link, N as NestedView, R as Router, b as RouterContext, d as RouterHookApi, c as RouterLayerContext, p as pageDescriptorKey, j as useActive, k as useAuth, e as useClient, u as useInject, f as useQueryParams, g as useRouter, h as useRouterEvents, i as useRouterState } from './useAuth-
|
|
2
|
+
import { a as $page, P as PageDescriptorProvider, l as ReactBrowserProvider, A as Auth } from './useAuth-Ps01oe8e.js';
|
|
3
|
+
export { $ as $auth, L as Link, N as NestedView, R as Router, b as RouterContext, d as RouterHookApi, c as RouterLayerContext, p as pageDescriptorKey, j as useActive, k as useAuth, e as useClient, u as useInject, f as useQueryParams, g as useRouter, h as useRouterEvents, i as useRouterState } from './useAuth-Ps01oe8e.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@alepha/server';
|
package/dist/index.cjs
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@alepha/core');
|
|
4
4
|
var server = require('@alepha/server');
|
|
5
|
-
var useAuth = require('./useAuth-
|
|
5
|
+
var useAuth = require('./useAuth-B9ypF48n.cjs');
|
|
6
6
|
var openidClient = require('openid-client');
|
|
7
7
|
var node_fs = require('node:fs');
|
|
8
8
|
var promises = require('node:fs/promises');
|
|
9
9
|
var node_path = require('node:path');
|
|
10
|
+
var cheerio = require('cheerio');
|
|
10
11
|
var server$1 = require('react-dom/server');
|
|
11
12
|
require('react/jsx-runtime');
|
|
12
13
|
require('react');
|
|
@@ -16,7 +17,7 @@ require('path-to-regexp');
|
|
|
16
17
|
class ReactAuthProvider {
|
|
17
18
|
log = core.$logger();
|
|
18
19
|
alepha = core.$inject(core.Alepha);
|
|
19
|
-
|
|
20
|
+
serverCookieProvider = core.$inject(server.ServerCookieProvider);
|
|
20
21
|
authProviders = [];
|
|
21
22
|
authorizationCode = server.$cookie({
|
|
22
23
|
name: "authorizationCode",
|
|
@@ -54,23 +55,30 @@ class ReactAuthProvider {
|
|
|
54
55
|
name: "configure",
|
|
55
56
|
handler: async () => {
|
|
56
57
|
const auths = this.alepha.getDescriptorValues(useAuth.$auth);
|
|
57
|
-
for (const
|
|
58
|
-
const options =
|
|
58
|
+
for (const { value, key, instance } of auths) {
|
|
59
|
+
const options = value.options;
|
|
59
60
|
if (options.oidc) {
|
|
61
|
+
this.log.debug(
|
|
62
|
+
`Discover OIDC auth provider -> ${options.oidc.issuer}`
|
|
63
|
+
);
|
|
64
|
+
const client = await openidClient.discovery(
|
|
65
|
+
new URL(options.oidc.issuer),
|
|
66
|
+
options.oidc.clientId,
|
|
67
|
+
{
|
|
68
|
+
client_secret: options.oidc.clientSecret
|
|
69
|
+
},
|
|
70
|
+
void 0,
|
|
71
|
+
{
|
|
72
|
+
execute: [openidClient.allowInsecureRequests]
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
instance[key].jwks = () => {
|
|
76
|
+
return client.serverMetadata().jwks_uri;
|
|
77
|
+
};
|
|
60
78
|
this.authProviders.push({
|
|
61
|
-
name: options.name ??
|
|
79
|
+
name: options.name ?? key,
|
|
62
80
|
redirectUri: options.oidc.redirectUri ?? "/api/_oauth/callback",
|
|
63
|
-
client
|
|
64
|
-
new URL(options.oidc.issuer),
|
|
65
|
-
options.oidc.clientId,
|
|
66
|
-
{
|
|
67
|
-
client_secret: options.oidc.clientSecret
|
|
68
|
-
},
|
|
69
|
-
void 0,
|
|
70
|
-
{
|
|
71
|
-
execute: [openidClient.allowInsecureRequests]
|
|
72
|
-
}
|
|
73
|
-
)
|
|
81
|
+
client
|
|
74
82
|
});
|
|
75
83
|
}
|
|
76
84
|
}
|
|
@@ -79,21 +87,19 @@ class ReactAuthProvider {
|
|
|
79
87
|
/**
|
|
80
88
|
* Configure Fastify to forward Session Access Token to Header Authorization.
|
|
81
89
|
*/
|
|
82
|
-
|
|
83
|
-
name: "
|
|
84
|
-
after: this.
|
|
85
|
-
handler: async (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
req.headers.authorization = `Bearer ${tokens.access_token}`;
|
|
91
|
-
}
|
|
92
|
-
if (this.user.get(req.cookies) && !this.tokens.get(req.cookies)) {
|
|
93
|
-
this.user.del(req.cookies);
|
|
94
|
-
}
|
|
90
|
+
onRequest = core.$hook({
|
|
91
|
+
name: "server:onRequest",
|
|
92
|
+
after: this.serverCookieProvider,
|
|
93
|
+
handler: async ({ request }) => {
|
|
94
|
+
if (request.cookies && !this.isViteFile(request.url.pathname) && !!this.authProviders.length) {
|
|
95
|
+
const tokens = await this.refresh(request.cookies);
|
|
96
|
+
if (tokens) {
|
|
97
|
+
request.headers.rep("authorization", `Bearer ${tokens.access_token}`);
|
|
95
98
|
}
|
|
96
|
-
|
|
99
|
+
if (this.user.get(request.cookies) && !this.tokens.get(request.cookies)) {
|
|
100
|
+
this.user.del(request.cookies);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
});
|
|
99
105
|
/**
|
|
@@ -122,7 +128,9 @@ class ReactAuthProvider {
|
|
|
122
128
|
});
|
|
123
129
|
return newTokens;
|
|
124
130
|
} catch (e) {
|
|
125
|
-
|
|
131
|
+
if (e instanceof Error) {
|
|
132
|
+
this.log.warn("Failed to refresh token", e.message);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
this.tokens.del(cookies);
|
|
@@ -316,13 +324,13 @@ const envSchema$1 = core.t.object({
|
|
|
316
324
|
REACT_SERVER_DIST: core.t.string({ default: "client" }),
|
|
317
325
|
REACT_SERVER_PREFIX: core.t.string({ default: "" }),
|
|
318
326
|
REACT_SSR_ENABLED: core.t.boolean({ default: false }),
|
|
319
|
-
|
|
327
|
+
REACT_ROOT_ID: core.t.string({ default: "root" })
|
|
320
328
|
});
|
|
321
329
|
class ReactServerProvider {
|
|
322
330
|
log = core.$logger();
|
|
323
331
|
alepha = core.$inject(core.Alepha);
|
|
324
332
|
router = core.$inject(useAuth.Router);
|
|
325
|
-
|
|
333
|
+
serverProvider = core.$inject(server.ServerProvider);
|
|
326
334
|
env = core.$inject(envSchema$1);
|
|
327
335
|
configure = core.$hook({
|
|
328
336
|
name: "configure",
|
|
@@ -330,7 +338,9 @@ class ReactServerProvider {
|
|
|
330
338
|
await this.configureRoutes();
|
|
331
339
|
}
|
|
332
340
|
});
|
|
341
|
+
id = Math.random().toString(36).substring(2, 7);
|
|
333
342
|
async configureRoutes() {
|
|
343
|
+
this.alepha.state("ReactServerProvider.ssr", false);
|
|
334
344
|
if (this.alepha.isTest()) {
|
|
335
345
|
this.processDescriptors();
|
|
336
346
|
}
|
|
@@ -338,14 +348,15 @@ class ReactServerProvider {
|
|
|
338
348
|
return;
|
|
339
349
|
}
|
|
340
350
|
if (process.env.VITE_ALEPHA_DEV === "true") {
|
|
351
|
+
const url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;
|
|
341
352
|
this.log.info("SSR (vite) OK");
|
|
342
|
-
|
|
343
|
-
|
|
353
|
+
this.alepha.state("ReactServerProvider.ssr", true);
|
|
354
|
+
const templateUrl = `${url}/index.html`;
|
|
344
355
|
const route2 = this.createHandler(
|
|
345
|
-
() => fetch(templateUrl).then((it) => it.text()).catch(() => void 0)
|
|
356
|
+
() => fetch(templateUrl).then((it) => it.text()).catch(() => void 0)
|
|
346
357
|
);
|
|
347
|
-
await this.
|
|
348
|
-
await this.
|
|
358
|
+
await this.serverProvider.route(route2);
|
|
359
|
+
await this.serverProvider.route({
|
|
349
360
|
...route2,
|
|
350
361
|
url: "*"
|
|
351
362
|
});
|
|
@@ -367,37 +378,16 @@ class ReactServerProvider {
|
|
|
367
378
|
this.log.warn("Missing static files, SSR will be disabled");
|
|
368
379
|
return;
|
|
369
380
|
}
|
|
370
|
-
await this.
|
|
381
|
+
await this.serverProvider.serve(this.createStaticHandler(root));
|
|
371
382
|
}
|
|
372
|
-
const template = this.
|
|
373
|
-
this.alepha.state("ReactServerProvider.template") ?? await promises.readFile(node_path.join(root, "index.html"), "utf-8")
|
|
374
|
-
);
|
|
383
|
+
const template = this.alepha.state("ReactServerProvider.template") ?? await promises.readFile(node_path.join(root, "index.html"), "utf-8");
|
|
375
384
|
const route = this.createHandler(async () => template);
|
|
376
|
-
await this.
|
|
377
|
-
await this.
|
|
385
|
+
await this.serverProvider.route(route);
|
|
386
|
+
await this.serverProvider.route({
|
|
378
387
|
...route,
|
|
379
388
|
url: "*"
|
|
380
389
|
});
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Check if the template contains the outlet.
|
|
384
|
-
*
|
|
385
|
-
* @param template
|
|
386
|
-
* @protected
|
|
387
|
-
*/
|
|
388
|
-
checkTemplate(template) {
|
|
389
|
-
if (!template.includes(this.env.REACT_SSR_OUTLET)) {
|
|
390
|
-
if (!template.includes('<div id="root"></div>')) {
|
|
391
|
-
throw new Error(
|
|
392
|
-
`Missing React SSR outlet in index.html, please add ${this.env.REACT_SSR_OUTLET} to the index.html file`
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
return template.replace(
|
|
396
|
-
`<div id="root"></div>`,
|
|
397
|
-
`<div id="root">${this.env.REACT_SSR_OUTLET}</div>`
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
return template;
|
|
390
|
+
this.alepha.state("ReactServerProvider.ssr", true);
|
|
401
391
|
}
|
|
402
392
|
/**
|
|
403
393
|
*
|
|
@@ -438,6 +428,10 @@ class ReactServerProvider {
|
|
|
438
428
|
}
|
|
439
429
|
};
|
|
440
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
*
|
|
433
|
+
* @protected
|
|
434
|
+
*/
|
|
441
435
|
processDescriptors() {
|
|
442
436
|
const pages = this.alepha.getDescriptorValues(useAuth.$page);
|
|
443
437
|
for (const { key, instance, value } of pages) {
|
|
@@ -478,7 +472,20 @@ class ReactServerProvider {
|
|
|
478
472
|
* @param template
|
|
479
473
|
* @param args
|
|
480
474
|
*/
|
|
481
|
-
async ssr(url, template
|
|
475
|
+
async ssr(url, template, args = {}) {
|
|
476
|
+
const hasAuth = this.alepha.has(ReactAuthProvider);
|
|
477
|
+
if (!args.user && args.cookies && hasAuth) {
|
|
478
|
+
const auth = this.alepha.get(ReactAuthProvider);
|
|
479
|
+
args.user = auth.user.get(args.cookies);
|
|
480
|
+
if (args.user) {
|
|
481
|
+
args.user.roles = [];
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (this.alepha.has(server.ServerLinksProvider) && hasAuth) {
|
|
485
|
+
const srv = this.alepha.get(server.ServerLinksProvider);
|
|
486
|
+
args.links = await srv.links();
|
|
487
|
+
this.alepha.als.set("links", args.links);
|
|
488
|
+
}
|
|
482
489
|
const { element, layers, redirect, context } = await this.router.render(
|
|
483
490
|
url.pathname + url.search,
|
|
484
491
|
{
|
|
@@ -493,42 +500,67 @@ class ReactServerProvider {
|
|
|
493
500
|
}
|
|
494
501
|
});
|
|
495
502
|
}
|
|
496
|
-
const
|
|
503
|
+
const html = server$1.renderToString(element);
|
|
504
|
+
const $ = cheerio.load(template);
|
|
497
505
|
const script = `<script>window.__ssr=${JSON.stringify({
|
|
506
|
+
links: args.links,
|
|
498
507
|
layers: layers.map((it) => ({
|
|
499
508
|
...it,
|
|
509
|
+
error: it.error ? {
|
|
510
|
+
...it.error,
|
|
511
|
+
name: it.error.name,
|
|
512
|
+
message: it.error.message,
|
|
513
|
+
stack: it.error.stack
|
|
514
|
+
// TODO: Hide stack in production ?
|
|
515
|
+
} : void 0,
|
|
500
516
|
index: void 0,
|
|
501
517
|
path: void 0,
|
|
502
518
|
element: void 0
|
|
503
519
|
}))
|
|
504
520
|
})}<\/script>`;
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
521
|
+
const body = $("body");
|
|
522
|
+
const root = body.find(`#${this.env.REACT_ROOT_ID}`);
|
|
523
|
+
if (root.length) {
|
|
524
|
+
root.html(html);
|
|
525
|
+
} else {
|
|
526
|
+
body.prepend(`<div id="${this.env.REACT_ROOT_ID}">${html}</div>`);
|
|
508
527
|
}
|
|
509
|
-
|
|
510
|
-
|
|
528
|
+
body.append(script);
|
|
529
|
+
if (context.head) {
|
|
530
|
+
this.renderHeadContext($, context.head);
|
|
511
531
|
}
|
|
512
|
-
|
|
513
|
-
return new Response(template, {
|
|
532
|
+
return new Response($.html(), {
|
|
514
533
|
headers: { "Content-Type": "text/html" }
|
|
515
534
|
});
|
|
516
535
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
536
|
+
renderHeadContext($, headContext) {
|
|
537
|
+
const head = $("head");
|
|
538
|
+
if (head) {
|
|
539
|
+
if (headContext.title) {
|
|
540
|
+
head.find("title").remove();
|
|
541
|
+
head.append(`<title>${headContext.title}</title>`);
|
|
542
|
+
}
|
|
543
|
+
if (headContext.meta) {
|
|
544
|
+
for (const it of headContext.meta) {
|
|
545
|
+
const meta = head.find(`meta[name="${it.name}"]`);
|
|
546
|
+
if (meta.length) {
|
|
547
|
+
meta.attr("content", it.content);
|
|
548
|
+
} else {
|
|
549
|
+
head.append(`<meta name="${it.name}" content="${it.content}" />`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (headContext.htmlAttributes) {
|
|
555
|
+
for (const [key, value] of Object.entries(headContext.htmlAttributes)) {
|
|
556
|
+
$("html").attr(key, value);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (headContext.bodyAttributes) {
|
|
560
|
+
for (const [key, value] of Object.entries(headContext.bodyAttributes)) {
|
|
561
|
+
$("body").attr(key, value);
|
|
529
562
|
}
|
|
530
563
|
}
|
|
531
|
-
return template;
|
|
532
564
|
}
|
|
533
565
|
}
|
|
534
566
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as _alepha_core from '@alepha/core';
|
|
2
|
-
import { EventEmitter, Alepha,
|
|
2
|
+
import { EventEmitter, Alepha, Static as Static$1, TSchema as TSchema$1, KIND, Async, Class, TObject as TObject$1 } from '@alepha/core';
|
|
3
3
|
import * as react from 'react';
|
|
4
|
-
import react__default, { ReactNode,
|
|
4
|
+
import react__default, { ReactNode, FC, AnchorHTMLAttributes } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { UserAccountToken } from '@alepha/security';
|
|
7
7
|
import * as _alepha_server from '@alepha/server';
|
|
8
|
-
import {
|
|
8
|
+
import { HttpLink, ServerCookieProvider, CookieManager, HttpClient, ServerProvider, ServeDescriptorOptions, RouteObject } from '@alepha/server';
|
|
9
9
|
import { Root } from 'react-dom/client';
|
|
10
10
|
import { MatchFunction, ParamData } from 'path-to-regexp';
|
|
11
11
|
import { Configuration } from 'openid-client';
|
|
12
|
+
import { CheerioAPI } from 'cheerio';
|
|
12
13
|
|
|
13
14
|
/** Symbol key applied to readonly types */
|
|
14
15
|
declare const ReadonlyKind: unique symbol;
|
|
@@ -149,13 +150,7 @@ interface NestedViewProps {
|
|
|
149
150
|
* @param props
|
|
150
151
|
* @constructor
|
|
151
152
|
*/
|
|
152
|
-
declare const NestedView: (props: NestedViewProps) => string | number | boolean | react.ReactElement<any, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null;
|
|
153
|
-
|
|
154
|
-
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
155
|
-
to: string;
|
|
156
|
-
children?: react__default.ReactNode;
|
|
157
|
-
}
|
|
158
|
-
declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element;
|
|
153
|
+
declare const NestedView: (props: NestedViewProps) => string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
|
|
159
154
|
|
|
160
155
|
declare class Router extends EventEmitter<RouterEvents> {
|
|
161
156
|
protected readonly log: _alepha_core.Logger;
|
|
@@ -348,6 +343,10 @@ interface Layer {
|
|
|
348
343
|
*
|
|
349
344
|
*/
|
|
350
345
|
props?: Record<string, any>;
|
|
346
|
+
/**
|
|
347
|
+
*
|
|
348
|
+
*/
|
|
349
|
+
error?: Error;
|
|
351
350
|
/**
|
|
352
351
|
*
|
|
353
352
|
*/
|
|
@@ -430,7 +429,7 @@ interface RouterRenderContext {
|
|
|
430
429
|
/**
|
|
431
430
|
*
|
|
432
431
|
*/
|
|
433
|
-
|
|
432
|
+
head?: RouterRenderHeadContext;
|
|
434
433
|
}
|
|
435
434
|
interface RouterRenderOptions extends RouterMatchOptions {
|
|
436
435
|
/**
|
|
@@ -456,7 +455,7 @@ interface RouterStackItem {
|
|
|
456
455
|
*/
|
|
457
456
|
error?: Error;
|
|
458
457
|
}
|
|
459
|
-
interface
|
|
458
|
+
interface RouterRenderHeadContext {
|
|
460
459
|
/**
|
|
461
460
|
*
|
|
462
461
|
*/
|
|
@@ -464,15 +463,15 @@ interface RouterRenderHelmetContext {
|
|
|
464
463
|
/**
|
|
465
464
|
*
|
|
466
465
|
*/
|
|
467
|
-
|
|
468
|
-
attributes?: Record<string, string>;
|
|
469
|
-
};
|
|
466
|
+
titleSeparator?: string;
|
|
470
467
|
/**
|
|
471
|
-
*
|
|
468
|
+
* Add html attributes to the <html> tag.
|
|
472
469
|
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
470
|
+
htmlAttributes?: Record<string, string>;
|
|
471
|
+
/**
|
|
472
|
+
* Add html attributes to the <body> tag.
|
|
473
|
+
*/
|
|
474
|
+
bodyAttributes?: Record<string, string>;
|
|
476
475
|
/**
|
|
477
476
|
*
|
|
478
477
|
*/
|
|
@@ -503,7 +502,7 @@ interface RouterRenderResult {
|
|
|
503
502
|
declare class ReactAuthProvider {
|
|
504
503
|
protected readonly log: _alepha_core.Logger;
|
|
505
504
|
protected readonly alepha: Alepha;
|
|
506
|
-
protected readonly
|
|
505
|
+
protected readonly serverCookieProvider: ServerCookieProvider;
|
|
507
506
|
protected authProviders: AuthProvider[];
|
|
508
507
|
protected readonly authorizationCode: _alepha_server.CookieDescriptor<TObject<{
|
|
509
508
|
codeVerifier: TOptional<TString>;
|
|
@@ -517,7 +516,7 @@ declare class ReactAuthProvider {
|
|
|
517
516
|
scope: TOptional<TString>;
|
|
518
517
|
issued_at: TOptional<TNumber>;
|
|
519
518
|
}>>;
|
|
520
|
-
|
|
519
|
+
readonly user: _alepha_server.CookieDescriptor<TObject<{
|
|
521
520
|
id: TString;
|
|
522
521
|
name: TOptional<TString>;
|
|
523
522
|
email: TOptional<TString>;
|
|
@@ -526,7 +525,7 @@ declare class ReactAuthProvider {
|
|
|
526
525
|
/**
|
|
527
526
|
* Configure Fastify to forward Session Access Token to Header Authorization.
|
|
528
527
|
*/
|
|
529
|
-
protected readonly
|
|
528
|
+
protected readonly onRequest: _alepha_core.HookDescriptor<"server:onRequest">;
|
|
530
529
|
/**
|
|
531
530
|
*
|
|
532
531
|
* @param cookies
|
|
@@ -611,12 +610,23 @@ interface ReactHydrationState {
|
|
|
611
610
|
user?: ReactUser;
|
|
612
611
|
auth?: "server" | "client";
|
|
613
612
|
layers?: PreviousLayerData[];
|
|
613
|
+
links?: HttpLink[];
|
|
614
614
|
}
|
|
615
615
|
|
|
616
|
+
declare const envSchema$2: _alepha_core.TObject<{
|
|
617
|
+
REACT_ROOT_ID: TString;
|
|
618
|
+
}>;
|
|
619
|
+
declare module "@alepha/core" {
|
|
620
|
+
interface Env extends Partial<Static$1<typeof envSchema$2>> {
|
|
621
|
+
}
|
|
622
|
+
}
|
|
616
623
|
declare class ReactBrowserProvider {
|
|
617
624
|
protected readonly log: _alepha_core.Logger;
|
|
618
625
|
protected readonly client: HttpClient;
|
|
619
626
|
protected readonly router: Router;
|
|
627
|
+
protected readonly env: {
|
|
628
|
+
REACT_ROOT_ID: string;
|
|
629
|
+
};
|
|
620
630
|
protected root: Root;
|
|
621
631
|
transitioning?: {
|
|
622
632
|
to: string;
|
|
@@ -655,8 +665,15 @@ declare class ReactBrowserProvider {
|
|
|
655
665
|
previous?: PreviousLayerData[];
|
|
656
666
|
}): Promise<{
|
|
657
667
|
url: string;
|
|
668
|
+
context: RouterRenderContext;
|
|
658
669
|
}>;
|
|
659
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Render the helmet context.
|
|
672
|
+
*
|
|
673
|
+
* @param ctx
|
|
674
|
+
* @protected
|
|
675
|
+
*/
|
|
676
|
+
protected renderHeadContext(ctx: RouterRenderHeadContext): void;
|
|
660
677
|
/**
|
|
661
678
|
* Get embedded layers from the server.
|
|
662
679
|
*
|
|
@@ -674,11 +691,6 @@ declare class ReactBrowserProvider {
|
|
|
674
691
|
* @protected
|
|
675
692
|
*/
|
|
676
693
|
protected ready: _alepha_core.HookDescriptor<"ready">;
|
|
677
|
-
/**
|
|
678
|
-
*
|
|
679
|
-
* @protected
|
|
680
|
-
*/
|
|
681
|
-
protected stop: _alepha_core.HookDescriptor<"stop">;
|
|
682
694
|
}
|
|
683
695
|
/**
|
|
684
696
|
*
|
|
@@ -815,12 +827,16 @@ interface PageDescriptorOptions<TConfig extends PageDescriptorConfigSchema = Pag
|
|
|
815
827
|
/**
|
|
816
828
|
*
|
|
817
829
|
*/
|
|
818
|
-
|
|
830
|
+
can?: () => boolean;
|
|
831
|
+
/**
|
|
832
|
+
*
|
|
833
|
+
*/
|
|
834
|
+
head?: RouterRenderHeadContext | ((props: TProps, previous?: RouterRenderHeadContext) => RouterRenderHeadContext);
|
|
819
835
|
/**
|
|
820
836
|
*
|
|
821
837
|
*/
|
|
822
838
|
notFoundHandler?: FC<{
|
|
823
|
-
|
|
839
|
+
url: string;
|
|
824
840
|
}>;
|
|
825
841
|
/**
|
|
826
842
|
*
|
|
@@ -833,6 +849,7 @@ interface PageDescriptorOptions<TConfig extends PageDescriptorConfigSchema = Pag
|
|
|
833
849
|
interface PageContext {
|
|
834
850
|
user?: UserAccountToken;
|
|
835
851
|
cookies?: CookieManager;
|
|
852
|
+
links?: HttpLink[];
|
|
836
853
|
}
|
|
837
854
|
interface PageDescriptorConfigValue<TConfig extends PageDescriptorConfigSchema = PageDescriptorConfigSchema> {
|
|
838
855
|
query: TConfig["query"] extends TSchema$1 ? Static$1<TConfig["query"]> : Record<string, string>;
|
|
@@ -857,6 +874,12 @@ declare const $page: {
|
|
|
857
874
|
[KIND]: string;
|
|
858
875
|
};
|
|
859
876
|
|
|
877
|
+
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
878
|
+
to: string | PageDescriptor;
|
|
879
|
+
children?: react__default.ReactNode;
|
|
880
|
+
}
|
|
881
|
+
declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
|
|
882
|
+
|
|
860
883
|
interface RouterContextValue {
|
|
861
884
|
router: Router;
|
|
862
885
|
alepha: Alepha;
|
|
@@ -875,7 +898,10 @@ declare class Auth {
|
|
|
875
898
|
alepha: Alepha;
|
|
876
899
|
log: _alepha_core.Logger;
|
|
877
900
|
client: HttpClient;
|
|
878
|
-
|
|
901
|
+
slugs: {
|
|
902
|
+
login: string;
|
|
903
|
+
logout: string;
|
|
904
|
+
};
|
|
879
905
|
start: _alepha_core.HookDescriptor<"start">;
|
|
880
906
|
login: (provider?: string) => void;
|
|
881
907
|
logout: () => void;
|
|
@@ -894,6 +920,7 @@ interface AuthDescriptorOptions {
|
|
|
894
920
|
interface AuthDescriptor {
|
|
895
921
|
[KIND]: typeof KEY;
|
|
896
922
|
options: AuthDescriptorOptions;
|
|
923
|
+
jwks: () => string;
|
|
897
924
|
}
|
|
898
925
|
declare const $auth: {
|
|
899
926
|
(options: AuthDescriptorOptions): AuthDescriptor;
|
|
@@ -962,47 +989,46 @@ declare const envSchema$1: TObject<{
|
|
|
962
989
|
REACT_SERVER_DIST: TString;
|
|
963
990
|
REACT_SERVER_PREFIX: TString;
|
|
964
991
|
REACT_SSR_ENABLED: TBoolean;
|
|
965
|
-
|
|
992
|
+
REACT_ROOT_ID: TString;
|
|
966
993
|
}>;
|
|
967
994
|
declare module "@alepha/core" {
|
|
968
995
|
interface Env extends Partial<Static$1<typeof envSchema$1>> {
|
|
969
996
|
}
|
|
970
997
|
interface State {
|
|
971
998
|
"ReactServerProvider.template"?: string;
|
|
999
|
+
"ReactServerProvider.ssr"?: boolean;
|
|
972
1000
|
}
|
|
973
1001
|
}
|
|
974
1002
|
declare class ReactServerProvider {
|
|
975
1003
|
protected readonly log: _alepha_core.Logger;
|
|
976
1004
|
protected readonly alepha: Alepha;
|
|
977
1005
|
protected readonly router: Router;
|
|
978
|
-
protected readonly
|
|
1006
|
+
protected readonly serverProvider: ServerProvider;
|
|
979
1007
|
protected readonly env: {
|
|
1008
|
+
REACT_ROOT_ID: string;
|
|
980
1009
|
REACT_SERVER_DIST: string;
|
|
981
1010
|
REACT_SERVER_PREFIX: string;
|
|
982
1011
|
REACT_SSR_ENABLED: boolean;
|
|
983
|
-
REACT_SSR_OUTLET: string;
|
|
984
1012
|
};
|
|
985
1013
|
protected readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
1014
|
+
id: string;
|
|
986
1015
|
protected configureRoutes(): Promise<void>;
|
|
987
1016
|
/**
|
|
988
|
-
* Check if the template contains the outlet.
|
|
989
1017
|
*
|
|
990
|
-
* @param
|
|
1018
|
+
* @param root
|
|
991
1019
|
* @protected
|
|
992
1020
|
*/
|
|
993
|
-
protected
|
|
1021
|
+
protected createStaticHandler(root: string): ServeDescriptorOptions;
|
|
994
1022
|
/**
|
|
995
1023
|
*
|
|
996
|
-
* @param
|
|
1024
|
+
* @param templateLoader
|
|
997
1025
|
* @protected
|
|
998
1026
|
*/
|
|
999
|
-
protected
|
|
1027
|
+
protected createHandler(templateLoader: () => Promise<string | undefined>): RouteObject;
|
|
1000
1028
|
/**
|
|
1001
1029
|
*
|
|
1002
|
-
* @param templateLoader
|
|
1003
1030
|
* @protected
|
|
1004
1031
|
*/
|
|
1005
|
-
protected createHandler(templateLoader: () => Promise<string | undefined>): CreateRoute;
|
|
1006
1032
|
protected processDescriptors(): void;
|
|
1007
1033
|
/**
|
|
1008
1034
|
*
|
|
@@ -1016,8 +1042,8 @@ declare class ReactServerProvider {
|
|
|
1016
1042
|
* @param template
|
|
1017
1043
|
* @param args
|
|
1018
1044
|
*/
|
|
1019
|
-
ssr(url: URL, template
|
|
1020
|
-
protected
|
|
1045
|
+
ssr(url: URL, template: string, args?: PageContext): Promise<Response>;
|
|
1046
|
+
protected renderHeadContext($: CheerioAPI, headContext: RouterRenderHeadContext): void;
|
|
1021
1047
|
}
|
|
1022
1048
|
|
|
1023
1049
|
declare class RedirectionError extends Error {
|
|
@@ -1040,4 +1066,4 @@ declare class ReactModule {
|
|
|
1040
1066
|
constructor();
|
|
1041
1067
|
}
|
|
1042
1068
|
|
|
1043
|
-
export { $auth, $page, type AnchorProps, Auth, type AuthDescriptor, type AuthDescriptorOptions, type AuthHook, type AuthProvider, type HrefLike, type Layer, Link, NestedView, type PageContext, type PageDescriptor, type PageDescriptorConfigSchema, type PageDescriptorConfigValue, type PageDescriptorOptions, PageDescriptorProvider, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactAuthProvider, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, type ReactUser, RedirectionError, Router, RouterContext, type RouterContextValue, type RouterEvents, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterMatchOptions, type RouterRenderContext, type
|
|
1069
|
+
export { $auth, $page, type AnchorProps, Auth, type AuthDescriptor, type AuthDescriptorOptions, type AuthHook, type AuthProvider, type HrefLike, type Layer, Link, NestedView, type PageContext, type PageDescriptor, type PageDescriptorConfigSchema, type PageDescriptorConfigValue, type PageDescriptorOptions, PageDescriptorProvider, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactAuthProvider, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, type ReactUser, RedirectionError, Router, RouterContext, type RouterContextValue, type RouterEvents, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterMatchOptions, type RouterRenderContext, type RouterRenderHeadContext, type RouterRenderOptions, type RouterRenderResult, type RouterStackItem, type RouterState, type SessionAuthorizationCode, type SessionTokens, type TPropsDefault, type TPropsParentDefault, type UseActiveHook, type UseQueryParamsHookOptions, envSchema$1 as envSchema, pageDescriptorKey, useActive, useAuth, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
|