@builder.io/plugin-commercelayer 0.0.4 → 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.
- package/dist/plugin.system.js +54 -56
- package/dist/plugin.system.js.map +1 -1
- package/package.json +5 -13
package/dist/plugin.system.js
CHANGED
|
@@ -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.
|
|
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,7 +146945,9 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
146953
146945
|
};
|
|
146954
146946
|
|
|
146955
146947
|
const authenticateClient = async ({ clientId, scope }) => {
|
|
146956
|
-
const
|
|
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",
|
|
@@ -146967,10 +146961,11 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
146967
146961
|
});
|
|
146968
146962
|
if (!response.ok) {
|
|
146969
146963
|
const errorText = await response.text();
|
|
146970
|
-
console.error("Auth Error:", errorText);
|
|
146971
|
-
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}`);
|
|
146972
146966
|
}
|
|
146973
146967
|
const data = await response.json();
|
|
146968
|
+
console.log("Auth response:", data);
|
|
146974
146969
|
return {
|
|
146975
146970
|
accessToken: data.access_token,
|
|
146976
146971
|
tokenType: data.token_type,
|
|
@@ -146979,6 +146974,32 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
146979
146974
|
createdAt: data.created_at
|
|
146980
146975
|
};
|
|
146981
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
|
+
};
|
|
146982
147003
|
const getOrganizationInfo = async (accessToken) => {
|
|
146983
147004
|
const [, payload] = accessToken.split(".");
|
|
146984
147005
|
const decodedPayload = JSON.parse(atob(payload));
|
|
@@ -146991,36 +147012,18 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
146991
147012
|
throw new Error("Invalid token: no organization found");
|
|
146992
147013
|
};
|
|
146993
147014
|
const getProduct = async (id, accessToken, baseEndpoint) => {
|
|
146994
|
-
const
|
|
146995
|
-
|
|
146996
|
-
"Authorization": `Bearer ${accessToken}`,
|
|
146997
|
-
"Content-Type": "application/json"
|
|
146998
|
-
}
|
|
146999
|
-
});
|
|
147000
|
-
if (!response.ok) {
|
|
147001
|
-
throw new Error(`Failed to fetch product: ${response.statusText}`);
|
|
147002
|
-
}
|
|
147003
|
-
const data = await response.json();
|
|
147015
|
+
const url = `${baseEndpoint}/api/skus/${id}`;
|
|
147016
|
+
const data = await makeApiRequest(url, accessToken);
|
|
147004
147017
|
return data.data;
|
|
147005
147018
|
};
|
|
147006
147019
|
const searchProducts = async (search, accessToken, baseEndpoint) => {
|
|
147007
147020
|
const params = new URLSearchParams({
|
|
147008
|
-
"filter[q][
|
|
147009
|
-
"
|
|
147021
|
+
"filter[q][name_or_code_cont]": search,
|
|
147022
|
+
"page[size]": "25"
|
|
147010
147023
|
});
|
|
147011
|
-
const
|
|
147012
|
-
|
|
147013
|
-
|
|
147014
|
-
"Accept": "application/vnd.api+json",
|
|
147015
|
-
"Content-Type": "application/vnd.api+json"
|
|
147016
|
-
}
|
|
147017
|
-
});
|
|
147018
|
-
if (!response.ok) {
|
|
147019
|
-
console.error("Search Error:", await response.text());
|
|
147020
|
-
throw new Error(`Failed to search products: ${response.statusText}`);
|
|
147021
|
-
}
|
|
147022
|
-
const data = await response.json();
|
|
147023
|
-
return data.data;
|
|
147024
|
+
const url = `${baseEndpoint}/api/skus?${params}`;
|
|
147025
|
+
const data = await makeApiRequest(url, accessToken);
|
|
147026
|
+
return data.data || [];
|
|
147024
147027
|
};
|
|
147025
147028
|
const transformProduct = (product) => ({
|
|
147026
147029
|
id: product.id,
|
|
@@ -147035,18 +147038,8 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147035
147038
|
const params = new URLSearchParams({
|
|
147036
147039
|
"filter[q][code_eq]": handle
|
|
147037
147040
|
});
|
|
147038
|
-
const
|
|
147039
|
-
|
|
147040
|
-
"Authorization": `Bearer ${accessToken}`,
|
|
147041
|
-
"Accept": "application/vnd.api+json",
|
|
147042
|
-
"Content-Type": "application/vnd.api+json"
|
|
147043
|
-
}
|
|
147044
|
-
});
|
|
147045
|
-
if (!response.ok) {
|
|
147046
|
-
console.error("Product Handle Error:", await response.text());
|
|
147047
|
-
throw new Error(`Failed to fetch product by handle: ${response.statusText}`);
|
|
147048
|
-
}
|
|
147049
|
-
const data = await response.json();
|
|
147041
|
+
const url = `${baseEndpoint}/api/skus?${params}`;
|
|
147042
|
+
const data = await makeApiRequest(url, accessToken);
|
|
147050
147043
|
if (!data.data?.[0]) {
|
|
147051
147044
|
throw new Error(`Product not found with handle: ${handle}`);
|
|
147052
147045
|
}
|
|
@@ -147061,22 +147054,26 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147061
147054
|
{
|
|
147062
147055
|
name: "clientId",
|
|
147063
147056
|
type: "string",
|
|
147064
|
-
required: true
|
|
147057
|
+
required: true,
|
|
147058
|
+
helperText: "Your Commerce Layer application Client ID"
|
|
147065
147059
|
},
|
|
147066
147060
|
{
|
|
147067
147061
|
name: "scope",
|
|
147068
147062
|
type: "string",
|
|
147069
|
-
required: true
|
|
147063
|
+
required: true,
|
|
147064
|
+
helperText: 'Commerce Layer scope (e.g., "market:all")'
|
|
147070
147065
|
}
|
|
147071
147066
|
],
|
|
147072
|
-
ctaText: "Connect Commerce Layer"
|
|
147067
|
+
ctaText: "Connect your Commerce Layer store"
|
|
147073
147068
|
},
|
|
147074
147069
|
async (settings) => {
|
|
147075
147070
|
try {
|
|
147076
147071
|
const clientId = settings.get("clientId");
|
|
147077
147072
|
const scope = settings.get("scope");
|
|
147073
|
+
console.log("Plugin initializing with:", { clientId, scope });
|
|
147078
147074
|
const auth = await authenticateClient({ clientId, scope });
|
|
147079
147075
|
const { baseEndpoint } = await getOrganizationInfo(auth.accessToken);
|
|
147076
|
+
console.log("Plugin initialized with:", { baseEndpoint, tokenLength: auth.accessToken.length });
|
|
147080
147077
|
return {
|
|
147081
147078
|
product: {
|
|
147082
147079
|
async findById(id) {
|
|
@@ -147088,6 +147085,7 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147088
147085
|
return transformProduct(product);
|
|
147089
147086
|
},
|
|
147090
147087
|
async search(search) {
|
|
147088
|
+
console.log("Searching for:", search);
|
|
147091
147089
|
const products = await searchProducts(search, auth.accessToken, baseEndpoint);
|
|
147092
147090
|
return products.map(transformProduct);
|
|
147093
147091
|
},
|