@shopify/ui-extensions-server-kit 5.2.1 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -1
- package/dist/ExtensionServerClient/ExtensionServerClient.d.ts +1 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.es.js +1 -1
- package/dist/ExtensionServerClient/ExtensionServerClient.test.d.ts +8 -0
- package/dist/ExtensionServerClient/server-types.d.ts +42 -0
- package/dist/context/constants.cjs.js +1 -1
- package/dist/context/constants.d.ts +0 -1
- package/dist/context/constants.es.js +0 -1
- package/dist/context/types.d.ts +1 -0
- package/dist/hooks/index.d.ts +0 -2
- package/dist/i18n.cjs.js +1 -1
- package/dist/i18n.d.ts +1 -20
- package/dist/i18n.es.js +0 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +40 -48
- package/dist/testing/extensions.cjs.js +1 -1
- package/dist/testing/extensions.es.js +2 -2
- package/dist/types.cjs.js +1 -1
- package/dist/types.d.ts +6 -4
- package/dist/types.es.js +2 -2
- package/dist/utilities/index.d.ts +0 -1
- 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 +7 -5
- package/project.json +0 -2
- package/src/ExtensionServerClient/ExtensionServerClient.test.ts +837 -330
- package/src/ExtensionServerClient/ExtensionServerClient.ts +10 -8
- package/src/ExtensionServerClient/server-types.ts +55 -0
- package/src/ExtensionServerClient/types.ts +2 -0
- package/src/context/ExtensionServerProvider.test.tsx +202 -39
- package/src/context/ExtensionServerProvider.tsx +1 -0
- package/src/context/constants.ts +3 -2
- package/src/context/types.ts +1 -0
- package/src/hooks/index.ts +0 -2
- package/src/i18n.ts +3 -3
- package/src/state/reducers/extensionServerReducer.test.ts +2 -2
- package/src/testing/extensions.ts +2 -2
- package/src/types.ts +5 -4
- package/src/utilities/index.ts +0 -1
- package/src/utilities/replaceUpdated.ts +1 -0
- package/src/utilities/set.ts +1 -0
- package/dist/hooks/useExtensionClient.cjs.js +0 -1
- package/dist/hooks/useExtensionClient.d.ts +0 -1
- package/dist/hooks/useExtensionClient.es.js +0 -8
- package/dist/hooks/useExtensionServerEvent.cjs.js +0 -1
- package/dist/hooks/useExtensionServerEvent.d.ts +0 -1
- package/dist/hooks/useExtensionServerEvent.es.js +0 -9
- package/dist/utilities/groupByKey.cjs.js +0 -1
- package/dist/utilities/groupByKey.d.ts +0 -3
- package/dist/utilities/groupByKey.es.js +0 -6
- 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/src/hooks/useExtensionClient.ts +0 -6
- package/src/hooks/useExtensionServerEvent.ts +0 -11
- package/src/utilities/groupByKey.ts +0 -3
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,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Surface } from './types.js';
|
|
2
|
+
import { ExtensionPayload, ExtensionPoint } from '../types';
|
|
3
|
+
import { FlattenedLocalization, Localization } from '../i18n';
|
|
4
|
+
export declare namespace ExtensionServer {
|
|
5
|
+
interface UIExtension extends ExtensionPayload {
|
|
6
|
+
extensionPoints: ExtensionPoint[];
|
|
7
|
+
localization?: FlattenedLocalization | Localization | null;
|
|
8
|
+
}
|
|
9
|
+
interface Client {
|
|
10
|
+
id: string;
|
|
11
|
+
connection: WebSocket;
|
|
12
|
+
options: Options;
|
|
13
|
+
connect(options?: Options): () => void;
|
|
14
|
+
on<TEvent extends keyof InboundEvents>(event: TEvent, listener: (payload: InboundEvents[TEvent]) => void): () => void;
|
|
15
|
+
persist<TEvent extends keyof OutboundPersistEvents>(event: TEvent, data: OutboundPersistEvents[TEvent]): void;
|
|
16
|
+
emit<TEvent extends keyof DispatchEvents>(...args: EmitArgs<TEvent>): void;
|
|
17
|
+
onConnection<TEvent extends 'close' | 'open'>(event: TEvent, listener: (event: Event) => void): () => void;
|
|
18
|
+
}
|
|
19
|
+
interface Options {
|
|
20
|
+
connection: {
|
|
21
|
+
url?: string;
|
|
22
|
+
automaticConnect?: boolean;
|
|
23
|
+
protocols?: string | string[];
|
|
24
|
+
};
|
|
25
|
+
surface?: Surface;
|
|
26
|
+
locales?: any;
|
|
27
|
+
}
|
|
28
|
+
interface ServerEvents {
|
|
29
|
+
event: string;
|
|
30
|
+
data: any;
|
|
31
|
+
}
|
|
32
|
+
interface InboundEvents {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}
|
|
35
|
+
interface OutboundPersistEvents {
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
}
|
|
38
|
+
interface DispatchEvents {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}
|
|
41
|
+
type EmitArgs<TEvent extends keyof DispatchEvents> = undefined extends DispatchEvents[TEvent] ? [event: TEvent] : [event: TEvent, payload: DispatchEvents[TEvent]];
|
|
42
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../ExtensionServerClient/ExtensionServerClient.cjs.js"),n=require("../state/reducers/constants.cjs.js"),e=require("../utilities/noop.cjs.js"),o=require("react"),r={connect:e.noop,dispatch:e.noop,state:n.INITIAL_STATE,client:new t.ExtensionServerClient},s=o.createContext(r);exports.extensionServerContext=s;
|
package/dist/context/types.d.ts
CHANGED
package/dist/hooks/index.d.ts
CHANGED
package/dist/i18n.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=["localization","name","description"];function L(n){const t=new Map;return u(n,(e,s)=>t.set(e,s)),t}function u(n,t,e){Object.keys(n).forEach(s=>{const o=n[s],r=e?`${e}.${s}`:s;o!=null&&(typeof o=="string"?t(r,o):u(o,t,r))})}function f(n,t){const e=a(n.translations[n.defaultLocale]),s=i(t),o=a(n.translations[s]),r=a(n.translations[t]);return d(new Map([...e,...o,...r]))}function a(n){return n?L(n):new Map}function c(n,t){const e=new Set(Object.keys(n.translations));if(e.size===0||e.has(t.user))return t.user;const s=i(t.user);if(e.has(s))return s;if(t.shop&&e.has(t.shop))return t.shop;const o=t.shop&&i(t.shop);return o&&e.has(o)?o:n.defaultLocale}function d(n){const t={};for(const[e,s]of n)t[e]=s;return t}function i(n){return n.split("-")[0]}function T(n,t){if(!n||!t)return;if(p(n))return n;const e=c(n,t),s=JSON.stringify(f(n,e));return{extensionLocale:e,translations:s,lastUpdated:n.lastUpdated}}function p(n){return typeof n.translations=="string"&&Object.prototype.hasOwnProperty.call(n,"extensionLocale")}exports.TRANSLATED_KEYS=l;exports.flattenDevExtensionTranslations=f;exports.getFlattenedLocalization=T;exports.isFlattenedTranslations=p;exports.resolveDevExtensionLocale=c;
|
package/dist/i18n.d.ts
CHANGED
|
@@ -22,9 +22,6 @@ export interface LocalesOptions {
|
|
|
22
22
|
user: string;
|
|
23
23
|
shop?: string;
|
|
24
24
|
}
|
|
25
|
-
export interface TranslationDictionary {
|
|
26
|
-
[key: string]: string | TranslationDictionary;
|
|
27
|
-
}
|
|
28
25
|
/**
|
|
29
26
|
* This is a flattened dictionary of extension translations for the active locale.
|
|
30
27
|
*
|
|
@@ -63,26 +60,10 @@ export interface TranslationDictionary {
|
|
|
63
60
|
* }
|
|
64
61
|
* ```
|
|
65
62
|
*/
|
|
66
|
-
|
|
63
|
+
interface ExtensionTranslationMap {
|
|
67
64
|
[key: string]: string;
|
|
68
65
|
}
|
|
69
66
|
export declare const TRANSLATED_KEYS: string[];
|
|
70
|
-
/**
|
|
71
|
-
* From a nested dictionary like the following :
|
|
72
|
-
*
|
|
73
|
-
* ```typescript
|
|
74
|
-
* const dictionary = {
|
|
75
|
-
* Foo: {
|
|
76
|
-
* Bar: {
|
|
77
|
-
* fooBar: 'something'
|
|
78
|
-
* }
|
|
79
|
-
* }
|
|
80
|
-
* }
|
|
81
|
-
*
|
|
82
|
-
* Returns a map containing this pair : {'Foo.Bar.fooBar': 'something'}
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare function dictionaryToFlatMap(dictionary: TranslationDictionary): Map<string, string>;
|
|
86
67
|
export declare function flattenDevExtensionTranslations(localization: Localization, locale: string): ExtensionTranslationMap;
|
|
87
68
|
export declare function resolveDevExtensionLocale(localization: Localization, locales: {
|
|
88
69
|
user: string;
|
package/dist/i18n.es.js
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./context/ExtensionServerProvider.cjs.js"),r=require("./context/constants.cjs.js"),o=require("./ExtensionServerClient/ExtensionServerClient.cjs.js"),s=require("./ExtensionServerClient/types.cjs.js"),i=require("./hooks/useExtensionServerContext.cjs.js"),c=require("./hooks/useExtensionServerState.cjs.js"),a=require("./hooks/useIsomorphicLayoutEffect.cjs.js"),e=require("./state/actions/actions.cjs.js"),u=require("./state/reducers/constants.cjs.js"),S=require("./state/reducers/extensionServerReducer.cjs.js"),E=require("./types.cjs.js"),x=require("./utilities/noop.cjs.js"),l=require("./utilities/replaceUpdated.cjs.js"),v=require("./utilities/set.cjs.js"),A=require("./utilities/assetToString.cjs.js"),d=require("./utilities/isValidSurface.cjs.js"),q=require("./utilities/isUIExtension.cjs.js"),t=require("./i18n.cjs.js");exports.ExtensionServerProvider=n.ExtensionServerProvider;exports.extensionServerContext=r.extensionServerContext;exports.ExtensionServerClient=o.ExtensionServerClient;exports.AVAILABLE_SURFACES=s.AVAILABLE_SURFACES;exports.useExtensionServerContext=i.useExtensionServerContext;exports.useExtensionServerState=c.useExtensionServerState;exports.useIsomorphicLayoutEffect=a.useIsomorphicLayoutEffect;exports.createConnectedAction=e.createConnectedAction;exports.createFocusAction=e.createFocusAction;exports.createRefreshAction=e.createRefreshAction;exports.createUnfocusAction=e.createUnfocusAction;exports.createUpdateAction=e.createUpdateAction;exports.INITIAL_STATE=u.INITIAL_STATE;exports.extensionServerReducer=S.extensionServerReducer;exports.Status=E.Status;exports.noop=x.noop;exports.replaceUpdated=l.replaceUpdated;exports.set=v.set;exports.assetToString=A.assetToString;exports.isValidSurface=d.isValidSurface;exports.isUIExtension=q.isUIExtension;exports.TRANSLATED_KEYS=t.TRANSLATED_KEYS;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,46 @@
|
|
|
1
1
|
import { ExtensionServerProvider as r } from "./context/ExtensionServerProvider.es.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ExtensionServerClient as
|
|
2
|
+
import { extensionServerContext as n } from "./context/constants.es.js";
|
|
3
|
+
import { ExtensionServerClient as s } from "./ExtensionServerClient/ExtensionServerClient.es.js";
|
|
4
4
|
import { AVAILABLE_SURFACES as a } from "./ExtensionServerClient/types.es.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { isValidSurface as q } from "./utilities/isValidSurface.es.js";
|
|
20
|
-
import { isUIExtension as G } from "./utilities/isUIExtension.es.js";
|
|
21
|
-
import { TRANSLATED_KEYS as J, dictionaryToFlatMap as O, flattenDevExtensionTranslations as Q, getFlattenedLocalization as W, isFlattenedTranslations as X, resolveDevExtensionLocale as Z } from "./i18n.es.js";
|
|
5
|
+
import { useExtensionServerContext as p } from "./hooks/useExtensionServerContext.es.js";
|
|
6
|
+
import { useExtensionServerState as m } from "./hooks/useExtensionServerState.es.js";
|
|
7
|
+
import { useIsomorphicLayoutEffect as A } from "./hooks/useIsomorphicLayoutEffect.es.js";
|
|
8
|
+
import { createConnectedAction as l, createFocusAction as v, createRefreshAction as d, createUnfocusAction as u, createUpdateAction as T } from "./state/actions/actions.es.js";
|
|
9
|
+
import { INITIAL_STATE as I } from "./state/reducers/constants.es.js";
|
|
10
|
+
import { extensionServerReducer as U } from "./state/reducers/extensionServerReducer.es.js";
|
|
11
|
+
import { Status as R } from "./types.es.js";
|
|
12
|
+
import { noop as _ } from "./utilities/noop.es.js";
|
|
13
|
+
import { replaceUpdated as h } from "./utilities/replaceUpdated.es.js";
|
|
14
|
+
import { set as V } from "./utilities/set.es.js";
|
|
15
|
+
import { assetToString as z } from "./utilities/assetToString.es.js";
|
|
16
|
+
import { isValidSurface as K } from "./utilities/isValidSurface.es.js";
|
|
17
|
+
import { isUIExtension as Y } from "./utilities/isUIExtension.es.js";
|
|
18
|
+
import { TRANSLATED_KEYS as j, flattenDevExtensionTranslations as k, getFlattenedLocalization as q, isFlattenedTranslations as w, resolveDevExtensionLocale as G } from "./i18n.es.js";
|
|
22
19
|
export {
|
|
23
20
|
a as AVAILABLE_SURFACES,
|
|
24
|
-
|
|
25
|
-
i as ExtensionServerClient,
|
|
21
|
+
s as ExtensionServerClient,
|
|
26
22
|
r as ExtensionServerProvider,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
E as useExtensionServerContext,
|
|
51
|
-
A as useExtensionServerEvent,
|
|
52
|
-
u as useExtensionServerState,
|
|
53
|
-
d as useIsomorphicLayoutEffect
|
|
23
|
+
I as INITIAL_STATE,
|
|
24
|
+
R as Status,
|
|
25
|
+
j as TRANSLATED_KEYS,
|
|
26
|
+
z as assetToString,
|
|
27
|
+
l as createConnectedAction,
|
|
28
|
+
v as createFocusAction,
|
|
29
|
+
d as createRefreshAction,
|
|
30
|
+
u as createUnfocusAction,
|
|
31
|
+
T as createUpdateAction,
|
|
32
|
+
n as extensionServerContext,
|
|
33
|
+
U as extensionServerReducer,
|
|
34
|
+
k as flattenDevExtensionTranslations,
|
|
35
|
+
q as getFlattenedLocalization,
|
|
36
|
+
w as isFlattenedTranslations,
|
|
37
|
+
Y as isUIExtension,
|
|
38
|
+
K as isValidSurface,
|
|
39
|
+
_ as noop,
|
|
40
|
+
h as replaceUpdated,
|
|
41
|
+
G as resolveDevExtensionLocale,
|
|
42
|
+
V as set,
|
|
43
|
+
p as useExtensionServerContext,
|
|
44
|
+
m as useExtensionServerState,
|
|
45
|
+
A as useIsomorphicLayoutEffect
|
|
54
46
|
};
|
|
@@ -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.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.Success="success",e))(t||{});exports.Status=t;
|
package/dist/types.d.ts
CHANGED
|
@@ -73,14 +73,14 @@ declare global {
|
|
|
73
73
|
export type DeepPartial<T> = {
|
|
74
74
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
interface ResourceURL {
|
|
77
77
|
url: string;
|
|
78
78
|
}
|
|
79
79
|
export interface Asset extends ResourceURL {
|
|
80
80
|
name: string;
|
|
81
81
|
lastUpdated: number;
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
interface Metafield {
|
|
84
84
|
namespace: string;
|
|
85
85
|
key: string;
|
|
86
86
|
}
|
|
@@ -93,8 +93,11 @@ export interface ExtensionPoint {
|
|
|
93
93
|
localization?: FlattenedLocalization | Localization | null;
|
|
94
94
|
name: string;
|
|
95
95
|
description?: string;
|
|
96
|
+
assets?: {
|
|
97
|
+
[name: string]: Asset;
|
|
98
|
+
};
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
type ExtensionPoints = string[] | ExtensionPoint[] | null;
|
|
98
101
|
interface CollectBuyerConsentCapabilities {
|
|
99
102
|
smsMarketing: boolean;
|
|
100
103
|
customerPrivacy: boolean;
|
|
@@ -149,7 +152,6 @@ export interface ExtensionPayload {
|
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
154
|
export declare enum Status {
|
|
152
|
-
Error = "error",
|
|
153
155
|
Success = "success"
|
|
154
156
|
}
|
|
155
157
|
export interface App {
|
package/dist/types.es.js
CHANGED
|
@@ -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,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/ui-extensions-server-kit",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Shopify/cli.git",
|
|
9
|
+
"directory": "packages/ui-extensions-server-kit"
|
|
10
|
+
},
|
|
6
11
|
"exports": {
|
|
7
12
|
"./package.json": "./package.json",
|
|
8
13
|
".": {
|
|
@@ -40,15 +45,12 @@
|
|
|
40
45
|
"devDependencies": {
|
|
41
46
|
"@shopify/react-testing": "^3.0.0",
|
|
42
47
|
"@shopify/ui-extensions-test-utils": "3.26.0",
|
|
43
|
-
"@types/node": "18.19.3",
|
|
44
48
|
"@types/react": "17.0.2",
|
|
45
49
|
"@vitejs/plugin-react-refresh": "^1.3.6",
|
|
46
|
-
"jest-websocket-mock": "^2.4.0",
|
|
47
50
|
"jsdom": "^20.0.3",
|
|
48
51
|
"react": "^17.0.2",
|
|
49
|
-
"typescript": "5.2.2",
|
|
50
52
|
"vi-fetch": "^0.8.0",
|
|
51
|
-
"vite": "
|
|
53
|
+
"vite": "6.3.5"
|
|
52
54
|
},
|
|
53
55
|
"peerDependencies": {
|
|
54
56
|
"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"
|