Skip to content

back merge #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/issues-jira.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Create Jira Ticket for Github Issue

on:
issues:
types: [opened]

jobs:
issue-jira:
runs-on: ubuntu-latest
steps:

- name: Login to Jira
uses: atlassian/gajira-login@master
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}

- name: Create Jira Issue
id: create_jira
uses: atlassian/gajira-create@master
with:
project: ${{ secrets.JIRA_PROJECT }}
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }}
summary: Github | Issue | ${{ github.event.repository.name }} | ${{ github.event.issue.title }}
description: |
*GitHub Issue:* ${{ github.event.issue.html_url }}

*Description:*
${{ github.event.issue.body }}
fields: "${{ secrets.ISSUES_JIRA_FIELDS }}"
33 changes: 0 additions & 33 deletions .github/workflows/jira.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/policy-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Checks the security policy and configurations
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
security-policy:
if: github.event.repository.visibility == 'public'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@master
- name: Checks for SECURITY.md policy file
run: |
if ! [[ -f "SECURITY.md" || -f ".github/SECURITY.md" ]]; then exit 1; fi
security-license:
if: github.event.repository.visibility == 'public'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@master
- name: Checks for License file
run: |
if ! [[ -f "LICENSE" || -f "License.txt" || -f "LICENSE.md" ]]; then exit 1; fi
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog


## [v1.20.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.20.2) (2025-04-21)
- Fix
- Handle api_version chaining and ensure backward compatibility

## [v1.20.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.20.1) (2025-04-07)
- Fix
- Ensure 'api' is replaced with 'app' in uiHostName regardless of position
Expand Down
12 changes: 10 additions & 2 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu
const response = await http.post(url, httpBody, headers)
if (response.data) {
const data = response.data || {}
if (http?.httpClientParams?.headers?.api_version) {
delete http.httpClientParams.headers.api_version
}
if (headers?.api_version) {
delete headers.api_version
}
if (headers) {
data.stackHeaders = headers
}
Expand Down Expand Up @@ -82,8 +88,7 @@ export const upload = async ({ http, urlPath, stackHeaders, formData, params, me
export const create = ({ http, params }) => {
return async function (data, param) {
this.stackHeaders = {
...this.stackHeaders,
...(http.httpClientParams.headers?.api_version && { api_version: http.httpClientParams.headers.api_version })
...this.stackHeaders
}
const headers = {
headers: {
Expand Down Expand Up @@ -259,6 +264,9 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {

export function parseData (response, stackHeaders, contentTypeUID, taxonomyUid, http) {
const data = response.data || {}
if (stackHeaders && 'api_version' in stackHeaders) {
delete stackHeaders.api_version
}
if (stackHeaders) {
data.stackHeaders = stackHeaders
}
Expand Down
178 changes: 7 additions & 171 deletions lib/stack/globalField/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cloneDeep from 'lodash/cloneDeep'
import { query, upload, parseData } from '../../entity'
import { create, update, deleteEntity, fetch, query, upload, parseData } from '../../entity'
import error from '../../core/contentstackError'
import FormData from 'form-data'
import { createReadStream } from 'fs'
Expand All @@ -11,10 +11,8 @@ import { createReadStream } from 'fs'

export function GlobalField (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.apiVersion = data.api_version || undefined

if (this.apiVersion) {
this.stackHeaders.api_version = this.apiVersion
if (data.api_version) {
this.stackHeaders.api_version = data.api_version
}
this.urlPath = `/global_fields`

Expand All @@ -39,89 +37,7 @@ export function GlobalField (http, data = {}) {
* .then((globalField) => console.log(globalField))
*
*/
this.update = async (config) => {
try {
// Add `api_version` to headers if `this.apiVersion` is defined
if (this.apiVersion) {
this.stackHeaders.api_version = this.apiVersion
}
const headers = {
headers: {
...cloneDeep(this.stackHeaders)
}
}
const response = await http.put(`${this.urlPath}`, config, headers)
// Remove `api_version` from headers after fetching data
if (this.apiVersion) {
delete this.stackHeaders.api_version
}
const data = response.data
if (data) {
if (this.stackHeaders) {
data.stackHeaders = this.stackHeaders
}
return data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}

/**
* @description The Update GlobalField call lets you update the name and description of an existing GlobalField.
* @memberof GlobalField
* @func update
* @returns {Promise<GlobalField.GlobalField>} Promise for GlobalField instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const data = {
* "global_field": {
* "title": "Nested Global Field33",
* "uid": "nested_global_field33",
* "schema": [
* {
* "data_type": "text",
* "display_name": "Single Line Textbox",
* "uid": "single_line"
* },
* {
* "data_type": "global_field",
* "display_name": "Global",
* "uid": "global_field",
* "reference_to": "nested_global_field_123"
* }
* ]
* }
* }
* client.stack({ api_key: 'api_key'}).globalField('global_field_uid').updateNestedGlobalField(data, { headers: { api_version: '3.2' }})
* .then((globalField) => {
console.log(globalField)
* })
*/
this.updateNestedGlobalField = async (config, headers = {}) => {
const apiVersion = { api_version: '3.2' }
this.stackHeaders = { ...this.stackHeaders, ...apiVersion, ...headers }
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) }
}
const response = await http.put(`${this.urlPath}`, config, headers)
const data = response.data
if (data) {
if (this.stackHeaders) {
data.stackHeaders = this.stackHeaders
}
return data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
this.update = update(http, 'global_field')

/**
* @description The Delete GlobalField call is used to delete an existing GlobalField permanently from your Stack.
Expand All @@ -135,38 +51,7 @@ export function GlobalField (http, data = {}) {
* client.stack({ api_key: 'api_key'}).globalField('global_field_uid').delete()
* .then((response) => console.log(response.notice))
*/
this.delete = async () => {
const param = {}
try {
// Add `api_version` to headers if `this.apiVersion` is defined
if (this.apiVersion) {
this.stackHeaders.api_version = this.apiVersion
}
const headers = {
headers: {
...cloneDeep(this.stackHeaders)
},
params: {
...cloneDeep(param)
}
}
const response = await http.delete(this.urlPath, headers)
if (this.apiVersion) {
delete this.stackHeaders.api_version
}
const data = response.data
if (data) {
if (this.stackHeaders) {
data.stackHeaders = this.stackHeaders
}
return data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
this.delete = deleteEntity(http)

/**
* @description The fetch GlobalField call fetches GlobalField details.
Expand All @@ -181,33 +66,7 @@ export function GlobalField (http, data = {}) {
* .then((globalField) => console.log(globalField))
*
*/
this.fetch = async function (param = {}) {
try {
if (this.apiVersion) {
this.stackHeaders.api_version = this.apiVersion
}
const headers = {
headers: {
...cloneDeep(this.stackHeaders)
},
params: {
...cloneDeep(param)
}
}
const response = await http.get(this.urlPath, headers)
const data = response.data
if (data) {
if (this.stackHeaders) {
data.stackHeaders = this.stackHeaders
}
return data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
this.fetch = fetch(http, 'global_field')
} else {
/**
* @description The Create a GlobalField call creates a new globalField in a particular stack of your Contentstack account.
Expand All @@ -230,30 +89,7 @@ export function GlobalField (http, data = {}) {
* client.stack().globalField().create({ global_field })
* .then((globalField) => console.log(globalField))
*/
this.create = async (payload) => {
try {
if (this.apiVersion) {
this.stackHeaders.api_version = this.apiVersion
}
const headers = {
headers: {
...cloneDeep(this.stackHeaders)
}
}
const response = await http.post(`${this.urlPath}`, payload, headers)
const data = response.data
if (data) {
if (this.stackHeaders) {
data.stackHeaders = this.stackHeaders
}
return data
} else {
throw error(response)
}
} catch (err) {
return error(err)
}
}
this.create = create({ http: http })

/**
* @description The Query on GlobalField will allow to fetch details of all or specific GlobalField
Expand Down
Loading
Loading