netlify-cms-lib-util
Advanced tools
Comparing version
@@ -6,2 +6,13 @@ # Change Log | ||
## 2.11.3 (2020-09-08) | ||
### Reverts | ||
* Revert "chore(release): publish" ([828bb16](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-lib-util/commit/828bb16415b8c22a34caa19c50c38b24ffe9ceae)) | ||
## 2.11.2 (2020-08-20) | ||
@@ -8,0 +19,0 @@ |
@@ -91,3 +91,5 @@ "use strict"; | ||
} catch (err) { | ||
if (attempt <= 5) { | ||
if (attempt > 5 || err.message === "Can't refresh access token when using implicit auth") { | ||
throw err; | ||
} else { | ||
if (!api.rateLimiter) { | ||
@@ -108,4 +110,2 @@ const timeout = err.resetSeconds || attempt * attempt; | ||
return requestWithBackoff(api, req, attempt + 1); | ||
} else { | ||
throw err; | ||
} | ||
@@ -112,0 +112,0 @@ } |
@@ -13,13 +13,15 @@ "use strict"; | ||
exports.MERGE_COMMIT_MESSAGE = MERGE_COMMIT_MESSAGE; | ||
const NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/'; | ||
const DEFAULT_NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/'; | ||
const isCMSLabel = label => label.startsWith(NETLIFY_CMS_LABEL_PREFIX); | ||
const getLabelPrefix = labelPrefix => labelPrefix || DEFAULT_NETLIFY_CMS_LABEL_PREFIX; | ||
const isCMSLabel = (label, labelPrefix) => label.startsWith(getLabelPrefix(labelPrefix)); | ||
exports.isCMSLabel = isCMSLabel; | ||
const labelToStatus = label => label.substr(NETLIFY_CMS_LABEL_PREFIX.length); | ||
const labelToStatus = (label, labelPrefix) => label.substr(getLabelPrefix(labelPrefix).length); | ||
exports.labelToStatus = labelToStatus; | ||
const statusToLabel = status => `${NETLIFY_CMS_LABEL_PREFIX}${status}`; | ||
const statusToLabel = (status, labelPrefix) => `${getLabelPrefix(labelPrefix)}${status}`; | ||
@@ -26,0 +28,0 @@ exports.statusToLabel = statusToLabel; |
{ | ||
"name": "netlify-cms-lib-util", | ||
"description": "Shared utilities for Netlify CMS.", | ||
"version": "2.11.2", | ||
"version": "2.11.3", | ||
"repository": "https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-lib-util", | ||
@@ -28,3 +28,3 @@ "bugs": "https://github.com/netlify/netlify-cms/issues", | ||
}, | ||
"gitHead": "c99d7affc7d4f59ade69a805aca9d55d554c54c1" | ||
"gitHead": "a8bfed55d258a9d15574bade4760a219d926d560" | ||
} |
@@ -22,21 +22,54 @@ import * as apiUtils from '../APIUtils'; | ||
it('should return true for CMS label', () => { | ||
expect(apiUtils.isCMSLabel('netlify-cms/draft')).toBe(true); | ||
expect(apiUtils.isCMSLabel('netlify-cms/draft', 'netlify-cms/')).toBe(true); | ||
}); | ||
it('should return false for non CMS label', () => { | ||
expect(apiUtils.isCMSLabel('other/label')).toBe(false); | ||
expect(apiUtils.isCMSLabel('other/label', 'netlify-cms/')).toBe(false); | ||
}); | ||
it('should return true if the prefix not provided for CMS label', () => { | ||
expect(apiUtils.isCMSLabel('netlify-cms/draft', '')).toBe(true); | ||
}); | ||
it('should return false if a different prefix provided for CMS label', () => { | ||
expect(apiUtils.isCMSLabel('netlify-cms/draft', 'other/')).toBe(false); | ||
}); | ||
it('should return true for CMS label when undefined prefix is passed', () => { | ||
expect(apiUtils.isCMSLabel('netlify-cms/draft', undefined)).toBe(true); | ||
}); | ||
}); | ||
describe('labelToStatus', () => { | ||
it('should get status from label', () => { | ||
expect(apiUtils.labelToStatus('netlify-cms/draft')).toBe('draft'); | ||
it('should get status from label when default prefix is passed', () => { | ||
expect(apiUtils.labelToStatus('netlify-cms/draft', 'netlify-cms/')).toBe('draft'); | ||
}); | ||
it('should get status from label when custom prefix is passed', () => { | ||
expect(apiUtils.labelToStatus('other/draft', 'other/')).toBe('draft'); | ||
}); | ||
it('should get status from label when empty prefix is passed', () => { | ||
expect(apiUtils.labelToStatus('netlify-cms/draft', '')).toBe('draft'); | ||
}); | ||
it('should get status from label when undefined prefix is passed', () => { | ||
expect(apiUtils.labelToStatus('netlify-cms/draft', undefined)).toBe('draft'); | ||
}); | ||
}); | ||
describe('statusToLabel', () => { | ||
it('should generate label from status', () => { | ||
expect(apiUtils.statusToLabel('draft')).toBe('netlify-cms/draft'); | ||
it('should generate label from status when default prefix is passed', () => { | ||
expect(apiUtils.statusToLabel('draft', 'netlify-cms/')).toBe('netlify-cms/draft'); | ||
}); | ||
it('should generate label from status when custom prefix is passed', () => { | ||
expect(apiUtils.statusToLabel('draft', 'other/')).toBe('other/draft'); | ||
}); | ||
it('should generate label from status when empty prefix is passed', () => { | ||
expect(apiUtils.statusToLabel('draft', '')).toBe('netlify-cms/draft'); | ||
}); | ||
it('should generate label from status when undefined prefix is passed', () => { | ||
expect(apiUtils.statusToLabel('draft', undefined)).toBe('netlify-cms/draft'); | ||
}); | ||
}); | ||
}); |
@@ -72,3 +72,5 @@ import { asyncLock, AsyncLock } from './asyncLock'; | ||
} catch (err) { | ||
if (attempt <= 5) { | ||
if (attempt > 5 || err.message === "Can't refresh access token when using implicit auth") { | ||
throw err; | ||
} else { | ||
if (!api.rateLimiter) { | ||
@@ -91,4 +93,2 @@ const timeout = err.resetSeconds || attempt * attempt; | ||
return requestWithBackoff(api, req, attempt + 1); | ||
} else { | ||
throw err; | ||
} | ||
@@ -95,0 +95,0 @@ } |
@@ -5,7 +5,12 @@ export const CMS_BRANCH_PREFIX = 'cms'; | ||
const NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/'; | ||
export const isCMSLabel = (label: string) => label.startsWith(NETLIFY_CMS_LABEL_PREFIX); | ||
export const labelToStatus = (label: string) => label.substr(NETLIFY_CMS_LABEL_PREFIX.length); | ||
export const statusToLabel = (status: string) => `${NETLIFY_CMS_LABEL_PREFIX}${status}`; | ||
const DEFAULT_NETLIFY_CMS_LABEL_PREFIX = 'netlify-cms/'; | ||
const getLabelPrefix = (labelPrefix: string) => labelPrefix || DEFAULT_NETLIFY_CMS_LABEL_PREFIX; | ||
export const isCMSLabel = (label: string, labelPrefix: string) => | ||
label.startsWith(getLabelPrefix(labelPrefix)); | ||
export const labelToStatus = (label: string, labelPrefix: string) => | ||
label.substr(getLabelPrefix(labelPrefix).length); | ||
export const statusToLabel = (status: string, labelPrefix: string) => | ||
`${getLabelPrefix(labelPrefix)}${status}`; | ||
export const generateContentKey = (collectionName: string, slug: string) => | ||
@@ -12,0 +17,0 @@ `${collectionName}/${slug}`; |
@@ -92,2 +92,3 @@ import semaphore, { Semaphore } from 'semaphore'; | ||
app_id?: string; | ||
cms_label_prefix?: string; | ||
}; | ||
@@ -94,0 +95,0 @@ media_folder: string; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
853288
0.34%4018
0.85%