sizebay-core-sdk 1.10.1 → 1.10.2

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.
@@ -1,5 +1,5 @@
1
- import { TrackData, TrackResponse } from '../types';
2
1
  import { Config } from '../config';
2
+ import { TrackData, TrackResponse } from '../types';
3
3
  export declare class Tracker {
4
4
  private endpoint;
5
5
  constructor(config: Config);
@@ -13,7 +13,7 @@ const p = {
13
13
  }
14
14
  // Adicione outros serviços conforme necessário
15
15
  };
16
- class S {
16
+ class l {
17
17
  constructor(t) {
18
18
  const e = t.env || "development";
19
19
  this.serviceOverrides = t.services || {}, this.endpoints = {};
@@ -37,7 +37,7 @@ class S {
37
37
  return this.serviceOverrides[t] || {};
38
38
  }
39
39
  }
40
- class l {
40
+ class S {
41
41
  constructor(t) {
42
42
  this.endpoint = t.getEndpoint("tracker");
43
43
  }
@@ -59,7 +59,10 @@ class l {
59
59
  try {
60
60
  return await o.json();
61
61
  } catch {
62
- return { statusCode: o.status, message: "Empty body" };
62
+ return {
63
+ statusCode: 201,
64
+ message: "Event successfully created."
65
+ };
63
66
  }
64
67
  } catch (o) {
65
68
  throw o;
@@ -230,12 +233,12 @@ class u {
230
233
  }
231
234
  }
232
235
  const O = [
233
- l,
236
+ S,
234
237
  T,
235
238
  u
236
239
  ];
237
240
  function E(r = {}) {
238
- const t = new S(r), e = O.map((n) => new n(t)), s = {};
241
+ const t = new l(r), e = O.map((n) => new n(t)), s = {};
239
242
  return e.forEach((n) => {
240
243
  [
241
244
  ...Object.getOwnPropertyNames(n),
@@ -1 +1 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i["sizebay-core-sdk"]={}))})(this,(function(i){"use strict";const a={tracker:{production:"https://data-event-service.internalsizebay.com",development:"https://data-event-service-dev.internalsizebay.com"},aiImageService:{production:"https://ai-image-service.internalsizebay.com",development:"https://ai-image-service-dev.internalsizebay.com"},session:{production:"https://vfr-v3-production.sizebay.technology/api/me",development:"https://vfr-v3-staging.sizebay.eu/api/me"}};class l{constructor(t){const e=t.env||"development";this.serviceOverrides=t.services||{},this.endpoints={};for(const s in a)if(Object.prototype.hasOwnProperty.call(a,s)){const o=a[s][e];if(!o)continue;this.endpoints[s]=o}}getEndpoint(t){const e=this.endpoints[t];if(!e)throw new Error(`Endpoint for service '${t}' is not configured.`);return e}getServiceConfig(t){return this.serviceOverrides[t]||{}}}class u{constructor(t){this.endpoint=t.getEndpoint("tracker")}async track(t,e){const s={eventName:t,...e},n=new URL(`${this.endpoint}/events`);try{const o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok){const r=await o.text();throw new Error(`Request error: ${o.status} - ${r}`)}try{return await o.json()}catch{return{statusCode:o.status,message:"Empty body"}}}catch(o){throw o}}}class d extends Error{constructor(t,e){let s;try{const n=JSON.parse(e);s=(n==null?void 0:n.message)||e}catch{s=e}super(s),this.statusCode=t,this.details=e,Object.setPrototypeOf(this,d.prototype)}}async function p(c,t){let e;try{e=await fetch(c,t)}catch(n){throw new d(0,n.message)}const s=await e.text();if(!e.ok)throw new d(e.status,s);return JSON.parse(s)}class S{constructor(t){this.endpoint=t.getEndpoint("aiImageService")}appendQueryParams(t,e){Object.entries(e).forEach(([s,n])=>{n!=null&&t.searchParams.append(s,String(n))})}getSimilarProducts(t){const e=new URL(`${this.endpoint}/recommendations/similar`);return this.appendQueryParams(e,t),p(e.toString(),{method:"GET",headers:{"Content-Type":"application/json"}})}getComplementaryProducts(t){const e=new URL(`${this.endpoint}/recommendations/complementary`);return this.appendQueryParams(e,t),p(e.toString(),{method:"GET",headers:{"Content-Type":"application/json"}})}searchSimilarByImage(t){const e=`${this.endpoint}/image-search/similar`;return p(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}searchComplementaryByImage(t){const e=`${this.endpoint}/image-search/complementary`;return p(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}}class T{constructor(t){this.sid=null,this.sessionId=null;const e=t.getEndpoint("session");this.sessionEndpoint=`${e}/`,this.profileEndpoint=`${e}/user/profile`}async getSessionInfo(){if(this.sid&&this.sessionId!==null)return{sid:this.sid,sessionId:this.sessionId};const t=await fetch(this.sessionEndpoint,{credentials:"include"});if(!t.ok){const s=await t.text();throw new Error(`Failed to fetch session info: ${t.status} – ${s}`)}const e=await t.json();return this.sid=e.catalogUser.id,this.sessionId=e.sessionId,{sid:this.sid,sessionId:this.sessionId}}async sendProfile(t,e){const s=e??(await this.getSessionInfo()).sid,n=new URL(this.profileEndpoint);n.searchParams.set("sid",s);const o=await fetch(n.toString(),{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:s,id:null,...t})});if(!o.ok){const r=await o.text();throw new Error(`Failed to send profile: ${o.status} – ${r}`)}}}const O=[u,S,T];function E(c={}){const t=new l(c),e=O.map(n=>new n(t)),s={};return e.forEach(n=>{[...Object.getOwnPropertyNames(n),...Object.getOwnPropertyNames(Object.getPrototypeOf(n))].forEach(r=>{if(r==="constructor")return;const h=n[r];typeof h=="function"&&(s[r]||(s[r]=(...y)=>h.apply(n,y)))})}),s}const f={TOP:"TOP",BOTTOM:"BOTTOM",SHOE_ACCESSORY:"SHOE_ACCESSORY",FULL_BODY:"FULL_BODY",UNDERWEAR_FULL_BODY:"UNDERWEAR_FULL_BODY",UNDERWEAR_BOTTOM:"UNDERWEAR_BOTTOM",UNDERWEAR_TOP:"UNDERWEAR_TOP",WETSUIT_FULL_BODY:"WETSUIT_FULL_BODY",WETSUIT_BOTTOM:"WETSUIT_BOTTOM",WETSUIT_TOP:"WETSUIT_TOP"},m={T_SHIRT:"t-shirt",SHIRT:"shirt",BLOUSE:"blouse",SWEATER:"sweater",HOODIE:"hoodie",JACKET:"jacket",COAT:"coat",CARDIGAN:"cardigan",BLAZER:"blazer",VEST:"vest",SWEATSHIRT:"sweatshirt",POLO_SHIRT:"polo shirt",TANK_TOP:"tank top",SKIRT:"skirt",TROUSERS:"trousers",JEANS:"jeans",SHORTS:"shorts",SNEAKERS:"sneakers",RUNNING_SHOES:"running shoes",BOOTS:"boots",ANKLE_BOOTS:"ankle boots",HIGH_HEELS:"high heels",FLATS:"flats",LOAFERS:"loafers",OXFORDS:"oxfords",SLIPPERS:"slippers",SANDALS:"sandals",DRESS:"dress",JUMPSUIT:"jumpsuit",SUIT:"suit",PANTIES:"panties",BRA:"bra",BIKINI:"bikini",BRIEFS:"briefs",BOXERS:"boxers",THONG:"thong",SWIMSUIT:"swimsuit",ONE_PIECE_SWIMSUIT:"one-piece swimsuit",WETSUIT:"wetsuit"};i.ClothType=f,i.ProductClass=m,i.createClient=E,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i["sizebay-core-sdk"]={}))})(this,(function(i){"use strict";const a={tracker:{production:"https://data-event-service.internalsizebay.com",development:"https://data-event-service-dev.internalsizebay.com"},aiImageService:{production:"https://ai-image-service.internalsizebay.com",development:"https://ai-image-service-dev.internalsizebay.com"},session:{production:"https://vfr-v3-production.sizebay.technology/api/me",development:"https://vfr-v3-staging.sizebay.eu/api/me"}};class l{constructor(e){const t=e.env||"development";this.serviceOverrides=e.services||{},this.endpoints={};for(const s in a)if(Object.prototype.hasOwnProperty.call(a,s)){const o=a[s][t];if(!o)continue;this.endpoints[s]=o}}getEndpoint(e){const t=this.endpoints[e];if(!t)throw new Error(`Endpoint for service '${e}' is not configured.`);return t}getServiceConfig(e){return this.serviceOverrides[e]||{}}}class u{constructor(e){this.endpoint=e.getEndpoint("tracker")}async track(e,t){const s={eventName:e,...t},n=new URL(`${this.endpoint}/events`);try{const o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok){const r=await o.text();throw new Error(`Request error: ${o.status} - ${r}`)}try{return await o.json()}catch{return{statusCode:201,message:"Event successfully created."}}}catch(o){throw o}}}class d extends Error{constructor(e,t){let s;try{const n=JSON.parse(t);s=(n==null?void 0:n.message)||t}catch{s=t}super(s),this.statusCode=e,this.details=t,Object.setPrototypeOf(this,d.prototype)}}async function p(c,e){let t;try{t=await fetch(c,e)}catch(n){throw new d(0,n.message)}const s=await t.text();if(!t.ok)throw new d(t.status,s);return JSON.parse(s)}class S{constructor(e){this.endpoint=e.getEndpoint("aiImageService")}appendQueryParams(e,t){Object.entries(t).forEach(([s,n])=>{n!=null&&e.searchParams.append(s,String(n))})}getSimilarProducts(e){const t=new URL(`${this.endpoint}/recommendations/similar`);return this.appendQueryParams(t,e),p(t.toString(),{method:"GET",headers:{"Content-Type":"application/json"}})}getComplementaryProducts(e){const t=new URL(`${this.endpoint}/recommendations/complementary`);return this.appendQueryParams(t,e),p(t.toString(),{method:"GET",headers:{"Content-Type":"application/json"}})}searchSimilarByImage(e){const t=`${this.endpoint}/image-search/similar`;return p(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}searchComplementaryByImage(e){const t=`${this.endpoint}/image-search/complementary`;return p(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}class T{constructor(e){this.sid=null,this.sessionId=null;const t=e.getEndpoint("session");this.sessionEndpoint=`${t}/`,this.profileEndpoint=`${t}/user/profile`}async getSessionInfo(){if(this.sid&&this.sessionId!==null)return{sid:this.sid,sessionId:this.sessionId};const e=await fetch(this.sessionEndpoint,{credentials:"include"});if(!e.ok){const s=await e.text();throw new Error(`Failed to fetch session info: ${e.status} – ${s}`)}const t=await e.json();return this.sid=t.catalogUser.id,this.sessionId=t.sessionId,{sid:this.sid,sessionId:this.sessionId}}async sendProfile(e,t){const s=t??(await this.getSessionInfo()).sid,n=new URL(this.profileEndpoint);n.searchParams.set("sid",s);const o=await fetch(n.toString(),{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:s,id:null,...e})});if(!o.ok){const r=await o.text();throw new Error(`Failed to send profile: ${o.status} – ${r}`)}}}const O=[u,S,T];function E(c={}){const e=new l(c),t=O.map(n=>new n(e)),s={};return t.forEach(n=>{[...Object.getOwnPropertyNames(n),...Object.getOwnPropertyNames(Object.getPrototypeOf(n))].forEach(r=>{if(r==="constructor")return;const h=n[r];typeof h=="function"&&(s[r]||(s[r]=(...y)=>h.apply(n,y)))})}),s}const f={TOP:"TOP",BOTTOM:"BOTTOM",SHOE_ACCESSORY:"SHOE_ACCESSORY",FULL_BODY:"FULL_BODY",UNDERWEAR_FULL_BODY:"UNDERWEAR_FULL_BODY",UNDERWEAR_BOTTOM:"UNDERWEAR_BOTTOM",UNDERWEAR_TOP:"UNDERWEAR_TOP",WETSUIT_FULL_BODY:"WETSUIT_FULL_BODY",WETSUIT_BOTTOM:"WETSUIT_BOTTOM",WETSUIT_TOP:"WETSUIT_TOP"},m={T_SHIRT:"t-shirt",SHIRT:"shirt",BLOUSE:"blouse",SWEATER:"sweater",HOODIE:"hoodie",JACKET:"jacket",COAT:"coat",CARDIGAN:"cardigan",BLAZER:"blazer",VEST:"vest",SWEATSHIRT:"sweatshirt",POLO_SHIRT:"polo shirt",TANK_TOP:"tank top",SKIRT:"skirt",TROUSERS:"trousers",JEANS:"jeans",SHORTS:"shorts",SNEAKERS:"sneakers",RUNNING_SHOES:"running shoes",BOOTS:"boots",ANKLE_BOOTS:"ankle boots",HIGH_HEELS:"high heels",FLATS:"flats",LOAFERS:"loafers",OXFORDS:"oxfords",SLIPPERS:"slippers",SANDALS:"sandals",DRESS:"dress",JUMPSUIT:"jumpsuit",SUIT:"suit",PANTIES:"panties",BRA:"bra",BIKINI:"bikini",BRIEFS:"briefs",BOXERS:"boxers",THONG:"thong",SWIMSUIT:"swimsuit",ONE_PIECE_SWIMSUIT:"one-piece swimsuit",WETSUIT:"wetsuit"};i.ClothType=f,i.ProductClass=m,i.createClient=E,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
@@ -1,5 +1,4 @@
1
- import { TrackSuccessResponse } from './track-success-response.dto';
2
1
  import { TrackBadRequestResponse } from './track-bad-request-response.dto';
3
2
  import { TrackServerErrorResponse } from './track-server-error-response.dto';
4
- import { TrackEmptyBodyResponse } from './track-empty-body-response.dto';
5
- export type TrackResponse = TrackSuccessResponse | TrackBadRequestResponse | TrackServerErrorResponse | TrackEmptyBodyResponse;
3
+ import { TrackSuccessResponse } from './track-success-response.dto';
4
+ export type TrackResponse = TrackSuccessResponse | TrackBadRequestResponse | TrackServerErrorResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sizebay-core-sdk",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "description": "A SDK designed for integrating multiple services (such as event tracking, AI services, etc.) into your application.",
5
5
  "main": "dist/sizebay-core-sdk.umd.js",
6
6
  "module": "dist/sizebay-core-sdk.es.js",
@@ -1,4 +0,0 @@
1
- export interface TrackEmptyBodyResponse {
2
- statusCode: 202 | 204;
3
- message: 'Empty body';
4
- }