The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix sentry issue (#6719)
martmullf9af25b57e15
diff --git a/packages/twenty-front/src/App.tsx b/packages/twenty-front/src/App.tsxindex f3668ff0b2d..4f126700047 100644--- a/packages/twenty-front/src/App.tsx+++ b/packages/twenty-front/src/App.tsx@@ -3,7 +3,6 @@ import {createBrowserRouter,createRoutesFromElements,Outlet,- redirect,Route,RouterProvider,Routes,@@ -192,14 +191,12 @@ const createRouter = (path={SettingsPath.AccountsEmails}element={<SettingsAccountsEmails />}/>- <Route- path={SettingsPath.Billing}- element={<SettingsBilling />}- loader={() => {- if (!isBillingEnabled) return redirect(AppPath.Index);- return null;- }}- />+ {isBillingEnabled && (+ <Route+ path={SettingsPath.Billing}+ element={<SettingsBilling />}+ />+ )}<Routepath={SettingsPath.WorkspaceMembersPage}element={<SettingsWorkspaceMembers />}@@ -324,15 +321,19 @@ const createRouter = (export const App = () => {const billing = useRecoilValue(billingState);+ const isFreeAccessEnabled = useIsFeatureEnabled('IS_FREE_ACCESS_ENABLED');const isCRMMigrationEnabled = useIsFeatureEnabled('IS_CRM_MIGRATION_ENABLED');const isServerlessFunctionSettingsEnabled = useIsFeatureEnabled('IS_FUNCTION_SETTINGS_ENABLED',);+ const isBillingPageEnabled =+ billing?.isBillingEnabled && !isFreeAccessEnabled;+return (<RouterProviderrouter={createRouter(- billing?.isBillingEnabled,+ isBillingPageEnabled,isCRMMigrationEnabled,isServerlessFunctionSettingsEnabled,)}diff --git a/packages/twenty-front/src/generated/graphql.tsx b/packages/twenty-front/src/generated/graphql.tsxindex 45bff9ca173..d9823a7969d 100644--- a/packages/twenty-front/src/generated/graphql.tsx+++ b/packages/twenty-front/src/generated/graphql.tsx@@ -215,6 +215,15 @@ export type ExchangeAuthCode = {refreshToken: AuthToken;};+export type ExecuteServerlessFunctionInput = {+ /** Id of the serverless function to execute */+ id: Scalars['UUID'];+ /** Payload in JSON format */+ payload?: InputMaybe<Scalars['JSON']>;+ /** Version of the serverless function to execute */+ version?: Scalars['String'];+};+export type FeatureFlag = {__typename?: 'FeatureFlag';id: Scalars['UUID'];@@ -287,6 +296,13 @@ export type FullName = {lastName: Scalars['String'];};+export type GetServerlessFunctionSourceCodeInput = {+ /** The id of the function. */+ id: Scalars['ID'];+ /** The version of the function */+ version?: Scalars['String'];+};+export type InvalidatePassword = {__typename?: 'InvalidatePassword';/** Boolean that confirms query was dispatched */@@ -343,8 +359,9 @@ export type Mutation = {generateJWT: AuthTokens;generateTransientToken: TransientToken;impersonate: Verify;+ publishServerlessFunction: ServerlessFunction;renewToken: AuthTokens;- runWorkflowVersion: WorkflowTriggerResult;+ runWorkflowVersion: WorkflowRun;sendInviteLink: SendInviteLink;signUp: LoginToken;skipSyncEmailOnboardingStep: OnboardingStepSuccess;@@ -431,8 +448,7 @@ export type MutationExchangeAuthorizationCodeArgs = {export type MutationExecuteOneServerlessFunctionArgs = {- id: Scalars['UUID'];- payload?: InputMaybe<Scalars['JSON']>;+ input: ExecuteServerlessFunctionInput;};@@ -452,6 +468,11 @@ export type MutationImpersonateArgs = {};+export type MutationPublishServerlessFunctionArgs = {+ input: PublishServerlessFunctionInput;+};++export type MutationRenewTokenArgs = {appToken: Scalars['String'];};@@ -594,6 +615,11 @@ export type ProductPricesEntity = {totalNumberOfPrices: Scalars['Int'];};+export type PublishServerlessFunctionInput = {+ /** The id of the function. */+ id: Scalars['ID'];+};+export type Query = {__typename?: 'Query';billingPortalSession: SessionEntity;@@ -606,6 +632,7 @@ export type Query = {getAISQLQuery: AisqlQueryResult;getPostgresCredentials?: Maybe<PostgresCredentials>;getProductPrices: ProductPricesEntity;+ getServerlessFunctionSourceCode: Scalars['String'];getTimelineCalendarEventsFromCompanyId: TimelineCalendarEventsWithTotal;getTimelineCalendarEventsFromPersonId: TimelineCalendarEventsWithTotal;getTimelineThreadsFromCompanyId: TimelineThreadsWithTotal;@@ -649,6 +676,11 @@ export type QueryGetProductPricesArgs = {};+export type QueryGetServerlessFunctionSourceCodeArgs = {+ input: GetServerlessFunctionSourceCodeInput;+};++export type QueryGetTimelineCalendarEventsFromCompanyIdArgs = {companyId: Scalars['UUID'];page: Scalars['Int'];@@ -768,9 +800,9 @@ export type ServerlessFunction = {createdAt: Scalars['DateTime'];description?: Maybe<Scalars['String']>;id: Scalars['UUID'];+ latestVersion?: Maybe<Scalars['String']>;name: Scalars['String'];runtime: Scalars['String'];- sourceCodeFullPath: Scalars['String'];sourceCodeHash: Scalars['String'];syncStatus: ServerlessFunctionSyncStatus;updatedAt: Scalars['DateTime'];@@ -1054,10 +1086,9 @@ export type Verify = {user: User;};-export type WorkflowTriggerResult = {- __typename?: 'WorkflowTriggerResult';- /** Execution result in JSON format */- result?: Maybe<Scalars['JSON']>;+export type WorkflowRun = {+ __typename?: 'WorkflowRun';+ workflowRunId: Scalars['UUID'];};export type Workspace = {diff --git a/packages/twenty-front/src/modules/settings/components/SettingsNavigationDrawerItems.tsx b/packages/twenty-front/src/modules/settings/components/SettingsNavigationDrawerItems.tsxindex f68981a195e..89bb9c0de21 100644--- a/packages/twenty-front/src/modules/settings/components/SettingsNavigationDrawerItems.tsx+++ b/packages/twenty-front/src/modules/settings/components/SettingsNavigationDrawerItems.tsx@@ -33,7 +33,10 @@ export const SettingsNavigationDrawerItems = () => {const isFunctionSettingsEnabled = useIsFeatureEnabled('IS_FUNCTION_SETTINGS_ENABLED',);+ const isFreeAccessEnabled = useIsFeatureEnabled('IS_FREE_ACCESS_ENABLED');const isCRMMigrationEnabled = useIsFeatureEnabled('IS_CRM_MIGRATION_ENABLED');+ const isBillingPageEnabled =+ billing?.isBillingEnabled && !isFreeAccessEnabled;return (<>@@ -84,7 +87,7 @@ export const SettingsNavigationDrawerItems = () => {path={SettingsPath.WorkspaceMembersPage}Icon={IconUsers}/>- {billing?.isBillingEnabled && (+ {isBillingPageEnabled && (<SettingsNavigationDrawerItemlabel="Billing"path={SettingsPath.Billing}diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/hooks/__tests__/useServerlessFunctionUpdateFormState.test.ts b/packages/twenty-front/src/modules/settings/serverless-functions/hooks/__tests__/useServerlessFunctionUpdateFormState.test.tsindex 1e60fa426a5..b8e6bd3b1dd 100644--- a/packages/twenty-front/src/modules/settings/serverless-functions/hooks/__tests__/useServerlessFunctionUpdateFormState.test.ts+++ b/packages/twenty-front/src/modules/settings/serverless-functions/hooks/__tests__/useServerlessFunctionUpdateFormState.test.ts@@ -24,7 +24,7 @@ describe('useServerlessFunctionUpdateFormState', () => {);useGetOneServerlessFunctionMock.useGetOneServerlessFunction.mockReturnValue({- serverlessFunction: { sourceCodeFullPath: undefined },+ serverlessFunction: { name: 'name' },},);const useGetOneServerlessFunctionSourceCodeMock = jest.requireMock(diff --git a/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts b/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.tsindex 1185aa04f0c..6ed0dd7f1e0 100644--- a/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts+++ b/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts@@ -7,4 +7,5 @@ export type FeatureFlagKey =| 'IS_FUNCTION_SETTINGS_ENABLED'| 'IS_COPILOT_ENABLED'| 'IS_CRM_MIGRATION_ENABLED'+ | 'IS_FREE_ACCESS_ENABLED'| 'IS_MESSAGE_THREAD_SUBSCRIBER_ENABLED';diff --git a/packages/twenty-front/src/pages/settings/serverless-functions/__stories__/SettingsServerlessFunctionDetail.stories.tsx b/packages/twenty-front/src/pages/settings/serverless-functions/__stories__/SettingsServerlessFunctionDetail.stories.tsxindex 219f10e7319..8543e0376a6 100644--- a/packages/twenty-front/src/pages/settings/serverless-functions/__stories__/SettingsServerlessFunctionDetail.stories.tsx+++ b/packages/twenty-front/src/pages/settings/serverless-functions/__stories__/SettingsServerlessFunctionDetail.stories.tsx@@ -38,7 +38,6 @@ const meta: Meta<PageDecoratorArgs> = {description: '',syncStatus: 'READY',runtime: 'nodejs18.x',- sourceCodeFullPath: SOURCE_CODE_FULL_PATH,sourceCodeHash: '42d2734b3dc8a7b45a16803ed7f417bc',updatedAt: '2024-02-24T10:23:10.673Z',createdAt: '2024-02-24T10:23:10.673Z',diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.tsindex a1bf997b8ca..a60992cc709 100644--- a/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts@@ -43,7 +43,7 @@ export class BillingResolver {@Args() { returnUrlPath }: BillingSessionInput,) {return {- url: await this.billingPortalWorkspaceService.computeBillingPortalSessionURL(+ url: await this.billingPortalWorkspaceService.computeBillingPortalSessionURLOrThrow(user.defaultWorkspaceId,returnUrlPath,),diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-portal.workspace-service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-portal.workspace-service.tsindex ca4685f07e3..d4a7a333f39 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-portal.workspace-service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-portal.workspace-service.ts@@ -65,18 +65,22 @@ export class BillingPortalWorkspaceService {return session.url;}- async computeBillingPortalSessionURL(+ async computeBillingPortalSessionURLOrThrow(workspaceId: string,returnUrlPath?: string,) {- const currentSubscriptionItem =+ const currentSubscription =await this.billingSubscriptionService.getCurrentBillingSubscriptionOrThrow({workspaceId,},);- const stripeCustomerId = currentSubscriptionItem.stripeCustomerId;+ if (!currentSubscription) {+ throw new Error('Error: missing subscription');+ }++ const stripeCustomerId = currentSubscription.stripeCustomerId;if (!stripeCustomerId) {throw new Error('Error: missing stripeCustomerId');