Skip to content

Commit

Permalink
Merge branch 'main' into zk-add-title-to-prospect
Browse files Browse the repository at this point in the history
  • Loading branch information
zkirby authored Aug 21, 2023
2 parents 825065b + e9d07c9 commit c348eee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/platforms/apollo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ const request = makeRequestFactory(async (auth, options) => {
});

export const client = {
auth: {
health: request(() => ({
url: `/auth/health`,
method: 'GET',
schema: z
.object({
is_logged_in: z.boolean().nullable(),
})
.partial(),
})),
},
users: {
search: request(
({
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/apollo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import searchUsers from './actions/users/search';
import searchLabels from './actions/labels/search';

import searchPeople from './actions/people/search';
import { permissions } from './permissions';

export * as types from './schemas';
export default platform('apollo', {
Expand All @@ -68,6 +69,7 @@ export default platform('apollo', {
},
constants,
client,
permissions,
actions: {
createAccount,
searchAccounts,
Expand Down
30 changes: 30 additions & 0 deletions src/platforms/apollo/permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { tryit } from 'radash';
import { PlatformPermissions } from '../../sdk';
import { client } from './client';

// NOTE: These will be used in the UI, so they should be user-friendly.
const INVALID_API_TOKEN_MESSAGE = 'Invalid API Token';

export const makePermissions = (): PlatformPermissions => {
return {
validate: async ({ auth }) => {
const [err, result] = await tryit(client.auth.health)(auth, {});
if (err || !result.data.is_logged_in) {
console.warn({
message: 'Failed to validate permissions for Apollo',
metadata: { error: err, result },
});
return {
valid: false,
errorMessage: INVALID_API_TOKEN_MESSAGE,
};
}
return {
valid: true,
errorMessage: null,
};
},
};
};

export const permissions = makePermissions();

0 comments on commit c348eee

Please sign in to comment.