Comparing version 0.2.3 to 0.2.4
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.truetoformApi=t():e.truetoformApi=t()}(this,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>o});const o=e=>{const t=(e=>{const t={"Content-Type":"application/json","X-TTF-API-KEY":e},o=async(e,o,r=null)=>{const s={method:e,headers:t,body:r?JSON.stringify(r):null,credentials:"include"},n=await fetch(`https://api.truetoform.online/v1/${o}`,s);if(!n.ok){const e=await n.json();throw new Error(`Error ${n.status}: ${e.message}`)}return 204===n.status?null:await n.json()};return{get:e=>o("GET",e),post:(e,t)=>o("POST",e,t),put:(e,t)=>o("PUT",e,t),delete:e=>o("DELETE",e)}})(e);return{getGarment:e=>{if(!e)throw new Error("garment ID is required");return t.get(`garments/${e}`)},getSurvey:e=>{if(!e)throw new Error("survey ID is required");return t.get(`surveys/${e}`)},getScan:e=>{if(!e)throw new Error("scan ID is required");return t.get(`scans/${e}`)},getPrediction:e=>{if(!e)throw new Error("prediction ID is required");return t.get(`predictions/${e}`)},createSession:()=>t.post("sessions"),createScanPrediction:(e,o)=>t.post("predictions/scan",{sessionId:o,garmentId:e}),createSurveyPrediction:(e,o)=>t.post("predictions/survey",{...o,garmentId:e}),deleteCookies:()=>Promise.all([t.delete("surveys"),t.delete("scans")]),getRealtimeSession:o=>{const r=encodeURIComponent(window.location.href),s=new WebSocket(`wss://api.truetoform.online?apiKey=${e}&referer=${r}`);s.onopen=()=>{console.log("ttf ws open"),s.send(JSON.stringify({sessionId:o}))},s.onclose=()=>{console.log("ttf ws closed")},s.onmessage=e=>{const t=JSON.parse(e.data);console.log("ttf ws message",t)};return{onProgressChange:e=>{s.onmessage=t=>{const o=JSON.parse(t.data);"SESSION_DATA"===o.type&&e(o.payload?.progress)}},onSessionReady:e=>{s.onmessage=async r=>{if("SESSION_DATA"===JSON.parse(r.data).type)try{const r=await(e=>t.get(`sessions/${e}/status`))(o),{actions:n,session_scan_status:a}=r;"FAILED"===a&&s.close();const i=n?.[0]?.usable_now;i&&(e(o),s.close())}catch(e){console.log("error calling getSessionStatus",e)}}},onFailure:e=>{s.onmessage=t=>{const o=JSON.parse(t.data);"ERROR"===o.type&&(console.log("ttf ws error",o),e(o))},s.onerror=t=>{console.log("ttf ws error",t),e({type:"ERROR",message:"WebSocket error"})}}}}}};return t})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.truetoformApi=t():e.truetoformApi=t()}(this,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var s in o)e.o(o,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:o[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>o});const o=e=>{const t=(e=>{const t={"Content-Type":"application/json","X-TTF-API-KEY":e},o=async(e,o,s=null)=>{const r={method:e,headers:t,body:s?JSON.stringify(s):null,credentials:"include"},n=await fetch(`https://api.truetoform.online/v1/${o}`,r);if(!n.ok){const e=await n.json();throw new Error(`Error ${n.status}: ${e.message}`)}return 204===n.status?null:await n.json()};return{get:e=>o("GET",e),post:(e,t)=>o("POST",e,t),put:(e,t)=>o("PUT",e,t),delete:e=>o("DELETE",e)}})(e);return{getGarment:e=>{if(!e)throw new Error("garment ID is required");return t.get(`garments/${e}`)},getSurvey:e=>{if(!e)throw new Error("survey ID is required");return t.get(`surveys/${e}`)},getScan:e=>{if(!e)throw new Error("scan ID is required");return t.get(`scans/${e}`)},getPrediction:e=>{if(!e)throw new Error("prediction ID is required");return t.get(`predictions/${e}`)},createSession:()=>t.post("sessions"),createScanPrediction:(e,o)=>t.post("predictions/scan",{sessionId:o,garmentId:e}),createSurveyPrediction:(e,o)=>t.post("predictions/survey",{...o,garmentId:e}),deleteCookies:()=>Promise.all([t.delete("surveys"),t.delete("scans")]),getRealtimeSession:o=>{const s=encodeURIComponent(window.location.href),r=new WebSocket(`wss://localhost:3000?apiKey=${e}&referer=${s}`);r.onopen=()=>{console.log("ttf ws open"),r.send(JSON.stringify({sessionId:o}))},r.onclose=()=>{console.log("ttf ws closed")},r.onmessage=e=>{const t=JSON.parse(e.data);console.log("ttf ws message",t)};return{onProgressChange:e=>{r.onmessage=t=>{const o=JSON.parse(t.data);"SESSION_DATA"===o.type&&e(o.payload?.progress)}},onSessionReady:e=>{r.onmessage=async s=>{if("SESSION_DATA"===JSON.parse(s.data).type)try{const s=await(e=>t.get(`sessions/${e}/status`))(o),{actions:n,session_scan_status:a}=s;"FAILED"===a&&r.close();const i=n?.[0]?.usable_now;i&&(e(o),r.close())}catch(e){console.log("error calling getSessionStatus",e)}}},onFailure:e=>{r.onmessage=t=>{const o=JSON.parse(t.data);"ERROR"===o.type&&(console.log("ttf ws error",o),e(o))},r.onerror=t=>{console.log("ttf ws error",t),e({type:"ERROR",message:"WebSocket error"})}}}}}};return t})())); |
@@ -51,3 +51,3 @@ import { createClient } from "./client"; | ||
const ws = new WebSocket( | ||
`wss://api.truetoform.online?apiKey=${apiKey}&referer=${referer}` | ||
`wss://localhost:3000?apiKey=${apiKey}&referer=${referer}` | ||
); | ||
@@ -54,0 +54,0 @@ // initial message to start the session |
{ | ||
"name": "ttf-api", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "The TrueToForm API SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16325