@forge/teamwork-graph 2.0.0 → 2.1.0-next.0-experimental-ab129b0
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 +289 -174
- package/out/__test__/entity-operations.test.js +468 -420
- package/out/__test__/error-handling.test.js +9 -9
- package/out/__test__/validators.test.js +43 -43
- package/out/graph.d.ts +5 -5
- package/out/graph.d.ts.map +1 -1
- package/out/graph.js +19 -19
- package/out/types/graph.d.ts +5 -5
- package/out/types/graph.d.ts.map +1 -1
- package/out/types/index.d.ts +2 -2
- package/out/types/index.d.ts.map +1 -1
- package/out/types/index.js +2 -2
- package/out/types/objects/branch.d.ts +14 -0
- package/out/types/objects/branch.d.ts.map +1 -0
- package/out/types/{entities → objects}/build.d.ts +3 -3
- package/out/types/objects/build.d.ts.map +1 -0
- package/out/types/{entities → objects}/calendar-event.d.ts +3 -3
- package/out/types/objects/calendar-event.d.ts.map +1 -0
- package/out/types/{entities → objects}/comment.d.ts +4 -4
- package/out/types/objects/comment.d.ts.map +1 -0
- package/out/types/{entities → objects}/commit.d.ts +3 -3
- package/out/types/objects/commit.d.ts.map +1 -0
- package/out/types/{common.d.ts → objects/common.d.ts} +7 -10
- package/out/types/objects/common.d.ts.map +1 -0
- package/out/types/{entities → objects}/conversation.d.ts +3 -3
- package/out/types/objects/conversation.d.ts.map +1 -0
- package/out/types/{entities → objects}/customer-org.d.ts +3 -3
- package/out/types/objects/customer-org.d.ts.map +1 -0
- package/out/types/{entities → objects}/deal.d.ts +3 -3
- package/out/types/objects/deal.d.ts.map +1 -0
- package/out/types/{entities → objects}/deployment.d.ts +3 -3
- package/out/types/objects/deployment.d.ts.map +1 -0
- package/out/types/{entities → objects}/design.d.ts +3 -3
- package/out/types/objects/design.d.ts.map +1 -0
- package/out/types/{entities → objects}/document.d.ts +3 -3
- package/out/types/objects/document.d.ts.map +1 -0
- package/out/types/objects/index.d.ts +26 -0
- package/out/types/objects/index.d.ts.map +1 -0
- package/out/types/{entities → objects}/message.d.ts +3 -3
- package/out/types/objects/message.d.ts.map +1 -0
- package/out/types/objects/organisation.d.ts +9 -0
- package/out/types/objects/organisation.d.ts.map +1 -0
- package/out/types/{entities → objects}/position.d.ts +3 -3
- package/out/types/objects/position.d.ts.map +1 -0
- package/out/types/{entities → objects}/project.d.ts +4 -4
- package/out/types/objects/project.d.ts.map +1 -0
- package/out/types/{entities → objects}/pull-request.d.ts +3 -3
- package/out/types/objects/pull-request.d.ts.map +1 -0
- package/out/types/{entities → objects}/remote-link.d.ts +3 -3
- package/out/types/objects/remote-link.d.ts.map +1 -0
- package/out/types/{entities → objects}/repository.d.ts +3 -3
- package/out/types/objects/repository.d.ts.map +1 -0
- package/out/types/{entities → objects}/software-service.d.ts +3 -3
- package/out/types/objects/software-service.d.ts.map +1 -0
- package/out/types/{entities → objects}/space.d.ts +3 -3
- package/out/types/objects/space.d.ts.map +1 -0
- package/out/types/{entities → objects}/video.d.ts +3 -3
- package/out/types/objects/video.d.ts.map +1 -0
- package/out/types/{entities → objects}/work-item.d.ts +3 -3
- package/out/types/objects/work-item.d.ts.map +1 -0
- package/out/types/{entities → objects}/worker.d.ts +3 -3
- package/out/types/objects/worker.d.ts.map +1 -0
- package/out/types/requests.d.ts +15 -15
- package/out/types/requests.d.ts.map +1 -1
- package/out/utils/validators.d.ts +6 -6
- package/out/utils/validators.d.ts.map +1 -1
- package/out/utils/validators.js +16 -16
- package/package.json +2 -2
- package/out/types/common.d.ts.map +0 -1
- package/out/types/entities/branch.d.ts +0 -14
- package/out/types/entities/branch.d.ts.map +0 -1
- package/out/types/entities/build.d.ts.map +0 -1
- package/out/types/entities/calendar-event.d.ts.map +0 -1
- package/out/types/entities/comment.d.ts.map +0 -1
- package/out/types/entities/commit.d.ts.map +0 -1
- package/out/types/entities/conversation.d.ts.map +0 -1
- package/out/types/entities/customer-org.d.ts.map +0 -1
- package/out/types/entities/deal.d.ts.map +0 -1
- package/out/types/entities/deployment.d.ts.map +0 -1
- package/out/types/entities/design.d.ts.map +0 -1
- package/out/types/entities/document.d.ts.map +0 -1
- package/out/types/entities/index.d.ts +0 -26
- package/out/types/entities/index.d.ts.map +0 -1
- package/out/types/entities/message.d.ts.map +0 -1
- package/out/types/entities/organisation.d.ts +0 -9
- package/out/types/entities/organisation.d.ts.map +0 -1
- package/out/types/entities/position.d.ts.map +0 -1
- package/out/types/entities/project.d.ts.map +0 -1
- package/out/types/entities/pull-request.d.ts.map +0 -1
- package/out/types/entities/remote-link.d.ts.map +0 -1
- package/out/types/entities/repository.d.ts.map +0 -1
- package/out/types/entities/software-service.d.ts.map +0 -1
- package/out/types/entities/space.d.ts.map +0 -1
- package/out/types/entities/video.d.ts.map +0 -1
- package/out/types/entities/work-item.d.ts.map +0 -1
- package/out/types/entities/worker.d.ts.map +0 -1
- /package/out/types/{entities → objects}/branch.js +0 -0
- /package/out/types/{entities → objects}/build.js +0 -0
- /package/out/types/{entities → objects}/calendar-event.js +0 -0
- /package/out/types/{entities → objects}/comment.js +0 -0
- /package/out/types/{entities → objects}/commit.js +0 -0
- /package/out/types/{common.js → objects/common.js} +0 -0
- /package/out/types/{entities → objects}/conversation.js +0 -0
- /package/out/types/{entities → objects}/customer-org.js +0 -0
- /package/out/types/{entities → objects}/deal.js +0 -0
- /package/out/types/{entities → objects}/deployment.js +0 -0
- /package/out/types/{entities → objects}/design.js +0 -0
- /package/out/types/{entities → objects}/document.js +0 -0
- /package/out/types/{entities → objects}/index.js +0 -0
- /package/out/types/{entities → objects}/message.js +0 -0
- /package/out/types/{entities → objects}/organisation.js +0 -0
- /package/out/types/{entities → objects}/position.js +0 -0
- /package/out/types/{entities → objects}/project.js +0 -0
- /package/out/types/{entities → objects}/pull-request.js +0 -0
- /package/out/types/{entities → objects}/remote-link.js +0 -0
- /package/out/types/{entities → objects}/repository.js +0 -0
- /package/out/types/{entities → objects}/software-service.js +0 -0
- /package/out/types/{entities → objects}/space.js +0 -0
- /package/out/types/{entities → objects}/video.js +0 -0
- /package/out/types/{entities → objects}/work-item.js +0 -0
- /package/out/types/{entities → objects}/worker.js +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Forge Graph
|
|
1
|
+
# Forge Teamwork Graph SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript SDK for interacting with the Forge Teamwork Graph API, providing a clean interface for managing objects, users, groups, and data operations.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,243 +8,358 @@ A client for interacting with the Forge Graph API.
|
|
|
8
8
|
npm install @forge/teamwork-graph
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
### Document Entity
|
|
11
|
+
## Quick Start
|
|
14
12
|
|
|
15
13
|
```typescript
|
|
16
14
|
import { graph } from '@forge/teamwork-graph';
|
|
17
|
-
import type {
|
|
18
|
-
|
|
15
|
+
import type { DocumentObject } from '@forge/teamwork-graph';
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// Create a document object
|
|
18
|
+
const document: DocumentObject = {
|
|
22
19
|
schemaVersion: '1.0',
|
|
23
20
|
id: 'doc-123',
|
|
24
21
|
updateSequenceNumber: Date.now(),
|
|
25
|
-
displayName: 'Project Requirements
|
|
22
|
+
displayName: 'Project Requirements',
|
|
26
23
|
url: 'https://example.com/docs/requirements',
|
|
27
|
-
|
|
28
|
-
// Optional base fields
|
|
29
24
|
description: 'Project requirements and specifications',
|
|
30
25
|
createdAt: new Date().toISOString(),
|
|
31
|
-
createdBy: {
|
|
32
|
-
accountId: 'acc-123',
|
|
33
|
-
email: 'creator@example.com'
|
|
34
|
-
},
|
|
35
26
|
lastUpdatedAt: new Date().toISOString(),
|
|
36
|
-
|
|
37
|
-
accountId: 'acc-456',
|
|
38
|
-
email: 'updater@example.com'
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
// Document ownership
|
|
42
|
-
owners: [
|
|
27
|
+
permissions: [
|
|
43
28
|
{
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
accessControls: [
|
|
30
|
+
{
|
|
31
|
+
principals: [
|
|
32
|
+
{
|
|
33
|
+
{ type: 'USER', id: 'user-123' }
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
]
|
|
46
38
|
}
|
|
47
39
|
],
|
|
40
|
+
'atlassian:document': {
|
|
41
|
+
type: {
|
|
42
|
+
category: 'document',
|
|
43
|
+
mimeType: 'text/plain'
|
|
44
|
+
},
|
|
45
|
+
content: {
|
|
46
|
+
mimeType: 'text/plain',
|
|
47
|
+
text: 'Document content...'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
thumbnail: {
|
|
51
|
-
externalUrl: 'https://example.com/thumbnail.png'
|
|
52
|
-
},
|
|
52
|
+
const result = await graph.setObjects({ objects: [document] });
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
type: 'atlassian:space',
|
|
63
|
-
value: {
|
|
64
|
-
entityId: 'space-123'
|
|
65
|
-
}
|
|
66
|
-
},
|
|
54
|
+
if (result.success) {
|
|
55
|
+
console.log('Document created successfully:', result.results);
|
|
56
|
+
} else {
|
|
57
|
+
console.error('Failed to create document:', result.error);
|
|
58
|
+
// Access the original error for debugging
|
|
59
|
+
console.error('Original error:', result.originalError);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
permissions: {
|
|
70
|
-
accessControls: [
|
|
71
|
-
{
|
|
72
|
-
principals: [
|
|
73
|
-
{ type: 'USER', id: 'user-123' },
|
|
74
|
-
{ type: 'GROUP', id: 'group-456' },
|
|
75
|
-
{ type: 'EVERYONE' }
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
smartLinkViewedBy: [
|
|
80
|
-
{
|
|
81
|
-
principalUser: {
|
|
82
|
-
type: 'USER',
|
|
83
|
-
id: 'user-789'
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
},
|
|
63
|
+
## Core Operations
|
|
88
64
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
values: ['PROJ-123', 'PROJ-456']
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
},
|
|
65
|
+
### Object Management
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { graph } from '@forge/teamwork-graph';
|
|
69
|
+
import type { DocumentObject } from '@forge/teamwork-graph';
|
|
98
70
|
|
|
99
|
-
|
|
71
|
+
// Bulk create/update objects
|
|
72
|
+
const document: DocumentObject = {
|
|
73
|
+
schemaVersion: '1.0',
|
|
74
|
+
id: 'doc-123',
|
|
75
|
+
updateSequenceNumber: Date.now(),
|
|
76
|
+
displayName: 'Project Requirements',
|
|
77
|
+
url: 'https://example.com/docs/requirements',
|
|
78
|
+
createdAt: new Date().toISOString(),
|
|
79
|
+
lastUpdatedAt: new Date().toISOString(),
|
|
80
|
+
permissions: [
|
|
81
|
+
{
|
|
82
|
+
accessControls: [
|
|
83
|
+
{
|
|
84
|
+
principals: [
|
|
85
|
+
{
|
|
86
|
+
{ type: 'USER', id: 'user-123' }
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
],
|
|
100
93
|
'atlassian:document': {
|
|
101
94
|
type: {
|
|
102
95
|
category: 'document',
|
|
103
|
-
mimeType: 'text/plain'
|
|
104
|
-
iconUrl: 'https://example.com/icon.png',
|
|
105
|
-
fileExtension: 'txt'
|
|
96
|
+
mimeType: 'text/plain'
|
|
106
97
|
},
|
|
107
98
|
content: {
|
|
108
99
|
mimeType: 'text/plain',
|
|
109
|
-
text: 'Document content...'
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
byteSize: 1234,
|
|
113
|
-
exportLinks: [
|
|
114
|
-
{
|
|
115
|
-
mimeType: 'application/pdf',
|
|
116
|
-
url: 'https://example.com/export/pdf'
|
|
117
|
-
}
|
|
118
|
-
],
|
|
119
|
-
collaborators: [
|
|
120
|
-
{ email: 'collaborator1@example.com' },
|
|
121
|
-
{ email: 'collaborator2@example.com' }
|
|
122
|
-
]
|
|
100
|
+
text: 'Document content...'
|
|
101
|
+
}
|
|
123
102
|
}
|
|
124
103
|
};
|
|
125
104
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
105
|
+
const bulkResult = await graph.setObjects({
|
|
106
|
+
objects: [document]
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Get object by external ID
|
|
110
|
+
const objectResult = await graph.getObjectByExternalId({
|
|
111
|
+
objectType: 'atlassian:document',
|
|
112
|
+
externalId: 'doc-123'
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (objectResult.success) {
|
|
116
|
+
console.log('Object found:', objectResult.object);
|
|
117
|
+
} else {
|
|
118
|
+
console.error('Object not found:', objectResult.error);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Delete objects by external IDs
|
|
122
|
+
const deleteResult = await graph.deleteObjectsByExternalId({
|
|
123
|
+
objectType: 'atlassian:document',
|
|
124
|
+
externalIds: ['doc-123', 'doc-456']
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Delete objects by properties
|
|
128
|
+
const deleteByPropsResult = await graph.deleteObjectsByProperties({
|
|
129
|
+
environment: 'staging',
|
|
130
|
+
status: 'completed'
|
|
131
|
+
});
|
|
129
132
|
```
|
|
130
133
|
|
|
131
|
-
###
|
|
134
|
+
### User Management
|
|
132
135
|
|
|
133
136
|
```typescript
|
|
137
|
+
import { graph } from '@forge/teamwork-graph';
|
|
138
|
+
|
|
139
|
+
// Bulk create/update users
|
|
140
|
+
const usersResult = await graph.setUsers({
|
|
141
|
+
users: [
|
|
142
|
+
{
|
|
143
|
+
externalId: 'user-123',
|
|
144
|
+
displayName: 'John Doe',
|
|
145
|
+
userName: 'johndoe',
|
|
146
|
+
name: {
|
|
147
|
+
formatted: 'John Doe',
|
|
148
|
+
familyName: 'Doe',
|
|
149
|
+
givenName: 'John'
|
|
150
|
+
},
|
|
151
|
+
emails: [
|
|
152
|
+
{ value: 'john@example.com', primary: true }
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
});
|
|
134
157
|
|
|
135
|
-
//
|
|
136
|
-
await graph.
|
|
158
|
+
// Get user by external ID
|
|
159
|
+
const userResult = await graph.getUserByExternalId({
|
|
160
|
+
externalId: 'user-123'
|
|
161
|
+
});
|
|
137
162
|
|
|
138
|
-
// Delete
|
|
139
|
-
await graph.
|
|
163
|
+
// Delete users by external IDs
|
|
164
|
+
const deleteUsersResult = await graph.deleteUsersByExternalId({
|
|
165
|
+
externalIds: ['user-123', 'user-456']
|
|
166
|
+
});
|
|
140
167
|
|
|
141
|
-
//
|
|
142
|
-
await graph.
|
|
168
|
+
// Map users to Atlassian accounts
|
|
169
|
+
const mapResult = await graph.mapUsers({
|
|
170
|
+
directMappings: [
|
|
171
|
+
{
|
|
172
|
+
externalId: 'user-123',
|
|
173
|
+
updateSequenceNumber: Date.now(),
|
|
174
|
+
updatedAt: Date.now(),
|
|
175
|
+
accountId: 'acc-123'
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
});
|
|
143
179
|
```
|
|
144
180
|
|
|
145
|
-
###
|
|
181
|
+
### Group Management
|
|
146
182
|
|
|
147
183
|
```typescript
|
|
184
|
+
import { graph } from '@forge/teamwork-graph';
|
|
148
185
|
|
|
149
|
-
//
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
186
|
+
// Bulk create/update groups
|
|
187
|
+
const groupsResult = await graph.setGroups({
|
|
188
|
+
groups: [
|
|
189
|
+
{
|
|
190
|
+
externalId: 'group-123',
|
|
191
|
+
displayName: 'Developers',
|
|
192
|
+
description: 'Development team'
|
|
193
|
+
}
|
|
157
194
|
]
|
|
158
195
|
});
|
|
159
196
|
|
|
160
|
-
//
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
197
|
+
// Get group by external ID
|
|
198
|
+
const groupResult = await graph.getGroupByExternalId({
|
|
199
|
+
externalId: 'group-123'
|
|
200
|
+
});
|
|
165
201
|
|
|
166
|
-
//
|
|
167
|
-
await graph.
|
|
202
|
+
// Delete groups by external IDs
|
|
203
|
+
const deleteGroupsResult = await graph.deleteGroupsByExternalId({
|
|
204
|
+
externalIds: ['group-123', 'group-456']
|
|
205
|
+
});
|
|
168
206
|
```
|
|
169
207
|
|
|
170
|
-
###
|
|
208
|
+
### Data Operations
|
|
171
209
|
|
|
172
210
|
```typescript
|
|
211
|
+
import { graph } from '@forge/teamwork-graph';
|
|
173
212
|
|
|
174
|
-
//
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
displayName: issue.summary,
|
|
187
|
-
type: 'issue',
|
|
188
|
-
assignee: issue.assignee.key
|
|
189
|
-
}));
|
|
190
|
-
};
|
|
213
|
+
// Fetch external data
|
|
214
|
+
const fetchResult = await graph.fetchData({
|
|
215
|
+
requestConfig: {
|
|
216
|
+
url: 'https://api.example.com/data',
|
|
217
|
+
method: 'GET',
|
|
218
|
+
headers: { 'Authorization': 'Bearer token' }
|
|
219
|
+
},
|
|
220
|
+
onResult: (data) => {
|
|
221
|
+
console.log('Data received:', data);
|
|
222
|
+
return data;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
191
225
|
|
|
192
|
-
// Transform
|
|
193
|
-
const
|
|
226
|
+
// Transform data
|
|
227
|
+
const transformResult = await graph.transformData({
|
|
228
|
+
data: { items: [{ id: 1, name: 'Item 1' }] },
|
|
229
|
+
transformMethod: (data) => {
|
|
230
|
+
return data.items.map(item => ({
|
|
231
|
+
id: `doc-${item.id}`,
|
|
232
|
+
displayName: item.name,
|
|
233
|
+
// Additional object properties would be added here
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
});
|
|
194
237
|
```
|
|
195
238
|
|
|
196
239
|
## Error Handling
|
|
197
240
|
|
|
198
|
-
The
|
|
241
|
+
The SDK provides comprehensive error handling with consistent error responses and access to original error objects for debugging.
|
|
242
|
+
|
|
243
|
+
### Error Response Structure
|
|
244
|
+
|
|
245
|
+
All operations return a response with this structure:
|
|
199
246
|
|
|
200
247
|
```typescript
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
248
|
+
interface BaseResponse {
|
|
249
|
+
success: boolean;
|
|
250
|
+
error?: string;
|
|
251
|
+
originalError?: unknown;
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Error Types
|
|
256
|
+
|
|
257
|
+
The SDK uses specific error classes for different types of failures:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
// Note: Error classes are not exported from the main package
|
|
261
|
+
// They are used internally by the SDK for error handling
|
|
262
|
+
|
|
263
|
+
// The SDK handles errors internally and returns them in the response
|
|
264
|
+
// You can access error information through the response object:
|
|
265
|
+
|
|
266
|
+
const result = await graph.setObjects({ objects: [] });
|
|
267
|
+
|
|
268
|
+
if (!result.success) {
|
|
269
|
+
console.error('Operation failed:', result.error);
|
|
270
|
+
|
|
271
|
+
// Access original error for debugging
|
|
272
|
+
if (result.originalError) {
|
|
273
|
+
console.error('Original error:', result.originalError);
|
|
215
274
|
}
|
|
216
275
|
}
|
|
217
276
|
```
|
|
218
277
|
|
|
219
|
-
|
|
278
|
+
### Error Handling Examples
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
// Handle object operations
|
|
282
|
+
const result = await graph.getObjectByExternalId({
|
|
283
|
+
objectType: 'atlassian:document',
|
|
284
|
+
externalId: 'nonexistent'
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
if (!result.success) {
|
|
288
|
+
console.error('Operation failed:', result.error);
|
|
289
|
+
|
|
290
|
+
// Access original error for debugging
|
|
291
|
+
if (result.originalError) {
|
|
292
|
+
console.error('Original error details:', result.originalError);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Handle validation errors (these are returned in the response)
|
|
297
|
+
const result = await graph.setObjects({
|
|
298
|
+
objects: [] // Empty array will return error in response
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (!result.success) {
|
|
302
|
+
console.error('Validation failed:', result.error);
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## TypeScript Support
|
|
307
|
+
|
|
308
|
+
The SDK is fully typed with comprehensive TypeScript definitions:
|
|
220
309
|
|
|
221
310
|
```typescript
|
|
222
311
|
import type {
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// User
|
|
232
|
-
|
|
312
|
+
// Object types
|
|
313
|
+
Object,
|
|
314
|
+
DocumentObject,
|
|
315
|
+
SetObjectsRequest,
|
|
316
|
+
BulkObjectResponse,
|
|
317
|
+
GetObjectByExternalIdRequest,
|
|
318
|
+
GetObjectByExternalIdResponse,
|
|
319
|
+
|
|
320
|
+
// User types
|
|
321
|
+
User,
|
|
322
|
+
UserPayload,
|
|
323
|
+
BulkUsersRequest,
|
|
324
|
+
BulkUsersResponse,
|
|
325
|
+
GetUserByExternalIdRequest,
|
|
326
|
+
GetUserByExternalIdResponse,
|
|
327
|
+
MapUsersRequest,
|
|
328
|
+
MapUsersResponse,
|
|
329
|
+
|
|
330
|
+
// Group types
|
|
331
|
+
Group,
|
|
233
332
|
GroupPayload,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
Principal,
|
|
239
|
-
Thumbnail,
|
|
333
|
+
BulkGroupsRequest,
|
|
334
|
+
BulkGroupsResponse,
|
|
335
|
+
GetGroupByExternalIdRequest,
|
|
336
|
+
GetGroupByExternalIdResponse,
|
|
240
337
|
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
338
|
+
// Data operation types
|
|
339
|
+
FetchDataRequest,
|
|
340
|
+
FetchDataResponse,
|
|
341
|
+
TransformDataRequest,
|
|
342
|
+
TransformDataResponse,
|
|
246
343
|
|
|
247
|
-
//
|
|
248
|
-
|
|
344
|
+
// Common types
|
|
345
|
+
DeleteObjectsByExternalIdRequest,
|
|
346
|
+
DeleteObjectsByExternalIdResponse,
|
|
347
|
+
DeleteObjectsByPropertiesRequest,
|
|
348
|
+
DeleteObjectsByPropertiesResponse,
|
|
349
|
+
DeleteUsersByExternalIdRequest,
|
|
350
|
+
DeleteUsersByExternalIdResponse,
|
|
351
|
+
DeleteGroupsByExternalIdRequest,
|
|
352
|
+
DeleteGroupsByExternalIdResponse
|
|
249
353
|
} from '@forge/teamwork-graph';
|
|
250
354
|
```
|
|
355
|
+
|
|
356
|
+
## Configuration
|
|
357
|
+
|
|
358
|
+
The SDK automatically handles authentication and configuration through the Forge platform. No additional setup is required.
|
|
359
|
+
|
|
360
|
+
## Best Practices
|
|
361
|
+
|
|
362
|
+
1. **Always check success flag**: Verify `result.success` before accessing response data
|
|
363
|
+
2. **Handle errors gracefully**: Use the `error` field for user-facing messages and `originalError` for debugging
|
|
364
|
+
3. **Validate input**: The SDK will throw validation errors for invalid input, so handle them appropriately
|
|
365
|
+
5. **Monitor rate limits**: The SDK handles rate limiting automatically, but monitor for `429` errors
|