@homekynd/hk-embed-sdk 0.1.0 → 0.1.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 v=Object.defineProperty,D=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var w=(n,e,t)=>e in n?v(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,b=(n,e)=>{for(var t in e||(e={}))P.call(e,t)&&w(n,t,e[t]);if(M)for(var t of M(e))T.call(e,t)&&w(n,t,e[t]);return n},I=(n,e)=>D(n,L(e));var h=(n,e,t)=>w(n,typeof e!="symbol"?e+"":e,t);var y=(n,e,t)=>new Promise((r,o)=>{var s=a=>{try{c(t.next(a))}catch(l){o(l)}},f=a=>{try{c(t.throw(a))}catch(l){o(l)}},c=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,f);c((t=t.apply(n,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),U="https://app.homekynd.com";function O(n,e){return y(this,null,function*(){try{const t=yield fetch(`${U}/api/v1/company/generate-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_secret:n,id:e})}),r=yield t.json();if(t.ok)return r.token;console.error("Error fetching token: please confirm your API Secret and Client ID",r)}catch(t){console.error("Fetch error:",t)}})}const N={designTool:"/company",configurator:"/configurator"},u="https://app.homekynd.com",_="https://hk-socket-987653813850.us-central1.run.app";class m{static setDeviceId(e){this.deviceId=e}static getDeviceId(){return this.deviceId}}h(m,"deviceId");class R{constructor(e){h(this,"container");h(this,"iframe");h(this,"currentToken");h(this,"created",!1);h(this,"screenMode","design-tool");const{container:t}=e;if(!t)throw new Error("Container element is required");this.container=t,this.create(e)}create(e){return y(this,null,function*(){if(this.created)return;const{clientId:t,apiKey:r,path:o="designTool",width:s="100%",height:f="100%",enablePathSync:c=!0}=e;o==="configurator"?this.screenMode="configurator":this.screenMode="design-tool";const a=new URL(window.location.href),g=a.searchParams.get("ifpath")||N[o],k=u.endsWith("/")?u:u+"/",S=g.startsWith("/")?g.substring(1):g,E=new URL(S,k),p=yield O(r,t);this.currentToken=p,p&&E.searchParams.set("token",p);const d=document.createElement("iframe");return d.src=E.toString(),d.style.border="0",d.style.width=isNaN(Number(s))?s:`${s}px`,d.style.height=isNaN(Number(f))?f:`${f}px`,this.iframe=d,d.onload=()=>{this.currentToken&&this.sendMessage({type:"SET_TOKEN",token:this.currentToken})},this.container.innerHTML="",this.container.appendChild(d),c&&(a.searchParams.set("ifpath",g),window.history.replaceState({},"",a.toString())),this.setupMessageHandling(),this.created=!0,{sendMessage:this.sendMessage.bind(this),onMessage:this.onMessage.bind(this)}})}setupMessageHandling(){window.addEventListener("message",e=>{var t;switch((t=e.data)==null?void 0:t.type){case"ROUTE_CHANGE":this.onRouteChange(e.data.path);break;case"SET_DEVICE_ID":m.setDeviceId(e.data.deviceId);break;case"ADD_MODEL":this.addModel(e.data.modelId);break}})}onRouteChange(e){this.inputParentRoute(e),this.inputIframeRoute(e)}inputParentRoute(e){const t=new URL(window.location.href);t.searchParams.set("ifpath",e),window.history.replaceState({},"",t.toString())}inputIframeRoute(e){if(!this.iframe)return;const t=new URL(this.iframe.src),r=u.endsWith("/")?u:u+"/",o=e.startsWith("/")?e.substring(1):e,s=new URL(o,r);t.pathname!==s.pathname&&(this.iframe.src=s.toString())}sendMessage(e){var t;if((t=this.iframe)!=null&&t.contentWindow){const r=new URL(u).origin;this.iframe.contentWindow.postMessage(e,r)}}onMessage(e){window.addEventListener("message",t=>{e(t.data)})}addModel(e){fetch(`${_}/api/${this.screenMode}/addmodel`,{method:"POST",body:JSON.stringify({modelData:{modelId:e},deviceId:m.getDeviceId()})})}}const C=n=>{const e=i.useRef(null),t=i.useRef(null),[r,o]=i.useState(!1),s=i.useMemo(()=>n,[n.clientId,n.apiKey,n.path,n.width,n.height,n.enablePathSync]);return i.useEffect(()=>{o(!0)},[]),(typeof window!="undefined"?i.useLayoutEffect:i.useEffect)(()=>{if(!(!r||typeof window=="undefined")){if(e.current&&!t.current)try{t.current=new R(I(b({},s),{container:e.current}))}catch(c){console.error("Error creating HKEmbed:",c)}return()=>{t.current&&(t.current=null)}}},[s,r]),i.createElement("div",{ref:e,style:n.style})},H=n=>{try{return window.postMessage({type:"ADD_MODEL",modelId:n}),{success:!0,message:"Model added"}}catch(e){return console.error(e),{success:!1,message:e instanceof Error?e.message:"An unknown error occurred"}}},K=()=>m.getDeviceId();exports.HKEmbed=R;exports.HKReactEmbed=C;exports.addModel=H;exports.getDeviceId=K;
1
+ "use strict";var v=Object.defineProperty,D=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var w=(n,e,t)=>e in n?v(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,b=(n,e)=>{for(var t in e||(e={}))P.call(e,t)&&w(n,t,e[t]);if(M)for(var t of M(e))T.call(e,t)&&w(n,t,e[t]);return n},I=(n,e)=>D(n,L(e));var h=(n,e,t)=>w(n,typeof e!="symbol"?e+"":e,t);var y=(n,e,t)=>new Promise((r,o)=>{var s=a=>{try{c(t.next(a))}catch(l){o(l)}},f=a=>{try{c(t.throw(a))}catch(l){o(l)}},c=a=>a.done?r(a.value):Promise.resolve(a.value).then(s,f);c((t=t.apply(n,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),U="https://app.homekynd.com";function O(n,e){return y(this,null,function*(){try{const t=yield fetch(`${U}/api/v1/company/generate-token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({api_secret:n,id:e})}),r=yield t.json();if(t.ok)return r.token;console.error("Error fetching token: please confirm your API Secret and Client ID",r)}catch(t){console.error("Fetch error:",t)}})}const N={designTool:"/company",configurator:"/configurator"};class m{static setDeviceId(e){this.deviceId=e}static getDeviceId(){return this.deviceId}}h(m,"deviceId");const u="https://app.homekynd.com",_="https://hk-socket-987653813850.us-central1.run.app";class R{constructor(e){h(this,"container");h(this,"iframe");h(this,"currentToken");h(this,"created",!1);h(this,"screenMode","design-tool");const{container:t}=e;if(!t)throw new Error("Container element is required");this.container=t,this.create(e)}create(e){return y(this,null,function*(){if(this.created)return;const{clientId:t,apiKey:r,path:o="designTool",width:s="100%",height:f="100%",enablePathSync:c=!0}=e;o==="configurator"?this.screenMode="configurator":this.screenMode="design-tool";const a=new URL(window.location.href),g=a.searchParams.get("ifpath")||N[o],k=u.endsWith("/")?u:u+"/",S=g.startsWith("/")?g.substring(1):g,E=new URL(S,k),p=yield O(r,t);this.currentToken=p,p&&E.searchParams.set("token",p);const d=document.createElement("iframe");return d.src=E.toString(),d.style.border="0",d.style.width=isNaN(Number(s))?s:`${s}px`,d.style.height=isNaN(Number(f))?f:`${f}px`,this.iframe=d,d.onload=()=>{this.currentToken&&this.sendMessage({type:"SET_TOKEN",token:this.currentToken})},this.container.innerHTML="",this.container.appendChild(d),c&&(a.searchParams.set("ifpath",g),window.history.replaceState({},"",a.toString())),this.setupMessageHandling(),this.created=!0,{sendMessage:this.sendMessage.bind(this),onMessage:this.onMessage.bind(this)}})}setupMessageHandling(){window.addEventListener("message",e=>{var t;switch((t=e.data)==null?void 0:t.type){case"ROUTE_CHANGE":this.onRouteChange(e.data.path);break;case"SET_DEVICE_ID":m.setDeviceId(e.data.deviceId);break;case"ADD_MODEL":this.addModel(e.data.modelId);break}})}onRouteChange(e){this.inputParentRoute(e),this.inputIframeRoute(e)}inputParentRoute(e){const t=new URL(window.location.href);t.searchParams.set("ifpath",e),window.history.replaceState({},"",t.toString())}inputIframeRoute(e){if(!this.iframe)return;const t=new URL(this.iframe.src),r=u.endsWith("/")?u:u+"/",o=e.startsWith("/")?e.substring(1):e,s=new URL(o,r);t.pathname!==s.pathname&&(this.iframe.src=s.toString())}sendMessage(e){var t;if((t=this.iframe)!=null&&t.contentWindow){const r=new URL(u).origin;this.iframe.contentWindow.postMessage(e,r)}}onMessage(e){window.addEventListener("message",t=>{e(t.data)})}addModel(e){fetch(`${_}/api/${this.screenMode}/addmodel`,{method:"POST",body:JSON.stringify({modelData:{modelId:e},deviceId:m.getDeviceId()})})}}const C=n=>{const e=i.useRef(null),t=i.useRef(null),[r,o]=i.useState(!1),s=i.useMemo(()=>n,[n.clientId,n.apiKey,n.path,n.width,n.height,n.enablePathSync]);return i.useEffect(()=>{o(!0)},[]),(typeof window!="undefined"?i.useLayoutEffect:i.useEffect)(()=>{if(!(!r||typeof window=="undefined")){if(e.current&&!t.current)try{t.current=new R(I(b({},s),{container:e.current}))}catch(c){console.error("Error creating HKEmbed:",c)}return()=>{t.current&&(t.current=null)}}},[s,r]),i.createElement("div",{ref:e,style:n.style})},H=n=>{try{return window.postMessage({type:"ADD_MODEL",modelId:n}),{success:!0,message:"Model added"}}catch(e){return console.error(e),{success:!1,message:e instanceof Error?e.message:"An unknown error occurred"}}},K=()=>m.getDeviceId();exports.HKEmbed=R;exports.HKReactEmbed=C;exports.addModel=H;exports.getDeviceId=K;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { default as default_2 } from 'react';
1
+ import { JSX as JSX_2 } from 'react/jsx-runtime';
2
2
 
3
3
  /**
4
4
  *
@@ -62,6 +62,6 @@ export declare type HKPath = Record<HKPathKey, string>;
62
62
 
63
63
  export declare type HKPathKey = "designTool" | "configurator";
64
64
 
65
- export declare const HKReactEmbed: default_2.FC<HKEmbedConfigReact>;
65
+ export declare const HKReactEmbed: (options: HKEmbedConfigReact) => JSX_2.Element;
66
66
 
67
67
  export { }
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ function C(n, e) {
53
53
  const A = {
54
54
  designTool: "/company",
55
55
  configurator: "/configurator"
56
- }, h = "https://app.homekynd.com", H = "https://hk-socket-987653813850.us-central1.run.app";
56
+ };
57
57
  class g {
58
58
  static setDeviceId(e) {
59
59
  this.deviceId = e;
@@ -63,6 +63,7 @@ class g {
63
63
  }
64
64
  }
65
65
  d(g, "deviceId");
66
+ const h = "https://app.homekynd.com", H = "https://hk-socket-987653813850.us-central1.run.app";
66
67
  class K {
67
68
  constructor(e) {
68
69
  d(this, "container");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@homekynd/hk-embed-sdk",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",