@forge/teamwork-graph 1.2.0-next.3-experimental-42e3178 → 1.2.0-next.4

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const api_1 = require("@forge/api");
4
4
  const graph_1 = require("../graph");
5
+ const validators_1 = require("../utils/validators");
5
6
  jest.mock('@forge/api');
6
7
  describe('TeamWorkGraphClient - setEntities', () => {
7
8
  let graphClient;
@@ -16,7 +17,7 @@ describe('TeamWorkGraphClient - setEntities', () => {
16
17
  const req = { entities: [] };
17
18
  await expect(graphClient.setEntities(req)).rejects.toThrow('entities array cannot be empty');
18
19
  });
19
- it('throws if more than 100 entities', async () => {
20
+ it(`throws if more than ${validators_1.MAX_BULK_ENTITIES} entities`, async () => {
20
21
  const documentEntity = {
21
22
  schemaVersion: '1.0',
22
23
  id: 'my-document',
@@ -48,9 +49,9 @@ describe('TeamWorkGraphClient - setEntities', () => {
48
49
  }
49
50
  };
50
51
  const req = {
51
- entities: Array(101).fill(documentEntity)
52
+ entities: Array(validators_1.MAX_BULK_ENTITIES + 1).fill(documentEntity)
52
53
  };
53
- await expect(graphClient.setEntities(req)).rejects.toThrow('Bulk ingestion supports maximum 100 entities');
54
+ await expect(graphClient.setEntities(req)).rejects.toThrow(`Bulk ingestion supports maximum ${validators_1.MAX_BULK_ENTITIES} entities`);
54
55
  });
55
56
  it('posts to /api/v1/entities/bulk and returns response', async () => {
56
57
  const documentEntity = {
@@ -314,11 +315,11 @@ describe('TeamWorkGraphClient - deleteEntitiesByExternalId', () => {
314
315
  })).rejects.toThrow('externalIds array cannot be empty');
315
316
  });
316
317
  it('should throw error when externalIds array exceeds limit', async () => {
317
- const manyExternalIds = Array(101).fill('pipelines/123/builds/456');
318
+ const manyExternalIds = Array(validators_1.MAX_BULK_ENTITIES_DELETE + 1).fill('pipelines/123/builds/456');
318
319
  await expect(graphClient.deleteEntitiesByExternalId({
319
320
  entityType: 'atlassian:document',
320
321
  externalIds: manyExternalIds
321
- })).rejects.toThrow('Bulk entity deletion supports maximum 100 entities');
322
+ })).rejects.toThrow(`Bulk entity deletion supports maximum ${validators_1.MAX_BULK_ENTITIES_DELETE} entities`);
322
323
  });
323
324
  it('should throw error when externalIds is not an array', async () => {
324
325
  await expect(graphClient.deleteEntitiesByExternalId({
@@ -6,22 +6,13 @@ jest.mock('@forge/api', () => ({
6
6
  __fetchProduct: jest.fn(),
7
7
  fetch: jest.fn()
8
8
  }));
9
- describe('Teamwork Graph Client Extended Features', () => {
9
+ describe('TeamWorkGraphClient - Extended Features', () => {
10
10
  let graphClient;
11
- let mockContext;
12
11
  beforeEach(() => {
13
12
  graphClient = new graph_1.TeamWorkGraphClient();
14
- mockContext = {
15
- ingestionContext: { id: 'test' },
16
- installContext: 'test-installation',
17
- principal: { accountId: 'test' },
18
- license: { isActive: true }
19
- };
20
- jest.spyOn(graphClient, 'saveToStage').mockImplementation(() => Promise.resolve());
21
- jest.spyOn(graphClient, 'validateData').mockImplementation(() => Promise.resolve());
22
13
  jest.clearAllMocks();
23
14
  });
24
- describe('fetchExternalData', () => {
15
+ describe('fetchData', () => {
25
16
  it('should successfully fetch and process external data', async () => {
26
17
  const mockData = { items: [{ id: 1, name: 'Task 1' }] };
27
18
  const mockResponse = {
@@ -30,33 +21,44 @@ describe('Teamwork Graph Client Extended Features', () => {
30
21
  json: jest.fn().mockResolvedValue(mockData)
31
22
  };
32
23
  api_1.fetch.mockResolvedValue(mockResponse);
33
- const requestConfig = {
34
- url: 'https://api.gitbook.com/api/tasks',
35
- method: 'GET',
36
- headers: { Authorization: 'Bearer token' }
24
+ const request = {
25
+ requestConfig: {
26
+ url: 'https://api.gitbook.com/api/tasks',
27
+ method: 'GET',
28
+ headers: { Authorization: 'Bearer token' }
29
+ },
30
+ onResult: jest.fn()
37
31
  };
38
- const onResult = jest.fn();
39
- const result = await graphClient.fetchData(mockContext, requestConfig, onResult);
32
+ const result = await graphClient.fetchData(request);
40
33
  expect(api_1.fetch).toHaveBeenCalledWith('https://api.gitbook.com/api/tasks', {
41
34
  method: 'GET',
42
35
  headers: { Authorization: 'Bearer token' }
43
36
  });
44
- expect(onResult).toHaveBeenCalledWith(mockData);
45
- expect(result).toEqual(mockData);
37
+ expect(request.onResult).toHaveBeenCalledWith(mockData);
38
+ expect(result).toEqual({
39
+ success: true,
40
+ data: mockData
41
+ });
46
42
  });
47
- it('should throw error when fetch fails', async () => {
43
+ it('should return error response when fetch fails', async () => {
48
44
  const mockResponse = {
49
45
  ok: false,
50
46
  status: 401
51
47
  };
52
48
  api_1.fetch.mockResolvedValue(mockResponse);
53
- const requestConfig = {
54
- url: 'https://api.gitbook.com/api/tasks',
55
- method: 'GET'
49
+ const request = {
50
+ requestConfig: {
51
+ url: 'https://api.gitbook.com/api/tasks',
52
+ method: 'GET'
53
+ },
54
+ onResult: jest.fn()
56
55
  };
57
- const onResult = jest.fn();
58
- await expect(graphClient.fetchData(mockContext, requestConfig, onResult)).rejects.toThrow(`Remote call failed with status: ${mockResponse.status}`);
59
- expect(onResult).not.toHaveBeenCalled();
56
+ const result = await graphClient.fetchData(request);
57
+ expect(result).toEqual({
58
+ success: false,
59
+ error: 'Remote call failed with status: 401'
60
+ });
61
+ expect(request.onResult).not.toHaveBeenCalled();
60
62
  });
61
63
  });
62
64
  describe('transformData', () => {
@@ -69,10 +71,32 @@ describe('Teamwork Graph Client Extended Features', () => {
69
71
  type: 'task'
70
72
  }))
71
73
  }));
72
- const result = await graphClient.transformData(mockContext, inputData, transformMethod);
74
+ const request = {
75
+ data: inputData,
76
+ transformMethod
77
+ };
78
+ const result = await graphClient.transformData(request);
73
79
  expect(transformMethod).toHaveBeenCalledWith(inputData);
74
80
  expect(result).toEqual({
75
- entities: [{ id: 'task-1', name: 'Task 1', type: 'task' }]
81
+ success: true,
82
+ transformedData: {
83
+ entities: [{ id: 'task-1', name: 'Task 1', type: 'task' }]
84
+ }
85
+ });
86
+ });
87
+ it('should return error response when transform method throws', async () => {
88
+ const inputData = { items: [{ id: 1, name: 'Task 1' }] };
89
+ const transformMethod = jest.fn().mockImplementation(() => {
90
+ throw new Error('Transform failed');
91
+ });
92
+ const request = {
93
+ data: inputData,
94
+ transformMethod
95
+ };
96
+ const result = await graphClient.transformData(request);
97
+ expect(result).toEqual({
98
+ success: false,
99
+ error: 'Transform failed'
76
100
  });
77
101
  });
78
102
  });
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const api_1 = require("@forge/api");
4
4
  const graph_1 = require("../graph");
5
+ const validators_1 = require("../utils/validators");
5
6
  jest.mock('@forge/api');
6
7
  describe('TeamWorkGraphClient - Group Operations', () => {
7
8
  let graphClient;
@@ -87,10 +88,10 @@ describe('TeamWorkGraphClient - Group Operations', () => {
87
88
  })).rejects.toThrow('groups array cannot be empty');
88
89
  });
89
90
  it('should throw error when groups array exceeds limit', async () => {
90
- const manyGroups = Array(101).fill(groupPayload);
91
+ const manyGroups = Array(validators_1.MAX_BULK_GROUPS + 1).fill(groupPayload);
91
92
  await expect(graphClient.setGroups({
92
93
  groups: manyGroups
93
- })).rejects.toThrow('Bulk group ingestion supports maximum 100 groups');
94
+ })).rejects.toThrow(`Bulk group ingestion supports maximum ${validators_1.MAX_BULK_GROUPS} groups`);
94
95
  });
95
96
  it('should throw error when groups is not an array', async () => {
96
97
  await expect(graphClient.setGroups({
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const api_1 = require("@forge/api");
4
4
  const graph_1 = require("../graph");
5
+ const validators_1 = require("../utils/validators");
5
6
  jest.mock('@forge/api');
6
7
  describe('TeamWorkGraphClient - User Operations', () => {
7
8
  let graphClient;
@@ -66,10 +67,10 @@ describe('TeamWorkGraphClient - User Operations', () => {
66
67
  })).rejects.toThrow('users array cannot be empty');
67
68
  });
68
69
  it('should throw error when users array exceeds limit', async () => {
69
- const manyUsers = Array(101).fill(userPayload);
70
+ const manyUsers = Array(validators_1.MAX_BULK_USERS + 1).fill(userPayload);
70
71
  await expect(graphClient.setUsers({
71
72
  users: manyUsers
72
- })).rejects.toThrow('Bulk user ingestion supports maximum 100 users');
73
+ })).rejects.toThrow(`Bulk user ingestion supports maximum ${validators_1.MAX_BULK_USERS} users`);
73
74
  });
74
75
  });
75
76
  describe('deleteUsersByExternalId', () => {
@@ -256,10 +257,10 @@ describe('TeamWorkGraphClient - User Operations', () => {
256
257
  })).rejects.toThrow('directMappings array cannot be empty');
257
258
  });
258
259
  it('should throw error when directMappings array exceeds limit', async () => {
259
- const manyMappings = Array(101).fill(mappingWithAccountId);
260
+ const manyMappings = Array(validators_1.MAX_USER_MAPPINGS + 1).fill(mappingWithAccountId);
260
261
  await expect(graphClient.mapUsers({
261
262
  directMappings: manyMappings
262
- })).rejects.toThrow('Bulk user mapping supports maximum 100 mappings');
263
+ })).rejects.toThrow(`Bulk user mapping supports maximum ${validators_1.MAX_USER_MAPPINGS} mappings`);
263
264
  });
264
265
  it('should throw error when directMappings is not an array', async () => {
265
266
  await expect(graphClient.mapUsers({
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validators.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.test.d.ts","sourceRoot":"","sources":["../../src/__test__/validators.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const validators_1 = require("../utils/validators");
4
+ describe('TeamWorkGraphClient - Validators', () => {
5
+ describe('validateArray', () => {
6
+ it('should pass for valid array', () => {
7
+ expect(() => (0, validators_1.validateArray)([1, 2, 3], 'test')).not.toThrow();
8
+ });
9
+ it('should throw for non-array', () => {
10
+ expect(() => (0, validators_1.validateArray)('not an array', 'test')).toThrow('test must be an array');
11
+ });
12
+ it('should throw for empty array', () => {
13
+ expect(() => (0, validators_1.validateArray)([], 'test')).toThrow('test array cannot be empty');
14
+ });
15
+ it('should throw for null', () => {
16
+ expect(() => (0, validators_1.validateArray)(null, 'test')).toThrow('test must be an array');
17
+ });
18
+ it('should throw for undefined', () => {
19
+ expect(() => (0, validators_1.validateArray)(undefined, 'test')).toThrow('test must be an array');
20
+ });
21
+ });
22
+ describe('validateArrayMaxLength', () => {
23
+ it('should pass for array within limit', () => {
24
+ expect(() => (0, validators_1.validateArrayMaxLength)([1, 2], 'test', 5)).not.toThrow();
25
+ });
26
+ it('should pass for array at limit', () => {
27
+ expect(() => (0, validators_1.validateArrayMaxLength)([1, 2, 3], 'test', 3)).not.toThrow();
28
+ });
29
+ it('should throw for array exceeding limit', () => {
30
+ expect(() => (0, validators_1.validateArrayMaxLength)([1, 2, 3, 4], 'test', 3)).toThrow('test supports maximum 3 items. Received 4');
31
+ });
32
+ });
33
+ describe('validateRequiredString', () => {
34
+ it('should pass for valid string', () => {
35
+ expect(() => (0, validators_1.validateRequiredString)('valid string', 'test')).not.toThrow();
36
+ });
37
+ it('should throw for empty string', () => {
38
+ expect(() => (0, validators_1.validateRequiredString)('', 'test')).toThrow('test is required');
39
+ });
40
+ it('should throw for whitespace string', () => {
41
+ expect(() => (0, validators_1.validateRequiredString)(' ', 'test')).toThrow('test is required');
42
+ });
43
+ it('should throw for null', () => {
44
+ expect(() => (0, validators_1.validateRequiredString)(null, 'test')).toThrow('test is required');
45
+ });
46
+ it('should throw for undefined', () => {
47
+ expect(() => (0, validators_1.validateRequiredString)(undefined, 'test')).toThrow('test is required');
48
+ });
49
+ });
50
+ describe('validateObject', () => {
51
+ it('should pass for valid object', () => {
52
+ expect(() => (0, validators_1.validateObject)({ key: 'value' }, 'test')).not.toThrow();
53
+ });
54
+ it('should throw for null', () => {
55
+ expect(() => (0, validators_1.validateObject)(null, 'test')).toThrow('test must be an object');
56
+ });
57
+ it('should throw for undefined', () => {
58
+ expect(() => (0, validators_1.validateObject)(undefined, 'test')).toThrow('test must be an object');
59
+ });
60
+ it('should throw for non-object', () => {
61
+ expect(() => (0, validators_1.validateObject)('not an object', 'test')).toThrow('test must be an object');
62
+ });
63
+ it('should throw for empty object', () => {
64
+ expect(() => (0, validators_1.validateObject)({}, 'test')).toThrow('test object cannot be empty');
65
+ });
66
+ });
67
+ describe('validateSetEntitiesRequest', () => {
68
+ it('should pass for valid entities array', () => {
69
+ const entities = Array(validators_1.MAX_BULK_ENTITIES).fill({ id: 'test' });
70
+ expect(() => (0, validators_1.validateSetEntitiesRequest)(entities)).not.toThrow();
71
+ });
72
+ it('should throw for non-array', () => {
73
+ expect(() => (0, validators_1.validateSetEntitiesRequest)('not array')).toThrow('entities must be an array');
74
+ });
75
+ it('should throw for empty array', () => {
76
+ expect(() => (0, validators_1.validateSetEntitiesRequest)([])).toThrow('entities array cannot be empty');
77
+ });
78
+ it('should throw for array exceeding limit', () => {
79
+ const entities = Array(validators_1.MAX_BULK_ENTITIES + 1).fill({ id: 'test' });
80
+ expect(() => (0, validators_1.validateSetEntitiesRequest)(entities)).toThrow(`Bulk ingestion supports maximum ${validators_1.MAX_BULK_ENTITIES} entities. Received ${validators_1.MAX_BULK_ENTITIES + 1}`);
81
+ });
82
+ });
83
+ describe('validateSetUsersRequest', () => {
84
+ it('should pass for valid users array', () => {
85
+ const users = Array(validators_1.MAX_BULK_USERS).fill({ id: 'test' });
86
+ expect(() => (0, validators_1.validateSetUsersRequest)(users)).not.toThrow();
87
+ });
88
+ it('should throw for non-array', () => {
89
+ expect(() => (0, validators_1.validateSetUsersRequest)('not array')).toThrow('users must be an array');
90
+ });
91
+ it('should throw for empty array', () => {
92
+ expect(() => (0, validators_1.validateSetUsersRequest)([])).toThrow('users array cannot be empty');
93
+ });
94
+ it('should throw for array exceeding limit', () => {
95
+ const users = Array(validators_1.MAX_BULK_USERS + 1).fill({ id: 'test' });
96
+ expect(() => (0, validators_1.validateSetUsersRequest)(users)).toThrow(`Bulk user ingestion supports maximum ${validators_1.MAX_BULK_USERS} users. Received ${validators_1.MAX_BULK_USERS + 1}`);
97
+ });
98
+ });
99
+ describe('validateSetGroupsRequest', () => {
100
+ it('should pass for valid groups array', () => {
101
+ const groups = Array(validators_1.MAX_BULK_GROUPS).fill({ id: 'test' });
102
+ expect(() => (0, validators_1.validateSetGroupsRequest)(groups)).not.toThrow();
103
+ });
104
+ it('should throw for non-array', () => {
105
+ expect(() => (0, validators_1.validateSetGroupsRequest)('not array')).toThrow('groups must be an array');
106
+ });
107
+ it('should throw for empty array', () => {
108
+ expect(() => (0, validators_1.validateSetGroupsRequest)([])).toThrow('groups array cannot be empty');
109
+ });
110
+ it('should throw for array exceeding limit', () => {
111
+ const groups = Array(validators_1.MAX_BULK_GROUPS + 1).fill({ id: 'test' });
112
+ expect(() => (0, validators_1.validateSetGroupsRequest)(groups)).toThrow(`Bulk group ingestion supports maximum ${validators_1.MAX_BULK_GROUPS} groups. Received ${validators_1.MAX_BULK_GROUPS + 1}`);
113
+ });
114
+ });
115
+ describe('validateDeleteEntitiesByExternalIdRequest', () => {
116
+ it('should pass for valid request', () => {
117
+ const entityType = 'test-type';
118
+ const externalIds = Array(validators_1.MAX_BULK_ENTITIES_DELETE).fill('test-id');
119
+ expect(() => (0, validators_1.validateDeleteEntitiesByExternalIdRequest)(entityType, externalIds)).not.toThrow();
120
+ });
121
+ it('should throw for empty entityType', () => {
122
+ expect(() => (0, validators_1.validateDeleteEntitiesByExternalIdRequest)('', ['test'])).toThrow('entityType is required');
123
+ });
124
+ it('should throw for whitespace entityType', () => {
125
+ expect(() => (0, validators_1.validateDeleteEntitiesByExternalIdRequest)(' ', ['test'])).toThrow('entityType is required');
126
+ });
127
+ it('should throw for non-array externalIds', () => {
128
+ expect(() => (0, validators_1.validateDeleteEntitiesByExternalIdRequest)('type', 'not array')).toThrow('externalIds must be an array');
129
+ });
130
+ it('should throw for empty externalIds array', () => {
131
+ expect(() => (0, validators_1.validateDeleteEntitiesByExternalIdRequest)('type', [])).toThrow('externalIds array cannot be empty');
132
+ });
133
+ it('should throw for externalIds exceeding limit', () => {
134
+ const externalIds = Array(validators_1.MAX_BULK_ENTITIES_DELETE + 1).fill('test-id');
135
+ expect(() => (0, validators_1.validateDeleteEntitiesByExternalIdRequest)('type', externalIds)).toThrow(`Bulk entity deletion supports maximum ${validators_1.MAX_BULK_ENTITIES_DELETE} entities. Received ${validators_1.MAX_BULK_ENTITIES_DELETE + 1}`);
136
+ });
137
+ });
138
+ describe('validateDeleteUsersByExternalIdRequest', () => {
139
+ it('should pass for valid externalIds array', () => {
140
+ const externalIds = ['id1', 'id2'];
141
+ expect(() => (0, validators_1.validateDeleteUsersByExternalIdRequest)(externalIds)).not.toThrow();
142
+ });
143
+ it('should throw for non-array', () => {
144
+ expect(() => (0, validators_1.validateDeleteUsersByExternalIdRequest)('not array')).toThrow('externalIds must be an array');
145
+ });
146
+ it('should throw for empty array', () => {
147
+ expect(() => (0, validators_1.validateDeleteUsersByExternalIdRequest)([])).toThrow('externalIds array cannot be empty');
148
+ });
149
+ });
150
+ describe('validateDeleteGroupsByExternalIdRequest', () => {
151
+ it('should pass for valid externalIds array', () => {
152
+ const externalIds = ['id1', 'id2'];
153
+ expect(() => (0, validators_1.validateDeleteGroupsByExternalIdRequest)(externalIds)).not.toThrow();
154
+ });
155
+ it('should throw for non-array', () => {
156
+ expect(() => (0, validators_1.validateDeleteGroupsByExternalIdRequest)('not array')).toThrow('externalIds must be an array');
157
+ });
158
+ it('should throw for empty array', () => {
159
+ expect(() => (0, validators_1.validateDeleteGroupsByExternalIdRequest)([])).toThrow('externalIds array cannot be empty');
160
+ });
161
+ });
162
+ describe('validateGetEntityByExternalIdRequest', () => {
163
+ it('should pass for valid request', () => {
164
+ expect(() => (0, validators_1.validateGetEntityByExternalIdRequest)('type', 'id')).not.toThrow();
165
+ });
166
+ it('should throw for empty entityType', () => {
167
+ expect(() => (0, validators_1.validateGetEntityByExternalIdRequest)('', 'id')).toThrow('entityType is required');
168
+ });
169
+ it('should throw for empty externalId', () => {
170
+ expect(() => (0, validators_1.validateGetEntityByExternalIdRequest)('type', '')).toThrow('externalId is required');
171
+ });
172
+ });
173
+ describe('validateGetUserByExternalIdRequest', () => {
174
+ it('should pass for valid externalId', () => {
175
+ expect(() => (0, validators_1.validateGetUserByExternalIdRequest)('valid-id')).not.toThrow();
176
+ });
177
+ it('should throw for empty externalId', () => {
178
+ expect(() => (0, validators_1.validateGetUserByExternalIdRequest)('')).toThrow('externalId is required');
179
+ });
180
+ });
181
+ describe('validateGetGroupByExternalIdRequest', () => {
182
+ it('should pass for valid externalId', () => {
183
+ expect(() => (0, validators_1.validateGetGroupByExternalIdRequest)('valid-id')).not.toThrow();
184
+ });
185
+ it('should throw for empty externalId', () => {
186
+ expect(() => (0, validators_1.validateGetGroupByExternalIdRequest)('')).toThrow('externalId is required');
187
+ });
188
+ });
189
+ describe('validateMapUsersRequest', () => {
190
+ it('should pass for valid mappings', () => {
191
+ const directMappings = [
192
+ { externalId: 'id1', accountId: 'acc1' },
193
+ { externalId: 'id2', externalEmailAddress: 'email@test.com' }
194
+ ];
195
+ expect(() => (0, validators_1.validateMapUsersRequest)(directMappings)).not.toThrow();
196
+ });
197
+ it('should throw for non-array', () => {
198
+ expect(() => (0, validators_1.validateMapUsersRequest)('not array')).toThrow('directMappings must be an array');
199
+ });
200
+ it('should throw for empty array', () => {
201
+ expect(() => (0, validators_1.validateMapUsersRequest)([])).toThrow('directMappings array cannot be empty');
202
+ });
203
+ it('should throw for array exceeding limit', () => {
204
+ const directMappings = Array(validators_1.MAX_USER_MAPPINGS + 1).fill({ externalId: 'id', accountId: 'acc' });
205
+ expect(() => (0, validators_1.validateMapUsersRequest)(directMappings)).toThrow(`Bulk user mapping supports maximum ${validators_1.MAX_USER_MAPPINGS} mappings. Received ${validators_1.MAX_USER_MAPPINGS + 1}`);
206
+ });
207
+ it('should throw for mapping without accountId or externalEmailAddress', () => {
208
+ const directMappings = [{ externalId: 'id' }];
209
+ expect(() => (0, validators_1.validateMapUsersRequest)(directMappings)).toThrow('Each mapping must have either accountId or externalEmailAddress');
210
+ });
211
+ it('should throw for mapping without externalId', () => {
212
+ const directMappings = [{ accountId: 'acc' }];
213
+ expect(() => (0, validators_1.validateMapUsersRequest)(directMappings)).toThrow('Each mapping must have an externalId');
214
+ });
215
+ });
216
+ describe('validateDeleteEntitiesByPropertiesRequest', () => {
217
+ it('should pass for valid properties object', () => {
218
+ expect(() => (0, validators_1.validateDeleteEntitiesByPropertiesRequest)({ key: 'value' })).not.toThrow();
219
+ });
220
+ it('should throw for null', () => {
221
+ expect(() => (0, validators_1.validateDeleteEntitiesByPropertiesRequest)(null)).toThrow('properties must be an object');
222
+ });
223
+ it('should throw for non-object', () => {
224
+ expect(() => (0, validators_1.validateDeleteEntitiesByPropertiesRequest)('not object')).toThrow('properties must be an object');
225
+ });
226
+ it('should throw for empty object', () => {
227
+ expect(() => (0, validators_1.validateDeleteEntitiesByPropertiesRequest)({})).toThrow('properties object cannot be empty');
228
+ });
229
+ });
230
+ describe('validateFetchDataRequest', () => {
231
+ it('should pass for valid request', () => {
232
+ const request = {
233
+ requestConfig: {
234
+ url: 'https://test.com',
235
+ method: 'GET',
236
+ headers: { 'Content-Type': 'application/json' }
237
+ },
238
+ onResult: () => {
239
+ }
240
+ };
241
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).not.toThrow();
242
+ });
243
+ it('should throw for null request', () => {
244
+ expect(() => (0, validators_1.validateFetchDataRequest)(null)).toThrow('request must be an object');
245
+ });
246
+ it('should throw for non-object request', () => {
247
+ expect(() => (0, validators_1.validateFetchDataRequest)('not object')).toThrow('request must be an object');
248
+ });
249
+ it('should throw for missing requestConfig', () => {
250
+ const request = {
251
+ onResult: () => {
252
+ }
253
+ };
254
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('requestConfig is required and must be an object');
255
+ });
256
+ it('should throw for non-object requestConfig', () => {
257
+ const request = {
258
+ requestConfig: 'not object',
259
+ onResult: () => {
260
+ }
261
+ };
262
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('requestConfig is required and must be an object');
263
+ });
264
+ it('should throw for missing url', () => {
265
+ const request = {
266
+ requestConfig: { method: 'GET' },
267
+ onResult: () => {
268
+ }
269
+ };
270
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('requestConfig.url is required and must be a string');
271
+ });
272
+ it('should throw for non-string url', () => {
273
+ const request = {
274
+ requestConfig: { url: 123, method: 'GET' },
275
+ onResult: () => {
276
+ }
277
+ };
278
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('requestConfig.url is required and must be a string');
279
+ });
280
+ it('should throw for missing method', () => {
281
+ const request = {
282
+ requestConfig: { url: 'https://test.com' },
283
+ onResult: () => {
284
+ }
285
+ };
286
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('requestConfig.method is required and must be a string');
287
+ });
288
+ it('should throw for non-string method', () => {
289
+ const request = {
290
+ requestConfig: { url: 'https://test.com', method: 123 },
291
+ onResult: () => {
292
+ }
293
+ };
294
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('requestConfig.method is required and must be a string');
295
+ });
296
+ it('should throw for missing onResult', () => {
297
+ const request = { requestConfig: { url: 'https://test.com', method: 'GET' } };
298
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('onResult is required and must be a function');
299
+ });
300
+ it('should throw for non-function onResult', () => {
301
+ const request = { requestConfig: { url: 'https://test.com', method: 'GET' }, onResult: 'not function' };
302
+ expect(() => (0, validators_1.validateFetchDataRequest)(request)).toThrow('onResult is required and must be a function');
303
+ });
304
+ });
305
+ describe('validateTransformDataRequest', () => {
306
+ it('should pass for valid request', () => {
307
+ const request = {
308
+ data: { test: 'data' },
309
+ transformMethod: () => {
310
+ }
311
+ };
312
+ expect(() => (0, validators_1.validateTransformDataRequest)(request)).not.toThrow();
313
+ });
314
+ it('should throw for null request', () => {
315
+ expect(() => (0, validators_1.validateTransformDataRequest)(null)).toThrow('request must be an object');
316
+ });
317
+ it('should throw for non-object request', () => {
318
+ expect(() => (0, validators_1.validateTransformDataRequest)('not object')).toThrow('request must be an object');
319
+ });
320
+ it('should throw for missing transformMethod', () => {
321
+ const request = { data: { test: 'data' } };
322
+ expect(() => (0, validators_1.validateTransformDataRequest)(request)).toThrow('transformMethod is required and must be a function');
323
+ });
324
+ it('should throw for non-function transformMethod', () => {
325
+ const request = { data: { test: 'data' }, transformMethod: 'not function' };
326
+ expect(() => (0, validators_1.validateTransformDataRequest)(request)).toThrow('transformMethod is required and must be a function');
327
+ });
328
+ });
329
+ });
package/out/graph.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TeamWorkGraph, ForgeExtendedContext, RequestConfig, BulkEntityRequest, BulkEntityResponse, BulkUsersRequest, BulkUsersResponse, DeleteUsersByExternalIdRequest, DeleteUsersByExternalIdResponse, GetUserByExternalIdRequest, GetUserByExternalIdResponse, MapUsersRequest, MapUsersResponse, BulkGroupsRequest, BulkGroupsResponse, DeleteGroupsByExternalIdRequest, DeleteGroupsByExternalIdResponse, GetGroupByExternalIdRequest, GetGroupByExternalIdResponse, GetEntityByExternalIdRequest, GetEntityByExternalIdResponse, DeleteEntitiesByExternalIdRequest, DeleteEntitiesByExternalIdResponse, DeleteEntitiesByPropertiesRequest, DeleteEntitiesByPropertiesResponse } from './types';
1
+ import { TeamWorkGraph, BulkEntityRequest, BulkEntityResponse, BulkUsersRequest, BulkUsersResponse, DeleteUsersByExternalIdRequest, DeleteUsersByExternalIdResponse, GetUserByExternalIdRequest, GetUserByExternalIdResponse, MapUsersRequest, MapUsersResponse, BulkGroupsRequest, BulkGroupsResponse, DeleteGroupsByExternalIdRequest, DeleteGroupsByExternalIdResponse, GetGroupByExternalIdRequest, GetGroupByExternalIdResponse, GetEntityByExternalIdRequest, GetEntityByExternalIdResponse, DeleteEntitiesByExternalIdRequest, DeleteEntitiesByExternalIdResponse, DeleteEntitiesByPropertiesRequest, DeleteEntitiesByPropertiesResponse, FetchDataRequest, FetchDataResponse, TransformDataRequest, TransformDataResponse } from './types';
2
2
  export declare class TeamWorkGraphClient implements TeamWorkGraph {
3
3
  setEntities: (request: BulkEntityRequest) => Promise<BulkEntityResponse>;
4
4
  getEntityByExternalId: (request: GetEntityByExternalIdRequest) => Promise<GetEntityByExternalIdResponse>;
@@ -11,11 +11,8 @@ export declare class TeamWorkGraphClient implements TeamWorkGraph {
11
11
  deleteUsersByExternalId: (request: DeleteUsersByExternalIdRequest) => Promise<DeleteUsersByExternalIdResponse>;
12
12
  getUserByExternalId: (request: GetUserByExternalIdRequest) => Promise<GetUserByExternalIdResponse>;
13
13
  mapUsers: (request: MapUsersRequest) => Promise<MapUsersResponse>;
14
- fetchData: (context: ForgeExtendedContext, requestConfig: RequestConfig, onResult: (data: any) => any) => Promise<any>;
15
- transformData: (context: ForgeExtendedContext, data: any, transformMethod: (data: any) => any) => Promise<any>;
16
- private saveToStage;
17
- private validateData;
18
- private validateContext;
14
+ fetchData: (request: FetchDataRequest) => Promise<FetchDataResponse>;
15
+ transformData: (request: TransformDataRequest) => Promise<TransformDataResponse>;
19
16
  private sendPostRequest;
20
17
  private sendDeleteRequest;
21
18
  private sendGetRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,+BAA+B,EAC/B,gCAAgC,EAChC,2BAA2B,EAC3B,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,kCAAkC,EAClC,iCAAiC,EACjC,kCAAkC,EACnC,MAAM,SAAS,CAAC;AASjB,qBAAa,mBAAoB,YAAW,aAAa;IACvD,WAAW,YAAmB,iBAAiB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@@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.teamworkgraph = exports.TeamWorkGraphClient = void 0;
4
4
  const api_1 = require("@forge/api");
5
5
  const error_handling_1 = require("./error-handling");
6
+ const validators_1 = require("./utils/validators");
6
7
  const STARGATE_BASE = '/graph/connector';
7
- const MAX_BULK_ENTITIES = 100;
8
- const MAX_BULK_USERS = 100;
9
- const MAX_BULK_GROUPS = 100;
10
- const MAX_BULK_ENTITIES_DELETE = 100;
11
- const MAX_USER_MAPPINGS = 100;
12
8
  class TeamWorkGraphClient {
13
9
  setEntities = async (request) => {
14
10
  const { entities } = request;
15
- if (!Array.isArray(entities)) {
16
- throw new Error('entities must be an array');
17
- }
18
- if (entities.length === 0) {
19
- throw new Error('entities array cannot be empty');
20
- }
21
- if (entities.length > MAX_BULK_ENTITIES) {
22
- throw new Error(`Bulk ingestion supports maximum ${MAX_BULK_ENTITIES} entities. Received ${entities.length}`);
23
- }
11
+ (0, validators_1.validateSetEntitiesRequest)(entities);
24
12
  const response = await this.sendPostRequest('/api/v1/entities/bulk', { entities });
25
13
  return response;
26
14
  };
27
15
  getEntityByExternalId = async (request) => {
28
16
  const { entityType, externalId } = request;
29
- if (!entityType || entityType.trim() === '') {
30
- throw new Error('entityType is required');
31
- }
32
- if (!externalId || externalId.trim() === '') {
33
- throw new Error('externalId is required');
34
- }
17
+ (0, validators_1.validateGetEntityByExternalIdRequest)(entityType, externalId);
35
18
  try {
36
19
  const url = new URL('/api/v1/entities', 'https://teamwork-graph.atlassian.net/api');
37
20
  url.searchParams.set('entityType', entityType);
@@ -52,18 +35,7 @@ class TeamWorkGraphClient {
52
35
  };
53
36
  deleteEntitiesByExternalId = async (request) => {
54
37
  const { entityType, externalIds } = request;
55
- if (!entityType || entityType.trim() === '') {
56
- throw new Error('entityType is required');
57
- }
58
- if (!Array.isArray(externalIds)) {
59
- throw new Error('externalIds must be an array');
60
- }
61
- if (externalIds.length === 0) {
62
- throw new Error('externalIds array cannot be empty');
63
- }
64
- if (externalIds.length > MAX_BULK_ENTITIES_DELETE) {
65
- throw new Error(`Bulk entity deletion supports maximum ${MAX_BULK_ENTITIES_DELETE} entities. Received ${externalIds.length}`);
66
- }
38
+ (0, validators_1.validateDeleteEntitiesByExternalIdRequest)(entityType, externalIds);
67
39
  const response = await this.sendDeleteRequest('/api/v1/entities/bulk/delete', {
68
40
  entityType,
69
41
  externalIds
@@ -71,37 +43,19 @@ class TeamWorkGraphClient {
71
43
  return response;
72
44
  };
73
45
  deleteEntitiesByProperties = async (request) => {
74
- if (!request || typeof request !== 'object') {
75
- throw new Error('properties must be an object');
76
- }
77
- if (Object.keys(request).length === 0) {
78
- throw new Error('properties object cannot be empty');
79
- }
46
+ (0, validators_1.validateDeleteEntitiesByPropertiesRequest)(request);
80
47
  const response = await this.sendDeleteRequest('/api/v1/entities/bulk/delete-by-properties', request);
81
48
  return response;
82
49
  };
83
50
  setGroups = async (request) => {
84
51
  const { groups } = request;
85
- if (!Array.isArray(groups)) {
86
- throw new Error('groups must be an array');
87
- }
88
- if (groups.length === 0) {
89
- throw new Error('groups array cannot be empty');
90
- }
91
- if (groups.length > MAX_BULK_GROUPS) {
92
- throw new Error(`Bulk group ingestion supports maximum ${MAX_BULK_GROUPS} groups. Received ${groups.length}`);
93
- }
52
+ (0, validators_1.validateSetGroupsRequest)(groups);
94
53
  const response = await this.sendPostRequest('/api/v1/groups/bulk', { groups });
95
54
  return response;
96
55
  };
97
56
  deleteGroupsByExternalId = async (request) => {
98
57
  const { externalIds } = request;
99
- if (!Array.isArray(externalIds)) {
100
- throw new Error('externalIds must be an array');
101
- }
102
- if (externalIds.length === 0) {
103
- throw new Error('externalIds array cannot be empty');
104
- }
58
+ (0, validators_1.validateDeleteGroupsByExternalIdRequest)(externalIds);
105
59
  const response = await this.sendPostRequest('/api/v1/groups/bulk/delete', {
106
60
  externalIds
107
61
  });
@@ -109,9 +63,7 @@ class TeamWorkGraphClient {
109
63
  };
110
64
  getGroupByExternalId = async (request) => {
111
65
  const { externalId } = request;
112
- if (!externalId || externalId.trim() === '') {
113
- throw new Error('externalId is required');
114
- }
66
+ (0, validators_1.validateGetGroupByExternalIdRequest)(externalId);
115
67
  try {
116
68
  const url = new URL('/api/v1/groups', 'https://teamwork-graph.atlassian.net/api');
117
69
  url.searchParams.set('externalId', externalId);
@@ -131,26 +83,13 @@ class TeamWorkGraphClient {
131
83
  };
132
84
  setUsers = async (request) => {
133
85
  const { users } = request;
134
- if (!Array.isArray(users)) {
135
- throw new Error('users must be an array');
136
- }
137
- if (users.length === 0) {
138
- throw new Error('users array cannot be empty');
139
- }
140
- if (users.length > MAX_BULK_USERS) {
141
- throw new Error(`Bulk user ingestion supports maximum ${MAX_BULK_USERS} users. Received ${users.length}`);
142
- }
86
+ (0, validators_1.validateSetUsersRequest)(users);
143
87
  const response = await this.sendPostRequest('/api/v1/users/bulk', { users });
144
88
  return response;
145
89
  };
146
90
  deleteUsersByExternalId = async (request) => {
147
91
  const { externalIds } = request;
148
- if (!Array.isArray(externalIds)) {
149
- throw new Error('externalIds must be an array');
150
- }
151
- if (externalIds.length === 0) {
152
- throw new Error('externalIds array cannot be empty');
153
- }
92
+ (0, validators_1.validateDeleteUsersByExternalIdRequest)(externalIds);
154
93
  const response = await this.sendPostRequest('/api/v1/users/bulk/delete', {
155
94
  externalIds
156
95
  });
@@ -158,9 +97,7 @@ class TeamWorkGraphClient {
158
97
  };
159
98
  getUserByExternalId = async (request) => {
160
99
  const { externalId } = request;
161
- if (!externalId || externalId.trim() === '') {
162
- throw new Error('externalId is required');
163
- }
100
+ (0, validators_1.validateGetUserByExternalIdRequest)(externalId);
164
101
  try {
165
102
  const url = new URL('/api/v1/users', 'https://teamwork-graph.atlassian.net/api');
166
103
  url.searchParams.set('externalId', externalId);
@@ -180,57 +117,55 @@ class TeamWorkGraphClient {
180
117
  };
181
118
  mapUsers = async (request) => {
182
119
  const { directMappings } = request;
183
- if (!Array.isArray(directMappings)) {
184
- throw new Error('directMappings must be an array');
185
- }
186
- if (directMappings.length === 0) {
187
- throw new Error('directMappings array cannot be empty');
188
- }
189
- if (directMappings.length > MAX_USER_MAPPINGS) {
190
- throw new Error(`Bulk user mapping supports maximum ${MAX_USER_MAPPINGS} mappings. Received ${directMappings.length}`);
191
- }
192
- const invalidMapping = directMappings.find((mapping) => !mapping.accountId && !mapping.externalEmailAddress);
193
- if (invalidMapping) {
194
- throw new Error('Each mapping must have either accountId or externalEmailAddress');
195
- }
196
- const mappingWithoutExternalId = directMappings.find((mapping) => !mapping.externalId);
197
- if (mappingWithoutExternalId) {
198
- throw new Error('Each mapping must have an externalId');
199
- }
120
+ (0, validators_1.validateMapUsersRequest)(directMappings);
200
121
  const response = await this.sendPostRequest('/api/v1/users/mappings', {
201
122
  directMappings
202
123
  });
203
124
  return response;
204
125
  };
205
- fetchData = async (context, requestConfig, onResult) => {
206
- this.validateContext(context);
126
+ fetchData = async (request) => {
127
+ (0, validators_1.validateFetchDataRequest)(request);
128
+ const { requestConfig, onResult } = request;
207
129
  const { url, method, headers } = requestConfig;
208
- const res = await (0, api_1.fetch)(url, {
209
- method: method,
210
- headers: headers
211
- });
212
- if (!res.ok) {
213
- throw new Error(`Remote call failed with status: ${res.status}`);
130
+ try {
131
+ const res = await (0, api_1.fetch)(url, {
132
+ method: method,
133
+ headers: headers
134
+ });
135
+ if (!res.ok) {
136
+ throw new Error(`Remote call failed with status: ${res.status}`);
137
+ }
138
+ const data = await res.json();
139
+ onResult(data);
140
+ return {
141
+ success: true,
142
+ data: data
143
+ };
144
+ }
145
+ catch (error) {
146
+ return {
147
+ success: false,
148
+ error: error instanceof Error ? error.message : 'Unknown error'
149
+ };
214
150
  }
215
- const data = await res.json();
216
- await this.saveToStage(data);
217
- await this.validateData(data);
218
- onResult(data);
219
- return data;
220
- };
221
- transformData = async (context, data, transformMethod) => {
222
- this.validateContext(context);
223
- return transformMethod(data);
224
151
  };
225
- async saveToStage(data) {
226
- }
227
- async validateData(data) {
228
- }
229
- validateContext(context) {
230
- if (!context) {
231
- throw new Error('Please pass the context object in your method. Refer this - https://developer.atlassian.com/platform/forge/function-reference/');
152
+ transformData = async (request) => {
153
+ (0, validators_1.validateTransformDataRequest)(request);
154
+ const { data, transformMethod } = request;
155
+ try {
156
+ const transformedData = transformMethod(data);
157
+ return {
158
+ success: true,
159
+ transformedData: transformedData
160
+ };
232
161
  }
233
- }
162
+ catch (error) {
163
+ return {
164
+ success: false,
165
+ error: error instanceof Error ? error.message : 'Unknown error'
166
+ };
167
+ }
168
+ };
234
169
  async sendPostRequest(path, body) {
235
170
  const response = await this.sendRequest(path, {
236
171
  method: 'POST',
@@ -54,25 +54,4 @@ export declare type AssociationObject = {
54
54
  export declare type Associations = {
55
55
  set: AssociationObject[];
56
56
  };
57
- export declare type IngestionContext = {
58
- id: string;
59
- [key: string]: string;
60
- };
61
- export declare type ForgeExtendedContext = {
62
- principal: {
63
- accountId: string;
64
- };
65
- installContext: string;
66
- workspaceId?: string;
67
- license: {
68
- isActive: boolean;
69
- };
70
- ingestionContext?: IngestionContext;
71
- };
72
- export declare type RequestConfig = {
73
- url: string;
74
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
75
- params?: Record<string, any>;
76
- headers?: any;
77
- };
78
57
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,oBAAY,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,qBAAqB,GAAG,WAAW,CAAC;IAC1E,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEF,o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IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,oBAAY,YAAY,GAAG;IACzB,GAAG,EAAE,iBAAiB,EAAE,CAAC;CAC1B,CAAC"}
@@ -1,12 +1,11 @@
1
- import { Result } from '@forge/api';
2
- import { ForgeExtendedContext, RequestConfig, BulkEntityRequest, BulkEntityResponse, BulkUsersRequest, BulkUsersResponse, DeleteUsersByExternalIdRequest, DeleteUsersByExternalIdResponse, GetUserByExternalIdRequest, GetUserByExternalIdResponse, MapUsersRequest, MapUsersResponse, BulkGroupsRequest, BulkGroupsResponse, DeleteGroupsByExternalIdRequest, DeleteGroupsByExternalIdResponse, GetGroupByExternalIdRequest, GetGroupByExternalIdResponse, GetEntityByExternalIdRequest, GetEntityByExternalIdResponse, DeleteEntitiesByExternalIdRequest, DeleteEntitiesByExternalIdResponse, DeleteEntitiesByPropertiesRequest, DeleteEntitiesByPropertiesResponse } from './';
1
+ import { BulkEntityRequest, BulkEntityResponse, BulkUsersRequest, BulkUsersResponse, DeleteUsersByExternalIdRequest, DeleteUsersByExternalIdResponse, GetUserByExternalIdRequest, GetUserByExternalIdResponse, MapUsersRequest, MapUsersResponse, BulkGroupsRequest, BulkGroupsResponse, DeleteGroupsByExternalIdRequest, DeleteGroupsByExternalIdResponse, GetGroupByExternalIdRequest, GetGroupByExternalIdResponse, GetEntityByExternalIdRequest, GetEntityByExternalIdResponse, DeleteEntitiesByExternalIdRequest, DeleteEntitiesByExternalIdResponse, DeleteEntitiesByPropertiesRequest, DeleteEntitiesByPropertiesResponse, FetchDataRequest, FetchDataResponse, TransformDataRequest, TransformDataResponse } from './';
3
2
  export interface TeamWorkGraph {
4
3
  setEntities(request: BulkEntityRequest): Promise<BulkEntityResponse>;
5
4
  getEntityByExternalId(request: GetEntityByExternalIdRequest): Promise<GetEntityByExternalIdResponse>;
6
5
  deleteEntitiesByExternalId(request: DeleteEntitiesByExternalIdRequest): Promise<DeleteEntitiesByExternalIdResponse>;
7
6
  deleteEntitiesByProperties(request: DeleteEntitiesByPropertiesRequest): Promise<DeleteEntitiesByPropertiesResponse>;
8
- fetchData(context: ForgeExtendedContext, requestConfig: RequestConfig, onResult: Function): Promise<Result>;
9
- transformData(context: ForgeExtendedContext, data: any, transformMethod: Function): Promise<any>;
7
+ fetchData(request: FetchDataRequest): Promise<FetchDataResponse>;
8
+ transformData(request: TransformDataRequest): Promise<TransformDataResponse>;
10
9
  setUsers(request: BulkUsersRequest): Promise<BulkUsersResponse>;
11
10
  deleteUsersByExternalId(request: DeleteUsersByExternalIdRequest): Promise<DeleteUsersByExternalIdResponse>;
12
11
  getUserByExternalId(request: GetUserByExternalIdRequest): Promise<GetUserByExternalIdResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/types/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,+BAA+B,EAC/B,gCAAgC,EAChC,2BAA2B,EAC3B,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,kCAAkC,EAClC,iCAAiC,EACjC,kCAAkC,EACnC,MAAM,IAAI,CAAC;AAEZ,MAAM,WAAW,aAAa;IAE5B,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrE,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;IACrG,0BAA0B,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;IACpH,0BAA0B,CA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ponse = {
119
119
  group?: Group;
120
120
  error?: string;
121
121
  };
122
+ export declare type FetchDataRequest = {
123
+ requestConfig: {
124
+ url: string;
125
+ method: string;
126
+ headers?: Record<string, string>;
127
+ };
128
+ onResult: (data: any) => any;
129
+ };
130
+ export declare type FetchDataResponse = {
131
+ success: boolean;
132
+ data?: any;
133
+ error?: string;
134
+ };
135
+ export declare type TransformDataRequest = {
136
+ data: any;
137
+ transformMethod: (data: any) => any;
138
+ };
139
+ export declare type TransformDataResponse = {
140
+ success: boolean;
141
+ transformedData?: any;
142
+ error?: string;
143
+ };
122
144
  //# sourceMappingURL=requests.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../src/types/requests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAGpE,oBAAY,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACzB,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ,CAAC;AAEF,oBAAY,4BAA4B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oBAAY,6BAA6B,GAAG;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,iCAAiC,GAAG;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF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M,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,CAAC;IACF,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC;CAC9B,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,oBAAoB,GAAG;IACjC,IAAI,EAAE,GAAG,CAAC;IACV,eAAe,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC;CACrC,CAAC;AAEF,oBAAY,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -0,0 +1,23 @@
1
+ export declare const MAX_BULK_ENTITIES = 100;
2
+ export declare const MAX_BULK_USERS = 100;
3
+ export declare const MAX_BULK_GROUPS = 100;
4
+ export declare const MAX_BULK_ENTITIES_DELETE = 100;
5
+ export declare const MAX_USER_MAPPINGS = 100;
6
+ export declare function validateArray(value: any, fieldName: string): void;
7
+ export declare function validateArrayMaxLength(value: any[], fieldName: string, maxLength: number, itemType?: string): void;
8
+ export declare function validateRequiredString(value: string | undefined, fieldName: string): void;
9
+ export declare function validateObject(value: any, fieldName: string): void;
10
+ export declare function validateSetEntitiesRequest(entities: any[]): void;
11
+ export declare function validateSetUsersRequest(users: any[]): void;
12
+ export declare function validateSetGroupsRequest(groups: any[]): void;
13
+ export declare function validateDeleteEntitiesByExternalIdRequest(entityType: string, externalIds: string[]): void;
14
+ export declare function validateDeleteUsersByExternalIdRequest(externalIds: string[]): void;
15
+ export declare function validateDeleteGroupsByExternalIdRequest(externalIds: string[]): void;
16
+ export declare function validateGetEntityByExternalIdRequest(entityType: string, externalId: string): void;
17
+ export declare function validateGetUserByExternalIdRequest(externalId: string): void;
18
+ export declare function validateGetGroupByExternalIdRequest(externalId: string): void;
19
+ export declare function validateMapUsersRequest(directMappings: any[]): void;
20
+ export declare function validateDeleteEntitiesByPropertiesRequest(properties: any): void;
21
+ export declare function validateFetchDataRequest(request: any): void;
22
+ export declare function validateTransformDataRequest(request: any): void;
23
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAKrC,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAOjE;AAKD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,SAAU,GAAG,IAAI,CAInH;AAKD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAIzF;AAKD,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAOlE;AAKD,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,CAGhE;AAKD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAG1D;AAKD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAG5D;AAKD,wBAAgB,yCAAyC,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAIzG;AAKD,wBAAgB,sCAAsC,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAElF;AAKD,wBAAgB,uCAAuC,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAEnF;AAKD,wBAAgB,oCAAoC,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAGjG;AAKD,wBAAgB,kCAAkC,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAE3E;AAKD,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAE5E;AAKD,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAenE;AAKD,wBAAgB,yCAAyC,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI,CAE/E;AAKD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAoB3D;AAKD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAQ/D"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateTransformDataRequest = exports.validateFetchDataRequest = exports.validateDeleteEntitiesByPropertiesRequest = exports.validateMapUsersRequest = exports.validateGetGroupByExternalIdRequest = exports.validateGetUserByExternalIdRequest = exports.validateGetEntityByExternalIdRequest = exports.validateDeleteGroupsByExternalIdRequest = exports.validateDeleteUsersByExternalIdRequest = exports.validateDeleteEntitiesByExternalIdRequest = exports.validateSetGroupsRequest = exports.validateSetUsersRequest = exports.validateSetEntitiesRequest = exports.validateObject = exports.validateRequiredString = exports.validateArrayMaxLength = exports.validateArray = exports.MAX_USER_MAPPINGS = exports.MAX_BULK_ENTITIES_DELETE = exports.MAX_BULK_GROUPS = exports.MAX_BULK_USERS = exports.MAX_BULK_ENTITIES = void 0;
4
+ exports.MAX_BULK_ENTITIES = 100;
5
+ exports.MAX_BULK_USERS = 100;
6
+ exports.MAX_BULK_GROUPS = 100;
7
+ exports.MAX_BULK_ENTITIES_DELETE = 100;
8
+ exports.MAX_USER_MAPPINGS = 100;
9
+ function validateArray(value, fieldName) {
10
+ if (!Array.isArray(value)) {
11
+ throw new Error(`${fieldName} must be an array`);
12
+ }
13
+ if (value.length === 0) {
14
+ throw new Error(`${fieldName} array cannot be empty`);
15
+ }
16
+ }
17
+ exports.validateArray = validateArray;
18
+ function validateArrayMaxLength(value, fieldName, maxLength, itemType = 'items') {
19
+ if (value.length > maxLength) {
20
+ throw new Error(`${fieldName} supports maximum ${maxLength} ${itemType}. Received ${value.length}`);
21
+ }
22
+ }
23
+ exports.validateArrayMaxLength = validateArrayMaxLength;
24
+ function validateRequiredString(value, fieldName) {
25
+ if (!value || value.trim() === '') {
26
+ throw new Error(`${fieldName} is required`);
27
+ }
28
+ }
29
+ exports.validateRequiredString = validateRequiredString;
30
+ function validateObject(value, fieldName) {
31
+ if (!value || typeof value !== 'object') {
32
+ throw new Error(`${fieldName} must be an object`);
33
+ }
34
+ if (Object.keys(value).length === 0) {
35
+ throw new Error(`${fieldName} object cannot be empty`);
36
+ }
37
+ }
38
+ exports.validateObject = validateObject;
39
+ function validateSetEntitiesRequest(entities) {
40
+ validateArray(entities, 'entities');
41
+ validateArrayMaxLength(entities, 'Bulk ingestion', exports.MAX_BULK_ENTITIES, 'entities');
42
+ }
43
+ exports.validateSetEntitiesRequest = validateSetEntitiesRequest;
44
+ function validateSetUsersRequest(users) {
45
+ validateArray(users, 'users');
46
+ validateArrayMaxLength(users, 'Bulk user ingestion', exports.MAX_BULK_USERS, 'users');
47
+ }
48
+ exports.validateSetUsersRequest = validateSetUsersRequest;
49
+ function validateSetGroupsRequest(groups) {
50
+ validateArray(groups, 'groups');
51
+ validateArrayMaxLength(groups, 'Bulk group ingestion', exports.MAX_BULK_GROUPS, 'groups');
52
+ }
53
+ exports.validateSetGroupsRequest = validateSetGroupsRequest;
54
+ function validateDeleteEntitiesByExternalIdRequest(entityType, externalIds) {
55
+ validateRequiredString(entityType, 'entityType');
56
+ validateArray(externalIds, 'externalIds');
57
+ validateArrayMaxLength(externalIds, 'Bulk entity deletion', exports.MAX_BULK_ENTITIES_DELETE, 'entities');
58
+ }
59
+ exports.validateDeleteEntitiesByExternalIdRequest = validateDeleteEntitiesByExternalIdRequest;
60
+ function validateDeleteUsersByExternalIdRequest(externalIds) {
61
+ validateArray(externalIds, 'externalIds');
62
+ }
63
+ exports.validateDeleteUsersByExternalIdRequest = validateDeleteUsersByExternalIdRequest;
64
+ function validateDeleteGroupsByExternalIdRequest(externalIds) {
65
+ validateArray(externalIds, 'externalIds');
66
+ }
67
+ exports.validateDeleteGroupsByExternalIdRequest = validateDeleteGroupsByExternalIdRequest;
68
+ function validateGetEntityByExternalIdRequest(entityType, externalId) {
69
+ validateRequiredString(entityType, 'entityType');
70
+ validateRequiredString(externalId, 'externalId');
71
+ }
72
+ exports.validateGetEntityByExternalIdRequest = validateGetEntityByExternalIdRequest;
73
+ function validateGetUserByExternalIdRequest(externalId) {
74
+ validateRequiredString(externalId, 'externalId');
75
+ }
76
+ exports.validateGetUserByExternalIdRequest = validateGetUserByExternalIdRequest;
77
+ function validateGetGroupByExternalIdRequest(externalId) {
78
+ validateRequiredString(externalId, 'externalId');
79
+ }
80
+ exports.validateGetGroupByExternalIdRequest = validateGetGroupByExternalIdRequest;
81
+ function validateMapUsersRequest(directMappings) {
82
+ validateArray(directMappings, 'directMappings');
83
+ validateArrayMaxLength(directMappings, 'Bulk user mapping', exports.MAX_USER_MAPPINGS, 'mappings');
84
+ const invalidMapping = directMappings.find((mapping) => !mapping.accountId && !mapping.externalEmailAddress);
85
+ if (invalidMapping) {
86
+ throw new Error('Each mapping must have either accountId or externalEmailAddress');
87
+ }
88
+ const mappingWithoutExternalId = directMappings.find((mapping) => !mapping.externalId);
89
+ if (mappingWithoutExternalId) {
90
+ throw new Error('Each mapping must have an externalId');
91
+ }
92
+ }
93
+ exports.validateMapUsersRequest = validateMapUsersRequest;
94
+ function validateDeleteEntitiesByPropertiesRequest(properties) {
95
+ validateObject(properties, 'properties');
96
+ }
97
+ exports.validateDeleteEntitiesByPropertiesRequest = validateDeleteEntitiesByPropertiesRequest;
98
+ function validateFetchDataRequest(request) {
99
+ if (!request || typeof request !== 'object') {
100
+ throw new Error('request must be an object');
101
+ }
102
+ if (!request.requestConfig || typeof request.requestConfig !== 'object') {
103
+ throw new Error('requestConfig is required and must be an object');
104
+ }
105
+ if (!request.requestConfig.url || typeof request.requestConfig.url !== 'string') {
106
+ throw new Error('requestConfig.url is required and must be a string');
107
+ }
108
+ if (!request.requestConfig.method || typeof request.requestConfig.method !== 'string') {
109
+ throw new Error('requestConfig.method is required and must be a string');
110
+ }
111
+ if (!request.onResult || typeof request.onResult !== 'function') {
112
+ throw new Error('onResult is required and must be a function');
113
+ }
114
+ }
115
+ exports.validateFetchDataRequest = validateFetchDataRequest;
116
+ function validateTransformDataRequest(request) {
117
+ if (!request || typeof request !== 'object') {
118
+ throw new Error('request must be an object');
119
+ }
120
+ if (!request.transformMethod || typeof request.transformMethod !== 'function') {
121
+ throw new Error('transformMethod is required and must be a function');
122
+ }
123
+ }
124
+ exports.validateTransformDataRequest = validateTransformDataRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/teamwork-graph",
3
- "version": "1.2.0-next.3-experimental-42e3178",
3
+ "version": "1.2.0-next.4",
4
4
  "description": "Forge TeamworkGraph SDK",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -22,7 +22,7 @@
22
22
  "jest-when": "^3.6.0"
23
23
  },
24
24
  "dependencies": {
25
- "@forge/api": "^6.0.2-next.1-experimental-42e3178"
25
+ "@forge/api": "^6.0.2-next.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "registry": "https://packages.atlassian.com/api/npm/npm-public/"