@builder.io/plugin-commercelayer 0.0.6 → 0.0.8-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.
@@ -146881,7 +146881,7 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146881
146881
  });
146882
146882
 
146883
146883
  var name = "@builder.io/plugin-commercelayer";
146884
- var version = "0.0.5";
146884
+ var version = "0.0.7";
146885
146885
  var description = "Commerce Layer plugin for Builder.io";
146886
146886
  var keywords = [
146887
146887
  ];
@@ -146902,20 +146902,11 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146902
146902
  var type = "module";
146903
146903
  var types = "dist/index.d.ts";
146904
146904
  var scripts = {
146905
- lint: "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
146906
146905
  prebuild: "rimraf dist",
146907
146906
  build: "rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript",
146908
146907
  start: "SERVE=true rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript -w",
146909
146908
  "release:dev": "npm run build && npm version prerelease --no-git-tag-version && npm publish --tag dev",
146910
- "release:patch": "npm run build && npm version patch --no-git-tag-version && npm publish",
146911
- test: "jest --coverage",
146912
- "test:watch": "jest --coverage --watch",
146913
- "test:prod": "npm run lint && npm run test -- --no-cache",
146914
- "report-coverage": "cat ./coverage/lcov.info | coveralls",
146915
- commit: "git-cz",
146916
- "semantic-release": "semantic-release",
146917
- "semantic-release-prepare": "ts-node tools/semantic-release-prepare",
146918
- "travis-deploy-once": "travis-deploy-once"
146909
+ "release:patch": "npm run build && npm version patch --no-git-tag-version && npm publish"
146919
146910
  };
146920
146911
  var devDependencies = {
146921
146912
  "@rollup/plugin-json": "^6.1.0",
@@ -146923,12 +146914,13 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146923
146914
  "@rollup/plugin-replace": "^5.0.5",
146924
146915
  "@rollup/plugin-typescript": "^11.1.6",
146925
146916
  "@types/node": "^20.11.19",
146917
+ rimraf: "^2.6.2",
146926
146918
  rollup: "^4.12.0",
146927
146919
  "rollup-plugin-esbuild": "^6.1.1",
146928
146920
  "rollup-plugin-serve": "^1.1.1",
146921
+ tslib: "^2.8.1",
146929
146922
  tsx: "^4.7.1",
146930
- typescript: "^5.2.2",
146931
- rimraf: "^2.6.2"
146923
+ typescript: "^5.2.2"
146932
146924
  };
146933
146925
  var dependencies = {
146934
146926
  "@builder.io/plugin-tools": "^0.0.6"
@@ -146953,14 +146945,13 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146953
146945
  };
146954
146946
 
146955
146947
  const authenticateClient = async ({ clientId, scope }) => {
146956
- const response = await fetch("https://auth.commercelayer.io/oauth/token", {
146948
+ const authUrl = "https://auth.commercelayer.io/oauth/token";
146949
+ console.log("Authenticating with:", { clientId, scope });
146950
+ const response = await fetch(authUrl, {
146957
146951
  method: "POST",
146958
146952
  headers: {
146959
146953
  "Accept": "application/json",
146960
- "Content-Type": "application/json",
146961
- "Access-Control-Allow-Origin": "*",
146962
- "Access-Control-Allow-Methods": "POST, OPTIONS",
146963
- "Access-Control-Allow-Headers": "Content-Type, Authorization"
146954
+ "Content-Type": "application/json"
146964
146955
  },
146965
146956
  body: JSON.stringify({
146966
146957
  grant_type: "client_credentials",
@@ -146970,10 +146961,11 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146970
146961
  });
146971
146962
  if (!response.ok) {
146972
146963
  const errorText = await response.text();
146973
- console.error("Auth Error:", errorText);
146974
- throw new Error(`Authentication failed: ${response.statusText}`);
146964
+ console.error("Auth Error:", { status: response.status, statusText: response.statusText, errorText });
146965
+ throw new Error(`Authentication failed: ${response.status} ${response.statusText} - ${errorText}`);
146975
146966
  }
146976
146967
  const data = await response.json();
146968
+ console.log("Auth response:", data);
146977
146969
  return {
146978
146970
  accessToken: data.access_token,
146979
146971
  tokenType: data.token_type,
@@ -146982,6 +146974,32 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146982
146974
  createdAt: data.created_at
146983
146975
  };
146984
146976
  };
146977
+ const makeApiRequest = async (url, accessToken, options = {}) => {
146978
+ console.log("Making API request:", { url, tokenLength: accessToken.length });
146979
+ const response = await fetch(url, {
146980
+ ...options,
146981
+ headers: {
146982
+ "Authorization": `Bearer ${accessToken}`,
146983
+ "Accept": "application/vnd.api+json",
146984
+ "Content-Type": "application/vnd.api+json",
146985
+ ...options.headers
146986
+ }
146987
+ });
146988
+ if (!response.ok) {
146989
+ const errorText = await response.text();
146990
+ console.error("API Error:", { status: response.status, statusText: response.statusText, errorText, url });
146991
+ try {
146992
+ const errorData = JSON.parse(errorText);
146993
+ console.error("Parsed error:", errorData);
146994
+ } catch (e) {
146995
+ console.error("Raw error text:", errorText);
146996
+ }
146997
+ throw new Error(`API request failed: ${response.status} ${response.statusText}`);
146998
+ }
146999
+ const data = await response.json();
147000
+ console.log("API response:", { url, dataLength: JSON.stringify(data).length });
147001
+ return data;
147002
+ };
146985
147003
  const getOrganizationInfo = async (accessToken) => {
146986
147004
  const [, payload] = accessToken.split(".");
146987
147005
  const decodedPayload = JSON.parse(atob(payload));
@@ -146994,36 +147012,18 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
146994
147012
  throw new Error("Invalid token: no organization found");
146995
147013
  };
146996
147014
  const getProduct = async (id, accessToken, baseEndpoint) => {
146997
- const response = await fetch(`${baseEndpoint}/api/skus/${id}`, {
146998
- headers: {
146999
- "Authorization": `Bearer ${accessToken}`,
147000
- "Content-Type": "application/json"
147001
- }
147002
- });
147003
- if (!response.ok) {
147004
- throw new Error(`Failed to fetch product: ${response.statusText}`);
147005
- }
147006
- const data = await response.json();
147015
+ const url = `${baseEndpoint}/api/skus/${id}`;
147016
+ const data = await makeApiRequest(url, accessToken);
147007
147017
  return data.data;
147008
147018
  };
147009
147019
  const searchProducts = async (search, accessToken, baseEndpoint) => {
147010
147020
  const params = new URLSearchParams({
147011
- "filter[q][code_or_name_cont]": search,
147012
- "include": "prices,stock_items"
147013
- });
147014
- const response = await fetch(`${baseEndpoint}/api/skus?${params}`, {
147015
- headers: {
147016
- "Authorization": `Bearer ${accessToken}`,
147017
- "Accept": "application/vnd.api+json",
147018
- "Content-Type": "application/vnd.api+json"
147019
- }
147021
+ "filter[q][name_or_code_cont]": search,
147022
+ "page[size]": "25"
147020
147023
  });
147021
- if (!response.ok) {
147022
- console.error("Search Error:", await response.text());
147023
- throw new Error(`Failed to search products: ${response.statusText}`);
147024
- }
147025
- const data = await response.json();
147026
- return data.data;
147024
+ const url = `${baseEndpoint}/api/skus?${params}`;
147025
+ const data = await makeApiRequest(url, accessToken);
147026
+ return data.data || [];
147027
147027
  };
147028
147028
  const transformProduct = (product) => ({
147029
147029
  id: product.id,
@@ -147038,18 +147038,8 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
147038
147038
  const params = new URLSearchParams({
147039
147039
  "filter[q][code_eq]": handle
147040
147040
  });
147041
- const response = await fetch(`${baseEndpoint}/api/skus?${params}`, {
147042
- headers: {
147043
- "Authorization": `Bearer ${accessToken}`,
147044
- "Accept": "application/vnd.api+json",
147045
- "Content-Type": "application/vnd.api+json"
147046
- }
147047
- });
147048
- if (!response.ok) {
147049
- console.error("Product Handle Error:", await response.text());
147050
- throw new Error(`Failed to fetch product by handle: ${response.statusText}`);
147051
- }
147052
- const data = await response.json();
147041
+ const url = `${baseEndpoint}/api/skus?${params}`;
147042
+ const data = await makeApiRequest(url, accessToken);
147053
147043
  if (!data.data?.[0]) {
147054
147044
  throw new Error(`Product not found with handle: ${handle}`);
147055
147045
  }
@@ -147064,22 +147054,26 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
147064
147054
  {
147065
147055
  name: "clientId",
147066
147056
  type: "string",
147067
- required: true
147057
+ required: true,
147058
+ helperText: "Your Commerce Layer application Client ID"
147068
147059
  },
147069
147060
  {
147070
147061
  name: "scope",
147071
147062
  type: "string",
147072
- required: true
147063
+ required: true,
147064
+ helperText: 'Commerce Layer scope (e.g., "market:all")'
147073
147065
  }
147074
147066
  ],
147075
- ctaText: "Connect Commerce Layer"
147067
+ ctaText: "Connect your Commerce Layer store"
147076
147068
  },
147077
147069
  async (settings) => {
147078
147070
  try {
147079
147071
  const clientId = settings.get("clientId");
147080
147072
  const scope = settings.get("scope");
147073
+ console.log("Plugin initializing with:", { clientId, scope });
147081
147074
  const auth = await authenticateClient({ clientId, scope });
147082
147075
  const { baseEndpoint } = await getOrganizationInfo(auth.accessToken);
147076
+ console.log("Plugin initialized with:", { baseEndpoint, tokenLength: auth.accessToken.length });
147083
147077
  return {
147084
147078
  product: {
147085
147079
  async findById(id) {
@@ -147091,6 +147085,7 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
147091
147085
  return transformProduct(product);
147092
147086
  },
147093
147087
  async search(search) {
147088
+ console.log("Searching for:", search);
147094
147089
  const products = await searchProducts(search, auth.accessToken, baseEndpoint);
147095
147090
  return products.map(transformProduct);
147096
147091
  },