Skip to content

Commit 0f1fc6a

Browse files
authored
Merge pull request #327 from contentstack/fix/staging-merge-cnonflicts
Fix/staging merge cnonflicts
2 parents f2c7adc + 0af5062 commit 0f1fc6a

File tree

10 files changed

+134
-305
lines changed

10 files changed

+134
-305
lines changed

.github/workflows/issues-jira.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Create Jira Ticket for Github Issue
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
issue-jira:
9+
runs-on: ubuntu-latest
10+
steps:
11+
12+
- name: Login to Jira
13+
uses: atlassian/gajira-login@master
14+
env:
15+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
16+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
17+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
18+
19+
- name: Create Jira Issue
20+
id: create_jira
21+
uses: atlassian/gajira-create@master
22+
with:
23+
project: ${{ secrets.JIRA_PROJECT }}
24+
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }}
25+
summary: Github | Issue | ${{ github.event.repository.name }} | ${{ github.event.issue.title }}
26+
description: |
27+
*GitHub Issue:* ${{ github.event.issue.html_url }}
28+
29+
*Description:*
30+
${{ github.event.issue.body }}
31+
fields: "${{ secrets.ISSUES_JIRA_FIELDS }}"

.github/workflows/jira.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/policy-scan.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Checks the security policy and configurations
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
jobs:
6+
security-policy:
7+
if: github.event.repository.visibility == 'public'
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
shell: bash
12+
steps:
13+
- uses: actions/checkout@master
14+
- name: Checks for SECURITY.md policy file
15+
run: |
16+
if ! [[ -f "SECURITY.md" || -f ".github/SECURITY.md" ]]; then exit 1; fi
17+
security-license:
18+
if: github.event.repository.visibility == 'public'
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: bash
23+
steps:
24+
- uses: actions/checkout@master
25+
- name: Checks for License file
26+
run: |
27+
if ! [[ -f "LICENSE" || -f "License.txt" || -f "LICENSE.md" ]]; then exit 1; fi

.github/workflows/sast-scan.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Changelog
22

3+
34
## [v1.20.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.20.2) (2025-04-21)
45
- Fix
5-
- Handle the sanity tests when ENVs are not provided
6+
- Handle api_version chaining and ensure backward compatibility
7+
68
## [v1.20.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.20.1) (2025-04-07)
79
- Fix
810
- Ensure 'api' is replaced with 'app' in uiHostName regardless of position

lib/entity.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu
4545
const response = await http.post(url, httpBody, headers)
4646
if (response.data) {
4747
const data = response.data || {}
48+
if (http?.httpClientParams?.headers?.api_version) {
49+
delete http.httpClientParams.headers.api_version
50+
}
51+
if (headers?.api_version) {
52+
delete headers.api_version
53+
}
4854
if (headers) {
4955
data.stackHeaders = headers
5056
}
@@ -82,8 +88,7 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me
8288
export const create = ({ http, params }) => {
8389
return async function (data, param) {
8490
this.stackHeaders = {
85-
...this.stackHeaders,
86-
...(http.httpClientParams.headers?.api_version && { api_version: http.httpClientParams.headers.api_version })
91+
...this.stackHeaders
8792
}
8893
const headers = {
8994
headers: {
@@ -259,6 +264,9 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {
259264

260265
export function parseData (response, stackHeaders, contentTypeUID, taxonomyUid, http) {
261266
const data = response.data || {}
267+
if (stackHeaders && 'api_version' in stackHeaders) {
268+
delete stackHeaders.api_version
269+
}
262270
if (stackHeaders) {
263271
data.stackHeaders = stackHeaders
264272
}

lib/stack/globalField/index.js

Lines changed: 7 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import { query, upload, parseData } from '../../entity'
2+
import { create, update, deleteEntity, fetch, query, upload, parseData } from '../../entity'
33
import error from '../../core/contentstackError'
44
import FormData from 'form-data'
55
import { createReadStream } from 'fs'
@@ -11,10 +11,8 @@ import { createReadStream } from 'fs'
1111

1212
export function GlobalField (http, data = {}) {
1313
this.stackHeaders = data.stackHeaders
14-
this.apiVersion = data.api_version || undefined
15-
16-
if (this.apiVersion) {
17-
this.stackHeaders.api_version = this.apiVersion
14+
if (data.api_version) {
15+
this.stackHeaders.api_version = data.api_version
1816
}
1917
this.urlPath = `/global_fields`
2018

@@ -39,89 +37,7 @@ export function GlobalField (http, data = {}) {
3937
* .then((globalField) => console.log(globalField))
4038
*
4139
*/
42-
this.update = async (config) => {
43-
try {
44-
// Add `api_version` to headers if `this.apiVersion` is defined
45-
if (this.apiVersion) {
46-
this.stackHeaders.api_version = this.apiVersion
47-
}
48-
const headers = {
49-
headers: {
50-
...cloneDeep(this.stackHeaders)
51-
}
52-
}
53-
const response = await http.put(`${this.urlPath}`, config, headers)
54-
// Remove `api_version` from headers after fetching data
55-
if (this.apiVersion) {
56-
delete this.stackHeaders.api_version
57-
}
58-
const data = response.data
59-
if (data) {
60-
if (this.stackHeaders) {
61-
data.stackHeaders = this.stackHeaders
62-
}
63-
return data
64-
} else {
65-
throw error(response)
66-
}
67-
} catch (err) {
68-
throw error(err)
69-
}
70-
}
71-
72-
/**
73-
* @description The Update GlobalField call lets you update the name and description of an existing GlobalField.
74-
* @memberof GlobalField
75-
* @func update
76-
* @returns {Promise<GlobalField.GlobalField>} Promise for GlobalField instance
77-
* @example
78-
* import * as contentstack from '@contentstack/management'
79-
* const client = contentstack.client()
80-
* const data = {
81-
* "global_field": {
82-
* "title": "Nested Global Field33",
83-
* "uid": "nested_global_field33",
84-
* "schema": [
85-
* {
86-
* "data_type": "text",
87-
* "display_name": "Single Line Textbox",
88-
* "uid": "single_line"
89-
* },
90-
* {
91-
* "data_type": "global_field",
92-
* "display_name": "Global",
93-
* "uid": "global_field",
94-
* "reference_to": "nested_global_field_123"
95-
* }
96-
* ]
97-
* }
98-
* }
99-
* client.stack({ api_key: 'api_key'}).globalField('global_field_uid').updateNestedGlobalField(data, { headers: { api_version: '3.2' }})
100-
* .then((globalField) => {
101-
console.log(globalField)
102-
* })
103-
*/
104-
this.updateNestedGlobalField = async (config, headers = {}) => {
105-
const apiVersion = { api_version: '3.2' }
106-
this.stackHeaders = { ...this.stackHeaders, ...apiVersion, ...headers }
107-
try {
108-
const headers = {
109-
headers: { ...cloneDeep(this.stackHeaders) }
110-
}
111-
const response = await http.put(`${this.urlPath}`, config, headers)
112-
const data = response.data
113-
if (data) {
114-
if (this.stackHeaders) {
115-
data.stackHeaders = this.stackHeaders
116-
}
117-
return data
118-
} else {
119-
throw error(response)
120-
}
121-
} catch (err) {
122-
throw error(err)
123-
}
124-
}
40+
this.update = update(http, 'global_field')
12541

12642
/**
12743
* @description The Delete GlobalField call is used to delete an existing GlobalField permanently from your Stack.
@@ -135,38 +51,7 @@ export function GlobalField (http, data = {}) {
13551
* client.stack({ api_key: 'api_key'}).globalField('global_field_uid').delete()
13652
* .then((response) => console.log(response.notice))
13753
*/
138-
this.delete = async () => {
139-
const param = {}
140-
try {
141-
// Add `api_version` to headers if `this.apiVersion` is defined
142-
if (this.apiVersion) {
143-
this.stackHeaders.api_version = this.apiVersion
144-
}
145-
const headers = {
146-
headers: {
147-
...cloneDeep(this.stackHeaders)
148-
},
149-
params: {
150-
...cloneDeep(param)
151-
}
152-
}
153-
const response = await http.delete(this.urlPath, headers)
154-
if (this.apiVersion) {
155-
delete this.stackHeaders.api_version
156-
}
157-
const data = response.data
158-
if (data) {
159-
if (this.stackHeaders) {
160-
data.stackHeaders = this.stackHeaders
161-
}
162-
return data
163-
} else {
164-
throw error(response)
165-
}
166-
} catch (err) {
167-
throw error(err)
168-
}
169-
}
54+
this.delete = deleteEntity(http)
17055

17156
/**
17257
* @description The fetch GlobalField call fetches GlobalField details.
@@ -181,33 +66,7 @@ export function GlobalField (http, data = {}) {
18166
* .then((globalField) => console.log(globalField))
18267
*
18368
*/
184-
this.fetch = async function (param = {}) {
185-
try {
186-
if (this.apiVersion) {
187-
this.stackHeaders.api_version = this.apiVersion
188-
}
189-
const headers = {
190-
headers: {
191-
...cloneDeep(this.stackHeaders)
192-
},
193-
params: {
194-
...cloneDeep(param)
195-
}
196-
}
197-
const response = await http.get(this.urlPath, headers)
198-
const data = response.data
199-
if (data) {
200-
if (this.stackHeaders) {
201-
data.stackHeaders = this.stackHeaders
202-
}
203-
return data
204-
} else {
205-
throw error(response)
206-
}
207-
} catch (err) {
208-
throw error(err)
209-
}
210-
}
69+
this.fetch = fetch(http, 'global_field')
21170
} else {
21271
/**
21372
* @description The Create a GlobalField call creates a new globalField in a particular stack of your Contentstack account.
@@ -230,30 +89,7 @@ export function GlobalField (http, data = {}) {
23089
* client.stack().globalField().create({ global_field })
23190
* .then((globalField) => console.log(globalField))
23291
*/
233-
this.create = async (payload) => {
234-
try {
235-
if (this.apiVersion) {
236-
this.stackHeaders.api_version = this.apiVersion
237-
}
238-
const headers = {
239-
headers: {
240-
...cloneDeep(this.stackHeaders)
241-
}
242-
}
243-
const response = await http.post(`${this.urlPath}`, payload, headers)
244-
const data = response.data
245-
if (data) {
246-
if (this.stackHeaders) {
247-
data.stackHeaders = this.stackHeaders
248-
}
249-
return data
250-
} else {
251-
throw error(response)
252-
}
253-
} catch (err) {
254-
return error(err)
255-
}
256-
}
92+
this.create = create({ http: http })
25793

25894
/**
25995
* @description The Query on GlobalField will allow to fetch details of all or specific GlobalField

0 commit comments

Comments
 (0)