@owlmeans/web-client 0.1.1 → 0.1.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/LICENSE +1 -1
- package/build/components/dispatcher/index.d.ts +2 -0
- package/build/components/dispatcher/index.d.ts.map +1 -1
- package/build/components/dispatcher/index.js +1 -0
- package/build/components/dispatcher/index.js.map +1 -1
- package/build/components/dispatcher/parametrise.d.ts +5 -0
- package/build/components/dispatcher/parametrise.d.ts.map +1 -0
- package/build/components/dispatcher/parametrise.js +24 -0
- package/build/components/dispatcher/parametrise.js.map +1 -0
- package/build/components/dispatcher/simplified.d.ts +1 -0
- package/build/components/dispatcher/simplified.d.ts.map +1 -0
- package/build/components/dispatcher/simplified.js +2 -0
- package/build/components/dispatcher/simplified.js.map +1 -0
- package/build/components/dispatcher/types.d.ts +6 -0
- package/build/components/dispatcher/types.d.ts.map +1 -0
- package/build/components/dispatcher/types.js +2 -0
- package/build/components/dispatcher/types.js.map +1 -0
- package/build/middleware.d.ts +3 -0
- package/build/middleware.d.ts.map +1 -0
- package/build/middleware.js +44 -0
- package/build/middleware.js.map +1 -0
- package/build/service.d.ts +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js +3 -2
- package/build/service.js.map +1 -1
- package/package.json +18 -17
- package/src/components/dispatcher/index.ts +2 -0
- package/src/components/dispatcher/parametrise.tsx +28 -0
- package/src/components/dispatcher/types.ts +6 -0
- package/src/middleware.ts +51 -0
- package/src/service.ts +7 -6
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 OwlMeans Common — Fullstack typescript framework
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/dispatcher/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/dispatcher/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/dispatcher/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/dispatcher/index.ts"],"names":[],"mappings":"AAEA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RoutedComponent } from "@owlmeans/client";
|
|
2
|
+
import type { DispatcherProps } from "@owlmeans/client-auth";
|
|
3
|
+
import { ParametrisedProps } from "./types.js";
|
|
4
|
+
export declare const parametriseDispatcher: (def: Partial<ParametrisedProps>, Com?: RoutedComponent<DispatcherProps>) => (props: ParametrisedProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
//# sourceMappingURL=parametrise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parametrise.d.ts","sourceRoot":"","sources":["../../../src/components/dispatcher/parametrise.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAI5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,qBAAqB,GAAI,KAAK,OAAO,CAAC,iBAAiB,CAAC,EAAE,MAAM,eAAe,CAAC,eAAe,CAAC,MAEnG,OAAO,iBAAiB,4CAiBjC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { Dispatcher } from "./component.js";
|
|
4
|
+
export const parametriseDispatcher = (def, Com) => {
|
|
5
|
+
console.log('Parametrising dispatcher with', def);
|
|
6
|
+
return (props) => {
|
|
7
|
+
console.log('Rendering parametrised dispatcher with', props);
|
|
8
|
+
const _props = useMemo(() => {
|
|
9
|
+
let payload = undefined;
|
|
10
|
+
if (def.payload != null) {
|
|
11
|
+
payload = def.payload;
|
|
12
|
+
}
|
|
13
|
+
if (props.payload != null) {
|
|
14
|
+
payload ??= {};
|
|
15
|
+
Object.assign(payload, props.payload);
|
|
16
|
+
}
|
|
17
|
+
return { ...def, ...props, payload };
|
|
18
|
+
}, [props]);
|
|
19
|
+
console.log('Computed dispatcher props', _props);
|
|
20
|
+
Com ??= Dispatcher;
|
|
21
|
+
return _jsx(Com, { ..._props });
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=parametrise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parametrise.js","sourceRoot":"","sources":["../../../src/components/dispatcher/parametrise.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAG3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAA+B,EAAE,GAAsC,EAAG,EAAE;IAChH,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;IACjD,OAAO,CAAC,KAAwB,EAAE,EAAE;QAClC,OAAO,CAAC,GAAG,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAA;QAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;YAC1B,IAAI,OAAO,GAA4B,SAAS,CAAA;YAChD,IAAI,GAAG,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;gBACxB,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;YACvB,CAAC;YACD,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC1B,OAAO,KAAK,EAAE,CAAA;gBACd,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;YACvC,CAAC;YACD,OAAO,EAAE,GAAG,GAAG,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAA;QACtC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;QACX,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAA;QAChD,GAAG,KAAK,UAAU,CAAA;QAClB,OAAO,KAAC,GAAG,OAAK,MAAM,GAAI,CAAA;IAC5B,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=simplified.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplified.d.ts","sourceRoot":"","sources":["../../../src/components/dispatcher/simplified.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplified.js","sourceRoot":"","sources":["../../../src/components/dispatcher/simplified.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModuleContextParams } from "@owlmeans/client";
|
|
2
|
+
import type { DispatcherProps } from "@owlmeans/client-auth";
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
4
|
+
export interface ParametrisedProps extends PropsWithChildren<ModuleContextParams & DispatcherProps> {
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/dispatcher/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE9C,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB,CAAC,mBAAmB,GAAG,eAAe,CAAC;CAClG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/dispatcher/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQnD,eAAO,MAAM,gBAAgB,EAAE,UAsC9B,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MiddlewareType, MiddlewareStage, AppType } from '@owlmeans/context';
|
|
2
|
+
import { AuthUnknown } from '@owlmeans/auth';
|
|
3
|
+
import { ResilientError } from '@owlmeans/error';
|
|
4
|
+
import { DEFAULT_ALIAS } from '@owlmeans/client-auth';
|
|
5
|
+
export const logoutMiddleware = {
|
|
6
|
+
type: MiddlewareType.Context,
|
|
7
|
+
stage: MiddlewareStage.Loading,
|
|
8
|
+
apply: async (context) => {
|
|
9
|
+
context.modules().forEach(module => {
|
|
10
|
+
if (module.route.route.type === AppType.Backend && module.call != null) {
|
|
11
|
+
const guards = module.getGuards();
|
|
12
|
+
if (guards.length > 0) {
|
|
13
|
+
if (module._auth_web_middleware_applied === true) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
module._auth_web_middleware_applied = true;
|
|
17
|
+
// const auth = context.service<GuardService>(service)
|
|
18
|
+
const call = module.call;
|
|
19
|
+
module.call = async (req, res) => {
|
|
20
|
+
try {
|
|
21
|
+
return await call(req, res);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (e instanceof Error) {
|
|
25
|
+
const err = ResilientError.ensure(e);
|
|
26
|
+
if (err instanceof AuthUnknown) {
|
|
27
|
+
if (err.message.endsWith(':invalid')) {
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
const auth = context.service(DEFAULT_ALIAS);
|
|
30
|
+
await auth.update(undefined);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAGrD,MAAM,CAAC,MAAM,gBAAgB,GAAe;IAC1C,IAAI,EAAE,cAAc,CAAC,OAAO;IAC5B,KAAK,EAAE,eAAe,CAAC,OAAO;IAC9B,KAAK,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;QACrB,OAAO,CAAC,OAAO,EAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;gBACvE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;gBACjC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtB,IAAI,MAAM,CAAC,4BAA4B,KAAK,IAAI,EAAE,CAAC;wBACjD,OAAM;oBACR,CAAC;oBACD,MAAM,CAAC,4BAA4B,GAAG,IAAI,CAAA;oBAC1C,sDAAsD;oBACtD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;oBACxB,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;wBAC/B,IAAI,CAAC;4BACH,OAAO,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;wBAC7B,CAAC;wBAAC,OAAO,CAAC,EAAE,CAAC;4BACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gCACvB,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;gCACpC,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;oCAC/B,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;wCACrC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;4CAClC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAc,aAAa,CAAC,CAAA;4CACxD,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;4CAC5B,MAAM,GAAG,CAAA;wCACX,CAAC;oCACH,CAAC;gCACH,CAAC;4BACH,CAAC;4BACD,MAAM,CAAC,CAAA;wBACT,CAAC;oBACH,CAAC,CAAA;gBAEH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
package/build/service.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AuthServiceAppend } from '@owlmeans/client-auth';
|
|
2
1
|
import type { AuthService } from '@owlmeans/auth-common';
|
|
2
|
+
import type { AuthServiceAppend } from '@owlmeans/client-auth';
|
|
3
3
|
import type { ClientConfig, ClientContext } from '@owlmeans/client-context';
|
|
4
4
|
export declare const makeAuthWebService: (alias?: string) => AuthService;
|
|
5
5
|
export declare const appendWebAuthService: <C extends ClientConfig, T extends ClientContext<C>>(ctx: T, alias?: string) => T & AuthServiceAppend;
|
package/build/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAI3E,eAAO,MAAM,kBAAkB,GAAI,QAAO,MAAsB,KAAG,WAclE,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,EACrF,KAAK,CAAC,EAAE,QAAO,MAAsB,KACpC,CAAC,GAAG,iBAaN,CAAA"}
|
package/build/service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DEFAULT_ALIAS } from '@owlmeans/client-auth';
|
|
2
|
-
import { makeAuthService } from '@owlmeans/client-auth';
|
|
3
1
|
import { DISPATCHER } from '@owlmeans/auth';
|
|
4
2
|
import { authMiddleware } from '@owlmeans/auth-common';
|
|
3
|
+
import { DEFAULT_ALIAS, makeAuthService } from '@owlmeans/client-auth';
|
|
4
|
+
import { logoutMiddleware } from './middleware.js';
|
|
5
5
|
export const makeAuthWebService = (alias = DEFAULT_ALIAS) => {
|
|
6
6
|
const service = makeAuthService(alias);
|
|
7
7
|
const update = service.update;
|
|
@@ -20,6 +20,7 @@ export const appendWebAuthService = (ctx, alias = DEFAULT_ALIAS) => {
|
|
|
20
20
|
const context = ctx;
|
|
21
21
|
context.registerService(service);
|
|
22
22
|
context.registerMiddleware(authMiddleware);
|
|
23
|
+
context.registerMiddleware(logoutMiddleware);
|
|
23
24
|
context.auth = () => ctx.service(service.alias);
|
|
24
25
|
return context;
|
|
25
26
|
};
|
package/build/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAGtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,aAAa,EAAe,EAAE;IAC/E,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IAEtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAC7B,OAAO,CAAC,MAAM,GAAG,KAAK,EAAC,KAAK,EAAC,EAAE;QAC7B,MAAM,MAAM,CAAC,KAAK,CAAC,CAAA;QACnB,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,MAAM,CAAuB,UAAU,CAAC,CAAA;YAC3E,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YACjC,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAA;QAC9B,CAAC;IACH,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,GAAM,EAAE,QAAgB,aAAa,EACd,EAAE;IACzB,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAEzC,MAAM,OAAO,GAAG,GAA4B,CAAA;IAE5C,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IAEhC,OAAO,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;IAC1C,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IAE5C,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE/C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/web-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"build": "tsc -b",
|
|
@@ -20,22 +21,22 @@
|
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@owlmeans/auth": "^0.1.
|
|
24
|
-
"@owlmeans/auth-common": "^0.1.
|
|
25
|
-
"@owlmeans/client": "^0.1.
|
|
26
|
-
"@owlmeans/client-auth": "^0.1.
|
|
27
|
-
"@owlmeans/client-context": "^0.1.
|
|
28
|
-
"@owlmeans/client-i18n": "^0.1.
|
|
29
|
-
"@owlmeans/client-module": "^0.1.
|
|
30
|
-
"@owlmeans/client-resource": "^0.1.
|
|
31
|
-
"@owlmeans/client-route": "^0.1.
|
|
32
|
-
"@owlmeans/config": "^0.1.
|
|
33
|
-
"@owlmeans/context": "^0.1.
|
|
34
|
-
"@owlmeans/error": "^0.1.
|
|
35
|
-
"@owlmeans/i18n": "^0.1.
|
|
36
|
-
"@owlmeans/route": "^0.1.
|
|
37
|
-
"@owlmeans/web-db": "^0.1.
|
|
38
|
-
"@owlmeans/web-router": "^0.1.
|
|
24
|
+
"@owlmeans/auth": "^0.1.2",
|
|
25
|
+
"@owlmeans/auth-common": "^0.1.2",
|
|
26
|
+
"@owlmeans/client": "^0.1.2",
|
|
27
|
+
"@owlmeans/client-auth": "^0.1.2",
|
|
28
|
+
"@owlmeans/client-context": "^0.1.2",
|
|
29
|
+
"@owlmeans/client-i18n": "^0.1.2",
|
|
30
|
+
"@owlmeans/client-module": "^0.1.2",
|
|
31
|
+
"@owlmeans/client-resource": "^0.1.2",
|
|
32
|
+
"@owlmeans/client-route": "^0.1.2",
|
|
33
|
+
"@owlmeans/config": "^0.1.2",
|
|
34
|
+
"@owlmeans/context": "^0.1.2",
|
|
35
|
+
"@owlmeans/error": "^0.1.2",
|
|
36
|
+
"@owlmeans/i18n": "^0.1.2",
|
|
37
|
+
"@owlmeans/route": "^0.1.2",
|
|
38
|
+
"@owlmeans/web-db": "^0.1.2",
|
|
39
|
+
"@owlmeans/web-router": "^0.1.2",
|
|
39
40
|
"react-dropzone": "^14.3.5"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RoutedComponent } from "@owlmeans/client"
|
|
2
|
+
import type { DispatcherProps } from "@owlmeans/client-auth"
|
|
3
|
+
import type { FlowPayload } from "@owlmeans/flow"
|
|
4
|
+
import { useMemo } from "react"
|
|
5
|
+
import { Dispatcher } from "./component.js"
|
|
6
|
+
import { ParametrisedProps } from "./types.js"
|
|
7
|
+
|
|
8
|
+
export const parametriseDispatcher = (def: Partial<ParametrisedProps>, Com?: RoutedComponent<DispatcherProps> ) => {
|
|
9
|
+
console.log('Parametrising dispatcher with', def)
|
|
10
|
+
return (props: ParametrisedProps) => {
|
|
11
|
+
console.log('Rendering parametrised dispatcher with', props)
|
|
12
|
+
const _props = useMemo(() => {
|
|
13
|
+
let payload: FlowPayload | undefined = undefined
|
|
14
|
+
if (def.payload != null) {
|
|
15
|
+
payload = def.payload
|
|
16
|
+
}
|
|
17
|
+
if (props.payload != null) {
|
|
18
|
+
payload ??= {}
|
|
19
|
+
Object.assign(payload, props.payload)
|
|
20
|
+
}
|
|
21
|
+
return { ...def, ...props, payload }
|
|
22
|
+
}, [props])
|
|
23
|
+
console.log('Computed dispatcher props', _props)
|
|
24
|
+
Com ??= Dispatcher
|
|
25
|
+
return <Com {..._props} />
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModuleContextParams } from "@owlmeans/client"
|
|
2
|
+
import type { DispatcherProps } from "@owlmeans/client-auth"
|
|
3
|
+
import type { PropsWithChildren } from "react"
|
|
4
|
+
|
|
5
|
+
export interface ParametrisedProps extends PropsWithChildren<ModuleContextParams & DispatcherProps> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Middleware } from '@owlmeans/context'
|
|
2
|
+
import { MiddlewareType, MiddlewareStage, AppType } from '@owlmeans/context'
|
|
3
|
+
import type { ClientModule } from '@owlmeans/client-module'
|
|
4
|
+
import { AuthUnknown } from '@owlmeans/auth'
|
|
5
|
+
import { ResilientError } from '@owlmeans/error'
|
|
6
|
+
import { DEFAULT_ALIAS } from '@owlmeans/client-auth'
|
|
7
|
+
import { AuthService } from '@owlmeans/auth-common'
|
|
8
|
+
|
|
9
|
+
export const logoutMiddleware: Middleware = {
|
|
10
|
+
type: MiddlewareType.Context,
|
|
11
|
+
stage: MiddlewareStage.Loading,
|
|
12
|
+
apply: async context => {
|
|
13
|
+
context.modules<Perked>().forEach(module => {
|
|
14
|
+
if (module.route.route.type === AppType.Backend && module.call != null) {
|
|
15
|
+
const guards = module.getGuards()
|
|
16
|
+
if (guards.length > 0) {
|
|
17
|
+
if (module._auth_web_middleware_applied === true) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
module._auth_web_middleware_applied = true
|
|
21
|
+
// const auth = context.service<GuardService>(service)
|
|
22
|
+
const call = module.call
|
|
23
|
+
module.call = async (req, res) => {
|
|
24
|
+
try {
|
|
25
|
+
return await call(req, res)
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (e instanceof Error) {
|
|
28
|
+
const err = ResilientError.ensure(e)
|
|
29
|
+
if (err instanceof AuthUnknown) {
|
|
30
|
+
if (err.message.endsWith(':invalid')) {
|
|
31
|
+
if (typeof window !== 'undefined') {
|
|
32
|
+
const auth = context.service<AuthService>(DEFAULT_ALIAS)
|
|
33
|
+
await auth.update(undefined)
|
|
34
|
+
throw err
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw e
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface Perked extends ClientModule<unknown> {
|
|
50
|
+
_auth_web_middleware_applied?: boolean
|
|
51
|
+
}
|
package/src/service.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
import { DEFAULT_ALIAS } from '@owlmeans/client-auth'
|
|
3
|
-
import type { AuthServiceAppend } from '@owlmeans/client-auth'
|
|
4
|
-
import type { AuthService } from '@owlmeans/auth-common'
|
|
5
|
-
import { makeAuthService } from '@owlmeans/client-auth'
|
|
6
|
-
import type { ClientModule } from '@owlmeans/client-module'
|
|
7
2
|
import { DISPATCHER } from '@owlmeans/auth'
|
|
8
|
-
import type {
|
|
3
|
+
import type { AuthService } from '@owlmeans/auth-common'
|
|
9
4
|
import { authMiddleware } from '@owlmeans/auth-common'
|
|
5
|
+
import type { AuthServiceAppend } from '@owlmeans/client-auth'
|
|
6
|
+
import { DEFAULT_ALIAS, makeAuthService } from '@owlmeans/client-auth'
|
|
7
|
+
import type { ClientConfig, ClientContext } from '@owlmeans/client-context'
|
|
8
|
+
import type { ClientModule } from '@owlmeans/client-module'
|
|
9
|
+
import { logoutMiddleware } from './middleware.js'
|
|
10
10
|
|
|
11
11
|
export const makeAuthWebService = (alias: string = DEFAULT_ALIAS): AuthService => {
|
|
12
12
|
const service = makeAuthService(alias)
|
|
@@ -34,6 +34,7 @@ export const appendWebAuthService = <C extends ClientConfig, T extends ClientCon
|
|
|
34
34
|
context.registerService(service)
|
|
35
35
|
|
|
36
36
|
context.registerMiddleware(authMiddleware)
|
|
37
|
+
context.registerMiddleware(logoutMiddleware)
|
|
37
38
|
|
|
38
39
|
context.auth = () => ctx.service(service.alias)
|
|
39
40
|
|