Skip to content

Commit 5a0f10d

Browse files
Merge branch 'staging' into fix/merge-conflicts
2 parents 414ecc9 + 868d984 commit 5a0f10d

13 files changed

+212
-83
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
expected_license_files=("LICENSE" "LICENSE.txt" "LICENSE.md" "License.txt")
28+
license_file_found=false
29+
current_year=$(date +"%Y")
30+
31+
for license_file in "${expected_license_files[@]}"; do
32+
if [ -f "$license_file" ]; then
33+
license_file_found=true
34+
# check the license file for the current year, if not exists, exit with error
35+
if ! grep -q "$current_year" "$license_file"; then
36+
echo "License file $license_file does not contain the current year."
37+
exit 2
38+
fi
39+
break
40+
fi
41+
done
42+
43+
if [ "$license_file_found" = false ]; then
44+
echo "No license file found. Please add a license file to the repository."
45+
exit 1
46+
fi

.github/workflows/sast-scan.yml

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

.github/workflows/secrets-scan.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
steps:
9+
- uses: actions/checkout@v4
10+
with:
11+
fetch-depth: '2'
12+
ref: '${{ github.event.pull_request.head.ref }}'
13+
- run: |
14+
git reset --soft HEAD~1
15+
- name: Install Talisman
16+
run: |
17+
# Download Talisman
18+
wget https://github.com/thoughtworks/talisman/releases/download/v1.37.0/talisman_linux_amd64 -O talisman
19+
20+
# Checksum verification
21+
checksum=$(sha256sum ./talisman | awk '{print $1}')
22+
if [ "$checksum" != "8e0ae8bb7b160bf10c4fa1448beb04a32a35e63505b3dddff74a092bccaaa7e4" ]; then exit 1; fi
23+
24+
# Make it executable
25+
chmod +x talisman
26+
- name: Run talisman
27+
run: |
28+
# Run Talisman with the pre-commit hook
29+
./talisman --githook pre-commit

.talismanrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
threshold: medium
22
fileignoreconfig:
3+
- filename: .github/workflows/secrets-scan.yml
4+
ignore_detectors:
5+
- filecontent
36
- filename: test/unit/mock/execution-mock.js
47
checksum: 89d239d37c9d8d0cdb6ac61553a7d2e2d9115a10207f7c0b387c3565c9cb6564
58
- filename: package-lock.json
6-
checksum: 0f9b6180aa8b66fdd055ef99f74f269febb07e90bbd64badf1039a4d375850b6
9+
checksum: bc3cbd474a69321d97be9557ef74a056b7fab4111869d496b0d0403c1c84b971
710
- filename: docdash-template/fixtures/documents/probe.js
811
checksum: e841ecf889d0e82367c53c48ee0b3be8bd68d7babf4777a87ced769f29686ac4
912
- filename: docdash-template/.travis.yml

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
2+
## [v1.2.8](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.6) (2024-05-26)
3+
- Fix: Added params support to getInstalledApps method for enhanced flexibility
24

3-
## [v1.3.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.6) (2024-04-28)
4-
- Enh: Added params support to getInstalledApps method for enhanced flexibility
5+
## [v1.2.7](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.6) (2024-05-15)
6+
- Fixed base URL path logic in contentstackClient to handle when region and host not provided
57

68
## [v1.2.6](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.6) (2024-03-03)
79
- Update sanity tests

lib/contentstackClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default function contentstackClient ({ http }) {
3131

3232
if (region && region !== Region.NA) {
3333
baseUrlPath = `https://${region}-api.contentstack.com:443/v3/user-session`
34+
} else if (!region && http?.defaults?.host) {
35+
baseUrlPath = `https://${http.defaults.host}:443/v3/user-session`
36+
} else {
37+
baseUrlPath = `https://api.contentstack.io:443/v3/user-session`
3438
}
3539

3640
function login (requestBody, params = {}) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/marketplace-sdk",
3-
"version": "1.3.0",
3+
"version": "1.2.8",
44
"description": "The Contentstack Marketplace SDK is used to manage the content of your Contentstack marketplace apps",
55
"main": "./dist/node/contentstack-marketplace.js",
66
"browser": "./dist/web/contentstack-marketplace.js",

sanity-report.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ console.log(`Failed Tests: ${failedTests}`)
2525
console.log(`Pending Tests: ${pendingTests}`)
2626
console.log(`Total Duration: ${durationInMinutes}m ${durationInSeconds.toFixed(2)}s`)
2727

28+
const host = process.env.DEFAULTHOST || ''
29+
let region = 'NA'
30+
31+
const match = host.match(/^([^-]+(?:-[^-]+)*)-api/)
32+
if (match && match[1]) {
33+
region = match[1].toUpperCase()
34+
}
35+
2836
const slackMessage = `
29-
*JavaScript Marketplace SDK Report*
37+
*JavaScript Marketplace SDK Report - ${region}*
3038
• Total Suites: *${totalSuites}*
3139
• Total Tests: *${totalTests}*
3240
• Passed Tests: *${passedTests}*

test/unit/ContentstackClient-test.js

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@ import { expect } from 'chai'
44
import { describe, it, beforeEach } from 'mocha'
55
import MockAdapter from 'axios-mock-adapter'
66
import Region from '../../lib/core/region'
7-
var host = 'http://localhost/'
7+
var host = 'localhost'
8+
9+
describe('Region Test ', () => {
10+
it('Contentstack Client login success with region NA', done => {
11+
var mock = new MockAdapter(axios)
12+
axios.defaults.region = Region.NA
13+
mock.onPost('https://api.contentstack.io:443/v3/user-session').reply(200, {
14+
user: {
15+
authtoken: 'Test Auth'
16+
}
17+
})
18+
19+
ContentstackClient({ http: axios })
20+
.login()
21+
.then((response) => {
22+
expect(response.user.authtoken).to.be.equal('Test Auth')
23+
done()
24+
})
25+
.catch(done)
26+
})
27+
})
828

929
describe('Contentstack Client', () => {
1030
beforeEach(function () {
11-
host = 'http://localhost/'
31+
host = 'localhost'
1232
axios.defaults.host = host
1333
axios.defaults.adapter = 'http'
1434
})
@@ -21,7 +41,7 @@ describe('Contentstack Client', () => {
2141

2242
it('Contentstack Client login success', done => {
2343
var mock = new MockAdapter(axios)
24-
mock.onPost('/user-session').reply(200, {
44+
mock.onPost('https://localhost:443/v3/user-session').reply(200, {
2545
user: {
2646
authtoken: 'Test Auth'
2747
}
@@ -37,7 +57,7 @@ describe('Contentstack Client', () => {
3757

3858
it('Contentstack Client Logout with Authtoken', done => {
3959
var mock = new MockAdapter(axios)
40-
mock.onDelete('/user-session').reply(200, {
60+
mock.onDelete('https://localhost:443/v3/user-session').reply(200, {
4161
notice: 'You\'ve logged out successfully'
4262
})
4363
ContentstackClient({ http: axios })
@@ -51,7 +71,7 @@ describe('Contentstack Client', () => {
5171

5272
it('Contentstack Client Logout', done => {
5373
var mock = new MockAdapter(axios)
54-
mock.onDelete('/user-session').reply(200, {
74+
mock.onDelete('https://localhost:443/v3/user-session').reply(200, {
5575
notice: 'You\'ve logged out successfully'
5676
})
5777
axios.defaults.headers = {
@@ -101,20 +121,57 @@ describe('Contentstack Client', () => {
101121
done()
102122
})
103123

104-
it('Contentstack Client login success with region', done => {
105-
var mock = new MockAdapter(axios)
106-
axios.defaults.region = Region.AZURE_NA
107-
mock.onPost('https://azure-na-api.contentstack.com:443/v3/user-session').reply(200, {
108-
user: {
109-
authtoken: 'Test Auth'
110-
}
124+
it('Contentstack Client login success with region AZURE-NA', done => {
125+
var mock = new MockAdapter(axios)
126+
axios.defaults.region = Region.AZURE_NA
127+
mock.onPost('https://azure-na-api.contentstack.com:443/v3/user-session').reply(200, {
128+
user: {
129+
authtoken: 'Test Auth'
130+
}
131+
})
132+
133+
ContentstackClient({ http: axios })
134+
.login()
135+
.then((response) => {
136+
expect(response.user.authtoken).to.be.equal('Test Auth')
137+
done()
111138
})
112-
ContentstackClient({ http: axios })
113-
.login()
114-
.then((response) => {
115-
expect(response.user.authtoken).to.be.equal('Test Auth')
116-
done()
117-
})
118-
.catch(done)
139+
.catch(done)
140+
})
141+
142+
it('Contentstack Client login success with region AZURE-EU', done => {
143+
var mock = new MockAdapter(axios)
144+
axios.defaults.region = Region.AZURE_EU
145+
mock.onPost('https://azure-eu-api.contentstack.com:443/v3/user-session').reply(200, {
146+
user: {
147+
authtoken: 'Test Auth'
148+
}
149+
})
150+
151+
ContentstackClient({ http: axios })
152+
.login()
153+
.then((response) => {
154+
expect(response.user.authtoken).to.be.equal('Test Auth')
155+
done()
156+
})
157+
.catch(done)
158+
})
159+
160+
it('Contentstack Client login success with region GCP-NA', done => {
161+
var mock = new MockAdapter(axios)
162+
axios.defaults.region = Region.GCP_NA
163+
mock.onPost('https://gcp-na-api.contentstack.com:443/v3/user-session').reply(200, {
164+
user: {
165+
authtoken: 'Test Auth'
166+
}
167+
})
168+
169+
ContentstackClient({ http: axios })
170+
.login()
171+
.then((response) => {
172+
expect(response.user.authtoken).to.be.equal('Test Auth')
173+
done()
174+
})
175+
.catch(done)
119176
})
120177
})

test/unit/concurrency-Queue-test.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,15 @@ describe('Concurrency queue test', () => {
130130
})
131131

132132
it('Refresh Token on 401 with 1000 concurrent request', done => {
133-
var mock = new MockAdapter(axios)
134-
mock.onPost('/user-session').reply(200, {
135-
token
136-
})
137-
const axiosClient = client({
138-
baseURL: `${host}:${port}`,
139-
authorization: 'Bearer <token_value>',
133+
const axiosClient = client({
134+
baseURL: `${host}:${port}`,
135+
authorization: 'Bearer <token_value>',
140136
logHandler: logHandlerStub,
141137
refreshToken: () => {
142-
return new Promise((resolve, reject) => {
143-
return contentstackClient({ http: axios }).login().then((res) => {
144-
resolve({ authorization: res.token })
145-
}).catch((error) => {
146-
reject(error)
138+
return Axios.post(`${host}:${port}/user-session`)
139+
.then((res) => {
140+
return { authorization: res.data.token }
147141
})
148-
})
149142
}
150143
})
151144
Promise.all(sequence(1003).map(() => axiosClient.axiosInstance.get('/unauthorized')))

0 commit comments

Comments
 (0)