Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ttf-api

Package Overview
Dependencies
Maintainers
0
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ttf-api - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

dist/index.js

@@ -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.send(JSON.stringify({sessionId:o})),s.onopen=()=>{console.log("ttf ws open")},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 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})()));

@@ -54,5 +54,5 @@ import { createClient } from "./client";

// initial message to start the session
ws.send(JSON.stringify({ sessionId }));
ws.onopen = () => {
console.log("ttf ws open");
ws.send(JSON.stringify({ sessionId }));
};

@@ -59,0 +59,0 @@ ws.onclose = () => {

{
"name": "ttf-api",
"version": "0.2.2",
"version": "0.2.3",
"description": "The TrueToForm API SDK",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc