@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @forge/migrations
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cf5eb2a: Added .npmignore file to forge-migrations package
8
+ - Updated dependencies [b3ee297]
9
+ - @forge/api@2.7.0
10
+
11
+ ## 0.1.1-next.1
12
+
13
+ ### Patch Changes
14
+
15
+ - cf5eb2af: Added .npmignore file to forge-migrations package
16
+
17
+ ## 0.1.1-next.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [b3ee2973]
22
+ - @forge/api@2.7.0-next.0
23
+
3
24
  ## 0.1.0
4
25
 
5
26
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/migrations",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "App migration methods for Forge app",
5
5
  "main": "out/index.js",
6
6
  "scripts": {
@@ -16,6 +16,6 @@
16
16
  "node-fetch": "2.6.1"
17
17
  },
18
18
  "dependencies": {
19
- "@forge/api": "^2.6.1"
19
+ "@forge/api": "^2.7.0"
20
20
  }
21
21
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=errors.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../src/__test__/errors.test.ts"],"names":[],"mappings":""}
@@ -1,16 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=migration.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration.test.d.ts","sourceRoot":"","sources":["../../src/__test__/migration.test.ts"],"names":[],"mappings":""}
@@ -1,221 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=query-api.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-api.test.d.ts","sourceRoot":"","sources":["../../src/__test__/query-api.test.ts"],"names":[],"mappings":""}
@@ -1,144 +0,0 @@
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
- });
@@ -1,15 +0,0 @@
1
- import { APIError } from '../migration/errors';
2
-
3
- describe('APIError', () => {
4
- describe('forStatus', () => {
5
- it.each([
6
- [400, 'Bad request'],
7
- [401, 'Unauthorized'],
8
- [403, 'Forbidden'],
9
- [404, 'Not Found'],
10
- [500, 'Internal server error']
11
- ] as const)('should contain the correct error message for a code of %s', (status, message) => {
12
- expect(APIError.forStatus(status, message).message).toEqual(message);
13
- });
14
- });
15
- });