From 596c065576cd35cb22faf1b4ef8f586a4447971e Mon Sep 17 00:00:00 2001
From: Gregor Schulz <gregor.schulz@holi.social>
Date: Thu, 21 Mar 2024 15:22:32 +0000
Subject: [PATCH] fix userId forwarding on production

---
 .envrc                  |  3 ---
 .husky/pre-commit       |  4 ----
 .pre-commit-config.yaml |  9 +++++++++
 CONTRIBUTING.md         |  7 ++++++-
 app/deps.ts             |  7 +++++--
 app/server.ts           | 32 +++++++++-----------------------
 app/test_helpers.ts     |  1 -
 7 files changed, 29 insertions(+), 34 deletions(-)
 delete mode 100755 .husky/pre-commit
 create mode 100644 .pre-commit-config.yaml

diff --git a/.envrc b/.envrc
index 4f0af3a..3b5bb14 100644
--- a/.envrc
+++ b/.envrc
@@ -7,6 +7,3 @@ fi
 
 # loads personal (secret) data from separate env file (not checked in)
 source_env_if_exists .envrc.local
-
-type yarn >/dev/null 2>&1 && PATH="$PATH:$(yarn global bin)"
-export PATH
\ No newline at end of file
diff --git a/.husky/pre-commit b/.husky/pre-commit
deleted file mode 100755
index c1d6996..0000000
--- a/.husky/pre-commit
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-. "$(dirname "$0")/_/husky.sh"
-
-gitleaks protect --staged -v -c ../.gitleaks.toml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..2f34ebc
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,9 @@
+repos:
+-   repo: local
+    hooks:
+    -   id: gitleaks
+        name: gitleaks
+        language: system
+        entry: gitleaks protect --staged -v -c ../.gitleaks.toml
+        pass_filenames: false
+        always_run: true
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 73c9f85..dd41d1f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -10,7 +10,12 @@ In this guide you will get an overview of the contribution workflow from opening
 
 ## New Contributor guide
 
-There's many ways you could contribute to holi. For all of them, you first need an account on our gitlab. Set one up [here](https://app.gitlab-pages.holi.team/users/sign_up), after which we will approve your account. You will get confirmation via E-Mail and can proceed with setting up your account by following the instructions in the E-Mail and in GitLab itself. 
+There's many ways you could contribute to holi. For all of them, you first need an account on our gitlab. Set one up
+[here](https://gitlab.holi.team/users/sign_up). Your account will then be confirmed by an administrator. This might take
+some time. Afterwards, you will receive an E-Mail welcoming you to our GitLab instance. Via a link in this mail, you can
+sign in and set up your account by following the instructions in the E-Mail and in GitLab itself.
+
+If you didn't receive a mail, make sure to check your spam folder before contacting us via support@holi.social.
 
 ### Finding and reporting bugs
 
diff --git a/app/deps.ts b/app/deps.ts
index 9ba1cb8..83b3e07 100644
--- a/app/deps.ts
+++ b/app/deps.ts
@@ -1,6 +1,9 @@
 export { serve } from "https://deno.land/std@0.155.0/http/server.ts";
-export { createSchema, createYoga } from "npm:graphql-yoga@5.1.0";
-export { useResponseCache } from "npm:@graphql-yoga/plugin-response-cache@3.2.0";
+export {
+  createSchema,
+  createYoga,
+  type YogaInitialContext,
+} from "npm:graphql-yoga@5.1.0";
 export { Parser } from "https://deno.land/x/html_parser@v0.1.3/src/mod.ts";
 export { ChannelTypeEnum, Novu } from "npm:@novu/node@0.22.0";
 export { GraphQLError } from "npm:graphql@16.8.1";
diff --git a/app/server.ts b/app/server.ts
index cc44e33..ccec357 100644
--- a/app/server.ts
+++ b/app/server.ts
@@ -3,7 +3,7 @@ import {
   createYoga,
   Novu,
   serve,
-  useResponseCache,
+  YogaInitialContext,
 } from "./deps.ts";
 import { logger } from "./logging.ts";
 import {
@@ -25,16 +25,9 @@ export interface ServerConfig {
   environment: string;
 }
 
-export type GraphQLContext = {
-  params?: {
-    extensions?: {
-      headers?: {
-        [key: string]: string;
-      };
-    };
-  };
-  userId?: string;
-};
+export type ServiceContext = {
+  userId: string;
+} & YogaInitialContext;
 
 const typeDefs = `
     enum Channel {
@@ -77,7 +70,7 @@ const createResolvers = (novu: Novu, config: ServerConfig) => {
         _parent: any,
         // deno-lint-ignore no-explicit-any
         _parameters: any,
-        context: GraphQLContext,
+        context: ServiceContext,
       ): Promise<PreferencesResponse> => {
         return config.fake
           ? Promise.resolve([])
@@ -89,7 +82,7 @@ const createResolvers = (novu: Novu, config: ServerConfig) => {
         // deno-lint-ignore no-explicit-any
         _parent: any,
         parameters: UpdatePreferencesParameters,
-        context: GraphQLContext,
+        context: ServiceContext,
       ): Promise<PreferencesResponse> =>
         config.fake ? Promise.resolve([]) : updatePreferences(
           novu,
@@ -104,23 +97,16 @@ export const createGraphQLServer = (
   novu: Novu,
   config: ServerConfig,
 ): GraphQLServer => {
-  const plugins = [
-    useResponseCache({
-      // cache by user id
-      session: (request: Request) => request.headers.get(HEADER_USER_ID),
-    }),
-  ];
   const resolvers = createResolvers(novu, config);
   return createYoga({
     schema: createSchema({ resolvers, typeDefs }),
     graphiql: config.environment === LOCAL_ENVIRONMENT,
-    plugins,
-    context: (context: GraphQLContext) => {
-      const headers = new Headers(context.params?.extensions?.headers);
+    context: (context: YogaInitialContext) => {
+      const headers = new Headers(context.request.headers);
       return {
         ...context,
         userId: headers.get(HEADER_USER_ID),
-      } as GraphQLContext;
+      } as ServiceContext;
     },
   });
 };
diff --git a/app/test_helpers.ts b/app/test_helpers.ts
index 2640116..bae4855 100644
--- a/app/test_helpers.ts
+++ b/app/test_helpers.ts
@@ -27,7 +27,6 @@ export const processGqlRequest = (
       operationName: null,
       variables: variables,
       query: query,
-      extensions: { headers },
     }),
   });
   return graphQLServer.handleRequest(request)
-- 
GitLab