@smart-cloud/wpsuite-core 2.0.0 → 2.0.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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(t&&(e=t(t=0)),e);var h=(t,e)=>{for(var n in e)d(t,n,{get:e[n],enumerable:!0})},I=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of O(e))!D.call(t,i)&&i!==n&&d(t,i,{get:()=>e[i],enumerable:!(r=X(e,i))||r.enumerable});return t};var Y=t=>I(d({},"__esModule",{value:!0}),t);function s(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return Uint8Array.from(atob(e),n=>n.charCodeAt(0))}var f,y=g(()=>{"use strict";f=(t,e)=>{let r=Uint8Array.from(atob(t),i=>i.charCodeAt(0)).map((i,a)=>i^e+a&255);return new TextDecoder().decode(r)}});var _,P,v=g(()=>{"use strict";y();_=f("x8fO2eD///yro8Pr9vmVxdby9MzU7Jnf9cSZxfSc1MLq2NjbxOTq3PCD2w==",146),P=f("xafW79Hk4tr1//jc/erTzuDa1uHt6MPx2M+U4uHO7/7W0uzH7v/MzYrL6Q==",146)});var R={};h(R,{getConfig:()=>z});function S(t){try{return new URL(t.includes("://")?t:`http://${t}`).hostname.toLowerCase()}catch{return t.replace(/\/+$/,"").toLowerCase()}}function M(t){let e=S(t);return e.startsWith("www.")?e.slice(4):e}function C(t){let e=S(t);if(N.test(e)||V.test(e)||e==="localhost")return!0;let n=(0,A.parse)(e,{allowPrivateDomains:!0});return!!(!n.domain||!n.publicSuffix||G.includes(n.publicSuffix))}function H(t){let e=S(t);return C(e)||E.test(e)?!0:e.split(".").some(n=>E.test(n))}function J(t){return C(t)||H(t)}function Z(t,e){return e?M(t)===e:!1}function j(t,e){return J(t)?{free:!0,covered:!0}:{free:!1,covered:Z(t,e)}}var u,A,x,W,b,E,G,N,V,z,T=g(()=>{"use strict";u=require("jose");v();y();A=require("tldts");typeof WpSuite<"u"?b=WpSuite.siteSettings:b={};E=/\b(dev|test|testing|staging|stage|qa|uat|preview|demo|sandbox|preprod|beta|canary)\b/i,G=["localhost","local","test","invalid","example","lan","internal"],N=/^(127\.)|^(10\.)|^(192\.168\.)|^(172\.(1[6-9]|2\d|3[0-1])\.)/,V=/^(::1$)|(^fc00:)|(^fd)/i;z=async()=>{let t=null;if(b.subscriber){let n=await(0,u.importJWK)({kty:"EC",x,y:W,crv:"P-256"},"ES256"),r=new Date().getFullYear(),i=Math.floor((Date.now()-new Date(r,0,1).getTime())/(1e3*60*60*24*7)),a=await fetch(WpSuite.uploadUrl+"lic.jws?t="+WpSuite.siteSettings.lastUpdate+"&y="+r+"&w="+i).then(o=>o.ok?o.text():null).catch(()=>null);if(a)try{let o=location.hostname.split(":")[0],{payload:l}=await(0,u.jwtVerify)(a,n,{algorithms:["ES256"]}),m=j(o,l.domain);if(!m.free&&!m.covered)throw new Error("Invalid domain in JWT");let w=l.key.split(":"),k=s(w[0]),U=s(w[1]),p=(await fetch(WpSuite.uploadUrl+"config.enc?t="+WpSuite.siteSettings.lastUpdate).then(c=>c.ok?c.text():null).catch(()=>null))?.split(":");if(p?.length===2){let c=s(p[0]),L=s(p[1]),B=await crypto.subtle.importKey("raw",k,{name:"AES-GCM"},!1,["decrypt"]),K=await crypto.subtle.decrypt({name:"AES-GCM",iv:U},B,new Uint8Array([...c,...L]));t=JSON.parse(new TextDecoder().decode(K)),t.subscriptionType=l.subscriptionType}}catch(o){console.error(o.message)}}return t??null};x=_;W=P});var tt={};h(tt,{TEXT_DOMAIN:()=>q,getConfig:()=>Q,getPlugin:()=>$,getWpSuite:()=>F});module.exports=Y(tt);function F(){return globalThis.WpSuite}function $(t){return globalThis.WpSuite?.plugins[t]}var q="hub-for-wpsuiteio",Q=async t=>{let n=await(await Promise.resolve().then(()=>(T(),R))).getConfig();return n&&(n={...n[t],subscriptionType:n.subscriptionType}),n};0&&(module.exports={TEXT_DOMAIN,getConfig,getPlugin,getWpSuite});
1
+ "use strict";var g=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var y=(t,e)=>()=>(t&&(e=t(t=0)),e);var P=(t,e)=>{for(var n in e)g(t,n,{get:e[n],enumerable:!0})},Y=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of I(e))!M.call(t,i)&&i!==n&&g(t,i,{get:()=>e[i],enumerable:!(r=X(e,i))||r.enumerable});return t};var G=t=>Y(g({},"__esModule",{value:!0}),t);function c(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return Uint8Array.from(atob(e),n=>n.charCodeAt(0))}var m,w=y(()=>{"use strict";m=(t,e)=>{let r=Uint8Array.from(atob(t),i=>i.charCodeAt(0)).map((i,s)=>i^e+s&255);return new TextDecoder().decode(r)}});var h,_,x=y(()=>{"use strict";w();h=m("1NbZyPPu4O24stT65ei69OXDw/3n3abuxvWu9Met+9P5yc/K1/X1zeOSzA==",129),_=m("1rbB/sL1/cvm7u/N7vv8/9Pr4dDe2fzA6/6j09L/wO/Fw/vW/e7T3Jna/g==",129)});var T={};P(T,{getConfig:()=>Q});function v(t){try{return new URL(t.includes("://")?t:`http://${t}`).hostname.toLowerCase()}catch{return t.replace(/\/+$/,"").toLowerCase()}}function Z(t){let e=v(t);return e.startsWith("www.")?e.slice(4):e}function C(t){let e=v(t);if(J.test(e)||$.test(e)||e==="localhost")return!0;let n=(0,k.parse)(e,{allowPrivateDomains:!0});return!!(!n.domain||!n.publicSuffix||H.includes(n.publicSuffix))}function j(t){let e=v(t);return C(e)||A.test(e)?!0:e.split(".").some(n=>A.test(n))}function z(t){return C(t)||j(t)}function F(t,e){return e?Z(t)===e:!1}function q(t,e){return z(t)?{free:!0,covered:!0}:{free:!1,covered:F(t,e)}}var p,k,W,R,S,A,H,J,$,Q,L=y(()=>{"use strict";p=require("jose");x();w();k=require("tldts");typeof WpSuite<"u"?S=WpSuite.siteSettings:S={};A=/\b(dev|test|testing|staging|stage|qa|uat|preview|demo|sandbox|preprod|beta|canary)\b/i,H=["localhost","local","test","invalid","example","lan","internal"],J=/^(127\.)|^(10\.)|^(192\.168\.)|^(172\.(1[6-9]|2\d|3[0-1])\.)/,$=/^(::1$)|(^fc00:)|(^fd)/i;Q=async()=>{let t=null;if(S.subscriber){let n=await(0,p.importJWK)({kty:"EC",x:W,y:R,crv:"P-256"},"ES256"),r=new Date().getFullYear(),i=Math.floor((Date.now()-new Date(r,0,1).getTime())/(1e3*60*60*24*7)),s=await fetch(WpSuite.uploadUrl+"lic.jws?t="+WpSuite.siteSettings.lastUpdate+"&y="+r+"&w="+i).then(o=>o.ok?o.text():null).catch(()=>null);if(s)try{let o=location.hostname.split(":")[0],{payload:a}=await(0,p.jwtVerify)(s,n,{algorithms:["ES256"]}),u=q(o,a.domain);if(!u.free&&!u.covered)throw new Error("Invalid domain in JWT");let l=a.key.split(":"),B=c(l[0]),U=c(l[1]),f=(await fetch(WpSuite.uploadUrl+"config.enc?t="+WpSuite.siteSettings.lastUpdate).then(d=>d.ok?d.text():null).catch(()=>null))?.split(":");if(f?.length===2){let d=c(f[0]),K=c(f[1]),D=await crypto.subtle.importKey("raw",B,{name:"AES-GCM"},!1,["decrypt"]),O=await crypto.subtle.decrypt({name:"AES-GCM",iv:U},D,new Uint8Array([...d,...K]));t=JSON.parse(new TextDecoder().decode(O)),t.subscriptionType=a.subscriptionType}}catch(o){console.error(o.message)}}return t??null};W=h;R=_});var rt={};P(rt,{TEXT_DOMAIN:()=>nt,attachDefaultPluginRuntime:()=>E,getConfig:()=>it,getPlugin:()=>et,getWpSuite:()=>tt});module.exports=G(rt);function b(t,e){return`wpsuite:${t}:${e}`}function N(t,e=8e3){return()=>new Promise(n=>{if(t.status==="available")return n("available");if(t.status==="error")return n("error");!t.status||t.status;let r=b(t.key,"ready"),i=b(t.key,"error"),s=()=>u("available"),o=()=>u("error"),a,u=l=>{window.removeEventListener(r,s),window.removeEventListener(i,o),a!==void 0&&window.clearTimeout(a),n(l)};window.addEventListener(r,s,{once:!0}),window.addEventListener(i,o,{once:!0}),a=window.setTimeout(()=>u("unavailable"),e)})}function V(t){return e=>{window.addEventListener(b(t,"ready"),()=>e(),{once:!0})}}function E(t,e){let n=e?.timeoutMs??8e3;return t.availability??=N(t,n),t.onReady??=V(t.key),t}function tt(){return globalThis.WpSuite}function et(t){return globalThis.WpSuite?.plugins[t]}var nt="hub-for-wpsuiteio",it=async t=>{let n=await(await Promise.resolve().then(()=>(L(),T))).getConfig();return n&&(n={...n[t],subscriptionType:n.subscriptionType}),n};0&&(module.exports={TEXT_DOMAIN,attachDefaultPluginRuntime,getConfig,getPlugin,getWpSuite});
package/dist/index.d.cts CHANGED
@@ -1,3 +1,8 @@
1
+ /** Attaches the default runtime functions to a plugin object */
2
+ declare function attachDefaultPluginRuntime<T extends WpSuitePluginBase>(plugin: T, opts?: {
3
+ timeoutMs?: number;
4
+ }): T;
5
+
1
6
  declare global {
2
7
  var WpSuite: WpSuiteGlobal | undefined;
3
8
  }
@@ -32,6 +37,7 @@ interface WpSuiteGlobal {
32
37
  }
33
38
  declare function getWpSuite(): WpSuiteGlobal | undefined;
34
39
  declare function getPlugin<K extends string>(key: K): WpSuitePluginBase | undefined;
40
+
35
41
  declare const TEXT_DOMAIN = "hub-for-wpsuiteio";
36
42
  interface SiteSettings {
37
43
  accountId?: string;
@@ -43,4 +49,4 @@ interface SiteSettings {
43
49
  type SubscriptionType = "PROFESSIONAL" | "AGENCY";
44
50
  declare const getConfig: (plugin: string) => Promise<Record<string, unknown> | null>;
45
51
 
46
- export { type PluginAvailability, type PluginStatus, type SiteSettings, type SubscriptionType, TEXT_DOMAIN, type WpSuiteEvents, type WpSuiteGlobal, type WpSuitePluginBase, type WpSuitePluginRegistry, type WpSuiteView, getConfig, getPlugin, getWpSuite };
52
+ export { type PluginAvailability, type PluginStatus, type SiteSettings, type SubscriptionType, TEXT_DOMAIN, type WpSuiteEvents, type WpSuiteGlobal, type WpSuitePluginBase, type WpSuitePluginRegistry, type WpSuiteView, attachDefaultPluginRuntime, getConfig, getPlugin, getWpSuite };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /** Attaches the default runtime functions to a plugin object */
2
+ declare function attachDefaultPluginRuntime<T extends WpSuitePluginBase>(plugin: T, opts?: {
3
+ timeoutMs?: number;
4
+ }): T;
5
+
1
6
  declare global {
2
7
  var WpSuite: WpSuiteGlobal | undefined;
3
8
  }
@@ -32,6 +37,7 @@ interface WpSuiteGlobal {
32
37
  }
33
38
  declare function getWpSuite(): WpSuiteGlobal | undefined;
34
39
  declare function getPlugin<K extends string>(key: K): WpSuitePluginBase | undefined;
40
+
35
41
  declare const TEXT_DOMAIN = "hub-for-wpsuiteio";
36
42
  interface SiteSettings {
37
43
  accountId?: string;
@@ -43,4 +49,4 @@ interface SiteSettings {
43
49
  type SubscriptionType = "PROFESSIONAL" | "AGENCY";
44
50
  declare const getConfig: (plugin: string) => Promise<Record<string, unknown> | null>;
45
51
 
46
- export { type PluginAvailability, type PluginStatus, type SiteSettings, type SubscriptionType, TEXT_DOMAIN, type WpSuiteEvents, type WpSuiteGlobal, type WpSuitePluginBase, type WpSuitePluginRegistry, type WpSuiteView, getConfig, getPlugin, getWpSuite };
52
+ export { type PluginAvailability, type PluginStatus, type SiteSettings, type SubscriptionType, TEXT_DOMAIN, type WpSuiteEvents, type WpSuiteGlobal, type WpSuitePluginBase, type WpSuitePluginRegistry, type WpSuiteView, attachDefaultPluginRuntime, getConfig, getPlugin, getWpSuite };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var U=Object.defineProperty;var p=(t,e)=>()=>(t&&(e=t(t=0)),e);var L=(t,e)=>{for(var n in e)U(t,n,{get:e[n],enumerable:!0})};function o(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return Uint8Array.from(atob(e),n=>n.charCodeAt(0))}var d,g=p(()=>{"use strict";d=(t,e)=>{let s=Uint8Array.from(atob(t),r=>r.charCodeAt(0)).map((r,a)=>r^e+a&255);return new TextDecoder().decode(s)}});var m,w,h=p(()=>{"use strict";g();m=d("x8fO2eD///yro8Pr9vmVxdby9MzU7Jnf9cSZxfSc1MLq2NjbxOTq3PCD2w==",146),w=d("xafW79Hk4tr1//jc/erTzuDa1uHt6MPx2M+U4uHO7/7W0uzH7v/MzYrL6Q==",146)});var x={};L(x,{getConfig:()=>H});import{importJWK as B,jwtVerify as K}from"jose";import{parse as X}from"tldts";function y(t){try{return new URL(t.includes("://")?t:`http://${t}`).hostname.toLowerCase()}catch{return t.replace(/\/+$/,"").toLowerCase()}}function Y(t){let e=y(t);return e.startsWith("www.")?e.slice(4):e}function E(t){let e=y(t);if(D.test(e)||I.test(e)||e==="localhost")return!0;let n=X(e,{allowPrivateDomains:!0});return!!(!n.domain||!n.publicSuffix||O.includes(n.publicSuffix))}function G(t){let e=y(t);return E(e)||_.test(e)?!0:e.split(".").some(n=>_.test(n))}function N(t){return E(t)||G(t)}function V(t,e){return e?Y(t)===e:!1}function M(t,e){return N(t)?{free:!0,covered:!0}:{free:!1,covered:V(t,e)}}var P,v,f,_,O,D,I,H,W=p(()=>{"use strict";h();g();typeof WpSuite<"u"?f=WpSuite.siteSettings:f={};_=/\b(dev|test|testing|staging|stage|qa|uat|preview|demo|sandbox|preprod|beta|canary)\b/i,O=["localhost","local","test","invalid","example","lan","internal"],D=/^(127\.)|^(10\.)|^(192\.168\.)|^(172\.(1[6-9]|2\d|3[0-1])\.)/,I=/^(::1$)|(^fc00:)|(^fd)/i;H=async()=>{let t=null;if(f.subscriber){let n=await B({kty:"EC",x:P,y:v,crv:"P-256"},"ES256"),s=new Date().getFullYear(),r=Math.floor((Date.now()-new Date(s,0,1).getTime())/(1e3*60*60*24*7)),a=await fetch(WpSuite.uploadUrl+"lic.jws?t="+WpSuite.siteSettings.lastUpdate+"&y="+s+"&w="+r).then(i=>i.ok?i.text():null).catch(()=>null);if(a)try{let i=location.hostname.split(":")[0],{payload:u}=await K(a,n,{algorithms:["ES256"]}),b=M(i,u.domain);if(!b.free&&!b.covered)throw new Error("Invalid domain in JWT");let S=u.key.split(":"),A=o(S[0]),C=o(S[1]),l=(await fetch(WpSuite.uploadUrl+"config.enc?t="+WpSuite.siteSettings.lastUpdate).then(c=>c.ok?c.text():null).catch(()=>null))?.split(":");if(l?.length===2){let c=o(l[0]),R=o(l[1]),T=await crypto.subtle.importKey("raw",A,{name:"AES-GCM"},!1,["decrypt"]),k=await crypto.subtle.decrypt({name:"AES-GCM",iv:C},T,new Uint8Array([...c,...R]));t=JSON.parse(new TextDecoder().decode(k)),t.subscriptionType=u.subscriptionType}}catch(i){console.error(i.message)}}return t??null};P=m;v=w});function et(){return globalThis.WpSuite}function nt(t){return globalThis.WpSuite?.plugins[t]}var it="hub-for-wpsuiteio",rt=async t=>{let n=await(await Promise.resolve().then(()=>(W(),x))).getConfig();return n&&(n={...n[t],subscriptionType:n.subscriptionType}),n};export{it as TEXT_DOMAIN,rt as getConfig,nt as getPlugin,et as getWpSuite};
1
+ var B=Object.defineProperty;var f=(t,e)=>()=>(t&&(e=t(t=0)),e);var U=(t,e)=>{for(var n in e)B(t,n,{get:e[n],enumerable:!0})};function c(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return Uint8Array.from(atob(e),n=>n.charCodeAt(0))}var y,b=f(()=>{"use strict";y=(t,e)=>{let o=Uint8Array.from(atob(t),r=>r.charCodeAt(0)).map((r,s)=>r^e+s&255);return new TextDecoder().decode(o)}});var S,v,P=f(()=>{"use strict";b();S=y("1NbZyPPu4O24stT65ei69OXDw/3n3abuxvWu9Met+9P5yc/K1/X1zeOSzA==",129),v=y("1rbB/sL1/cvm7u/N7vv8/9Pr4dDe2fzA6/6j09L/wO/Fw/vW/e7T3Jna/g==",129)});var A={};U(A,{getConfig:()=>j});import{importJWK as X,jwtVerify as I}from"jose";import{parse as M}from"tldts";function w(t){try{return new URL(t.includes("://")?t:`http://${t}`).hostname.toLowerCase()}catch{return t.replace(/\/+$/,"").toLowerCase()}}function V(t){let e=w(t);return e.startsWith("www.")?e.slice(4):e}function x(t){let e=w(t);if(G.test(e)||N.test(e)||e==="localhost")return!0;let n=M(e,{allowPrivateDomains:!0});return!!(!n.domain||!n.publicSuffix||Y.includes(n.publicSuffix))}function H(t){let e=w(t);return x(e)||E.test(e)?!0:e.split(".").some(n=>E.test(n))}function J(t){return x(t)||H(t)}function $(t,e){return e?V(t)===e:!1}function Z(t,e){return J(t)?{free:!0,covered:!0}:{free:!1,covered:$(t,e)}}var h,_,m,E,Y,G,N,j,W=f(()=>{"use strict";P();b();typeof WpSuite<"u"?m=WpSuite.siteSettings:m={};E=/\b(dev|test|testing|staging|stage|qa|uat|preview|demo|sandbox|preprod|beta|canary)\b/i,Y=["localhost","local","test","invalid","example","lan","internal"],G=/^(127\.)|^(10\.)|^(192\.168\.)|^(172\.(1[6-9]|2\d|3[0-1])\.)/,N=/^(::1$)|(^fc00:)|(^fd)/i;j=async()=>{let t=null;if(m.subscriber){let n=await X({kty:"EC",x:h,y:_,crv:"P-256"},"ES256"),o=new Date().getFullYear(),r=Math.floor((Date.now()-new Date(o,0,1).getTime())/(1e3*60*60*24*7)),s=await fetch(WpSuite.uploadUrl+"lic.jws?t="+WpSuite.siteSettings.lastUpdate+"&y="+o+"&w="+r).then(i=>i.ok?i.text():null).catch(()=>null);if(s)try{let i=location.hostname.split(":")[0],{payload:a}=await I(s,n,{algorithms:["ES256"]}),u=Z(i,a.domain);if(!u.free&&!u.covered)throw new Error("Invalid domain in JWT");let l=a.key.split(":"),R=c(l[0]),k=c(l[1]),p=(await fetch(WpSuite.uploadUrl+"config.enc?t="+WpSuite.siteSettings.lastUpdate).then(d=>d.ok?d.text():null).catch(()=>null))?.split(":");if(p?.length===2){let d=c(p[0]),C=c(p[1]),T=await crypto.subtle.importKey("raw",R,{name:"AES-GCM"},!1,["decrypt"]),L=await crypto.subtle.decrypt({name:"AES-GCM",iv:k},T,new Uint8Array([...d,...C]));t=JSON.parse(new TextDecoder().decode(L)),t.subscriptionType=a.subscriptionType}}catch(i){console.error(i.message)}}return t??null};h=S;_=v});function g(t,e){return`wpsuite:${t}:${e}`}function K(t,e=8e3){return()=>new Promise(n=>{if(t.status==="available")return n("available");if(t.status==="error")return n("error");!t.status||t.status;let o=g(t.key,"ready"),r=g(t.key,"error"),s=()=>u("available"),i=()=>u("error"),a,u=l=>{window.removeEventListener(o,s),window.removeEventListener(r,i),a!==void 0&&window.clearTimeout(a),n(l)};window.addEventListener(o,s,{once:!0}),window.addEventListener(r,i,{once:!0}),a=window.setTimeout(()=>u("unavailable"),e)})}function D(t){return e=>{window.addEventListener(g(t,"ready"),()=>e(),{once:!0})}}function O(t,e){let n=e?.timeoutMs??8e3;return t.availability??=K(t,n),t.onReady??=D(t.key),t}function st(){return globalThis.WpSuite}function at(t){return globalThis.WpSuite?.plugins[t]}var ut="hub-for-wpsuiteio",ct=async t=>{let n=await(await Promise.resolve().then(()=>(W(),A))).getConfig();return n&&(n={...n[t],subscriptionType:n.subscriptionType}),n};export{ut as TEXT_DOMAIN,O as attachDefaultPluginRuntime,ct as getConfig,at as getPlugin,st as getWpSuite};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-cloud/wpsuite-core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "WP Suite Core package",
5
5
  "author": "Smart Cloud Solutions Inc.",
6
6
  "license": "MIT",