@shopify/ui-extensions-server-kit 0.0.0-snapshot-20240820121935 → 0.0.0-snapshot-20250604200552
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 +7 -1
- package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -1
- package/dist/ExtensionServerClient/ExtensionServerClient.es.js +1 -1
- package/dist/context/ExtensionServerProvider.cjs.js +1 -1
- package/dist/context/ExtensionServerProvider.es.js +13 -12
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +37 -36
- package/dist/state/actions/actions.cjs.js +1 -1
- package/dist/state/actions/actions.d.ts +2 -1
- package/dist/state/actions/actions.es.js +7 -0
- package/dist/state/actions/types.d.ts +5 -1
- package/dist/testing/extensions.cjs.js +1 -1
- package/dist/testing/extensions.es.js +2 -2
- package/dist/types.d.ts +8 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.d.ts +3 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.d.ts +2 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.d.ts +17 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.d.ts +9 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +1 -0
- package/node_modules/@shopify/ui-extensions-test-utils/package.json +2 -3
- package/package.json +2 -4
- package/project.json +0 -2
- package/src/ExtensionServerClient/ExtensionServerClient.ts +2 -1
- package/src/ExtensionServerClient/types.ts +2 -0
- package/src/context/ExtensionServerProvider.tsx +2 -0
- package/src/state/actions/actions.ts +8 -1
- package/src/state/actions/types.ts +12 -1
- package/src/state/reducers/extensionServerReducer.test.ts +16 -2
- package/src/testing/extensions.ts +2 -2
- package/src/types.ts +3 -0
- package/src/utilities/replaceUpdated.ts +1 -0
- package/src/utilities/set.ts +1 -0
- package/node_modules/@types/node/LICENSE +0 -21
- package/node_modules/@types/node/README.md +0 -15
- package/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/assert.d.ts +0 -985
- package/node_modules/@types/node/async_hooks.d.ts +0 -522
- package/node_modules/@types/node/buffer.d.ts +0 -2321
- package/node_modules/@types/node/child_process.d.ts +0 -1544
- package/node_modules/@types/node/cluster.d.ts +0 -432
- package/node_modules/@types/node/console.d.ts +0 -412
- package/node_modules/@types/node/constants.d.ts +0 -19
- package/node_modules/@types/node/crypto.d.ts +0 -4451
- package/node_modules/@types/node/dgram.d.ts +0 -586
- package/node_modules/@types/node/diagnostics_channel.d.ts +0 -192
- package/node_modules/@types/node/dns/promises.d.ts +0 -381
- package/node_modules/@types/node/dns.d.ts +0 -809
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/domain.d.ts +0 -170
- package/node_modules/@types/node/events.d.ts +0 -803
- package/node_modules/@types/node/fs/promises.d.ts +0 -1205
- package/node_modules/@types/node/fs.d.ts +0 -4211
- package/node_modules/@types/node/globals.d.ts +0 -377
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/http.d.ts +0 -1801
- package/node_modules/@types/node/http2.d.ts +0 -2386
- package/node_modules/@types/node/https.d.ts +0 -544
- package/node_modules/@types/node/index.d.ts +0 -88
- package/node_modules/@types/node/inspector.d.ts +0 -2739
- package/node_modules/@types/node/module.d.ts +0 -298
- package/node_modules/@types/node/net.d.ts +0 -913
- package/node_modules/@types/node/os.d.ts +0 -473
- package/node_modules/@types/node/package.json +0 -235
- package/node_modules/@types/node/path.d.ts +0 -191
- package/node_modules/@types/node/perf_hooks.d.ts +0 -626
- package/node_modules/@types/node/process.d.ts +0 -1531
- package/node_modules/@types/node/punycode.d.ts +0 -117
- package/node_modules/@types/node/querystring.d.ts +0 -141
- package/node_modules/@types/node/readline/promises.d.ts +0 -143
- package/node_modules/@types/node/readline.d.ts +0 -666
- package/node_modules/@types/node/repl.d.ts +0 -430
- package/node_modules/@types/node/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/stream/web.d.ts +0 -336
- package/node_modules/@types/node/stream.d.ts +0 -1731
- package/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/test.d.ts +0 -1113
- package/node_modules/@types/node/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/timers.d.ts +0 -126
- package/node_modules/@types/node/tls.d.ts +0 -1203
- package/node_modules/@types/node/trace_events.d.ts +0 -171
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -985
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -522
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2321
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1544
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -412
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4450
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -586
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -192
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -381
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -754
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1205
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4211
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -377
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1801
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2386
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -544
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2739
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -298
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -913
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -473
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -626
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1531
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -143
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -666
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -336
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1731
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1113
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -126
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1203
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -171
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -206
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -937
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2075
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -541
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -667
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -692
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/@types/node/tty.d.ts +0 -206
- package/node_modules/@types/node/url.d.ts +0 -937
- package/node_modules/@types/node/util.d.ts +0 -2075
- package/node_modules/@types/node/v8.d.ts +0 -541
- package/node_modules/@types/node/vm.d.ts +0 -667
- package/node_modules/@types/node/wasi.d.ts +0 -158
- package/node_modules/@types/node/worker_threads.d.ts +0 -692
- package/node_modules/@types/node/zlib.d.ts +0 -517
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
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)
|
|
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;
|
|
@@ -85,7 +85,7 @@ class z {
|
|
|
85
85
|
var a, c, h, l, u;
|
|
86
86
|
if (!this.options.locales || !f(t))
|
|
87
87
|
return t;
|
|
88
|
-
const e = ((c = (a = this.uiExtensionsByUuid[t.uuid]) == null ? void 0 : a.localization) == null ? void 0 : c.lastUpdated) !== ((h = t.localization) == null ? void 0 : h.lastUpdated) ? g(t.localization, this.options.locales) : ((l = this.uiExtensionsByUuid[t.uuid]) == null ? void 0 : l.localization)
|
|
88
|
+
const e = ((c = (a = this.uiExtensionsByUuid[t.uuid]) == null ? void 0 : a.localization) == null ? void 0 : c.lastUpdated) !== ((h = t.localization) == null ? void 0 : h.lastUpdated) ? g(t.localization, this.options.locales) : ((l = this.uiExtensionsByUuid[t.uuid]) == null ? void 0 : l.localization) ?? t.localization, i = e && d(e) ? JSON.parse(e.translations) : e, o = {
|
|
89
89
|
...t,
|
|
90
90
|
localization: e,
|
|
91
91
|
name: i && t.name.startsWith("t:") ? this._getLocalizedValue(i, t.name) : t.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./constants.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./constants.cjs.js"),n=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,o]=p.useExtensionServerState(),[c,l]=r.useState(S),[t]=r.useState(()=>new d.ExtensionServerClient),u=r.useCallback((s=c)=>{l(s)},[c]);a.useIsomorphicLayoutEffect(()=>t.connect(c),[t,c]),a.useIsomorphicLayoutEffect(()=>{const s=[t.on("update",e=>o(n.createUpdateAction(e))),t.on("connected",e=>o(n.createConnectedAction(e))),t.on("refresh",e=>o(n.createRefreshAction(e))),t.on("focus",e=>o(n.createFocusAction(e))),t.on("unfocus",e=>o(n.createUnfocusAction(e))),t.on("log",e=>o(n.createLogAction(e)))];return()=>s.forEach(e=>e())},[o]);const v=r.useMemo(()=>({dispatch:o,state:i,connect:u,client:t}),[o,u,i,t]);return r.createElement(E.extensionServerContext.Provider,{value:v},f)}exports.ExtensionServerProvider=x;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { extensionServerContext as
|
|
2
|
-
import { createUpdateAction as
|
|
1
|
+
import { extensionServerContext as l } from "./constants.es.js";
|
|
2
|
+
import { createUpdateAction as d, createConnectedAction as v, createRefreshAction as x, createFocusAction as A, createUnfocusAction as E, createLogAction as S } from "../state/actions/actions.es.js";
|
|
3
3
|
import { ExtensionServerClient as h } from "../ExtensionServerClient/ExtensionServerClient.es.js";
|
|
4
4
|
import { useIsomorphicLayoutEffect as i } from "../hooks/useIsomorphicLayoutEffect.es.js";
|
|
5
|
-
import { useExtensionServerState as
|
|
6
|
-
import
|
|
7
|
-
function
|
|
8
|
-
const [c, o] =
|
|
5
|
+
import { useExtensionServerState as C } from "../hooks/useExtensionServerState.es.js";
|
|
6
|
+
import g, { useState as a, useCallback as L, useMemo as P } from "react";
|
|
7
|
+
function F({ children: u, options: f }) {
|
|
8
|
+
const [c, o] = C(), [n, m] = a(f), [t] = a(() => new h()), s = L(
|
|
9
9
|
(r = n) => {
|
|
10
10
|
m(r);
|
|
11
11
|
},
|
|
@@ -13,17 +13,18 @@ function I({ children: u, options: f }) {
|
|
|
13
13
|
);
|
|
14
14
|
i(() => t.connect(n), [t, n]), i(() => {
|
|
15
15
|
const r = [
|
|
16
|
-
t.on("update", (e) => o(
|
|
16
|
+
t.on("update", (e) => o(d(e))),
|
|
17
17
|
t.on("connected", (e) => o(v(e))),
|
|
18
18
|
t.on("refresh", (e) => o(x(e))),
|
|
19
|
-
t.on("focus", (e) => o(
|
|
20
|
-
t.on("unfocus", (e) => o(
|
|
19
|
+
t.on("focus", (e) => o(A(e))),
|
|
20
|
+
t.on("unfocus", (e) => o(E(e))),
|
|
21
|
+
t.on("log", (e) => o(S(e)))
|
|
21
22
|
];
|
|
22
23
|
return () => r.forEach((e) => e());
|
|
23
24
|
}, [o]);
|
|
24
|
-
const p =
|
|
25
|
-
return /* @__PURE__ */
|
|
25
|
+
const p = P(() => ({ dispatch: o, state: c, connect: s, client: t }), [o, s, c, t]);
|
|
26
|
+
return /* @__PURE__ */ g.createElement(l.Provider, { value: p }, u);
|
|
26
27
|
}
|
|
27
28
|
export {
|
|
28
|
-
|
|
29
|
+
F as ExtensionServerProvider
|
|
29
30
|
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./context/ExtensionServerProvider.cjs.js"),n=require("./context/constants.cjs.js"),o=require("./ExtensionServerClient/ExtensionServerClient.cjs.js"),s=require("./ExtensionServerClient/types.cjs.js"),i=require("./hooks/useExtensionClient.cjs.js"),c=require("./hooks/useExtensionServerContext.cjs.js"),a=require("./hooks/useExtensionServerEvent.cjs.js"),u=require("./hooks/useExtensionServerState.cjs.js"),E=require("./hooks/useIsomorphicLayoutEffect.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./context/ExtensionServerProvider.cjs.js"),n=require("./context/constants.cjs.js"),o=require("./ExtensionServerClient/ExtensionServerClient.cjs.js"),s=require("./ExtensionServerClient/types.cjs.js"),i=require("./hooks/useExtensionClient.cjs.js"),c=require("./hooks/useExtensionServerContext.cjs.js"),a=require("./hooks/useExtensionServerEvent.cjs.js"),u=require("./hooks/useExtensionServerState.cjs.js"),E=require("./hooks/useIsomorphicLayoutEffect.cjs.js"),e=require("./state/actions/actions.cjs.js"),S=require("./state/reducers/constants.cjs.js"),x=require("./state/reducers/extensionServerReducer.cjs.js"),l=require("./types.cjs.js"),v=require("./utilities/groupByKey.cjs.js"),A=require("./utilities/noop.cjs.js"),d=require("./utilities/replaceUpdated.cjs.js"),p=require("./utilities/set.cjs.js"),T=require("./utilities/assetToString.cjs.js"),q=require("./utilities/isValidSurface.cjs.js"),L=require("./utilities/isUIExtension.cjs.js"),t=require("./i18n.cjs.js");exports.ExtensionServerProvider=r.ExtensionServerProvider;exports.DEFAULT_VALUE=n.DEFAULT_VALUE;exports.extensionServerContext=n.extensionServerContext;exports.ExtensionServerClient=o.ExtensionServerClient;exports.AVAILABLE_SURFACES=s.AVAILABLE_SURFACES;exports.useExtensionClient=i.useExtensionClient;exports.useExtensionServerContext=c.useExtensionServerContext;exports.useExtensionServerEvent=a.useExtensionServerEvent;exports.useExtensionServerState=u.useExtensionServerState;exports.useIsomorphicLayoutEffect=E.useIsomorphicLayoutEffect;exports.createConnectedAction=e.createConnectedAction;exports.createFocusAction=e.createFocusAction;exports.createLogAction=e.createLogAction;exports.createRefreshAction=e.createRefreshAction;exports.createUnfocusAction=e.createUnfocusAction;exports.createUpdateAction=e.createUpdateAction;exports.INITIAL_STATE=S.INITIAL_STATE;exports.extensionServerReducer=x.extensionServerReducer;exports.Status=l.Status;exports.groupByKey=v.groupByKey;exports.noop=A.noop;exports.replaceUpdated=d.replaceUpdated;exports.set=p.set;exports.assetToString=T.assetToString;exports.isValidSurface=q.isValidSurface;exports.isUIExtension=L.isUIExtension;exports.TRANSLATED_KEYS=t.TRANSLATED_KEYS;exports.dictionaryToFlatMap=t.dictionaryToFlatMap;exports.flattenDevExtensionTranslations=t.flattenDevExtensionTranslations;exports.getFlattenedLocalization=t.getFlattenedLocalization;exports.isFlattenedTranslations=t.isFlattenedTranslations;exports.resolveDevExtensionLocale=t.resolveDevExtensionLocale;
|
package/dist/index.es.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
import { ExtensionServerProvider as r } from "./context/ExtensionServerProvider.es.js";
|
|
2
2
|
import { DEFAULT_VALUE as n, extensionServerContext as x } from "./context/constants.es.js";
|
|
3
|
-
import { ExtensionServerClient as
|
|
4
|
-
import { AVAILABLE_SURFACES as
|
|
5
|
-
import { useExtensionClient as
|
|
3
|
+
import { ExtensionServerClient as s } from "./ExtensionServerClient/ExtensionServerClient.es.js";
|
|
4
|
+
import { AVAILABLE_SURFACES as p } from "./ExtensionServerClient/types.es.js";
|
|
5
|
+
import { useExtensionClient as c } from "./hooks/useExtensionClient.es.js";
|
|
6
6
|
import { useExtensionServerContext as E } from "./hooks/useExtensionServerContext.es.js";
|
|
7
|
-
import { useExtensionServerEvent as
|
|
7
|
+
import { useExtensionServerEvent as S } from "./hooks/useExtensionServerEvent.es.js";
|
|
8
8
|
import { useExtensionServerState as u } from "./hooks/useExtensionServerState.es.js";
|
|
9
9
|
import { useIsomorphicLayoutEffect as d } from "./hooks/useIsomorphicLayoutEffect.es.js";
|
|
10
|
-
import { createConnectedAction as
|
|
10
|
+
import { createConnectedAction as T, createFocusAction as U, createLogAction as C, createRefreshAction as F, createUnfocusAction as I, createUpdateAction as g } from "./state/actions/actions.es.js";
|
|
11
11
|
import { INITIAL_STATE as D } from "./state/reducers/constants.es.js";
|
|
12
12
|
import { extensionServerReducer as _ } from "./state/reducers/extensionServerReducer.es.js";
|
|
13
|
-
import { Status as
|
|
14
|
-
import { groupByKey as
|
|
15
|
-
import { noop as
|
|
16
|
-
import { replaceUpdated as
|
|
17
|
-
import { set as
|
|
18
|
-
import { assetToString as
|
|
19
|
-
import { isValidSurface as
|
|
20
|
-
import { isUIExtension as
|
|
21
|
-
import { TRANSLATED_KEYS as
|
|
13
|
+
import { Status as h } from "./types.es.js";
|
|
14
|
+
import { groupByKey as K } from "./utilities/groupByKey.es.js";
|
|
15
|
+
import { noop as z } from "./utilities/noop.es.js";
|
|
16
|
+
import { replaceUpdated as P } from "./utilities/replaceUpdated.es.js";
|
|
17
|
+
import { set as b } from "./utilities/set.es.js";
|
|
18
|
+
import { assetToString as k } from "./utilities/assetToString.es.js";
|
|
19
|
+
import { isValidSurface as w } from "./utilities/isValidSurface.es.js";
|
|
20
|
+
import { isUIExtension as H } from "./utilities/isUIExtension.es.js";
|
|
21
|
+
import { TRANSLATED_KEYS as O, dictionaryToFlatMap as Q, flattenDevExtensionTranslations as W, getFlattenedLocalization as X, isFlattenedTranslations as Z, resolveDevExtensionLocale as $ } from "./i18n.es.js";
|
|
22
22
|
export {
|
|
23
|
-
|
|
23
|
+
p as AVAILABLE_SURFACES,
|
|
24
24
|
n as DEFAULT_VALUE,
|
|
25
|
-
|
|
25
|
+
s as ExtensionServerClient,
|
|
26
26
|
r as ExtensionServerProvider,
|
|
27
27
|
D as INITIAL_STATE,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
h as Status,
|
|
29
|
+
O as TRANSLATED_KEYS,
|
|
30
|
+
k as assetToString,
|
|
31
|
+
T as createConnectedAction,
|
|
32
32
|
U as createFocusAction,
|
|
33
|
-
C as
|
|
34
|
-
F as
|
|
35
|
-
I as
|
|
36
|
-
|
|
33
|
+
C as createLogAction,
|
|
34
|
+
F as createRefreshAction,
|
|
35
|
+
I as createUnfocusAction,
|
|
36
|
+
g as createUpdateAction,
|
|
37
|
+
Q as dictionaryToFlatMap,
|
|
37
38
|
x as extensionServerContext,
|
|
38
39
|
_ as extensionServerReducer,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
W as flattenDevExtensionTranslations,
|
|
41
|
+
X as getFlattenedLocalization,
|
|
42
|
+
K as groupByKey,
|
|
43
|
+
Z as isFlattenedTranslations,
|
|
44
|
+
H as isUIExtension,
|
|
45
|
+
w as isValidSurface,
|
|
46
|
+
z as noop,
|
|
47
|
+
P as replaceUpdated,
|
|
48
|
+
$ as resolveDevExtensionLocale,
|
|
49
|
+
b as set,
|
|
50
|
+
c as useExtensionClient,
|
|
50
51
|
E as useExtensionServerContext,
|
|
51
|
-
|
|
52
|
+
S as useExtensionServerEvent,
|
|
52
53
|
u as useExtensionServerState,
|
|
53
54
|
d as useIsomorphicLayoutEffect
|
|
54
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){return{type:"connected",payload:e}}function c(e){return{type:"update",payload:e}}function n(e){return{type:"refresh",payload:e}}function o(e){return{type:"focus",payload:e}}function r(e){return{type:"unfocus",payload:e}}exports.createConnectedAction=t;exports.createFocusAction=o;exports.createRefreshAction=n;exports.createUnfocusAction=r;exports.createUpdateAction=c;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){return{type:"connected",payload:e}}function c(e){return{type:"update",payload:e}}function n(e){return{type:"refresh",payload:e}}function o(e){return{type:"focus",payload:e}}function r(e){return{type:"unfocus",payload:e}}function u(e){return{type:"log",payload:e}}exports.createConnectedAction=t;exports.createFocusAction=o;exports.createLogAction=u;exports.createRefreshAction=n;exports.createUnfocusAction=r;exports.createUpdateAction=c;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ConnectedAction, UpdateAction, RefreshAction, FocusAction, UnfocusAction } from './types';
|
|
1
|
+
import type { ConnectedAction, UpdateAction, RefreshAction, FocusAction, UnfocusAction, LogAction } from './types';
|
|
2
2
|
export declare function createConnectedAction(payload: ConnectedAction['payload']): ConnectedAction;
|
|
3
3
|
export declare function createUpdateAction(payload: UpdateAction['payload']): UpdateAction;
|
|
4
4
|
export declare function createRefreshAction(payload: RefreshAction['payload']): RefreshAction;
|
|
5
5
|
export declare function createFocusAction(payload: FocusAction['payload']): FocusAction;
|
|
6
6
|
export declare function createUnfocusAction(payload: UnfocusAction['payload']): UnfocusAction;
|
|
7
|
+
export declare function createLogAction(payload: LogAction['payload']): LogAction;
|
|
@@ -28,9 +28,16 @@ function o(e) {
|
|
|
28
28
|
payload: e
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
function u(e) {
|
|
32
|
+
return {
|
|
33
|
+
type: "log",
|
|
34
|
+
payload: e
|
|
35
|
+
};
|
|
36
|
+
}
|
|
31
37
|
export {
|
|
32
38
|
t as createConnectedAction,
|
|
33
39
|
r as createFocusAction,
|
|
40
|
+
u as createLogAction,
|
|
34
41
|
c as createRefreshAction,
|
|
35
42
|
o as createUnfocusAction,
|
|
36
43
|
n as createUpdateAction
|
|
@@ -18,4 +18,8 @@ export interface UnfocusAction {
|
|
|
18
18
|
type: 'unfocus';
|
|
19
19
|
payload: ExtensionServer.InboundEvents['unfocus'];
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export interface LogAction {
|
|
22
|
+
type: 'log';
|
|
23
|
+
payload: ExtensionServer.InboundEvents['log'];
|
|
24
|
+
}
|
|
25
|
+
export type ExtensionServerActions = ConnectedAction | UpdateAction | RefreshAction | FocusAction | UnfocusAction | LogAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../types.cjs.js");let i=0;function a(e){return`00000000000${e}`.slice(-12)}function r(e={}){const t=`00000000-0000-0000-0000-${a(i++)}`,n=Date.now();return{handle:"my-extension",name:"My extension",description:"My extension description",surface:"admin",type:"purchase_option",externalType:"external_type",uuid:t,version:"extension version",...e,assets:{main:{name:"main",url:`https://secure-link.com/extensions/${t}/assets/handle.js?lastUpdated=${n}`,lastUpdated:n},...e.assets
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../types.cjs.js");let i=0;function a(e){return`00000000000${e}`.slice(-12)}function r(e={}){const t=`00000000-0000-0000-0000-${a(i++)}`,n=Date.now();return{handle:"my-extension",name:"My extension",description:"My extension description",surface:"admin",type:"purchase_option",externalType:"external_type",uuid:t,version:"extension version",...e,assets:{main:{name:"main",url:`https://secure-link.com/extensions/${t}/assets/handle.js?lastUpdated=${n}`,lastUpdated:n},...e.assets??{}},development:{hidden:!1,status:s.Status.Success,resource:{url:"resourceUrl"},root:{url:`https://secure-link.com/extensions/${t}`},renderer:{name:"render name",version:"1.0.0"},...e.development??{}},extensionPoints:e.extensionPoints,capabilities:e.capabilities,localization:e.localization,authenticatedRedirectStartUrl:e.authenticatedRedirectStartUrl,authenticatedRedirectRedirectUrls:e.authenticatedRedirectRedirectUrls,settings:{fields:[{key:"sample-key",name:"sample_name",type:"sample_type"}]}}}exports.mockExtension=r;
|
|
@@ -21,7 +21,7 @@ function c(e = {}) {
|
|
|
21
21
|
url: `https://secure-link.com/extensions/${t}/assets/handle.js?lastUpdated=${n}`,
|
|
22
22
|
lastUpdated: n
|
|
23
23
|
},
|
|
24
|
-
...e.assets
|
|
24
|
+
...e.assets ?? {}
|
|
25
25
|
},
|
|
26
26
|
development: {
|
|
27
27
|
hidden: !1,
|
|
@@ -36,7 +36,7 @@ function c(e = {}) {
|
|
|
36
36
|
name: "render name",
|
|
37
37
|
version: "1.0.0"
|
|
38
38
|
},
|
|
39
|
-
...e.development
|
|
39
|
+
...e.development ?? {}
|
|
40
40
|
},
|
|
41
41
|
// this is due to the naive DeepPartial but also more complex ones
|
|
42
42
|
// [see stackoverflow](https://stackoverflow.com/a/68699273) assume that
|
package/dist/types.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ declare global {
|
|
|
47
47
|
navigate: {
|
|
48
48
|
url: string;
|
|
49
49
|
};
|
|
50
|
+
log: {
|
|
51
|
+
level: string;
|
|
52
|
+
args: unknown[];
|
|
53
|
+
extensionName: string;
|
|
54
|
+
};
|
|
50
55
|
}
|
|
51
56
|
namespace API {
|
|
52
57
|
interface BaseResponse {
|
|
@@ -93,6 +98,9 @@ export interface ExtensionPoint {
|
|
|
93
98
|
localization?: FlattenedLocalization | Localization | null;
|
|
94
99
|
name: string;
|
|
95
100
|
description?: string;
|
|
101
|
+
assets?: {
|
|
102
|
+
[name: string]: Asset;
|
|
103
|
+
};
|
|
96
104
|
}
|
|
97
105
|
export type ExtensionPoints = string[] | ExtensionPoint[] | null;
|
|
98
106
|
interface CollectBuyerConsentCapabilities {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface HookWrapper<T> {
|
|
3
|
+
result: T;
|
|
4
|
+
/**
|
|
5
|
+
* Use to wrap calls to stateful hook methods:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const hook = testHook(() => useToggle(false))
|
|
9
|
+
* expect(hook.result.value).toBe(false)
|
|
10
|
+
* hook.act(() => hook.result.toggle())
|
|
11
|
+
* expect(hook.result.value).toBe(true)
|
|
12
|
+
* ```
|
|
13
|
+
**/
|
|
14
|
+
act<TR>(callback: (currentResult: T) => TR): TR;
|
|
15
|
+
forceUpdate(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function renderHook<T, TP>(hook: () => T, Providers?: React.ComponentType<TP>, options?: Omit<TP, 'children'>): HookWrapper<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type ProviderComponent<TProps = any> = React.ComponentType<React.PropsWithChildren<TProps>>;
|
|
3
|
+
export type Tail<T extends any[]> = T extends [head: any, ...tail: infer TRest] ? TRest : never;
|
|
4
|
+
export type PropUnion<TProviders extends any[], TProps extends {
|
|
5
|
+
[k: string]: any;
|
|
6
|
+
} = Empty> = TProviders[0] extends React.ComponentType<any> ? React.ComponentPropsWithoutRef<TProviders[0]> & PropUnion<Tail<TProviders>> : TProps;
|
|
7
|
+
export interface Empty {
|
|
8
|
+
}
|
|
9
|
+
export declare function withProviders<T extends ProviderComponent[]>(...providers: T): ProviderComponent<PropUnion<T>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/ui-extensions-test-utils",
|
|
3
3
|
"version": "3.26.0",
|
|
4
|
+
"packageManager": "pnpm@10.11.1",
|
|
4
5
|
"private": true,
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"main": "dist/index",
|
|
@@ -28,12 +29,10 @@
|
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@shopify/react-testing": "^3.0.0",
|
|
31
|
-
"@types/node": "18.19.3",
|
|
32
32
|
"@types/react": "16.14.0",
|
|
33
33
|
"@types/react-dom": "^16.9.11",
|
|
34
34
|
"react": "^17.0.2",
|
|
35
|
-
"react-dom": "^17.0.2"
|
|
36
|
-
"typescript": "5.2.2"
|
|
35
|
+
"react-dom": "^17.0.2"
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|
|
39
38
|
"react": "^17.0.2"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/ui-extensions-server-kit",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-20250604200552",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
@@ -40,15 +40,13 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@shopify/react-testing": "^3.0.0",
|
|
42
42
|
"@shopify/ui-extensions-test-utils": "3.26.0",
|
|
43
|
-
"@types/node": "18.19.3",
|
|
44
43
|
"@types/react": "17.0.2",
|
|
45
44
|
"@vitejs/plugin-react-refresh": "^1.3.6",
|
|
46
45
|
"jest-websocket-mock": "^2.4.0",
|
|
47
46
|
"jsdom": "^20.0.3",
|
|
48
47
|
"react": "^17.0.2",
|
|
49
|
-
"typescript": "5.2.2",
|
|
50
48
|
"vi-fetch": "^0.8.0",
|
|
51
|
-
"vite": "
|
|
49
|
+
"vite": "5.4.12"
|
|
52
50
|
},
|
|
53
51
|
"peerDependencies": {
|
|
54
52
|
"react": "^17.0.2"
|
package/project.json
CHANGED
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
},
|
|
57
57
|
"test": {
|
|
58
58
|
"executor": "nx:run-commands",
|
|
59
|
-
"dependsOn": ["^build"],
|
|
60
59
|
"options": {
|
|
61
60
|
"command": "pnpm vitest run",
|
|
62
61
|
"cwd": "packages/ui-extensions-server-kit"
|
|
@@ -64,7 +63,6 @@
|
|
|
64
63
|
},
|
|
65
64
|
"test:watch": {
|
|
66
65
|
"executor": "nx:run-commands",
|
|
67
|
-
"dependsOn": ["^build"],
|
|
68
66
|
"options": {
|
|
69
67
|
"command": "pnpm vitest watch",
|
|
70
68
|
"cwd": "packages/ui-extensions-server-kit"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-dynamic-delete */
|
|
1
2
|
/* eslint-disable no-console */
|
|
2
3
|
import {Surface} from './types.js'
|
|
3
4
|
import {
|
|
@@ -211,7 +212,7 @@ export class ExtensionServerClient implements ExtensionServer.Client {
|
|
|
211
212
|
|
|
212
213
|
const localization = shouldUpdateTranslations
|
|
213
214
|
? getFlattenedLocalization(extension.localization, this.options.locales)
|
|
214
|
-
: this.uiExtensionsByUuid[extension.uuid]?.localization
|
|
215
|
+
: this.uiExtensionsByUuid[extension.uuid]?.localization ?? extension.localization
|
|
215
216
|
|
|
216
217
|
const parsedTranslation: {[key: string]: string} =
|
|
217
218
|
localization && isFlattenedTranslations(localization) ? JSON.parse(localization.translations) : localization
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
createRefreshAction,
|
|
6
6
|
createFocusAction,
|
|
7
7
|
createUnfocusAction,
|
|
8
|
+
createLogAction,
|
|
8
9
|
} from '../state'
|
|
9
10
|
|
|
10
11
|
import {ExtensionServerClient} from '../ExtensionServerClient'
|
|
@@ -35,6 +36,7 @@ export function ExtensionServerProvider({children, options: defaultOptions}: Ext
|
|
|
35
36
|
client.on('refresh', (payload) => dispatch(createRefreshAction(payload))),
|
|
36
37
|
client.on('focus', (payload) => dispatch(createFocusAction(payload))),
|
|
37
38
|
client.on('unfocus', (payload) => dispatch(createUnfocusAction(payload))),
|
|
39
|
+
client.on('log', (payload) => dispatch(createLogAction(payload))),
|
|
38
40
|
]
|
|
39
41
|
|
|
40
42
|
return () => listeners.forEach((unsubscribe) => unsubscribe())
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {ConnectedAction, UpdateAction, RefreshAction, FocusAction, UnfocusAction} from './types'
|
|
1
|
+
import type {ConnectedAction, UpdateAction, RefreshAction, FocusAction, UnfocusAction, LogAction} from './types'
|
|
2
2
|
|
|
3
3
|
export function createConnectedAction(payload: ConnectedAction['payload']): ConnectedAction {
|
|
4
4
|
return {
|
|
@@ -34,3 +34,10 @@ export function createUnfocusAction(payload: UnfocusAction['payload']): UnfocusA
|
|
|
34
34
|
payload,
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
export function createLogAction(payload: LogAction['payload']): LogAction {
|
|
39
|
+
return {
|
|
40
|
+
type: 'log',
|
|
41
|
+
payload,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -23,4 +23,15 @@ export interface UnfocusAction {
|
|
|
23
23
|
payload: ExtensionServer.InboundEvents['unfocus']
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export
|
|
26
|
+
export interface LogAction {
|
|
27
|
+
type: 'log'
|
|
28
|
+
payload: ExtensionServer.InboundEvents['log']
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ExtensionServerActions =
|
|
32
|
+
| ConnectedAction
|
|
33
|
+
| UpdateAction
|
|
34
|
+
| RefreshAction
|
|
35
|
+
| FocusAction
|
|
36
|
+
| UnfocusAction
|
|
37
|
+
| LogAction
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createRefreshAction,
|
|
8
8
|
createFocusAction,
|
|
9
9
|
createUnfocusAction,
|
|
10
|
+
createLogAction,
|
|
10
11
|
} from '../actions'
|
|
11
12
|
|
|
12
13
|
import type {ExtensionServerState} from './types'
|
|
@@ -105,7 +106,7 @@ describe('extensionServerReducer()', () => {
|
|
|
105
106
|
const state1 = extensionServerReducer(previousState, action)
|
|
106
107
|
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
107
108
|
const url1 = new URL(state1.extensions[0].assets.main.url)
|
|
108
|
-
const timestamp1 = url1.searchParams.get('lastUpdated')
|
|
109
|
+
const timestamp1 = url1.searchParams.get('lastUpdated') ?? ''
|
|
109
110
|
|
|
110
111
|
expect(timestamp1.length).toBeGreaterThan(0)
|
|
111
112
|
|
|
@@ -115,7 +116,7 @@ describe('extensionServerReducer()', () => {
|
|
|
115
116
|
const state2 = extensionServerReducer(state1, action)
|
|
116
117
|
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
117
118
|
const url2 = new URL(state2.extensions[0].assets.main.url)
|
|
118
|
-
const timestamp2 = url2.searchParams.get('lastUpdated')
|
|
119
|
+
const timestamp2 = url2.searchParams.get('lastUpdated') ?? ''
|
|
119
120
|
|
|
120
121
|
expect(timestamp2.length).toBeGreaterThan(0)
|
|
121
122
|
expect(timestamp1).not.toStrictEqual(timestamp2)
|
|
@@ -157,4 +158,17 @@ describe('extensionServerReducer()', () => {
|
|
|
157
158
|
expect(state.extensions[0].development.focused).toBe(false)
|
|
158
159
|
})
|
|
159
160
|
})
|
|
161
|
+
|
|
162
|
+
test('does not mutate the state when receiving log events', () => {
|
|
163
|
+
const extension = mockExtension()
|
|
164
|
+
const previousState: ExtensionServerState = {
|
|
165
|
+
store: 'test-store.com',
|
|
166
|
+
extensions: [extension],
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const action = createLogAction({level: 'info', args: ['test'], extensionName: extension.name})
|
|
170
|
+
const state = extensionServerReducer(previousState, action)
|
|
171
|
+
|
|
172
|
+
expect(state).toStrictEqual(previousState)
|
|
173
|
+
})
|
|
160
174
|
})
|
|
@@ -29,7 +29,7 @@ export function mockExtension(obj: DeepPartial<ExtensionPayload> = {}): Extensio
|
|
|
29
29
|
url: `https://secure-link.com/extensions/${uuid}/assets/handle.js?lastUpdated=${lastUpdated}`,
|
|
30
30
|
lastUpdated,
|
|
31
31
|
},
|
|
32
|
-
...((obj.assets
|
|
32
|
+
...((obj.assets ?? {}) as any),
|
|
33
33
|
},
|
|
34
34
|
development: {
|
|
35
35
|
hidden: false,
|
|
@@ -44,7 +44,7 @@ export function mockExtension(obj: DeepPartial<ExtensionPayload> = {}): Extensio
|
|
|
44
44
|
name: 'render name',
|
|
45
45
|
version: '1.0.0',
|
|
46
46
|
},
|
|
47
|
-
...((obj.development
|
|
47
|
+
...((obj.development ?? {}) as any),
|
|
48
48
|
},
|
|
49
49
|
// this is due to the naive DeepPartial but also more complex ones
|
|
50
50
|
// [see stackoverflow](https://stackoverflow.com/a/68699273) assume that
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-invalid-void-type */
|
|
1
2
|
/* eslint-disable @shopify/strict-component-boundaries */
|
|
2
3
|
import {FlattenedLocalization, Localization} from './i18n'
|
|
3
4
|
import './ExtensionServerClient/types'
|
|
@@ -37,6 +38,7 @@ declare global {
|
|
|
37
38
|
focus: {uuid: string}[]
|
|
38
39
|
unfocus: void
|
|
39
40
|
navigate: {url: string}
|
|
41
|
+
log: {level: string; args: unknown[]; extensionName: string}
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
// API responses
|
|
@@ -93,6 +95,7 @@ export interface ExtensionPoint {
|
|
|
93
95
|
localization?: FlattenedLocalization | Localization | null
|
|
94
96
|
name: string
|
|
95
97
|
description?: string
|
|
98
|
+
assets?: {[name: string]: Asset}
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
export type ExtensionPoints = string[] | ExtensionPoint[] | null
|
|
@@ -4,6 +4,7 @@ export function replaceUpdated<T>(arr: T[], updates: T[], cb: (v: T) => unknown)
|
|
|
4
4
|
// eslint-disable-next-line node/callback-return
|
|
5
5
|
const key = cb(item)
|
|
6
6
|
if (updatesMap.has(key)) {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
7
8
|
const updated = updatesMap.get(key)!
|
|
8
9
|
updatesMap.delete(key)
|
|
9
10
|
return updated
|
package/src/utilities/set.ts
CHANGED
|
@@ -16,6 +16,7 @@ export function set<TObject, TValue>(obj: TObject, pathFn: (o: TObject) => TValu
|
|
|
16
16
|
|
|
17
17
|
const newObj: TObject = {...obj}
|
|
18
18
|
let current: any = newObj
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
20
|
const lastKey = path.pop()!
|
|
20
21
|
|
|
21
22
|
for (const key of path) {
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Microsoft Corporation.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE
|