@forge/migrations 0.1.0 → 0.1.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.
@@ -1,243 +0,0 @@
1
- import { APIError } from '../migration/errors';
2
- import { migration } from '../migration';
3
- import { Progress } from '../migration/migration-adaptor';
4
- import { when } from 'jest-when';
5
- import fetch, { Response } from 'node-fetch';
6
- import { mocked } from 'ts-jest/utils';
7
-
8
- let transferId: string;
9
- let invalidTransferId: string;
10
- let progress: Progress;
11
- let keys: string[];
12
- let invalidKeys: string[];
13
- let namespace: string;
14
- let mappingByKeyResponseWithKeys: string;
15
- let mappingByKeyResponseWithInvalidKeys: string;
16
- let s3Key: string;
17
- let invalidS3Key: string;
18
- let feedbackPayload: object;
19
- let appDataListResponse: string;
20
- let appDataPayloadResponse: string;
21
- jest.mock('node-fetch');
22
-
23
- describe('migration', () => {
24
- beforeAll(() => {
25
- (global as any).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
-
34
- describe('sendMigrationProgress', () => {
35
- beforeAll(() => {
36
- progress = { status: 'IN_PROGRESS', percent: 10, message: 'reporting' };
37
- when((global as any).api.asApp().__requestAtlassian)
38
- .calledWith(`/app/migration/forge/v1/progress/${transferId}`, {
39
- method: 'POST',
40
- headers: {
41
- 'content-type': 'application/json'
42
- },
43
- body: JSON.stringify(progress)
44
- })
45
- .mockReturnValue({
46
- status: 200,
47
- text: jest.fn().mockImplementationOnce(() => Promise.resolve()),
48
- json: jest.fn().mockImplementationOnce(() => Promise.resolve())
49
- })
50
- .calledWith(`/app/migration/forge/v1/progress/${invalidTransferId}`, {
51
- method: 'POST',
52
- headers: {
53
- 'content-type': 'application/json'
54
- },
55
- body: JSON.stringify(progress)
56
- })
57
- .mockReturnValue({
58
- status: 403,
59
- statusText: 'Forbidden'
60
- });
61
- });
62
-
63
- it('should update progress when sendProgress method called with valid transferId', async () => {
64
- const returnedValue = migration.sendProgress(transferId, progress);
65
- await expect(returnedValue).resolves.toBeUndefined();
66
- });
67
-
68
- it('should return 403 when sendProgress method called with invalid transferId', async () => {
69
- const returnedValue = migration.sendProgress(invalidTransferId, progress);
70
- await expect(returnedValue).rejects.toThrow(APIError.forStatus(403, 'Forbidden'));
71
- });
72
- });
73
-
74
- describe('getMappingById', () => {
75
- beforeAll(() => {
76
- keys = ['email/abc@example.com', 'email/admin@example.com'];
77
- invalidKeys = ['email/abc@example.com', 'email/admin@example'];
78
- namespace = 'identity:user';
79
- mappingByKeyResponseWithKeys =
80
- '{"email/abc@example.com":"5a20a4d7c6bd4a32df3a711","email/admin@example.com":"5a29c4ae20cfc31b0dc0e112"}';
81
- mappingByKeyResponseWithInvalidKeys = '{"email/abc@example.com":"5a20a4d7c6bd4a32df3a711"}';
82
-
83
- when((global as any).api.asApp().__requestAtlassian)
84
- .calledWith(`/app/migration/forge/v1/mapping/${transferId}/find?namespace=${namespace}`, {
85
- method: 'POST',
86
- headers: {
87
- 'content-type': 'application/json'
88
- },
89
- body: JSON.stringify(keys)
90
- })
91
- .mockReturnValue({
92
- status: 200,
93
- text: jest.fn().mockResolvedValue(mappingByKeyResponseWithKeys),
94
- json: jest.fn().mockResolvedValue(JSON.parse(mappingByKeyResponseWithKeys))
95
- })
96
- .calledWith(`/app/migration/forge/v1/mapping/${transferId}/find?namespace=${namespace}`, {
97
- method: 'POST',
98
- headers: {
99
- 'content-type': 'application/json'
100
- },
101
- body: JSON.stringify(invalidKeys)
102
- })
103
- .mockReturnValue({
104
- status: 200,
105
- text: jest.fn().mockResolvedValue(mappingByKeyResponseWithInvalidKeys),
106
- json: jest.fn().mockResolvedValue(JSON.parse(mappingByKeyResponseWithInvalidKeys))
107
- })
108
- .calledWith(`/app/migration/forge/v1/mapping/${invalidTransferId}/find?namespace=${namespace}`, {
109
- method: 'POST',
110
- headers: {
111
- 'content-type': 'application/json'
112
- },
113
- body: JSON.stringify(keys)
114
- })
115
- .mockReturnValue({
116
- status: 403,
117
- statusText: 'Forbidden'
118
- });
119
- });
120
-
121
- it('should return MappingResponse when getMappingById method called with valid transferId', async () => {
122
- const returnedValue = await migration.getMappingById(transferId, namespace, keys);
123
- expect(JSON.stringify(returnedValue)).toEqual(mappingByKeyResponseWithKeys);
124
- });
125
-
126
- it('should return 403 when getMappingById method called with invalid transferId', async () => {
127
- const returnedValue = migration.getMappingById(invalidTransferId, namespace, keys);
128
- await expect(returnedValue).rejects.toThrow(APIError.forStatus(403, 'Forbidden'));
129
- });
130
-
131
- it('should return MappingResponse except for invalid keys when getMappingById method called with valid transferId', async () => {
132
- const returnedValue = await migration.getMappingById(transferId, namespace, invalidKeys);
133
- expect(JSON.stringify(returnedValue)).toEqual(mappingByKeyResponseWithInvalidKeys);
134
- });
135
- });
136
-
137
- describe('getAppDataList', () => {
138
- beforeAll(() => {
139
- appDataListResponse =
140
- '[{"s3Key":"2ea231e3-ab0d-4236-97f7-26f951df1c11","label":null},{"s3Key":"317a3631-2fef-4940-a418-7096e971eb11","label":null}]';
141
-
142
- when((global as any).api.asApp().__requestAtlassian)
143
- .calledWith(`/app/migration/forge/v1/data/${transferId}/all`)
144
- .mockReturnValue({
145
- status: 200,
146
- text: jest.fn().mockResolvedValue(appDataListResponse),
147
- json: jest.fn().mockResolvedValue(JSON.parse(appDataListResponse))
148
- })
149
- .calledWith(`/app/migration/forge/v1/data/${invalidTransferId}/all`)
150
- .mockReturnValue({
151
- status: 403,
152
- statusText: 'Forbidden'
153
- });
154
- });
155
-
156
- it('should return AppDataListResponse when getAppDataList method called with valid transferId', async () => {
157
- const returnedValue = await migration.getAppDataList(transferId);
158
- expect(returnedValue).toEqual(JSON.parse(appDataListResponse));
159
- });
160
-
161
- it('should return 403 when getAppDataList method called with invalid transferId', async () => {
162
- const returnedValue = migration.getAppDataList(invalidTransferId);
163
- await expect(returnedValue).rejects.toThrow(APIError.forStatus(403, 'Forbidden'));
164
- });
165
- });
166
-
167
- describe('getAppDataPayload', () => {
168
- beforeAll(() => {
169
- s3Key = '7941b65d-094b-4305-97f2-e2b412c6db0a';
170
- invalidS3Key = '7941b65d-094b-4305-97f2-e2b412c000';
171
- appDataPayloadResponse = '{ "url": "https://rps--stg-east--app-migration-service--ams.s3.amazonaws.com/test"}';
172
-
173
- mocked(fetch).mockImplementation(() =>
174
- Promise.resolve({
175
- text: () => Promise.resolve('Sample app data')
176
- } as Response)
177
- );
178
-
179
- when((global as any).api.asApp().__requestAtlassian)
180
- .calledWith(`/app/migration/forge/v1/data/${s3Key}`)
181
- .mockReturnValue({
182
- status: 200,
183
- text: jest.fn().mockResolvedValue(JSON.stringify(appDataPayloadResponse)),
184
- json: jest.fn().mockResolvedValue(JSON.parse(appDataPayloadResponse))
185
- })
186
- .calledWith(`/app/migration/forge/v1/data/${invalidS3Key}`)
187
- .mockReturnValue({
188
- status: 403,
189
- statusText: 'Forbidden'
190
- });
191
- });
192
-
193
- it('should return Response when getAppDataPayload method called with valid S3Key', async () => {
194
- const returnedValue = await migration.getAppDataPayload(s3Key);
195
- await expect(returnedValue.text()).resolves.toBe('Sample app data');
196
- });
197
-
198
- it('should return 403 when getAppDataPayload method called with invalid S3Key', async () => {
199
- const returnedValue = migration.getAppDataPayload(invalidS3Key);
200
- await expect(returnedValue).rejects.toThrow(APIError.forStatus(403, 'Forbidden'));
201
- });
202
- });
203
-
204
- describe('updateFeedback', () => {
205
- beforeAll(() => {
206
- feedbackPayload = { transferId: transferId, msg: 'Current Data processed, send next' };
207
- when((global as any).api.asApp().__requestAtlassian)
208
- .calledWith(`/app/migration/forge/v1/feedback/${transferId}`, {
209
- method: 'POST',
210
- headers: {
211
- 'content-type': 'application/json'
212
- },
213
- body: JSON.stringify(feedbackPayload)
214
- })
215
- .mockReturnValue({
216
- status: 200,
217
- text: jest.fn().mockImplementationOnce(() => Promise.resolve()),
218
- json: jest.fn().mockImplementationOnce(() => Promise.resolve())
219
- })
220
- .calledWith(`/app/migration/forge/v1/feedback/${invalidTransferId}`, {
221
- method: 'POST',
222
- headers: {
223
- 'content-type': 'application/json'
224
- },
225
- body: JSON.stringify(feedbackPayload)
226
- })
227
- .mockReturnValue({
228
- status: 403,
229
- statusText: 'Forbidden'
230
- });
231
- });
232
-
233
- it('should send feedback when updateFeedback method called with valid transferId', async () => {
234
- const returnedValue = migration.updateFeedback(transferId, feedbackPayload);
235
- await expect(returnedValue).resolves.toBeUndefined();
236
- });
237
-
238
- it('should return 403 when updateFeedback method called with invalid transferId', async () => {
239
- const returnedValue = migration.updateFeedback(invalidTransferId, feedbackPayload);
240
- await expect(returnedValue).rejects.toThrow(APIError.forStatus(403, 'Forbidden'));
241
- });
242
- });
243
- });
@@ -1,177 +0,0 @@
1
- import { ListResults, Result } from '../migration/migration-adaptor';
2
- import { when } from 'jest-when';
3
- import { migration } from '../migration';
4
-
5
- describe('QueryApi', () => {
6
- const transferId = '521ee36a-b673-3dc6-b60b-12460332c200';
7
-
8
- (global as any).api = {
9
- asApp: jest.fn().mockReturnValue({
10
- __requestAtlassian: jest.fn()
11
- })
12
- };
13
-
14
- describe('getMappings', () => {
15
- let expectedMappingsResultMany: ListResults;
16
- let expectedMappingsResultManyWithCursor: ListResults;
17
- let expectedMappingsResultSingle: Result;
18
- let lastEntityId: string;
19
-
20
- beforeAll(() => {
21
- lastEntityId = 'base64:ZW1haWwvYWRtaW5AZXhhbXBsZS5jb20vNg';
22
- const mappingsResponse = `{"meta":{"pageSize":5000,"hasNext":false,"lastEntity":"${lastEntityId}"},"items":{"email/admin@example.com":"5a29c4ae20cfc31b0dc0eafe","confluence.userkey/2c9682714db22c7c014db22f51970002":"5a29c4ae20cfc31b0dc0eafe"}}`;
23
-
24
- const mappingsResponseWithoutLastEntity =
25
- '{"meta":{"pageSize":5000,"hasNext":false,"lastEntity":null},"items":{"email/admin@example.com":"5a29c4ae20cfc31b0dc0eafe","confluence.userkey/2c9682714db22c7c014db22f51970002":"5a29c4ae20cfc31b0dc0eafe"}}';
26
-
27
- const valueObject = '5a29c4ae20cfc31b0dc0eafe' as any;
28
- when((global as any).api.asApp().__requestAtlassian)
29
- .calledWith(
30
- `/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user&lastEntity=${lastEntityId}`
31
- )
32
- .mockReturnValue({
33
- status: 200,
34
- text: jest.fn().mockResolvedValue(mappingsResponseWithoutLastEntity),
35
- json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponseWithoutLastEntity))
36
- })
37
- .calledWith(`/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user`)
38
- .mockReturnValue({
39
- status: 200,
40
- text: jest.fn().mockResolvedValue(mappingsResponse),
41
- json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponse))
42
- })
43
- .calledWith(`/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user&pageSize=1`)
44
- .mockReturnValue({
45
- status: 200,
46
- text: jest.fn().mockResolvedValue(mappingsResponse),
47
- json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponse))
48
- })
49
- .calledWith(
50
- `/app/migration/forge/v1/mapping/${transferId}/page?namespace=identity:user&pageSize=1&lastEntity=${lastEntityId}`
51
- )
52
- .mockReturnValue({
53
- status: 200,
54
- text: jest.fn().mockResolvedValue(mappingsResponse),
55
- json: jest.fn().mockResolvedValue(JSON.parse(mappingsResponse))
56
- });
57
-
58
- expectedMappingsResultMany = {
59
- results: [
60
- {
61
- key: 'email/admin@example.com',
62
- value: valueObject
63
- },
64
- { key: 'confluence.userkey/2c9682714db22c7c014db22f51970002', value: valueObject }
65
- ],
66
- nextCursor: undefined
67
- };
68
-
69
- expectedMappingsResultManyWithCursor = {
70
- results: [
71
- { key: 'email/admin@example.com', value: valueObject },
72
- { key: 'confluence.userkey/2c9682714db22c7c014db22f51970002', value: valueObject }
73
- ],
74
- nextCursor: lastEntityId
75
- };
76
- expectedMappingsResultSingle = { key: 'email/admin@example.com', value: valueObject };
77
- });
78
-
79
- it('should fetch multiple values for getMappings', async () => {
80
- const results = await migration.getMappings(transferId, 'identity:user').getMany();
81
-
82
- expect(results).toEqual(expectedMappingsResultManyWithCursor);
83
- });
84
-
85
- it('should allow specifying a cursor for getMappings with getMany', async () => {
86
- const result = await migration.getMappings(transferId, 'identity:user').cursor(lastEntityId).getMany();
87
- expect(result).toEqual(expectedMappingsResultMany);
88
- });
89
-
90
- it('get single mapping when getMappings called with getOne', async () => {
91
- const result = await migration.getMappings(transferId, 'identity:user').getOne();
92
-
93
- expect(result).toEqual(expectedMappingsResultSingle);
94
- });
95
-
96
- it('should allow specifying a cursor for getMappings with getOne', async () => {
97
- const result = await migration.getMappings(transferId, 'identity:user').cursor(lastEntityId).getOne();
98
-
99
- expect(result).toEqual(expectedMappingsResultSingle);
100
- });
101
- });
102
-
103
- describe('getContainers', () => {
104
- let expectedResultContainersManyWithCursor: ListResults;
105
- let expectedResultContainersManyWithoutCursor: ListResults;
106
- let expectedResultContainersSingle: Result;
107
- let lastEntityId: string;
108
-
109
- beforeAll(() => {
110
- lastEntityId = 'db11c8af-c82b-3569-9a11-f288c9cc9535';
111
- const containersResponse = `{"meta":{"pageSize":0,"hasNext":false,"lastEntity":"${lastEntityId}"},"containers":[{ "key": "TES", "sourceId": "884737", "type": "ConfluenceSpace" }]}`;
112
-
113
- const containersResponseWithoutLastEntity =
114
- '{"meta":{"pageSize":0,"hasNext":false,"lastEntity":null},"containers":[{ "key": "TES", "sourceId": "884737", "type": "ConfluenceSpace" }]}';
115
-
116
- expectedResultContainersManyWithCursor = {
117
- results: [{ key: '0', value: { key: 'TES', sourceId: '884737', type: 'ConfluenceSpace' } }],
118
- nextCursor: lastEntityId
119
- };
120
- expectedResultContainersManyWithoutCursor = {
121
- results: [{ key: '0', value: { key: 'TES', sourceId: '884737', type: 'ConfluenceSpace' } }],
122
- nextCursor: undefined
123
- };
124
- expectedResultContainersSingle = { key: '0', value: { key: 'TES', sourceId: '884737', type: 'ConfluenceSpace' } };
125
-
126
- when((global as any).api.asApp().__requestAtlassian)
127
- .calledWith(
128
- `/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace&lastEntity=${lastEntityId}`
129
- )
130
- .mockReturnValue({
131
- status: 200,
132
- text: jest.fn().mockResolvedValue(containersResponseWithoutLastEntity),
133
- json: jest.fn().mockResolvedValue(JSON.parse(containersResponseWithoutLastEntity))
134
- })
135
- .calledWith(`/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace`)
136
- .mockReturnValue({
137
- status: 200,
138
- text: jest.fn().mockResolvedValue(containersResponse),
139
- json: jest.fn().mockResolvedValue(JSON.parse(containersResponse))
140
- })
141
- .calledWith(`/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace&pageSize=1`)
142
- .mockReturnValue({
143
- status: 200,
144
- text: jest.fn().mockResolvedValue(containersResponse),
145
- json: jest.fn().mockResolvedValue(JSON.parse(containersResponse))
146
- })
147
- .calledWith(
148
- `/app/migration/forge/v1/container/${transferId}/page?containerType=ConfluenceSpace&pageSize=1&lastEntity=${lastEntityId}`
149
- )
150
- .mockReturnValue({
151
- status: 200,
152
- text: jest.fn().mockResolvedValue(containersResponse),
153
- json: jest.fn().mockResolvedValue(JSON.parse(containersResponse))
154
- });
155
- });
156
-
157
- it('should allow specifying a cursor for getContainers with getMany', async () => {
158
- const result = await migration.getContainers(transferId, 'ConfluenceSpace').cursor(lastEntityId).getMany();
159
- expect(result).toEqual(expectedResultContainersManyWithoutCursor);
160
- });
161
-
162
- it('should fetch multiple values when getContainers is called with getMany', async () => {
163
- const result = await migration.getContainers(transferId, 'ConfluenceSpace').getMany();
164
- expect(result).toEqual(expectedResultContainersManyWithCursor);
165
- });
166
-
167
- it('should allow specifying a cursor for getContainers with getOne', async () => {
168
- const result = await migration.getContainers(transferId, 'ConfluenceSpace').cursor(lastEntityId).getOne();
169
- expect(result).toEqual(expectedResultContainersSingle);
170
- });
171
-
172
- it('get single mapping when getContainers called with getOne', async () => {
173
- const result = await migration.getContainers(transferId, 'ConfluenceSpace').getOne();
174
- expect(result).toEqual(expectedResultContainersSingle);
175
- });
176
- });
177
- });
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import { migration } from './migration';
2
-
3
- export { migration };
@@ -1,13 +0,0 @@
1
- export class APIError extends Error {
2
- private constructor(message: string) {
3
- super(message);
4
- }
5
-
6
- public static forStatus(status: number, message: string): APIError {
7
- return new APIError(message);
8
- }
9
-
10
- public static forUnexpected(message: string): APIError {
11
- return new APIError(message);
12
- }
13
- }
@@ -1,33 +0,0 @@
1
- import { Migration } from './migration';
2
- import { Progress } from './migration-adaptor';
3
- import { DefaultQueryBuilder } from './query-api';
4
-
5
- export const getMigrationInstance = (adapter: Migration) => {
6
- return {
7
- sendProgress: (transferId: string, progress: Progress) => adapter.sendProgress(transferId, progress),
8
- getMappingById: (transferId: string, namespace: string, keys: Array<string>) =>
9
- adapter.getMappingById(transferId, namespace, keys),
10
- updateFeedback: (transferId: string, feedback: object) => adapter.updateFeedback(transferId, feedback),
11
- getAppDataList: (transferId: string) => adapter.getAppDataList(transferId),
12
- getAppDataPayload: (s3Key: string) => adapter.getAppDataPayload(s3Key),
13
- getMappings: (transferId: string, namespace: string) =>
14
- new DefaultQueryBuilder(adapter, { transferId: transferId, namespace: namespace }),
15
- getContainers: (transferId: string, containerType: string) =>
16
- new DefaultQueryBuilder(adapter, { transferId: transferId, containerType: containerType })
17
- };
18
- };
19
-
20
- export const migration = {
21
- sendProgress: (transferId: string, progress: Progress) =>
22
- getMigrationInstance(new Migration()).sendProgress(transferId, progress),
23
- getMappingById: (transferId: string, namespace: string, keys: Array<string>) =>
24
- getMigrationInstance(new Migration()).getMappingById(transferId, namespace, keys),
25
- updateFeedback: (transferId: string, feedback: object) =>
26
- getMigrationInstance(new Migration()).updateFeedback(transferId, feedback),
27
- getAppDataList: (transferId: string) => getMigrationInstance(new Migration()).getAppDataList(transferId),
28
- getAppDataPayload: (s3Key: string) => getMigrationInstance(new Migration()).getAppDataPayload(s3Key),
29
- getMappings: (transferId: string, namespace: string) =>
30
- getMigrationInstance(new Migration()).getMappings(transferId, namespace),
31
- getContainers: (transferId: string, containerType: string) =>
32
- getMigrationInstance(new Migration()).getContainers(transferId, containerType)
33
- };
@@ -1,71 +0,0 @@
1
- import { Response } from 'node-fetch';
2
-
3
- export interface MigrationAdapter {
4
- sendProgress(transferId: string, progress: Progress): Promise<void>;
5
- getMappingById(transferId: string, namespace: string, keys: Array<string>): Promise<MappingResponse>;
6
- getAppDataList(transferId: string): Promise<AppDataListResponse>;
7
- getAppDataPayload(s3Key: string): Promise<Response>;
8
- updateFeedback(transferId: string, feedback: object): Promise<void>;
9
- }
10
-
11
- export interface MappingResponse {
12
- result: Map<string, string>;
13
- }
14
-
15
- export interface AppData {
16
- s3Key: string;
17
- label: string;
18
- }
19
-
20
- export interface AppDataListResponse {
21
- result: Set<AppData>;
22
- }
23
-
24
- export interface AppDataPayloadResponse {
25
- url: string;
26
- }
27
-
28
- export interface Progress {
29
- status: string;
30
- percent: number;
31
- message: string;
32
- }
33
-
34
- export interface PaginationMappingResponse {
35
- meta: PaginationResponseMeta;
36
- items: Map<string, string>;
37
- }
38
-
39
- interface PaginationResponseMeta {
40
- pageSize: number;
41
- hasNext: boolean;
42
- lastEntity?: string;
43
- }
44
-
45
- export interface PaginationContainerResponse {
46
- containers: Array<object>;
47
- meta: PaginationResponseMeta;
48
- }
49
-
50
- export interface ListOptions {
51
- transferId: string;
52
- namespace?: string;
53
- containerType?: string;
54
- cursor?: string;
55
- }
56
-
57
- export interface Result {
58
- key: string;
59
- value: object;
60
- }
61
-
62
- export interface ListResults {
63
- results: Result[];
64
- nextCursor?: string;
65
- }
66
-
67
- export interface QueryBuilder {
68
- cursor(cursor: string): QueryBuilder;
69
- getMany(): Promise<ListResults>;
70
- getOne(): Promise<Result | undefined>;
71
- }
@@ -1,111 +0,0 @@
1
- import fetch, { Response } from 'node-fetch';
2
-
3
- import {
4
- AppDataListResponse,
5
- AppDataPayloadResponse,
6
- MappingResponse,
7
- MigrationAdapter,
8
- Progress,
9
- ListOptions,
10
- ListResults,
11
- Result,
12
- PaginationContainerResponse,
13
- PaginationMappingResponse
14
- } from './migration-adaptor';
15
-
16
- import { getResponseBody, invokeGETApi, invokePOSTApi } from './utils';
17
-
18
- export class Migration implements MigrationAdapter {
19
- private readonly basePath = '/app/migration/forge/v1';
20
-
21
- sendProgress = async (transferId: string, progress: Progress): Promise<void> => {
22
- const result = await invokePOSTApi(`${this.basePath}/progress/${transferId}`, progress);
23
- return getResponseBody(result);
24
- };
25
-
26
- getMappingById = async (transferId: string, namespace: string, keys: Array<string>): Promise<MappingResponse> => {
27
- const result = await invokePOSTApi(`${this.basePath}/mapping/${transferId}/find?namespace=${namespace}`, keys);
28
- return getResponseBody(result);
29
- };
30
-
31
- getAppDataList = async (transferId: string): Promise<AppDataListResponse> => {
32
- const result = await invokeGETApi(`${this.basePath}/data/${transferId}/all`);
33
- return getResponseBody(result);
34
- };
35
-
36
- getAppDataPayload = async (s3Key: string): Promise<Response> => {
37
- const result = await invokeGETApi(`${this.basePath}/data/${s3Key}`);
38
- const responseBody: AppDataPayloadResponse = await getResponseBody(result);
39
- return fetch(responseBody.url);
40
- };
41
-
42
- updateFeedback = async (transferId: string, feedback: object): Promise<void> => {
43
- const result = await invokePOSTApi(`${this.basePath}/feedback/${transferId}`, feedback);
44
- return getResponseBody(result);
45
- };
46
-
47
- getMappings = async (
48
- transferId: string,
49
- namespace?: string,
50
- lastEntity?: string,
51
- pageSize?: number
52
- ): Promise<ListResults> => {
53
- let queryParams = `namespace=${namespace}`;
54
- if (pageSize != undefined) {
55
- queryParams = queryParams + `&pageSize=${pageSize}`;
56
- }
57
- if (lastEntity != undefined) {
58
- queryParams = queryParams + `&lastEntity=${lastEntity}`;
59
- }
60
-
61
- const result = await invokeGETApi(`${this.basePath}/mapping/${transferId}/page?${queryParams}`);
62
- const mappingResponse: PaginationMappingResponse = await getResponseBody(result);
63
-
64
- let results: Result[] = [];
65
- if (mappingResponse.items != null) {
66
- results = Object.entries(mappingResponse.items).map((item) => {
67
- return { key: item[0], value: item[1] as object };
68
- });
69
- }
70
-
71
- return {
72
- results: results,
73
- nextCursor: mappingResponse.meta.lastEntity != null ? mappingResponse.meta.lastEntity : undefined
74
- };
75
- };
76
-
77
- getContainers = async (
78
- transferId: string,
79
- containerType?: string,
80
- lastEntity?: string,
81
- pageSize?: number
82
- ): Promise<ListResults> => {
83
- let queryParams = `containerType=${containerType}`;
84
- if (pageSize != undefined) {
85
- queryParams = queryParams + `&pageSize=${pageSize}`;
86
- }
87
- if (lastEntity != undefined) {
88
- queryParams = queryParams + `&lastEntity=${lastEntity}`;
89
- }
90
-
91
- const result = await invokeGETApi(`${this.basePath}/container/${transferId}/page?${queryParams}`);
92
- const containerResponse: PaginationContainerResponse = await getResponseBody(result);
93
- let results: Result[] = [];
94
- if (containerResponse.containers != null) {
95
- results = Object.entries(containerResponse.containers).map((item) => {
96
- return { key: item[0], value: item[1] };
97
- });
98
- }
99
-
100
- return {
101
- results: results,
102
- nextCursor: containerResponse.meta.lastEntity != null ? containerResponse.meta.lastEntity : undefined
103
- };
104
- };
105
-
106
- list = async (options: ListOptions, pageSize?: number): Promise<ListResults> => {
107
- if (options.namespace != undefined)
108
- return this.getMappings(options.transferId, options.namespace, options.cursor, pageSize);
109
- else return this.getContainers(options.transferId, options.containerType, options.cursor, pageSize);
110
- };
111
- }
@@ -1,24 +0,0 @@
1
- import { QueryBuilder, Result, ListOptions, ListResults } from './migration-adaptor';
2
- import { Migration } from './migration';
3
-
4
- export class DefaultQueryBuilder implements QueryBuilder {
5
- constructor(private migration: Pick<Migration, 'list'>, private queryOptions: ListOptions) {}
6
-
7
- cursor(cursor: string): QueryBuilder {
8
- return new DefaultQueryBuilder(this.migration, {
9
- ...this.queryOptions,
10
- cursor
11
- });
12
- }
13
-
14
- async getOne(): Promise<Result | undefined> {
15
- const listResults = await this.migration.list(this.queryOptions, 1);
16
- if (listResults.results && listResults.results.length > 0) {
17
- return listResults.results[0];
18
- }
19
- }
20
-
21
- async getMany(): Promise<ListResults> {
22
- return this.migration.list(this.queryOptions);
23
- }
24
- }