@nuskin/contentstack-lib 1.0.0-pur-1208.2 → 1.0.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/.releaserc +1 -1
- package/README.md +14 -12
- package/__tests__/api.spec.js +0 -37
- package/docs/CHANGELOG.md +1 -1
- package/gl-sbom-npm-yarn.cdx.json +3 -3
- package/package.json +1 -1
- package/src/api.js +7 -0
package/.releaserc
CHANGED
package/README.md
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
# @nuskin/
|
|
1
|
+
# @nuskin/contentstack-lib
|
|
2
2
|
|
|
3
3
|
This project extends the Contentstack delivery sdk, to be shared between the backend (AWS Lambda) and frontend.
|
|
4
4
|
1. It simplifies initializing the Stack object.
|
|
5
5
|
2. It extends the stack with a new function getSingletonEntries most commonly used to get translations
|
|
6
6
|
3. CONTENTSTACK DOES NOT MERGE COMMON ENGLISH WITH US-en STRINGS. FALLBACK IN CONTENTSTACK DOES NOT WORK AS EXPECTED.
|
|
7
7
|
getSingletonEntries TAKES AN OPTION CALLED mergeWithFallback. IF THAT IS SET TO TRUE THEN IT WILL MERGE THE RESULTS
|
|
8
|
-
FOR COMMON SPANISH AND MX-es FOR EXAMPLE.
|
|
8
|
+
FOR COMMON SPANISH AND MX-es FOR EXAMPLE.
|
|
9
9
|
4. getSingletonEntries also allows you to convert the keys from snake case to camel case.
|
|
10
10
|
|
|
11
11
|
## Installing
|
|
12
12
|
|
|
13
|
-
Update the .npmrc in your project to use the nexus registry @ns:registry=https://nexus3.nuskin.net/repository/npm-internal/
|
|
14
|
-
|
|
15
13
|
Usng npm:
|
|
16
14
|
|
|
17
15
|
```bash
|
|
18
|
-
npm install @
|
|
16
|
+
npm install @nuskin/contentstack-lib
|
|
19
17
|
```
|
|
20
18
|
|
|
21
19
|
Usng yarn:
|
|
22
20
|
|
|
23
21
|
```bash
|
|
24
|
-
yarn add @
|
|
22
|
+
yarn add @nuskin/contentstack-lib
|
|
25
23
|
```
|
|
26
24
|
|
|
27
25
|
## Example usage
|
|
28
26
|
|
|
29
27
|
```js
|
|
30
|
-
const { getStack } = require('@
|
|
28
|
+
const { getStack, init } = require('@nuskin/contentstack-lib')
|
|
29
|
+
|
|
30
|
+
// Initialize the module with params needed for connecting to contentstack
|
|
31
|
+
// These fields can be gotten from the parameter store
|
|
32
|
+
init({env, apiKey, deliveryToken})
|
|
31
33
|
|
|
32
|
-
//
|
|
33
|
-
const Stack = getStack(
|
|
34
|
+
// Call getStack to get the stack object
|
|
35
|
+
const Stack = getStack()
|
|
34
36
|
|
|
35
37
|
// get all languages
|
|
36
38
|
const languages = await Stack.ContentType('supported_language').Query().toJSON().find();
|
|
@@ -44,7 +46,7 @@ const translations = Stack.getStrings({
|
|
|
44
46
|
contentTypes: ['checkout_adr_strings', 'checkout_cart_strings'], // List of content types you want to get translations for
|
|
45
47
|
language: 'en',
|
|
46
48
|
country: 'US',
|
|
47
|
-
merge: true // Will combine checkout_adr_strings and checkout_cart_strings object with single list of strings
|
|
49
|
+
merge: true // Will combine checkout_adr_strings and checkout_cart_strings object with single list of strings
|
|
48
50
|
});
|
|
49
51
|
|
|
50
52
|
// Use this function instead to get your translations
|
|
@@ -65,12 +67,12 @@ const [
|
|
|
65
67
|
mergeWithFallback: true
|
|
66
68
|
});
|
|
67
69
|
|
|
68
|
-
// We could possibly add functionality to return the list of regions markets and languages in a single object structure
|
|
70
|
+
// We could possibly add functionality to return the list of regions markets and languages in a single object structure
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
## Resources
|
|
72
74
|
|
|
73
|
-
- https://code.tls.nuskin.io/ns-am/utility/npm/
|
|
75
|
+
- https://code.tls.nuskin.io/ns-am/utility/npm/contentstack-lib
|
|
74
76
|
|
|
75
77
|
## License
|
|
76
78
|
|
package/__tests__/api.spec.js
CHANGED
|
@@ -48,43 +48,6 @@ const mockResults = () => {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
describe("ContentstackApi", () => {
|
|
51
|
-
// test("retries with just the language if can't get strings for country", async () => {
|
|
52
|
-
// mockPromiseResult.mockClear();
|
|
53
|
-
// mockPromiseResult.mockRejectedValueOnce(new Error("Failed"));
|
|
54
|
-
// mockResults();
|
|
55
|
-
// const {getStack} = require('../src/api');
|
|
56
|
-
// const Stack = getStack('dev');
|
|
57
|
-
// await Stack.getStrings({contentTypes: ['checkout_adr_strings', 'checkout_cart_strings'], language: 'en', country: 'US', merge: true});
|
|
58
|
-
// expect(mockPromiseResult).toHaveBeenCalledTimes(4);
|
|
59
|
-
// });
|
|
60
|
-
|
|
61
|
-
// test("getStrings for multiple contentTypes", async () => {
|
|
62
|
-
// mockResults();
|
|
63
|
-
// const {getStack} = require('../src/api');
|
|
64
|
-
// const Stack = getStack('dev');
|
|
65
|
-
// const strings = await Stack.getStrings({contentTypes: ['checkout_adr_strings', 'checkout_cart_strings'], language: 'en', merge: false});
|
|
66
|
-
// expect(strings).toStrictEqual(stringsResult);
|
|
67
|
-
// });
|
|
68
|
-
|
|
69
|
-
// test("getStrings merged", async () => {
|
|
70
|
-
// mockResults();
|
|
71
|
-
// const {getStack} = require('../src/api');
|
|
72
|
-
// const Stack = getStack('dev');
|
|
73
|
-
// const strings = await Stack.getStrings({contentTypes: ['checkout_adr_strings', 'checkout_cart_strings'], language: 'en', merge: true});
|
|
74
|
-
// expect(strings).toStrictEqual(mergedResult);
|
|
75
|
-
// });
|
|
76
|
-
|
|
77
|
-
// test("getStrings throws error", async () => {
|
|
78
|
-
// mockResults();
|
|
79
|
-
// const {getStack} = require('../src/api');
|
|
80
|
-
// const Stack = getStack('dev');
|
|
81
|
-
// try {
|
|
82
|
-
// await Stack.getStrings({});
|
|
83
|
-
// } catch(err) {
|
|
84
|
-
// expect(err).toStrictEqual(new Error('Call to getStrings: options.contentTypes and language are required'));
|
|
85
|
-
// }
|
|
86
|
-
// })
|
|
87
|
-
|
|
88
51
|
test("getSingletonEntries", async () => {
|
|
89
52
|
mockResults();
|
|
90
53
|
const {getStack} = require('../src/api');
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 1.0.0 (2024-09-30)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bomFormat": "CycloneDX",
|
|
3
3
|
"specVersion": "1.4",
|
|
4
|
-
"serialNumber": "urn:uuid:
|
|
4
|
+
"serialNumber": "urn:uuid:701c511f-f50c-425c-8761-df965916315e",
|
|
5
5
|
"version": 1,
|
|
6
6
|
"metadata": {
|
|
7
|
-
"timestamp": "2024-09-
|
|
7
|
+
"timestamp": "2024-09-30T15:46:41Z",
|
|
8
8
|
"tools": [
|
|
9
9
|
{
|
|
10
10
|
"vendor": "GitLab",
|
|
11
11
|
"name": "Gemnasium",
|
|
12
|
-
"version": "5.7.
|
|
12
|
+
"version": "5.7.2"
|
|
13
13
|
}
|
|
14
14
|
],
|
|
15
15
|
"authors": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuskin/contentstack-lib",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "This project contains configuration and api code to access Contentstack, to be shared between the backend (AWS Lambda) and frontend (Vue, etc).",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
package/src/api.js
CHANGED
|
@@ -169,6 +169,13 @@ function getStack() {
|
|
|
169
169
|
return Stack;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* init needs to be called first before getStack can be called
|
|
174
|
+
*
|
|
175
|
+
* @param {string} env - environment for the getStack call
|
|
176
|
+
* @param {stirng} apiKey - api_key for the getStack call
|
|
177
|
+
* @param {string} deliveryToken - delivery_token for the getStack call
|
|
178
|
+
*/
|
|
172
179
|
function init({env, apiKey, deliveryToken}) {
|
|
173
180
|
environment = env;
|
|
174
181
|
api_key = apiKey;
|