Skip to content

Commit a6b5510

Browse files
committed
Merge branch 'feat/oauth-support' into feat/DX-2264-oauth-test-cases
2 parents 682b5bd + 2f411ae commit a6b5510

File tree

80 files changed

+2822
-4900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2822
-4900
lines changed

.eslintrc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = {
2-
// "env": {
3-
// "browser": true,
4-
// "amd": true
5-
// },
2+
env: {
3+
"es2020": true
4+
},
65
extends: 'standard',
76
// "globals": {
87
// "Atomics": "readonly",
@@ -15,6 +14,7 @@ module.exports = {
1514
// "ecmaVersion": 2015,
1615
// "sourceType": "module"
1716
// },
17+
parser: "@babel/eslint-parser", // Use Babel parser to handle modern JS syntax
1818
plugins: [
1919
'standard',
2020
'promise'

.github/workflows/lint-check.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint Check on PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: '22.x'
19+
registry-url: 'https://registry.npmjs.org'
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Run ESLint
25+
run: npm run lint

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [v1.19.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.5) (2025-03-17)
4+
- Fix
5+
- Added AuditLog in the stack class
6+
- Fixed the Unit Test cases and added sanity test case for audit log
7+
38
## [v1.19.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.4) (2025-03-10)
49
- Fix
510
- added fix for variants import

lib/app/installation/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,4 @@ export function InstallationCollection (http, data) {
250250
return obj.map((installationData) => {
251251
return new Installation(http, { data: installationData })
252252
})
253-
}
253+
}

lib/contentstackClient.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ export default function contentstackClient ({ http }) {
193193
* .then(() => console.log('Logged in successfully'))
194194
*
195195
*/
196-
function oauth(params = {}) {
197-
http.defaults.versioningStrategy = "path";
198-
const appId = params.appId || '6400aa06db64de001a31c8a9';
199-
const clientId = params.clientId || 'Ie0FEfTzlfAHL4xM';
200-
const redirectUri = params.redirectUri || 'http://localhost:8184';
201-
const responseType = params.responseType || 'code';
202-
const scope = params.scope;
203-
const clientSecret = params.clientSecret;
204-
return new OAuthHandler(http, appId, clientId, redirectUri, clientSecret,responseType, scope);
196+
function oauth (params = {}) {
197+
http.defaults.versioningStrategy = 'path'
198+
const appId = params.appId || '6400aa06db64de001a31c8a9'
199+
const clientId = params.clientId || 'Ie0FEfTzlfAHL4xM'
200+
const redirectUri = params.redirectUri || 'http://localhost:8184'
201+
const responseType = params.responseType || 'code'
202+
const scope = params.scope
203+
const clientSecret = params.clientSecret
204+
return new OAuthHandler(http, appId, clientId, redirectUri, clientSecret, responseType, scope)
205205
}
206206

207207
return {
@@ -211,6 +211,6 @@ export default function contentstackClient ({ http }) {
211211
stack: stack,
212212
organization: organization,
213213
axiosInstance: http,
214-
oauth,
214+
oauth
215215
}
216216
}

lib/contentstackCollection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export default class ContentstackCollection {
1010
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
1111
data.stackHeaders = {
1212
...data.stackHeaders,
13-
responseHeaders: response.headers,
14-
};
13+
responseHeaders: response.headers
14+
}
1515
}
1616
if (wrapperCollection) {
1717
this.items = wrapperCollection(http, data)

lib/core/concurrency-queue.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ export function ConcurrencyQueue ({ axios, config }) {
7777
request.data = transformFormData(request)
7878
}
7979
if (axios?.oauth?.accessToken) {
80-
const isTokenExpired = axios.oauth.tokenExpiryTime && Date.now() > axios.oauth.tokenExpiryTime;
80+
const isTokenExpired = axios.oauth.tokenExpiryTime && Date.now() > axios.oauth.tokenExpiryTime
8181
if (isTokenExpired) {
8282
return refreshAccessToken().catch((error) => {
83-
throw new Error('Failed to refresh access token: ' + error.message);
84-
});
83+
throw new Error('Failed to refresh access token: ' + error.message)
84+
})
8585
}
86-
}
87-
86+
}
87+
8888
request.retryCount = request?.retryCount || 0
89-
setAuthorizationHeaders(request);
89+
setAuthorizationHeaders(request)
9090
if (request.cancelToken === undefined) {
9191
const source = Axios.CancelToken.source()
9292
request.cancelToken = source.token
@@ -121,32 +121,31 @@ export function ConcurrencyQueue ({ axios, config }) {
121121
request.authtoken = this.config.authtoken
122122
} else if (axios?.oauth?.accessToken) {
123123
// If OAuth access token is available in axios instance
124-
request.headers.authorization = `Bearer ${axios.oauth.accessToken}`;
125-
request.authorization = `Bearer ${axios.oauth.accessToken}`;
124+
request.headers.authorization = `Bearer ${axios.oauth.accessToken}`
125+
request.authorization = `Bearer ${axios.oauth.accessToken}`
126126
delete request.headers.authtoken
127127
}
128128
}
129129

130-
//Refresh Access Token
130+
// Refresh Access Token
131131
const refreshAccessToken = async () => {
132132
try {
133133
// Try to refresh the token
134-
await new OAuthHandler(axios).refreshAccessToken();
135-
this.paused = false; // Resume the request queue once the token is refreshed
134+
await new OAuthHandler(axios).refreshAccessToken()
135+
this.paused = false // Resume the request queue once the token is refreshed
136136

137137
// Retry the requests that were pending due to token expiration
138138
this.running.forEach(({ request, resolve, reject }) => {
139139
// Retry the request
140-
axios(request).then(resolve).catch(reject);
141-
});
142-
this.running = []; // Clear the running queue after retrying requests
140+
axios(request).then(resolve).catch(reject)
141+
})
142+
this.running = [] // Clear the running queue after retrying requests
143143
} catch (error) {
144-
this.paused = false; // stop queueing requests on failure
145-
this.running.forEach(({ reject }) => reject(error)); // Reject all queued requests
146-
this.running = []; // Clear the running queue
144+
this.paused = false // stop queueing requests on failure
145+
this.running.forEach(({ reject }) => reject(error)) // Reject all queued requests
146+
this.running = [] // Clear the running queue
147147
}
148148
}
149-
150149

151150
const delay = (time, isRefreshToken = false) => {
152151
if (!this.paused) {
@@ -196,7 +195,7 @@ export function ConcurrencyQueue ({ axios, config }) {
196195
message: 'Unable to refresh token',
197196
name: 'Token Error',
198197
config: queueItem.request,
199-
stack: (error instanceof Error) ? error.stack : null,
198+
stack: (error instanceof Error) ? error.stack : null
200199
})
201200
})
202201
this.queue = []

lib/core/contentstackHTTPClient.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,24 @@ export default function contentstackHttpClient (options) {
6565
config.basePath = `/${config.basePath.split('/').filter(Boolean).join('/')}`
6666
}
6767
const baseURL = config.endpoint || `${protocol}://${hostname}:${port}${config.basePath}/{api-version}`
68-
let uiHostName = hostname;
69-
let developerHubBaseUrl = hostname;
68+
let uiHostName = hostname
69+
let developerHubBaseUrl = hostname
7070

7171
if (hostname.endsWith('io')) {
72-
uiHostName = hostname.replace('io', 'com');
72+
uiHostName = hostname.replace('io', 'com')
7373
}
7474

7575
if (hostname.startsWith('api')) {
76-
uiHostName = uiHostName.replace('api', 'app');
76+
uiHostName = uiHostName.replace('api', 'app')
7777
}
78-
const uiBaseUrl = config.endpoint || `${protocol}://${uiHostName}`;
78+
const uiBaseUrl = config.endpoint || `${protocol}://${uiHostName}`
7979

8080
developerHubBaseUrl = developerHubBaseUrl
8181
?.replace('api', 'developerhub-api')
8282
.replace(/^dev\d+/, 'dev') // Replaces any 'dev1', 'dev2', etc. with 'dev'
8383
.replace('io', 'com')
8484
.replace(/^http/, '') // Removing `http` if already present
85-
.replace(/^/, 'https://'); // Adds 'https://' at the start if not already there
85+
.replace(/^/, 'https://') // Adds 'https://' at the start if not already there
8686

8787
// set ui host name
8888
const axiosOptions = {

0 commit comments

Comments
 (0)