Skip to content

Commit 7163349

Browse files
authored
Merge pull request #22 from contentstack/feat/branches
feat: added support for branches
2 parents b295752 + c909fd5 commit 7163349

File tree

9 files changed

+5244
-10266
lines changed

9 files changed

+5244
-10266
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "@contentstack/datasync-manager",
33
"author": "Contentstack LLC <support@contentstack.com>",
4-
"version": "1.2.4",
4+
"version": "2.0.0",
55
"description": "The primary module of Contentstack DataSync. Syncs Contentstack data with your server using Contentstack Sync API",
66
"main": "dist/index.js",
77
"dependencies": {
8+
"@braintree/sanitize-url": "^6.0.2",
89
"debug": "^4.3.4",
910
"dns-socket": "^4.2.2",
1011
"lodash": "^4.17.21",
@@ -34,7 +35,7 @@
3435
"semantic-release": "^19.0.5",
3536
"ts-jest": "^29.0.1",
3637
"tslint": "^5.18.0",
37-
"typescript": "^3.9.2"
38+
"typescript": "^4.9.4"
3839
},
3940
"scripts": {
4041
"clean": "rimraf dist typings coverage .tokens .ledger .checkpoint",

src/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Debug from 'debug'
88
import { request } from 'https'
99
import { join } from 'path'
1010
import { stringify } from 'querystring'
11+
import { sanitizeUrl } from '@braintree/sanitize-url';
1112
import { readFileSync } from './util/fs'
1213

1314
const debug = Debug('api')
@@ -25,6 +26,7 @@ export const init = (contentstack) => {
2526
'X-User-Agent': `datasync-manager/v${packageInfo.version}`,
2627
'access_token': Contentstack.deliveryToken,
2728
'api_key': Contentstack.apiKey,
29+
branch: Contentstack.branch,
2830
}
2931

3032
if (Contentstack.MAX_RETRY_LIMIT) {
@@ -52,7 +54,7 @@ export const get = (req, RETRY = 1) => {
5254
headers: Contentstack.headers,
5355
hostname: Contentstack.host,
5456
method: Contentstack.verbs.get,
55-
path: req.path,
57+
path: sanitizeUrl(req.path),
5658
port: Contentstack.port,
5759
protocol: Contentstack.protocol,
5860
}

src/core/q.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { series } from '../util/series'
1414
import { saveFailedItems } from '../util/unprocessible'
1515
import { load } from './plugins'
1616
import { saveToken } from './token-management'
17+
import { getConfig } from '../index';
1718

1819
const debug = Debug('q')
1920
const notifications = new EventEmitter()
@@ -159,6 +160,8 @@ export class Q extends EventEmitter {
159160
const contentType = data._content_type_uid
160161
const locale = data.locale
161162
const uid = data.uid
163+
const branch = getConfig().contentstack.branch
164+
data.branch = branch
162165

163166
if (data.hasOwnProperty('_checkpoint')) {
164167
checkpoint = data._checkpoint
@@ -216,6 +219,7 @@ export class Q extends EventEmitter {
216219

217220
debug(`Completed '${action}' on connector successfully!`)
218221
if (typeof schema !== 'undefined') {
222+
schema.branch = branch
219223
await this.contentStore.updateContentType(schema)
220224
}
221225

src/core/token-management.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const saveToken = (name, token) => {
110110
await writeFile(file, JSON.stringify(ledgerDetails))
111111
}
112112

113-
return resolve()
113+
return resolve('')
114114
} catch (error) {
115115
return reject(error)
116116
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const start = (config: IConfig = {}): Promise<{}> => {
229229
}).then(() => {
230230
logger.info('Contentstack sync utility started successfully!')
231231

232-
return resolve()
232+
return resolve('')
233233
}).catch(reject)
234234
} catch (error) {
235235
return reject(error)

src/util/fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const writeFile = (filePath, data) => {
3636
return reject(wfError)
3737
}
3838

39-
return resolve()
39+
return resolve('')
4040
})
4141
} catch (writeFileError) {
4242

@@ -108,7 +108,7 @@ export const mkdir = (path) => {
108108
return reject(error)
109109
}
110110

111-
return resolve()
111+
return resolve('')
112112
})
113113
} catch (error) {
114114
return reject(error)

src/util/unprocessible.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const saveFilteredItems = (items, name, token) => {
5050
const config = getConfig()
5151
let filename
5252
if (!config.syncManager.saveFilteredItems) {
53-
return resolve()
53+
return resolve('')
5454
}
5555
const objDetails = {
5656
items,
@@ -80,21 +80,21 @@ export const saveFilteredItems = (items, name, token) => {
8080
logger.error(`Failed to write ${JSON.stringify(loggedItems)} at ${error}`)
8181
logger.error(error)
8282

83-
return resolve()
83+
return resolve('')
8484
})
8585
}).catch((error) => {
8686
logger.error(`Failed to read file from path ${fail}`)
8787
logger.error(error)
8888

89-
return resolve()
89+
return resolve('')
9090
})
9191
}
9292

9393
return writeFile(file, JSON.stringify([objDetails])).then(resolve).catch((error) => {
9494
logger.error(`Failed while writing ${JSON.stringify(objDetails)} at ${file}`)
9595
logger.error(error)
9696

97-
return resolve()
97+
return resolve('')
9898
})
9999
} catch (error) {
100100
return reject(error)

src/util/validations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export const validateConfig = (config) => {
2121
throw new Error(`Config '${key}' key cannot be undefined`)
2222
}
2323
})
24-
if (typeof config.contentstack !== 'object' || !config.contentstack.apiKey || !config.contentstack.deliveryToken) {
25-
throw new Error('Config \'contentstack\' should be of type object and have \'apiKey\' and \'token\'')
24+
if (typeof config.contentstack !== 'object' || !config.contentstack.apiKey || !config.contentstack.deliveryToken || !config.contentstack.branch) {
25+
throw new Error('Config \'contentstack\' should be of type object and have \'apiKey\', \'token\' and \'branch\'')
2626
}
2727

2828
if (config.queue) {

0 commit comments

Comments
 (0)