@nuskin/product-components 3.6.4 → 3.6.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.6.5](https://code.tls.nuskin.io/ns-am/ux/product-components/compare/v3.6.4...v3.6.5) (2023-06-06)
2
+
3
+
4
+ ### Fix
5
+
6
+ * use recommended product API (CX16-9278) ([28a5f29](https://code.tls.nuskin.io/ns-am/ux/product-components/commit/28a5f296474ac0bae22de726dcd39afae9b771a0))
7
+
1
8
  ## [3.6.4](https://code.tls.nuskin.io/ns-am/ux/product-components/compare/v3.6.3...v3.6.4) (2023-06-06)
2
9
 
3
10
 
@@ -118,7 +118,7 @@ import Product from "../../models/product";
118
118
  import Price from "./Price.vue";
119
119
  import get from "lodash/get";
120
120
  import {
121
- findProductsByAnyId,
121
+ findProductsById,
122
122
  getProductTranslations
123
123
  } from "../../services/NsProductContentService";
124
124
 
@@ -340,9 +340,10 @@ export default {
340
340
  this.loading = true;
341
341
 
342
342
  try {
343
- const products = await findProductsByAnyId(
343
+ const products = await findProductsById(
344
344
  sliderProductIds,
345
- this.country + "-" + this.language
345
+ this.country,
346
+ this.language
346
347
  );
347
348
 
348
349
  this.products = sliderProductIds
@@ -381,10 +382,7 @@ export default {
381
382
  },
382
383
 
383
384
  initProductTranslations() {
384
- getProductTranslations(
385
- ["addToCartButton"],
386
- this.country + "-" + this.language
387
- )
385
+ getProductTranslations(["addToCartButton"], this.country, this.language)
388
386
  .then(translations => {
389
387
  this.translations = translations;
390
388
  })
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "bomFormat": "CycloneDX",
3
3
  "specVersion": "1.4",
4
- "serialNumber": "urn:uuid:485ea4e5-23b9-4ca8-a800-f9d5d9c534d5",
4
+ "serialNumber": "urn:uuid:e2145c59-f65d-4d51-a466-361d36d2bed4",
5
5
  "version": 1,
6
6
  "metadata": {
7
- "timestamp": "2023-06-06T20:35:01Z",
7
+ "timestamp": "2023-06-06T22:53:20Z",
8
8
  "tools": [
9
9
  {
10
10
  "vendor": "GitLab",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/product-components",
3
- "version": "3.6.4",
3
+ "version": "3.6.5",
4
4
  "description": "Nu Skin Product Components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -33,52 +33,47 @@ import { RunConfigService } from "@nuskin/ns-util";
33
33
  * @property {string} [status.backorderedAvailableDate]
34
34
  */
35
35
 
36
- const productFields = `
37
- id
38
- title
39
- productImages {
40
- url
41
- alt
42
- }
43
- slug
44
- salesLabel
45
- variants {
46
- sku
47
- variantLabel
48
- isExclusive
49
- availableQuantity
50
- productImages {
51
- url
52
- alt
53
- }
54
- pricingJson
55
- price {
56
- currencyCode
57
- retail
58
- retailSales
59
- retailSubscription
60
- wholesale
61
- wholesaleSales
62
- wholesaleSubscription
63
- }
64
- status {
65
- status
66
- isBackordered
67
- backorderedAvailableDate
68
- }
69
- primaryBrand
70
- }
71
- `;
72
-
73
- const CombinedIdsProductsQuery = `
74
- query CombinedIdsProductsQuery($uids: [String!]!, $skus: [String!]!, $locale: String) {
75
- productsBySku(skus: $skus, locale: $locale) {
76
- ${productFields}
77
- }
78
- productsByUid(uids: $uids, locale: $locale) {
79
- ${productFields}
36
+ const ProductsByIdQuery = `
37
+ query ProductsById($ids: [String!]!, $market: String, $language: String) {
38
+ productsById(ids: $ids, market: $market, language: $language, quantity: 1) {
39
+ products {
40
+ id
41
+ title
42
+ productImages {
43
+ url
44
+ alt
45
+ }
46
+ slug
47
+ salesLabel
48
+ variants {
49
+ sku
50
+ variantLabel
51
+ isExclusive
52
+ availableQuantity
53
+ productImages {
54
+ url
55
+ alt
56
+ }
57
+ pricingJson
58
+ price {
59
+ currencyCode
60
+ retail
61
+ retailSales
62
+ retailSubscription
63
+ wholesale
64
+ wholesaleSales
65
+ wholesaleSubscription
66
+ }
67
+ status {
68
+ status
69
+ isBackordered
70
+ backorderedAvailableDate
71
+ }
72
+ primaryBrand
73
+ }
80
74
  }
81
75
  }
76
+ }
82
77
  `;
83
78
 
84
79
  /**
@@ -86,8 +81,8 @@ const CombinedIdsProductsQuery = `
86
81
  * @returns {string}
87
82
  */
88
83
  const productTranslationsQuery = fields => `
89
- query ProductTranslationsQuery($locale: String) {
90
- productTranslations(locale: $locale) {
84
+ query ProductTranslationsQuery($market: String, $language: String) {
85
+ pdpStrings(market: $market, language: $language) {
91
86
  ${fields.join("\n")}
92
87
  }
93
88
  }
@@ -99,55 +94,54 @@ function getProductGraphqlUrl() {
99
94
 
100
95
  switch (env) {
101
96
  case "dev":
102
- return "https://devapi.cloud.nuskin.com/cs-product-graphql/v1";
97
+ return "https://test.nuskin.com/product-api/graphql";
103
98
  case "stage":
104
99
  case "test":
105
- return "https://testapi.cloud.nuskin.com/cs-product-graphql/v1";
100
+ return "https://test.nuskin.com/product-api/graphql";
106
101
  case "unknown":
107
102
  case "prod":
108
103
  default:
109
- return "https://api.cloud.nuskin.com/cs-product-graphql/v1";
104
+ return "https://www.nuskin.com/product-api/graphql";
110
105
  }
111
106
  }
112
107
 
113
108
  /**
114
109
  * Retrieves product data for the given SKUs and/or product UIDs
115
110
  * @param {string[]} ids Product IDs; can be SKUs and/or UIDs
116
- * @param {string} csLocale Contentstack locale code (e.g. "US-en")
111
+ * @param {string} market Market country code
112
+ * @param {string} language Market language code
117
113
  * @return {Promise<ProductData[]>}
118
114
  */
119
- export async function findProductsByAnyId(ids, csLocale) {
115
+ export async function findProductsById(ids, market, language) {
120
116
  const url = getProductGraphqlUrl();
121
117
 
122
- const skus = ids.filter(id => /^\d{8}$/.test(id));
123
- const uids = ids.filter(id => /^blt[0-9a-f]{16}$/.test(id));
124
-
125
118
  const response = await axios.post(url, {
126
- query: CombinedIdsProductsQuery,
127
- variables: { uids, skus, locale: csLocale }
119
+ query: ProductsByIdQuery,
120
+ variables: { ids, market, language }
128
121
  });
129
122
 
130
- if (!response.data) return [];
131
-
132
- const uidProducts = response.data.data.productsByUid || [];
133
- const skuProducts = response.data.data.productsBySku || [];
123
+ if (!response.data || !response.data.data) return [];
134
124
 
135
- return uidProducts.concat(skuProducts);
125
+ return response.data.data.productsById.products;
136
126
  }
137
127
 
138
128
  /**
139
129
  * @param {string[]} fields Product string fields to get
140
- * @param {string} csLocale Contentstack locale code (e.g. "US-en")
130
+ * @param {string} market Market country code
131
+ * @param {string} language Market language code
141
132
  */
142
- export async function getProductTranslations(fields, csLocale) {
133
+ export async function getProductTranslations(fields, market, language) {
134
+ // If no fields are specified, don't bother attempting an API query
135
+ if (fields.length === 0) return {};
136
+
143
137
  const url = getProductGraphqlUrl();
144
138
  const query = productTranslationsQuery(fields);
145
139
 
146
140
  const response = await axios.post(url, {
147
141
  query,
148
- variables: { locale: csLocale }
142
+ variables: { market, language }
149
143
  });
150
144
 
151
145
  if (!response.data || !response.data.data) return {};
152
- return response.data.data.productTranslations || {};
146
+ return response.data.data.pdpStrings || {};
153
147
  }