@cratis/arc.react 18.7.19 → 18.7.21
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/commands/for_useCommand/FakeCommand.ts +4 -5
- package/commands/for_useCommand/when_creating_instance_with_initial_values.ts +3 -1
- package/commands/useCommand.ts +5 -5
- package/dist/cjs/commands/for_useCommand/FakeCommand.d.ts +0 -1
- package/dist/cjs/commands/for_useCommand/FakeCommand.d.ts.map +1 -1
- package/dist/cjs/commands/useCommand.js +5 -5
- package/dist/cjs/commands/useCommand.js.map +1 -1
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +25 -9
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/given/an_identity_provider.d.ts +26 -0
- package/dist/cjs/identity/for_IdentityProvider/given/an_identity_provider.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts.map +1 -0
- package/dist/esm/commands/for_useCommand/FakeCommand.d.ts +0 -1
- package/dist/esm/commands/for_useCommand/FakeCommand.d.ts.map +1 -1
- package/dist/esm/commands/for_useCommand/FakeCommand.js +5 -4
- package/dist/esm/commands/for_useCommand/FakeCommand.js.map +1 -1
- package/dist/esm/commands/for_useCommand/when_creating_instance_with_initial_values.js +3 -1
- package/dist/esm/commands/for_useCommand/when_creating_instance_with_initial_values.js.map +1 -1
- package/dist/esm/commands/useCommand.js +5 -5
- package/dist/esm/commands/useCommand.js.map +1 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +25 -9
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.d.ts +26 -0
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.js +75 -0
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.js +27 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.js +21 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.js +19 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.js +14 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.js +17 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing_identity.js +15 -45
- package/dist/esm/identity/for_IdentityProvider/when_refreshing_identity.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IdentityProvider.tsx +28 -9
- package/identity/for_IdentityProvider/given/an_identity_provider.ts +103 -0
- package/identity/for_IdentityProvider/when_initial_fetch_fails.ts +35 -0
- package/identity/for_IdentityProvider/when_initial_fetch_succeeds.ts +29 -0
- package/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.ts +29 -0
- package/identity/for_IdentityProvider/when_refresh_is_called/and_fails.ts +23 -0
- package/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.ts +30 -0
- package/identity/for_IdentityProvider/when_refreshing_identity.ts +17 -51
- package/package.json +2 -2
|
@@ -12,7 +12,10 @@ export interface FakeCommandContent {
|
|
|
12
12
|
export class FakeCommand extends Command<FakeCommandContent> {
|
|
13
13
|
readonly route = '/api/fake-command';
|
|
14
14
|
readonly validation = {} as CommandValidator;
|
|
15
|
-
readonly propertyDescriptors: PropertyDescriptor[] = [
|
|
15
|
+
readonly propertyDescriptors: PropertyDescriptor[] = [
|
|
16
|
+
new PropertyDescriptor('someProperty', String, true),
|
|
17
|
+
new PropertyDescriptor('anotherProperty', Number, true)
|
|
18
|
+
];
|
|
16
19
|
|
|
17
20
|
someProperty?: string;
|
|
18
21
|
anotherProperty?: number;
|
|
@@ -21,10 +24,6 @@ export class FakeCommand extends Command<FakeCommandContent> {
|
|
|
21
24
|
return [];
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
get properties(): string[] {
|
|
25
|
-
return ['someProperty', 'anotherProperty'];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
27
|
constructor() {
|
|
29
28
|
super(Object, false);
|
|
30
29
|
}
|
|
@@ -22,7 +22,9 @@ describe('when creating instance with initial values', () => {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const config: ArcConfiguration = {
|
|
25
|
-
microservice: 'test-microservice'
|
|
25
|
+
microservice: 'test-microservice',
|
|
26
|
+
apiBasePath: '/api',
|
|
27
|
+
origin: 'https://example.com'
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
render(
|
package/commands/useCommand.ts
CHANGED
|
@@ -53,16 +53,16 @@ export function useCommand<
|
|
|
53
53
|
|
|
54
54
|
const setCommandValues = (values: TCommandContent) => {
|
|
55
55
|
const valuesRecord = values as Record<string, unknown>;
|
|
56
|
-
command!.current!.
|
|
57
|
-
if (valuesRecord[
|
|
58
|
-
(command.current as Record<string, unknown>)[
|
|
56
|
+
command!.current!.propertyDescriptors.forEach((propertyDescriptor) => {
|
|
57
|
+
if (valuesRecord[propertyDescriptor.name] !== undefined && valuesRecord[propertyDescriptor.name] != null) {
|
|
58
|
+
(command.current as Record<string, unknown>)[propertyDescriptor.name] = valuesRecord[propertyDescriptor.name];
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const clearCommandValues = () => {
|
|
64
|
-
command.current!.
|
|
65
|
-
(command.current as Record<string, unknown>)[
|
|
64
|
+
command.current!.propertyDescriptors.forEach((propertyDescriptor) => {
|
|
65
|
+
(command.current as Record<string, unknown>)[propertyDescriptor.name] = undefined;
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -11,7 +11,6 @@ export declare class FakeCommand extends Command<FakeCommandContent> {
|
|
|
11
11
|
someProperty?: string;
|
|
12
12
|
anotherProperty?: number;
|
|
13
13
|
get requestParameters(): string[];
|
|
14
|
-
get properties(): string[];
|
|
15
14
|
constructor();
|
|
16
15
|
}
|
|
17
16
|
//# sourceMappingURL=FakeCommand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeCommand.d.ts","sourceRoot":"","sources":["../../../../commands/for_useCommand/FakeCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,WAAY,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACxD,QAAQ,CAAC,KAAK,uBAAuB;IACrC,QAAQ,CAAC,UAAU,EAAS,gBAAgB,CAAC;IAC7C,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"FakeCommand.d.ts","sourceRoot":"","sources":["../../../../commands/for_useCommand/FakeCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,WAAY,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACxD,QAAQ,CAAC,KAAK,uBAAuB;IACrC,QAAQ,CAAC,UAAU,EAAS,gBAAgB,CAAC;IAC7C,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAGhD;IAEF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAEhC;;CAKJ"}
|
|
@@ -29,15 +29,15 @@ function useCommand(commandType, initialValues) {
|
|
|
29
29
|
context.addCommand?.(command.current);
|
|
30
30
|
const setCommandValues = (values) => {
|
|
31
31
|
const valuesRecord = values;
|
|
32
|
-
command.current.
|
|
33
|
-
if (valuesRecord[
|
|
34
|
-
command.current[
|
|
32
|
+
command.current.propertyDescriptors.forEach((propertyDescriptor) => {
|
|
33
|
+
if (valuesRecord[propertyDescriptor.name] !== undefined && valuesRecord[propertyDescriptor.name] != null) {
|
|
34
|
+
command.current[propertyDescriptor.name] = valuesRecord[propertyDescriptor.name];
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
const clearCommandValues = () => {
|
|
39
|
-
command.current.
|
|
40
|
-
command.current[
|
|
39
|
+
command.current.propertyDescriptors.forEach((propertyDescriptor) => {
|
|
40
|
+
command.current[propertyDescriptor.name] = undefined;
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
return [command.current, setCommandValues, clearCommandValues];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommand.js","sources":["../../../commands/useCommand.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { useState, useCallback, useContext, useRef, useMemo } from 'react';\nimport { Command } from '@cratis/arc/commands';\nimport React from 'react';\nimport { CommandScopeContext } from './CommandScope';\nimport { ArcContext } from '../ArcContext';\n\nexport type SetCommandValues<TCommandContent> = (command: TCommandContent) => void;\nexport type ClearCommandValues = () => void;\n\n/**\n * Use a command in a component.\n * @param commandType Type of the command to use.\n * @param initialValues Any initial values to set for the command.\n * @returns Tuple with the command, a {@link SetCommandValues<TCommandContent>} delegate to set values on command and {@link ClearCommandValues} delegate clear values.\n */\nexport function useCommand<\n TCommand extends Command<TCommandContent, TCommandResponse>,\n TCommandContent = object,\n TCommandResponse = object\n>(\n commandType: Constructor<TCommand>,\n initialValues?: TCommandContent\n): [TCommand, SetCommandValues<TCommandContent>, ClearCommandValues] {\n const command = useRef<TCommand | null>(null);\n const [hasChanges, setHasChanges] = useState(false);\n const arc = useContext(ArcContext);\n\n const propertyChangedCallback = useCallback(() => {\n if (command.current?.hasChanges !== hasChanges) {\n setHasChanges(command.current?.hasChanges ?? false);\n }\n }, []);\n\n command.current = useMemo(() => {\n const instance = new commandType();\n instance.setMicroservice(arc.microservice);\n instance.setApiBasePath(arc.apiBasePath ?? '');\n instance.setOrigin(arc.origin ?? '');\n instance.setHttpHeadersCallback(arc.httpHeadersCallback ?? (() => ({})));\n if (initialValues) {\n instance.setInitialValues(initialValues);\n }\n instance.onPropertyChanged(propertyChangedCallback, instance);\n return instance;\n }, []);\n\n const context = React.useContext(CommandScopeContext);\n context.addCommand?.(command.current! as Command<object, object>);\n\n const setCommandValues = (values: TCommandContent) => {\n const valuesRecord = values as Record<string, unknown>;\n command!.current!.
|
|
1
|
+
{"version":3,"file":"useCommand.js","sources":["../../../commands/useCommand.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { useState, useCallback, useContext, useRef, useMemo } from 'react';\nimport { Command } from '@cratis/arc/commands';\nimport React from 'react';\nimport { CommandScopeContext } from './CommandScope';\nimport { ArcContext } from '../ArcContext';\n\nexport type SetCommandValues<TCommandContent> = (command: TCommandContent) => void;\nexport type ClearCommandValues = () => void;\n\n/**\n * Use a command in a component.\n * @param commandType Type of the command to use.\n * @param initialValues Any initial values to set for the command.\n * @returns Tuple with the command, a {@link SetCommandValues<TCommandContent>} delegate to set values on command and {@link ClearCommandValues} delegate clear values.\n */\nexport function useCommand<\n TCommand extends Command<TCommandContent, TCommandResponse>,\n TCommandContent = object,\n TCommandResponse = object\n>(\n commandType: Constructor<TCommand>,\n initialValues?: TCommandContent\n): [TCommand, SetCommandValues<TCommandContent>, ClearCommandValues] {\n const command = useRef<TCommand | null>(null);\n const [hasChanges, setHasChanges] = useState(false);\n const arc = useContext(ArcContext);\n\n const propertyChangedCallback = useCallback(() => {\n if (command.current?.hasChanges !== hasChanges) {\n setHasChanges(command.current?.hasChanges ?? false);\n }\n }, []);\n\n command.current = useMemo(() => {\n const instance = new commandType();\n instance.setMicroservice(arc.microservice);\n instance.setApiBasePath(arc.apiBasePath ?? '');\n instance.setOrigin(arc.origin ?? '');\n instance.setHttpHeadersCallback(arc.httpHeadersCallback ?? (() => ({})));\n if (initialValues) {\n instance.setInitialValues(initialValues);\n }\n instance.onPropertyChanged(propertyChangedCallback, instance);\n return instance;\n }, []);\n\n const context = React.useContext(CommandScopeContext);\n context.addCommand?.(command.current! as Command<object, object>);\n\n const setCommandValues = (values: TCommandContent) => {\n const valuesRecord = values as Record<string, unknown>;\n command!.current!.propertyDescriptors.forEach((propertyDescriptor) => {\n if (valuesRecord[propertyDescriptor.name] !== undefined && valuesRecord[propertyDescriptor.name] != null) {\n (command.current as Record<string, unknown>)[propertyDescriptor.name] = valuesRecord[propertyDescriptor.name];\n }\n });\n };\n\n const clearCommandValues = () => {\n command.current!.propertyDescriptors.forEach((propertyDescriptor) => {\n (command.current as Record<string, unknown>)[propertyDescriptor.name] = undefined;\n });\n };\n\n return [command.current!, setCommandValues, clearCommandValues];\n}\n"],"names":["useRef","useState","useContext","ArcContext","useCallback","useMemo","CommandScopeContext"],"mappings":";;;;;;AAmBM,SAAU,UAAU,CAKtB,WAAkC,EAClC,aAA+B,EAAA;AAE/B,IAAA,MAAM,OAAO,GAAGA,YAAM,CAAkB,IAAI,CAAC;IAC7C,M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AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,qBAAqB,
|
|
1
|
+
{"version":3,"file":"IdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/IdentityProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAe7C,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,kBAAkB,CAAC,EAAE,WAAW,CAAC;CACpC,CAAC;AAMF,eAAO,MAAM,uBAAuB,qCAAiE,CAAC;AAEtG,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IACvC,mBAAmB,CAAC,EAAE,cAAc,CAAC;IACrC,WAAW,CAAC,EAAE,WAAW,CAAA;CAC5B;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,qBAAqB,4CA4D5D,CAAC"}
|
|
@@ -22,13 +22,22 @@ const defaultContextValue = {
|
|
|
22
22
|
const IdentityProviderContext = React.createContext(defaultContextValue);
|
|
23
23
|
const IdentityProvider = (props) => {
|
|
24
24
|
const arc = React.useContext(ArcContext.ArcContext);
|
|
25
|
-
const
|
|
25
|
+
const fetchIdentity = () => {
|
|
26
|
+
return identity.IdentityProvider.getCurrent(props.detailsType).then(identity => {
|
|
27
|
+
const wrappedIdentity = wrapRefresh(identity);
|
|
28
|
+
setContext({
|
|
29
|
+
identity: wrappedIdentity,
|
|
30
|
+
detailsConstructor: props.detailsType
|
|
31
|
+
});
|
|
32
|
+
return wrappedIdentity;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
26
35
|
const wrapRefresh = (identity) => {
|
|
27
36
|
const originalRefresh = identity.refresh.bind(identity);
|
|
28
37
|
return {
|
|
29
38
|
...identity,
|
|
30
39
|
refresh: () => {
|
|
31
|
-
return new Promise(resolve => {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
32
41
|
originalRefresh().then(newIdentity => {
|
|
33
42
|
const wrappedIdentity = wrapRefresh(newIdentity);
|
|
34
43
|
setContext({
|
|
@@ -36,21 +45,28 @@ const IdentityProvider = (props) => {
|
|
|
36
45
|
detailsConstructor: props.detailsType
|
|
37
46
|
});
|
|
38
47
|
resolve(wrappedIdentity);
|
|
39
|
-
});
|
|
48
|
+
}).catch(reject);
|
|
40
49
|
});
|
|
41
50
|
}
|
|
42
51
|
};
|
|
43
52
|
};
|
|
53
|
+
const initialIdentity = {
|
|
54
|
+
id: '',
|
|
55
|
+
name: '',
|
|
56
|
+
details: {},
|
|
57
|
+
isSet: false,
|
|
58
|
+
refresh: () => fetchIdentity()
|
|
59
|
+
};
|
|
60
|
+
const [context, setContext] = React.useState({
|
|
61
|
+
identity: wrapRefresh(initialIdentity),
|
|
62
|
+
detailsConstructor: props.detailsType
|
|
63
|
+
});
|
|
44
64
|
React.useEffect(() => {
|
|
45
65
|
identity.IdentityProvider.setHttpHeadersCallback(props.httpHeadersCallback);
|
|
46
66
|
identity.IdentityProvider.setApiBasePath(arc.apiBasePath ?? '');
|
|
47
67
|
identity.IdentityProvider.setOrigin(arc.origin ?? '');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setContext({
|
|
51
|
-
identity: wrappedIdentity,
|
|
52
|
-
detailsConstructor: props.detailsType
|
|
53
|
-
});
|
|
68
|
+
fetchIdentity().catch(error => {
|
|
69
|
+
console.error('Failed to fetch initial identity:', error);
|
|
54
70
|
});
|
|
55
71
|
}, []);
|
|
56
72
|
return (jsxRuntime.jsx(IdentityProviderContext.Provider, { value: context, children: props.children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport React from 'react';\nimport { useState, useEffect, useContext } from 'react';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentity } from '@cratis/arc/identity';\nimport { IdentityProvider as RootIdentityProvider } from '@cratis/arc/identity';\nimport { GetHttpHeaders } from '@cratis/arc';\nimport { ArcContext } from '../ArcContext';\n\nconst defaultIdentityContext: IIdentity = {\n id: '',\n name: '',\n details: {},\n isSet: false,\n refresh: () => {\n return new Promise((resolve, reject) => {\n reject('Not implemented');\n });\n }\n};\n\ntype IdentityContextValue = {\n identity: IIdentity;\n detailsConstructor?: Constructor;\n};\n\nconst defaultContextValue: IdentityContextValue = {\n identity: defaultIdentityContext\n};\n\nexport const IdentityProviderContext = React.createContext<IdentityContextValue>(defaultContextValue);\n\nexport interface IdentityProviderProps {\n children?: JSX.Element | JSX.Element[],\n httpHeadersCallback?: GetHttpHeaders,\n detailsType?: Constructor\n}\n\nexport const IdentityProvider = (props: IdentityProviderProps) => {\n const arc = useContext(ArcContext);\n const
|
|
1
|
+
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport React from 'react';\nimport { useState, useEffect, useContext } from 'react';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentity } from '@cratis/arc/identity';\nimport { IdentityProvider as RootIdentityProvider } from '@cratis/arc/identity';\nimport { GetHttpHeaders } from '@cratis/arc';\nimport { ArcContext } from '../ArcContext';\n\nconst defaultIdentityContext: IIdentity = {\n id: '',\n name: '',\n details: {},\n isSet: false,\n refresh: () => {\n return new Promise((resolve, reject) => {\n reject('Not implemented');\n });\n }\n};\n\ntype IdentityContextValue = {\n identity: IIdentity;\n detailsConstructor?: Constructor;\n};\n\nconst defaultContextValue: IdentityContextValue = {\n identity: defaultIdentityContext\n};\n\nexport const IdentityProviderContext = React.createContext<IdentityContextValue>(defaultContextValue);\n\nexport interface IdentityProviderProps {\n children?: JSX.Element | JSX.Element[],\n httpHeadersCallback?: GetHttpHeaders,\n detailsType?: Constructor\n}\n\nexport const IdentityProvider = (props: IdentityProviderProps) => {\n const arc = useContext(ArcContext);\n \n const fetchIdentity = (): Promise<IIdentity> => {\n return RootIdentityProvider.getCurrent(props.detailsType).then(identity => {\n const wrappedIdentity = wrapRefresh(identity);\n setContext({\n identity: wrappedIdentity,\n detailsConstructor: props.detailsType\n });\n return wrappedIdentity;\n });\n };\n\n const wrapRefresh = (identity: IIdentity): IIdentity => {\n const originalRefresh = identity.refresh.bind(identity);\n return {\n ...identity,\n refresh: () => {\n return new Promise<IIdentity>((resolve, reject) => {\n originalRefresh().then(newIdentity => {\n const wrappedIdentity = wrapRefresh(newIdentity);\n setContext({\n identity: wrappedIdentity,\n detailsConstructor: props.detailsType\n });\n resolve(wrappedIdentity);\n }).catch(reject);\n });\n }\n };\n };\n\n const initialIdentity: IIdentity = {\n id: '',\n name: '',\n details: {},\n isSet: false,\n refresh: () => fetchIdentity()\n };\n\n const [context, setContext] = useState<IdentityContextValue>({\n identity: wrapRefresh(initialIdentity),\n detailsConstructor: props.detailsType\n });\n\n useEffect(() => {\n RootIdentityProvider.setHttpHeadersCallback(props.httpHeadersCallback!);\n RootIdentityProvider.setApiBasePath(arc.apiBasePath ?? '');\n RootIdentityProvider.setOrigin(arc.origin ?? '');\n fetchIdentity().catch(error => {\n console.error('Failed to fetch initial identity:', error);\n });\n }, []);\n\n return (\n <IdentityProviderContext.Provider value={context}>\n {props.children}\n </IdentityProviderContext.Provider>\n );\n};\n"],"names":["useContext","ArcContext","RootIdentityProvider","useState","useEffect","_jsx"],"mappings":";;;;;;;AAWA,MAAM,sBAAsB,GAAc;AACtC,IAAA,EAAE,EAAE,EAAE;AACN,IAAA,IAAI,EAAE,EAAE;AACR,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,KAAK,EAAE,KAAK;IACZ,OAAO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BAAA,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;AACpB,gBAAA,CAAC,CAAC;YACN;SACH;AACL,IAAA,CAAC;AAED,IAAA,MAAM,eAAe,GAAc;AAC/B,QAAA,EAAE,EAAE,EAAE;AACN,QAAA,IAAI,EAAE,EAAE;AACR,QAAA,OAAO,EAAE,EAAE;AACX,QAAA,KAAK,EAAE,KAAK;AACZ,QAAA,OAAO,EAAE,MAAM,aAAa;KAC/B;AAED,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,cAAQ,CAAuB;AACzD,QAAA,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC;QACtC,kBAAkB,EAAE,KAAK,CAAC;AAC7B,KAAA,CAAC;IAEFC,eAAS,CAAC,MAAK;AACX,QAAAF,yBAAoB,CAAC,sBAAsB,CAAC,KAAK,CAAC,mBAAoB,CAAC;QACvEA,yBAAoB,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;QAC1DA,yBAAoB,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;AAChD,QAAA,aAAa,EAAE,CAAC,KAAK,CAAC,KAAK,IAAG;AAC1B,YAAA,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC;AAC7D,QAAA,CAAC,CAAC;IACN,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,QACIG,cAAA,CAAC,uBAAuB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,OAAO,YAC3C,KAAK,CAAC,QAAQ,EAAA,CACgB;AAE3C;;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RenderResult } from '@testing-library/react';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import { IIdentity } from '@cratis/arc/identity';
|
|
5
|
+
import { createFetchHelper } from '@cratis/arc/helpers/fetchHelper';
|
|
6
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
7
|
+
export declare class an_identity_provider {
|
|
8
|
+
capturedIdentity: IIdentity | null;
|
|
9
|
+
renderCount: number;
|
|
10
|
+
renderResult: RenderResult;
|
|
11
|
+
originalApiBasePath: string;
|
|
12
|
+
originalOrigin: string;
|
|
13
|
+
private originalConsoleError?;
|
|
14
|
+
fetchHelper: ReturnType<typeof createFetchHelper>;
|
|
15
|
+
fetchStub: sinon.SinonStub;
|
|
16
|
+
constructor();
|
|
17
|
+
setupSuccessfulIdentityFetch(id: string, name: string, details?: object): void;
|
|
18
|
+
setupFailedIdentityFetch(): void;
|
|
19
|
+
createTestComponent(): () => React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
20
|
+
renderProvider(detailsType?: Constructor): void;
|
|
21
|
+
waitForAsyncUpdates(): Promise<void>;
|
|
22
|
+
suppressConsoleErrors(): void;
|
|
23
|
+
restoreConsole(): void;
|
|
24
|
+
cleanup(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=an_identity_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"an_identity_provider.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/given/an_identity_provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAU,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,oBAAoB;IAC7B,gBAAgB,EAAE,SAAS,GAAG,IAAI,CAAQ;IAC1C,WAAW,SAAK;IAChB,YAAY,EAAG,YAAY,CAAC;IAC5B,mBAAmB,SAAM;IACzB,cAAc,SAAM;IACpB,OAAO,CAAC,oBAAoB,CAAC,CAAuB;IACpD,WAAW,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAClD,SAAS,EAAG,KAAK,CAAC,SAAS,CAAC;;IAY5B,4BAA4B,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAW;IAO3E,wBAAwB;IAKxB,mBAAmB;IAQnB,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW;IAqBlC,mBAAmB;IAIzB,qBAAqB;IAOrB,cAAc;IAOd,OAAO;CASV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_initial_fetch_fails.d.ts","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_initial_fetch_fails.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_initial_fetch_succeeds.d.ts","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_initial_fetch_succeeds.ts"],"names":[],"mappings":""}
|
package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after_initial_failure.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_fails.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/and_fails.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_succeeds.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.ts"],"names":[],"mappings":""}
|
|
@@ -11,7 +11,6 @@ export declare class FakeCommand extends Command<FakeCommandContent> {
|
|
|
11
11
|
someProperty?: string;
|
|
12
12
|
anotherProperty?: number;
|
|
13
13
|
get requestParameters(): string[];
|
|
14
|
-
get properties(): string[];
|
|
15
14
|
constructor();
|
|
16
15
|
}
|
|
17
16
|
//# sourceMappingURL=FakeCommand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeCommand.d.ts","sourceRoot":"","sources":["../../../../commands/for_useCommand/FakeCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,WAAY,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACxD,QAAQ,CAAC,KAAK,uBAAuB;IACrC,QAAQ,CAAC,UAAU,EAAS,gBAAgB,CAAC;IAC7C,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"FakeCommand.d.ts","sourceRoot":"","sources":["../../../../commands/for_useCommand/FakeCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,WAAY,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACxD,QAAQ,CAAC,KAAK,uBAAuB;IACrC,QAAQ,CAAC,UAAU,EAAS,gBAAgB,CAAC;IAC7C,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAGhD;IAEF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAEhC;;CAKJ"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Command } from '@cratis/arc/commands';
|
|
2
|
+
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
2
3
|
export class FakeCommand extends Command {
|
|
3
4
|
route = '/api/fake-command';
|
|
4
5
|
validation = {};
|
|
5
|
-
propertyDescriptors = [
|
|
6
|
+
propertyDescriptors = [
|
|
7
|
+
new PropertyDescriptor('someProperty', String, true),
|
|
8
|
+
new PropertyDescriptor('anotherProperty', Number, true)
|
|
9
|
+
];
|
|
6
10
|
someProperty;
|
|
7
11
|
anotherProperty;
|
|
8
12
|
get requestParameters() {
|
|
9
13
|
return [];
|
|
10
14
|
}
|
|
11
|
-
get properties() {
|
|
12
|
-
return ['someProperty', 'anotherProperty'];
|
|
13
|
-
}
|
|
14
15
|
constructor() {
|
|
15
16
|
super(Object, false);
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeCommand.js","sourceRoot":"","sources":["../../../../commands/for_useCommand/FakeCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAoB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"FakeCommand.js","sourceRoot":"","sources":["../../../../commands/for_useCommand/FakeCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAoB,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAO5D,MAAM,OAAO,WAAY,SAAQ,OAA2B;IAC/C,KAAK,GAAG,mBAAmB,CAAC;IAC5B,UAAU,GAAG,EAAsB,CAAC;IACpC,mBAAmB,GAAyB;QACjD,IAAI,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC;QACpD,IAAI,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,CAAC;KAC1D,CAAC;IAEF,YAAY,CAAU;IACtB,eAAe,CAAU;IAEzB,IAAI,iBAAiB;QACjB,OAAO,EAAE,CAAC;IACd,CAAC;IAED;QACI,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;CACJ"}
|
|
@@ -15,7 +15,9 @@ describe('when creating instance with initial values', () => {
|
|
|
15
15
|
return React.createElement('div', null, 'Test');
|
|
16
16
|
};
|
|
17
17
|
const config = {
|
|
18
|
-
microservice: 'test-microservice'
|
|
18
|
+
microservice: 'test-microservice',
|
|
19
|
+
apiBasePath: '/api',
|
|
20
|
+
origin: 'https://example.com'
|
|
19
21
|
};
|
|
20
22
|
render(React.createElement(ArcContext.Provider, { value: config }, React.createElement(TestComponent)));
|
|
21
23
|
it('should set someProperty from initial values', () => capturedCommand.someProperty.should.equal('initial-value'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when_creating_instance_with_initial_values.js","sourceRoot":"","sources":["../../../../commands/for_useCommand/when_creating_instance_with_initial_values.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAEhE,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACxD,IAAI,eAAe,GAAuB,IAAI,CAAC;IAE/C,MAAM,aAAa,GAAuB;QACtC,YAAY,EAAE,eAAe;QAC7B,eAAe,EAAE,EAAE;KACtB,CAAC;IAEF,MAAM,aAAa,GAAG,GAAG,EAAE;QACvB,MAAM,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QACzD,eAAe,GAAG,OAAO,CAAC;QAC1B,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC,CAAC;IAEF,MAAM,MAAM,GAAqB;QAC7B,YAAY,EAAE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"when_creating_instance_with_initial_values.js","sourceRoot":"","sources":["../../../../commands/for_useCommand/when_creating_instance_with_initial_values.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAEhE,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACxD,IAAI,eAAe,GAAuB,IAAI,CAAC;IAE/C,MAAM,aAAa,GAAuB;QACtC,YAAY,EAAE,eAAe;QAC7B,eAAe,EAAE,EAAE;KACtB,CAAC;IAEF,MAAM,aAAa,GAAG,GAAG,EAAE;QACvB,MAAM,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QACzD,eAAe,GAAG,OAAO,CAAC;QAC1B,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC,CAAC;IAEF,MAAM,MAAM,GAAqB;QAC7B,YAAY,EAAE,mBAAmB;QACjC,WAAW,EAAE,MAAM;QACnB,MAAM,EAAE,qBAAqB;KAChC,CAAC;IAEF,MAAM,CACF,KAAK,CAAC,aAAa,CACf,UAAU,CAAC,QAAQ,EACnB,EAAE,KAAK,EAAE,MAAM,EAAE,EACjB,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,CACrC,CACJ,CAAC;IAEF,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE,CAAC,eAAgB,CAAC,YAAa,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IACtH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE,CAAC,eAAgB,CAAC,eAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACnH,CAAC,CAAC,CAAC"}
|
|
@@ -27,15 +27,15 @@ function useCommand(commandType, initialValues) {
|
|
|
27
27
|
context.addCommand?.(command.current);
|
|
28
28
|
const setCommandValues = (values) => {
|
|
29
29
|
const valuesRecord = values;
|
|
30
|
-
command.current.
|
|
31
|
-
if (valuesRecord[
|
|
32
|
-
command.current[
|
|
30
|
+
command.current.propertyDescriptors.forEach((propertyDescriptor) => {
|
|
31
|
+
if (valuesRecord[propertyDescriptor.name] !== undefined && valuesRecord[propertyDescriptor.name] != null) {
|
|
32
|
+
command.current[propertyDescriptor.name] = valuesRecord[propertyDescriptor.name];
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
const clearCommandValues = () => {
|
|
37
|
-
command.current.
|
|
38
|
-
command.current[
|
|
37
|
+
command.current.propertyDescriptors.forEach((propertyDescriptor) => {
|
|
38
|
+
command.current[propertyDescriptor.name] = undefined;
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
return [command.current, setCommandValues, clearCommandValues];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommand.js","sources":["../../../commands/useCommand.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { useState, useCallback, useContext, useRef, useMemo } from 'react';\nimport { Command } from '@cratis/arc/commands';\nimport React from 'react';\nimport { CommandScopeContext } from './CommandScope';\nimport { ArcContext } from '../ArcContext';\n\nexport type SetCommandValues<TCommandContent> = (command: TCommandContent) => void;\nexport type ClearCommandValues = () => void;\n\n/**\n * Use a command in a component.\n * @param commandType Type of the command to use.\n * @param initialValues Any initial values to set for the command.\n * @returns Tuple with the command, a {@link SetCommandValues<TCommandContent>} delegate to set values on command and {@link ClearCommandValues} delegate clear values.\n */\nexport function useCommand<\n TCommand extends Command<TCommandContent, TCommandResponse>,\n TCommandContent = object,\n TCommandResponse = object\n>(\n commandType: Constructor<TCommand>,\n initialValues?: TCommandContent\n): [TCommand, SetCommandValues<TCommandContent>, ClearCommandValues] {\n const command = useRef<TCommand | null>(null);\n const [hasChanges, setHasChanges] = useState(false);\n const arc = useContext(ArcContext);\n\n const propertyChangedCallback = useCallback(() => {\n if (command.current?.hasChanges !== hasChanges) {\n setHasChanges(command.current?.hasChanges ?? false);\n }\n }, []);\n\n command.current = useMemo(() => {\n const instance = new commandType();\n instance.setMicroservice(arc.microservice);\n instance.setApiBasePath(arc.apiBasePath ?? '');\n instance.setOrigin(arc.origin ?? '');\n instance.setHttpHeadersCallback(arc.httpHeadersCallback ?? (() => ({})));\n if (initialValues) {\n instance.setInitialValues(initialValues);\n }\n instance.onPropertyChanged(propertyChangedCallback, instance);\n return instance;\n }, []);\n\n const context = React.useContext(CommandScopeContext);\n context.addCommand?.(command.current! as Command<object, object>);\n\n const setCommandValues = (values: TCommandContent) => {\n const valuesRecord = values as Record<string, unknown>;\n command!.current!.
|
|
1
|
+
{"version":3,"file":"useCommand.js","sources":["../../../commands/useCommand.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { useState, useCallback, useContext, useRef, useMemo } from 'react';\nimport { Command } from '@cratis/arc/commands';\nimport React from 'react';\nimport { CommandScopeContext } from './CommandScope';\nimport { ArcContext } from '../ArcContext';\n\nexport type SetCommandValues<TCommandContent> = (command: TCommandContent) => void;\nexport type ClearCommandValues = () => void;\n\n/**\n * Use a command in a component.\n * @param commandType Type of the command to use.\n * @param initialValues Any initial values to set for the command.\n * @returns Tuple with the command, a {@link SetCommandValues<TCommandContent>} delegate to set values on command and {@link ClearCommandValues} delegate clear values.\n */\nexport function useCommand<\n TCommand extends Command<TCommandContent, TCommandResponse>,\n TCommandContent = object,\n TCommandResponse = object\n>(\n commandType: Constructor<TCommand>,\n initialValues?: TCommandContent\n): [TCommand, SetCommandValues<TCommandContent>, ClearCommandValues] {\n const command = useRef<TCommand | null>(null);\n const [hasChanges, setHasChanges] = useState(false);\n const arc = useContext(ArcContext);\n\n const propertyChangedCallback = useCallback(() => {\n if (command.current?.hasChanges !== hasChanges) {\n setHasChanges(command.current?.hasChanges ?? false);\n }\n }, []);\n\n command.current = useMemo(() => {\n const instance = new commandType();\n instance.setMicroservice(arc.microservice);\n instance.setApiBasePath(arc.apiBasePath ?? '');\n instance.setOrigin(arc.origin ?? '');\n instance.setHttpHeadersCallback(arc.httpHeadersCallback ?? (() => ({})));\n if (initialValues) {\n instance.setInitialValues(initialValues);\n }\n instance.onPropertyChanged(propertyChangedCallback, instance);\n return instance;\n }, []);\n\n const context = React.useContext(CommandScopeContext);\n context.addCommand?.(command.current! as Command<object, object>);\n\n const setCommandValues = (values: TCommandContent) => {\n const valuesRecord = values as Record<string, unknown>;\n command!.current!.propertyDescriptors.forEach((propertyDescriptor) => {\n if (valuesRecord[propertyDescriptor.name] !== undefined && valuesRecord[propertyDescriptor.name] != null) {\n (command.current as Record<string, unknown>)[propertyDescriptor.name] = valuesRecord[propertyDescriptor.name];\n }\n });\n };\n\n const clearCommandValues = () => {\n command.current!.propertyDescriptors.forEach((propertyDescriptor) => {\n (command.current as Record<string, unknown>)[propertyDescriptor.name] = undefined;\n });\n };\n\n return [command.current!, setCommandValues, clearCommandValues];\n}\n"],"names":["React"],"mappings":";;;;AAmBM,SAAU,UAAU,CAKtB,WAAkC,EAClC,aAA+B,EAAA;AAE/B,IAAA,MAAM,OAAO,GAAG,MAAM,CAAkB,IAAI,CAAC;IAC7C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,C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":"IdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/IdentityProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAe7C,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,kBAAkB,CAAC,EAAE,WAAW,CAAC;CACpC,CAAC;AAMF,eAAO,MAAM,uBAAuB,qCAAiE,CAAC;AAEtG,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IACvC,mBAAmB,CAAC,EAAE,cAAc,CAAC;IACrC,WAAW,CAAC,EAAE,WAAW,CAAA;CAC5B;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,qBAAqB,4CA4D5D,CAAC"}
|
|
@@ -20,13 +20,22 @@ const defaultContextValue = {
|
|
|
20
20
|
const IdentityProviderContext = React__default.createContext(defaultContextValue);
|
|
21
21
|
const IdentityProvider = (props) => {
|
|
22
22
|
const arc = useContext(ArcContext);
|
|
23
|
-
const
|
|
23
|
+
const fetchIdentity = () => {
|
|
24
|
+
return IdentityProvider$1.getCurrent(props.detailsType).then(identity => {
|
|
25
|
+
const wrappedIdentity = wrapRefresh(identity);
|
|
26
|
+
setContext({
|
|
27
|
+
identity: wrappedIdentity,
|
|
28
|
+
detailsConstructor: props.detailsType
|
|
29
|
+
});
|
|
30
|
+
return wrappedIdentity;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
24
33
|
const wrapRefresh = (identity) => {
|
|
25
34
|
const originalRefresh = identity.refresh.bind(identity);
|
|
26
35
|
return {
|
|
27
36
|
...identity,
|
|
28
37
|
refresh: () => {
|
|
29
|
-
return new Promise(resolve => {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
30
39
|
originalRefresh().then(newIdentity => {
|
|
31
40
|
const wrappedIdentity = wrapRefresh(newIdentity);
|
|
32
41
|
setContext({
|
|
@@ -34,21 +43,28 @@ const IdentityProvider = (props) => {
|
|
|
34
43
|
detailsConstructor: props.detailsType
|
|
35
44
|
});
|
|
36
45
|
resolve(wrappedIdentity);
|
|
37
|
-
});
|
|
46
|
+
}).catch(reject);
|
|
38
47
|
});
|
|
39
48
|
}
|
|
40
49
|
};
|
|
41
50
|
};
|
|
51
|
+
const initialIdentity = {
|
|
52
|
+
id: '',
|
|
53
|
+
name: '',
|
|
54
|
+
details: {},
|
|
55
|
+
isSet: false,
|
|
56
|
+
refresh: () => fetchIdentity()
|
|
57
|
+
};
|
|
58
|
+
const [context, setContext] = useState({
|
|
59
|
+
identity: wrapRefresh(initialIdentity),
|
|
60
|
+
detailsConstructor: props.detailsType
|
|
61
|
+
});
|
|
42
62
|
useEffect(() => {
|
|
43
63
|
IdentityProvider$1.setHttpHeadersCallback(props.httpHeadersCallback);
|
|
44
64
|
IdentityProvider$1.setApiBasePath(arc.apiBasePath ?? '');
|
|
45
65
|
IdentityProvider$1.setOrigin(arc.origin ?? '');
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
setContext({
|
|
49
|
-
identity: wrappedIdentity,
|
|
50
|
-
detailsConstructor: props.detailsType
|
|
51
|
-
});
|
|
66
|
+
fetchIdentity().catch(error => {
|
|
67
|
+
console.error('Failed to fetch initial identity:', error);
|
|
52
68
|
});
|
|
53
69
|
}, []);
|
|
54
70
|
return (jsx(IdentityProviderContext.Provider, { value: context, children: props.children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport React from 'react';\nimport { useState, useEffect, useContext } from 'react';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentity } from '@cratis/arc/identity';\nimport { IdentityProvider as RootIdentityProvider } from '@cratis/arc/identity';\nimport { GetHttpHeaders } from '@cratis/arc';\nimport { ArcContext } from '../ArcContext';\n\nconst defaultIdentityContext: IIdentity = {\n id: '',\n name: '',\n details: {},\n isSet: false,\n refresh: () => {\n return new Promise((resolve, reject) => {\n reject('Not implemented');\n });\n }\n};\n\ntype IdentityContextValue = {\n identity: IIdentity;\n detailsConstructor?: Constructor;\n};\n\nconst defaultContextValue: IdentityContextValue = {\n identity: defaultIdentityContext\n};\n\nexport const IdentityProviderContext = React.createContext<IdentityContextValue>(defaultContextValue);\n\nexport interface IdentityProviderProps {\n children?: JSX.Element | JSX.Element[],\n httpHeadersCallback?: GetHttpHeaders,\n detailsType?: Constructor\n}\n\nexport const IdentityProvider = (props: IdentityProviderProps) => {\n const arc = useContext(ArcContext);\n const
|
|
1
|
+
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport React from 'react';\nimport { useState, useEffect, useContext } from 'react';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentity } from '@cratis/arc/identity';\nimport { IdentityProvider as RootIdentityProvider } from '@cratis/arc/identity';\nimport { GetHttpHeaders } from '@cratis/arc';\nimport { ArcContext } from '../ArcContext';\n\nconst defaultIdentityContext: IIdentity = {\n id: '',\n name: '',\n details: {},\n isSet: false,\n refresh: () => {\n return new Promise((resolve, reject) => {\n reject('Not implemented');\n });\n }\n};\n\ntype IdentityContextValue = {\n identity: IIdentity;\n detailsConstructor?: Constructor;\n};\n\nconst defaultContextValue: IdentityContextValue = {\n identity: defaultIdentityContext\n};\n\nexport const IdentityProviderContext = React.createContext<IdentityContextValue>(defaultContextValue);\n\nexport interface IdentityProviderProps {\n children?: JSX.Element | JSX.Element[],\n httpHeadersCallback?: GetHttpHeaders,\n detailsType?: Constructor\n}\n\nexport const IdentityProvider = (props: IdentityProviderProps) => {\n const arc = useContext(ArcContext);\n \n const fetchIdentity = (): Promise<IIdentity> => {\n return RootIdentityProvider.getCurrent(props.detailsType).then(identity => {\n const wrappedIdentity = wrapRefresh(identity);\n setContext({\n identity: wrappedIdentity,\n detailsConstructor: props.detailsType\n });\n return wrappedIdentity;\n });\n };\n\n const wrapRefresh = (identity: IIdentity): IIdentity => {\n const originalRefresh = identity.refresh.bind(identity);\n return {\n ...identity,\n refresh: () => {\n return new Promise<IIdentity>((resolve, reject) => {\n originalRefresh().then(newIdentity => {\n const wrappedIdentity = wrapRefresh(newIdentity);\n setContext({\n identity: wrappedIdentity,\n detailsConstructor: props.detailsType\n });\n resolve(wrappedIdentity);\n }).catch(reject);\n });\n }\n };\n };\n\n const initialIdentity: IIdentity = {\n id: '',\n name: '',\n details: {},\n isSet: false,\n refresh: () => fetchIdentity()\n };\n\n const [context, setContext] = useState<IdentityContextValue>({\n identity: wrapRefresh(initialIdentity),\n detailsConstructor: props.detailsType\n });\n\n useEffect(() => {\n RootIdentityProvider.setHttpHeadersCallback(props.httpHeadersCallback!);\n RootIdentityProvider.setApiBasePath(arc.apiBasePath ?? '');\n RootIdentityProvider.setOrigin(arc.origin ?? '');\n fetchIdentity().catch(error => {\n console.error('Failed to fetch initial identity:', error);\n });\n }, []);\n\n return (\n <IdentityProviderContext.Provider value={context}>\n {props.children}\n </IdentityProviderContext.Provider>\n );\n};\n"],"names":["React","RootIdentityProvider","_jsx"],"mappings":";;;;;AAWA,MAAM,sBAAsB,GAAc;AACtC,IAAA,EAAE,EAAE,EAAE;AACN,IAAA,IAAI,EAAE,EAAE;AACR,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,MAAK;QACV,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;YACnC,MAAM,CAAC,iBAAiB,CAAC;AAC7B,QAAA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Ae,GAAc;AAC/B,QAAA,EAAE,EAAE,EAAE;AACN,QAAA,IAAI,EAAE,EAAE;AACR,QAAA,OAAO,EAAE,EAAE;AACX,QAAA,KAAK,EAAE,KAAK;AACZ,QAAA,OAAO,EAAE,MAAM,aAAa;KAC/B;AAED,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB;AACzD,QAAA,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC;QACtC,kBAAkB,EAAE,KAAK,CAAC;AAC7B,KAAA,CAAC;IAEF,SAAS,CAAC,MAAK;AACX,QAAAA,kBAAoB,CAAC,sBAAsB,CAAC,KAAK,CAAC,mBAAoB,CAAC;QACvEA,kBAAoB,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;QAC1DA,kBAAoB,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;AAChD,QAAA,aAAa,EAAE,CAAC,KAAK,CAAC,KAAK,IAAG;AAC1B,YAAA,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC;AAC7D,QAAA,CAAC,CAAC;IACN,CAAC,EAAE,EAAE,CAAC;AAEN,IAAA,QACIC,GAAA,CAAC,uBAAuB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,OAAO,YAC3C,KAAK,CAAC,QAAQ,EAAA,CACgB;AAE3C;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RenderResult } from '@testing-library/react';
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import { IIdentity } from '@cratis/arc/identity';
|
|
5
|
+
import { createFetchHelper } from '@cratis/arc/helpers/fetchHelper';
|
|
6
|
+
import { Constructor } from '@cratis/fundamentals';
|
|
7
|
+
export declare class an_identity_provider {
|
|
8
|
+
capturedIdentity: IIdentity | null;
|
|
9
|
+
renderCount: number;
|
|
10
|
+
renderResult: RenderResult;
|
|
11
|
+
originalApiBasePath: string;
|
|
12
|
+
originalOrigin: string;
|
|
13
|
+
private originalConsoleError?;
|
|
14
|
+
fetchHelper: ReturnType<typeof createFetchHelper>;
|
|
15
|
+
fetchStub: sinon.SinonStub;
|
|
16
|
+
constructor();
|
|
17
|
+
setupSuccessfulIdentityFetch(id: string, name: string, details?: object): void;
|
|
18
|
+
setupFailedIdentityFetch(): void;
|
|
19
|
+
createTestComponent(): () => React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
20
|
+
renderProvider(detailsType?: Constructor): void;
|
|
21
|
+
waitForAsyncUpdates(): Promise<void>;
|
|
22
|
+
suppressConsoleErrors(): void;
|
|
23
|
+
restoreConsole(): void;
|
|
24
|
+
cleanup(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=an_identity_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"an_identity_provider.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/given/an_identity_provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAU,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,oBAAoB;IAC7B,gBAAgB,EAAE,SAAS,GAAG,IAAI,CAAQ;IAC1C,WAAW,SAAK;IAChB,YAAY,EAAG,YAAY,CAAC;IAC5B,mBAAmB,SAAM;IACzB,cAAc,SAAM;IACpB,OAAO,CAAC,oBAAoB,CAAC,CAAuB;IACpD,WAAW,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAClD,SAAS,EAAG,KAAK,CAAC,SAAS,CAAC;;IAY5B,4BAA4B,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAW;IAO3E,wBAAwB;IAKxB,mBAAmB;IAQnB,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW;IAqBlC,mBAAmB;IAIzB,qBAAqB;IAOrB,cAAc;IAOd,OAAO;CASV"}
|