mirror of
https://github.com/documenso/documenso.git
synced 2026-07-27 02:15:05 +10:00
fix: lint project (#2693)
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import { CreateEmailIdentityCommand, SESv2Client } from '@aws-sdk/client-sesv2';
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
import { generateKeyPair } from 'crypto';
|
||||
import { promisify } from 'util';
|
||||
|
||||
import { DOCUMENSO_ENCRYPTION_KEY } from '@documenso/lib/constants/crypto';
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { symmetricEncrypt } from '@documenso/lib/universal/crypto';
|
||||
@@ -10,6 +6,9 @@ import { generateDatabaseId } from '@documenso/lib/universal/id';
|
||||
import { generateEmailDomainRecords } from '@documenso/lib/utils/email-domains';
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
import { generateKeyPair } from 'crypto';
|
||||
import { promisify } from 'util';
|
||||
|
||||
export const getSesClient = () => {
|
||||
const accessKeyId = env('NEXT_PRIVATE_SES_ACCESS_KEY_ID');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { UserSecurityAuditLogType } from '@prisma/client';
|
||||
|
||||
import { getOrganisationAuthenticationPortalOptions } from '@documenso/auth/server/lib/utils/organisation-portal';
|
||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||
import {
|
||||
@@ -11,16 +9,14 @@ import { addUserToOrganisation } from '@documenso/lib/server-only/organisation/a
|
||||
import { ZOrganisationAccountLinkMetadataSchema } from '@documenso/lib/types/organisation';
|
||||
import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { UserSecurityAuditLogType } from '@prisma/client';
|
||||
|
||||
export interface LinkOrganisationAccountOptions {
|
||||
token: string;
|
||||
requestMeta: RequestMetadata;
|
||||
}
|
||||
|
||||
export const linkOrganisationAccount = async ({
|
||||
token,
|
||||
requestMeta,
|
||||
}: LinkOrganisationAccountOptions) => {
|
||||
export const linkOrganisationAccount = async ({ token, requestMeta }: LinkOrganisationAccountOptions) => {
|
||||
if (!IS_BILLING_ENABLED()) {
|
||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
message: 'Billing is not enabled',
|
||||
@@ -65,9 +61,7 @@ export const linkOrganisationAccount = async ({
|
||||
});
|
||||
}
|
||||
|
||||
const tokenMetadata = ZOrganisationAccountLinkMetadataSchema.safeParse(
|
||||
verificationToken.metadata,
|
||||
);
|
||||
const tokenMetadata = ZOrganisationAccountLinkMetadataSchema.safeParse(verificationToken.metadata);
|
||||
|
||||
if (!tokenMetadata.success) {
|
||||
console.error('Invalid token metadata', tokenMetadata.error);
|
||||
@@ -94,9 +88,7 @@ export const linkOrganisationAccount = async ({
|
||||
const oauthConfig = tokenMetadata.data.oauthConfig;
|
||||
|
||||
const userAlreadyLinked = user.accounts.find(
|
||||
(account) =>
|
||||
account.provider === clientOptions.id &&
|
||||
account.providerAccountId === oauthConfig.providerAccountId,
|
||||
(account) => account.provider === clientOptions.id && account.providerAccountId === oauthConfig.providerAccountId,
|
||||
);
|
||||
|
||||
if (organisationMember && userAlreadyLinked) {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { DeleteEmailIdentityCommand } from '@aws-sdk/client-sesv2';
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
|
||||
import { DOCUMENSO_ENCRYPTION_KEY } from '@documenso/lib/constants/crypto';
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { symmetricDecrypt } from '@documenso/lib/universal/crypto';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
|
||||
import { getSesClient, verifyDomainWithDKIM } from './create-email-domain';
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import { createElement } from 'react';
|
||||
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import crypto from 'crypto';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { mailer } from '@documenso/email/mailer';
|
||||
import { OrganisationAccountLinkConfirmationTemplate } from '@documenso/email/templates/organisation-account-link-confirmation';
|
||||
import { getI18nInstance } from '@documenso/lib/client-only/providers/i18n-server';
|
||||
@@ -15,6 +9,10 @@ import { getEmailContext } from '@documenso/lib/server-only/email/get-email-cont
|
||||
import type { TOrganisationAccountLinkMetadata } from '@documenso/lib/types/organisation';
|
||||
import { renderEmailWithI18N } from '@documenso/lib/utils/render-email-with-i18n';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import crypto from 'crypto';
|
||||
import { DateTime } from 'luxon';
|
||||
import { createElement } from 'react';
|
||||
|
||||
export type SendOrganisationAccountLinkConfirmationEmailProps = TOrganisationAccountLinkMetadata & {
|
||||
organisationName: string;
|
||||
@@ -109,10 +107,7 @@ export const sendOrganisationAccountLinkConfirmationEmail = async ({
|
||||
name: user.name || '',
|
||||
},
|
||||
from: DOCUMENSO_INTERNAL_EMAIL,
|
||||
subject:
|
||||
type === 'create'
|
||||
? i18n._(msg`Account creation request`)
|
||||
: i18n._(msg`Account linking request`),
|
||||
subject: type === 'create' ? i18n._(msg`Account creation request`) : i18n._(msg`Account linking request`),
|
||||
html,
|
||||
text,
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { GetEmailIdentityCommand } from '@aws-sdk/client-sesv2';
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
|
||||
import { getSesClient } from './create-email-domain';
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { ERROR_CODES } from './errors';
|
||||
import { getServerLimits } from './server';
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import { DocumentSource, EnvelopeType, SubscriptionStatus } from '@prisma/client';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||
import { INTERNAL_CLAIM_ID } from '@documenso/lib/types/subscription';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { DocumentSource, EnvelopeType, SubscriptionStatus } from '@prisma/client';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import {
|
||||
FREE_PLAN_LIMITS,
|
||||
INACTIVE_PLAN_LIMITS,
|
||||
PAID_PLAN_LIMITS,
|
||||
SELFHOSTED_PLAN_LIMITS,
|
||||
} from './constants';
|
||||
import { FREE_PLAN_LIMITS, INACTIVE_PLAN_LIMITS, PAID_PLAN_LIMITS, SELFHOSTED_PLAN_LIMITS } from './constants';
|
||||
import { ERROR_CODES } from './errors';
|
||||
import type { TLimitsResponseSchema } from './schema';
|
||||
|
||||
@@ -19,10 +13,7 @@ export type GetServerLimitsOptions = {
|
||||
teamId: number;
|
||||
};
|
||||
|
||||
export const getServerLimits = async ({
|
||||
userId,
|
||||
teamId,
|
||||
}: GetServerLimitsOptions): Promise<TLimitsResponseSchema> => {
|
||||
export const getServerLimits = async ({ userId, teamId }: GetServerLimitsOptions): Promise<TLimitsResponseSchema> => {
|
||||
const organisation = await prisma.organisation.findFirst({
|
||||
where: {
|
||||
teams: {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type Stripe from 'stripe';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { stripe } from '@documenso/lib/server-only/stripe';
|
||||
import type Stripe from 'stripe';
|
||||
|
||||
export type CreateCheckoutSessionOptions = {
|
||||
customerId: string;
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { stripe } from '@documenso/lib/server-only/stripe';
|
||||
import { INTERNAL_CLAIM_ID, type InternalClaim, internalClaims } from '@documenso/lib/types/subscription';
|
||||
import { toHumanPrice } from '@documenso/lib/universal/stripe/to-human-price';
|
||||
import { clone } from 'remeda';
|
||||
import type Stripe from 'stripe';
|
||||
|
||||
import { stripe } from '@documenso/lib/server-only/stripe';
|
||||
import {
|
||||
INTERNAL_CLAIM_ID,
|
||||
type InternalClaim,
|
||||
internalClaims,
|
||||
} from '@documenso/lib/types/subscription';
|
||||
import { toHumanPrice } from '@documenso/lib/universal/stripe/to-human-price';
|
||||
|
||||
export type InternalClaimPlans = {
|
||||
[key in INTERNAL_CLAIM_ID]: InternalClaim & {
|
||||
monthlyPrice?: Stripe.Price & {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { OrganisationClaim, Subscription } from '@prisma/client';
|
||||
import type Stripe from 'stripe';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { stripe } from '@documenso/lib/server-only/stripe';
|
||||
import { appLog } from '@documenso/lib/utils/debugger';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import type { OrganisationClaim, Subscription } from '@prisma/client';
|
||||
import type Stripe from 'stripe';
|
||||
|
||||
import { isPriceSeatsBased } from './is-price-seats-based';
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||
import type { Stripe } from '@documenso/lib/server-only/stripe';
|
||||
import { stripe } from '@documenso/lib/server-only/stripe';
|
||||
import { env } from '@documenso/lib/utils/env';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { onSubscriptionCreated } from './on-subscription-created';
|
||||
import { onSubscriptionDeleted } from './on-subscription-deleted';
|
||||
@@ -35,9 +34,7 @@ export const stripeWebhookHandler = async (req: Request): Promise<Response> => {
|
||||
}
|
||||
|
||||
const signature =
|
||||
typeof req.headers.get('stripe-signature') === 'string'
|
||||
? req.headers.get('stripe-signature')
|
||||
: '';
|
||||
typeof req.headers.get('stripe-signature') === 'string' ? req.headers.get('stripe-signature') : '';
|
||||
|
||||
if (!signature) {
|
||||
return Response.json(
|
||||
@@ -76,25 +73,22 @@ export const stripeWebhookHandler = async (req: Request): Promise<Response> => {
|
||||
|
||||
await onSubscriptionCreated({ subscription });
|
||||
|
||||
return Response.json(
|
||||
{ success: true, message: 'Webhook received' } satisfies StripeWebhookResponse,
|
||||
{ status: 200 },
|
||||
);
|
||||
return Response.json({ success: true, message: 'Webhook received' } satisfies StripeWebhookResponse, {
|
||||
status: 200,
|
||||
});
|
||||
})
|
||||
.with('customer.subscription.updated', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const subscription = event.data.object as Stripe.Subscription;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const previousAttributes = event.data
|
||||
.previous_attributes as Partial<Stripe.Subscription> | null;
|
||||
const previousAttributes = event.data.previous_attributes as Partial<Stripe.Subscription> | null;
|
||||
|
||||
await onSubscriptionUpdated({ subscription, previousAttributes });
|
||||
|
||||
return Response.json(
|
||||
{ success: true, message: 'Webhook received' } satisfies StripeWebhookResponse,
|
||||
{ status: 200 },
|
||||
);
|
||||
return Response.json({ success: true, message: 'Webhook received' } satisfies StripeWebhookResponse, {
|
||||
status: 200,
|
||||
});
|
||||
})
|
||||
.with('customer.subscription.deleted', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
import { OrganisationType, SubscriptionStatus } from '@prisma/client';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import {
|
||||
createOrganisation,
|
||||
createOrganisationClaimUpsertData,
|
||||
} from '@documenso/lib/server-only/organisation/create-organisation';
|
||||
import { type Stripe } from '@documenso/lib/server-only/stripe';
|
||||
import type {
|
||||
InternalClaim,
|
||||
StripeOrganisationCreateMetadata,
|
||||
} from '@documenso/lib/types/subscription';
|
||||
import {
|
||||
INTERNAL_CLAIM_ID,
|
||||
ZStripeOrganisationCreateMetadataSchema,
|
||||
} from '@documenso/lib/types/subscription';
|
||||
import type { Stripe } from '@documenso/lib/server-only/stripe';
|
||||
import type { InternalClaim, StripeOrganisationCreateMetadata } from '@documenso/lib/types/subscription';
|
||||
import { INTERNAL_CLAIM_ID, ZStripeOrganisationCreateMetadataSchema } from '@documenso/lib/types/subscription';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { OrganisationType, SubscriptionStatus } from '@prisma/client';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { extractStripeClaim } from './on-subscription-updated';
|
||||
|
||||
@@ -33,8 +26,7 @@ type StripeWebhookResponse = {
|
||||
* potentially created.
|
||||
*/
|
||||
export const onSubscriptionCreated = async ({ subscription }: OnSubscriptionCreatedOptions) => {
|
||||
const customerId =
|
||||
typeof subscription.customer === 'string' ? subscription.customer : subscription.customer.id;
|
||||
const customerId = typeof subscription.customer === 'string' ? subscription.customer : subscription.customer.id;
|
||||
|
||||
// Todo: logging
|
||||
if (subscription.items.data.length !== 1) {
|
||||
@@ -123,16 +115,10 @@ type HandleOrganisationCreateOptions = {
|
||||
/**
|
||||
* Handles the creation of an organisation.
|
||||
*/
|
||||
const handleOrganisationCreate = async ({
|
||||
customerId,
|
||||
claim,
|
||||
unknownCreateData,
|
||||
}: HandleOrganisationCreateOptions) => {
|
||||
const handleOrganisationCreate = async ({ customerId, claim, unknownCreateData }: HandleOrganisationCreateOptions) => {
|
||||
let organisationCreateFlowData: StripeOrganisationCreateMetadata | null = null;
|
||||
|
||||
const parseResult = ZStripeOrganisationCreateMetadataSchema.safeParse(
|
||||
JSON.parse(unknownCreateData),
|
||||
);
|
||||
const parseResult = ZStripeOrganisationCreateMetadataSchema.safeParse(JSON.parse(unknownCreateData));
|
||||
|
||||
if (!parseResult.success) {
|
||||
console.error('Invalid organisation create flow data');
|
||||
@@ -189,10 +175,7 @@ const handleOrganisationUpdate = async ({ customerId, claim }: HandleOrganisatio
|
||||
}
|
||||
|
||||
// Todo: logging
|
||||
if (
|
||||
organisation.subscription &&
|
||||
organisation.subscription.status !== SubscriptionStatus.INACTIVE
|
||||
) {
|
||||
if (organisation.subscription && organisation.subscription.status !== SubscriptionStatus.INACTIVE) {
|
||||
console.error('Organisation already has an active subscription');
|
||||
|
||||
// This should never happen
|
||||
@@ -208,10 +191,7 @@ const handleOrganisationUpdate = async ({ customerId, claim }: HandleOrganisatio
|
||||
let newOrganisationType: OrganisationType = OrganisationType.ORGANISATION;
|
||||
|
||||
// Keep the organisation as personal if the claim is for an individual.
|
||||
if (
|
||||
organisation.type === OrganisationType.PERSONAL &&
|
||||
claim.id === INTERNAL_CLAIM_ID.INDIVIDUAL
|
||||
) {
|
||||
if (organisation.type === OrganisationType.PERSONAL && claim.id === INTERNAL_CLAIM_ID.INDIVIDUAL) {
|
||||
newOrganisationType = OrganisationType.PERSONAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { SubscriptionStatus } from '@prisma/client';
|
||||
|
||||
import { createOrganisationClaimUpsertData } from '@documenso/lib/server-only/organisation/create-organisation';
|
||||
import type { Stripe } from '@documenso/lib/server-only/stripe';
|
||||
import { INTERNAL_CLAIM_ID, internalClaims } from '@documenso/lib/types/subscription';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { SubscriptionStatus } from '@prisma/client';
|
||||
|
||||
import { extractStripeClaimId } from './on-subscription-updated';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { OrganisationType, SubscriptionStatus } from '@prisma/client';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { createOrganisationClaimUpsertData } from '@documenso/lib/server-only/organisation/create-organisation';
|
||||
import { type Stripe, stripe } from '@documenso/lib/server-only/stripe';
|
||||
import { INTERNAL_CLAIM_ID } from '@documenso/lib/types/subscription';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { OrganisationType, SubscriptionStatus } from '@prisma/client';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
export type OnSubscriptionUpdatedOptions = {
|
||||
subscription: Stripe.Subscription;
|
||||
@@ -16,12 +15,8 @@ type StripeWebhookResponse = {
|
||||
message: string;
|
||||
};
|
||||
|
||||
export const onSubscriptionUpdated = async ({
|
||||
subscription,
|
||||
previousAttributes,
|
||||
}: OnSubscriptionUpdatedOptions) => {
|
||||
const customerId =
|
||||
typeof subscription.customer === 'string' ? subscription.customer : subscription.customer.id;
|
||||
export const onSubscriptionUpdated = async ({ subscription, previousAttributes }: OnSubscriptionUpdatedOptions) => {
|
||||
const customerId = typeof subscription.customer === 'string' ? subscription.customer : subscription.customer.id;
|
||||
|
||||
// Todo: logging
|
||||
if (subscription.items.data.length !== 1) {
|
||||
@@ -67,9 +62,7 @@ export const onSubscriptionUpdated = async ({
|
||||
const previousItem = previousAttributes?.items?.data[0];
|
||||
const updatedItem = subscription.items.data[0];
|
||||
|
||||
const previousSubscriptionClaimId = previousItem
|
||||
? await extractStripeClaimId(previousItem.price)
|
||||
: null;
|
||||
const previousSubscriptionClaimId = previousItem ? await extractStripeClaimId(previousItem.price) : null;
|
||||
const updatedSubscriptionClaim = await extractStripeClaim(updatedItem.price);
|
||||
|
||||
if (!updatedSubscriptionClaim) {
|
||||
|
||||
Reference in New Issue
Block a user