@builder.io/plugin-commercelayer 0.0.9-2 → 0.1.1
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 +18 -1
- package/dist/plugin.system.js +102 -2
- package/dist/plugin.system.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,13 +11,30 @@ 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
16
|
### Product Fields
|
|
17
17
|
|
|
18
18
|
- `Commerce Layer Product` - Search and select products from your Commerce Layer catalog
|
|
19
19
|
- `Commerce Layer Product Preview` - Preview product templates with live data
|
|
20
20
|
|
|
21
|
+
### Connect Data
|
|
22
|
+
|
|
23
|
+
The plugin also provides a "Connect Data" feature that allows you to fetch live product data directly from your Commerce Layer API:
|
|
24
|
+
|
|
25
|
+
- **Real-time data access** - Connect to your Commerce Layer products as a data source
|
|
26
|
+
- **Flexible querying** - Search products by name or SKU code with configurable result limits
|
|
27
|
+
- **Full product data** - Access all product attributes including SKU codes, prices, images, and metadata
|
|
28
|
+
- **Dynamic content** - Use live product data in your Builder.io content and templates
|
|
29
|
+
|
|
30
|
+
To use Connect Data:
|
|
31
|
+
1. In the Builder.io editor, go to the "Connect Data" panel
|
|
32
|
+
2. Click "Add Data" and select "CommerceLayer" from the data sources
|
|
33
|
+
3. Configure your query parameters (search terms, result limits)
|
|
34
|
+
4. Use the returned product data in your content via data bindings
|
|
35
|
+
|
|
36
|
+
Example: Access product SKU code with `data.attributes.code` or product name with `data.attributes.name`
|
|
37
|
+
|
|
21
38
|
### Component Model Fields
|
|
22
39
|
|
|
23
40
|
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.0
|
|
146884
|
+
var version = "0.1.0";
|
|
146885
146885
|
var description = "Commerce Layer plugin for Builder.io";
|
|
146886
146886
|
var keywords = [
|
|
146887
146887
|
];
|
|
@@ -147056,6 +147056,104 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147056
147056
|
return data.data[0];
|
|
147057
147057
|
};
|
|
147058
147058
|
|
|
147059
|
+
const buildCommerceLayerUrl = ({
|
|
147060
|
+
resource,
|
|
147061
|
+
resourceId,
|
|
147062
|
+
query,
|
|
147063
|
+
limit,
|
|
147064
|
+
baseEndpoint,
|
|
147065
|
+
token
|
|
147066
|
+
}) => {
|
|
147067
|
+
let url;
|
|
147068
|
+
if (resourceId) {
|
|
147069
|
+
url = `${baseEndpoint}/api/skus/${resourceId}`;
|
|
147070
|
+
} else {
|
|
147071
|
+
const params = new URLSearchParams();
|
|
147072
|
+
if (query) {
|
|
147073
|
+
params.set("filter[q][name_or_code_cont]", query);
|
|
147074
|
+
}
|
|
147075
|
+
params.set("page[size]", (limit || 25).toString());
|
|
147076
|
+
url = `${baseEndpoint}/api/skus?${params}`;
|
|
147077
|
+
}
|
|
147078
|
+
return {
|
|
147079
|
+
"@type": "@builder.io/core:Request",
|
|
147080
|
+
request: {
|
|
147081
|
+
url,
|
|
147082
|
+
method: "GET",
|
|
147083
|
+
headers: {
|
|
147084
|
+
"Authorization": `Bearer ${token}`,
|
|
147085
|
+
"Accept": "application/vnd.api+json",
|
|
147086
|
+
"Content-Type": "application/vnd.api+json"
|
|
147087
|
+
}
|
|
147088
|
+
},
|
|
147089
|
+
options: {
|
|
147090
|
+
resource,
|
|
147091
|
+
resourceId,
|
|
147092
|
+
pluginId: pkg.name
|
|
147093
|
+
}
|
|
147094
|
+
};
|
|
147095
|
+
};
|
|
147096
|
+
const RESOURCE_TYPES = [
|
|
147097
|
+
{
|
|
147098
|
+
name: "Product",
|
|
147099
|
+
id: "product",
|
|
147100
|
+
description: "All of your Commerce Layer products (SKUs)."
|
|
147101
|
+
}
|
|
147102
|
+
];
|
|
147103
|
+
const getDataConfig = (service, baseEndpoint, token) => {
|
|
147104
|
+
return {
|
|
147105
|
+
name: "CommerceLayer",
|
|
147106
|
+
icon: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F9893958430eb4c59af7ab616ba868941",
|
|
147107
|
+
getResourceTypes: async () => RESOURCE_TYPES.map(
|
|
147108
|
+
(model) => ({
|
|
147109
|
+
...model,
|
|
147110
|
+
inputs: () => [
|
|
147111
|
+
{
|
|
147112
|
+
friendlyName: "Limit",
|
|
147113
|
+
name: "limit",
|
|
147114
|
+
type: "number",
|
|
147115
|
+
defaultValue: 25,
|
|
147116
|
+
max: 100,
|
|
147117
|
+
min: 1
|
|
147118
|
+
},
|
|
147119
|
+
{
|
|
147120
|
+
friendlyName: "Search",
|
|
147121
|
+
name: "query",
|
|
147122
|
+
type: "string",
|
|
147123
|
+
helperText: "Search by product name or SKU code"
|
|
147124
|
+
}
|
|
147125
|
+
],
|
|
147126
|
+
toUrl: ({ entry, query, limit }) => buildCommerceLayerUrl({
|
|
147127
|
+
query,
|
|
147128
|
+
limit,
|
|
147129
|
+
resource: model.id,
|
|
147130
|
+
resourceId: entry,
|
|
147131
|
+
baseEndpoint,
|
|
147132
|
+
token
|
|
147133
|
+
}),
|
|
147134
|
+
canPickEntries: true
|
|
147135
|
+
})
|
|
147136
|
+
),
|
|
147137
|
+
getEntriesByResourceType: async (resourceTypeId, options = {}) => {
|
|
147138
|
+
const entry = options.resourceEntryId;
|
|
147139
|
+
if (entry) {
|
|
147140
|
+
const entryObj = await service[resourceTypeId].findById(entry);
|
|
147141
|
+
return [
|
|
147142
|
+
{
|
|
147143
|
+
id: String(entryObj.id),
|
|
147144
|
+
name: entryObj.title
|
|
147145
|
+
}
|
|
147146
|
+
];
|
|
147147
|
+
}
|
|
147148
|
+
const response = await service[resourceTypeId].search(options.searchText || "");
|
|
147149
|
+
return response.map((result) => ({
|
|
147150
|
+
id: String(result.id),
|
|
147151
|
+
name: result.title
|
|
147152
|
+
}));
|
|
147153
|
+
}
|
|
147154
|
+
};
|
|
147155
|
+
};
|
|
147156
|
+
|
|
147059
147157
|
registerCommercePlugin(
|
|
147060
147158
|
{
|
|
147061
147159
|
name: "CommerceLayer",
|
|
@@ -147089,7 +147187,7 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147089
147187
|
const scope = settings.get("scope");
|
|
147090
147188
|
const auth = await authenticateClient({ clientId, clientSecret, scope });
|
|
147091
147189
|
const { baseEndpoint } = await getOrganizationInfo(auth.accessToken);
|
|
147092
|
-
|
|
147190
|
+
const service = {
|
|
147093
147191
|
product: {
|
|
147094
147192
|
async findById(id) {
|
|
147095
147193
|
const token = await getValidToken(clientId, clientSecret, scope);
|
|
@@ -147125,6 +147223,8 @@ System.register(['@builder.io/sdk', '@emotion/core', '@material-ui/core', 'react
|
|
|
147125
147223
|
}
|
|
147126
147224
|
}
|
|
147127
147225
|
};
|
|
147226
|
+
appState.registerDataPlugin(getDataConfig(service, baseEndpoint, auth.accessToken));
|
|
147227
|
+
return service;
|
|
147128
147228
|
} catch (error) {
|
|
147129
147229
|
console.error(error);
|
|
147130
147230
|
appState.snackBar.show(
|