feat(notion): add auth and new DB items trigger
This commit is contained in:
14
packages/backend/src/apps/notion/common/add-auth-header.ts
Normal file
14
packages/backend/src/apps/notion/common/add-auth-header.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
if (requestConfig.additionalProperties?.skipAddingAuthHeader) return requestConfig;
|
||||
|
||||
if ($.auth.data?.accessToken) {
|
||||
const authorizationHeader = `Bearer ${$.auth.data.accessToken}`;
|
||||
requestConfig.headers.Authorization = authorizationHeader;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
@@ -0,0 +1,9 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addNotionVersionHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
requestConfig.headers['Notion-Version'] = '2022-06-28';
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addNotionVersionHeader;
|
17
packages/backend/src/apps/notion/common/get-current-user.ts
Normal file
17
packages/backend/src/apps/notion/common/get-current-user.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Owner = {
|
||||
user: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const userId = ($.auth.data.owner as Owner).user.id;
|
||||
const response = await $.http.get(`/v1/users/${userId}`);
|
||||
|
||||
const currentUser = response.data;
|
||||
return currentUser;
|
||||
};
|
||||
|
||||
export default getCurrentUser;
|
Reference in New Issue
Block a user