@shopify/ui-extensions-server-kit 5.4.0 → 5.4.1
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/ExtensionServerClient/ExtensionServerClient.d.ts +3 -5
- package/dist/ExtensionServerClient/server-types.d.ts +31 -7
- package/dist/_virtual/jsx-runtime.cjs.js +1 -0
- package/dist/_virtual/jsx-runtime.cjs2.js +1 -0
- package/dist/_virtual/jsx-runtime.es.js +5 -0
- package/dist/_virtual/jsx-runtime.es2.js +4 -0
- package/dist/_virtual/react-jsx-runtime.development.cjs.js +1 -0
- package/dist/_virtual/react-jsx-runtime.development.es.js +4 -0
- package/dist/_virtual/react-jsx-runtime.production.min.cjs.js +1 -0
- package/dist/_virtual/react-jsx-runtime.production.min.es.js +4 -0
- package/dist/i18n.d.ts +2 -8
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.es.js +18 -18
- package/dist/index.es2.js +3 -3
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.cjs.js +22 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.es.js +604 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.cjs.js +9 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.es.js +28 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.cjs.js +1 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.es.js +10 -0
- package/dist/packages/ui-extensions-server-kit/src/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -0
- package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/ExtensionServerClient.es.js +21 -18
- package/dist/packages/ui-extensions-server-kit/src/context/ExtensionServerProvider.cjs.js +1 -0
- package/dist/packages/ui-extensions-server-kit/src/context/ExtensionServerProvider.es.js +30 -0
- package/dist/{context → packages/ui-extensions-server-kit/src/context}/constants.cjs.js +1 -1
- package/dist/packages/ui-extensions-server-kit/src/hooks/useExtensionServerContext.cjs.js +1 -0
- package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerContext.es.js +3 -2
- package/dist/packages/ui-extensions-server-kit/src/testing/MockExtensionServerProvider.cjs.js +1 -0
- package/dist/packages/ui-extensions-server-kit/src/testing/MockExtensionServerProvider.es.js +25 -0
- package/dist/packages/ui-extensions-server-kit/src/utilities/isUIExtension.cjs.js +1 -0
- package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/isUIExtension.es.js +3 -2
- package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/isValidSurface.cjs.js +1 -1
- package/dist/packages/ui-extensions-server-kit/src/utilities/isValidSurface.es.js +7 -0
- package/dist/types.d.ts +11 -8
- package/dist/utilities/isUIExtension.d.ts +1 -1
- package/dist/utilities/isValidSurface.d.ts +1 -1
- package/dist/utilities/set.d.ts +1 -1
- package/node_modules/{@shopify/react-testing/LICENSE.md → @testing-library/react/LICENSE} +2 -3
- package/node_modules/@testing-library/react/README.md +692 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.cjs.js +537 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.esm.js +497 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.cjs.js +501 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.esm.js +461 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.js +502 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.min.js +2 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.min.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.js +538 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.min.js +2 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.min.js.map +1 -0
- package/node_modules/@testing-library/react/dist/act-compat.js +80 -0
- package/node_modules/@testing-library/react/dist/config.js +33 -0
- package/node_modules/@testing-library/react/dist/fire-event.js +70 -0
- package/node_modules/@testing-library/react/dist/index.js +52 -0
- package/node_modules/@testing-library/react/dist/pure.js +356 -0
- package/node_modules/@testing-library/react/dont-cleanup-after-each.js +1 -0
- package/node_modules/@testing-library/react/package.json +116 -0
- package/node_modules/@testing-library/react/pure.d.ts +1 -0
- package/node_modules/@testing-library/react/pure.js +2 -0
- package/node_modules/@testing-library/react/types/index.d.ts +287 -0
- package/node_modules/@testing-library/react/types/pure.d.ts +1 -0
- package/node_modules/@vitejs/plugin-react/README.md +159 -0
- package/node_modules/@vitejs/plugin-react/dist/index.d.ts +75 -0
- package/node_modules/@vitejs/plugin-react/dist/index.js +401 -0
- package/node_modules/@vitejs/plugin-react/dist/refresh-runtime.js +663 -0
- package/node_modules/@vitejs/plugin-react/package.json +77 -0
- package/node_modules/@vitejs/plugin-react/types/preamble.d.ts +1 -0
- package/package.json +8 -9
- package/project.json +1 -1
- package/src/ExtensionServerClient/ExtensionServerClient.test.ts +6 -5
- package/src/ExtensionServerClient/ExtensionServerClient.ts +27 -19
- package/src/ExtensionServerClient/server-types.ts +17 -7
- package/src/ExtensionServerClient/types.ts +0 -2
- package/src/context/ExtensionServerProvider.test.tsx +55 -73
- package/src/context/ExtensionServerProvider.tsx +1 -0
- package/src/i18n.ts +2 -5
- package/src/state/reducers/extensionServerReducer.test.ts +2 -2
- package/src/types.ts +11 -6
- package/src/utilities/assetToString.ts +0 -1
- package/src/utilities/isUIExtension.ts +5 -4
- package/src/utilities/isValidSurface.ts +2 -3
- package/src/utilities/replaceUpdated.ts +0 -2
- package/src/utilities/set.ts +10 -5
- package/tests/setup.ts +1 -4
- package/vite.config.mts +57 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +0 -1
- package/dist/context/ExtensionServerProvider.cjs.js +0 -1
- package/dist/context/ExtensionServerProvider.es.js +0 -29
- package/dist/hooks/useExtensionServerContext.cjs.js +0 -1
- package/dist/testing/MockExtensionServerProvider.cjs.js +0 -1
- package/dist/testing/MockExtensionServerProvider.es.js +0 -24
- package/dist/utilities/isUIExtension.cjs.js +0 -1
- package/dist/utilities/isValidSurface.es.js +0 -7
- package/node_modules/@shopify/react-testing/README.md +0 -711
- package/node_modules/@shopify/react-testing/build/cjs/TestWrapper.js +0 -52
- package/node_modules/@shopify/react-testing/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -47
- package/node_modules/@shopify/react-testing/build/cjs/compat.js +0 -14
- package/node_modules/@shopify/react-testing/build/cjs/destroy.js +0 -13
- package/node_modules/@shopify/react-testing/build/cjs/element.js +0 -225
- package/node_modules/@shopify/react-testing/build/cjs/index.js +0 -21
- package/node_modules/@shopify/react-testing/build/cjs/matchers/components.js +0 -46
- package/node_modules/@shopify/react-testing/build/cjs/matchers/context.js +0 -25
- package/node_modules/@shopify/react-testing/build/cjs/matchers/index.js +0 -16
- package/node_modules/@shopify/react-testing/build/cjs/matchers/props.js +0 -38
- package/node_modules/@shopify/react-testing/build/cjs/matchers/strings.js +0 -42
- package/node_modules/@shopify/react-testing/build/cjs/matchers/utilities.js +0 -110
- package/node_modules/@shopify/react-testing/build/cjs/mount.js +0 -76
- package/node_modules/@shopify/react-testing/build/cjs/root.js +0 -284
- package/node_modules/@shopify/react-testing/build/cjs/toReactString.js +0 -86
- package/node_modules/@shopify/react-testing/build/cjs/types.js +0 -28
- package/node_modules/@shopify/react-testing/build/esm/TestWrapper.mjs +0 -44
- package/node_modules/@shopify/react-testing/build/esm/_virtual/_rollupPluginBabelHelpers.mjs +0 -42
- package/node_modules/@shopify/react-testing/build/esm/compat.mjs +0 -10
- package/node_modules/@shopify/react-testing/build/esm/destroy.mjs +0 -9
- package/node_modules/@shopify/react-testing/build/esm/element.mjs +0 -221
- package/node_modules/@shopify/react-testing/build/esm/index.mjs +0 -5
- package/node_modules/@shopify/react-testing/build/esm/matchers/components.mjs +0 -41
- package/node_modules/@shopify/react-testing/build/esm/matchers/context.mjs +0 -21
- package/node_modules/@shopify/react-testing/build/esm/matchers/index.mjs +0 -14
- package/node_modules/@shopify/react-testing/build/esm/matchers/props.mjs +0 -33
- package/node_modules/@shopify/react-testing/build/esm/matchers/strings.mjs +0 -37
- package/node_modules/@shopify/react-testing/build/esm/matchers/utilities.mjs +0 -101
- package/node_modules/@shopify/react-testing/build/esm/mount.mjs +0 -70
- package/node_modules/@shopify/react-testing/build/esm/root.mjs +0 -275
- package/node_modules/@shopify/react-testing/build/esm/toReactString.mjs +0 -80
- package/node_modules/@shopify/react-testing/build/esm/types.mjs +0 -26
- package/node_modules/@shopify/react-testing/build/esnext/TestWrapper.esnext +0 -44
- package/node_modules/@shopify/react-testing/build/esnext/compat.esnext +0 -10
- package/node_modules/@shopify/react-testing/build/esnext/destroy.esnext +0 -9
- package/node_modules/@shopify/react-testing/build/esnext/element.esnext +0 -221
- package/node_modules/@shopify/react-testing/build/esnext/index.esnext +0 -5
- package/node_modules/@shopify/react-testing/build/esnext/matchers/components.esnext +0 -41
- package/node_modules/@shopify/react-testing/build/esnext/matchers/context.esnext +0 -21
- package/node_modules/@shopify/react-testing/build/esnext/matchers/index.esnext +0 -14
- package/node_modules/@shopify/react-testing/build/esnext/matchers/props.esnext +0 -33
- package/node_modules/@shopify/react-testing/build/esnext/matchers/strings.esnext +0 -37
- package/node_modules/@shopify/react-testing/build/esnext/matchers/utilities.esnext +0 -99
- package/node_modules/@shopify/react-testing/build/esnext/mount.esnext +0 -71
- package/node_modules/@shopify/react-testing/build/esnext/root.esnext +0 -275
- package/node_modules/@shopify/react-testing/build/esnext/toReactString.esnext +0 -80
- package/node_modules/@shopify/react-testing/build/esnext/types.esnext +0 -26
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts +0 -17
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts +0 -3
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts +0 -2
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts +0 -42
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts +0 -7
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts +0 -12
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts +0 -8
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts +0 -20
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts +0 -10
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts +0 -11
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts +0 -17
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts +0 -39
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts +0 -55
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts +0 -5
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts +0 -89
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/index.esnext +0 -1
- package/node_modules/@shopify/react-testing/index.js +0 -1
- package/node_modules/@shopify/react-testing/index.mjs +0 -1
- package/node_modules/@shopify/react-testing/matchers.esnext +0 -1
- package/node_modules/@shopify/react-testing/matchers.js +0 -1
- package/node_modules/@shopify/react-testing/matchers.mjs +0 -1
- package/node_modules/@shopify/react-testing/package.json +0 -69
- package/node_modules/@shopify/ui-extensions-test-utils/CHANGELOG.md +0 -66
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.d.ts +0 -3
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.js +0 -3
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.d.ts +0 -2
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.js +0 -5
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.d.ts +0 -17
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.js +0 -20
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.d.ts +0 -9
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +0 -7
- package/node_modules/@shopify/ui-extensions-test-utils/package.json +0 -40
- package/node_modules/@shopify/ui-extensions-test-utils/project.json +0 -39
- package/node_modules/@vitejs/plugin-react-refresh/README.md +0 -73
- package/node_modules/@vitejs/plugin-react-refresh/index.d.ts +0 -14
- package/node_modules/@vitejs/plugin-react-refresh/index.js +0 -239
- package/node_modules/@vitejs/plugin-react-refresh/package.json +0 -35
- /package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/types.cjs.js +0 -0
- /package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/types.es.js +0 -0
- /package/dist/{context → packages/ui-extensions-server-kit/src/context}/constants.es.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerState.cjs.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerState.es.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useIsomorphicLayoutEffect.cjs.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useIsomorphicLayoutEffect.es.js +0 -0
- /package/dist/{i18n.cjs.js → packages/ui-extensions-server-kit/src/i18n.cjs.js} +0 -0
- /package/dist/{i18n.es.js → packages/ui-extensions-server-kit/src/i18n.es.js} +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/actions/actions.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/actions/actions.es.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/constants.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/constants.es.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/extensionServerReducer.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/extensionServerReducer.es.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/app.cjs.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/app.es.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/extensions.cjs.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/extensions.es.js +0 -0
- /package/dist/{types.cjs.js → packages/ui-extensions-server-kit/src/types.cjs.js} +0 -0
- /package/dist/{types.es.js → packages/ui-extensions-server-kit/src/types.es.js} +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/assetToString.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/assetToString.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/noop.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/noop.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/replaceUpdated.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/replaceUpdated.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/set.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/set.es.js +0 -0
- /package/node_modules/@vitejs/{plugin-react-refresh → plugin-react}/LICENSE +0 -0
package/src/i18n.ts
CHANGED
|
@@ -6,7 +6,7 @@ type Translation = string | {[key: string]: Translation}
|
|
|
6
6
|
|
|
7
7
|
export interface Localization {
|
|
8
8
|
defaultLocale: string
|
|
9
|
-
translations:
|
|
9
|
+
translations: Record<string, Record<string, Translation>>
|
|
10
10
|
lastUpdated: number
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -63,9 +63,7 @@ interface TranslationDictionary {
|
|
|
63
63
|
* }
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
|
|
67
|
-
[key: string]: string
|
|
68
|
-
}
|
|
66
|
+
type ExtensionTranslationMap = Record<string, string>
|
|
69
67
|
|
|
70
68
|
export const TRANSLATED_KEYS = ['localization', 'name', 'description']
|
|
71
69
|
/**
|
|
@@ -105,7 +103,6 @@ function traverseDictionary(
|
|
|
105
103
|
}
|
|
106
104
|
|
|
107
105
|
if (typeof value === 'string') {
|
|
108
|
-
// eslint-disable-next-line node/callback-return
|
|
109
106
|
callback(translationKey, value)
|
|
110
107
|
} else {
|
|
111
108
|
traverseDictionary(value, callback, translationKey)
|
|
@@ -103,7 +103,7 @@ describe('extensionServerReducer()', () => {
|
|
|
103
103
|
const action = createRefreshAction([{uuid: extension.uuid}])
|
|
104
104
|
|
|
105
105
|
const state1 = extensionServerReducer(previousState, action)
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
const url1 = new URL(state1.extensions[0].assets.main.url)
|
|
108
108
|
const timestamp1 = url1.searchParams.get('lastUpdated') ?? ''
|
|
109
109
|
|
|
@@ -113,7 +113,7 @@ describe('extensionServerReducer()', () => {
|
|
|
113
113
|
await new Promise((resolve) => setTimeout(resolve, 1))
|
|
114
114
|
|
|
115
115
|
const state2 = extensionServerReducer(state1, action)
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
const url2 = new URL(state2.extensions[0].assets.main.url)
|
|
118
118
|
const timestamp2 = url2.searchParams.get('lastUpdated') ?? ''
|
|
119
119
|
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-invalid-void-type */
|
|
2
|
-
/* eslint-disable @shopify/strict-component-boundaries */
|
|
3
1
|
import {FlattenedLocalization, Localization} from './i18n'
|
|
4
2
|
import './ExtensionServerClient/types'
|
|
5
3
|
import type {Surface} from './ExtensionServerClient/types'
|
|
@@ -94,7 +92,7 @@ export interface ExtensionPoint {
|
|
|
94
92
|
localization?: FlattenedLocalization | Localization | null
|
|
95
93
|
name: string
|
|
96
94
|
description?: string
|
|
97
|
-
assets?:
|
|
95
|
+
assets?: Record<string, Asset>
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
type ExtensionPoints = string[] | ExtensionPoint[] | null
|
|
@@ -119,7 +117,7 @@ interface Capabilities {
|
|
|
119
117
|
export interface ExtensionPayload {
|
|
120
118
|
type: string
|
|
121
119
|
externalType: string
|
|
122
|
-
assets:
|
|
120
|
+
assets: Record<string, Asset>
|
|
123
121
|
development: {
|
|
124
122
|
hidden: boolean
|
|
125
123
|
status: Status
|
|
@@ -154,13 +152,13 @@ export interface ExtensionPayload {
|
|
|
154
152
|
name?: string
|
|
155
153
|
description?: string
|
|
156
154
|
required?: boolean
|
|
157
|
-
validations?:
|
|
155
|
+
validations?: unknown[]
|
|
158
156
|
}[]
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
export interface ExtensionSupportedFeatures {
|
|
163
|
-
|
|
161
|
+
runsOffline: boolean
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
export enum Status {
|
|
@@ -184,4 +182,11 @@ export interface App {
|
|
|
184
182
|
}
|
|
185
183
|
supportEmail?: string
|
|
186
184
|
supportLocales?: string[]
|
|
185
|
+
allowedDomains?: string[]
|
|
186
|
+
assets?: {
|
|
187
|
+
[key: string]: {
|
|
188
|
+
url: string
|
|
189
|
+
lastUpdated: number
|
|
190
|
+
}
|
|
191
|
+
}
|
|
187
192
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {Asset} from '../types'
|
|
2
2
|
|
|
3
3
|
export function assetToString(asset: Asset) {
|
|
4
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
5
4
|
const url = new URL(asset.url)
|
|
6
5
|
url.searchParams.set('lastUpdated', String(asset.lastUpdated))
|
|
7
6
|
return url.toString()
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export function isUIExtension(extension:
|
|
1
|
+
export function isUIExtension(extension: unknown): extension is ExtensionServer.UIExtension {
|
|
2
|
+
const ext = extension as ExtensionServer.UIExtension
|
|
2
3
|
return (
|
|
3
|
-
|
|
4
|
-
Array.isArray(
|
|
5
|
-
|
|
4
|
+
ext.type === 'ui_extension' &&
|
|
5
|
+
Array.isArray(ext.extensionPoints) &&
|
|
6
|
+
ext.extensionPoints.every((extensionPoint: unknown) => typeof extensionPoint === 'object')
|
|
6
7
|
)
|
|
7
8
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/* eslint-disable @shopify/strict-component-boundaries */
|
|
2
1
|
import {AVAILABLE_SURFACES} from '../ExtensionServerClient/types'
|
|
3
2
|
import type {Surface} from '../ExtensionServerClient/types'
|
|
4
3
|
|
|
5
|
-
export function isValidSurface(surface:
|
|
6
|
-
return surface && AVAILABLE_SURFACES.includes(surface)
|
|
4
|
+
export function isValidSurface(surface: unknown): surface is Surface {
|
|
5
|
+
return Boolean(surface) && AVAILABLE_SURFACES.includes(surface as Surface)
|
|
7
6
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export function replaceUpdated<T>(arr: T[], updates: T[], cb: (v: T) => unknown): T[] {
|
|
2
2
|
const updatesMap = new Map(updates.map((updated) => [cb(updated), updated]))
|
|
3
3
|
const updated = arr.map((item) => {
|
|
4
|
-
// eslint-disable-next-line node/callback-return
|
|
5
4
|
const key = cb(item)
|
|
6
5
|
if (updatesMap.has(key)) {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
8
6
|
const updated = updatesMap.get(key)!
|
|
9
7
|
updatesMap.delete(key)
|
|
10
8
|
return updated
|
package/src/utilities/set.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Deep sets an object in a type-safe way
|
|
3
3
|
*/
|
|
4
|
-
export function set<TObject, TValue>(
|
|
4
|
+
export function set<TObject extends object, TValue>(
|
|
5
|
+
obj: TObject,
|
|
6
|
+
pathFn: (o: TObject) => TValue,
|
|
7
|
+
value: TValue,
|
|
8
|
+
): TObject {
|
|
5
9
|
const path: string[] = []
|
|
6
|
-
const proxy:
|
|
10
|
+
const proxy: unknown = new Proxy(
|
|
7
11
|
{},
|
|
8
12
|
{
|
|
9
13
|
get: (_, prop: string) => {
|
|
@@ -12,11 +16,12 @@ export function set<TObject, TValue>(obj: TObject, pathFn: (o: TObject) => TValu
|
|
|
12
16
|
},
|
|
13
17
|
},
|
|
14
18
|
)
|
|
15
|
-
pathFn(proxy)
|
|
19
|
+
pathFn(proxy as TObject)
|
|
16
20
|
|
|
17
|
-
const newObj
|
|
21
|
+
const newObj = {...obj}
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
23
|
let current: any = newObj
|
|
19
|
-
|
|
24
|
+
|
|
20
25
|
const lastKey = path.pop()!
|
|
21
26
|
|
|
22
27
|
for (const key of path) {
|
package/tests/setup.ts
CHANGED
package/vite.config.mts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {createEntryFiles} from './scripts/create-entry-files.js'
|
|
2
|
+
import {defineConfig} from 'vite'
|
|
3
|
+
import react from '@vitejs/plugin-react'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
root: path.join(__dirname, 'src'),
|
|
9
|
+
build: {
|
|
10
|
+
outDir: path.join(__dirname, 'dist'),
|
|
11
|
+
lib: {
|
|
12
|
+
name: 'UIExtensionsServerKit',
|
|
13
|
+
entry: path.join(__dirname, 'src/index.ts'),
|
|
14
|
+
formats: ['cjs', 'es'],
|
|
15
|
+
fileName: (type) => `index.${type}.js`,
|
|
16
|
+
},
|
|
17
|
+
rollupOptions: {
|
|
18
|
+
external: ['react'],
|
|
19
|
+
input: {
|
|
20
|
+
index: path.join(__dirname, 'src/index.ts'),
|
|
21
|
+
testing: path.join(__dirname, 'src/testing/index.ts'),
|
|
22
|
+
},
|
|
23
|
+
output: {
|
|
24
|
+
globals: {
|
|
25
|
+
react: 'React',
|
|
26
|
+
},
|
|
27
|
+
preserveModules: true,
|
|
28
|
+
assetFileNames: `[name].[ext]`,
|
|
29
|
+
entryFileNames: ({facadeModuleId}) => {
|
|
30
|
+
return facadeModuleId.endsWith('testing/index.ts') ? 'index.[format].js' : '[name].[format].js'
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
test: {
|
|
36
|
+
globals: true,
|
|
37
|
+
environment: 'jsdom',
|
|
38
|
+
setupFiles: [path.resolve(__dirname, './tests/setup.ts')],
|
|
39
|
+
deps: {
|
|
40
|
+
inline: ['@shopify/react-testing'],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
resolve: {
|
|
44
|
+
alias: {
|
|
45
|
+
'@shopify/ui-extensions-test-utils': path.resolve(__dirname, '../ui-extensions-test-utils/src'),
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
plugins: [
|
|
49
|
+
react(),
|
|
50
|
+
createEntryFiles({
|
|
51
|
+
files: {
|
|
52
|
+
index: './dist/index',
|
|
53
|
+
testing: './dist/testing/index',
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../i18n.cjs.js"),E=require("../utilities/isValidSurface.cjs.js"),f=require("../utilities/isUIExtension.cjs.js");class g{constructor(n={}){this.EVENT_THAT_WILL_MUTATE_THE_SERVER=["update"],this.listeners={},this.connectionListeners={close:new Set,open:new Set},this.connected=!1,this.uiExtensionsByUuid={},this.id=(Math.random()+1).toString(36).substring(7),this.options=p({...n,connection:{automaticConnect:!0,protocols:[],...n.connection??{}}}),this.setupConnection(this.options.connection.automaticConnect)}connect(n={connection:{}}){const t=S(this.options,n);return JSON.stringify(t)!==JSON.stringify(this.options)&&(this.options=t,this.setupConnection(!0)),()=>{this.closeConnection()}}on(n,t){return this.listeners[n]||(this.listeners[n]=new Set),this.listeners[n].add(t),()=>this.listeners[n].delete(t)}persist(n,t){var s,e,i;if(this.EVENT_THAT_WILL_MUTATE_THE_SERVER.includes(n))return this.options.locales?((e=t.extensions)==null||e.forEach(o=>{h.TRANSLATED_KEYS.forEach(a=>{var c;f.isUIExtension(o)&&((c=o.extensionPoints)==null||c.forEach(l=>{delete l[a]})),delete o[a]})}),(i=this.connection)==null?void 0:i.send(JSON.stringify({event:n,data:t}))):(s=this.connection)==null?void 0:s.send(JSON.stringify({event:n,data:t}));console.warn('You tried to use "persist" with a dispatch event. Please use the "emit" method instead.')}emit(...n){var e;const[t,s]=n;if(this.EVENT_THAT_WILL_MUTATE_THE_SERVER.includes(t))return console.warn(`You tried to use "emit" with a the "${t}" event. Please use the "persist" method instead to persist changes to the server.`);(e=this.connection)==null||e.send(JSON.stringify({event:"dispatch",data:{type:t,payload:s}}))}onConnection(n,t){return this.connectionListeners[n].add(t),()=>this.connectionListeners[n].delete(t)}initializeConnection(){var n;this.connection&&(this.connection.addEventListener("open",t=>{this.connected=!0,this.connectionListeners.open.forEach(s=>s(t))}),this.connection.addEventListener("close",t=>{this.connected=!1,this.connectionListeners.close.forEach(s=>s(t))}),(n=this.connection)==null||n.addEventListener("message",t=>{var s,e;try{const{event:i,data:o}=JSON.parse(t.data);if(i==="dispatch"){const{type:c,payload:l}=o;(s=this.listeners[c])==null||s.forEach(u=>u(l));return}const a=o.extensions?T(o.extensions,this.options.surface):o.extensions;(e=this.listeners[i])==null||e.forEach(c=>{c({...o,extensions:this._getLocalizedExtensions(a)})})}catch(i){console.error("[ExtensionServer] Something went wrong while parsing a server message:",i instanceof Error?i.message:i)}}))}setupConnection(n=!0){this.options.connection.url&&n&&(this.closeConnection(),this.connection=new WebSocket(this.options.connection.url,this.options.connection.protocols),this.initializeConnection())}closeConnection(){var n;this.connected&&((n=this.connection)==null||n.close())}_getLocalizedExtensions(n){return n==null?void 0:n.map(t=>{var a,c,l,u,d;if(!this.options.locales||!f.isUIExtension(t))return t;const e=((c=(a=this.uiExtensionsByUuid[t.uuid])==null?void 0:a.localization)==null?void 0:c.lastUpdated)!==((l=t.localization)==null?void 0:l.lastUpdated)?h.getFlattenedLocalization(t.localization,this.options.locales):((u=this.uiExtensionsByUuid[t.uuid])==null?void 0:u.localization)??t.localization,i=e&&h.isFlattenedTranslations(e)?JSON.parse(e.translations):e,o={...t,localization:e,name:i&&t.name.startsWith("t:")?this._getLocalizedValue(i,t.name):t.name,...t.description&&{description:i&&((d=t.description)!=null&&d.startsWith("t:"))?this._getLocalizedValue(i,t.description):t.description}};return this.uiExtensionsByUuid[t.uuid]={...o,extensionPoints:this._getLocalizedExtensionPoints(e,o)},this.uiExtensionsByUuid[t.uuid]})}_getLocalizedExtensionPoints(n,{extensionPoints:t,name:s,description:e}){return!n||!h.isFlattenedTranslations(n)?t:t==null?void 0:t.map(i=>({...i,localization:n,name:s,...e&&{description:e}}))}_getLocalizedValue(n,t){const s=t.replace("t:","");return n[s]||t}}function S(r,n){return p({...r,...n,connection:{...r.connection,...n.connection}})}function p(r){return E.isValidSurface(r.surface)||delete r.surface,r}function T(r,n){return n?r.filter(t=>t.surface===n?!0:Array.isArray(t.extensionPoints)?t.extensionPoints.filter(i=>typeof i=="string"?!1:i.surface===n).length>0:!1):r}exports.ExtensionServerClient=g;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./constants.cjs.js"),o=require("../state/actions/actions.cjs.js"),d=require("../ExtensionServerClient/ExtensionServerClient.cjs.js"),a=require("../hooks/useIsomorphicLayoutEffect.cjs.js"),p=require("../hooks/useExtensionServerState.cjs.js"),r=require("react");function x({children:f,options:S}){const[i,n]=p.useExtensionServerState(),[c,v]=r.useState(S),[t]=r.useState(()=>new d.ExtensionServerClient),u=r.useCallback((s=c)=>{v(s)},[c]);a.useIsomorphicLayoutEffect(()=>t.connect(c),[t,c]),a.useIsomorphicLayoutEffect(()=>{const s=[t.on("update",e=>n(o.createUpdateAction(e))),t.on("connected",e=>n(o.createConnectedAction(e))),t.on("refresh",e=>n(o.createRefreshAction(e))),t.on("focus",e=>n(o.createFocusAction(e))),t.on("unfocus",e=>n(o.createUnfocusAction(e)))];return()=>s.forEach(e=>e())},[n]);const l=r.useMemo(()=>({dispatch:n,state:i,connect:u,client:t}),[n,u,i,t]);return r.createElement(E.extensionServerContext.Provider,{value:l},f)}exports.ExtensionServerProvider=x;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { extensionServerContext as d } from "./constants.es.js";
|
|
2
|
-
import { createUpdateAction as l, createConnectedAction as v, createRefreshAction as x, createFocusAction as E, createUnfocusAction as S } from "../state/actions/actions.es.js";
|
|
3
|
-
import { ExtensionServerClient as h } from "../ExtensionServerClient/ExtensionServerClient.es.js";
|
|
4
|
-
import { useIsomorphicLayoutEffect as i } from "../hooks/useIsomorphicLayoutEffect.es.js";
|
|
5
|
-
import { useExtensionServerState as A } from "../hooks/useExtensionServerState.es.js";
|
|
6
|
-
import C, { useState as a, useCallback as P, useMemo as R } from "react";
|
|
7
|
-
function I({ children: u, options: f }) {
|
|
8
|
-
const [c, o] = A(), [n, m] = a(f), [t] = a(() => new h()), s = P(
|
|
9
|
-
(r = n) => {
|
|
10
|
-
m(r);
|
|
11
|
-
},
|
|
12
|
-
[n]
|
|
13
|
-
);
|
|
14
|
-
i(() => t.connect(n), [t, n]), i(() => {
|
|
15
|
-
const r = [
|
|
16
|
-
t.on("update", (e) => o(l(e))),
|
|
17
|
-
t.on("connected", (e) => o(v(e))),
|
|
18
|
-
t.on("refresh", (e) => o(x(e))),
|
|
19
|
-
t.on("focus", (e) => o(E(e))),
|
|
20
|
-
t.on("unfocus", (e) => o(S(e)))
|
|
21
|
-
];
|
|
22
|
-
return () => r.forEach((e) => e());
|
|
23
|
-
}, [o]);
|
|
24
|
-
const p = R(() => ({ dispatch: o, state: c, connect: s, client: t }), [o, s, c, t]);
|
|
25
|
-
return /* @__PURE__ */ C.createElement(d.Provider, { value: p }, u);
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
I as ExtensionServerProvider
|
|
29
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../context/constants.cjs.js"),t=require("react"),n=()=>t.useContext(e.extensionServerContext);exports.useExtensionServerContext=n;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../context/ExtensionServerProvider.cjs.js"),c=require("../context/constants.cjs.js"),s=require("../hooks/useExtensionServerContext.cjs.js"),t=require("react");function u({children:n,...e}){const r=s.useExtensionServerContext(),o=t.useMemo(()=>({...r,...e}),[r,e]);return t.createElement(c.extensionServerContext.Provider,{value:o},n)}function v({children:n,options:e={connection:{}},...r}){return t.createElement(i.ExtensionServerProvider,{options:e},t.createElement(u,{...r},n))}exports.MockExtensionServerProvider=v;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ExtensionServerProvider as i } from "../context/ExtensionServerProvider.es.js";
|
|
2
|
-
import { extensionServerContext as c } from "../context/constants.es.js";
|
|
3
|
-
import { useExtensionServerContext as m } from "../hooks/useExtensionServerContext.es.js";
|
|
4
|
-
import n, { useMemo as v } from "react";
|
|
5
|
-
function a({ children: t, ...e }) {
|
|
6
|
-
const r = m(), o = v(
|
|
7
|
-
() => ({
|
|
8
|
-
...r,
|
|
9
|
-
...e
|
|
10
|
-
}),
|
|
11
|
-
[r, e]
|
|
12
|
-
);
|
|
13
|
-
return /* @__PURE__ */ n.createElement(c.Provider, { value: o }, t);
|
|
14
|
-
}
|
|
15
|
-
function l({
|
|
16
|
-
children: t,
|
|
17
|
-
options: e = { connection: {} },
|
|
18
|
-
...r
|
|
19
|
-
}) {
|
|
20
|
-
return /* @__PURE__ */ n.createElement(i, { options: e }, /* @__PURE__ */ n.createElement(a, { ...r }, t));
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
l as MockExtensionServerProvider
|
|
24
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(e){return e.type==="ui_extension"&&Array.isArray(e.extensionPoints)&&e.extensionPoints.every(t=>typeof t=="object")}exports.isUIExtension=i;
|