@builder.io/plugin-commercelayer 0.0.9-3 → 0.1.2-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/README.md +21 -3
- package/dist/plugin.system.js +67 -53
- package/dist/plugin.system.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,13 +11,31 @@ Go to [builder.io/account/organization](https://builder.io/account/organization)
|
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
The plugin provides new field types for your Builder.io models:
|
|
14
|
+
The plugin provides new field types for your Builder.io models and data connection capabilities:
|
|
15
15
|
|
|
16
|
-
### Product Fields
|
|
16
|
+
### Product & Bundle Fields
|
|
17
17
|
|
|
18
|
-
- `Commerce Layer Product` - Search and select products from your Commerce Layer catalog
|
|
18
|
+
- `Commerce Layer Product` - Search and select products (SKUs) from your Commerce Layer catalog
|
|
19
|
+
- `Commerce Layer Bundle` - Search and select bundles from your Commerce Layer catalog
|
|
19
20
|
- `Commerce Layer Product Preview` - Preview product templates with live data
|
|
20
21
|
|
|
22
|
+
### Connect Data
|
|
23
|
+
|
|
24
|
+
The plugin also provides a "Connect Data" feature that allows you to fetch live product data directly from your Commerce Layer API:
|
|
25
|
+
|
|
26
|
+
- **Real-time data access** - Connect to your Commerce Layer products as a data source
|
|
27
|
+
- **Flexible querying** - Search products or bundles by name or SKU code with configurable result limits
|
|
28
|
+
- **Full product data** - Access all product attributes including SKU codes, prices, images, and metadata
|
|
29
|
+
- **Dynamic content** - Use live product data in your Builder.io content and templates
|
|
30
|
+
|
|
31
|
+
To use Connect Data:
|
|
32
|
+
1. In the Builder.io editor, go to the "Connect Data" panel
|
|
33
|
+
2. Click "Add Data" and select "CommerceLayer" from the data sources
|
|
34
|
+
3. Configure your query parameters (search terms, result limits)
|
|
35
|
+
4. Use the returned product data in your content via data bindings
|
|
36
|
+
|
|
37
|
+
Example: Access product SKU code with `data.attributes.code` or product name with `data.attributes.name`
|
|
38
|
+
|
|
21
39
|
### Component Model Fields
|
|
22
40
|
|
|
23
41
|
Component models can be used to create product page templates. Using the following fields makes previewing the templates straightforward:
|
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.
|
|
146884
|
+
var version = "0.1.1";
|
|
146885
146885
|
var description = "Commerce Layer plugin for Builder.io";
|
|
146886
146886
|
var keywords = [
|
|
146887
146887
|
];
|
|
@@ -147020,38 +147020,42 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147020
147020
|
}
|
|
147021
147021
|
throw new Error("Invalid token: no organization found");
|
|
147022
147022
|
};
|
|
147023
|
-
const
|
|
147024
|
-
|
|
147023
|
+
const RESOURCE_ENDPOINTS = {
|
|
147024
|
+
product: "skus",
|
|
147025
|
+
bundle: "bundles"
|
|
147026
|
+
};
|
|
147027
|
+
const getResource = async (type, id, accessToken, baseEndpoint) => {
|
|
147028
|
+
const url = `${baseEndpoint}/api/${RESOURCE_ENDPOINTS[type]}/${id}`;
|
|
147025
147029
|
const data = await makeApiRequest(url, accessToken);
|
|
147026
147030
|
return data.data;
|
|
147027
147031
|
};
|
|
147028
|
-
const
|
|
147032
|
+
const searchResources = async (type, search, accessToken, baseEndpoint) => {
|
|
147029
147033
|
const params = new URLSearchParams({
|
|
147030
147034
|
"filter[q][name_or_code_cont]": search,
|
|
147031
147035
|
"page[size]": "25"
|
|
147032
147036
|
});
|
|
147033
|
-
const url = `${baseEndpoint}/api
|
|
147037
|
+
const url = `${baseEndpoint}/api/${RESOURCE_ENDPOINTS[type]}?${params}`;
|
|
147034
147038
|
const data = await makeApiRequest(url, accessToken);
|
|
147035
147039
|
return data.data || [];
|
|
147036
147040
|
};
|
|
147037
|
-
const
|
|
147038
|
-
id:
|
|
147039
|
-
type
|
|
147040
|
-
title:
|
|
147041
|
-
handle:
|
|
147042
|
-
price:
|
|
147043
|
-
image: {
|
|
147044
|
-
src:
|
|
147045
|
-
}
|
|
147046
|
-
});
|
|
147047
|
-
const
|
|
147041
|
+
const transformResource = (resource, type) => ({
|
|
147042
|
+
id: resource.id,
|
|
147043
|
+
type,
|
|
147044
|
+
title: resource.attributes.name,
|
|
147045
|
+
handle: resource.attributes.code,
|
|
147046
|
+
price: resource.attributes.price,
|
|
147047
|
+
image: resource.attributes.image_url ? {
|
|
147048
|
+
src: resource.attributes.image_url
|
|
147049
|
+
} : void 0
|
|
147050
|
+
});
|
|
147051
|
+
const getResourceByHandle = async (type, handle, accessToken, baseEndpoint) => {
|
|
147048
147052
|
const params = new URLSearchParams({
|
|
147049
147053
|
"filter[q][code_eq]": handle
|
|
147050
147054
|
});
|
|
147051
|
-
const url = `${baseEndpoint}/api
|
|
147055
|
+
const url = `${baseEndpoint}/api/${RESOURCE_ENDPOINTS[type]}?${params}`;
|
|
147052
147056
|
const data = await makeApiRequest(url, accessToken);
|
|
147053
147057
|
if (!data.data?.[0]) {
|
|
147054
|
-
throw new Error(
|
|
147058
|
+
throw new Error(`${type} not found with handle: ${handle}`);
|
|
147055
147059
|
}
|
|
147056
147060
|
return data.data[0];
|
|
147057
147061
|
};
|
|
@@ -147065,15 +147069,16 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147065
147069
|
token
|
|
147066
147070
|
}) => {
|
|
147067
147071
|
let url;
|
|
147072
|
+
const endpoint = RESOURCE_ENDPOINTS[resource];
|
|
147068
147073
|
if (resourceId) {
|
|
147069
|
-
url = `${baseEndpoint}/api
|
|
147074
|
+
url = `${baseEndpoint}/api/${endpoint}/${resourceId}`;
|
|
147070
147075
|
} else {
|
|
147071
147076
|
const params = new URLSearchParams();
|
|
147072
147077
|
if (query) {
|
|
147073
147078
|
params.set("filter[q][name_or_code_cont]", query);
|
|
147074
147079
|
}
|
|
147075
147080
|
params.set("page[size]", (limit || 25).toString());
|
|
147076
|
-
url = `${baseEndpoint}/api
|
|
147081
|
+
url = `${baseEndpoint}/api/${endpoint}?${params}`;
|
|
147077
147082
|
}
|
|
147078
147083
|
return {
|
|
147079
147084
|
"@type": "@builder.io/core:Request",
|
|
@@ -147098,6 +147103,11 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147098
147103
|
name: "Product",
|
|
147099
147104
|
id: "product",
|
|
147100
147105
|
description: "All of your Commerce Layer products (SKUs)."
|
|
147106
|
+
},
|
|
147107
|
+
{
|
|
147108
|
+
name: "Bundle",
|
|
147109
|
+
id: "bundle",
|
|
147110
|
+
description: "All of your Commerce Layer bundles."
|
|
147101
147111
|
}
|
|
147102
147112
|
];
|
|
147103
147113
|
const getDataConfig = (service, baseEndpoint, token) => {
|
|
@@ -147187,41 +147197,45 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147187
147197
|
const scope = settings.get("scope");
|
|
147188
147198
|
const auth = await authenticateClient({ clientId, clientSecret, scope });
|
|
147189
147199
|
const { baseEndpoint } = await getOrganizationInfo(auth.accessToken);
|
|
147190
|
-
const
|
|
147191
|
-
|
|
147192
|
-
|
|
147193
|
-
|
|
147194
|
-
|
|
147195
|
-
|
|
147196
|
-
|
|
147197
|
-
|
|
147198
|
-
|
|
147199
|
-
|
|
147200
|
-
|
|
147201
|
-
|
|
147202
|
-
|
|
147203
|
-
|
|
147204
|
-
|
|
147205
|
-
|
|
147206
|
-
|
|
147207
|
-
|
|
147208
|
-
|
|
147209
|
-
|
|
147210
|
-
|
|
147211
|
-
|
|
147212
|
-
|
|
147213
|
-
|
|
147214
|
-
|
|
147215
|
-
"Authorization": `Bearer ${token}`
|
|
147216
|
-
}
|
|
147217
|
-
},
|
|
147218
|
-
options: {
|
|
147219
|
-
product: id,
|
|
147220
|
-
pluginId: pkg.name
|
|
147200
|
+
const createResourceService = (type) => ({
|
|
147201
|
+
async findById(id) {
|
|
147202
|
+
const token = await getValidToken(clientId, clientSecret, scope);
|
|
147203
|
+
const resource = await getResource(type, id, token, baseEndpoint);
|
|
147204
|
+
return transformResource(resource, type);
|
|
147205
|
+
},
|
|
147206
|
+
async findByHandle(handle) {
|
|
147207
|
+
const token = await getValidToken(clientId, clientSecret, scope);
|
|
147208
|
+
const resource = await getResourceByHandle(type, handle, token, baseEndpoint);
|
|
147209
|
+
return transformResource(resource, type);
|
|
147210
|
+
},
|
|
147211
|
+
async search(search) {
|
|
147212
|
+
const token = await getValidToken(clientId, clientSecret, scope);
|
|
147213
|
+
const resources = await searchResources(type, search, token, baseEndpoint);
|
|
147214
|
+
return resources.map((res) => transformResource(res, type));
|
|
147215
|
+
},
|
|
147216
|
+
getRequestObject(id) {
|
|
147217
|
+
const token = cachedAuth?.token || auth.accessToken;
|
|
147218
|
+
return {
|
|
147219
|
+
"@type": "@builder.io/core:Request",
|
|
147220
|
+
request: {
|
|
147221
|
+
url: `${baseEndpoint}/api/${RESOURCE_ENDPOINTS[type]}/${id}`,
|
|
147222
|
+
method: "GET",
|
|
147223
|
+
headers: {
|
|
147224
|
+
"Authorization": `Bearer ${token}`
|
|
147221
147225
|
}
|
|
147222
|
-
}
|
|
147223
|
-
|
|
147226
|
+
},
|
|
147227
|
+
options: {
|
|
147228
|
+
[type]: id,
|
|
147229
|
+
resourceType: type,
|
|
147230
|
+
resourceId: id,
|
|
147231
|
+
pluginId: pkg.name
|
|
147232
|
+
}
|
|
147233
|
+
};
|
|
147224
147234
|
}
|
|
147235
|
+
});
|
|
147236
|
+
const service = {
|
|
147237
|
+
product: createResourceService("product"),
|
|
147238
|
+
bundle: createResourceService("bundle")
|
|
147225
147239
|
};
|
|
147226
147240
|
appState.registerDataPlugin(getDataConfig(service, baseEndpoint, auth.accessToken));
|
|
147227
147241
|
return service;
|