diff --git a/.cursorrules b/.cursorrules deleted file mode 100644 index 37f139dc0..000000000 --- a/.cursorrules +++ /dev/null @@ -1,3 +0,0 @@ -when importing db, or client, it should look like this: - -import { db } from "@/db/initDrizzle.js"; \ No newline at end of file diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 163988705..000000000 --- a/.editorconfig +++ /dev/null @@ -1,59 +0,0 @@ -[*] -cpp_indent_braces=false -cpp_indent_multi_line_relative_to=innermost_parenthesis -cpp_indent_within_parentheses=indent -cpp_indent_preserve_within_parentheses=false -cpp_indent_case_labels=false -cpp_indent_case_contents=true -cpp_indent_case_contents_when_block=false -cpp_indent_lambda_braces_when_parameter=true -cpp_indent_goto_labels=one_left -cpp_indent_preprocessor=leftmost_column -cpp_indent_access_specifiers=false -cpp_indent_namespace_contents=true -cpp_indent_preserve_comments=false -cpp_new_line_before_open_brace_namespace=ignore -cpp_new_line_before_open_brace_type=ignore -cpp_new_line_before_open_brace_function=ignore -cpp_new_line_before_open_brace_block=ignore -cpp_new_line_before_open_brace_lambda=ignore -cpp_new_line_scope_braces_on_separate_lines=false -cpp_new_line_close_brace_same_line_empty_type=false -cpp_new_line_close_brace_same_line_empty_function=false -cpp_new_line_before_catch=true -cpp_new_line_before_else=true -cpp_new_line_before_while_in_do_while=false -cpp_space_before_function_open_parenthesis=remove -cpp_space_within_parameter_list_parentheses=false -cpp_space_between_empty_parameter_list_parentheses=false -cpp_space_after_keywords_in_control_flow_statements=true -cpp_space_within_control_flow_statement_parentheses=false -cpp_space_before_lambda_open_parenthesis=false -cpp_space_within_cast_parentheses=false -cpp_space_after_cast_close_parenthesis=false -cpp_space_within_expression_parentheses=false -cpp_space_before_block_open_brace=true -cpp_space_between_empty_braces=false -cpp_space_before_initializer_list_open_brace=false -cpp_space_within_initializer_list_braces=true -cpp_space_preserve_in_initializer_list=true -cpp_space_before_open_square_bracket=false -cpp_space_within_square_brackets=false -cpp_space_before_empty_square_brackets=false -cpp_space_between_empty_square_brackets=false -cpp_space_group_square_brackets=true -cpp_space_within_lambda_brackets=false -cpp_space_between_empty_lambda_brackets=false -cpp_space_before_comma=false -cpp_space_after_comma=true -cpp_space_remove_around_member_operators=true -cpp_space_before_inheritance_colon=true -cpp_space_before_constructor_colon=true -cpp_space_remove_before_semicolon=true -cpp_space_after_semicolon=false -cpp_space_remove_around_unary_operator=true -cpp_space_around_binary_operator=insert -cpp_space_around_assignment_operator=insert -cpp_space_pointer_reference_alignment=left -cpp_space_around_ternary_operator=insert -cpp_wrap_preserve_blocks=one_liners diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0adccd21f..55310744f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -414,13 +414,8 @@ importers: specifier: ^34.0.1 version: 34.0.2(react-dom@18.2.0(react@18.2.0))(react@18.2.0) autumn-js: -<<<<<<< HEAD - specifier: ^0.0.77 - version: 0.0.77(react@18.2.0) -======= specifier: ^0.0.93 - version: 0.0.93(better-auth@1.2.9)(react@18.3.1) ->>>>>>> main + version: 0.0.93(better-auth@1.2.9)(better-call@1.0.12)(react@18.2.0) axios: specifier: ^1.8.3 version: 1.8.3 @@ -11718,14 +11713,6 @@ snapshots: attr-accept@2.2.5: {} - autumn-js@0.0.77(react@18.2.0): - dependencies: - chalk: 5.4.1 - rou3: 0.6.3 - swr: 2.3.4(react@18.2.0) - optionalDependencies: - react: 18.2.0 - autumn-js@0.0.77(react@18.3.1): dependencies: chalk: 5.4.1 @@ -11734,15 +11721,16 @@ snapshots: optionalDependencies: react: 18.3.1 - autumn-js@0.0.93(better-auth@1.2.9)(react@18.3.1): + autumn-js@0.0.93(better-auth@1.2.9)(better-call@1.0.12)(react@18.2.0): dependencies: chalk: 5.4.1 rou3: 0.6.3 - swr: 2.3.3(react@18.3.1) - zod: 3.25.64 + swr: 2.3.4(react@18.2.0) + zod: 3.25.76 optionalDependencies: better-auth: 1.2.9 - react: 18.3.1 + better-call: 1.0.12 + react: 18.2.0 axios@1.10.0: dependencies: diff --git a/server/src/external/autumn/autumnCli.ts b/server/src/external/autumn/autumnCli.ts index e633f8dca..44ef1de5b 100644 --- a/server/src/external/autumn/autumnCli.ts +++ b/server/src/external/autumn/autumnCli.ts @@ -18,7 +18,7 @@ import { TrackParams, UsageParams, } from "autumn-js"; -import { AttachBody } from "@/internal/customers/attach/models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; export default class AutumnError extends Error { message: string; @@ -104,14 +104,14 @@ export class AutumnInt { deleteInStripe = false, }: { deleteInStripe?: boolean; - } = {}, + } = {} ) { const response = await fetch( `${this.baseUrl}${path}?${deleteInStripe ? "delete_in_stripe=true" : ""}`, { method: "DELETE", headers: this.headers, - }, + } ); if (response.status != 200) { @@ -216,7 +216,7 @@ export class AutumnInt { customerId: string, params?: { expand?: CusExpand[]; - }, + } ): Promise< Customer & { invoices: any[]; @@ -233,7 +233,7 @@ export class AutumnInt { } const data = await this.get( - `/customers/${customerId}?${queryParams.toString()}`, + `/customers/${customerId}?${queryParams.toString()}` ); return data; }, @@ -248,7 +248,7 @@ export class AutumnInt { deleteInStripe = false, }: { deleteInStripe?: boolean; - } = {}, + } = {} ) => { const data = await this.delete(`/customers/${customerId}`, { deleteInStripe, @@ -260,19 +260,19 @@ export class AutumnInt { entities = { get: async (customerId: string, entityId: string) => { const data = await this.get( - `/customers/${customerId}/entities/${entityId}?expand=${EntityExpand.Invoices}`, + `/customers/${customerId}/entities/${entityId}?expand=${EntityExpand.Invoices}` ); return data; }, create: async ( customerId: string, - entity: CreateEntity | CreateEntity[], + entity: CreateEntity | CreateEntity[] ) => { // let entities = Array.isArray(entity) ? entity : [entity]; const data = await this.post( `/customers/${customerId}/entities?with_autumn_id=true`, - entity, + entity ); return data; @@ -285,7 +285,7 @@ export class AutumnInt { delete: async (customerId: string, entityId: string) => { const data = await this.delete( - `/customers/${customerId}/entities/${entityId}`, + `/customers/${customerId}/entities/${entityId}` ); return data; }, @@ -302,10 +302,10 @@ export class AutumnInt { get: async ( productId: string, - { v1Schema = false }: { v1Schema?: boolean } = {}, + { v1Schema = false }: { v1Schema?: boolean } = {} ) => { const data = await this.get( - `/products/${productId}?${v1Schema ? "schemaVersion=1" : ""}`, + `/products/${productId}?${v1Schema ? "schemaVersion=1" : ""}` ); return data; }, diff --git a/server/src/internal/api/entitled/handlers/getProductCheckPreview.ts b/server/src/internal/api/entitled/handlers/getProductCheckPreview.ts index 8cef2e152..fb53f4ff5 100644 --- a/server/src/internal/api/entitled/handlers/getProductCheckPreview.ts +++ b/server/src/internal/api/entitled/handlers/getProductCheckPreview.ts @@ -1,7 +1,7 @@ import { checkToAttachParams } from "@/internal/customers/attach/attachUtils/attachParams/checkToAttachParams.js"; import { FullCustomer, FullProduct } from "@autumn/shared"; import { ExtendedRequest } from "@/utils/models/Request.js"; -import { AttachBody } from "@/internal/customers/attach/models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { attachParamsToPreview } from "@/internal/customers/attach/handleAttachPreview/attachParamsToPreview.js"; import { diff --git a/server/src/internal/customers/attach/attachRouter.ts b/server/src/internal/customers/attach/attachRouter.ts index 968612d06..1451f796d 100644 --- a/server/src/internal/customers/attach/attachRouter.ts +++ b/server/src/internal/customers/attach/attachRouter.ts @@ -29,7 +29,7 @@ import { orgToVersion } from "@/utils/versionUtils.js"; import { handleAttachRaceCondition } from "@/external/redis/redisUtils.js"; import { routeHandler } from "@/utils/routerUtils.js"; import { ExtendedRequest, ExtendedResponse } from "@/utils/models/Request.js"; -import { AttachBodySchema } from "./models/AttachBody.js"; +import { AttachBodySchema } from "@autumn/shared"; import { processAttachBody } from "./attachUtils/attachParams/processAttachBody.js"; import { handleAttachPreview } from "./handleAttachPreview/handleAttachPreview.js"; import { handleAttach } from "./handleAttach.js"; @@ -113,7 +113,7 @@ export const handlePublicAttachErrors = async ({ // 1. If on paid plan, not allowed to switch product const curProductFree = isFreeProduct( - curCusProduct?.customer_prices.map((cp: any) => cp.price) || [], // if no current product... + curCusProduct?.customer_prices.map((cp: any) => cp.price) || [] // if no current product... ); if (!curProductFree) { @@ -171,7 +171,7 @@ export const checkStripeConnections = async ({ env, product, logger, - }), + }) ); } await Promise.all(batchProductUpdates); @@ -205,7 +205,7 @@ export const createStripePrices = async ({ logger, internalEntityId: attachParams.internalEntityId, useCheckout, - }), + }) ); } await Promise.all(batchPriceUpdates); @@ -271,7 +271,7 @@ const handleAttachOld = async (req: any, res: any) => ? customer.entities.find( (e) => e.id === attachBody.entity_id || - e.internal_id === attachBody.entity_id, + e.internal_id === attachBody.entity_id )?.internal_id : undefined; diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getCusAndProducts.ts b/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getCusAndProducts.ts index a0a2ed180..4fd4c6fd5 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getCusAndProducts.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getCusAndProducts.ts @@ -5,7 +5,7 @@ import RecaseError from "@/utils/errorUtils.js"; import { notNullish } from "@/utils/genUtils.js"; import { ExtendedRequest } from "@/utils/models/Request.js"; import { ErrCode, CusProductStatus } from "@autumn/shared"; -import { AttachBody } from "../../../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; const getProductsForAttach = async ({ req, @@ -37,7 +37,7 @@ const getProductsForAttach = async ({ for (const prod of products) { let otherProd = products.find( - (p) => p.group === prod.group && !p.is_add_on && p.id !== prod.id, + (p) => p.group === prod.group && !p.is_add_on && p.id !== prod.id ); if (otherProd && !otherProd.is_add_on && !isOneOff(prod.prices)) { diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts b/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts index ad9c9ea1d..931056ad9 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/attachParamsUtils/getPricesAndEnts.ts @@ -19,7 +19,7 @@ import { Entitlement, CreateFreeTrial, } from "@autumn/shared"; -import { AttachBody } from "../../../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { mapOptionsList } from "../../mapOptionsList.js"; export const getPricesAndEnts = async ({ diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts b/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts index 334ad893a..ad1b16e3d 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/getAttachParams.ts @@ -1,5 +1,5 @@ import { ExtendedRequest } from "@/utils/models/Request.js"; -import { AttachBody } from "../../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { processAttachBody } from "./processAttachBody.js"; import { orgToVersion } from "@/utils/versionUtils.js"; import { APIVersion } from "@autumn/shared"; diff --git a/server/src/internal/customers/attach/attachUtils/attachParams/processAttachBody.ts b/server/src/internal/customers/attach/attachUtils/attachParams/processAttachBody.ts index bcaa60cac..b023d2104 100644 --- a/server/src/internal/customers/attach/attachUtils/attachParams/processAttachBody.ts +++ b/server/src/internal/customers/attach/attachUtils/attachParams/processAttachBody.ts @@ -1,5 +1,5 @@ import { ExtendedRequest } from "@/utils/models/Request.js"; -import { AttachBody } from "../../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { createStripeCli } from "@/external/stripe/utils.js"; import { getStripeCusData } from "./attachParamsUtils/getStripeCusData.js"; import { getPricesAndEnts } from "./attachParamsUtils/getPricesAndEnts.js"; diff --git a/server/src/internal/customers/attach/attachUtils/getAttachBranch.ts b/server/src/internal/customers/attach/attachUtils/getAttachBranch.ts index 5696e2e12..3d0134d15 100644 --- a/server/src/internal/customers/attach/attachUtils/getAttachBranch.ts +++ b/server/src/internal/customers/attach/attachUtils/getAttachBranch.ts @@ -1,6 +1,6 @@ import { ExtendedRequest } from "@/utils/models/Request.js"; -import { AttachBody } from "../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { AttachParams } from "../../cusProducts/AttachParams.js"; import { notNullish } from "@/utils/genUtils.js"; import { AttachBranch, AttachErrCode, BillingInterval } from "@autumn/shared"; @@ -91,7 +91,7 @@ const getOptionsToUpdate = ({ for (const newOptions of newOptionsList) { let internalFeatureId = newOptions.internal_feature_id; let existingOptions = oldOptionsList.find( - (o) => o.internal_feature_id === internalFeatureId, + (o) => o.internal_feature_id === internalFeatureId ); let price = findPrepaidPrice({ diff --git a/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts b/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts index 709724860..26543571b 100644 --- a/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts +++ b/server/src/internal/customers/attach/attachUtils/getAttachConfig.ts @@ -1,7 +1,7 @@ import { AttachParams } from "../../cusProducts/AttachParams.js"; import { AttachFlags } from "../models/AttachFlags.js"; import { AttachConfig, AttachBranch } from "@autumn/shared"; -import { AttachBody } from "../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { isFreeProduct } from "@/internal/products/productUtils.js"; import { nullish } from "@/utils/genUtils.js"; import { ProrationBehavior } from "@autumn/shared"; diff --git a/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts b/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts index d3883ee49..1272054b0 100644 --- a/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts +++ b/server/src/internal/customers/attach/attachUtils/getAttachFunction.ts @@ -12,7 +12,7 @@ import { import { handleUpgradeDiffInterval } from "../attachFunctions/upgradeDiffIntFlow/handleUpgradeDiffInt.js"; import { handleCreateCheckout } from "../../add-product/handleCreateCheckout.js"; import { handleAddProduct } from "../attachFunctions/addProductFlow/handleAddProduct.js"; -import { AttachBody } from "../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { AttachConfig } from "@autumn/shared"; import { handleScheduleFunction } from "../attachFunctions/scheduleFlow/handleScheduleFunction.js"; import { handleUpdateQuantityFunction } from "../attachFunctions/updateQuantityFlow/updateQuantityFlow.js"; @@ -136,7 +136,7 @@ export const runAttachFunction = async ({ logger.info(`--------------------------------`); logger.info( - `ATTACHING ${productIdsStr} to ${customer.name} (${customer.id || customer.email}), org: ${org.slug}\n`, + `ATTACHING ${productIdsStr} to ${customer.name} (${customer.id || customer.email}), org: ${org.slug}\n` ); if (customer.entity) { logger.info(`Entity: ${customer.entity.name} (${customer.entity.id})`); @@ -149,7 +149,7 @@ export const runAttachFunction = async ({ curSameProduct: curSameProduct?.product.id, curScheduledProduct: curScheduledProduct?.product.id, }, - }, + } ); // config.proration = ProrationBehavior.None; @@ -206,7 +206,7 @@ export const runAttachFunction = async ({ product_ids: attachParams.products.map((p) => p.id), code: SuccessCode.RenewedProduct, message: `Successfully renewed product ${attachParams.products[0].id}`, - }), + }) ); return; } diff --git a/server/src/internal/customers/attach/attachUtils/handleAttachErrors.ts b/server/src/internal/customers/attach/attachUtils/handleAttachErrors.ts index 82751e93d..7c61ae6af 100644 --- a/server/src/internal/customers/attach/attachUtils/handleAttachErrors.ts +++ b/server/src/internal/customers/attach/attachUtils/handleAttachErrors.ts @@ -3,7 +3,7 @@ import { ErrCode } from "@/errors/errCodes.js"; import { StatusCodes } from "http-status-codes"; import { AttachParams } from "../../cusProducts/AttachParams.js"; import { AttachBranch, AttachErrCode, UsagePriceConfig } from "@autumn/shared"; -import { AttachBody } from "../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { AttachConfig, AttachFlags } from "../models/AttachFlags.js"; import { getEntOptions, @@ -158,7 +158,7 @@ const handleUpdateQuantityErrors = async ({ const allowance = getResetBalance({ entitlement: curr.entitlement, options: cusProduct.options.find( - (o) => o.internal_feature_id == option.internal_feature_id, + (o) => o.internal_feature_id == option.internal_feature_id ), relatedPrice: price, }); diff --git a/server/src/internal/customers/attach/handleAttach.ts b/server/src/internal/customers/attach/handleAttach.ts index d61d760ac..6d77a3e9c 100644 --- a/server/src/internal/customers/attach/handleAttach.ts +++ b/server/src/internal/customers/attach/handleAttach.ts @@ -1,7 +1,7 @@ import { handleAttachRaceCondition } from "@/external/redis/redisUtils.js"; import { ExtendedRequest, ExtendedResponse } from "@/utils/models/Request.js"; import { routeHandler } from "@/utils/routerUtils.js"; -import { AttachBodySchema } from "./models/AttachBody.js"; +import { AttachBodySchema } from "@autumn/shared"; import { getAttachParams } from "./attachUtils/attachParams/getAttachParams.js"; import { getAttachBranch } from "./attachUtils/getAttachBranch.js"; import { getAttachConfig } from "./attachUtils/getAttachConfig.js"; diff --git a/server/src/internal/customers/attach/handleAttachPreview/attachParamsToPreview.ts b/server/src/internal/customers/attach/handleAttachPreview/attachParamsToPreview.ts index 9b1daf7c4..6117a5c29 100644 --- a/server/src/internal/customers/attach/handleAttachPreview/attachParamsToPreview.ts +++ b/server/src/internal/customers/attach/handleAttachPreview/attachParamsToPreview.ts @@ -1,6 +1,6 @@ import { ExtendedRequest } from "@/utils/models/Request.js"; import { AttachParams } from "../../cusProducts/AttachParams.js"; -import { AttachBody } from "../models/AttachBody.js"; +import { AttachBody } from "@autumn/shared"; import { getAttachBranch } from "../attachUtils/getAttachBranch.js"; import { getAttachConfig } from "../attachUtils/getAttachConfig.js"; import { AttachFunction } from "@autumn/shared"; diff --git a/server/src/internal/customers/attach/handleAttachPreview/handleAttachPreview.ts b/server/src/internal/customers/attach/handleAttachPreview/handleAttachPreview.ts index 21a43f043..f4f8ce823 100644 --- a/server/src/internal/customers/attach/handleAttachPreview/handleAttachPreview.ts +++ b/server/src/internal/customers/attach/handleAttachPreview/handleAttachPreview.ts @@ -1,7 +1,7 @@ import { routeHandler } from "@/utils/routerUtils.js"; import { getAttachParams } from "../attachUtils/attachParams/getAttachParams.js"; -import { AttachBodySchema } from "../models/AttachBody.js"; +import { AttachBodySchema } from "@autumn/shared"; import { ExtendedResponse } from "@/utils/models/Request.js"; import { ExtendedRequest } from "@/utils/models/Request.js"; diff --git a/server/src/internal/customers/cusUtils/cusUtils.ts b/server/src/internal/customers/cusUtils/cusUtils.ts index 00dbc4840..120b0bede 100644 --- a/server/src/internal/customers/cusUtils/cusUtils.ts +++ b/server/src/internal/customers/cusUtils/cusUtils.ts @@ -59,25 +59,6 @@ export const updateCustomerDetails = async ({ return customer; }; -const CusProductResultSchema = CusProductSchema.extend({ - customer: CustomerSchema, - product: ProductSchema, -}); - -export const flipProductResults = ( - cusProducts: z.infer[], -) => { - const customers = []; - - for (const cusProduct of cusProducts) { - customers.push({ - ...cusProduct.customer, - customer_products: [cusProduct], - }); - } - return customers; -}; - export const getCusInvoices = async ({ db, internalCustomerId, @@ -106,7 +87,7 @@ export const getCusInvoices = async ({ invoice: i, withItems, features, - }), + }) ); return processedInvoices; @@ -140,7 +121,7 @@ export const getCusEntsInFeatures = async ({ if (internalFeatureIds) { cusEnts = cusEnts.filter((cusEnt) => - internalFeatureIds.includes(cusEnt.internal_feature_id), + internalFeatureIds.includes(cusEnt.internal_feature_id) ); } @@ -149,7 +130,7 @@ export const getCusEntsInFeatures = async ({ cusEnts = cusEnts.filter( (cusEnt) => nullish(cusEnt.customer_product.internal_entity_id) || - cusEnt.customer_product.internal_entity_id === entity.internal_id, + cusEnt.customer_product.internal_entity_id === entity.internal_id // || cusEnt.entities ); } diff --git a/server/tsconfig.build.json b/server/tsconfig.build.json index 2197394fa..a715cdcb8 100644 --- a/server/tsconfig.build.json +++ b/server/tsconfig.build.json @@ -17,6 +17,8 @@ "allowSyntheticDefaultImports": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, + "incremental": false, + "noEmitOnError": false, "paths": { "@/*": ["src/*"], "@emails/*": ["emails/*"] diff --git a/shared/index.ts b/shared/index.ts index 7bd98f261..c8b614fdd 100644 --- a/shared/index.ts +++ b/shared/index.ts @@ -131,6 +131,7 @@ export * from "./models/attachModels/attachPreviewModels.js"; export * from "./models/attachModels/attachEnums/AttachBranch.js"; export * from "./models/attachModels/attachEnums/AttachFunction.js"; export * from "./models/attachModels/attachEnums/AttachConfig.js"; +export * from "./models/attachModels/attachBody.js"; // Utils export * from "./utils/displayUtils.js"; diff --git a/server/src/internal/customers/attach/models/AttachBody.ts b/shared/models/attachModels/attachBody.ts similarity index 83% rename from server/src/internal/customers/attach/models/AttachBody.ts rename to shared/models/attachModels/attachBody.ts index a69e82bc7..1935f3b54 100644 --- a/server/src/internal/customers/attach/models/AttachBody.ts +++ b/shared/models/attachModels/attachBody.ts @@ -1,12 +1,8 @@ -import { notNullish } from "@/utils/genUtils.js"; -import { - CreateFreeTrialSchema, - FreeTrialSchema, - ProductItemSchema, -} from "@autumn/shared"; - -import { FeatureOptionsSchema } from "@autumn/shared"; import { z } from "zod"; +import { FeatureOptionsSchema } from "../cusProductModels/cusProductModels.js"; +import { ProductItemSchema } from "../productV2Models/productItemModels/productItemModels.js"; +import { CreateFreeTrialSchema } from "../productModels/freeTrialModels/freeTrialModels.js"; +import { notNullish } from "../../utils/utils.js"; export const AttachBodySchema = z .object({ @@ -58,7 +54,7 @@ export const AttachBodySchema = z }, { message: "`product_id` is not provided", - }, + } ) .refine( (data) => { @@ -70,7 +66,7 @@ export const AttachBodySchema = z }, { message: "provide either one `product_id` or `product_ids`", - }, + } ) .refine( (data) => { @@ -85,7 +81,7 @@ export const AttachBodySchema = z }, { message: "Can't pass in duplicate product_ids", - }, + } ) .refine( (data) => { @@ -97,7 +93,7 @@ export const AttachBodySchema = z }, { message: "Can't pass in product_ids if is_custom is true", - }, + } ) .refine( (data) => { @@ -109,20 +105,7 @@ export const AttachBodySchema = z }, { message: "Can't pass in items if is_custom is false", - }, + } ); -// .refine( -// (data) => { -// if (data.free_trial && !data.is_custom) { -// return false; -// } - -// return true; -// }, -// { -// message: "Can't pass in free_trial if is_custom is false", -// }, -// ); - export type AttachBody = z.infer; diff --git a/shared/utils/utils.ts b/shared/utils/utils.ts new file mode 100644 index 000000000..d954eec82 --- /dev/null +++ b/shared/utils/utils.ts @@ -0,0 +1 @@ +export const notNullish = (value: any) => value !== null && value !== undefined; diff --git a/vite/src/components/ui/chart.tsx b/vite/src/components/ui/chart.tsx deleted file mode 100644 index e4589f04f..000000000 --- a/vite/src/components/ui/chart.tsx +++ /dev/null @@ -1,351 +0,0 @@ -import * as React from "react" -import * as RechartsPrimitive from "recharts" - -import { cn } from "@/lib/utils" - -// Format: { THEME_NAME: CSS_SELECTOR } -const THEMES = { light: "", dark: ".dark" } as const - -export type ChartConfig = { - [k in string]: { - label?: React.ReactNode - icon?: React.ComponentType - } & ( - | { color?: string; theme?: never } - | { color?: never; theme: Record } - ) -} - -type ChartContextProps = { - config: ChartConfig -} - -const ChartContext = React.createContext(null) - -function useChart() { - const context = React.useContext(ChartContext) - - if (!context) { - throw new Error("useChart must be used within a ") - } - - return context -} - -function ChartContainer({ - id, - className, - children, - config, - ...props -}: React.ComponentProps<"div"> & { - config: ChartConfig - children: React.ComponentProps< - typeof RechartsPrimitive.ResponsiveContainer - >["children"] -}) { - const uniqueId = React.useId() - const chartId = `chart-${id || uniqueId.replace(/:/g, "")}` - - return ( - -
- - - {children} - -
-
- ) -} - -const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => { - const colorConfig = Object.entries(config).filter( - ([, config]) => config.theme || config.color - ) - - if (!colorConfig.length) { - return null - } - - return ( -