Initial commit: backend, storefront, vendor-panel added

This commit is contained in:
2025-08-01 11:05:32 +08:00
commit 08174125d2
2958 changed files with 310810 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
{
"name": "@mercurjs/framework",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"!dist/**/__tests__",
"!dist/**/__mocks__",
"!dist/**/__fixtures__"
],
"engines": {
"node": ">=20"
},
"license": "MIT",
"scripts": {
"build": "rimraf dist && tsc --build",
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
},
"devDependencies": {
"@medusajs/framework": "2.8.6",
"@medusajs/test-utils": "2.8.6",
"@mikro-orm/cli": "6.4.3",
"@mikro-orm/core": "6.4.3",
"@mikro-orm/migrations": "6.4.3",
"@mikro-orm/postgresql": "6.4.3",
"@swc/core": "^1.7.28",
"@swc/jest": "^0.2.36",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"tsc-alias": "^1.8.6",
"typescript": "^5.6.2"
},
"peerDependencies": {
"@medusajs/framework": "2.8.6",
"@mikro-orm/core": "6.4.3",
"@mikro-orm/migrations": "6.4.3",
"@mikro-orm/postgresql": "6.4.3",
"awilix": "^8.0.1"
}
}

View File

@@ -0,0 +1,2 @@
export * from "./types";
export * from "./utils";

View File

@@ -0,0 +1,4 @@
import { AlgoliaProduct } from './algolia-product'
import { AlgoliaReview } from './algolia-review'
export type AlgoliaEntity = AlgoliaProduct | AlgoliaReview

View File

@@ -0,0 +1,128 @@
import { z } from "zod";
import { StoreStatus } from "../seller";
export type AlgoliaProduct = z.infer<typeof AlgoliaProductValidator>;
export const AlgoliaProductValidator = z.object({
id: z.string(),
title: z.string(),
handle: z.string(),
subtitle: z.string().nullable(),
description: z.string().nullable(),
thumbnail: z.string().nullable(),
average_rating: z.coerce.number().nullable().default(null),
supported_countries: z.array(z.string()).nullable().default([]),
options: z.array(z.record(z.string())).nullable().default(null),
images: z
.array(
z.object({
id: z.string(),
url: z.string(),
rank: z.number(),
})
)
.nullable()
.optional(),
collection: z
.object({
title: z.string(),
})
.nullable()
.optional(),
type: z
.object({
value: z.string(),
})
.nullable()
.optional(),
tags: z
.array(
z.object({
value: z.string(),
})
)
.optional(),
categories: z
.array(
z.object({
name: z.string(),
id: z.string(),
})
)
.optional(),
variants: z.any().nullable().default(null),
brand: z
.object({
name: z.string(),
})
.optional(),
attribute_values: z
.array(
z.object({
name: z.string(),
value: z.string(),
is_filterable: z.boolean(),
ui_component: z.string(),
})
)
.optional(),
sku: z.string().nullable().optional(),
ean: z.string().nullable().optional(),
upc: z.string().nullable().optional(),
barcode: z.string().nullable().optional(),
hs_code: z.string().nullable().optional(),
mid_code: z.string().nullable().optional(),
weight: z.coerce.number().nullable().optional(),
length: z.coerce.number().nullable().optional(),
height: z.coerce.number().nullable().optional(),
width: z.coerce.number().nullable().optional(),
origin_country: z.string().nullable().optional(),
material: z.string().nullable().optional(),
seller: z
.object({
id: z.string(),
handle: z.string().nullish(),
store_status: z.nativeEnum(StoreStatus).nullish(),
})
.nullable(),
});
export const AlgoliaVariantValidator = z.object({
id: z.string(),
title: z.string().nullish(),
sku: z.string().nullish(),
barcode: z.string().nullish(),
ean: z.string().nullish(),
ups: z.string().nullish(),
allow_backorder: z.boolean(),
manage_inventory: z.boolean(),
hs_code: z.string().nullish(),
origin_country: z.string().nullish(),
mid_code: z.string().nullish(),
material: z.string().nullish(),
weight: z.number().nullish(),
length: z.number().nullish(),
height: z.number().nullish(),
wifth: z.number().nullish(),
variant_rank: z.number().nullish(),
options: z.array(
z.object({
id: z.string(),
value: z.string(),
option: z.object({
id: z.string(),
title: z.string(),
}),
})
),
prices: z.array(
z.object({
id: z.string(),
title: z.string().nullish(),
currency_code: z.string(),
min_quantity: z.number().nullish(),
max_quantity: z.number().nullish(),
rules_count: z.number(),
amount: z.number(),
})
),
});

View File

@@ -0,0 +1,11 @@
import { z } from 'zod'
export type AlgoliaReview = z.infer<typeof AlgoliaReviewValidator>
export const AlgoliaReviewValidator = z.object({
id: z.string(),
reference: z.string(),
reference_id: z.string(),
rating: z.coerce.number(),
customer_note: z.string().nullable(),
seller_note: z.string().nullable()
})

View File

@@ -0,0 +1,13 @@
export enum AlgoliaEvents {
PRODUCTS_CHANGED = 'algolia.products.changed',
PRODUCTS_DELETED = 'algolia.products.deleted',
REVIEW_CHANGED = 'algolia.reviews.changed'
}
export enum IntermediateEvents {
FULFULLMENT_SET_CHANGED = 'algolia.intermediate.fulfillment_set.changed',
SERVICE_ZONE_CHANGED = 'algolia.intermediate.service_zone.changed',
SHIPPING_OPTION_CHANGED = 'algolia.intermediate.shipping_option.changed',
STOCK_LOCATION_CHANGED = 'algolia.intermediate.stock_location.changed',
INVENTORY_ITEM_CHANGED = 'algolia.intermediate.inventory_item.changed'
}

View File

@@ -0,0 +1,4 @@
export enum IndexType {
PRODUCT = 'products',
REVIEW = 'reviews'
}

View File

@@ -0,0 +1,5 @@
export * from './index-types'
export * from './algolia-entity'
export * from './algolia-product'
export * from './algolia-review'
export * from './events'

View File

@@ -0,0 +1,40 @@
export enum AttributeUIComponent {
SELECT = "select",
MULTIVALUE = "multivalue",
UNIT = "unit",
TOGGLE = "toggle",
TEXTAREA = "text_area",
COLOR_PICKER = "color_picker",
}
export interface ProductAttributeValueDTO {
value: string;
attribute_id: string;
}
export interface AttributePossibleValueDTO {
id: string;
value: string;
rank: number;
created_at: string;
metadata?: Record<string, unknown>;
}
export interface AttributeDTO {
id: string;
name: string;
description: string;
handle: string;
is_filterable: boolean;
ui_component: AttributeUIComponent;
metadata?: Record<string, unknown>;
possible_values?: AttributePossibleValueDTO[];
values?: Array<{
id: string;
value: string;
}>;
product_categories?: Array<{
id: string;
name: string;
}>;
}

View File

@@ -0,0 +1,2 @@
export * from './mutations'
export * from './common'

View File

@@ -0,0 +1,51 @@
import { AttributeUIComponent } from './common'
export interface CreateAttributeValueDTO {
value: string
rank: number
attribute_id: string
metadata?: Record<string, unknown>
}
export interface UpdateAttributeDTO {
id: string
name?: string
description?: string
handle?: string
is_filterable?: boolean
metadata?: Record<string, unknown>
possible_values?: UpsertAttributeValueDTO[]
product_category_ids?: { id: string }[]
}
export interface UpsertAttributeValueDTO {
id?: string
value?: string
rank?: number
metadata?: Record<string, unknown>
attribute_id?: string
}
export interface CreateAttributeDTO {
name: string
description?: string
handle?: string
is_filterable?: boolean
metadata?: Record<string, unknown>
ui_component: AttributeUIComponent
possible_values?: Omit<CreateAttributeValueDTO, 'attribute_id'>[]
product_category_ids?: string[]
}
export interface UpdateAttributeValueDTO {
id: string
value?: string
rank?: number
metadata?: Record<string, unknown> | null
}
export type CreateProductAttributeValueDTO = {
attribute_id: string
product_id: string
value: string
}

View File

@@ -0,0 +1 @@
export * from "./mutations";

View File

@@ -0,0 +1,3 @@
export type CreateBrandDTO = {
brand_name: string
}

View File

@@ -0,0 +1,60 @@
import { BigNumberValue } from '@medusajs/framework/types'
export type CommissionRateDTO = {
id: string
created_at: Date
updated_at: Date
type: string
percentage_rate: number | null
include_tax: boolean
price_set_id: string | null
max_price_set_id: string | null
min_price_set_id: string | null
}
export type CommissionRuleDTO = {
id: string
created_at: Date
updated_at: Date
name: string
reference: string
reference_id: string
rate: CommissionRateDTO
}
export type CommissionLineDTO = {
id: string
item_line_id: string
rule_id: string
currency_code: string
value: BigNumberValue
created_at: Date
updated_at: Date
}
export type CommissionCalculationContext = {
product_type_id: string
product_category_id: string
seller_id: string
}
type Price = { amount: number; currency_code: string }
export type AdminCommissionAggregate = {
id: string
name: string
type: string
reference: string
reference_id: string
include_tax: boolean
is_active: boolean
ref_value: string
price_set_id: string | null
price_set: Price[]
min_price_set_id: string | null
min_price_set: Price[]
max_price_set_id: string | null
max_price_set: Price[]
percentage_rate: number | null
fee_value: string
}

View File

@@ -0,0 +1,2 @@
export * from './common'
export * from './mutations'

View File

@@ -0,0 +1,36 @@
import { CommissionLineDTO } from './common'
export type Price = {
amount: number
currency_code: string
}
export type CreateCommissionRateDTO = {
type: string
percentage_rate?: number
include_tax: boolean
price_set?: Price[]
min_price_set?: Price[]
max_price_set?: Price[]
}
export type CreateCommissionRuleDTO = {
name: string
reference: string
reference_id: string
is_active: boolean
rate: CreateCommissionRateDTO
}
export type CreateCommissionLineDTO = Omit<
CommissionLineDTO,
'id' | 'created_at' | 'updated_at'
>
export type UpdateCommissionRateDTO = Partial<CreateCommissionRateDTO> & {
id: string
}
export type UpdateCommissionRuleDTO = Partial<CreateCommissionRuleDTO> & {
id: string
}

View File

@@ -0,0 +1,14 @@
export enum ConfigurationRuleType {
GLOBAL_PRODUCT_CATALOG = 'global_product_catalog',
REQUIRE_PRODUCT_APPROVAL = 'require_product_approval',
PRODUCT_REQUEST_ENABLED = 'product_request_enabled',
PRODUCT_IMPORT_ENABLED = 'product_import_enabled'
}
export type ConfigurationRule = {
id: string
rule_type: ConfigurationRuleType
is_enabled: boolean
created_at: Date
updated_at: Date
}

View File

@@ -0,0 +1,2 @@
export * from './common'
export * from './mutations'

View File

@@ -0,0 +1,11 @@
import { ConfigurationRuleType } from './common'
export interface CreateConfigurationRuleDTO {
rule_type: ConfigurationRuleType
is_enabled: boolean
}
export interface UpdateConfigurationRuleDTO {
id: string
is_enabled: boolean
}

View File

@@ -0,0 +1,14 @@
export * from "./configuration";
export * from "./seller";
export * from "./reviews";
export * from "./payout";
export * from "./marketplace";
export * from "./brand";
export * from "./commission";
export * from "./wishlist";
export * from "./attribute";
export * from "./order-return-request";
export * from "./requests";
export * from "./split-order-payment";
export * from "./algolia";
export * from "./payment-stripe-connect";

View File

@@ -0,0 +1,45 @@
import {
BigNumberInput,
CartDTO,
CustomerDTO,
FulfillmentStatus,
OrderDTO,
OrderDetailDTO,
OrderStatus,
PaymentCollectionDTO,
PaymentCollectionStatus,
SalesChannelDTO
} from '@medusajs/framework/types'
export type OrderSetDTO = {
id: string
created_at: Date
updated_at: Date
display_id: number
customer_id?: string
customer?: CustomerDTO
cart_id: string
cart?: CartDTO
sales_channel_id?: string
sales_channel?: SalesChannelDTO
payment_collection_id?: string
payment_collection?: PaymentCollectionDTO
}
export type OrderSetWithOrdersDTO = OrderSetDTO & {
orders: (OrderDTO & OrderDetailDTO)[]
}
export type FormattedOrderSetDTO = OrderSetDTO & {
status: OrderStatus
payment_status: PaymentCollectionStatus
fulfillment_status: FulfillmentStatus
total: BigNumberInput
tax_total: BigNumberInput
subtotal: BigNumberInput
shipping_total: BigNumberInput
shipping_tax_total: BigNumberInput
}

View File

@@ -0,0 +1,3 @@
export enum OrderSetWorkflowEvents {
PLACED = 'order_set.placed'
}

View File

@@ -0,0 +1,3 @@
export * from './events'
export * from './common'
export * from './mutations'

View File

@@ -0,0 +1,6 @@
export type CreateOrderSetDTO = {
cart_id: string
customer_id: string
payment_collection_id: string
sales_channel_id: string
}

View File

@@ -0,0 +1,20 @@
export type OrderReturnRequestLineItemDTO = {
id: string
line_item_id: string
quantity: number
}
export type OrderReturnRequestDTO = {
id: string
line_items: OrderReturnRequestLineItemDTO[]
customer_id: string
customer_note: string
shipping_option_id: string | null
vendor_reviewer_id: string | null
vendor_reviewer_note: string | null
vendor_review_date: Date | null
admin_reviewer_id: string | null
admin_reviewer_note: string | null
admin_review_date: Date | null
status: string
}

View File

@@ -0,0 +1,2 @@
export * from './common'
export * from './mutations'

View File

@@ -0,0 +1,32 @@
export type CreateOrderReturnRequestDTO = {
order_id: string;
shipping_option_id?: string;
line_items: { line_item_id: string; quantity: number; reason_id?: string }[];
customer_id: string;
customer_note: string;
};
export type OrderReturnRequestStatus =
| "pending"
| "refunded"
| "withdrawn"
| "escalated"
| "canceled";
export type VendorUpdateOrderReturnRequestDTO = {
id: string;
vendor_reviewer_id: string;
vendor_reviewer_note: string;
vendor_review_date: Date;
status: OrderReturnRequestStatus;
location_id?: string;
};
export type AdminUpdateOrderReturnRequestDTO = {
id: string;
admin_reviewer_id: string;
admin_reviewer_note: string;
admin_review_date: Date;
status: OrderReturnRequestStatus;
location_id?: string;
};

View File

@@ -0,0 +1,19 @@
import Stripe from 'stripe'
export const PaymentProviderKeys = {
CARD: 'card'
}
export type PaymentIntentOptions = Omit<
Stripe.PaymentIntentCreateParams,
'amount' | 'currency' | 'metadata' | 'transfer_group'
>
export const ErrorCodes = {
PAYMENT_INTENT_UNEXPECTED_STATE: 'payment_intent_unexpected_state'
}
export const ErrorIntentStatus = {
SUCCEEDED: 'succeeded',
CANCELED: 'canceled'
}

View File

@@ -0,0 +1,38 @@
/* Payment Account */
import { BigNumberInput } from '@medusajs/framework/types'
export enum PayoutAccountStatus {
PENDING = 'pending',
ACTIVE = 'active',
DISABLED = 'disabled'
}
export type PayoutAccountDTO = {
id: string
created_at: Date
updated_at: Date
reference_id: string
data: Record<string, unknown>
status: PayoutAccountStatus
}
/* Onboarding */
export type OnboardingDTO = {
id: string
created_at: Date
updated_at: Date
data: Record<string, unknown>
context: Record<string, unknown>
}
/* Payout */
export type PayoutDTO = {
id: string
created_at: Date
updated_at: Date
data: Record<string, unknown> | null
amount: BigNumberInput
currency_code: string
}

View File

@@ -0,0 +1,19 @@
export enum PayoutWorkflowEvents {
FAILED = "payout.failed",
SUCCEEDED = "payout.succeeded",
RECEIVED = "payout.received",
}
export enum PayoutWebhookEvents {
ACCOUNT_WEBHOOK_RECEIVED = "payout_account.webhook_received",
}
export enum PayoutWebhookAction {
ACCOUNT_AUTHORIZED = "account_authorized",
ACCOUNT_DEAUTHORIZED = "account_deauthorized",
ACCOUNT_REQUIRES_ACTION = "account_requires_action",
}
export enum PayoutSummaryEvents {
NOTIFICATION_SENT = "payout.notification_sent",
}

View File

@@ -0,0 +1,4 @@
export * from './events'
export * from './common'
export * from './mutations'
export * from './provider'

View File

@@ -0,0 +1,35 @@
import { BigNumberInput } from '@medusajs/framework/types'
import { OnboardingDTO, PayoutAccountDTO } from './common'
export interface CreatePayoutAccountDTO {
context: Record<string, unknown>
}
export interface UpdatePayoutAccountDTO
extends Omit<Partial<PayoutAccountDTO>, 'id' | 'created_at' | 'updated_at'> {
id: string
}
export interface CreateOnboardingDTO
extends Omit<
Partial<OnboardingDTO>,
'id' | 'created_at' | 'updated_at' | 'data'
> {
payout_account_id: string
context: Record<string, unknown>
}
export type CreatePayoutDTO = {
amount: BigNumberInput
currency_code: string
account_id: string
transaction_id: string
source_transaction: string
}
export type CreatePayoutReversalDTO = {
payout_id: string
amount: BigNumberInput
currency_code: string
}

View File

@@ -0,0 +1,69 @@
import Stripe from 'stripe'
import { BigNumberInput } from '@medusajs/framework/types'
import { PayoutWebhookAction } from './events'
export type ProcessPayoutInput = {
amount: BigNumberInput
currency: string
account_reference_id: string
transaction_id: string
source_transaction: string
}
export type ReversePayoutInput = {
transfer_id: string
amount: BigNumberInput
currency: string
}
export type ProcessPayoutResponse = {
data: Record<string, unknown>
}
export type CreatePayoutAccountInput = {
context: Record<string, unknown>
account_id: string
}
export type CreatePayoutAccountResponse = {
data: Record<string, unknown>
id: string
}
export type PayoutWebhookActionPayload = {
data: Record<string, unknown>
rawData: string | Buffer
headers: Record<string, unknown>
}
export type PayoutWebhookActionAndDataResponse = {
action: PayoutWebhookAction
data: {
account_id: string
}
}
export type InitializeOnboardingResponse = {
data: Record<string, unknown>
}
export interface IPayoutProvider {
createPayout(input: ProcessPayoutInput): Promise<ProcessPayoutResponse>
createPayoutAccount(
input: CreatePayoutAccountInput
): Promise<CreatePayoutAccountResponse>
reversePayout(input: ReversePayoutInput): Promise<Stripe.TransferReversal>
/**
* Initialize the onboarding process for a payout account.
*/
initializeOnboarding(
accountId: string,
context: Record<string, unknown>
): Promise<InitializeOnboardingResponse>
getAccount(accountId: string): Promise<Stripe.Account>
getWebhookActionAndData(
payload: PayoutWebhookActionPayload
): Promise<PayoutWebhookActionAndDataResponse>
}

View File

@@ -0,0 +1,11 @@
export type RequestDTO = {
id: string
type: string
data: Record<string, unknown>
submitter_id: string
reviewer_id: string
reviewer_note: string
status: 'pending' | 'accepted' | 'rejected'
created_at: Date
updated_at: Date
}

View File

@@ -0,0 +1,48 @@
export enum SellerAccountRequestUpdatedEvent {
ACCEPTED = "requests.seller.accepted",
REJECTED = "requests.seller.rejected",
}
export enum SellerRequest {
CREATED = "requests.seller.created",
}
export enum RequestUpdated {
CREATED = "requests.*.created",
}
export enum ProductCategoryRequestUpdatedEvent {
ACCEPTED = "requests.product_category.accepted",
REJECTED = "requests.product_category.rejected",
}
export enum ProductCollectionRequestUpdatedEvent {
ACCEPTED = "requests.product_collection.accepted",
REJECTED = "requests.product_collection.rejected",
}
export enum ProductRequestUpdatedEvent {
CREATED = "requests.product.created",
ACCEPTED = "requests.product.accepted",
REJECTED = "requests.product.rejected",
}
export enum ProductUpdateRequestUpdatedEvent {
CREATED = "requests.product_update.created",
ACCEPTED = "requests.product_update.accepted",
REJECTED = "requests.product_update.rejected",
}
export enum SellerTeamInviteEvent {
CREATED = "seller.team.invite.created",
}
export enum ProductTypeRequestUpdatedEvent {
ACCEPTED = "requests.product_type.accepted",
REJECTED = "requests.product_type.rejected",
}
export enum ProductTagRequestUpdatedEvent {
ACCEPTED = "requests.product_tag.accepted",
REJECTED = "requests.product_tag.rejected",
}

View File

@@ -0,0 +1,10 @@
export const HumanizeTypes = {
product_collection: "Product Collection",
product_category: "Product Category",
product_update: "Product Update",
product: "Product",
seller: "Seller",
review_remove: "Review Remove",
product_type: "Product Type",
product_tag: "Product Tag",
};

View File

@@ -0,0 +1,4 @@
export * from "./mutations";
export * from "./common";
export * from "./events";
export * from "./humanize_types";

View File

@@ -0,0 +1,31 @@
export type RequestStatus = 'pending' | 'accepted' | 'rejected' | 'draft'
export type CreateRequestDTO = {
type: string
data: any
submitter_id: string
reviewer_id?: string
reviewer_note?: string
status?: RequestStatus
}
export type UpdateRequestDTO = {
id: string
reviewer_id?: string
reviewer_note?: string
status: RequestStatus
}
export type UpdateRequestDataDTO = {
id: string
type: string
data: any
}
export type AcceptRequestDTO = {
id: string
reviewer_id: string
reviewer_note: string
data: any
status: RequestStatus
}

View File

@@ -0,0 +1,10 @@
export type ReviewDTO = {
id: string
reference: 'product' | 'seller'
rating: number
customer_note: string | null
customer_id: string
seller_note: string | null
created_at: Date
updated_at: Date | null
}

View File

@@ -0,0 +1,2 @@
export * from './common'
export * from './mutatations'

View File

@@ -0,0 +1,15 @@
export type CreateReviewDTO = {
order_id: string
reference: 'product' | 'seller'
reference_id: string
rating: number
customer_note: string | null
customer_id: string
}
export type UpdateReviewDTO = {
id: string
rating?: number
customer_note?: string
seller_note?: string
}

View File

@@ -0,0 +1,67 @@
export enum StoreStatus {
ACTIVE = "ACTIVE",
INACTIVE = "INACTIVE",
SUSPENDED = "SUSPENDED",
}
export type SellerDTO = {
id: string;
store_status: StoreStatus;
created_at: Date;
updated_at: Date;
name: string;
email: string | null;
phone: string | null;
description: string | null;
address_line: string | null;
city: string | null;
state: string | null;
postal_code: string | null;
country_code: string | null;
tax_id: string | null;
handle: string;
photo: string | null;
members?: Partial<MemberDTO>[];
};
export type SellerWithPayoutAccountDTO = SellerDTO & {
payout_account: {
id: string;
created_at: Date;
updated_at: Date;
reference_id: string;
data: Record<string, unknown>;
status: string;
};
};
export enum MemberRole {
OWNER = "owner",
ADMIN = "admin",
MEMBER = "member",
}
export type MemberDTO = {
id: string;
created_at: Date;
updated_at: Date;
role: MemberRole;
email: string | null;
name: string | null;
bio: string | null;
photo: string | null;
phone: string | null;
seller?: Partial<SellerDTO>;
};
export type MemberInviteDTO = {
id: string;
created_at: Date;
updated_at: Date;
email: string;
role: MemberRole;
seller?: Partial<SellerDTO>;
token: string;
expires_at: Date;
accepted: boolean;
};

View File

@@ -0,0 +1,3 @@
export enum SellerEvents {
STORE_STATUS_CHANGED = 'seller.store_status_changed'
}

View File

@@ -0,0 +1,3 @@
export * from "./common";
export * from "./mutations";
export * from "./events";

View File

@@ -0,0 +1,68 @@
import { MemberInviteDTO, MemberRole, SellerDTO, StoreStatus } from './common'
export interface CreateSellerDTO
extends Omit<
Partial<SellerDTO>,
'id' | 'created_at' | 'updated_at' | 'members'
> {
name: string
}
export interface UpdateSellerDTO {
id: string
name?: string
email?: string
phone?: string
description?: string
address_line?: string
city?: string
state?: string
postal_code?: string
country_code?: string
tax_id?: string
handle?: string
photo?: string
store_status?: StoreStatus
}
export interface CreateMemberDTO {
seller_id: string
role?: MemberRole
name: string
email: string
bio?: string
photo?: string
phone?: string
}
export interface UpdateMemberDTO {
id: string
role?: MemberRole
name?: string
email?: string
bio?: string
photo?: string
phone?: string
}
export interface CreateMemberInviteDTO
extends Omit<
MemberInviteDTO,
'id' | 'created_at' | 'updated_at' | 'accepted' | 'expires_at' | 'token'
> {
seller_id: string
}
export interface AcceptMemberInviteDTO {
token: string
name: string
}
export interface UpdateMemberInviteDTO extends Partial<MemberInviteDTO> {
id: string
}
export interface CreateSellerInvitationDTO {
email: string
registration_url: string
}

View File

@@ -0,0 +1,9 @@
export type SplitOrderPaymentDTO = {
id: string
status: string
currency_code: string
authorized_amount: number
captured_amount: number
refunded_amount: number
payment_collection_id: string
}

View File

@@ -0,0 +1,2 @@
export * from './mutations'
export * from './common'

View File

@@ -0,0 +1,20 @@
export type CreateSplitOrderPaymentsDTO = {
order_id: string
status: string
currency_code: string
authorized_amount: number
payment_collection_id: string
}
export type UpdateSplitOrderPaymentsDTO = {
id: string
status?: string
authorized_amount?: number
captured_amount?: number
refunded_amount?: number
}
export type RefundSplitOrderPaymentsDTO = {
id: string
amount: number
}

View File

@@ -0,0 +1,25 @@
import {
PriceDTO,
ProductDTO,
ProductVariantDTO
} from '@medusajs/framework/types'
export interface WishlistProductVariantDTO extends ProductVariantDTO {
prices: PriceDTO[]
}
export interface WishlistProduct extends ProductDTO {
variants: WishlistProductVariantDTO[]
}
export type Wishlist = {
id: string
products: WishlistProduct[]
}
export type WishlistItem = {
wishlist_id: string
wishlist: Wishlist
}
export type WishlistResponse = WishlistItem[]

View File

@@ -0,0 +1,2 @@
export * from "./common";
export * from "./mutations";

View File

@@ -0,0 +1,10 @@
export type CreateWishlistDTO = {
reference: 'product'
reference_id: string
customer_id: string
}
export type DeleteWishlistDTO = {
id: string
reference_id: string
}

View File

@@ -0,0 +1 @@
export * from './money'

View File

@@ -0,0 +1,79 @@
import { BigNumberInput } from '@medusajs/framework/types'
import { BigNumber, MathBN } from '@medusajs/framework/utils'
function getCurrencyMultiplier(currency) {
const currencyMultipliers = {
0: [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'UGX',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'
],
3: ['BHD', 'IQD', 'JOD', 'KWD', 'OMR', 'TND']
}
currency = currency.toUpperCase()
let power = 2
for (const [key, value] of Object.entries(currencyMultipliers)) {
if (value.includes(currency)) {
power = parseInt(key, 10)
break
}
}
return Math.pow(10, power)
}
/**
* Converts an amount to the format required by Stripe based on currency.
* https://docs.stripe.com/currencies
* @param {BigNumberInput} amount - The amount to be converted.
* @param {string} currency - The currency code (e.g., 'USD', 'JOD').
* @returns {number} - The converted amount in the smallest currency unit.
*/
export function getSmallestUnit(
amount: BigNumberInput,
currency: string
): number {
const multiplier = getCurrencyMultiplier(currency)
const amount_ =
Math.round(new BigNumber(MathBN.mult(amount, multiplier)).numeric) /
multiplier
const smallestAmount = new BigNumber(MathBN.mult(amount_, multiplier))
let numeric = smallestAmount.numeric
// Check if the currency requires rounding to the nearest ten
if (multiplier === 1e3) {
numeric = Math.ceil(numeric / 10) * 10
}
return parseInt(numeric.toString().split('.').shift()!, 10)
}
/**
* Converts an amount from the smallest currency unit to the standard unit based on currency.
* @param {BigNumberInput} amount - The amount in the smallest currency unit.
* @param {string} currency - The currency code (e.g., 'USD', 'JOD').
* @returns {number} - The converted amount in the standard currency unit.
*/
export function getAmountFromSmallestUnit(
amount: BigNumberInput,
currency: string
): number {
const multiplier = getCurrencyMultiplier(currency)
const standardAmount = new BigNumber(MathBN.div(amount, multiplier))
return standardAmount.numeric
}

View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"outDir": "${configDir}/dist",
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"noUnusedLocals": true,
"module": "node16",
"moduleResolution": "node16",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true,
"incremental": false
},
"include": ["${configDir}/src"],
"exclude": ["${configDir}/dist", "${configDir}/node_modules"]
}