@forge/teamwork-graph 0.1.0-next.0 → 0.1.0-next.2
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/README.md +64 -12
- package/out/__test__/graph-extended.test.d.ts +2 -0
- package/out/__test__/graph-extended.test.d.ts.map +1 -0
- package/out/__test__/graph-extended.test.js +82 -0
- package/out/__test__/graph.test.js +111 -2
- package/out/graph.d.ts +11 -7
- package/out/graph.d.ts.map +1 -1
- package/out/graph.js +32 -9
- package/out/utils/types.d.ts +44 -12
- package/out/utils/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ npm install @forge/teamwork-graph
|
|
|
16
16
|
import { graph } from '@forge/teamwork-graph';
|
|
17
17
|
import type { EntityPayload, DocumentCategory } from '@forge/teamwork-graph';
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
const documentPayload: EntityPayload = {
|
|
20
21
|
// Required base fields
|
|
21
22
|
schemaVersion: '1.0',
|
|
@@ -122,24 +123,74 @@ const documentPayload: EntityPayload = {
|
|
|
122
123
|
}
|
|
123
124
|
};
|
|
124
125
|
|
|
125
|
-
// Send the document to the API
|
|
126
|
-
|
|
126
|
+
// Send the document to the API - now with context parameter
|
|
127
|
+
// context will be provided by the framework
|
|
128
|
+
await graph.setEntity(context, documentPayload);
|
|
127
129
|
```
|
|
128
130
|
|
|
129
131
|
### Delete Operations
|
|
130
132
|
|
|
131
133
|
```typescript
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
|
|
135
|
+
// Delete an entity - now with context parameter
|
|
136
|
+
await graph.deleteEntity(context, 'entity-123');
|
|
137
|
+
|
|
138
|
+
// Delete a user - now with context parameter
|
|
139
|
+
await graph.deleteUser(context, 'user-123');
|
|
140
|
+
|
|
141
|
+
// Delete a group - now with context parameter
|
|
142
|
+
await graph.deleteGroup(context, 'group-123');
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Fetch External Data
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
|
|
149
|
+
// Define the request configuration
|
|
150
|
+
const requestConfig = () => ({
|
|
151
|
+
path: '/api/v1/tasks',
|
|
152
|
+
method: 'GET',
|
|
153
|
+
remoteKey: 'jira',
|
|
154
|
+
url: 'https://your-instance.atlassian.net',
|
|
155
|
+
headers: [
|
|
156
|
+
{ 'Authorization': 'Bearer your-token' }
|
|
157
|
+
]
|
|
136
158
|
});
|
|
137
159
|
|
|
138
|
-
//
|
|
139
|
-
|
|
160
|
+
// Define the result handler
|
|
161
|
+
const handleResult = (data) => {
|
|
162
|
+
console.log('Fetched data:', data);
|
|
163
|
+
// Process the data as needed
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// Fetch and process the data
|
|
167
|
+
await graph.fetchExternalData(context, requestConfig, handleResult);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Transform Data
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
|
|
174
|
+
// Define the raw data
|
|
175
|
+
const rawData = {
|
|
176
|
+
issues: [
|
|
177
|
+
{ key: 'PROJ-123', summary: 'Fix bug', assignee: { key: 'user1' } },
|
|
178
|
+
{ key: 'PROJ-456', summary: 'Add feature', assignee: { key: 'user2' } }
|
|
179
|
+
]
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// Define the transform function
|
|
183
|
+
const transformToEntities = (data) => {
|
|
184
|
+
return data.issues.map(issue => ({
|
|
185
|
+
id: issue.key,
|
|
186
|
+
displayName: issue.summary,
|
|
187
|
+
type: 'issue',
|
|
188
|
+
assignee: issue.assignee.key
|
|
189
|
+
}));
|
|
190
|
+
};
|
|
140
191
|
|
|
141
|
-
//
|
|
142
|
-
await graph.
|
|
192
|
+
// Transform the data
|
|
193
|
+
const transformedData = await graph.transformData(context, rawData, transformToEntities);
|
|
143
194
|
```
|
|
144
195
|
|
|
145
196
|
## Error Handling
|
|
@@ -156,7 +207,8 @@ errorCodes.TOO_MANY_REQUESTS // 429 Rate Limit
|
|
|
156
207
|
errorCodes.UNKNOWN_ERROR // Other errors
|
|
157
208
|
|
|
158
209
|
try {
|
|
159
|
-
|
|
210
|
+
const context = { id: 'operation-123', cloudId: 'cloud-123' };
|
|
211
|
+
await graph.setEntity(context, /* ... */);
|
|
160
212
|
} catch (error) {
|
|
161
213
|
if (error instanceof ForgeGraphAPIError) {
|
|
162
214
|
console.error(error.code, error.message);
|
|
@@ -193,6 +245,6 @@ import type {
|
|
|
193
245
|
AssociationObject,
|
|
194
246
|
|
|
195
247
|
// Operations
|
|
196
|
-
|
|
248
|
+
RequestConfig
|
|
197
249
|
} from '@forge/teamwork-graph';
|
|
198
250
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-extended.test.d.ts","sourceRoot":"","sources":["../../src/__test__/graph-extended.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const api_1 = require("@forge/api");
|
|
4
|
+
const graph_1 = require("../graph");
|
|
5
|
+
jest.mock('@forge/api', () => ({
|
|
6
|
+
__fetchProduct: jest.fn(),
|
|
7
|
+
invokeRemote: jest.fn()
|
|
8
|
+
}));
|
|
9
|
+
describe('Teamwork Graph Client Extended Features', () => {
|
|
10
|
+
let graphClient;
|
|
11
|
+
let mockContext;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
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
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
describe('fetchExternalData', () => {
|
|
25
|
+
it('should successfully fetch and process external data', async () => {
|
|
26
|
+
const mockData = { items: [{ id: 1, name: 'Task 1' }] };
|
|
27
|
+
const mockResponse = {
|
|
28
|
+
ok: true,
|
|
29
|
+
status: 200,
|
|
30
|
+
json: jest.fn().mockResolvedValue(mockData)
|
|
31
|
+
};
|
|
32
|
+
api_1.invokeRemote.mockResolvedValue(mockResponse);
|
|
33
|
+
const requestConfig = {
|
|
34
|
+
path: '/api/tasks',
|
|
35
|
+
method: 'GET',
|
|
36
|
+
remoteKey: 'jira',
|
|
37
|
+
headers: { Authorization: 'Bearer token' }
|
|
38
|
+
};
|
|
39
|
+
const onResult = jest.fn();
|
|
40
|
+
const result = await graphClient.fetchData(mockContext, requestConfig, onResult);
|
|
41
|
+
expect(api_1.invokeRemote).toHaveBeenCalledWith('jira', {
|
|
42
|
+
path: '/api/tasks',
|
|
43
|
+
method: 'GET',
|
|
44
|
+
headers: { Authorization: 'Bearer token' }
|
|
45
|
+
});
|
|
46
|
+
expect(onResult).toHaveBeenCalledWith(mockData);
|
|
47
|
+
expect(result).toEqual(mockData);
|
|
48
|
+
});
|
|
49
|
+
it('should throw error when invokeRemote fails', async () => {
|
|
50
|
+
const mockResponse = {
|
|
51
|
+
ok: false,
|
|
52
|
+
status: 401
|
|
53
|
+
};
|
|
54
|
+
api_1.invokeRemote.mockResolvedValue(mockResponse);
|
|
55
|
+
const requestConfig = {
|
|
56
|
+
path: '/api/tasks',
|
|
57
|
+
method: 'GET',
|
|
58
|
+
remoteKey: 'jira'
|
|
59
|
+
};
|
|
60
|
+
const onResult = jest.fn();
|
|
61
|
+
await expect(graphClient.fetchData(mockContext, requestConfig, onResult)).rejects.toThrow('invokeRemote failed: 401');
|
|
62
|
+
expect(onResult).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('transformData', () => {
|
|
66
|
+
it('should transform data using the provided transform method', async () => {
|
|
67
|
+
const inputData = { items: [{ id: 1, name: 'Task 1' }] };
|
|
68
|
+
const transformMethod = jest.fn().mockImplementation((data) => ({
|
|
69
|
+
entities: data.items.map((item) => ({
|
|
70
|
+
id: `task-${item.id}`,
|
|
71
|
+
name: item.name,
|
|
72
|
+
type: 'task'
|
|
73
|
+
}))
|
|
74
|
+
}));
|
|
75
|
+
const result = await graphClient.transformData(mockContext, inputData, transformMethod);
|
|
76
|
+
expect(transformMethod).toHaveBeenCalledWith(inputData);
|
|
77
|
+
expect(result).toEqual({
|
|
78
|
+
entities: [{ id: 'task-1', name: 'Task 1', type: 'task' }]
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -7,10 +7,17 @@ jest.mock('@forge/api');
|
|
|
7
7
|
describe('Teamwork Graph Client', () => {
|
|
8
8
|
let graphClient;
|
|
9
9
|
let mockFetch;
|
|
10
|
+
let mockContext;
|
|
10
11
|
beforeEach(() => {
|
|
11
12
|
graphClient = new graph_1.TeamWorkGraphClient();
|
|
12
13
|
mockFetch = jest.fn();
|
|
13
14
|
api_1.__fetchProduct.mockReturnValue(mockFetch);
|
|
15
|
+
mockContext = {
|
|
16
|
+
ingestionContext: { id: 'test' },
|
|
17
|
+
installContext: 'test-installation',
|
|
18
|
+
principal: { accountId: 'test' },
|
|
19
|
+
license: { isActive: true }
|
|
20
|
+
};
|
|
14
21
|
jest.clearAllMocks();
|
|
15
22
|
});
|
|
16
23
|
describe('setEntity', () => {
|
|
@@ -30,7 +37,7 @@ describe('Teamwork Graph Client', () => {
|
|
|
30
37
|
ok: true,
|
|
31
38
|
json: () => Promise.resolve(expectedResponse)
|
|
32
39
|
});
|
|
33
|
-
const result = await graphClient.setEntity(entityPayload);
|
|
40
|
+
const result = await graphClient.setEntity(mockContext, entityPayload);
|
|
34
41
|
expect(mockFetch).toHaveBeenCalledWith('/graph/connector/api/v1/entity', {
|
|
35
42
|
method: 'POST',
|
|
36
43
|
body: JSON.stringify(entityPayload),
|
|
@@ -53,7 +60,109 @@ describe('Teamwork Graph Client', () => {
|
|
|
53
60
|
}))
|
|
54
61
|
};
|
|
55
62
|
mockFetch.mockResolvedValueOnce(errorResponse);
|
|
56
|
-
await expect(graphClient.setEntity(entityPayload)).rejects.toThrow(errors_1.ForgeGraphAPIError);
|
|
63
|
+
await expect(graphClient.setEntity(mockContext, entityPayload)).rejects.toThrow(errors_1.ForgeGraphAPIError);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('setUser', () => {
|
|
67
|
+
const userPayload = {
|
|
68
|
+
externalId: 'user-123',
|
|
69
|
+
accountId: 'acc-123',
|
|
70
|
+
displayName: 'Test User',
|
|
71
|
+
userName: 'testuser',
|
|
72
|
+
nickname: 'tester',
|
|
73
|
+
name: {
|
|
74
|
+
formatted: 'Test User',
|
|
75
|
+
familyName: 'User',
|
|
76
|
+
givenName: 'Test'
|
|
77
|
+
},
|
|
78
|
+
photos: ['https://example.com/avatar.jpg'],
|
|
79
|
+
emails: [
|
|
80
|
+
{ value: 'test@example.com', primary: true },
|
|
81
|
+
{ value: 'backup@example.com', primary: false }
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
it('should successfully post user data', async () => {
|
|
85
|
+
const expectedResponse = { success: true, user: userPayload };
|
|
86
|
+
mockFetch.mockResolvedValueOnce({
|
|
87
|
+
ok: true,
|
|
88
|
+
json: () => Promise.resolve(expectedResponse)
|
|
89
|
+
});
|
|
90
|
+
const result = await graphClient.setUser(mockContext, userPayload);
|
|
91
|
+
expect(mockFetch).toHaveBeenCalledWith('/graph/connector/api/v1/user', {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
body: JSON.stringify(userPayload),
|
|
94
|
+
redirect: 'follow',
|
|
95
|
+
headers: { 'Content-Type': 'application/json' }
|
|
96
|
+
});
|
|
97
|
+
expect(result).toEqual(expectedResponse);
|
|
98
|
+
});
|
|
99
|
+
it('should throw ForgeGraphAPIError when request fails', async () => {
|
|
100
|
+
const errorResponse = {
|
|
101
|
+
ok: false,
|
|
102
|
+
status: 400,
|
|
103
|
+
statusText: 'Bad Request',
|
|
104
|
+
headers: {
|
|
105
|
+
get: () => null
|
|
106
|
+
},
|
|
107
|
+
text: () => Promise.resolve(JSON.stringify({
|
|
108
|
+
code: errors_1.errorCodes.INVALID_REQUEST_BODY,
|
|
109
|
+
message: 'Invalid user data'
|
|
110
|
+
}))
|
|
111
|
+
};
|
|
112
|
+
mockFetch.mockResolvedValueOnce(errorResponse);
|
|
113
|
+
await expect(graphClient.setUser(mockContext, userPayload)).rejects.toThrow(errors_1.ForgeGraphAPIError);
|
|
114
|
+
});
|
|
115
|
+
it('should handle minimal user object with only required fields', async () => {
|
|
116
|
+
const minimalUser = {
|
|
117
|
+
externalId: 'min-user-123'
|
|
118
|
+
};
|
|
119
|
+
const expectedResponse = { success: true, user: minimalUser };
|
|
120
|
+
mockFetch.mockResolvedValueOnce({
|
|
121
|
+
ok: true,
|
|
122
|
+
json: () => Promise.resolve(expectedResponse)
|
|
123
|
+
});
|
|
124
|
+
const result = await graphClient.setUser(mockContext, minimalUser);
|
|
125
|
+
expect(mockFetch).toHaveBeenCalledWith('/graph/connector/api/v1/user', {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
body: JSON.stringify(minimalUser),
|
|
128
|
+
redirect: 'follow',
|
|
129
|
+
headers: { 'Content-Type': 'application/json' }
|
|
130
|
+
});
|
|
131
|
+
expect(result).toEqual(expectedResponse);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('deleteUser', () => {
|
|
135
|
+
const userId = 'user-123';
|
|
136
|
+
it('should successfully delete a user', async () => {
|
|
137
|
+
const expectedResponse = { success: true };
|
|
138
|
+
mockFetch.mockResolvedValueOnce({
|
|
139
|
+
ok: true,
|
|
140
|
+
json: () => Promise.resolve(expectedResponse)
|
|
141
|
+
});
|
|
142
|
+
const result = await graphClient.deleteUser(mockContext, userId);
|
|
143
|
+
expect(mockFetch).toHaveBeenCalledWith('/graph/connector/api/v1/user', {
|
|
144
|
+
method: 'DELETE',
|
|
145
|
+
body: JSON.stringify({ userId: userId }),
|
|
146
|
+
redirect: 'follow',
|
|
147
|
+
headers: { 'Content-Type': 'application/json' }
|
|
148
|
+
});
|
|
149
|
+
expect(result).toEqual(expectedResponse);
|
|
150
|
+
});
|
|
151
|
+
it('should throw ForgeGraphAPIError when delete request fails', async () => {
|
|
152
|
+
const errorResponse = {
|
|
153
|
+
ok: false,
|
|
154
|
+
status: 404,
|
|
155
|
+
statusText: 'Not Found',
|
|
156
|
+
headers: {
|
|
157
|
+
get: () => null
|
|
158
|
+
},
|
|
159
|
+
text: () => Promise.resolve(JSON.stringify({
|
|
160
|
+
code: 'USER_NOT_FOUND',
|
|
161
|
+
message: 'User not found'
|
|
162
|
+
}))
|
|
163
|
+
};
|
|
164
|
+
mockFetch.mockResolvedValueOnce(errorResponse);
|
|
165
|
+
await expect(graphClient.deleteUser(mockContext, userId)).rejects.toThrow(errors_1.ForgeGraphAPIError);
|
|
57
166
|
});
|
|
58
167
|
});
|
|
59
168
|
});
|
package/out/graph.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Result } from '@forge/api';
|
|
2
|
-
import { EntityPayload, UserObject, GroupObject,
|
|
2
|
+
import { EntityPayload, UserObject, GroupObject, TeamWorkGraph, ForgeExtendedContext, RequestConfig } from './utils/types';
|
|
3
3
|
export declare class TeamWorkGraphClient implements TeamWorkGraph {
|
|
4
|
-
setEntity: (entity: EntityPayload) => Promise<Result>;
|
|
5
|
-
deleteEntity: (
|
|
6
|
-
setUser: (user: UserObject) => Promise<Result>;
|
|
7
|
-
deleteUser: (userId: string) => Promise<Result>;
|
|
8
|
-
setGroup: (group: GroupObject) => Promise<Result>;
|
|
9
|
-
deleteGroup: (groupId: string) => Promise<Result>;
|
|
4
|
+
setEntity: (context: ForgeExtendedContext, entity: EntityPayload) => Promise<Result>;
|
|
5
|
+
deleteEntity: (context: ForgeExtendedContext, entityId: string) => Promise<Result>;
|
|
6
|
+
setUser: (context: ForgeExtendedContext, user: UserObject) => Promise<Result>;
|
|
7
|
+
deleteUser: (context: ForgeExtendedContext, userId: string) => Promise<Result>;
|
|
8
|
+
setGroup: (context: ForgeExtendedContext, group: GroupObject) => Promise<Result>;
|
|
9
|
+
deleteGroup: (context: ForgeExtendedContext, groupId: string) => Promise<Result>;
|
|
10
|
+
fetchData: (context: ForgeExtendedContext, requestConfig: RequestConfig, onResult: (data: any) => any) => Promise<any>;
|
|
11
|
+
private saveToStage;
|
|
12
|
+
private validateData;
|
|
13
|
+
transformData: (context: ForgeExtendedContext, data: any, transformMethod: (data: any) => any) => Promise<any>;
|
|
10
14
|
private sendPostRequest;
|
|
11
15
|
private sendDeleteRequest;
|
|
12
16
|
private sendRequest;
|
package/out/graph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,MAAM,
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,MAAM,EAA6B,MAAM,YAAY,CAAC;AAE5F,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,aAAa,EACd,MAAM,eAAe,CAAC;AAGvB,qBAAa,mBAAoB,YAAW,aAAa;IACvD,SAAS,YAAmB,oBAAoB,UAAU,aAAa,KAAG,QAAQ,MAAM,CAAC,CAEvF;IAEF,YAAY,YAAmB,oBAAoB,YAAY,MAAM,KAAG,QAAQ,MAAM,CAAC,CAErF;IAEF,OAAO,YAAmB,oBAAoB,QAAQ,UAAU,KAAG,QAAQ,MAAM,CAAC,CAEhF;IAEF,UAAU,YAAmB,oBAAoB,UAAU,MAAM,KAAG,QAAQ,MAAM,CAAC,CAEjF;IAEF,QAAQ,YAAmB,oBAAoB,SAAS,WAAW,KAAG,QAAQ,MAAM,CAAC,CAEnF;IAEF,WAAW,YAAmB,oBAAoB,WAAW,MAAM,KAAG,QAAQ,MAAM,CAAC,CAEnF;IAEF,SAAS,YAAmB,oBAAoB,iBAAiB,aAAa,mBAAmB,GAAG,KAAK,GAAG,kBAuB1G;YAEY,WAAW;YAIX,YAAY;IAI1B,aAAa,YAAmB,oBAAoB,QAAQ,GAAG,0BAA0B,GAAG,KAAK,GAAG,kBAGlG;YAEY,eAAe;YAaf,iBAAiB;YAajB,WAAW;CAY1B;AAED,eAAO,MAAM,aAAa,qBAA4B,CAAC"}
|
package/out/graph.js
CHANGED
|
@@ -5,23 +5,46 @@ const api_1 = require("@forge/api");
|
|
|
5
5
|
const error_handling_1 = require("./error-handling");
|
|
6
6
|
const starGateBase = '/graph/connector';
|
|
7
7
|
class TeamWorkGraphClient {
|
|
8
|
-
setEntity = async (entity) => {
|
|
8
|
+
setEntity = async (context, entity) => {
|
|
9
9
|
return this.sendPostRequest('/api/v1/entity', entity);
|
|
10
10
|
};
|
|
11
|
-
deleteEntity = async (
|
|
12
|
-
return this.sendDeleteRequest('/api/v1/entity', {
|
|
11
|
+
deleteEntity = async (context, entityId) => {
|
|
12
|
+
return this.sendDeleteRequest('/api/v1/entity', { entityId: entityId });
|
|
13
13
|
};
|
|
14
|
-
setUser = async (user) => {
|
|
14
|
+
setUser = async (context, user) => {
|
|
15
15
|
return this.sendPostRequest('/api/v1/user', user);
|
|
16
16
|
};
|
|
17
|
-
deleteUser = async (userId) => {
|
|
18
|
-
return this.sendDeleteRequest('/api/v1/user', {
|
|
17
|
+
deleteUser = async (context, userId) => {
|
|
18
|
+
return this.sendDeleteRequest('/api/v1/user', { userId: userId });
|
|
19
19
|
};
|
|
20
|
-
setGroup = async (group) => {
|
|
20
|
+
setGroup = async (context, group) => {
|
|
21
21
|
return this.sendPostRequest('/api/v1/group', group);
|
|
22
22
|
};
|
|
23
|
-
deleteGroup = async (groupId) => {
|
|
24
|
-
return this.sendDeleteRequest('/api/v1/group', {
|
|
23
|
+
deleteGroup = async (context, groupId) => {
|
|
24
|
+
return this.sendDeleteRequest('/api/v1/group', { groupId: groupId });
|
|
25
|
+
};
|
|
26
|
+
fetchData = async (context, requestConfig, onResult) => {
|
|
27
|
+
const { path, method, remoteKey, headers } = requestConfig;
|
|
28
|
+
const res = await (0, api_1.invokeRemote)(remoteKey, {
|
|
29
|
+
path: path,
|
|
30
|
+
method: method,
|
|
31
|
+
headers: headers
|
|
32
|
+
});
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(`invokeRemote failed: ${res.status}`);
|
|
35
|
+
}
|
|
36
|
+
const data = await res.json();
|
|
37
|
+
await this.saveToStage(data);
|
|
38
|
+
await this.validateData(data);
|
|
39
|
+
onResult(data);
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
42
|
+
async saveToStage(data) {
|
|
43
|
+
}
|
|
44
|
+
async validateData(data) {
|
|
45
|
+
}
|
|
46
|
+
transformData = async (context, data, transformMethod) => {
|
|
47
|
+
return transformMethod(data);
|
|
25
48
|
};
|
|
26
49
|
async sendPostRequest(path, body) {
|
|
27
50
|
const response = await this.sendRequest(path, {
|
package/out/utils/types.d.ts
CHANGED
|
@@ -2,8 +2,20 @@ import { Result } from '@forge/api';
|
|
|
2
2
|
export declare type UserObject = {
|
|
3
3
|
accountId?: string;
|
|
4
4
|
id?: string;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
externalId: string;
|
|
6
|
+
userName?: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
nickname?: string;
|
|
9
|
+
name?: {
|
|
10
|
+
formatted: string;
|
|
11
|
+
familyName: string;
|
|
12
|
+
givenName: string;
|
|
13
|
+
};
|
|
14
|
+
photos?: string[];
|
|
15
|
+
emails?: {
|
|
16
|
+
value: string;
|
|
17
|
+
primary: boolean;
|
|
18
|
+
}[];
|
|
7
19
|
};
|
|
8
20
|
export declare type Thumbnail = {
|
|
9
21
|
externalUrl: string;
|
|
@@ -88,10 +100,6 @@ export declare type GroupObject = {
|
|
|
88
100
|
aliases?: string[];
|
|
89
101
|
nonEditableAliases?: string[];
|
|
90
102
|
};
|
|
91
|
-
export declare type DeleteContext = {
|
|
92
|
-
target: string;
|
|
93
|
-
token: string;
|
|
94
|
-
};
|
|
95
103
|
export declare type AssociationObject = {
|
|
96
104
|
associationType: string;
|
|
97
105
|
values: string[];
|
|
@@ -99,12 +107,36 @@ export declare type AssociationObject = {
|
|
|
99
107
|
export declare type Associations = {
|
|
100
108
|
set: AssociationObject[];
|
|
101
109
|
};
|
|
110
|
+
export declare type IngestionContext = {
|
|
111
|
+
id: string;
|
|
112
|
+
[key: string]: string;
|
|
113
|
+
};
|
|
114
|
+
export declare type ForgeExtendedContext = {
|
|
115
|
+
principal: {
|
|
116
|
+
accountId: string;
|
|
117
|
+
};
|
|
118
|
+
installContext: string;
|
|
119
|
+
workspaceId?: string;
|
|
120
|
+
license: {
|
|
121
|
+
isActive: boolean;
|
|
122
|
+
};
|
|
123
|
+
ingestionContext?: IngestionContext;
|
|
124
|
+
};
|
|
125
|
+
export declare type RequestConfig = {
|
|
126
|
+
path: string;
|
|
127
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
128
|
+
params?: Record<string, any>;
|
|
129
|
+
headers?: any;
|
|
130
|
+
remoteKey: string;
|
|
131
|
+
};
|
|
102
132
|
export interface TeamWorkGraph {
|
|
103
|
-
setEntity(entity: EntityPayload): Promise<Result>;
|
|
104
|
-
deleteEntity(
|
|
105
|
-
setUser(user: UserObject): Promise<Result>;
|
|
106
|
-
deleteUser(userId: string): Promise<Result>;
|
|
107
|
-
setGroup(group: GroupObject): Promise<Result>;
|
|
108
|
-
deleteGroup(groupId: string): Promise<Result>;
|
|
133
|
+
setEntity(context: ForgeExtendedContext, entity: EntityPayload): Promise<Result>;
|
|
134
|
+
deleteEntity(context: ForgeExtendedContext, entityId: string): Promise<Result>;
|
|
135
|
+
setUser(context: ForgeExtendedContext, user: UserObject): Promise<Result>;
|
|
136
|
+
deleteUser(context: ForgeExtendedContext, userId: string): Promise<Result>;
|
|
137
|
+
setGroup(context: ForgeExtendedContext, group: GroupObject): Promise<Result>;
|
|
138
|
+
deleteGroup(context: ForgeExtendedContext, groupId: string): Promise<Result>;
|
|
139
|
+
fetchData(context: ForgeExtendedContext, requestConfig: RequestConfig, onResult: Function): Promise<Result>;
|
|
140
|
+
transformData(context: ForgeExtendedContext, data: any, transformMethod: Function): Promise<any>;
|
|
109
141
|
}
|
|
110
142
|
//# sourceMappingURL=types.d.ts.map
|
package/out/utils/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGpC,oBAAY,UAAU,GAAG;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGpC,oBAAY,UAAU,GAAG;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE;QACL,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,KAAK,EA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