Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-mice-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@team-plain/typescript-sdk': minor
---

Adds getMyWorkspace to fetch the workspace of the authenticated API key
21 changes: 19 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import {
CustomerByIdDocument,
CustomerGroupByIdDocument,
type CustomerGroupMembershipPartsFragment,
type CustomerGroupPartsFragment, CustomerGroupsDocument,
type CustomerPartsFragment, CustomersDocument,
type CustomerGroupPartsFragment,
CustomerGroupsDocument,
type CustomerPartsFragment,
CustomersDocument,
type EmailPartsFragment,
type IssuePartsFragment,
MyWorkspaceDocument,
type PageInfo,
RemoveCustomerFromCustomerGroupsDocument,
ReplyToEmailDocument,
Expand All @@ -23,6 +26,7 @@ import {
UpsertCustomerDocument,
UpsertCustomTimelineEntryDocument,
type UpsertResult,
type WorkspacePartsFragment
} from './graphql/types';
import { request } from './request';
import type { Result } from './result';
Expand Down Expand Up @@ -293,4 +297,17 @@ export class PlainClient {
return nonNullable(q.createAttachmentUploadUrl.attachmentUploadUrl);
});
}

/**
* Fetch the workspace for the authenticated API key.
*/
async getMyWorkspace(): SDKResult<WorkspacePartsFragment> {
const res = await request(this.#ctx, {
query: MyWorkspaceDocument,
});

return unwrapData(res, (q) => {
return nonNullable(q.myWorkspace);
});
}
}
20 changes: 20 additions & 0 deletions src/graphql/fragments/workspaceParts.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fragment WorkspaceParts on Workspace {
__typename
id
name
publicName
isDemoWorkspace
createdBy {
...ActorParts
}
createdAt {
...DateTimeParts
}
updatedBy {
...ActorParts
}
updatedAt {
...DateTimeParts

}
}
5 changes: 5 additions & 0 deletions src/graphql/queries/myWorkspace.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query myWorkspace {
myWorkspace {
...WorkspaceParts
}
}
Loading