@builder.io/plugin-commercelayer 0.0.2 → 0.0.3-0

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.
@@ -33174,7 +33174,7 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33174
33174
  }); };
33175
33175
 
33176
33176
  var name = "@builder.io/plugin-commercelayer";
33177
- var version = "0.0.1";
33177
+ var version = "0.0.2";
33178
33178
  var description = "";
33179
33179
  var keywords = [
33180
33180
  ];
@@ -33353,7 +33353,6 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33353
33353
  })
33354
33354
  });
33355
33355
  const data = await response.json();
33356
- console.log("returning auth token ", data.access_token);
33357
33356
  return data.access_token;
33358
33357
  };
33359
33358
  const baseUrl = (url) => {
@@ -33364,22 +33363,26 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33364
33363
  Accept: `application/vnd.api+json`
33365
33364
  };
33366
33365
  const transformResource = (resource) => ({
33366
+ sku: resource?.attributes?.code,
33367
33367
  ...resource,
33368
- id: resource.id,
33368
+ id: `${resource?.attributes?.name?.split(" ").join("-").replace("(", "").replace(")", "").toLowerCase()}/${resource?.attributes?.code}`,
33369
33369
  title: resource?.attributes?.name,
33370
33370
  handle: resource.id,
33371
33371
  image: {
33372
33372
  src: resource?.attributes?.image_url
33373
- }
33373
+ },
33374
+ tempSlug: resource?.attributes?.name?.split(" ").join("-").replace("(", "").replace(")", "").toLowerCase()
33374
33375
  });
33375
33376
  const service = {
33376
33377
  product: {
33377
33378
  async findById(id) {
33379
+ const code = id.split("/")[1];
33380
+ const finalId = code;
33378
33381
  const token = await authToken();
33379
- const key = `${id}productById`;
33380
- const product = basicCache.get(key) || await fetch(baseUrl(`skus/${id}`), { headers: { ...headers, Authorization: "Bearer " + token } }).then((res) => res.json()).then((res) => res.data).then(transformResource);
33381
- basicCache.set(key, product);
33382
- return product;
33382
+ const key = `${finalId}productById`;
33383
+ const productsList = basicCache.get(key) || await fetch(baseUrl(`skus?filter[q][code_eq]=${finalId}`), { headers: { ...headers, Authorization: "Bearer " + token } }).then((res) => res.json()).then((res) => res.data).then((data) => data.map(transformResource));
33384
+ basicCache.set(key, productsList[0]);
33385
+ return productsList[0];
33383
33386
  },
33384
33387
  async search(search) {
33385
33388
  const token = await authToken();
@@ -33390,7 +33393,8 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33390
33393
  });
33391
33394
  return response.data.map(transformResource);
33392
33395
  },
33393
- getRequestObject(id) {
33396
+ getRequestObject(id, options) {
33397
+ const prd = JSON.parse(JSON.stringify(options));
33394
33398
  return {
33395
33399
  "@type": "@builder.io/core:Request",
33396
33400
  request: {
@@ -33398,7 +33402,11 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33398
33402
  headers
33399
33403
  },
33400
33404
  options: {
33401
- product: id
33405
+ product: {
33406
+ id,
33407
+ productSku: prd?.sku,
33408
+ productSlug: prd?.tempSlug
33409
+ }
33402
33410
  }
33403
33411
  };
33404
33412
  }