Skip to content

Commit 2974363

Browse files
authored
add getMyWorkspace (#44)
1 parent 7762a59 commit 2974363

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

.changeset/six-mice-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@team-plain/typescript-sdk': minor
3+
---
4+
5+
Adds getMyWorkspace to fetch the workspace of the authenticated API key

src/client.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import {
1111
CustomerByIdDocument,
1212
CustomerGroupByIdDocument,
1313
type CustomerGroupMembershipPartsFragment,
14-
type CustomerGroupPartsFragment, CustomerGroupsDocument,
15-
type CustomerPartsFragment, CustomersDocument,
14+
type CustomerGroupPartsFragment,
15+
CustomerGroupsDocument,
16+
type CustomerPartsFragment,
17+
CustomersDocument,
1618
type EmailPartsFragment,
1719
type IssuePartsFragment,
20+
MyWorkspaceDocument,
1821
type PageInfo,
1922
RemoveCustomerFromCustomerGroupsDocument,
2023
ReplyToEmailDocument,
@@ -23,6 +26,7 @@ import {
2326
UpsertCustomerDocument,
2427
UpsertCustomTimelineEntryDocument,
2528
type UpsertResult,
29+
type WorkspacePartsFragment
2630
} from './graphql/types';
2731
import { request } from './request';
2832
import type { Result } from './result';
@@ -293,4 +297,17 @@ export class PlainClient {
293297
return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl);
294298
});
295299
}
300+
301+
/**
302+
* Fetch the workspace for the authenticated API key.
303+
*/
304+
async getMyWorkspace(): SDKResult<WorkspacePartsFragment> {
305+
const res = await request(this.#ctx, {
306+
query: MyWorkspaceDocument,
307+
});
308+
309+
return unwrapData(res, (q) => {
310+
return nonNullable(q.myWorkspace);
311+
});
312+
}
296313
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fragment WorkspaceParts on Workspace {
2+
__typename
3+
id
4+
name
5+
publicName
6+
isDemoWorkspace
7+
createdBy {
8+
...ActorParts
9+
}
10+
createdAt {
11+
...DateTimeParts
12+
}
13+
updatedBy {
14+
...ActorParts
15+
}
16+
updatedAt {
17+
...DateTimeParts
18+
19+
}
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query myWorkspace {
2+
myWorkspace {
3+
...WorkspaceParts
4+
}
5+
}

0 commit comments

Comments
 (0)