Skip to content

feat: added support for branches #22

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 6 commits into from
Dec 9, 2022
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
15,477 changes: 5,224 additions & 10,253 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@contentstack/datasync-manager",
"author": "Contentstack LLC <support@contentstack.com>",
"version": "1.2.4",
"version": "2.0.0",
"description": "The primary module of Contentstack DataSync. Syncs Contentstack data with your server using Contentstack Sync API",
"main": "dist/index.js",
"dependencies": {
"@braintree/sanitize-url": "^6.0.2",
"debug": "^4.3.4",
"dns-socket": "^4.2.2",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -34,7 +35,7 @@
"semantic-release": "^19.0.5",
"ts-jest": "^29.0.1",
"tslint": "^5.18.0",
"typescript": "^3.9.2"
"typescript": "^4.9.4"
},
"scripts": {
"clean": "rimraf dist typings coverage .tokens .ledger .checkpoint",
Expand Down
4 changes: 3 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Debug from 'debug'
import { request } from 'https'
import { join } from 'path'
import { stringify } from 'querystring'
import { sanitizeUrl } from '@braintree/sanitize-url';
import { readFileSync } from './util/fs'

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

if (Contentstack.MAX_RETRY_LIMIT) {
Expand Down Expand Up @@ -52,7 +54,7 @@ export const get = (req, RETRY = 1) => {
headers: Contentstack.headers,
hostname: Contentstack.host,
method: Contentstack.verbs.get,
path: req.path,
path: sanitizeUrl(req.path),
port: Contentstack.port,
protocol: Contentstack.protocol,
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/q.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { series } from '../util/series'
import { saveFailedItems } from '../util/unprocessible'
import { load } from './plugins'
import { saveToken } from './token-management'
import { getConfig } from '../index';

const debug = Debug('q')
const notifications = new EventEmitter()
Expand Down Expand Up @@ -159,6 +160,8 @@ export class Q extends EventEmitter {
const contentType = data._content_type_uid
const locale = data.locale
const uid = data.uid
const branch = getConfig().contentstack.branch
data.branch = branch

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

debug(`Completed '${action}' on connector successfully!`)
if (typeof schema !== 'undefined') {
schema.branch = branch
await this.contentStore.updateContentType(schema)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/token-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const saveToken = (name, token) => {
await writeFile(file, JSON.stringify(ledgerDetails))
}

return resolve()
return resolve('')
} catch (error) {
return reject(error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const start = (config: IConfig = {}): Promise<{}> => {
}).then(() => {
logger.info('Contentstack sync utility started successfully!')

return resolve()
return resolve('')
}).catch(reject)
} catch (error) {
return reject(error)
Expand Down
4 changes: 2 additions & 2 deletions src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const writeFile = (filePath, data) => {
return reject(wfError)
}

return resolve()
return resolve('')
})
} catch (writeFileError) {

Expand Down Expand Up @@ -108,7 +108,7 @@ export const mkdir = (path) => {
return reject(error)
}

return resolve()
return resolve('')
})
} catch (error) {
return reject(error)
Expand Down
8 changes: 4 additions & 4 deletions src/util/unprocessible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const saveFilteredItems = (items, name, token) => {
const config = getConfig()
let filename
if (!config.syncManager.saveFilteredItems) {
return resolve()
return resolve('')
}
const objDetails = {
items,
Expand Down Expand Up @@ -80,21 +80,21 @@ export const saveFilteredItems = (items, name, token) => {
logger.error(`Failed to write ${JSON.stringify(loggedItems)} at ${error}`)
logger.error(error)

return resolve()
return resolve('')
})
}).catch((error) => {
logger.error(`Failed to read file from path ${fail}`)
logger.error(error)

return resolve()
return resolve('')
})
}

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

return resolve()
return resolve('')
})
} catch (error) {
return reject(error)
Expand Down
4 changes: 2 additions & 2 deletions src/util/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const validateConfig = (config) => {
throw new Error(`Config '${key}' key cannot be undefined`)
}
})
if (typeof config.contentstack !== 'object' || !config.contentstack.apiKey || !config.contentstack.deliveryToken) {
throw new Error('Config \'contentstack\' should be of type object and have \'apiKey\' and \'token\'')
if (typeof config.contentstack !== 'object' || !config.contentstack.apiKey || !config.contentstack.deliveryToken || !config.contentstack.branch) {
throw new Error('Config \'contentstack\' should be of type object and have \'apiKey\', \'token\' and \'branch\'')
}

if (config.queue) {
Expand Down