@contentstack/datasync-manager 1.2.4 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +1 -1
  2. package/dist/api.js +16 -10
  3. package/dist/config.js +1 -0
  4. package/dist/core/index.js +33 -26
  5. package/dist/core/inet.js +10 -7
  6. package/dist/core/plugins.js +6 -5
  7. package/dist/core/process.js +7 -6
  8. package/dist/core/q.js +22 -16
  9. package/dist/core/token-management.js +23 -20
  10. package/dist/index.js +48 -37
  11. package/dist/util/build-paths.js +15 -14
  12. package/dist/util/fs.js +19 -15
  13. package/dist/util/index.js +53 -43
  14. package/dist/util/logger.js +3 -2
  15. package/dist/util/promise.map.js +3 -2
  16. package/dist/util/series.js +3 -2
  17. package/dist/util/unprocessible.js +14 -12
  18. package/dist/util/validations.js +34 -24
  19. package/package.json +8 -2
  20. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  21. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  22. package/.github/workflows/codeql-analysis.yml +0 -68
  23. package/.github/workflows/jira.yml +0 -28
  24. package/.github/workflows/release.yml +0 -53
  25. package/.github/workflows/sast-scan.yml +0 -11
  26. package/.github/workflows/sca-scan.yml +0 -15
  27. package/.github/workflows/secrets-scan.yml +0 -11
  28. package/.releaserc +0 -9
  29. package/.talismanrc +0 -4
  30. package/CODEOWNERS +0 -1
  31. package/SECURITY.md +0 -27
  32. package/example/config.js +0 -60
  33. package/example/index.js +0 -30
  34. package/test/api.ts +0 -152
  35. package/test/core/filteredItems.ts +0 -58
  36. package/test/core/index.ts +0 -18
  37. package/test/core/inet.ts +0 -23
  38. package/test/core/q.ts +0 -42
  39. package/test/core/sync.ts +0 -19
  40. package/test/core/token-management.ts +0 -40
  41. package/test/dummy/api-responses/404.ts +0 -3
  42. package/test/dummy/api-responses/content-type.ts +0 -30
  43. package/test/dummy/api-responses/delete-asset.ts +0 -9
  44. package/test/dummy/api-responses/delete-content-type.ts +0 -6
  45. package/test/dummy/api-responses/delete-entry.ts +0 -9
  46. package/test/dummy/api-responses/delete.ts +0 -32
  47. package/test/dummy/api-responses/empty.ts +0 -7
  48. package/test/dummy/api-responses/entries.ts +0 -31
  49. package/test/dummy/api-responses/filter-items.ts +0 -32
  50. package/test/dummy/api-responses/global-field.ts +0 -175
  51. package/test/dummy/api-responses/markdown-content-type.ts +0 -202
  52. package/test/dummy/api-responses/markdown-entries.ts +0 -56
  53. package/test/dummy/api-responses/mixed.ts +0 -77
  54. package/test/dummy/api-responses/publish-asset.ts +0 -14
  55. package/test/dummy/api-responses/publish-entry.ts +0 -14
  56. package/test/dummy/api-responses/publish.ts +0 -35
  57. package/test/dummy/api-responses/references-content-type-2.ts +0 -240
  58. package/test/dummy/api-responses/references-content-type.ts +0 -272
  59. package/test/dummy/api-responses/references-entries.ts +0 -156
  60. package/test/dummy/api-responses/unpublish-asset.ts +0 -9
  61. package/test/dummy/api-responses/unpublish-entry.ts +0 -9
  62. package/test/dummy/api-responses/unpublish.ts +0 -26
  63. package/test/dummy/config.ts +0 -34
  64. package/test/dummy/connector-listener-instances.ts +0 -69
  65. package/test/dummy/filter-items.ts +0 -32
  66. package/test/dummy/plugins/myplugin1/index.js +0 -20
  67. package/test/dummy/plugins/myplugin2/index.js +0 -20
  68. package/test/dummy/references-content-type.ts +0 -340
  69. package/test/dummy/references-entry-expected.ts +0 -161
  70. package/test/dummy/references-entry.ts +0 -95
  71. package/test/index.ts +0 -330
  72. package/test/util/fs.ts +0 -92
  73. package/test/util/index.ts +0 -157
  74. package/test/util/log-save-filtered-items.ts +0 -42
  75. package/test/util/validations.ts +0 -158
  76. package/tslint.json +0 -53
package/test/api.ts DELETED
@@ -1,152 +0,0 @@
1
-
2
- import { readFileSync } from 'fs'
3
- import { cloneDeep, merge } from 'lodash'
4
- import nock from 'nock'
5
- import { join } from 'path'
6
- import { get, init } from '../src/api'
7
- import { config as internalConfig } from '../src/config'
8
- import { setLogger } from '../src/util/logger'
9
- import { response as emptyResponse } from './dummy/api-responses/empty'
10
- import { response as publishResponse } from './dummy/api-responses/publish'
11
- import { config as mockConfig } from './dummy/config'
12
-
13
- const packageInfo: any = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'))
14
-
15
- beforeEach(() => {
16
- const configs = cloneDeep(merge({}, internalConfig, mockConfig))
17
- init(configs.contentstack)
18
-
19
- nock('https://api.localhost.io', {
20
- reqheaders: {
21
- 'access_token': 'dummyDeliveryToken',
22
- 'api_key': 'dummyApiKey',
23
- 'x-user-agent': `datasync-manager/v${packageInfo.version}`,
24
- },
25
- })
26
- .get('/200')
27
- // .query({sync_token: 'dummySyncToken', environment: 'test', limit: 100})
28
- .reply(200, publishResponse)
29
-
30
- nock('https://api.localhost.io', {
31
- reqheaders: {
32
- 'access_token': 'dummyDeliveryToken',
33
- 'api_key': 'dummyApiKey',
34
- 'x-user-agent': `datasync-manager/v${packageInfo.version}`,
35
- },
36
- })
37
- .get('/200')
38
- .query({pagination_token: 'publish-token', environment: 'test', limit: 100})
39
- .reply(200, emptyResponse)
40
-
41
- nock('https://api.localhost.io', {
42
- reqheaders: {
43
- 'access_token': 'dummyDeliveryToken',
44
- 'api_key': 'dummyApiKey',
45
- 'x-user-agent': `datasync-manager/v${packageInfo.version}`,
46
- },
47
- })
48
- .get('/429')
49
- .reply(429, emptyResponse)
50
-
51
- nock('https://api.localhost.io', {
52
- reqheaders: {
53
- 'access_token': 'dummyDeliveryToken',
54
- 'api_key': 'dummyApiKey',
55
- 'x-user-agent': `datasync-manager/v${packageInfo.version}`,
56
- },
57
- })
58
- .get('/500')
59
- .reply(500, publishResponse)
60
-
61
- nock('https://api.localhost.io', {
62
- reqheaders: {
63
- 'access_token': 'dummyDeliveryToken',
64
- 'api_key': 'dummyApiKey',
65
- 'x-user-agent': `datasync-manager/v${packageInfo.version}`,
66
- },
67
- })
68
- .get('/retry-exceeded')
69
- .reply(500, emptyResponse)
70
-
71
- nock('https://api.localhost.io', {
72
- reqheaders: {
73
- 'access_token': 'dummyDeliveryToken',
74
- 'api_key': 'dummyApiKey',
75
- 'x-user-agent': `datasync-manager/v${packageInfo.version}`,
76
- },
77
- })
78
- .get('/unknown-status')
79
- .reply(199, {
80
- key: 'unknown reject',
81
- })
82
- })
83
-
84
- describe('test api - get()', () => {
85
- beforeAll(() => {
86
- setLogger()
87
- })
88
-
89
- test('status 200: without errors', () => {
90
- const request = {
91
- path: '/200',
92
- }
93
-
94
- return get(request).then((response) => {
95
- expect(response).toHaveProperty('items')
96
- }).catch((error) => {
97
- expect(error)
98
- })
99
- })
100
-
101
- test('status 429: rate limit error', () => {
102
- const request = {
103
- path: '/429',
104
- }
105
-
106
- return get(request).then((response) => {
107
- expect(response).toBe({})
108
- }).catch((error) => {
109
- expect(error)
110
- })
111
- })
112
-
113
- test('server error', () => {
114
- const request = {
115
- path: '/500',
116
- }
117
-
118
- return get(request).then((response) => {
119
- expect(response).toBe({})
120
- }).catch((error) => {
121
- console.error(error)
122
- expect(error)
123
- })
124
- })
125
-
126
- test('retry exceeded', () => {
127
- const request = {
128
- path: '/retry-exceeded',
129
- }
130
- const err = new Error('Max retry limit exceeded!')
131
- return get(request, 9).then((response) => {
132
- expect(response).toBe({})
133
- }).catch((error) => {
134
- expect(error).toMatchObject(err)
135
- })
136
- })
137
-
138
- // test('unknown status', () => {
139
- // const request = {
140
- // path: '/unknown-status',
141
- // }
142
- // // const rej = {
143
- // // key: 'unknown reject',
144
- // // }
145
-
146
- // // expect(get(request)).rejects.toHaveProperty('key')
147
- // return get(request).catch((error) => {
148
- // expect(error).toHaveProperty('key')
149
- // })
150
- // })
151
-
152
- })
@@ -1,58 +0,0 @@
1
- import { cloneDeep, merge } from 'lodash'
2
- import { join, resolve} from 'path'
3
- import rimraf from 'rimraf'
4
- import { setConfig } from '../../src'
5
- import { config as internalConfig } from '../../src/config'
6
- import { buildConfigPaths } from '../../src/util/build-paths'
7
- import { setLogger } from '../../src/util/logger'
8
- import { saveFilteredItems } from '../../src/util/unprocessible'
9
- import { config as mockConfig } from '../dummy/config'
10
-
11
- const config = cloneDeep(merge({}, internalConfig, mockConfig))
12
-
13
- describe('filter items', () => {
14
- beforeAll(() => {
15
- setLogger()
16
- })
17
- afterAll(() => {
18
- const filteredFilePath = resolve(join(__dirname, '..', '..', 'test-filtered'))
19
- rimraf.sync(filteredFilePath)
20
- })
21
-
22
- test('Save filtered items should work without errors', () => {
23
- const items = [
24
- {
25
- key: 'dummy object',
26
- },
27
- ]
28
- const name = 'dummy_token'
29
- const token = '123'
30
-
31
- const configs: any = cloneDeep(config)
32
- configs.paths = buildConfigPaths()
33
- configs.paths.filtered = resolve(join(__dirname, '..', '..', 'test-filtered'))
34
- setConfig(configs)
35
-
36
- return saveFilteredItems(items, name, token).then((empty) => {
37
- expect(empty).toBeUndefined()
38
- }).catch((error) => {
39
- expect(error).toBeNull()
40
- })
41
- })
42
-
43
- test('Save filtered items should throw ENOENT error', () => {
44
- const items = [
45
- {
46
- key: 'dummy object',
47
- },
48
- ]
49
- const name = 'dummy_token'
50
- const token = '123'
51
-
52
- return saveFilteredItems(items, name, token).then((empty) => {
53
- expect(empty).toBeUndefined()
54
- }).catch((error) => {
55
- expect(error).toBeNull()
56
- })
57
- })
58
- })
@@ -1,18 +0,0 @@
1
- /*!
2
- * Contentstack Sync Manager
3
- * Copyright (c) 2019 Contentstack LLC
4
- * MIT Licensed
5
- */
6
-
7
- import { lock, unlock } from '../../src/core'
8
- import { setLogger } from '../../src/util/logger'
9
-
10
- describe('check lock-unlock', () => {
11
- beforeAll(() => {
12
- setLogger()
13
- })
14
- test('lock-unlock', () => {
15
- expect(lock()).toBeUndefined()
16
- expect(unlock(true)).toBeUndefined()
17
- })
18
- })
package/test/core/inet.ts DELETED
@@ -1,23 +0,0 @@
1
- import { cloneDeep, merge } from 'lodash'
2
- import { setConfig } from '../../src'
3
- import { config as internalConfig } from '../../src/config'
4
- import { checkNetConnectivity, init, netConnectivityIssues } from '../../src/core/inet'
5
- import { config as mockConfig } from '../dummy/config'
6
-
7
- const config = cloneDeep(merge({}, internalConfig, mockConfig))
8
-
9
- describe('# inet', () => {
10
- beforeAll(() => {
11
- setConfig(config)
12
- init()
13
- })
14
- test('Check for internet connectivity', () => {
15
- expect(checkNetConnectivity())
16
- .toBeUndefined()
17
- })
18
-
19
- test('Check for internet connectivity issue', () => {
20
- expect(netConnectivityIssues({}))
21
- .toEqual(false)
22
- })
23
- })
package/test/core/q.ts DELETED
@@ -1,42 +0,0 @@
1
- import { cloneDeep, merge } from 'lodash'
2
- import { setConfig } from '../../src'
3
- import { config as internalConfig } from '../../src/config'
4
- import { notifications, Q } from '../../src/core/q'
5
- import { buildConfigPaths } from '../../src/util/build-paths'
6
- import { setLogger } from '../../src/util/logger'
7
- import { config } from '../dummy/config'
8
- import { assetConnector, contentConnector } from '../dummy/connector-listener-instances'
9
-
10
- const configs: any = cloneDeep(merge({}, internalConfig, config))
11
-
12
- beforeAll(() => {
13
- setLogger()
14
- })
15
-
16
- test('error handler should work fine', () => {
17
- setConfig(configs)
18
- configs.paths = buildConfigPaths()
19
-
20
- const q = new Q(contentConnector, assetConnector, configs)
21
- const errorObject = {
22
- data: {
23
- _checkpoint: {
24
- name: 'dummyCheckpointName',
25
- token: 'dummyCheckpointToken',
26
- },
27
- uid: '123',
28
- },
29
- error: 'dummyError',
30
- }
31
- notifications.on('error', (error) => {
32
- expect(error).toMatchObject(errorObject)
33
- })
34
-
35
- return q.errorHandler(errorObject)
36
- .then((result) => {
37
- expect(result).toBeUndefined()
38
- })
39
- .catch((error) => {
40
- expect(error).toBeNull()
41
- })
42
- })
package/test/core/sync.ts DELETED
@@ -1,19 +0,0 @@
1
- import { cloneDeep, merge } from 'lodash'
2
- import { setConfig } from '../../src'
3
- import { config as internalConfig } from '../../src/config'
4
- import { poke } from '../../src/core'
5
- import { buildConfigPaths } from '../../src/util/build-paths'
6
- import { setLogger } from '../../src/util/logger'
7
- import { config } from '../dummy/config'
8
-
9
- const configs: any = cloneDeep(merge({}, internalConfig, config))
10
-
11
- beforeAll(() => {
12
- setConfig(configs)
13
- configs.paths = buildConfigPaths()
14
- setLogger()
15
- })
16
-
17
- test('Poke should work without errors', () => {
18
- expect(poke()).toBeUndefined()
19
- })
@@ -1,40 +0,0 @@
1
- import { writeFileSync } from 'fs'
2
- import { cloneDeep } from 'lodash'
3
- import mkdirp from 'mkdirp'
4
- import { join, resolve } from 'path'
5
- import rimraf from 'rimraf'
6
- import { setConfig } from '../../src'
7
- import { getToken } from '../../src/core/token-management'
8
- import { buildConfigPaths } from '../../src/util/build-paths'
9
- import { setLogger } from '../../src/util/logger'
10
- import { config } from '../dummy/config'
11
-
12
- describe('token management', () => {
13
- beforeAll(() => {
14
- setLogger()
15
- })
16
-
17
- test('get token by type should work without errors', () => {
18
- const tokenData = {
19
- name: 'sync_token',
20
- timestamp: 'ts-one',
21
- token: 'token-one',
22
- }
23
- const configs: any = cloneDeep(config)
24
- configs.paths = buildConfigPaths()
25
- const tknPath = resolve(join(__dirname, '..', 'testing'))
26
- mkdirp.sync(tknPath)
27
- configs.paths.checkpoint = resolve(join(tknPath, '.checkpoint'))
28
- configs.paths.ledger = resolve(join(__dirname, 'testing', '..', '.ledger'))
29
- setConfig(configs)
30
-
31
- writeFileSync(configs.paths.checkpoint, JSON.stringify(tokenData))
32
-
33
- return getToken().then((tokenDetails) => {
34
- expect(tokenDetails).toMatchObject(tokenData)
35
- rimraf.sync(tknPath)
36
- }).catch((error) => {
37
- expect(error).toBeNull()
38
- })
39
- })
40
- })
@@ -1,3 +0,0 @@
1
- export const response = {
2
-
3
- }
@@ -1,30 +0,0 @@
1
- export const contentType = {
2
- content_type: {
3
- _version: 1,
4
- schema: [{
5
- data_type: 'text',
6
- display_name: 'Title',
7
- field_metadata: {
8
- _default: true,
9
- },
10
- mandatory: true,
11
- multiple: false,
12
- uid: 'title',
13
- unique: true,
14
- },
15
- {
16
- data_type: 'text',
17
- display_name: 'URL',
18
- field_metadata: {
19
- _default: true,
20
- },
21
- mandatory: true,
22
- multiple: false,
23
- uid: 'url',
24
- unique: true,
25
- },
26
- ],
27
- title: 'Authors',
28
- uid: 'authors',
29
- },
30
- }
@@ -1,9 +0,0 @@
1
- export const item = {
2
- content_type_uid: 'sys_assets',
3
- data: {
4
- locale: 'es-es',
5
- uid: 'blt39193a579518bb10',
6
- },
7
- event_at: '2019-01-08T15:19:53.844Z',
8
- type: 'asset_deleted',
9
- }
@@ -1,6 +0,0 @@
1
- export const item = {
2
- content_type_uid: 'del',
3
- data: {},
4
- event_at: '2019-01-08T15:21:10.552Z',
5
- type: 'content_type_deleted',
6
- }
@@ -1,9 +0,0 @@
1
- export const item = {
2
- content_type_uid: 'a',
3
- data: {
4
- locale: 'es-es',
5
- uid: 'blt6aa83e702326fc65',
6
- },
7
- event_at: '2019-01-08T15:20:17.873Z',
8
- type: 'entry_deleted',
9
- }
@@ -1,32 +0,0 @@
1
- export const response = {
2
- items: [
3
- {
4
- content_type_uid: 'del',
5
- data: {},
6
- event_at: '2019-01-08T15:21:10.552Z',
7
- type: 'content_type_deleted',
8
- },
9
- {
10
- content_type_uid: 'a',
11
- data: {
12
- locale: 'es-es',
13
- uid: 'blt6aa83e702326fc65',
14
- },
15
- event_at: '2019-01-08T15:20:17.873Z',
16
- type: 'entry_deleted',
17
- },
18
- {
19
- content_type_uid: 'sys_assets',
20
- data: {
21
- locale: 'es-es',
22
- uid: 'blt39193a579518bb10',
23
- },
24
- event_at: '2019-01-08T15:19:53.844Z',
25
- type: 'asset_deleted',
26
- },
27
- ],
28
- limit: 100,
29
- skip: 0,
30
- sync_token: 'delete-token',
31
- total_count: 3,
32
- }
@@ -1,7 +0,0 @@
1
- export const response = {
2
- items: [],
3
- limit: 100,
4
- sync_token: 'last-token',
5
- skip: 0,
6
- total_count: 0,
7
- }
@@ -1,31 +0,0 @@
1
- export const response = {
2
- items: [
3
- {
4
- content_type_uid: 'authors',
5
- data: {
6
- locale: 'es-es',
7
- publish_details: {
8
- locale: 'es-es',
9
- time: '2019-01-04T20:37:11.052Z',
10
- },
11
- title: 'Test Global Search',
12
- uid: 'blt862233378d02b304',
13
- },
14
- event_at: '2019-01-04T20:37:11.052Z',
15
- type: 'entry_published',
16
- },
17
- {
18
- content_type_uid: 'authors',
19
- data: {
20
- locale: 'es-es',
21
- uid: 'blt1e5bcf16685e2505',
22
- },
23
- event_at: '2019-01-07T13:42:00.625Z',
24
- type: 'entry_unpublished',
25
- },
26
- ],
27
- limit: 100,
28
- skip: 0,
29
- sync_token: 'entries-token',
30
- total_count: 2,
31
- }
@@ -1,32 +0,0 @@
1
- export const response = {
2
- items: [
3
- {
4
- content_type_uid: 'authors',
5
- data: {
6
- locale: 'es-es',
7
- publish_details: {
8
- locale: 'es-es',
9
- time: '2019-01-04T20:37:11.052Z',
10
- },
11
- title: 'Test Global Search',
12
- uid: 'blt862233378d02b304',
13
- },
14
- event_at: '2019-01-04T20:37:11.052Z',
15
- type: 'entry_published',
16
- },
17
- {
18
- content_type_uid: 'sys_assets',
19
- data: {
20
- publish_details: {
21
- locale: 'es-es',
22
- time: '2019-01-02T13:42:58.721Z',
23
- },
24
- title: 'medium.png',
25
- uid: 'blt2a94dd7005d1229c',
26
- },
27
- event_at: '2019-01-04T20:37:11.052Z',
28
- type: 'asset_published',
29
- },
30
- ],
31
- pagination_token: 'pagination-token-2',
32
- }