Skip to content

Commit 99cbc64

Browse files
Feat/cs 44592 variant group (#4)
* sca-scan.yml * jira.yml * sast-scan.yml * secrets-scan.yml * codeql-analysis.yml * Added variant support * Removed CodeQL github action in private repo * Updated details * Added Variants support with content type uid * Updated the dependency packages version * moved slack/bolt package to devDependencies * Changed node version to 18 * Fixed errors from merge conflits --------- Co-authored-by: Aravind Kumar <[email protected]>
1 parent dcbeb49 commit 99cbc64

27 files changed

+1887
-299
lines changed

.github/workflows/jira.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
types: [opened]
55
jobs:
6-
security:
6+
security-jira:
77
if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}}
88
runs-on: ubuntu-latest
99
steps:
@@ -26,3 +26,8 @@ jobs:
2626
PR: ${{ github.event.pull_request.html_url }}
2727
2828
fields: "${{ secrets.JIRA_FIELDS }}"
29+
- name: Transition issue
30+
uses: atlassian/gajira-transition@v3
31+
with:
32+
issue: ${{ steps.create.outputs.issue }}
33+
transition: ${{ secrets.JIRA_TRANSITION }}

.github/workflows/sast-scan.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: SAST Scan
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
jobs:
6+
security-sast:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Semgrep Scan
11+
run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto

.github/workflows/sca-scan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
types: [opened, synchronize, reopened]
55
jobs:
6-
security:
6+
security-sca:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@master

.github/workflows/secrets-scan.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Secrets Scan
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
jobs:
6+
security-secrets:
7+
runs-on: ubuntu-latest
8+
if: ${{ github.base_ref == 'main' || github.base_ref == 'master' }}
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Install Expect, jq and Python
15+
run: sudo apt-get update --fix-missing && sudo apt-get install -y expect jq python3 python3-pip wkhtmltopdf
16+
17+
- name: Install Python packages
18+
run: pip install pandas json2html tabulate
19+
20+
- name: Install Talisman
21+
run: |
22+
curl --silent https://raw.githubusercontent.com/thoughtworks/talisman/v1.32.0/install.sh > install.bash
23+
chmod +x install.bash
24+
./install.bash
25+
26+
- name: Run Talisman
27+
id: run_talisman
28+
run: /usr/local/bin/talisman --scan
29+
continue-on-error: true
30+
31+
- name: Convert JSON to HTML
32+
run: |
33+
python3 -c "
34+
import json
35+
import os
36+
from json2html import *
37+
with open('talisman_report/talisman_reports/data/report.json') as f:
38+
data = json.load(f)
39+
html = json2html.convert(json = data)
40+
os.makedirs('talisman_html_report', exist_ok=True)
41+
with open('talisman_html_report/report.html', 'w') as f:
42+
f.write(html)
43+
" && wkhtmltopdf talisman_html_report/report.html talisman_report.pdf
44+
45+
- name: Upload Report
46+
id: upload_report
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: talisman-report-pdf
50+
path: talisman_report.pdf
51+
52+
- name: Check the status of talisman scan
53+
run: |
54+
# if [[ ${{ steps.run_talisman.outcome }} == "success" ]]; then exit 0; else echo "Download the Talisman scan report from Artifact: ${{ steps.upload_report.outputs.artifact-url }}" && exit 1; fi
55+
echo "Download the Talisman scan report from Artifact: ${{ steps.upload_report.outputs.artifact-url }}";

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
2-
## [v1.16.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.16.0) (2024-04-02)
2+
3+
## [v1.16.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.16.0) (2024-04-16)
34
- Feature
4-
- Variants support added
5+
- Variants Group support added
6+
57
## [v1.15.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.3) (2024-02-16)
68
- Fix
79
- Fix for updating entry

lib/stack/index.js

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { BranchAlias } from './branchAlias'
2020
import { AuditLog } from './auditlog'
2121
import { Taxonomy } from './taxonomy'
2222
import { ManagementToken } from './managementToken'
23+
import { VariantGroup } from './variantGroup'
2324

2425
/**
2526
* A stack is a space that stores the content of a project (a web or mobile property). Within a stack, you can create content structures, content entries, users, etc. related to the project. Read more about <a href='https://www.contentstack.com/docs/guide/stack'>Stacks</a>.
@@ -676,6 +677,28 @@ export function Stack (http, data) {
676677
}
677678
}
678679

680+
/**
681+
* @description Variant Group allows you to create a variant groups.
682+
* @param {String} uid The UID of the variant group you want to get details.
683+
* @returns {VariantGroup} Instance of VariantGroup.
684+
* @example
685+
* import * as contentstack from '@contentstack/management'
686+
* const client = contentstack.client()
687+
*
688+
* client.stack({ api_key: 'api_key'}).variantGroup().create()
689+
* .then((variant_group) => console.log(variant_group))
690+
*
691+
* client.stack({ api_key: 'api_key'}).variantGroup('variant_group_uid').fetch()
692+
* .then((variant_group) => console.log(variant_group))
693+
*/
694+
this.variantGroup = (variantGroupUid = null) => {
695+
const data = { stackHeaders: this.stackHeaders }
696+
if (variantGroupUid) {
697+
data.variant_group = { uid: variantGroupUid }
698+
}
699+
return new VariantGroup(http, data)
700+
}
701+
679702
/**
680703
* @description A role is a collection of permissions that will be applicable to all the users who are assigned this role.
681704
* @memberof Stack

lib/stack/variantGroup/index.js

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import { create, update, deleteEntity, fetch, query } from '../../entity'
3+
import { Variants } from './variants/index'
4+
5+
/**
6+
* Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language. This feature allows you to set up multilingual websites and cater to a wide variety of audience by serving content in their local language(s). Read more about <a href='https://www.contentstack.com/docs/developers/multi-language-content'>VariantGroups</a>.
7+
* @namespace VariantGroup
8+
*/
9+
10+
export function VariantGroup (http, data = {}) {
11+
this.stackHeaders = data.stackHeaders
12+
this.urlPath = `/variant_groups`
13+
14+
if (data.variant_group) {
15+
Object.assign(this, cloneDeep(data.variant_group))
16+
this.urlPath += `/${this.uid}`
17+
/**
18+
* @description The Update VariantGroup call lets you update the name and description of an existing VariantGroup.
19+
* @memberof VariantGroup
20+
* @func update
21+
* @returns {Promise<VariantGroup.VariantGroup>} Promise for VariantGroup instance
22+
* @example
23+
* import * as contentstack from '@contentstack/management'
24+
* const client = contentstack.client()
25+
*
26+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').fetch()
27+
* .then((variant_group) => {
28+
* variant_group.name = 'test'
29+
* variant_group.content_types = ['iphone_product_page']
30+
* return variant_group.update()
31+
* })
32+
* .then((variant_group) => console.log(variant_group))
33+
*
34+
*/
35+
this.update = update(/* The `http` parameter is being used as a dependency injection to make HTTP
36+
requests within the `VariantGroup` and `VariantGroupCollection` functions.
37+
It allows the functions to interact with an external API or server to
38+
perform operations such as creating, updating, deleting, fetching, or
39+
querying variant groups. */
40+
/* The `http` parameter in the `VariantGroup` function is being used to make
41+
HTTP requests to interact with the Contentstack API. It is likely being
42+
used to send requests to create, update, delete, fetch, or query variant
43+
groups and their related entities. */
44+
http, 'variant_group')
45+
46+
/**
47+
* @description The Delete VariantGroup call is used to delete an existing VariantGroup permanently from your Stack.
48+
* @memberof VariantGroup
49+
* @func delete
50+
* @returns {Object} Response Object.
51+
* @example
52+
* import * as contentstack from '@contentstack/management'
53+
* const client = contentstack.client()
54+
*
55+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').delete()
56+
* .then((response) => console.log(response.notice))
57+
*/
58+
this.delete = deleteEntity(http)
59+
60+
/**
61+
* @description The fetch VariantGroup call fetches VariantGroup details.
62+
* @memberof VariantGroup
63+
* @func fetch
64+
* @returns {Promise<VariantGroup.VariantGroup>} Promise for VariantGroup instance
65+
* @param {Int} version Enter the unique ID of the content type of which you want to retrieve the details. The UID is generated based on the title of the content type. The unique ID of a content type is unique across a stack.
66+
* @example
67+
* import * as contentstack from '@contentstack/management'
68+
* const client = contentstack.client()
69+
*
70+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').fetch()
71+
* .then((variant_group) => console.log(variant_group))
72+
*
73+
*/
74+
this.fetch = fetch(http, 'variant_group')
75+
76+
/**
77+
* @description Content type defines the structure or schema of a page or a section of your web or mobile property.
78+
* @param {String} uid The UID of the ContentType you want to get details.
79+
* @returns {ContenType} Instace of ContentType.
80+
* @example
81+
* import * as contentstack from '@contentstack/management'
82+
* const client = contentstack.client()
83+
*
84+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').variants('variant_uid').fetch()
85+
* .then((Variants) => console.log(Variants))
86+
*/
87+
this.variants = (uid = null) => {
88+
const data = { stackHeaders: this.stackHeaders }
89+
data.variant_group_uid = this.uid
90+
if (uid) {
91+
data.variants = { uid: uid }
92+
}
93+
return new Variants(http, data)
94+
}
95+
96+
} else {
97+
/**
98+
* @description The Create a variant group call creates a new variant group in a particular stack of your Contentstack account.
99+
* @memberof VariantGroup
100+
* @func create
101+
* @returns {Promise<VariantGroup.VariantGroup>} Promise for VariantGroup instance
102+
*
103+
* @example
104+
* import * as contentstack from '@contentstack/management'
105+
* const client = contentstack.client()
106+
* const variant_group = {
107+
* "name": "Colors",
108+
* "content_types": [
109+
* "iphone_product_page"
110+
* ],
111+
* "uid": "iphone_color_white", // optional
112+
* }
113+
* client.stack().VariantGroup().create({ variant_group } )
114+
* .then((variant_group) => console.log(variant_group))
115+
*/
116+
this.create = create({ http: http })
117+
118+
/**
119+
* @description The Query on Variant Groups will allow to fetch details of all or specific Variant Groups
120+
* @memberof VariantGroup
121+
* @func query
122+
* @param {Boolean} include_count Set this to 'true' to include in response the total count of content types available in your stack.
123+
* @returns {Array<VariantGroup>} Array of ContentTyoe.
124+
*
125+
* @example
126+
* import * as contentstack from '@contentstack/management'
127+
* const client = contentstack.client()
128+
*
129+
* client.stack(api_key).VariantGroup().query({ query: { code: 'variant_group-code' } }).find()
130+
* .then((variant_groups) => console.log(variant_groups))
131+
*/
132+
this.query = query({ http: http, wrapperCollection: VariantGroupCollection })
133+
}
134+
return this
135+
}
136+
137+
export function VariantGroupCollection (http, data) {
138+
const obj = cloneDeep(data.variant_groups) || []
139+
const variant_groupCollection = obj.map((userdata) => {
140+
return new VariantGroup(http, { variant_group: userdata, stackHeaders: data.stackHeaders })
141+
})
142+
return variant_groupCollection
143+
}
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import { create, update, fetch, query } from '../../../entity'
3+
4+
/**
5+
* Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language. This feature allows you to set up multilingual websites and cater to a wide variety of audience by serving content in their local language(s). Read more about <a href='https://www.contentstack.com/docs/developers/multi-language-content'>VariantGroups</a>.
6+
* @namespace Variants
7+
*/
8+
9+
export function Variants (http, data = {}) {
10+
this.stackHeaders = data.stackHeaders
11+
this.variant_group_uid = data.variant_group_uid
12+
this.urlPath = `/variant_groups/${this.variant_group_uid}/variants`
13+
14+
if (data.variants) {
15+
Object.assign(this, cloneDeep(data.variants))
16+
this.urlPath += `/${this.uid}`
17+
/**
18+
* @description The Update Variants call lets you update the name and description of an existing Variants.
19+
* @memberof Variants
20+
* @func update
21+
* @returns {Promise<Variants.Variants>} Promise for Variants instance
22+
* @example
23+
* import * as contentstack from '@contentstack/management'
24+
* const client = contentstack.client()
25+
*
26+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').variants('variant_uid').fetch()
27+
* .then((variants) => {
28+
* variants.name = 'test'
29+
* variants.content_types = ['iphone_product_page']
30+
* return variants.update()
31+
* })
32+
* .then((variants) => console.log(variants))
33+
*
34+
*/
35+
this.update = update(http, 'variants')
36+
37+
/**
38+
* @description The fetch Variants call fetches Variants details.
39+
* @memberof Variants
40+
* @func fetch
41+
* @returns {Promise<Variants.Variants>} Promise for Variants instance
42+
* @param {Int} version Enter the unique ID of the content type of which you want to retrieve the details. The UID is generated based on the title of the content type. The unique ID of a content type is unique across a stack.
43+
* @example
44+
* import * as contentstack from '@contentstack/management'
45+
* const client = contentstack.client()
46+
*
47+
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').variants('variant_uid').fetch()
48+
* .then((variants) => console.log(variants))
49+
*
50+
*/
51+
this.fetch = fetch(http, 'variants')
52+
} else {
53+
/**
54+
* @description The Create a variant group call creates a new variant group in a particular stack of your Contentstack account.
55+
* @memberof Variants
56+
* @func create
57+
* @returns {Promise<Variants.Variants>} Promise for Variants instance
58+
*
59+
* @example
60+
* import * as contentstack from '@contentstack/management'
61+
* const client = contentstack.client()
62+
* const data = {
63+
* "uid": "iphone_color_white", // optional
64+
* "name": "White",
65+
* "personalize_metadata": { // optional sent from personalize while creating variant
66+
* "experience_uid": "exp1",
67+
* "experience_short_uid": "expShortUid1",
68+
* "project_uid": "project_uid1",
69+
* "variant_short_uid": "variantShort_uid1"
70+
* },
71+
* }
72+
* client.stack().VariantGroup('variant_group_uid').variants().create({ data } )
73+
* .then((variants) => console.log(variants))
74+
*/
75+
this.create = create({ http: http })
76+
77+
/**
78+
* @description The Query on Variant Groups will allow to fetch details of all or specific Variant Groups
79+
* @memberof Variants
80+
* @func query
81+
* @param {Boolean} include_count Set this to 'true' to include in response the total count of content types available in your stack.
82+
* @returns {Array<VariantGroup>} Array of ContentTyoe.
83+
*
84+
* @example
85+
* import * as contentstack from '@contentstack/management'
86+
* const client = contentstack.client()
87+
88+
* client.stack(api_key).VariantGroup('variant_group_uid').variants().query({ query: { name: 'white' } }).find()
89+
* .then((variant_groups) => console.log(variant_groups))
90+
*/
91+
this.query = query({ http: http, wrapperCollection: VariantsCollection })
92+
}
93+
return this
94+
}
95+
96+
export function VariantsCollection (http, data) {
97+
const obj = cloneDeep(data.variants) || []
98+
const variantsCollection = obj.map((userdata) => {
99+
return new Variants(http, { variants: userdata, variant_group_uid: data.variant_group_uid ,stackHeaders: data.stackHeaders })
100+
})
101+
return variantsCollection
102+
}

0 commit comments

Comments
 (0)