@owlmeans/client-panel 0.1.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/LICENSE +21 -0
- package/README.md +791 -0
- package/build/.gitkeep +0 -0
- package/build/auth/i18n/en.json +56 -0
- package/build/auth/i18n.d.ts +2 -0
- package/build/auth/i18n.d.ts.map +1 -0
- package/build/auth/i18n.js +4 -0
- package/build/auth/i18n.js.map +1 -0
- package/build/auth/index.d.ts +2 -0
- package/build/auth/index.d.ts.map +1 -0
- package/build/auth/index.js +2 -0
- package/build/auth/index.js.map +1 -0
- package/build/auth/plugins/consts.d.ts +4 -0
- package/build/auth/plugins/consts.d.ts.map +1 -0
- package/build/auth/plugins/consts.js +13 -0
- package/build/auth/plugins/consts.js.map +1 -0
- package/build/auth/plugins/exports.d.ts +3 -0
- package/build/auth/plugins/exports.d.ts.map +1 -0
- package/build/auth/plugins/exports.js +3 -0
- package/build/auth/plugins/exports.js.map +1 -0
- package/build/auth/plugins/types.d.ts +6 -0
- package/build/auth/plugins/types.d.ts.map +1 -0
- package/build/auth/plugins/types.js +2 -0
- package/build/auth/plugins/types.js.map +1 -0
- package/build/components/consts.d.ts +6 -0
- package/build/components/consts.d.ts.map +1 -0
- package/build/components/consts.js +7 -0
- package/build/components/consts.js.map +1 -0
- package/build/components/context.d.ts +9 -0
- package/build/components/context.d.ts.map +1 -0
- package/build/components/context.js +30 -0
- package/build/components/context.js.map +1 -0
- package/build/components/form/context.d.ts +8 -0
- package/build/components/form/context.d.ts.map +1 -0
- package/build/components/form/context.js +26 -0
- package/build/components/form/context.js.map +1 -0
- package/build/components/form/helper.d.ts +4 -0
- package/build/components/form/helper.d.ts.map +1 -0
- package/build/components/form/helper.js +5 -0
- package/build/components/form/helper.js.map +1 -0
- package/build/components/form/index.d.ts +4 -0
- package/build/components/form/index.d.ts.map +1 -0
- package/build/components/form/index.js +4 -0
- package/build/components/form/index.js.map +1 -0
- package/build/components/form/types.d.ts +33 -0
- package/build/components/form/types.d.ts.map +1 -0
- package/build/components/form/types.js +2 -0
- package/build/components/form/types.js.map +1 -0
- package/build/components/index.d.ts +6 -0
- package/build/components/index.d.ts.map +1 -0
- package/build/components/index.js +5 -0
- package/build/components/index.js.map +1 -0
- package/build/components/layout/helper.d.ts +6 -0
- package/build/components/layout/helper.d.ts.map +1 -0
- package/build/components/layout/helper.js +17 -0
- package/build/components/layout/helper.js.map +1 -0
- package/build/components/layout/index.d.ts +2 -0
- package/build/components/layout/index.d.ts.map +1 -0
- package/build/components/layout/index.js +2 -0
- package/build/components/layout/index.js.map +1 -0
- package/build/components/types.d.ts +7 -0
- package/build/components/types.d.ts.map +1 -0
- package/build/components/types.js +2 -0
- package/build/components/types.js.map +1 -0
- package/build/helper/form.d.ts +3 -0
- package/build/helper/form.d.ts.map +1 -0
- package/build/helper/form.js +5 -0
- package/build/helper/form.js.map +1 -0
- package/build/helper/index.d.ts +2 -0
- package/build/helper/index.d.ts.map +1 -0
- package/build/helper/index.js +2 -0
- package/build/helper/index.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -0
- package/package.json +74 -0
- package/src/auth/i18n/en.json +56 -0
- package/src/auth/i18n.ts +5 -0
- package/src/auth/index.ts +2 -0
- package/src/auth/plugins/consts.ts +15 -0
- package/src/auth/plugins/exports.ts +3 -0
- package/src/auth/plugins/types.ts +6 -0
- package/src/components/consts.ts +6 -0
- package/src/components/context.tsx +44 -0
- package/src/components/form/context.tsx +39 -0
- package/src/components/form/helper.ts +7 -0
- package/src/components/form/index.ts +4 -0
- package/src/components/form/types.ts +37 -0
- package/src/components/index.ts +6 -0
- package/src/components/layout/helper.ts +26 -0
- package/src/components/layout/index.ts +2 -0
- package/src/components/types.ts +7 -0
- package/src/helper/form.ts +7 -0
- package/src/helper/index.ts +2 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"basic-ed25519": {
|
|
3
|
+
"entityId": {
|
|
4
|
+
"label": "Organization id"
|
|
5
|
+
},
|
|
6
|
+
"address": {
|
|
7
|
+
"label": "User DID"
|
|
8
|
+
},
|
|
9
|
+
"privateKey": {
|
|
10
|
+
"label": "Private key"
|
|
11
|
+
},
|
|
12
|
+
"submit": "Authenticate"
|
|
13
|
+
},
|
|
14
|
+
"re-captcha": {
|
|
15
|
+
"guideline": "We need to make sure that you are not a robot. Please click in the white box below to prove that you are a human."
|
|
16
|
+
},
|
|
17
|
+
"wallet-provider": {
|
|
18
|
+
"pin": {
|
|
19
|
+
"loading": "Loading...",
|
|
20
|
+
"guideline": "Use this pin-code on any resource supporting wallet-base authorization"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"wallet-consumer": {
|
|
24
|
+
"pin": {
|
|
25
|
+
"label": "Pin-code",
|
|
26
|
+
"hint": "Scan the QR code or genereta a pin-code with your OwlMeans ID app"
|
|
27
|
+
},
|
|
28
|
+
"submit": "Proceed with pin"
|
|
29
|
+
},
|
|
30
|
+
"oidp-auth": {
|
|
31
|
+
"reset": "Reset",
|
|
32
|
+
"error": {
|
|
33
|
+
"socket": {
|
|
34
|
+
"timeout": {
|
|
35
|
+
"rely": "Authentication window expired. Please refresh to try again."
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"oidp-create-id": {
|
|
41
|
+
"error": {
|
|
42
|
+
"socket": {
|
|
43
|
+
"timeout": {
|
|
44
|
+
"call": "Action timeout! For security reason we set a time limit on authentication actions. Please try again.",
|
|
45
|
+
"rely": "Authentication code expired. Please try again."
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"auth": {
|
|
49
|
+
"authorization": {
|
|
50
|
+
"sequence": "Auhtentcation process was interupted by the authentication app you use."
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"reset": "Reload"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/auth/i18n.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JSONSchemaType } from 'ajv'
|
|
2
|
+
import { Ed22519BasicAuthUIPluginForm } from './types.js'
|
|
3
|
+
|
|
4
|
+
// @TODO Move to some abstract layer cause this validation is the same for both client
|
|
5
|
+
// and server
|
|
6
|
+
export const Ed22519BasicAuthUIPluginFormSchema: JSONSchemaType<Ed22519BasicAuthUIPluginForm> = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
entityId: { type: 'string', minLength: 1, maxLength: 255, default: '' },
|
|
10
|
+
address: { type: 'string', minLength: 1, maxLength: 255, default: '' },
|
|
11
|
+
privateKey: { type: 'string', minLength: 1, maxLength: 512, default: '' }
|
|
12
|
+
},
|
|
13
|
+
required: ['entityId', 'address', 'privateKey'],
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FC } from 'react'
|
|
2
|
+
import { createContext, useContext as useReactContext } from 'react'
|
|
3
|
+
import type { TPanelContext } from './types.js'
|
|
4
|
+
import { I18nProps, useCommonI18n, useI18nLib } from '@owlmeans/client-i18n'
|
|
5
|
+
import { useContext } from '@owlmeans/client'
|
|
6
|
+
import { ResilientError } from '@owlmeans/error'
|
|
7
|
+
|
|
8
|
+
const PanelContext_ = createContext<TPanelContext>({})
|
|
9
|
+
|
|
10
|
+
export const PanelContext: FC<TPanelContext> = ({ children, ...props }) => {
|
|
11
|
+
const parent = usePanelHelper()
|
|
12
|
+
props = { ...parent, ...props }
|
|
13
|
+
|
|
14
|
+
return <PanelContext_.Provider value={props}>{children}</PanelContext_.Provider>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const usePanelHelper = () => useReactContext<TPanelContext>(PanelContext_)
|
|
18
|
+
|
|
19
|
+
export const usePanelI18n = (name?: string, override?: I18nProps["i18n"]) => {
|
|
20
|
+
const context = useContext()
|
|
21
|
+
const i18n = { ...usePanelHelper(), ...override }
|
|
22
|
+
const prefix = (i18n?.prefix ?? '') + (name != null && i18n?.prefix != null ? '.' : '') + (name ?? '')
|
|
23
|
+
|
|
24
|
+
return useCommonI18n(
|
|
25
|
+
i18n?.resource ?? context.cfg.service,
|
|
26
|
+
i18n?.ns ?? context.cfg.service ?? i18n?.resource,
|
|
27
|
+
prefix
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const usePanelError = (name: string, error?: ResilientError) => {
|
|
32
|
+
const t = usePanelI18n()
|
|
33
|
+
const key = name
|
|
34
|
+
|
|
35
|
+
const libT = useI18nLib('errors')
|
|
36
|
+
|
|
37
|
+
return error != null ?
|
|
38
|
+
error.type != null
|
|
39
|
+
? t([`${key}.errors.${error.type}`, `errors.${error.type}`], {
|
|
40
|
+
defaultValue: libT(error.type ?? 'form-field')
|
|
41
|
+
}) : t(`${key}.error`, {
|
|
42
|
+
defaultValue: libT('form-field')
|
|
43
|
+
}) : undefined
|
|
44
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FC, PropsWithChildren } from 'react'
|
|
2
|
+
import { createContext, useContext as useReactContext } from 'react'
|
|
3
|
+
import { useCommonI18n, useI18nLib } from '@owlmeans/client-i18n'
|
|
4
|
+
import type { FieldError } from 'react-hook-form'
|
|
5
|
+
import { useContext } from '@owlmeans/client'
|
|
6
|
+
import type { TFormContext } from './types.js'
|
|
7
|
+
|
|
8
|
+
const FormContext_ = createContext<TFormContext>({} as unknown as TFormContext)
|
|
9
|
+
|
|
10
|
+
export const FormContext: FC<PropsWithChildren<TFormContext>> = ({ children, ...props }) =>
|
|
11
|
+
<FormContext_.Provider value={props}>{children}</FormContext_.Provider>
|
|
12
|
+
|
|
13
|
+
export const useClientFormContext = () => useReactContext<TFormContext>(FormContext_)
|
|
14
|
+
|
|
15
|
+
export const useFormI18n = () => {
|
|
16
|
+
const context = useContext()
|
|
17
|
+
const { i18n, name } = useClientFormContext()
|
|
18
|
+
const prefix = (i18n?.prefix != null ? i18n.prefix + '.' : '') + (name ?? '')
|
|
19
|
+
return useCommonI18n(
|
|
20
|
+
i18n?.resource ?? context.cfg.service,
|
|
21
|
+
i18n?.ns ?? i18n?.resource ?? context.cfg.service,
|
|
22
|
+
prefix
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const useFormError = (name: string, error?: FieldError) => {
|
|
27
|
+
const t = useFormI18n()
|
|
28
|
+
const key = name
|
|
29
|
+
|
|
30
|
+
const libT = useI18nLib('errors')
|
|
31
|
+
|
|
32
|
+
return error != null ?
|
|
33
|
+
error.type != null
|
|
34
|
+
? t([`${key}.errors.${error.type}`, `errors.${error.type}`], {
|
|
35
|
+
defaultValue: libT(error.type ?? 'form-field')
|
|
36
|
+
}) : t(`${key}.error`, {
|
|
37
|
+
defaultValue: libT('form-field')
|
|
38
|
+
}) : undefined
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AnySchema } from 'ajv'
|
|
2
|
+
import type { PropsWithChildren, MutableRefObject } from 'react'
|
|
3
|
+
import type { UseFormReturn, FieldValues } from 'react-hook-form'
|
|
4
|
+
import type { I18nProps } from '@owlmeans/client-i18n'
|
|
5
|
+
import type { Toggleable } from '@owlmeans/client'
|
|
6
|
+
import type { BlockScaling } from '../consts.js'
|
|
7
|
+
|
|
8
|
+
export interface FormProps extends PropsWithChildren<I18nProps> {
|
|
9
|
+
name?: string
|
|
10
|
+
formRef?: MutableRefObject<FormRef<any> | null>
|
|
11
|
+
defaults?: Record<string, any>
|
|
12
|
+
validation?: AnySchema
|
|
13
|
+
decorate?: boolean
|
|
14
|
+
horizontal?: BlockScaling
|
|
15
|
+
vertical?: BlockScaling
|
|
16
|
+
onSubmit?: FormOnSubmit<any>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FormRef<T extends FieldValues = FieldValues> {
|
|
20
|
+
form: UseFormReturn<T>
|
|
21
|
+
update: (data: T) => void
|
|
22
|
+
loader: Toggleable
|
|
23
|
+
error: (error: unknown, target?: string) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FormOnSubmit<T> {
|
|
27
|
+
(data: T, update?: (data: T) => void): Promise<void> | void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TFormContext extends Omit<FormProps, 'defaults' | 'children'> {
|
|
31
|
+
loader: Toggleable
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface FormFieldProps {
|
|
35
|
+
name: string
|
|
36
|
+
def?: any
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ClientRoute } from '@owlmeans/client-route'
|
|
2
|
+
import type { Location } from 'react-router'
|
|
3
|
+
import type { ClientModule } from '@owlmeans/client-module'
|
|
4
|
+
import type { AbstractRequest } from '@owlmeans/module'
|
|
5
|
+
|
|
6
|
+
import { useLocation } from 'react-router'
|
|
7
|
+
import { useContext } from '@owlmeans/client'
|
|
8
|
+
import { usePanelI18n } from '../context.js'
|
|
9
|
+
import { useMemo } from 'react'
|
|
10
|
+
|
|
11
|
+
export const usePanelLayout = <T = {}, R extends AbstractRequest = AbstractRequest>(): ClientModule<T, R> => {
|
|
12
|
+
const context = useContext()
|
|
13
|
+
const location: Location<ClientRoute> = useLocation()
|
|
14
|
+
|
|
15
|
+
return context.module(location.state.alias)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useLayoutTitle = (name?: string, alias?: string): string => {
|
|
19
|
+
const layout = usePanelLayout()
|
|
20
|
+
const t = usePanelI18n(name)
|
|
21
|
+
alias = alias ?? layout.alias
|
|
22
|
+
|
|
23
|
+
return useMemo(() => t(`${prepareLayoutTitle(alias)}`), [alias, name])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const prepareLayoutTitle = (title: string) => `${title.replace(/\W+/g, '.')}.title`
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
import type { AnySchema, JSONSchemaType } from 'ajv'
|
|
3
|
+
|
|
4
|
+
export const schemaToFormDefault = (schema: AnySchema): Record<string, any> => {
|
|
5
|
+
const _schema: JSONSchemaType<unknown> = schema as JSONSchemaType<unknown>
|
|
6
|
+
return Object.fromEntries(Object.entries(_schema.properties).map(([key, value]) => [key, (value as any).default ?? '']))
|
|
7
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"../tsconfig.default.json",
|
|
4
|
+
"../tsconfig.react.json",
|
|
5
|
+
],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"rootDir": "./src/", /* Specify the root folder within your source files. */
|
|
8
|
+
"outDir": "./build/", /* Specify an output folder for all emitted files. */
|
|
9
|
+
"moduleResolution": "Bundler"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"./dist/**/*",
|
|
13
|
+
"./build/**/*",
|
|
14
|
+
"./*.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/index.ts","./src/auth/i18n.ts","./src/auth/index.ts","./src/auth/plugins/consts.ts","./src/auth/plugins/exports.ts","./src/auth/plugins/types.ts","./src/components/consts.ts","./src/components/context.tsx","./src/components/index.ts","./src/components/types.ts","./src/components/form/context.tsx","./src/components/form/helper.ts","./src/components/form/index.ts","./src/components/form/types.ts","./src/components/layout/helper.ts","./src/components/layout/index.ts","./src/helper/form.ts","./src/helper/index.ts"],"version":"5.6.3"}
|