@actdim/dynstruct 0.9.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.
Files changed (43) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +2 -0
  3. package/dist/appDomain/appContracts.d.ts +113 -0
  4. package/dist/appDomain/appContracts.d.ts.map +1 -0
  5. package/dist/appDomain/appContracts.es.js +12 -0
  6. package/dist/appDomain/appContracts.es.js.map +1 -0
  7. package/dist/appDomain/navigation.d.ts +8 -0
  8. package/dist/appDomain/navigation.d.ts.map +1 -0
  9. package/dist/appDomain/navigation.es.js +18 -0
  10. package/dist/appDomain/navigation.es.js.map +1 -0
  11. package/dist/appDomain/security/securityContracts.d.ts +94 -0
  12. package/dist/appDomain/security/securityContracts.d.ts.map +1 -0
  13. package/dist/appDomain/security/securityContracts.es.js +15 -0
  14. package/dist/appDomain/security/securityContracts.es.js.map +1 -0
  15. package/dist/appDomain/security/securityProvider.d.ts +31 -0
  16. package/dist/appDomain/security/securityProvider.d.ts.map +1 -0
  17. package/dist/appDomain/security/securityProvider.es.js +265 -0
  18. package/dist/appDomain/security/securityProvider.es.js.map +1 -0
  19. package/dist/componentModel/componentModel.d.ts +129 -0
  20. package/dist/componentModel/componentModel.d.ts.map +1 -0
  21. package/dist/componentModel/componentModel.es.js +198 -0
  22. package/dist/componentModel/componentModel.es.js.map +1 -0
  23. package/dist/componentModel/scope.d.ts +34 -0
  24. package/dist/componentModel/scope.d.ts.map +1 -0
  25. package/dist/componentModel/scope.es.js +139 -0
  26. package/dist/componentModel/scope.es.js.map +1 -0
  27. package/dist/net/apiError.d.ts +22 -0
  28. package/dist/net/apiError.d.ts.map +1 -0
  29. package/dist/net/apiError.es.js +47 -0
  30. package/dist/net/apiError.es.js.map +1 -0
  31. package/dist/net/client.d.ts +20 -0
  32. package/dist/net/client.d.ts.map +1 -0
  33. package/dist/net/client.es.js +146 -0
  34. package/dist/net/client.es.js.map +1 -0
  35. package/dist/net/request.d.ts +44 -0
  36. package/dist/net/request.d.ts.map +1 -0
  37. package/dist/net/request.es.js +33 -0
  38. package/dist/net/request.es.js.map +1 -0
  39. package/dist/reactHooks.d.ts +2 -0
  40. package/dist/reactHooks.d.ts.map +1 -0
  41. package/dist/reactHooks.es.js +9 -0
  42. package/dist/reactHooks.es.js.map +1 -0
  43. package/package.json +92 -0
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2025 Pavel Borodaev
2
+
3
+ This software is publicly accessible but proprietary.
4
+
5
+ Permission is granted to use and reference this package for personal or internal purposes only.
6
+ You may not modify, redistribute, decompile, or create derivative works from this software, in whole or in part, without prior written permission from the author.
7
+
8
+ This software is provided "as is", without warranty of any kind.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # @actdim/dynstruct
2
+ Build scalable applications with dynamic structured components, explicit wiring, and decoupled message flow. Keep architecture clean and modular.
@@ -0,0 +1,113 @@
1
+ import { MsgBus, MsgBusStructBase, MsgBusStructFactory } from '@actdim/msgmesh/msgBusCore';
2
+ import { BaseSecurityDomainConfig as BaseSecurityDomainConfig, BaseSecurityBusStruct } from './security/securityContracts';
3
+ import { ReactNode } from 'react';
4
+ export declare const $NAV_GOTO = "APP-NAV-GOTO";
5
+ export declare const $NAV_GET_CONTEXT = "APP-NAV-CONTEXT";
6
+ export declare const $NOTICE = "APP-NOTICE";
7
+ export declare const $CONFIG_GET = "APP-CONFIG-GET";
8
+ export declare const $FETCH = "APP-FETCH";
9
+ export declare const $KV_STORE_GET = "APP-KV-STORE-GET";
10
+ export declare const $KV_STORE_SET = "APP-KV-STORE-SET";
11
+ export declare const $KV_STORE_REMOVE = "APP-KV-STORE-REMOVE";
12
+ export type Module = "security" | "api-client";
13
+ export type NavPath = {
14
+ pathname: string;
15
+ search: string;
16
+ hash: string;
17
+ };
18
+ export type NavLocation<State = any> = NavPath & {
19
+ state: State;
20
+ key: string;
21
+ };
22
+ export type NavAction = "POP" | "PUSH" | "REPLACE";
23
+ export type NavRouteParams = Record<string, string | undefined>;
24
+ export type NavRoute<TParams extends NavRouteParams = NavRouteParams> = {
25
+ path(params?: TParams): string;
26
+ match(path: string): TParams;
27
+ element: ReactNode;
28
+ defaultParams?: TParams;
29
+ };
30
+ export type NavRoutes = Record<string, NavRoute>;
31
+ export type NavContext = {
32
+ location?: NavLocation;
33
+ searchParams?: URLSearchParams;
34
+ params?: NavRouteParams;
35
+ navType?: NavAction;
36
+ };
37
+ export type AppError<TModule = Module> = {
38
+ module: TModule;
39
+ type: string;
40
+ title?: string;
41
+ source?: any;
42
+ details?: any;
43
+ timestamp?: string;
44
+ traceId?: string;
45
+ field?: string;
46
+ reason?: string;
47
+ };
48
+ export type BaseApiBusStruct = BaseSecurityBusStruct & MsgBusStructFactory<{}>;
49
+ export type BaseAppBusStruct = BaseApiBusStruct & MsgBusStructFactory<{
50
+ [$NOTICE]: {
51
+ in: {
52
+ text: string;
53
+ title?: string;
54
+ type: any;
55
+ };
56
+ out: void;
57
+ };
58
+ [$CONFIG_GET]: {
59
+ in: void;
60
+ out: BaseAppDomainConfig;
61
+ };
62
+ [$NAV_GOTO]: {
63
+ in: string | number;
64
+ out: void;
65
+ };
66
+ [$NAV_GET_CONTEXT]: {
67
+ in: void;
68
+ out: NavContext;
69
+ };
70
+ [$FETCH]: {
71
+ in: {
72
+ url: string;
73
+ params: RequestInit;
74
+ };
75
+ out: Response;
76
+ };
77
+ [$KV_STORE_GET]: {
78
+ in: {
79
+ key: string;
80
+ useEncryption?: boolean;
81
+ };
82
+ out: string;
83
+ };
84
+ [$KV_STORE_SET]: {
85
+ in: {
86
+ key: string;
87
+ value: any;
88
+ useEncryption?: boolean;
89
+ };
90
+ out: void;
91
+ };
92
+ [$KV_STORE_REMOVE]: {
93
+ in: {
94
+ key: string;
95
+ };
96
+ out: void;
97
+ };
98
+ } & MsgBusStructBase>;
99
+ export type BaseApiConfig = {
100
+ url?: string;
101
+ versions?: string[];
102
+ };
103
+ export type BaseAppDomainConfig<TSecurityDomainConfig extends BaseSecurityDomainConfig = BaseSecurityDomainConfig, TApiConfig extends BaseApiConfig = BaseApiConfig> = {
104
+ id: string;
105
+ name?: string;
106
+ baseUrl: string;
107
+ security: TSecurityDomainConfig;
108
+ apis: Record<string, TApiConfig>;
109
+ };
110
+ export type BaseAppContext<TMsgBusStruct extends BaseAppBusStruct = BaseAppBusStruct> = {
111
+ msgBus: MsgBus<TMsgBusStruct>;
112
+ };
113
+ //# sourceMappingURL=appContracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appContracts.d.ts","sourceRoot":"","sources":["../../src/appDomain/appContracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,wBAAwB,IAAI,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AACrI,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,eAAO,MAAM,SAAS,iBAAiB,CAAC;AACxC,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAE5C,eAAO,MAAM,MAAM,cAAc,CAAC;AAElC,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAChD,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAChD,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAGtD,MAAM,MAAM,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC;AAE/C,MAAM,MAAM,OAAO,GAAG;IAIlB,QAAQ,EAAE,MAAM,CAAC;IAIjB,MAAM,EAAE,MAAM,CAAC;IAIf,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,KAAK,GAAG,GAAG,IAAI,OAAO,GAAG;IAI7C,KAAK,EAAE,KAAK,CAAC;IAOb,GAAG,EAAE,MAA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b,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAGF,MAAM,MAAM,mBAAmB,CAC3B,qBAAqB,SAAS,wBAAwB,GAAG,wBAAwB,EACjF,UAAU,SAAS,aAAa,GAAG,aAAa,IAChD;IACA,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAEpC,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,aAAa,SAAS,gBAAgB,GAAG,gBAAgB,IAAI;IACpF,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;CACjC,CAAC"}
@@ -0,0 +1,12 @@
1
+ const E = "APP-NAV-GOTO", T = "APP-NAV-CONTEXT", O = "APP-NOTICE", P = "APP-CONFIG-GET", A = "APP-FETCH", V = "APP-KV-STORE-GET", N = "APP-KV-STORE-SET", _ = "APP-KV-STORE-REMOVE";
2
+ export {
3
+ P as $CONFIG_GET,
4
+ A as $FETCH,
5
+ V as $KV_STORE_GET,
6
+ _ as $KV_STORE_REMOVE,
7
+ N as $KV_STORE_SET,
8
+ T as $NAV_GET_CONTEXT,
9
+ E as $NAV_GOTO,
10
+ O as $NOTICE
11
+ };
12
+ //# sourceMappingURL=appContracts.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appContracts.es.js","sources":["../../src/appDomain/appContracts.ts"],"sourcesContent":["import { $CG_ERROR, MsgBus, MsgBusStructBase, MsgBusStructFactory } from \"@actdim/msgmesh/msgBusCore\";\r\nimport { BaseSecurityDomainConfig as BaseSecurityDomainConfig, BaseSecurityBusStruct } from \"@/appDomain/security/securityContracts\";\r\nimport { ReactNode } from \"react\";\r\n\r\nexport const $NAV_GOTO = \"APP-NAV-GOTO\";\r\nexport const $NAV_GET_CONTEXT = \"APP-NAV-CONTEXT\";\r\n// TOAST\r\nexport const $NOTICE = \"APP-NOTICE\";\r\nexport const $CONFIG_GET = \"APP-CONFIG-GET\";\r\n// ERROR?\r\nexport const $FETCH = \"APP-FETCH\";\r\n\r\nexport const $KV_STORE_GET = \"APP-KV-STORE-GET\";\r\nexport const $KV_STORE_SET = \"APP-KV-STORE-SET\";\r\nexport const $KV_STORE_REMOVE = \"APP-KV-STORE-REMOVE\";\r\n// TODO: has, clear, entries\r\n\r\nexport type Module = \"security\" | \"api-client\";\r\n\r\nexport type NavPath = {\r\n /**\r\n * A URL pathname, beginning with a /.\r\n */\r\n pathname: string;\r\n /**\r\n * A URL search string, beginning with a ?.\r\n */\r\n search: string;\r\n /**\r\n * A URL fragment identifier, beginning with a #.\r\n */\r\n hash: string;\r\n};\r\n\r\nexport type NavLocation<State = any> = NavPath & {\r\n /**\r\n * A value of arbitrary data associated with this location.\r\n */\r\n state: State;\r\n /**\r\n * A unique string associated with this location. May be used to safely store\r\n * and retrieve data in some other storage API, like `localStorage`.\r\n *\r\n * Note: This value is always \"default\" on the initial location.\r\n */\r\n key: string;\r\n};\r\n\r\nexport type NavAction =\r\n /**\r\n * A POP indicates a change to an arbitrary index in the history stack, such\r\n * as a back or forward navigation. It does not describe the direction of the\r\n * navigation, only that the current index changed.\r\n *\r\n * Note: This is the default action for newly created history objects.\r\n */\r\n | \"POP\"\r\n /**\r\n * A PUSH indicates a new entry being added to the history stack, such as when\r\n * a link is clicked and a new page loads. When this happens, all subsequent\r\n * entries in the stack are lost.\r\n */\r\n | \"PUSH\"\r\n /**\r\n * A REPLACE indicates the entry at the current index in the history stack\r\n * being replaced by a new one.\r\n */\r\n | \"REPLACE\";\r\n\r\n// AppRouteParams\r\nexport type NavRouteParams = Record<string, string | undefined>;\r\n\r\n// AppRoute\r\nexport type NavRoute<TParams extends NavRouteParams = NavRouteParams> = {\r\n path(params?: TParams): string;\r\n match(path: string): TParams;\r\n element: ReactNode;\r\n defaultParams?: TParams;\r\n};\r\n\r\nexport type NavRoutes = Record<string, NavRoute>;\r\n\r\nexport type NavContext = {\r\n // route?: NavRoute;\r\n location?: NavLocation;\r\n searchParams?: URLSearchParams;\r\n params?: NavRouteParams;\r\n navType?: NavAction;\r\n};\r\n\r\n// OperationContext?\r\nexport type AppError<TModule = Module> = {\r\n module: TModule;\r\n // code: string;\r\n type: string;\r\n title?: string;\r\n source?: any;\r\n details?: any;\r\n // instance?: string;\r\n timestamp?: string;\r\n // errors: AppError[];\r\n traceId?: string;\r\n field?: string;\r\n reason?: string;\r\n};\r\n\r\n// Base(App)Api(Msg)BusStruct\r\nexport type BaseApiBusStruct = BaseSecurityBusStruct &\r\n MsgBusStructFactory<{\r\n // \"GET-VERSION\"?: {\r\n // in: any;\r\n // };\r\n }>;\r\n\r\n// BaseAppMsgBusStruct\r\nexport type BaseAppBusStruct = BaseApiBusStruct &\r\n MsgBusStructFactory<\r\n {\r\n [$NOTICE]: {\r\n in: {\r\n text: string;\r\n title?: string;\r\n type: any;\r\n };\r\n out: void;\r\n };\r\n [$CONFIG_GET]: {\r\n in: void;\r\n out: BaseAppDomainConfig;\r\n };\r\n [$NAV_GOTO]: {\r\n in: string | number;\r\n out: void;\r\n };\r\n [$NAV_GET_CONTEXT]: {\r\n in: void;\r\n out: NavContext;\r\n };\r\n [$FETCH]: {\r\n in: {\r\n url: string;\r\n params: RequestInit;\r\n };\r\n out: Response;\r\n };\r\n [$KV_STORE_GET]: {\r\n in: {\r\n key: string;\r\n useEncryption?: boolean;\r\n };\r\n out: string;\r\n };\r\n [$KV_STORE_SET]: {\r\n in: {\r\n key: string;\r\n value: any;\r\n useEncryption?: boolean;\r\n };\r\n out: void;\r\n };\r\n [$KV_STORE_REMOVE]: {\r\n in: {\r\n key: string;\r\n };\r\n out: void;\r\n };\r\n } & MsgBusStructBase\r\n >;\r\n\r\nexport type BaseApiConfig = {\r\n url?: string;\r\n versions?: string[];\r\n};\r\n\r\n// BaseApp(Domain)Config\r\nexport type BaseAppDomainConfig<\r\n TSecurityDomainConfig extends BaseSecurityDomainConfig = BaseSecurityDomainConfig,\r\n TApiConfig extends BaseApiConfig = BaseApiConfig\r\n> = {\r\n id: string;\r\n name?: string;\r\n baseUrl: string;\r\n security: TSecurityDomainConfig;\r\n apis: Record<string, TApiConfig>;\r\n // HATEOAS? (React Admin)\r\n};\r\n\r\nexport type BaseAppContext<TMsgBusStruct extends BaseAppBusStruct = BaseAppBusStruct> = {\r\n msgBus: MsgBus<TMsgBusStruct>;\r\n};\r\n"],"names":["$NAV_GOTO","$NAV_GET_CONTEXT","$NOTICE","$CONFIG_GET","$FETCH","$KV_STORE_GET","$KV_STORE_SET","$KV_STORE_REMOVE"],"mappings":"AAIO,MAAMA,IAAY,gBACZC,IAAmB,mBAEnBC,IAAU,cACVC,IAAc,kBAEdC,IAAS,aAETC,IAAgB,oBAChBC,IAAgB,oBAChBC,IAAmB;"}
@@ -0,0 +1,8 @@
1
+ import { NavRoute, NavRouteParams } from './appContracts';
2
+ import { ReactNode } from 'react';
3
+ export declare function createNavigationRoute<TParams extends NavRouteParams = NavRouteParams>(config: {
4
+ pattern: string;
5
+ element: ReactNode;
6
+ defaultParams?: TParams;
7
+ }): NavRoute<TParams>;
8
+ //# sourceMappingURL=navigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/appDomain/navigation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc,EAAE,MAAM,EAAE;IAC3F,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B,GAmBQ,QAAQ,CAAC,OAAO,CAAC,CACzB"}
@@ -0,0 +1,18 @@
1
+ import { compile as m, match as u } from "path-to-regexp";
2
+ function l(t) {
3
+ const a = m(t.pattern), n = u(t.pattern);
4
+ return {
5
+ path: (e) => e ? a(e) : t.pattern,
6
+ match: (e) => {
7
+ const r = n(e);
8
+ if (r !== !1)
9
+ return r.params;
10
+ },
11
+ element: t.element,
12
+ defaultParams: t.defaultParams
13
+ };
14
+ }
15
+ export {
16
+ l as createNavigationRoute
17
+ };
18
+ //# sourceMappingURL=navigation.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.es.js","sources":["../../src/appDomain/navigation.ts"],"sourcesContent":["import { compile, match } from \"path-to-regexp\";\r\nimport { NavRoute, NavRouteParams } from \"./appContracts\";\r\nimport { ReactNode } from \"react\";\r\n// createAppRoute\r\nexport function createNavigationRoute<TParams extends NavRouteParams = NavRouteParams>(config: {\r\n pattern: string;\r\n element: ReactNode;\r\n defaultParams?: TParams;\r\n}) {\r\n const toPath = compile(config.pattern);\r\n const matcher = match(config.pattern);\r\n return {\r\n path: (params?: object) => {\r\n if (!params) {\r\n return config.pattern;\r\n }\r\n return toPath(params);\r\n },\r\n match: (path: string) => {\r\n const matchResult = matcher(path);\r\n if (matchResult === false) {\r\n return undefined;\r\n }\r\n return matchResult.params;\r\n },\r\n element: config.element,\r\n defaultParams: config.defaultParams\r\n } as NavRoute<TParams>;\r\n}\r\n"],"names":["createNavigationRoute","config","toPath","compile","matcher","match","params","path","matchResult"],"mappings":";AAIO,SAASA,EAAuEC,GAIpF;AACO,QAAAC,IAASC,EAAQF,EAAO,OAAO,GAC/BG,IAAUC,EAAMJ,EAAO,OAAO;AAC7B,SAAA;AAAA,IACH,MAAM,CAACK,MACEA,IAGEJ,EAAOI,CAAM,IAFTL,EAAO;AAAA,IAItB,OAAO,CAACM,MAAiB;AACf,YAAAC,IAAcJ,EAAQG,CAAI;AAChC,UAAIC,MAAgB;AAGpB,eAAOA,EAAY;AAAA,IACvB;AAAA,IACA,SAASP,EAAO;AAAA,IAChB,eAAeA,EAAO;AAAA,EAAA;AAE9B;"}
@@ -0,0 +1,94 @@
1
+ import { MsgBusStruct, MsgBusStructBase } from '@actdim/msgmesh/msgBusCore';
2
+ import { RequireExtends, Skip } from '@actdim/utico/typeCore';
3
+ export declare enum AccessLevel {
4
+ None = 0,
5
+ Inherited = 1,
6
+ NoRender = 2,
7
+ Hidden = 4,
8
+ Disabled = 8,
9
+ ReadOnly = 16,
10
+ Full = 31
11
+ }
12
+ export type UserCredentials = {
13
+ username: string;
14
+ password: string;
15
+ };
16
+ export type IAccessDescriptor = {
17
+ [P in AccessLevel]?: string;
18
+ };
19
+ export declare const $SIGNIN = "APP-SECURITY-AUTH-SIGNIN";
20
+ export declare const $REQUEST_SIGNIN = "APP-SECURITY-REQUEST-AUTH-SIGNIN";
21
+ export declare const $SIGNOUT = "APP-SECURITY-AUTH-SIGNOUT";
22
+ export declare const $REQUEST_SIGNOUT = "APP-SECURITY-REQUEST-AUTH-SIGNOUT";
23
+ export declare const $REFRESH = "APP-SECURITY-AUTH-REFRESH";
24
+ export declare const $REQUEST_AUTH = "APP-SECURITY-REQUEST-AUTH";
25
+ export declare const $GET_ACL = "APP-SECURITY-GET-ACL";
26
+ export declare const $GET_CONTEXT = "APP-SECURITY-GET-CONTEXT";
27
+ export declare const $GET_CONFIG = "APP-SECURITY-GET-CONFIG";
28
+ export type SecurityTokens = {
29
+ accessToken?: string;
30
+ refreshToken?: string;
31
+ };
32
+ export type BaseSecurityBusStruct = RequireExtends<{
33
+ [$SIGNIN]: {
34
+ in: UserCredentials;
35
+ out: SecurityContext;
36
+ };
37
+ [$REQUEST_SIGNIN]: {
38
+ in: {
39
+ callbackUrl: string;
40
+ };
41
+ };
42
+ [$SIGNOUT]: {
43
+ in: void;
44
+ out: void;
45
+ };
46
+ [$REQUEST_SIGNOUT]: {
47
+ in: {
48
+ callbackUrl: string;
49
+ };
50
+ };
51
+ [$REFRESH]: {
52
+ in: Skip<SecurityTokens, "accessToken">;
53
+ out: SecurityContext;
54
+ };
55
+ [$REQUEST_AUTH]: {
56
+ in: void;
57
+ out: void;
58
+ };
59
+ [$GET_ACL]: {
60
+ in: ISecurable;
61
+ out: IAccessDescriptor;
62
+ };
63
+ [$GET_CONTEXT]: {
64
+ in: void;
65
+ out: SecurityContext;
66
+ };
67
+ [$GET_CONFIG]: {
68
+ in: void;
69
+ out: BaseSecurityDomainConfig;
70
+ };
71
+ } & MsgBusStructBase, MsgBusStruct>;
72
+ export type ISecurable = {
73
+ id: string;
74
+ };
75
+ export type SecurityContext<TUserInfo = any> = {
76
+ accessToken: string;
77
+ refreshToken: string;
78
+ userInfo: TUserInfo;
79
+ authProvider: string;
80
+ domain: string;
81
+ tokenExpiresAt: string;
82
+ };
83
+ export type BaseSecurityDomainConfig = {
84
+ id: string;
85
+ name?: string;
86
+ authType: string;
87
+ routes: {
88
+ authSignIn: string;
89
+ authSignOut: string;
90
+ authRefresh: string;
91
+ authService: string;
92
+ };
93
+ };
94
+ //# sourceMappingURL=securityContracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"securityContracts.d.ts","sourceRoot":"","sources":["../../../src/appDomain/security/securityContracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9D,oBAAY,WAAW;IACnB,IAAI,IAAI;IACR,SAAS,IAAS;IAClB,QAAQ,IAAS;IACjB,MAAM,IAAS;IACf,QAAQ,IAAS;IACjB,QAAQ,KAAS;IACjB,IAAI,KAAa;CACpB;AAGD,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;KAE3B,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,MAAM;CAC9B,CAAC;AAEF,eAAO,MAAM,OAAO,6BAA6B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AAC,EAAE;QACZ,EAAE,EAAE,IAAI,CAAC;QACT,GAAG,EAAE,eAAe,CAAC;KACxB,CAAC;IACF,CAAC,WAAW,CAAC,EAAE;QACX,EAAE,EAAE,IAAI,CAAC;QACT,GAAG,EAAE,wBAAwB,CAAC;KACjC,CAAC;CACL,GAAG,gBAAgB,EACpB,YAAY,CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;CACd,CAAC;AAGF,MAAM,MAAM,eAAe,CAAC,SAAS,GAAG,GAAG,IAAI;IAG3C,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IAGrB,QAAQ,EAAE,SAAS,CAAC;IAEpB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IAEf,cAAc,EAAE,MAAM,CAAC;CAE1B,CAAC;AAGF,MAAM,MAAM,wBAAwB,GAAG;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IAEjB,MAAM,EAAE;QACJ,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QAGpB,WAAW,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC"}
@@ -0,0 +1,15 @@
1
+ var E = /* @__PURE__ */ ((T) => (T[T.None = 0] = "None", T[T.Inherited = 1] = "Inherited", T[T.NoRender = 2] = "NoRender", T[T.Hidden = 4] = "Hidden", T[T.Disabled = 8] = "Disabled", T[T.ReadOnly = 16] = "ReadOnly", T[T.Full = 31] = "Full", T))(E || {});
2
+ const U = "APP-SECURITY-AUTH-SIGNIN", I = "APP-SECURITY-REQUEST-AUTH-SIGNIN", S = "APP-SECURITY-AUTH-SIGNOUT", R = "APP-SECURITY-REQUEST-AUTH-SIGNOUT", n = "APP-SECURITY-AUTH-REFRESH", N = "APP-SECURITY-REQUEST-AUTH", P = "APP-SECURITY-GET-ACL", G = "APP-SECURITY-GET-CONTEXT", C = "APP-SECURITY-GET-CONFIG";
3
+ export {
4
+ P as $GET_ACL,
5
+ C as $GET_CONFIG,
6
+ G as $GET_CONTEXT,
7
+ n as $REFRESH,
8
+ N as $REQUEST_AUTH,
9
+ I as $REQUEST_SIGNIN,
10
+ R as $REQUEST_SIGNOUT,
11
+ U as $SIGNIN,
12
+ S as $SIGNOUT,
13
+ E as AccessLevel
14
+ };
15
+ //# sourceMappingURL=securityContracts.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"securityContracts.es.js","sources":["../../../src/appDomain/security/securityContracts.ts"],"sourcesContent":["import { MsgBus, MsgBusStruct, MsgBusStructBase } from \"@actdim/msgmesh/msgBusCore\";\r\nimport { RequireExtends, Skip } from \"@actdim/utico/typeCore\";\r\n// abstract\r\nexport enum AccessLevel {\r\n None = 0,\r\n Inherited = 1 << 0, // Unset\r\n NoRender = 1 << 1,\r\n Hidden = 1 << 2,\r\n Disabled = 1 << 3,\r\n ReadOnly = 1 << 4, // View\r\n Full = ~(~0 << 5) // Unrestricted\r\n}\r\n\r\n// HTTP RFC 7231\r\nexport type UserCredentials = {\r\n username: string;\r\n password: string;\r\n};\r\n\r\nexport type IAccessDescriptor = {\r\n // deny/grant reason(s)\r\n [P in AccessLevel]?: string;\r\n};\r\n\r\nexport const $SIGNIN = \"APP-SECURITY-AUTH-SIGNIN\";\r\nexport const $REQUEST_SIGNIN = \"APP-SECURITY-REQUEST-AUTH-SIGNIN\";\r\nexport const $SIGNOUT = \"APP-SECURITY-AUTH-SIGNOUT\";\r\nexport const $REQUEST_SIGNOUT = \"APP-SECURITY-REQUEST-AUTH-SIGNOUT\";\r\nexport const $REFRESH = \"APP-SECURITY-AUTH-REFRESH\";\r\nexport const $REQUEST_AUTH = \"APP-SECURITY-REQUEST-AUTH\";\r\nexport const $GET_ACL = \"APP-SECURITY-GET-ACL\";\r\nexport const $GET_CONTEXT = \"APP-SECURITY-GET-CONTEXT\";\r\nexport const $GET_CONFIG = \"APP-SECURITY-GET-CONFIG\";\r\n\r\nexport type SecurityTokens = {\r\n accessToken?: string;\r\n refreshToken?: string;\r\n};\r\n\r\n// Base(App)Security(Msg)BusStruct\r\nexport type BaseSecurityBusStruct = RequireExtends<\r\n {\r\n [$SIGNIN]: {\r\n in: UserCredentials;\r\n out: SecurityContext;\r\n };\r\n [$REQUEST_SIGNIN]: {\r\n in: {\r\n callbackUrl: string;\r\n };\r\n // out: void;\r\n };\r\n [$SIGNOUT]: {\r\n in: void;\r\n out: void;\r\n };\r\n [$REQUEST_SIGNOUT]: {\r\n in: {\r\n callbackUrl: string;\r\n };\r\n // out: void;\r\n };\r\n [$REFRESH]: {\r\n in: Skip<SecurityTokens, \"accessToken\">;\r\n out: SecurityContext;\r\n };\r\n [$REQUEST_AUTH]: {\r\n in: void;\r\n out: void;\r\n };\r\n [$GET_ACL]: {\r\n in: ISecurable;\r\n out: IAccessDescriptor;\r\n };\r\n [$GET_CONTEXT]: {\r\n in: void;\r\n out: SecurityContext;\r\n };\r\n [$GET_CONFIG]: {\r\n in: void;\r\n out: BaseSecurityDomainConfig;\r\n }; \r\n } & MsgBusStructBase,\r\n MsgBusStruct\r\n>;\r\n\r\nexport type ISecurable = {\r\n id: string;\r\n};\r\n\r\n// AppSecurityContext\r\nexport type SecurityContext<TUserInfo = any> = {\r\n // isAuthenticated: boolean;\r\n // isExpired: boolean;\r\n accessToken: string;\r\n refreshToken: string;\r\n // sessionToken: string;\r\n // sid: string; // SID is an acronym for \"security identity\", grant recipient\r\n userInfo: TUserInfo;\r\n // authority: string;\r\n authProvider: string; // authSource\r\n domain: string; // protection space, scope of protection\r\n // authExpiresAt\r\n tokenExpiresAt: string;\r\n // acl: any;\r\n};\r\n\r\n// Base(App)Security(Domain)Config\r\nexport type BaseSecurityDomainConfig = {\r\n id: string;\r\n name?: string;\r\n authType: string;\r\n // endpoints\r\n routes: {\r\n authSignIn: string;\r\n authSignOut: string;\r\n authRefresh: string;\r\n // RFC 8414 (OIDC) — \"OAuth 2.0 Authorization Server Metadata\"\r\n // https://datatracker.ietf.org/doc/html/rfc8414 \r\n authService: string;\r\n };\r\n};\r\n"],"names":["AccessLevel","$SIGNIN","$REQUEST_SIGNIN","$SIGNOUT","$REQUEST_SIGNOUT","$REFRESH","$REQUEST_AUTH","$GET_ACL","$GET_CONTEXT","$GET_CONFIG"],"mappings":"AAGY,IAAAA,sBAAAA,OACRA,EAAAA,EAAA,OAAO,CAAP,IAAA,QACAA,EAAAA,EAAA,YAAY,CAAZ,IAAA,aACAA,EAAAA,EAAA,WAAW,CAAX,IAAA,YACAA,EAAAA,EAAA,SAAS,CAAT,IAAA,UACAA,EAAAA,EAAA,WAAW,CAAX,IAAA,YACAA,EAAAA,EAAA,WAAW,EAAX,IAAA,YACAA,EAAAA,EAAA,OAAO,EAAP,IAAA,QAPQA,IAAAA,KAAA,CAAA,CAAA;AAqBL,MAAMC,IAAU,4BACVC,IAAkB,oCAClBC,IAAW,6BACXC,IAAmB,qCACnBC,IAAW,6BACXC,IAAgB,6BAChBC,IAAW,wBACXC,IAAe,4BACfC,IAAc;"}
@@ -0,0 +1,31 @@
1
+ import { AccessLevel, IAccessDescriptor, ISecurable, UserCredentials, SecurityContext } from './securityContracts';
2
+ import { MsgBus } from '@actdim/msgmesh/msgBusCore';
3
+ import { BaseAppBusStruct } from '../appContracts';
4
+ export declare class SecurityProvider<TUserInfo = any> {
5
+ private msgBus;
6
+ private domainConfig;
7
+ private storageKeys;
8
+ private accessToken;
9
+ private refreshToken;
10
+ private userCredentials;
11
+ private userInfo;
12
+ private authProvider;
13
+ private tokenExpiresAt;
14
+ private acl;
15
+ private fetcher;
16
+ private init;
17
+ constructor(msgBus: MsgBus<BaseAppBusStruct>);
18
+ getContext(): SecurityContext;
19
+ private updateConfigAsync;
20
+ restoreDataAsync(): Promise<void>;
21
+ get domain(): string;
22
+ clearSavedDataAsync(): Promise<void>;
23
+ requestAuthorize(): Promise<void>;
24
+ signInAsync(credentials: UserCredentials): Promise<SecurityContext>;
25
+ saveDataAsync(): Promise<void>;
26
+ signOutAsync(): Promise<void>;
27
+ refreshAsync(): Promise<SecurityContext>;
28
+ getAcl<T extends ISecurable>(obj: T): Promise<IAccessDescriptor>;
29
+ verifyAccess<T extends ISecurable>(obj: T, accessLevel?: AccessLevel): Promise<boolean>;
30
+ }
31
+ //# sourceMappingURL=securityProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"securityProvider.d.ts","sourceRoot":"","sources":["../../../src/appDomain/security/securityProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,iBAAiB,EACjB,UAAU,EAEV,eAAe,EAEf,eAAe,EAClB,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAiC5D,qBAAa,gBAAgB,CAAC,SAAS,GAAG,GAAG;IAKzC,OAAO,CAAC,MAAM,CAA2B;IAEzC,OAAO,CAAC,YAAY,CAA2B;IAE/C,OAAO,CAAC,WAAW,CAAqB;IAExC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,eAAe,CAAkB;IAEzC,OAAO,CAAC,QAAQ,CAAY;IAG5B,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,GAAG,CAAM;IAEjB,OAAO,CAAC,OAAO,CAA8E;IAE7F,OAAO,CAAC,IAAI,CAAe;gBAEf,MAAM,EAAE,MAAM,CAAC,gBAAgB,CAAC;IA8DrC,UAAU,IAAI,eAAe;YAWtB,iBAAiB;IASzB,gBAAgB;IAqDtB,IAAW,MAAM,IAAI,MAAM,CAE1B;IAaK,mBAAmB;IA+BnB,gBAAgB;IA0BhB,WAAW,CAAC,WAAW,EAAE,eAAe;IA0CxC,aAAa;IA+Bb,YAAY;IAgCZ,YAAY;IA4CZ,MAAM,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,CAAC;IASnC,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,CAAC,EAAE,WAAW,cAAmB;CAOlF"}
@@ -0,0 +1,265 @@
1
+ var d = Object.defineProperty;
2
+ var T = (r, s, e) => s in r ? d(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
3
+ var t = (r, s, e) => T(r, typeof s != "symbol" ? s + "" : s, e);
4
+ import { AccessLevel as y } from "./securityContracts.es.js";
5
+ import { getValuePrefixer as g } from "@actdim/utico/typeCore";
6
+ import "jwt-decode";
7
+ import { getResponseResult as h } from "../../net/request.es.js";
8
+ import { ApiError as l } from "../../net/apiError.es.js";
9
+ const p = {
10
+ accessToken: "ACCESS_TOKEN",
11
+ refreshToken: "REFRESH_TOKEN",
12
+ acl: "ACL",
13
+ userCredentials: "USER_CREDENTIALS",
14
+ userInfo: "USER_INFO"
15
+ };
16
+ class f {
17
+ constructor(s) {
18
+ // private isAuthenticated: boolean;
19
+ // private isExpired: boolean;
20
+ t(this, "msgBus");
21
+ t(this, "domainConfig");
22
+ t(this, "storageKeys");
23
+ t(this, "accessToken");
24
+ t(this, "refreshToken");
25
+ t(this, "userCredentials");
26
+ t(this, "userInfo");
27
+ // private authority: string;
28
+ t(this, "authProvider");
29
+ t(this, "tokenExpiresAt");
30
+ // RBAC vs ABAC vs PBAC: https://habr.com/ru/companies/otus/articles/698080/
31
+ t(this, "acl");
32
+ t(this, "fetcher", window);
33
+ t(this, "init");
34
+ this.msgBus = s, this.init = this.updateConfigAsync(), this.msgBus.provide({
35
+ channel: "APP-SECURITY-GET-CONTEXT",
36
+ callback: (e) => this.getContext()
37
+ }), this.msgBus.provide({
38
+ channel: "APP-SECURITY-GET-ACL",
39
+ callback: (e) => this.getAcl(e.payload)
40
+ }), this.msgBus.provide({
41
+ channel: "APP-SECURITY-AUTH-SIGNIN",
42
+ callback: (e) => this.signInAsync(e.payload)
43
+ }), this.msgBus.provide({
44
+ channel: "APP-SECURITY-AUTH-SIGNOUT",
45
+ callback: (e) => this.signOutAsync()
46
+ }), this.msgBus.provide({
47
+ channel: "APP-SECURITY-AUTH-REFRESH",
48
+ callback: (e) => this.refreshAsync()
49
+ }), this.msgBus.provide({
50
+ channel: "APP-SECURITY-REQUEST-AUTH",
51
+ callback: (e) => this.requestAuthorize()
52
+ }), this.msgBus.provide({
53
+ channel: "APP-SECURITY-GET-CONFIG",
54
+ callback: async (e) => {
55
+ var a;
56
+ return (a = (await this.msgBus.dispatchAsync({
57
+ channel: "APP-CONFIG-GET"
58
+ })).payload) == null ? void 0 : a.security;
59
+ }
60
+ });
61
+ }
62
+ getContext() {
63
+ return {
64
+ accessToken: this.accessToken,
65
+ refreshToken: this.refreshToken,
66
+ userInfo: this.userInfo,
67
+ authProvider: this.authProvider,
68
+ domain: this.domain,
69
+ tokenExpiresAt: this.tokenExpiresAt
70
+ };
71
+ }
72
+ async updateConfigAsync() {
73
+ const s = await this.msgBus.dispatchAsync({
74
+ channel: "APP-CONFIG-GET"
75
+ });
76
+ this.domainConfig = s.payload.security;
77
+ const e = g(this.domainConfig.id);
78
+ this.storageKeys = e(p);
79
+ }
80
+ async restoreDataAsync() {
81
+ this.accessToken = (await this.msgBus.dispatchAsync({
82
+ channel: "APP-KV-STORE-GET",
83
+ payload: {
84
+ key: this.storageKeys.accessToken
85
+ }
86
+ })).payload, this.refreshToken = (await this.msgBus.dispatchAsync({
87
+ channel: "APP-KV-STORE-GET",
88
+ payload: {
89
+ key: this.storageKeys.refreshToken
90
+ }
91
+ })).payload;
92
+ let s = (await this.msgBus.dispatchAsync({
93
+ channel: "APP-KV-STORE-GET",
94
+ payload: {
95
+ key: this.storageKeys.userCredentials
96
+ }
97
+ })).payload;
98
+ this.userCredentials = s ? JSON.parse(s) : {
99
+ username: void 0,
100
+ password: void 0
101
+ }, s = (await this.msgBus.dispatchAsync({
102
+ channel: "APP-KV-STORE-GET",
103
+ payload: {
104
+ key: this.storageKeys.acl
105
+ }
106
+ })).payload, this.acl = s ? JSON.parse(s) : {}, this.accessToken && this.msgBus.dispatch({
107
+ channel: "APP-SECURITY-AUTH-SIGNIN",
108
+ group: "out",
109
+ payload: this.getContext()
110
+ });
111
+ }
112
+ get domain() {
113
+ return this.domainConfig.id;
114
+ }
115
+ // cleanUserAndActionsStorage = (): void => {
116
+ // const obsoleteKeysRegexMatch = /^(user|actions)@.+$/;
117
+ // for (let i = localStorage.length - 1; i >= 0; i--) {
118
+ // const key = localStorage.key(i);
119
+ // if (key && obsoleteKeysRegexMatch.test(key)) {
120
+ // localStorage.removeItem(key);
121
+ // }
122
+ // }
123
+ // };
124
+ // removeSavedData
125
+ async clearSavedDataAsync() {
126
+ this.accessToken = null, await this.msgBus.dispatchAsync({
127
+ channel: "APP-KV-STORE-REMOVE",
128
+ payload: {
129
+ key: this.storageKeys.accessToken
130
+ }
131
+ }), this.refreshToken = null, await this.msgBus.dispatchAsync({
132
+ channel: "APP-KV-STORE-REMOVE",
133
+ payload: {
134
+ key: this.storageKeys.refreshToken
135
+ }
136
+ }), this.userCredentials = null, await this.msgBus.dispatchAsync({
137
+ channel: "APP-KV-STORE-REMOVE",
138
+ payload: {
139
+ key: this.storageKeys.userCredentials
140
+ }
141
+ }), this.acl = null, await this.msgBus.dispatchAsync({
142
+ channel: "APP-KV-STORE-REMOVE",
143
+ payload: {
144
+ key: this.storageKeys.acl
145
+ }
146
+ });
147
+ }
148
+ async requestAuthorize() {
149
+ this.accessToken = null, this.acl = null;
150
+ const s = this.msgBus.onceAsync({
151
+ channel: "APP-SECURITY-AUTH-SIGNIN",
152
+ group: "out"
153
+ }), e = async () => {
154
+ throw await this.msgBus.onceAsync({
155
+ channel: "APP-SECURITY-AUTH-SIGNOUT",
156
+ group: "out"
157
+ }), new Error("Auth failed: login aborted");
158
+ };
159
+ this.msgBus.dispatch({
160
+ channel: "APP-SECURITY-REQUEST-AUTH-SIGNIN",
161
+ payload: {
162
+ callbackUrl: window.location.pathname + window.location.search
163
+ }
164
+ }), await Promise.race([s, e]);
165
+ }
166
+ async signInAsync(s) {
167
+ var u;
168
+ let e = (u = this.domainConfig.routes) == null ? void 0 : u.authSignIn;
169
+ e = e.replace(/[?&]$/, "");
170
+ const a = JSON.stringify(s), n = {
171
+ url: e,
172
+ body: a,
173
+ method: "POST",
174
+ headers: {
175
+ "Content-Type": "application/json",
176
+ Accept: "text/plain"
177
+ }
178
+ }, i = {
179
+ ...n,
180
+ status: "executing"
181
+ }, c = await this.fetcher.fetch(e, n);
182
+ await h(c, i), l.assert(c, i);
183
+ let o = c.resolved.json;
184
+ return this.userCredentials = s, this.accessToken = o.accessToken, this.refreshToken = o.refreshToken, this.saveDataAsync(), this.getContext();
185
+ }
186
+ async saveDataAsync() {
187
+ await this.msgBus.dispatchAsync({
188
+ channel: "APP-KV-STORE-SET",
189
+ payload: {
190
+ key: this.storageKeys.accessToken,
191
+ value: this.accessToken || null
192
+ }
193
+ }), await this.msgBus.dispatchAsync({
194
+ channel: "APP-KV-STORE-SET",
195
+ payload: {
196
+ key: this.storageKeys.refreshToken,
197
+ value: this.refreshToken || null
198
+ }
199
+ }), await this.msgBus.dispatchAsync({
200
+ channel: "APP-KV-STORE-SET",
201
+ payload: {
202
+ key: this.storageKeys.userCredentials,
203
+ value: this.userCredentials ? JSON.stringify(this.userCredentials) : ""
204
+ }
205
+ }), await this.msgBus.dispatchAsync({
206
+ channel: "APP-KV-STORE-SET",
207
+ payload: {
208
+ key: this.storageKeys.acl,
209
+ value: this.acl ? JSON.stringify(this.acl) : ""
210
+ }
211
+ });
212
+ }
213
+ async signOutAsync() {
214
+ var i;
215
+ let s = (i = this.domainConfig.routes) == null ? void 0 : i.authSignOut;
216
+ s && (s = s.replace(/[?&]$/, ""));
217
+ const e = {
218
+ url: s,
219
+ method: "POST",
220
+ headers: {
221
+ "Content-Type": "application/json",
222
+ Accept: "text/plain"
223
+ }
224
+ }, a = {
225
+ ...e,
226
+ status: "executing"
227
+ }, n = await this.fetcher.fetch(s, e);
228
+ await h(n, a), l.assert(n, a), this.clearSavedDataAsync();
229
+ }
230
+ async refreshAsync() {
231
+ var o;
232
+ let s = (o = this.domainConfig.routes) == null ? void 0 : o.authRefresh;
233
+ s && (s = s.replace(/[?&]$/, ""));
234
+ let e = {
235
+ refreshToken: this.refreshToken
236
+ };
237
+ const a = JSON.stringify(e), n = {
238
+ url: s,
239
+ body: a,
240
+ method: "POST",
241
+ // useAuth: true,
242
+ headers: {
243
+ "Content-Type": "application/json",
244
+ Accept: "text/plain"
245
+ }
246
+ }, i = {
247
+ ...n,
248
+ status: "executing"
249
+ }, c = await this.fetcher.fetch(s, n);
250
+ return await h(c, i), l.assert(c, i), e = c.resolved.json, this.accessToken = e.accessToken, this.refreshToken = e.refreshToken, this.saveDataAsync(), this.getContext();
251
+ }
252
+ async getAcl(s) {
253
+ return {
254
+ [y.Full]: ""
255
+ };
256
+ }
257
+ // authorize
258
+ async verifyAccess(s, e = y.Full) {
259
+ return this.getAcl(s), !1;
260
+ }
261
+ }
262
+ export {
263
+ f as SecurityProvider
264
+ };
265
+ //# sourceMappingURL=securityProvider.es.js.map