@forge/migrations 0.0.0-experimental-416047f

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 (45) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +22 -0
  3. package/out/__test__/errors.test.d.ts +2 -0
  4. package/out/__test__/errors.test.d.ts.map +1 -0
  5. package/out/__test__/errors.test.js +16 -0
  6. package/out/__test__/migration.test.d.ts +2 -0
  7. package/out/__test__/migration.test.d.ts.map +1 -0
  8. package/out/__test__/migration.test.js +221 -0
  9. package/out/__test__/query-api.test.d.ts +2 -0
  10. package/out/__test__/query-api.test.d.ts.map +1 -0
  11. package/out/__test__/query-api.test.js +144 -0
  12. package/out/index.d.ts +3 -0
  13. package/out/index.d.ts.map +1 -0
  14. package/out/index.js +5 -0
  15. package/out/migration/errors.d.ts +6 -0
  16. package/out/migration/errors.d.ts.map +1 -0
  17. package/out/migration/errors.js +15 -0
  18. package/out/migration/index.d.ts +22 -0
  19. package/out/migration/index.d.ts.map +1 -0
  20. package/out/migration/index.js +25 -0
  21. package/out/migration/migration-adaptor.d.ts +60 -0
  22. package/out/migration/migration-adaptor.d.ts.map +1 -0
  23. package/out/migration/migration-adaptor.js +2 -0
  24. package/out/migration/migration.d.ts +14 -0
  25. package/out/migration/migration.d.ts.map +1 -0
  26. package/out/migration/migration.js +81 -0
  27. package/out/migration/query-api.d.ts +11 -0
  28. package/out/migration/query-api.d.ts.map +1 -0
  29. package/out/migration/query-api.js +22 -0
  30. package/out/migration/utils.d.ts +5 -0
  31. package/out/migration/utils.d.ts.map +1 -0
  32. package/out/migration/utils.js +33 -0
  33. package/package.json +21 -0
  34. package/src/__test__/errors.test.ts +15 -0
  35. package/src/__test__/migration.test.ts +243 -0
  36. package/src/__test__/query-api.test.ts +177 -0
  37. package/src/index.ts +3 -0
  38. package/src/migration/errors.ts +13 -0
  39. package/src/migration/index.ts +33 -0
  40. package/src/migration/migration-adaptor.ts +71 -0
  41. package/src/migration/migration.ts +111 -0
  42. package/src/migration/query-api.ts +24 -0
  43. package/src/migration/utils.ts +31 -0
  44. package/tsconfig.json +13 -0
  45. package/tsconfig.tsbuildinfo +1504 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @forge/migrations
2
+
3
+ ## 0.0.0-experimental-416047f
4
+
5
+ ### Minor Changes
6
+
7
+ - 824eea3: Adding 2 paginated endpoints in query format to fetch mappings and container details from app migration platform
8
+
9
+ ## 0.1.0-next.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 824eea3: Adding 2 paginated endpoints in query format to fetch mappings and container details from app migration platform
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Forge Migrations
2
+
3
+ API methods exposed to perform app migrations in Forge apps. These include methods to simplify calls to app migration platform.
4
+
5
+ ## Requirements
6
+
7
+ See [Set up Forge](https://developer.atlassian.com/platform/forge/set-up-forge/) for details of the software required to develop Forge apps.
8
+
9
+ ## Usage
10
+
11
+ In your Forge app, include the following:
12
+
13
+ ```
14
+
15
+ import migration from '@forge/migrations';
16
+
17
+ ```
18
+
19
+
20
+ ## Support
21
+
22
+ See [Get help](https://developer.atlassian.com/platform/forge/get-help/) for how to get help and provide feedback.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=errors.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/__test__/errors.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const errors_1 = require("../migration/errors");
4
+ describe('APIError', () => {
5
+ describe('forStatus', () => {
6
+ it.each([
7
+ [400, 'Bad request'],
8
+ [401, 'Unauthorized'],
9
+ [403, 'Forbidden'],
10
+ [404, 'Not Found'],
11
+ [500, 'Internal server error']
12
+ ])('should contain the correct error message for a code of %s', (status, message) => {
13
+ expect(errors_1.APIError.forStatus(status, message).message).toEqual(message);
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=migration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.test.d.ts","sourceRoot":"","sources":["../../src/__test__/migration.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const errors_1 = require("../migration/errors");
5
+ const migration_1 = require("../migration");
6
+ const jest_when_1 = require("jest-when");
7
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
8
+ const utils_1 = require("ts-jest/utils");
9
+ let transferId;
10
+ let invalidTransferId;
11
+ let progress;
12
+ let keys;
13
+ let invalidKeys;
14
+ let namespace;
15
+ let mappingByKeyResponseWithKeys;
16
+ let mappingByKeyResponseWithInvalidKeys;
17
+ let s3Key;
18
+ let invalidS3Key;
19
+ let feedbackPayload;
20
+ let appDataListResponse;
21
+ let appDataPayloadResponse;
22
+ jest.mock('node-fetch');
23
+ describe('migration', () => {
24
+ beforeAll(() => {
25
+ global.api = {
26
+ asApp: jest.fn().mockReturnValue({
27
+ __requestAtlassian: jest.fn()
28
+ })
29
+ };
30
+ transferId = '521ee36a-b673-3dc6-b60b-12460332c200';
31
+ invalidTransferId = '521ee36a-b673-3dc6-b60b-12460332c001';
32
+ });
33
+ describe('sendMigrationProgress', () => {
34
+ beforeAll(() => {
35
+ progress = { status: 'IN_PROGRESS', percent: 10, message: 'reporting' };
36
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
37
+ .calledWith(`/app/migration/forge/v1/progress/${transferId}`, {
38
+ method: 'POST',
39
+ headers: {
40
+ 'content-type': 'application/json'
41
+ },
42
+ body: JSON.stringify(progress)
43
+ })
44
+ .mockReturnValue({
45
+ status: 200,
46
+ text: jest.fn().mockImplementationOnce(() => Promise.resolve()),
47
+ json: jest.fn().mockImplementationOnce(() => Promise.resolve())
48
+ })
49
+ .calledWith(`/app/migration/forge/v1/progress/${invalidTransferId}`, {
50
+ method: 'POST',
51
+ headers: {
52
+ 'content-type': 'application/json'
53
+ },
54
+ body: JSON.stringify(progress)
55
+ })
56
+ .mockReturnValue({
57
+ status: 403,
58
+ statusText: 'Forbidden'
59
+ });
60
+ });
61
+ it('should update progress when sendProgress method called with valid transferId', async () => {
62
+ const returnedValue = migration_1.migration.sendProgress(transferId, progress);
63
+ await expect(returnedValue).resolves.toBeUndefined();
64
+ });
65
+ it('should return 403 when sendProgress method called with invalid transferId', async () => {
66
+ const returnedValue = migration_1.migration.sendProgress(invalidTransferId, progress);
67
+ await expect(returnedValue).rejects.toThrow(errors_1.APIError.forStatus(403, 'Forbidden'));
68
+ });
69
+ });
70
+ describe('getMappingById', () => {
71
+ beforeAll(() => {
72
+ keys = ['email/abc@example.com', 'email/admin@example.com'];
73
+ invalidKeys = ['email/abc@example.com', 'email/admin@example'];
74
+ namespace = 'identity:user';
75
+ mappingByKeyResponseWithKeys =
76
+ '{"email/abc@example.com":"5a20a4d7c6bd4a32df3a711","email/admin@example.com":"5a29c4ae20cfc31b0dc0e112"}';
77
+ mappingByKeyResponseWithInvalidKeys = '{"email/abc@example.com":"5a20a4d7c6bd4a32df3a711"}';
78
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
79
+ .calledWith(`/app/migration/forge/v1/mapping/${transferId}/find?namespace=${namespace}`, {
80
+ method: 'POST',
81
+ headers: {
82
+ 'content-type': 'application/json'
83
+ },
84
+ body: JSON.stringify(keys)
85
+ })
86
+ .mockReturnValue({
87
+ status: 200,
88
+ text: jest.fn().mockResolvedValue(mappingByKeyResponseWithKeys),
89
+ json: jest.fn().mockResolvedValue(JSON.parse(mappingByKeyResponseWithKeys))
90
+ })
91
+ .calledWith(`/app/migration/forge/v1/mapping/${transferId}/find?namespace=${namespace}`, {
92
+ method: 'POST',
93
+ headers: {
94
+ 'content-type': 'application/json'
95
+ },
96
+ body: JSON.stringify(invalidKeys)
97
+ })
98
+ .mockReturnValue({
99
+ status: 200,
100
+ text: jest.fn().mockResolvedValue(mappingByKeyResponseWithInvalidKeys),
101
+ json: jest.fn().mockResolvedValue(JSON.parse(mappingByKeyResponseWithInvalidKeys))
102
+ })
103
+ .calledWith(`/app/migration/forge/v1/mapping/${invalidTransferId}/find?namespace=${namespace}`, {
104
+ method: 'POST',
105
+ headers: {
106
+ 'content-type': 'application/json'
107
+ },
108
+ body: JSON.stringify(keys)
109
+ })
110
+ .mockReturnValue({
111
+ status: 403,
112
+ statusText: 'Forbidden'
113
+ });
114
+ });
115
+ it('should return MappingResponse when getMappingById method called with valid transferId', async () => {
116
+ const returnedValue = await migration_1.migration.getMappingById(transferId, namespace, keys);
117
+ expect(JSON.stringify(returnedValue)).toEqual(mappingByKeyResponseWithKeys);
118
+ });
119
+ it('should return 403 when getMappingById method called with invalid transferId', async () => {
120
+ const returnedValue = migration_1.migration.getMappingById(invalidTransferId, namespace, keys);
121
+ await expect(returnedValue).rejects.toThrow(errors_1.APIError.forStatus(403, 'Forbidden'));
122
+ });
123
+ it('should return MappingResponse except for invalid keys when getMappingById method called with valid transferId', async () => {
124
+ const returnedValue = await migration_1.migration.getMappingById(transferId, namespace, invalidKeys);
125
+ expect(JSON.stringify(returnedValue)).toEqual(mappingByKeyResponseWithInvalidKeys);
126
+ });
127
+ });
128
+ describe('getAppDataList', () => {
129
+ beforeAll(() => {
130
+ appDataListResponse =
131
+ '[{"s3Key":"2ea231e3-ab0d-4236-97f7-26f951df1c11","label":null},{"s3Key":"317a3631-2fef-4940-a418-7096e971eb11","label":null}]';
132
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
133
+ .calledWith(`/app/migration/forge/v1/data/${transferId}/all`)
134
+ .mockReturnValue({
135
+ status: 200,
136
+ text: jest.fn().mockResolvedValue(appDataListResponse),
137
+ json: jest.fn().mockResolvedValue(JSON.parse(appDataListResponse))
138
+ })
139
+ .calledWith(`/app/migration/forge/v1/data/${invalidTransferId}/all`)
140
+ .mockReturnValue({
141
+ status: 403,
142
+ statusText: 'Forbidden'
143
+ });
144
+ });
145
+ it('should return AppDataListResponse when getAppDataList method called with valid transferId', async () => {
146
+ const returnedValue = await migration_1.migration.getAppDataList(transferId);
147
+ expect(returnedValue).toEqual(JSON.parse(appDataListResponse));
148
+ });
149
+ it('should return 403 when getAppDataList method called with invalid transferId', async () => {
150
+ const returnedValue = migration_1.migration.getAppDataList(invalidTransferId);
151
+ await expect(returnedValue).rejects.toThrow(errors_1.APIError.forStatus(403, 'Forbidden'));
152
+ });
153
+ });
154
+ describe('getAppDataPayload', () => {
155
+ beforeAll(() => {
156
+ s3Key = '7941b65d-094b-4305-97f2-e2b412c6db0a';
157
+ invalidS3Key = '7941b65d-094b-4305-97f2-e2b412c000';
158
+ appDataPayloadResponse = '{ "url": "https://rps--stg-east--app-migration-service--ams.s3.amazonaws.com/test"}';
159
+ utils_1.mocked(node_fetch_1.default).mockImplementation(() => Promise.resolve({
160
+ text: () => Promise.resolve('Sample app data')
161
+ }));
162
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
163
+ .calledWith(`/app/migration/forge/v1/data/${s3Key}`)
164
+ .mockReturnValue({
165
+ status: 200,
166
+ text: jest.fn().mockResolvedValue(JSON.stringify(appDataPayloadResponse)),
167
+ json: jest.fn().mockResolvedValue(JSON.parse(appDataPayloadResponse))
168
+ })
169
+ .calledWith(`/app/migration/forge/v1/data/${invalidS3Key}`)
170
+ .mockReturnValue({
171
+ status: 403,
172
+ statusText: 'Forbidden'
173
+ });
174
+ });
175
+ it('should return Response when getAppDataPayload method called with valid S3Key', async () => {
176
+ const returnedValue = await migration_1.migration.getAppDataPayload(s3Key);
177
+ await expect(returnedValue.text()).resolves.toBe('Sample app data');
178
+ });
179
+ it('should return 403 when getAppDataPayload method called with invalid S3Key', async () => {
180
+ const returnedValue = migration_1.migration.getAppDataPayload(invalidS3Key);
181
+ await expect(returnedValue).rejects.toThrow(errors_1.APIError.forStatus(403, 'Forbidden'));
182
+ });
183
+ });
184
+ describe('updateFeedback', () => {
185
+ beforeAll(() => {
186
+ feedbackPayload = { transferId: transferId, msg: 'Current Data processed, send next' };
187
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
188
+ .calledWith(`/app/migration/forge/v1/feedback/${transferId}`, {
189
+ method: 'POST',
190
+ headers: {
191
+ 'content-type': 'application/json'
192
+ },
193
+ body: JSON.stringify(feedbackPayload)
194
+ })
195
+ .mockReturnValue({
196
+ status: 200,
197
+ text: jest.fn().mockImplementationOnce(() => Promise.resolve()),
198
+ json: jest.fn().mockImplementationOnce(() => Promise.resolve())
199
+ })
200
+ .calledWith(`/app/migration/forge/v1/feedback/${invalidTransferId}`, {
201
+ method: 'POST',
202
+ headers: {
203
+ 'content-type': 'application/json'
204
+ },
205
+ body: JSON.stringify(feedbackPayload)
206
+ })
207
+ .mockReturnValue({
208
+ status: 403,
209
+ statusText: 'Forbidden'
210
+ });
211
+ });
212
+ it('should send feedback when updateFeedback method called with valid transferId', async () => {
213
+ const returnedValue = migration_1.migration.updateFeedback(transferId, feedbackPayload);
214
+ await expect(returnedValue).resolves.toBeUndefined();
215
+ });
216
+ it('should return 403 when updateFeedback method called with invalid transferId', async () => {
217
+ const returnedValue = migration_1.migration.updateFeedback(invalidTransferId, feedbackPayload);
218
+ await expect(returnedValue).rejects.toThrow(errors_1.APIError.forStatus(403, 'Forbidden'));
219
+ });
220
+ });
221
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=query-api.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-api.test.d.ts","sourceRoot":"","sources":["../../src/__test__/query-api.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jest_when_1 = require("jest-when");
4
+ const migration_1 = require("../migration");
5
+ describe('QueryApi', () => {
6
+ const transferId = '521ee36a-b673-3dc6-b60b-12460332c200';
7
+ global.api = {
8
+ asApp: jest.fn().mockReturnValue({
9
+ __requestAtlassian: jest.fn()
10
+ })
11
+ };
12
+ describe('getMappings', () => {
13
+ let expectedMappingsResultMany;
14
+ let expectedMappingsResultManyWithCursor;
15
+ let expectedMappingsResultSingle;
16
+ let lastEntityId;
17
+ beforeAll(() => {
18
+ lastEntityId = 'base64:ZW1haWwvYWRtaW5AZXhhbXBsZS5jb20vNg';
19
+ const mappingsResponse = `{"meta":{"pageSize":5000,"hasNext":false,"lastEntity":"${lastEntityId}"},"items":{"email/admin@example.com":"5a29c4ae20cfc31b0dc0eafe","confluence.userkey/2c9682714db22c7c014db22f51970002":"5a29c4ae20cfc31b0dc0eafe"}}`;
20
+ const mappingsResponseWithoutLastEntity = '{"meta":{"pageSize":5000,"hasNext":false,"lastEntity":null},"items":{"email/admin@example.com":"5a29c4ae20cfc31b0dc0eafe","confluence.userkey/2c9682714db22c7c014db22f51970002":"5a29c4ae20cfc31b0dc0eafe"}}';
21
+ const valueObject = '5a29c4ae20cfc31b0dc0eafe';
22
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
23
+ .calledWith(`/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user&lastEntity=${lastEntityId}`)
24
+ .mockReturnValue({
25
+ status: 200,
26
+ text: jest.fn().mockResolvedValue(mappingsResponseWithoutLastEntity),
27
+ json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponseWithoutLastEntity))
28
+ })
29
+ .calledWith(`/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user`)
30
+ .mockReturnValue({
31
+ status: 200,
32
+ text: jest.fn().mockResolvedValue(mappingsResponse),
33
+ json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponse))
34
+ })
35
+ .calledWith(`/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user&pageSize=1`)
36
+ .mockReturnValue({
37
+ status: 200,
38
+ text: jest.fn().mockResolvedValue(mappingsResponse),
39
+ json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponse))
40
+ })
41
+ .calledWith(`/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user&pageSize=1&lastEntity=${lastEntityId}`)
42
+ .mockReturnValue({
43
+ status: 200,
44
+ text: jest.fn().mockResolvedValue(mappingsResponse),
45
+ json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponse))
46
+ });
47
+ expectedMappingsResultMany = {
48
+ results: [
49
+ {
50
+ key: 'email/admin@example.com',
51
+ value: valueObject
52
+ },
53
+ { key: 'confluence.userkey/2c9682714db22c7c014db22f51970002', value: valueObject }
54
+ ],
55
+ nextCursor: undefined
56
+ };
57
+ expectedMappingsResultManyWithCursor = {
58
+ results: [
59
+ { key: 'email/admin@example.com', value: valueObject },
60
+ { key: 'confluence.userkey/2c9682714db22c7c014db22f51970002', value: valueObject }
61
+ ],
62
+ nextCursor: lastEntityId
63
+ };
64
+ expectedMappingsResultSingle = { key: 'email/admin@example.com', value: valueObject };
65
+ });
66
+ it('should fetch multiple values for getMappings', async () => {
67
+ const results = await migration_1.migration.getMappings(transferId, 'identity:user').getMany();
68
+ expect(results).toEqual(expectedMappingsResultManyWithCursor);
69
+ });
70
+ it('should allow specifying a cursor for getMappings with getMany', async () => {
71
+ const result = await migration_1.migration.getMappings(transferId, 'identity:user').cursor(lastEntityId).getMany();
72
+ expect(result).toEqual(expectedMappingsResultMany);
73
+ });
74
+ it('get single mapping when getMappings called with getOne', async () => {
75
+ const result = await migration_1.migration.getMappings(transferId, 'identity:user').getOne();
76
+ expect(result).toEqual(expectedMappingsResultSingle);
77
+ });
78
+ it('should allow specifying a cursor for getMappings with getOne', async () => {
79
+ const result = await migration_1.migration.getMappings(transferId, 'identity:user').cursor(lastEntityId).getOne();
80
+ expect(result).toEqual(expectedMappingsResultSingle);
81
+ });
82
+ });
83
+ describe('getContainers', () => {
84
+ let expectedResultContainersManyWithCursor;
85
+ let expectedResultContainersManyWithoutCursor;
86
+ let expectedResultContainersSingle;
87
+ let lastEntityId;
88
+ beforeAll(() => {
89
+ lastEntityId = 'db11c8af-c82b-3569-9a11-f288c9cc9535';
90
+ const containersResponse = `{"meta":{"pageSize":0,"hasNext":false,"lastEntity":"${lastEntityId}"},"containers":[{ "key": "TES", "sourceId": "884737", "type": "ConfluenceSpace" }]}`;
91
+ const containersResponseWithoutLastEntity = '{"meta":{"pageSize":0,"hasNext":false,"lastEntity":null},"containers":[{ "key": "TES", "sourceId": "884737", "type": "ConfluenceSpace" }]}';
92
+ expectedResultContainersManyWithCursor = {
93
+ results: [{ key: '0', value: { key: 'TES', sourceId: '884737', type: 'ConfluenceSpace' } }],
94
+ nextCursor: lastEntityId
95
+ };
96
+ expectedResultContainersManyWithoutCursor = {
97
+ results: [{ key: '0', value: { key: 'TES', sourceId: '884737', type: 'ConfluenceSpace' } }],
98
+ nextCursor: undefined
99
+ };
100
+ expectedResultContainersSingle = { key: '0', value: { key: 'TES', sourceId: '884737', type: 'ConfluenceSpace' } };
101
+ jest_when_1.when(global.api.asApp().__requestAtlassian)
102
+ .calledWith(`/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace&lastEntity=${lastEntityId}`)
103
+ .mockReturnValue({
104
+ status: 200,
105
+ text: jest.fn().mockResolvedValue(containersResponseWithoutLastEntity),
106
+ json: jest.fn().mockResolvedValue(JSON.parse(containersResponseWithoutLastEntity))
107
+ })
108
+ .calledWith(`/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace`)
109
+ .mockReturnValue({
110
+ status: 200,
111
+ text: jest.fn().mockResolvedValue(containersResponse),
112
+ json: jest.fn().mockResolvedValue(JSON.parse(containersResponse))
113
+ })
114
+ .calledWith(`/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace&pageSize=1`)
115
+ .mockReturnValue({
116
+ status: 200,
117
+ text: jest.fn().mockResolvedValue(containersResponse),
118
+ json: jest.fn().mockResolvedValue(JSON.parse(containersResponse))
119
+ })
120
+ .calledWith(`/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace&pageSize=1&lastEntity=${lastEntityId}`)
121
+ .mockReturnValue({
122
+ status: 200,
123
+ text: jest.fn().mockResolvedValue(containersResponse),
124
+ json: jest.fn().mockResolvedValue(JSON.parse(containersResponse))
125
+ });
126
+ });
127
+ it('should allow specifying a cursor for getContainers with getMany', async () => {
128
+ const result = await migration_1.migration.getContainers(transferId, 'ConfluenceSpace').cursor(lastEntityId).getMany();
129
+ expect(result).toEqual(expectedResultContainersManyWithoutCursor);
130
+ });
131
+ it('should fetch multiple values when getContainers is called with getMany', async () => {
132
+ const result = await migration_1.migration.getContainers(transferId, 'ConfluenceSpace').getMany();
133
+ expect(result).toEqual(expectedResultContainersManyWithCursor);
134
+ });
135
+ it('should allow specifying a cursor for getContainers with getOne', async () => {
136
+ const result = await migration_1.migration.getContainers(transferId, 'ConfluenceSpace').cursor(lastEntityId).getOne();
137
+ expect(result).toEqual(expectedResultContainersSingle);
138
+ });
139
+ it('get single mapping when getContainers called with getOne', async () => {
140
+ const result = await migration_1.migration.getContainers(transferId, 'ConfluenceSpace').getOne();
141
+ expect(result).toEqual(expectedResultContainersSingle);
142
+ });
143
+ });
144
+ });
package/out/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { migration } from './migration';
2
+ export { migration };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/out/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migration = void 0;
4
+ const migration_1 = require("./migration");
5
+ Object.defineProperty(exports, "migration", { enumerable: true, get: function () { return migration_1.migration; } });
@@ -0,0 +1,6 @@
1
+ export declare class APIError extends Error {
2
+ private constructor();
3
+ static forStatus(status: number, message: string): APIError;
4
+ static forUnexpected(message: string): APIError;
5
+ }
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/migration/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IACjC,OAAO;WAIO,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ;WAIpD,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ;CAGvD"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIError = void 0;
4
+ class APIError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ }
8
+ static forStatus(status, message) {
9
+ return new APIError(message);
10
+ }
11
+ static forUnexpected(message) {
12
+ return new APIError(message);
13
+ }
14
+ }
15
+ exports.APIError = APIError;
@@ -0,0 +1,22 @@
1
+ import { Migration } from './migration';
2
+ import { Progress } from './migration-adaptor';
3
+ import { DefaultQueryBuilder } from './query-api';
4
+ export declare const getMigrationInstance: (adapter: Migration) => {
5
+ sendProgress: (transferId: string, progress: Progress) => Promise<void>;
6
+ getMappingById: (transferId: string, namespace: string, keys: Array<string>) => Promise<import("./migration-adaptor").MappingResponse>;
7
+ updateFeedback: (transferId: string, feedback: object) => Promise<void>;
8
+ getAppDataList: (transferId: string) => Promise<import("./migration-adaptor").AppDataListResponse>;
9
+ getAppDataPayload: (s3Key: string) => Promise<import("node-fetch").Response>;
10
+ getMappings: (transferId: string, namespace: string) => DefaultQueryBuilder;
11
+ getContainers: (transferId: string, containerType: string) => DefaultQueryBuilder;
12
+ };
13
+ export declare const migration: {
14
+ sendProgress: (transferId: string, progress: Progress) => Promise<void>;
15
+ getMappingById: (transferId: string, namespace: string, keys: Array<string>) => Promise<import("./migration-adaptor").MappingResponse>;
16
+ updateFeedback: (transferId: string, feedback: object) => Promise<void>;
17
+ getAppDataList: (transferId: string) => Promise<import("./migration-adaptor").AppDataListResponse>;
18
+ getAppDataPayload: (s3Key: string) => Promise<import("node-fetch").Response>;
19
+ getMappings: (transferId: string, namespace: string) => DefaultQueryBuilder;
20
+ getContainers: (transferId: string, containerType: string) => DefaultQueryBuilder;
21
+ };
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migration/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,oBAAoB,YAAa,SAAS;+BAExB,MAAM,YAAY,QAAQ;iCACxB,MAAM,aAAa,MAAM,QAAQ,KAAK,CAAC,MAAM,CAAC;iCAE9C,MAAM,YAAY,MAAM;iCACxB,MAAM;+BACR,MAAM;8BACP,MAAM,aAAa,MAAM;gCAEvB,MAAM,iBAAiB,MAAM;CAG5D,CAAC;AAEF,eAAO,MAAM,SAAS;+BACO,MAAM,YAAY,QAAQ;iCAExB,MAAM,aAAa,MAAM,QAAQ,KAAK,CAAC,MAAM,CAAC;iCAE9C,MAAM,YAAY,MAAM;iCAExB,MAAM;+BACR,MAAM;8BACP,MAAM,aAAa,MAAM;gCAEvB,MAAM,iBAAiB,MAAM;CAE1D,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migration = exports.getMigrationInstance = void 0;
4
+ const migration_1 = require("./migration");
5
+ const query_api_1 = require("./query-api");
6
+ exports.getMigrationInstance = (adapter) => {
7
+ return {
8
+ sendProgress: (transferId, progress) => adapter.sendProgress(transferId, progress),
9
+ getMappingById: (transferId, namespace, keys) => adapter.getMappingById(transferId, namespace, keys),
10
+ updateFeedback: (transferId, feedback) => adapter.updateFeedback(transferId, feedback),
11
+ getAppDataList: (transferId) => adapter.getAppDataList(transferId),
12
+ getAppDataPayload: (s3Key) => adapter.getAppDataPayload(s3Key),
13
+ getMappings: (transferId, namespace) => new query_api_1.DefaultQueryBuilder(adapter, { transferId: transferId, namespace: namespace }),
14
+ getContainers: (transferId, containerType) => new query_api_1.DefaultQueryBuilder(adapter, { transferId: transferId, containerType: containerType })
15
+ };
16
+ };
17
+ exports.migration = {
18
+ sendProgress: (transferId, progress) => exports.getMigrationInstance(new migration_1.Migration()).sendProgress(transferId, progress),
19
+ getMappingById: (transferId, namespace, keys) => exports.getMigrationInstance(new migration_1.Migration()).getMappingById(transferId, namespace, keys),
20
+ updateFeedback: (transferId, feedback) => exports.getMigrationInstance(new migration_1.Migration()).updateFeedback(transferId, feedback),
21
+ getAppDataList: (transferId) => exports.getMigrationInstance(new migration_1.Migration()).getAppDataList(transferId),
22
+ getAppDataPayload: (s3Key) => exports.getMigrationInstance(new migration_1.Migration()).getAppDataPayload(s3Key),
23
+ getMappings: (transferId, namespace) => exports.getMigrationInstance(new migration_1.Migration()).getMappings(transferId, namespace),
24
+ getContainers: (transferId, containerType) => exports.getMigrationInstance(new migration_1.Migration()).getContainers(transferId, containerType)
25
+ };
@@ -0,0 +1,60 @@
1
+ import { Response } from 'node-fetch';
2
+ export interface MigrationAdapter {
3
+ sendProgress(transferId: string, progress: Progress): Promise<void>;
4
+ getMappingById(transferId: string, namespace: string, keys: Array<string>): Promise<MappingResponse>;
5
+ getAppDataList(transferId: string): Promise<AppDataListResponse>;
6
+ getAppDataPayload(s3Key: string): Promise<Response>;
7
+ updateFeedback(transferId: string, feedback: object): Promise<void>;
8
+ }
9
+ export interface MappingResponse {
10
+ result: Map<string, string>;
11
+ }
12
+ export interface AppData {
13
+ s3Key: string;
14
+ label: string;
15
+ }
16
+ export interface AppDataListResponse {
17
+ result: Set<AppData>;
18
+ }
19
+ export interface AppDataPayloadResponse {
20
+ url: string;
21
+ }
22
+ export interface Progress {
23
+ status: string;
24
+ percent: number;
25
+ message: string;
26
+ }
27
+ export interface PaginationMappingResponse {
28
+ meta: PaginationResponseMeta;
29
+ items: Map<string, string>;
30
+ }
31
+ interface PaginationResponseMeta {
32
+ pageSize: number;
33
+ hasNext: boolean;
34
+ lastEntity?: string;
35
+ }
36
+ export interface PaginationContainerResponse {
37
+ containers: Array<object>;
38
+ meta: PaginationResponseMeta;
39
+ }
40
+ export interface ListOptions {
41
+ transferId: string;
42
+ namespace?: string;
43
+ containerType?: string;
44
+ cursor?: string;
45
+ }
46
+ export interface Result {
47
+ key: string;
48
+ value: object;
49
+ }
50
+ export interface ListResults {
51
+ results: Result[];
52
+ nextCursor?: string;
53
+ }
54
+ export interface QueryBuilder {
55
+ cursor(cursor: string): QueryBuilder;
56
+ getMany(): Promise<ListResults>;
57
+ getOne(): Promise<Result | undefined>;
58
+ }
59
+ export {};
60
+ //# sourceMappingURL=migration-adaptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-adaptor.d.ts","sourceRoot":"","sources":["../../src/migration/migration-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACrG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACjE,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpD,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAED,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IACrC,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAChC,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { Response } from 'node-fetch';
2
+ import { AppDataListResponse, MappingResponse, MigrationAdapter, Progress, ListOptions, ListResults } from './migration-adaptor';
3
+ export declare class Migration implements MigrationAdapter {
4
+ private readonly basePath;
5
+ sendProgress: (transferId: string, progress: Progress) => Promise<void>;
6
+ getMappingById: (transferId: string, namespace: string, keys: Array<string>) => Promise<MappingResponse>;
7
+ getAppDataList: (transferId: string) => Promise<AppDataListResponse>;
8
+ getAppDataPayload: (s3Key: string) => Promise<Response>;
9
+ updateFeedback: (transferId: string, feedback: object) => Promise<void>;
10
+ getMappings: (transferId: string, namespace?: string | undefined, lastEntity?: string | undefined, pageSize?: number | undefined) => Promise<ListResults>;
11
+ getContainers: (transferId: string, containerType?: string | undefined, lastEntity?: string | undefined, pageSize?: number | undefined) => Promise<ListResults>;
12
+ list: (options: ListOptions, pageSize?: number | undefined) => Promise<ListResults>;
13
+ }
14
+ //# sourceMappingURL=migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/migration/migration.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EACL,mBAAmB,EAEnB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,WAAW,EAIZ,MAAM,qBAAqB,CAAC;AAI7B,qBAAa,SAAU,YAAW,gBAAgB;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IAEtD,YAAY,eAAsB,MAAM,YAAY,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAG1E;IAEF,cAAc,eAAsB,MAAM,aAAa,MAAM,QAAQ,KAAK,CAAC,MAAM,CAAC,KAAG,OAAO,CAAC,eAAe,CAAC,CAG3G;IAEF,cAAc,eAAsB,MAAM,KAAG,OAAO,CAAC,mBAAmB,CAAC,CAGvE;IAEF,iBAAiB,UAAiB,MAAM,KAAG,OAAO,CAAC,QAAQ,CAAC,CAI1D;IAEF,cAAc,eAAsB,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC,CAG1E;IAEF,WAAW,eACG,MAAM,qGAIjB,OAAO,CAAC,WAAW,CAAC,CAuBrB;IAEF,aAAa,eACC,MAAM,yGAIjB,OAAO,CAAC,WAAW,CAAC,CAsBrB;IAEF,IAAI,YAAmB,WAAW,oCAAsB,OAAO,CAAC,WAAW,CAAC,CAI1E;CACH"}