@builder.io/plugin-sfcc-commerce-api 0.0.5 → 0.0.6

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 CHANGED
@@ -1,3 +1,62 @@
1
- # Builder.io Saleforce Commerce Api plugin [alpha]
1
+ # Builder.io Salesforce Commerce Api plugin [alpha]
2
+
3
+ Easily connect your SalesForce B2C Commerce PWA APP to your Builder.io content!
4
+
5
+ ## SalesForce Setup API Access
6
+ Read through this [get started guide](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/setting-up-api-access.html) to make sure you have your *Shopper Login and API Access Service (SLAS)* client setup ready.
7
+
8
+
9
+ ## Installation
10
+
11
+ Go to [builder.io/account/organization](https://builder.io/account/organization) and type `@builder.io/plugin-sfcc-commerce-api` in the input, then hit save.
12
+
13
+
14
+ ![Installation screenshot](https://cdn.builder.io/api/v1/image/assets%2Fd1ed12c3338144da8dd6b63b35d14c30%2F2c0da6f6b3104d6d87bdf62caa9ee271)
15
+
16
+ Following, you'll be prompted to enter the following data:
17
+ * Client id
18
+ * Organization id
19
+ * Proxy address
20
+ * Short code
21
+ * Site id
22
+
23
+ **The same configuration you find at your config/default.js file**
24
+ ![Config screenshot](https://cdn.builder.io/api/v1/image/assets%2F1fa6810c36c54e87bfe1a6cc0f0be906%2Fa1e74597f82e46d390fd0b328c19bf78)
25
+
26
+ Log into your Administration panel with your SFCC credentials at your [account administrator panel](https://account.demandware.com/)
27
+
28
+ ![Credentials screenshot](https://cdn.builder.io/api/v1/image/assets%2Fd1ed12c3338144da8dd6b63b35d14c30%2F92cfc4b9885d41eaa4d5c23b00ebeace)
29
+
30
+
31
+ After putting the required info, hit the connect button. You will now see a few new field types (for [model](https://builder.io/c/docs/guides/getting-started-with-models) fields, [symbol](https://builder.io/c/docs/guides/symbols) inputs, [custom components](https://builder.io/c/docs/custom-react-components) fields), and [custom targeting attributes](https://www.builder.io/c/docs/guides/targeting-and-scheduling#custom-targeting) that can be used in three different contexts:
32
+
33
+
34
+
35
+ ![Custom targeting attributes](https://cdn.builder.io/api/v1/image/assets%2Fd1ed12c3338144da8dd6b63b35d14c30%2F761dc7267e3b45198c460dfe6b0cec8e)
36
+
37
+ ### Custom targeting
38
+
39
+ Custom targeting in Builder.io allow users to target content by a multitude of attributes, and in this plugin you'll be able to add specific content from SFCC products, for this you'll need first to set the target attributes on the host site, either by setting the `userAttributes` if you're rendering client side:
40
+
41
+ ```ts
42
+ builder.setUserAttributes({
43
+ product: currentProduct.id,
44
+ });
45
+ ```
46
+
47
+ Or by passing it as a query param to the [content API](https://www.builder.io/c/docs/query-api#:~:text=userAttributes) call, or in [graqhql query](https://www.builder.io/c/docs/graphql-api#:~:text=with%20targeting) for e.g in Gatsby or nextjs.
48
+
49
+ - `SfCommerceProduct` when used as a custom targeting type, it'll target contexts where the field is set to the product ID, you'll need to set the product ID on the host environment, using one of the methods above.
50
+
51
+ - `SfCommerceProductsList` when used as a custom targeting type, it'll target contexts where the field is set to the a list of product Ids, you'll need to set the list of product Ids on the host environment, using one of the methods above.
52
+
53
+ - `SfCommerceCategory` can be used as custom targeting attribute to target specific category by ID, you'll need to set the category ID on the host environment, using one of the methods above.
54
+
55
+ - `SfCommerceCategoriesList` when used as a custom targeting type, it'll target contexts where the field is set to the a list of category Ids, you'll need to set the list of category Ids on the host environment, using one of the methods above.
56
+
57
+
58
+ ### Seeing the plugin in action
59
+
60
+ Try creating a custom [model](https://builder.io/c/docs/guides/getting-started-with-models), [component](https://builder.io/c/docs/custom-react-components), or [symbol](https://builder.io/c/docs/guides/symbols) using any of the SFCC field types, and edit away!
61
+
2
62
 
3
- TODO
@@ -33563,7 +33563,7 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33563
33563
  }); };
33564
33564
 
33565
33565
  var name = "@builder.io/plugin-sfcc-commerce-api";
33566
- var version = "0.0.4";
33566
+ var version = "0.0.5";
33567
33567
  var description = "";
33568
33568
  var keywords = [
33569
33569
  ];
@@ -33734,6 +33734,21 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33734
33734
  src: cat.image || "https://unpkg.com/css.gg@2.0.0/icons/svg/box.svg"
33735
33735
  }
33736
33736
  });
33737
+ const transformRecommender = (rec) => ({
33738
+ ...rec,
33739
+ id: rec.name,
33740
+ title: rec.name,
33741
+ image: {
33742
+ src: "https://cdn.builder.io/api/v1/image/assets%2Fd1ed12c3338144da8dd6b63b35d14c30%2Fe1439f0d991c4e2d968c84a38059f1d2"
33743
+ }
33744
+ });
33745
+ const getRecommenders = (siteId, clientId) => {
33746
+ const url = new URL("https://cdn.builder.io/api/v1/proxy-api");
33747
+ url.searchParams.set("url", `https://api.cquotient.com/v3/personalization/recommenders/${siteId}`);
33748
+ url.searchParams.set("headers.x-cq-client-id", clientId);
33749
+ url.searchParams.set("apiKey", appState.user.apiKey);
33750
+ return fetch(url).then((res) => res.json()).then((res) => res.recommenders.map(transformRecommender));
33751
+ };
33737
33752
  class Api {
33738
33753
  constructor(apiKey, pluginId) {
33739
33754
  this.apiKey = apiKey;
@@ -33797,6 +33812,7 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33797
33812
  registerCommercePlugin({
33798
33813
  name: "SFCommerce",
33799
33814
  id: pkg.name,
33815
+ noPreviewTypes: true,
33800
33816
  settings: [
33801
33817
  {
33802
33818
  name: "clientId",
@@ -33822,11 +33838,40 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33822
33838
  name: "siteId",
33823
33839
  type: "string",
33824
33840
  required: true
33841
+ },
33842
+ {
33843
+ name: "einsteinId",
33844
+ friendlyName: "Einstein API Client ID",
33845
+ type: "string"
33846
+ },
33847
+ {
33848
+ name: "einsteinSiteId",
33849
+ friendlyName: "Einstein API Site ID",
33850
+ type: "string"
33825
33851
  }
33826
33852
  ],
33827
33853
  ctaText: `Connect your Salesforce Commerce API`
33828
- }, async () => {
33854
+ }, async (settings) => {
33829
33855
  const api = new Api(appState.user.apiKey, pkg.name);
33856
+ const einsteinId = settings.get("einsteinId");
33857
+ const einsteinSiteId = settings.get("einsteinSiteId");
33858
+ let recommendersType = {};
33859
+ if (einsteinId && einsteinSiteId) {
33860
+ const recommenders = await getRecommenders(einsteinSiteId, einsteinId);
33861
+ recommendersType = {
33862
+ recommender: {
33863
+ search(search = "") {
33864
+ return Promise.resolve(recommenders.filter((rec) => JSON.stringify(rec).includes(search)));
33865
+ },
33866
+ findById(id) {
33867
+ return Promise.resolve(recommenders.find((rec) => rec.id === id));
33868
+ },
33869
+ getRequestObject(id) {
33870
+ return id;
33871
+ }
33872
+ }
33873
+ };
33874
+ }
33830
33875
  return {
33831
33876
  product: {
33832
33877
  async findById(id) {
@@ -33865,7 +33910,8 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
33865
33910
  }
33866
33911
  };
33867
33912
  }
33868
- }
33913
+ },
33914
+ ...recommendersType
33869
33915
  };
33870
33916
  });
33871
33917