@appshell/react 1.0.0-alpha.8 → 1.0.0-alpha.80

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 (141) hide show
  1. package/README.md +36 -49
  2. package/dist/main.js +1 -1
  3. package/dist/types/config/src/axios.d.ts +0 -1
  4. package/dist/types/config/src/configmap.d.ts +0 -1
  5. package/dist/types/config/src/context.d.ts +3 -4
  6. package/dist/types/config/src/credentials.d.ts +0 -2
  7. package/dist/types/config/src/generate.manifest.d.ts +30 -2
  8. package/dist/types/config/src/index.d.ts +7 -10
  9. package/dist/types/config/src/loader.d.ts +18 -0
  10. package/dist/types/config/src/mappers/appshell.config.d.ts +9 -3
  11. package/dist/types/config/src/outdated.d.ts +0 -1
  12. package/dist/types/config/src/publish.d.ts +79 -5
  13. package/dist/types/config/src/sync.d.ts +0 -1
  14. package/dist/types/config/src/tls.d.ts +23 -0
  15. package/dist/types/config/src/types.d.ts +164 -30
  16. package/dist/types/config/src/utils/blur.d.ts +0 -1
  17. package/dist/types/config/src/utils/compare.d.ts +0 -1
  18. package/dist/types/config/src/utils/config.d.ts +0 -1
  19. package/dist/types/config/src/utils/copy.d.ts +0 -1
  20. package/dist/types/config/src/utils/dump.d.ts +10 -0
  21. package/dist/types/config/src/utils/index.d.ts +1 -4
  22. package/dist/types/config/src/utils/list.d.ts +0 -1
  23. package/dist/types/config/src/utils/load.d.ts +0 -1
  24. package/dist/types/config/src/validators/AppshellTemplateValidator.d.ts +0 -1
  25. package/dist/types/config/src/validators/index.d.ts +0 -3
  26. package/dist/types/loader/src/index.d.ts +0 -1
  27. package/dist/types/loader/src/loadAppshellComponent.d.ts +13 -14
  28. package/dist/types/loader/src/remoteLoader.d.ts +2 -3
  29. package/dist/types/loader/src/resolvers.d.ts +4 -12
  30. package/dist/types/loader/src/types.d.ts +0 -1
  31. package/dist/types/react/src/components/LoadingError.d.ts +0 -1
  32. package/dist/types/react/src/components/RemoteSlot.d.ts +28 -0
  33. package/dist/types/react/src/contexts/RemoteContext.d.ts +2 -4
  34. package/dist/types/react/src/hooks/useRemote.d.ts +1 -2
  35. package/dist/types/react/src/index.d.ts +2 -9
  36. package/dist/types/react/src/resources/jsonResource.d.ts +0 -1
  37. package/dist/types/react/src/types.d.ts +0 -1
  38. package/dist/types/runtime/src/errors.d.ts +32 -0
  39. package/dist/types/runtime/src/identity.d.ts +47 -0
  40. package/dist/types/runtime/src/index.d.ts +6 -0
  41. package/dist/types/runtime/src/store.d.ts +25 -0
  42. package/dist/types/runtime/src/types.d.ts +9 -0
  43. package/dist/types/runtime/src/wire.d.ts +58 -0
  44. package/package.json +14 -4
  45. package/CHANGELOG.md +0 -203
  46. package/__tests__/AppshellComponent.spec.tsx +0 -53
  47. package/__tests__/LoadingError.spec.tsx +0 -14
  48. package/__tests__/ManifestContext.spec.tsx +0 -50
  49. package/__tests__/ReactHost.spec.tsx +0 -136
  50. package/__tests__/__snapshots__/AppshellComponent.spec.tsx.snap +0 -9
  51. package/__tests__/__snapshots__/LoadingError.spec.tsx.snap +0 -88
  52. package/__tests__/__snapshots__/ReactHost.spec.tsx.snap +0 -11
  53. package/__tests__/fixtures/Manifest.ts +0 -16
  54. package/__tests__/fixtures/TestComponent.tsx +0 -5
  55. package/__tests__/fixtures/TestGlobalConfig.ts +0 -8
  56. package/__tests__/jsonResource.spec.ts +0 -27
  57. package/__tests__/useRemote.spec.tsx +0 -36
  58. package/__tests__/utils/waitForResource.ts +0 -15
  59. package/dist/types/config/src/axios.d.ts.map +0 -1
  60. package/dist/types/config/src/configmap.d.ts.map +0 -1
  61. package/dist/types/config/src/context.d.ts.map +0 -1
  62. package/dist/types/config/src/credentials.d.ts.map +0 -1
  63. package/dist/types/config/src/deregister.d.ts +0 -3
  64. package/dist/types/config/src/deregister.d.ts.map +0 -1
  65. package/dist/types/config/src/generate.env.d.ts +0 -3
  66. package/dist/types/config/src/generate.env.d.ts.map +0 -1
  67. package/dist/types/config/src/generate.global-config.d.ts +0 -10
  68. package/dist/types/config/src/generate.global-config.d.ts.map +0 -1
  69. package/dist/types/config/src/generate.manifest.d.ts.map +0 -1
  70. package/dist/types/config/src/index.d.ts.map +0 -1
  71. package/dist/types/config/src/mappers/appshell.config.d.ts.map +0 -1
  72. package/dist/types/config/src/outdated.d.ts.map +0 -1
  73. package/dist/types/config/src/publish.d.ts.map +0 -1
  74. package/dist/types/config/src/register.d.ts +0 -4
  75. package/dist/types/config/src/register.d.ts.map +0 -1
  76. package/dist/types/config/src/sync.d.ts.map +0 -1
  77. package/dist/types/config/src/types.d.ts.map +0 -1
  78. package/dist/types/config/src/utils/blur.d.ts.map +0 -1
  79. package/dist/types/config/src/utils/compare.d.ts.map +0 -1
  80. package/dist/types/config/src/utils/config.d.ts.map +0 -1
  81. package/dist/types/config/src/utils/copy.d.ts.map +0 -1
  82. package/dist/types/config/src/utils/index.d.ts.map +0 -1
  83. package/dist/types/config/src/utils/isValidUrl.d.ts +0 -3
  84. package/dist/types/config/src/utils/isValidUrl.d.ts.map +0 -1
  85. package/dist/types/config/src/utils/list.d.ts.map +0 -1
  86. package/dist/types/config/src/utils/load.d.ts.map +0 -1
  87. package/dist/types/config/src/utils/loadJson.d.ts +0 -10
  88. package/dist/types/config/src/utils/loadJson.d.ts.map +0 -1
  89. package/dist/types/config/src/utils/merge.d.ts +0 -4
  90. package/dist/types/config/src/utils/merge.d.ts.map +0 -1
  91. package/dist/types/config/src/validators/AppshellGlobalConfigValidator.d.ts +0 -4
  92. package/dist/types/config/src/validators/AppshellGlobalConfigValidator.d.ts.map +0 -1
  93. package/dist/types/config/src/validators/AppshellManifestValidator.d.ts +0 -4
  94. package/dist/types/config/src/validators/AppshellManifestValidator.d.ts.map +0 -1
  95. package/dist/types/config/src/validators/AppshellTemplateValidator.d.ts.map +0 -1
  96. package/dist/types/config/src/validators/index.d.ts.map +0 -1
  97. package/dist/types/loader/src/fetchDynamicScript.d.ts +0 -3
  98. package/dist/types/loader/src/fetchDynamicScript.d.ts.map +0 -1
  99. package/dist/types/loader/src/index.d.ts.map +0 -1
  100. package/dist/types/loader/src/loadAppshellComponent.d.ts.map +0 -1
  101. package/dist/types/loader/src/remoteLoader.d.ts.map +0 -1
  102. package/dist/types/loader/src/resolvers.d.ts.map +0 -1
  103. package/dist/types/loader/src/types.d.ts.map +0 -1
  104. package/dist/types/react/src/components/AppshellComponent.d.ts +0 -30
  105. package/dist/types/react/src/components/AppshellComponent.d.ts.map +0 -1
  106. package/dist/types/react/src/components/LoadingError.d.ts.map +0 -1
  107. package/dist/types/react/src/components/ReactHost.d.ts +0 -9
  108. package/dist/types/react/src/components/ReactHost.d.ts.map +0 -1
  109. package/dist/types/react/src/contexts/GlobalConfigContext.d.ts +0 -11
  110. package/dist/types/react/src/contexts/GlobalConfigContext.d.ts.map +0 -1
  111. package/dist/types/react/src/contexts/ManifestContext.d.ts +0 -12
  112. package/dist/types/react/src/contexts/ManifestContext.d.ts.map +0 -1
  113. package/dist/types/react/src/contexts/MetadataContext.d.ts +0 -11
  114. package/dist/types/react/src/contexts/MetadataContext.d.ts.map +0 -1
  115. package/dist/types/react/src/contexts/RemoteContext.d.ts.map +0 -1
  116. package/dist/types/react/src/hooks/useGlobalConfig.d.ts +0 -4
  117. package/dist/types/react/src/hooks/useGlobalConfig.d.ts.map +0 -1
  118. package/dist/types/react/src/hooks/useManifest.d.ts +0 -4
  119. package/dist/types/react/src/hooks/useManifest.d.ts.map +0 -1
  120. package/dist/types/react/src/hooks/useMetadata.d.ts +0 -4
  121. package/dist/types/react/src/hooks/useMetadata.d.ts.map +0 -1
  122. package/dist/types/react/src/hooks/useRemote.d.ts.map +0 -1
  123. package/dist/types/react/src/index.d.ts.map +0 -1
  124. package/dist/types/react/src/resources/jsonResource.d.ts.map +0 -1
  125. package/dist/types/react/src/types.d.ts.map +0 -1
  126. package/src/components/AppshellComponent.tsx +0 -82
  127. package/src/components/LoadingError.tsx +0 -15
  128. package/src/components/ReactHost.tsx +0 -55
  129. package/src/contexts/GlobalConfigContext.tsx +0 -17
  130. package/src/contexts/ManifestContext.tsx +0 -40
  131. package/src/contexts/MetadataContext.tsx +0 -17
  132. package/src/contexts/RemoteContext.tsx +0 -22
  133. package/src/hooks/useGlobalConfig.ts +0 -7
  134. package/src/hooks/useManifest.ts +0 -7
  135. package/src/hooks/useMetadata.ts +0 -6
  136. package/src/hooks/useRemote.ts +0 -7
  137. package/src/index.ts +0 -11
  138. package/src/resources/jsonResource.ts +0 -35
  139. package/src/types.ts +0 -3
  140. package/tsconfig.json +0 -7
  141. package/webpack.config.js +0 -42
@@ -1,55 +0,0 @@
1
- /* eslint-disable react/jsx-props-no-spreading */
2
- import { AppshellGlobalConfig } from 'packages/config/src/types';
3
- import React, { FC, ReactNode, useEffect } from 'react';
4
- import { GlobalConfigProvider } from '../contexts/GlobalConfigContext';
5
- import AppshellComponent from './AppshellComponent';
6
-
7
- /** The registry inlines the composition, so a shell it served needs no config fetch. */
8
- const inlinedConfig = (): AppshellGlobalConfig | undefined => {
9
- const composition = typeof window === 'undefined' ? undefined : window.__appshell_config__;
10
- return composition && { index: composition.index };
11
- };
12
-
13
- const ReactHost: FC<{
14
- configUrl?: string;
15
- remote: string;
16
- fallback?: ReactNode;
17
- [x: string]: unknown;
18
- }> = ({ configUrl, remote, fallback, ...rest }) => {
19
- const [config, setGlobalConfig] = React.useState<AppshellGlobalConfig | undefined>(inlinedConfig);
20
-
21
- useEffect(() => {
22
- if (config) {
23
- return;
24
- }
25
-
26
- if (!configUrl) {
27
- setGlobalConfig({ index: {} });
28
- return;
29
- }
30
-
31
- const fetchGlobalConfig = async () => {
32
- const res = await fetch(configUrl);
33
- setGlobalConfig(res.ok ? await res.json() : { index: {} });
34
- };
35
-
36
- fetchGlobalConfig();
37
- }, [config, configUrl]);
38
-
39
- if (!config) {
40
- return null;
41
- }
42
-
43
- return (
44
- <GlobalConfigProvider config={config}>
45
- <AppshellComponent remote={remote} fallback={fallback} {...rest} />
46
- </GlobalConfigProvider>
47
- );
48
- };
49
-
50
- ReactHost.defaultProps = {
51
- configUrl: undefined,
52
- fallback: undefined,
53
- };
54
-
55
- export default ReactHost;
@@ -1,17 +0,0 @@
1
- import { AppshellGlobalConfig } from 'packages/config/src/types';
2
- import React, { createContext, FC, ReactNode } from 'react';
3
-
4
- interface GlobalConfigProviderProps {
5
- config: AppshellGlobalConfig;
6
- children: ReactNode;
7
- }
8
-
9
- export const GlobalConfigContext = createContext<AppshellGlobalConfig>({ index: {} });
10
-
11
- export const GlobalConfigProvider: FC<GlobalConfigProviderProps> = ({ config, children }) => (
12
- <GlobalConfigContext.Provider value={config}>{children}</GlobalConfigContext.Provider>
13
- );
14
-
15
- export const GlobalConfigConsumer = GlobalConfigContext.Consumer;
16
-
17
- export default GlobalConfigContext;
@@ -1,40 +0,0 @@
1
- import { AppshellManifest } from '@appshell/config';
2
- import type { FC, ReactNode } from 'react';
3
- import React, { createContext, useMemo } from 'react';
4
-
5
- interface ManifestProviderProps {
6
- manifest: AppshellManifest;
7
- children: ReactNode;
8
- }
9
-
10
- export const ManifestContext = createContext<AppshellManifest>({
11
- remotes: {},
12
- modules: {},
13
- environment: {},
14
- });
15
-
16
- // `modules` is build-time webpack config that the browser has no use for, and it is
17
- // the bulkiest field to inline. Warn for one release to find any consumer still on it.
18
- const deprecateModules = (manifest: AppshellManifest): AppshellManifest =>
19
- new Proxy(manifest, {
20
- get(target, property, receiver) {
21
- if (property === 'modules') {
22
- // eslint-disable-next-line no-console
23
- console.warn(
24
- 'useManifest().modules is deprecated and will be removed. It is build-time webpack config; use useRemote() for what the browser needs. Please open an issue at github.com/appshell-org/appshell if you rely on it.',
25
- );
26
- }
27
-
28
- return Reflect.get(target, property, receiver);
29
- },
30
- });
31
-
32
- export const ManifestProvider: FC<ManifestProviderProps> = ({ manifest, children }) => {
33
- const value = useMemo(() => deprecateModules(manifest), [manifest]);
34
-
35
- return <ManifestContext.Provider value={value}>{children}</ManifestContext.Provider>;
36
- };
37
-
38
- export const ManifestConsumer = ManifestContext.Consumer;
39
-
40
- export default ManifestContext;
@@ -1,17 +0,0 @@
1
- import { Metadata } from '@appshell/config';
2
- import React, { createContext, FC, ReactNode } from 'react';
3
-
4
- interface MetadataProviderProps {
5
- metata: Metadata;
6
- children: ReactNode;
7
- }
8
-
9
- export const MetadataContext = createContext<Metadata>({});
10
-
11
- export const MetadataProvider: FC<MetadataProviderProps> = ({ metata, children }) => (
12
- <MetadataContext.Provider value={metata}>{children}</MetadataContext.Provider>
13
- );
14
-
15
- export const MetadataConsumer = MetadataContext.Consumer;
16
-
17
- export default MetadataContext;
@@ -1,22 +0,0 @@
1
- import { AppshellRemote } from '@appshell/config';
2
- import type { FC, ReactNode } from 'react';
3
- import React, { createContext } from 'react';
4
-
5
- interface RemoteProviderProps {
6
- remote?: AppshellRemote;
7
- children: ReactNode;
8
- }
9
-
10
- export const RemoteContext = createContext<AppshellRemote | undefined>(undefined);
11
-
12
- export const RemoteProvider: FC<RemoteProviderProps> = ({ remote, children }) => (
13
- <RemoteContext.Provider value={remote}>{children}</RemoteContext.Provider>
14
- );
15
-
16
- RemoteProvider.defaultProps = {
17
- remote: undefined,
18
- };
19
-
20
- export const RemoteConsumer = RemoteContext.Consumer;
21
-
22
- export default RemoteContext;
@@ -1,7 +0,0 @@
1
- import { AppshellGlobalConfig } from 'packages/config/src/types';
2
- import React from 'react';
3
- // eslint-disable-next-line import/no-named-as-default
4
- import GlobalConfigContext from '../contexts/GlobalConfigContext';
5
-
6
- export default (): AppshellGlobalConfig =>
7
- React.useContext<AppshellGlobalConfig>(GlobalConfigContext);
@@ -1,7 +0,0 @@
1
- import { AppshellManifest } from '@appshell/config';
2
- import React from 'react';
3
-
4
- // eslint-disable-next-line import/no-named-as-default
5
- import ManifestContext from '../contexts/ManifestContext';
6
-
7
- export default (): AppshellManifest => React.useContext<AppshellManifest>(ManifestContext);
@@ -1,6 +0,0 @@
1
- import { Metadata } from '@appshell/config';
2
- import React from 'react';
3
- // eslint-disable-next-line import/no-named-as-default
4
- import MetadataContext from '../contexts/MetadataContext';
5
-
6
- export default (): Metadata => React.useContext<Metadata>(MetadataContext);
@@ -1,7 +0,0 @@
1
- import { AppshellRemote } from '@appshell/config';
2
- import React from 'react';
3
- // eslint-disable-next-line import/no-named-as-default
4
- import RemoteContext from '../contexts/RemoteContext';
5
-
6
- /** The remote backing the nearest `AppshellComponent` — it already knows its own key. */
7
- export default (): AppshellRemote | undefined => React.useContext(RemoteContext);
package/src/index.ts DELETED
@@ -1,11 +0,0 @@
1
- export { default as AppshellComponent, FederatedComponent } from './components/AppshellComponent';
2
- export { default as ReactHost } from './components/ReactHost';
3
- export { GlobalConfigProvider } from './contexts/GlobalConfigContext';
4
- export { ManifestProvider } from './contexts/ManifestContext';
5
- export { MetadataProvider } from './contexts/MetadataContext';
6
- export { RemoteProvider } from './contexts/RemoteContext';
7
- export { default as useGlobalConfig } from './hooks/useGlobalConfig';
8
- export { default as useManifest } from './hooks/useManifest';
9
- export { default as useMetadata } from './hooks/useMetadata';
10
- export { default as useRemote } from './hooks/useRemote';
11
- export { default as jsonResource } from './resources/jsonResource';
@@ -1,35 +0,0 @@
1
- export default <TResource>(url: string) => {
2
- let status = 'pending';
3
- let result: TResource | Error;
4
- const suspender = fetch(url, {
5
- headers: {
6
- 'Content-Type': 'application/json',
7
- Accept: 'application/json',
8
- },
9
- // eslint-disable-next-line consistent-return
10
- }).then((response) => {
11
- if (response.ok) {
12
- return response.json().then((data) => {
13
- status = 'success';
14
- result = data;
15
- });
16
- }
17
- status = 'error';
18
- result = new Error(`${response.status} ${response.statusText} ${response.url}`);
19
- });
20
-
21
- return {
22
- read() {
23
- if (status === 'pending') {
24
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
25
- throw suspender as Promise<TResource>;
26
- } else if (status === 'error') {
27
- throw result as Error;
28
- } else if (status === 'success') {
29
- return result;
30
- }
31
-
32
- return undefined;
33
- },
34
- };
35
- };
package/src/types.ts DELETED
@@ -1,3 +0,0 @@
1
- export type Resource<TResource = unknown> = {
2
- read(): TResource | Error | undefined;
3
- };
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig",
3
- "compilerOptions": {
4
- "declarationDir": "./dist/types"
5
- },
6
- "include": ["./src"]
7
- }
package/webpack.config.js DELETED
@@ -1,42 +0,0 @@
1
- const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
2
- const Visualizer = require('webpack-visualizer-plugin2');
3
-
4
- module.exports = (env, { mode }) => {
5
- const isDevelopment = mode === 'development';
6
-
7
- return {
8
- entry: './src/index',
9
- mode,
10
- devtool: isDevelopment ? 'eval-source-map' : false,
11
- output: {
12
- filename: '[name].js',
13
- pathinfo: false,
14
- libraryTarget: 'umd',
15
- },
16
- resolve: {
17
- extensions: ['.js', '.ts', '.tsx'],
18
- plugins: [new TsconfigPathsPlugin()],
19
- },
20
- module: {
21
- rules: [
22
- {
23
- test: /\.tsx?$/,
24
- exclude: /node_modules/,
25
- use: [
26
- {
27
- loader: 'babel-loader',
28
- options: {
29
- presets: ['@babel/preset-react', '@babel/preset-typescript'],
30
- },
31
- },
32
- ],
33
- },
34
- ],
35
- },
36
- // plugins: [isDevelopment && new Visualizer()].filter(Boolean),
37
- externals: {
38
- react: 'react',
39
- 'react-dom': 'reactDOM',
40
- },
41
- };
42
- };