1
0

vendure-config.ts 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. import { ApolloServerPlugin } from '@apollo/server';
  2. import { RenderPageOptions } from '@apollographql/graphql-playground-html';
  3. import { DynamicModule, Type } from '@nestjs/common';
  4. import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
  5. import { LanguageCode } from '@vendure/common/lib/generated-types';
  6. import { ValidationContext } from 'graphql';
  7. import { DataSourceOptions } from 'typeorm';
  8. import { Middleware } from '../common';
  9. import { PermissionDefinition } from '../common/permission-definition';
  10. import { JobBufferStorageStrategy } from '../job-queue/job-buffer/job-buffer-storage-strategy';
  11. import { AssetImportStrategy } from './asset-import-strategy/asset-import-strategy';
  12. import { AssetNamingStrategy } from './asset-naming-strategy/asset-naming-strategy';
  13. import { AssetPreviewStrategy } from './asset-preview-strategy/asset-preview-strategy';
  14. import { AssetStorageStrategy } from './asset-storage-strategy/asset-storage-strategy';
  15. import { AuthenticationStrategy } from './auth/authentication-strategy';
  16. import { PasswordHashingStrategy } from './auth/password-hashing-strategy';
  17. import { PasswordValidationStrategy } from './auth/password-validation-strategy';
  18. import { CollectionFilter } from './catalog/collection-filter';
  19. import { ProductVariantPriceCalculationStrategy } from './catalog/product-variant-price-calculation-strategy';
  20. import { ProductVariantPriceSelectionStrategy } from './catalog/product-variant-price-selection-strategy';
  21. import { ProductVariantPriceUpdateStrategy } from './catalog/product-variant-price-update-strategy';
  22. import { StockDisplayStrategy } from './catalog/stock-display-strategy';
  23. import { StockLocationStrategy } from './catalog/stock-location-strategy';
  24. import { CustomFields } from './custom-field/custom-field-types';
  25. import { EntityDuplicator } from './entity/entity-duplicator';
  26. import { EntityIdStrategy } from './entity/entity-id-strategy';
  27. import { MoneyStrategy } from './entity/money-strategy';
  28. import { EntityMetadataModifier } from './entity-metadata/entity-metadata-modifier';
  29. import { FulfillmentHandler } from './fulfillment/fulfillment-handler';
  30. import { FulfillmentProcess } from './fulfillment/fulfillment-process';
  31. import { JobQueueStrategy } from './job-queue/job-queue-strategy';
  32. import { VendureLogger } from './logger/vendure-logger';
  33. import { ActiveOrderStrategy } from './order/active-order-strategy';
  34. import { ChangedPriceHandlingStrategy } from './order/changed-price-handling-strategy';
  35. import { GuestCheckoutStrategy } from './order/guest-checkout-strategy';
  36. import { OrderByCodeAccessStrategy } from './order/order-by-code-access-strategy';
  37. import { OrderCodeStrategy } from './order/order-code-strategy';
  38. import { OrderItemPriceCalculationStrategy } from './order/order-item-price-calculation-strategy';
  39. import { OrderMergeStrategy } from './order/order-merge-strategy';
  40. import { OrderPlacedStrategy } from './order/order-placed-strategy';
  41. import { OrderProcess } from './order/order-process';
  42. import { OrderSellerStrategy } from './order/order-seller-strategy';
  43. import { StockAllocationStrategy } from './order/stock-allocation-strategy';
  44. import { PaymentMethodEligibilityChecker } from './payment/payment-method-eligibility-checker';
  45. import { PaymentMethodHandler } from './payment/payment-method-handler';
  46. import { PaymentProcess } from './payment/payment-process';
  47. import { PromotionAction } from './promotion/promotion-action';
  48. import { PromotionCondition } from './promotion/promotion-condition';
  49. import { RefundProcess } from './refund/refund-process';
  50. import { SessionCacheStrategy } from './session-cache/session-cache-strategy';
  51. import { ShippingCalculator } from './shipping-method/shipping-calculator';
  52. import { ShippingEligibilityChecker } from './shipping-method/shipping-eligibility-checker';
  53. import { ShippingLineAssignmentStrategy } from './shipping-method/shipping-line-assignment-strategy';
  54. import { ErrorHandlerStrategy } from './system/error-handler-strategy';
  55. import { HealthCheckStrategy } from './system/health-check-strategy';
  56. import { TaxLineCalculationStrategy } from './tax/tax-line-calculation-strategy';
  57. import { TaxZoneStrategy } from './tax/tax-zone-strategy';
  58. /**
  59. * @description
  60. * The ApiOptions define how the Vendure GraphQL APIs are exposed, as well as allowing the API layer
  61. * to be extended with middleware.
  62. *
  63. * @docsCategory configuration
  64. */
  65. export interface ApiOptions {
  66. /**
  67. * @description
  68. * Set the hostname of the server. If not set, the server will be available on localhost.
  69. *
  70. * @default ''
  71. */
  72. hostname?: string;
  73. /**
  74. * @description
  75. * Which port the Vendure server should listen on.
  76. *
  77. * @default 3000
  78. */
  79. port: number;
  80. /**
  81. * @description
  82. * The path to the admin GraphQL API.
  83. *
  84. * @default 'admin-api'
  85. */
  86. adminApiPath?: string;
  87. /**
  88. * @description
  89. * The path to the shop GraphQL API.
  90. *
  91. * @default 'shop-api'
  92. */
  93. shopApiPath?: string;
  94. /**
  95. * @description
  96. * The playground config to the admin GraphQL API
  97. * [ApolloServer playground](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructoroptions-apolloserver).
  98. *
  99. * @default false
  100. */
  101. adminApiPlayground?: boolean | RenderPageOptions;
  102. /**
  103. * @description
  104. * The playground config to the shop GraphQL API
  105. * [ApolloServer playground](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructoroptions-apolloserver).
  106. *
  107. * @default false
  108. */
  109. shopApiPlayground?: boolean | RenderPageOptions;
  110. /**
  111. * @description
  112. * The debug config to the admin GraphQL API
  113. * [ApolloServer playground](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructoroptions-apolloserver).
  114. *
  115. * @default false
  116. */
  117. adminApiDebug?: boolean;
  118. /**
  119. * @description
  120. * The debug config to the shop GraphQL API
  121. * [ApolloServer playground](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#constructoroptions-apolloserver).
  122. *
  123. * @default false
  124. */
  125. shopApiDebug?: boolean;
  126. /**
  127. * @description
  128. * The maximum number of items that may be returned by a query which returns a `PaginatedList` response. In other words,
  129. * this is the upper limit of the `take` input option.
  130. *
  131. * @default 100
  132. */
  133. shopListQueryLimit?: number;
  134. /**
  135. * @description
  136. * The maximum number of items that may be returned by a query which returns a `PaginatedList` response. In other words,
  137. * this is the upper limit of the `take` input option.
  138. *
  139. * @default 1000
  140. */
  141. adminListQueryLimit?: number;
  142. /**
  143. * @description
  144. * Custom functions to use as additional validation rules when validating the schema for the admin GraphQL API
  145. * [ApolloServer validation rules](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#validationrules).
  146. *
  147. * @default []
  148. */
  149. adminApiValidationRules?: Array<(context: ValidationContext) => any>;
  150. /**
  151. * @description
  152. * Custom functions to use as additional validation rules when validating the schema for the shop GraphQL API
  153. * [ApolloServer validation rules](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#validationrules).
  154. *
  155. * @default []
  156. */
  157. shopApiValidationRules?: Array<(context: ValidationContext) => any>;
  158. /**
  159. * @description
  160. * The name of the property which contains the token of the
  161. * active channel. This property can be included either in
  162. * the request header or as a query string.
  163. *
  164. * @default 'vendure-token'
  165. */
  166. channelTokenKey?: string;
  167. /**
  168. * @description
  169. * Set the CORS handling for the server. See the [express CORS docs](https://github.com/expressjs/cors#configuration-options).
  170. *
  171. * @default { origin: true, credentials: true }
  172. */
  173. cors?: boolean | CorsOptions;
  174. /**
  175. * @description
  176. * Custom Express or NestJS middleware for the server. More information can be found in the {@link Middleware} docs.
  177. *
  178. * @default []
  179. */
  180. middleware?: Middleware[];
  181. /**
  182. * @description
  183. * Custom [ApolloServerPlugins](https://www.apollographql.com/docs/apollo-server/integrations/plugins/) which
  184. * allow the extension of the Apollo Server, which is the underlying GraphQL server used by Vendure.
  185. *
  186. * Apollo plugins can be used e.g. to perform custom data transformations on incoming operations or outgoing
  187. * data.
  188. *
  189. * @default []
  190. */
  191. apolloServerPlugins?: ApolloServerPlugin[];
  192. /**
  193. * @description
  194. * Controls whether introspection of the GraphQL APIs is enabled. For production, it is recommended to disable
  195. * introspection, since exposing your entire schema can allow an attacker to trivially learn all operations
  196. * and much more easily find any potentially exploitable queries.
  197. *
  198. * **Note:** when introspection is disabled, tooling which relies on it for things like autocompletion
  199. * will not work.
  200. *
  201. * @example
  202. * ```ts
  203. * {
  204. * introspection: process.env.NODE_ENV !== 'production'
  205. * }
  206. * ```
  207. *
  208. * @default true
  209. * @since 1.5.0
  210. */
  211. introspection?: boolean;
  212. }
  213. /**
  214. * @description
  215. * Options for the handling of the cookies used to track sessions (only applicable if
  216. * `authOptions.tokenMethod` is set to `'cookie'`). These options are passed directly
  217. * to the Express [cookie-session middleware](https://github.com/expressjs/cookie-session).
  218. *
  219. * @docsCategory auth
  220. */
  221. export interface CookieOptions {
  222. /**
  223. * @description
  224. * The name of the cookies to set.
  225. * If set to a string, both cookies for the Admin API and Shop API will have the same name.
  226. * If set as an object, it makes it possible to give different names to the Admin API and the Shop API cookies
  227. *
  228. * @default 'session'
  229. */
  230. name?: string | { shop: string; admin: string };
  231. /**
  232. * @description
  233. * The secret used for signing the session cookies for authenticated users. Only applies
  234. * tokenMethod is set to 'cookie'.
  235. *
  236. * In production applications, this should not be stored as a string in
  237. * source control for security reasons, but may be loaded from an external
  238. * file not under source control, or from an environment variable, for example.
  239. *
  240. * @default (random character string)
  241. */
  242. secret?: string;
  243. /**
  244. * @description
  245. * a string indicating the path of the cookie.
  246. *
  247. * @default '/'
  248. */
  249. path?: string;
  250. /**
  251. * @description
  252. * a string indicating the domain of the cookie (no default).
  253. */
  254. domain?: string;
  255. /**
  256. * @description
  257. * a boolean or string indicating whether the cookie is a "same site" cookie (false by default). This can be set to 'strict',
  258. * 'lax', 'none', or true (which maps to 'strict').
  259. *
  260. * @default false
  261. */
  262. sameSite?: 'strict' | 'lax' | 'none' | boolean;
  263. /**
  264. * @description
  265. * a boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS).
  266. */
  267. secure?: boolean;
  268. /**
  269. * @description
  270. * a boolean indicating whether the cookie is only to be sent over HTTPS (use this if you handle SSL not in your node process).
  271. */
  272. secureProxy?: boolean;
  273. /**
  274. * @description
  275. * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true by default).
  276. *
  277. * @default true
  278. */
  279. httpOnly?: boolean;
  280. /**
  281. * @description
  282. * a boolean indicating whether the cookie is to be signed (true by default). If this is true, another cookie of the same name with the .sig
  283. * suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the
  284. * first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.
  285. */
  286. signed?: boolean;
  287. /**
  288. * @description
  289. * a boolean indicating whether to overwrite previously set cookies of the same name (true by default). If this is true, all cookies set during
  290. * the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
  291. */
  292. overwrite?: boolean;
  293. /**
  294. * @description
  295. * A number representing the milliseconds from Date.now() for expiry
  296. *
  297. * @since 2.2.0
  298. */
  299. maxAge?: number;
  300. /**
  301. * @description
  302. * a Date object indicating the cookie's expiration date (expires at the end of session by default).
  303. *
  304. * @since 2.2.0
  305. */
  306. expires?: Date;
  307. }
  308. /**
  309. * @description
  310. * The AuthOptions define how authentication and authorization is managed.
  311. *
  312. * @docsCategory auth
  313. * */
  314. export interface AuthOptions {
  315. /**
  316. * @description
  317. * Disable authentication & permissions checks.
  318. * NEVER set the to true in production. It exists
  319. * only to aid certain development tasks.
  320. *
  321. * @default false
  322. */
  323. disableAuth?: boolean;
  324. /**
  325. * @description
  326. * Sets the method by which the session token is delivered and read.
  327. *
  328. * * 'cookie': Upon login, a 'Set-Cookie' header will be returned to the client, setting a
  329. * cookie containing the session token. A browser-based client (making requests with credentials)
  330. * should automatically send the session cookie with each request.
  331. * * 'bearer': Upon login, the token is returned in the response and should be then stored by the
  332. * client app. Each request should include the header `Authorization: Bearer <token>`.
  333. *
  334. * Note that if the bearer method is used, Vendure will automatically expose the configured
  335. * `authTokenHeaderKey` in the server's CORS configuration (adding `Access-Control-Expose-Headers: vendure-auth-token`
  336. * by default).
  337. *
  338. * From v1.2.0 it is possible to specify both methods as a tuple: `['cookie', 'bearer']`.
  339. *
  340. * @default 'cookie'
  341. */
  342. tokenMethod?: 'cookie' | 'bearer' | ReadonlyArray<'cookie' | 'bearer'>;
  343. /**
  344. * @description
  345. * Options related to the handling of cookies when using the 'cookie' tokenMethod.
  346. */
  347. cookieOptions?: CookieOptions;
  348. /**
  349. * @description
  350. * Sets the header property which will be used to send the auth token when using the 'bearer' method.
  351. *
  352. * @default 'vendure-auth-token'
  353. */
  354. authTokenHeaderKey?: string;
  355. /**
  356. * @description
  357. * Session duration, i.e. the time which must elapse from the last authenticated request
  358. * after which the user must re-authenticate.
  359. *
  360. * Expressed as a string describing a time span per
  361. * [zeit/ms](https://github.com/zeit/ms.js). Eg: `60`, `'2 days'`, `'10h'`, `'7d'`
  362. *
  363. * @default '1y'
  364. */
  365. sessionDuration?: string | number;
  366. /**
  367. * @description
  368. * This strategy defines how sessions will be cached. By default, sessions are cached using a simple
  369. * in-memory caching strategy which is suitable for development and low-traffic, single-instance
  370. * deployments.
  371. *
  372. * @default InMemorySessionCacheStrategy
  373. */
  374. sessionCacheStrategy?: SessionCacheStrategy;
  375. /**
  376. * @description
  377. * The "time to live" of a given item in the session cache. This determines the length of time (in seconds)
  378. * that a cache entry is kept before being considered "stale" and being replaced with fresh data
  379. * taken from the database.
  380. *
  381. * @default 300
  382. */
  383. sessionCacheTTL?: number;
  384. /**
  385. * @description
  386. * Determines whether new User accounts require verification of their email address.
  387. *
  388. * If set to "true", when registering via the `registerCustomerAccount` mutation, one should *not* set the
  389. * `password` property - doing so will result in an error. Instead, the password is set at a later stage
  390. * (once the email with the verification token has been opened) via the `verifyCustomerAccount` mutation.
  391. *
  392. * @default true
  393. */
  394. requireVerification?: boolean;
  395. /**
  396. * @description
  397. * Sets the length of time that a verification token is valid for, after which the verification token must be refreshed.
  398. *
  399. * Expressed as a string describing a time span per
  400. * [zeit/ms](https://github.com/zeit/ms.js). Eg: `60`, `'2 days'`, `'10h'`, `'7d'`
  401. *
  402. * @default '7d'
  403. */
  404. verificationTokenDuration?: string | number;
  405. /**
  406. * @description
  407. * Configures the credentials to be used to create a superadmin
  408. */
  409. superadminCredentials?: SuperadminCredentials;
  410. /**
  411. * @description
  412. * Configures one or more AuthenticationStrategies which defines how authentication
  413. * is handled in the Shop API.
  414. * @default NativeAuthenticationStrategy
  415. */
  416. shopAuthenticationStrategy?: AuthenticationStrategy[];
  417. /**
  418. * @description
  419. * Configures one or more AuthenticationStrategy which defines how authentication
  420. * is handled in the Admin API.
  421. * @default NativeAuthenticationStrategy
  422. */
  423. adminAuthenticationStrategy?: AuthenticationStrategy[];
  424. /**
  425. * @description
  426. * Allows custom Permissions to be defined, which can be used to restrict access to custom
  427. * GraphQL resolvers defined in plugins.
  428. *
  429. * @default []
  430. */
  431. customPermissions?: PermissionDefinition[];
  432. /**
  433. * @description
  434. * Allows you to customize the way passwords are hashed when using the {@link NativeAuthenticationStrategy}.
  435. *
  436. * @default BcryptPasswordHashingStrategy
  437. * @since 1.3.0
  438. */
  439. passwordHashingStrategy?: PasswordHashingStrategy;
  440. /**
  441. * @description
  442. * Allows you to set a custom policy for passwords when using the {@link NativeAuthenticationStrategy}.
  443. * By default, it uses the {@link DefaultPasswordValidationStrategy}, which will impose a minimum length
  444. * of four characters. To improve security for production, you are encouraged to specify a more strict
  445. * policy, which you can do like this:
  446. *
  447. * @example
  448. * ```ts
  449. * {
  450. * passwordValidationStrategy: new DefaultPasswordValidationStrategy({
  451. * // Minimum eight characters, at least one letter and one number
  452. * regexp: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/,
  453. * }),
  454. * }
  455. * ```
  456. *
  457. * @since 1.5.0
  458. * @default DefaultPasswordValidationStrategy
  459. */
  460. passwordValidationStrategy?: PasswordValidationStrategy;
  461. }
  462. /**
  463. * @docsCategory orders
  464. * @docsPage OrderOptions
  465. * */
  466. export interface OrderOptions {
  467. /**
  468. * @description
  469. * The maximum number of individual items allowed in a single order. This option exists
  470. * to prevent excessive resource usage when dealing with very large orders. For example,
  471. * if an order contains a million items, then any operations on that order (modifying a quantity,
  472. * adding or removing an item) will require Vendure to loop through all million items
  473. * to perform price calculations against active promotions and taxes. This can have a significant
  474. * performance impact for very large values.
  475. *
  476. * Attempting to exceed this limit will cause Vendure to throw a `OrderLimitError`.
  477. *
  478. * @default 999
  479. */
  480. orderItemsLimit?: number;
  481. /**
  482. * @description
  483. * The maximum number of items allowed per order line. This option is an addition
  484. * on the `orderItemsLimit` for more granular control. Note `orderItemsLimit` is still
  485. * important in order to prevent excessive resource usage.
  486. *
  487. * Attempting to exceed this limit will cause Vendure to throw a OrderLimitError`.
  488. *
  489. * @default 999
  490. */
  491. orderLineItemsLimit?: number;
  492. /**
  493. * @description
  494. * Defines the logic used to calculate the unit price of an OrderLine when adding an
  495. * item to an Order.
  496. *
  497. * @default DefaultPriceCalculationStrategy
  498. */
  499. orderItemPriceCalculationStrategy?: OrderItemPriceCalculationStrategy;
  500. /**
  501. * @description
  502. * Allows the definition of custom states and transition logic for the order process state machine.
  503. * Takes an array of objects implementing the {@link OrderProcess} interface.
  504. *
  505. * @default []
  506. */
  507. process?: Array<OrderProcess<any>>;
  508. /**
  509. * @description
  510. * Determines the point of the order process at which stock gets allocated.
  511. *
  512. * @default DefaultStockAllocationStrategy
  513. */
  514. stockAllocationStrategy?: StockAllocationStrategy;
  515. /**
  516. * @description
  517. * Defines the strategy used to merge a guest Order and an existing Order when
  518. * signing in.
  519. *
  520. * @default MergeOrdersStrategy
  521. */
  522. mergeStrategy?: OrderMergeStrategy;
  523. /**
  524. * @description
  525. * Defines the strategy used to merge a guest Order and an existing Order when
  526. * signing in as part of the checkout flow.
  527. *
  528. * @default UseGuestStrategy
  529. */
  530. checkoutMergeStrategy?: OrderMergeStrategy;
  531. /**
  532. * @description
  533. * Allows a user-defined function to create Order codes. This can be useful when
  534. * integrating with existing systems. By default, Vendure will generate a 16-character
  535. * alphanumeric string.
  536. *
  537. * Note: when using a custom function for Order codes, bear in mind the database limit
  538. * for string types (e.g. 255 chars for a varchar field in MySQL), and also the need
  539. * for codes to be unique.
  540. *
  541. * @default DefaultOrderCodeStrategy
  542. */
  543. orderCodeStrategy?: OrderCodeStrategy;
  544. /**
  545. * @description
  546. * Defines the strategy used to check if and how an Order may be retrieved via the orderByCode query.
  547. *
  548. * The default strategy permits permanent access to the Customer owning the Order and anyone
  549. * within 2 hours after placing the Order.
  550. *
  551. * @since 1.1.0
  552. * @default DefaultOrderByCodeAccessStrategy
  553. */
  554. orderByCodeAccessStrategy?: OrderByCodeAccessStrategy;
  555. /**
  556. * @description
  557. * Defines how we handle the situation where an item exists in an Order, and
  558. * then later on another is added but in the meantime the price of the ProductVariant has changed.
  559. *
  560. * By default, the latest price will be used. Any price changes resulting from using a newer price
  561. * will be reflected in the GraphQL `OrderLine.unitPrice[WithTax]ChangeSinceAdded` field.
  562. *
  563. * @default DefaultChangedPriceHandlingStrategy
  564. */
  565. changedPriceHandlingStrategy?: ChangedPriceHandlingStrategy;
  566. /**
  567. * @description
  568. * Defines the point of the order process at which the Order is set as "placed".
  569. *
  570. * @default DefaultOrderPlacedStrategy
  571. */
  572. orderPlacedStrategy?: OrderPlacedStrategy;
  573. /**
  574. * @description
  575. * Defines the strategy used to determine the active Order when interacting with Shop API operations
  576. * such as `activeOrder` and `addItemToOrder`. By default, the strategy uses the active Session.
  577. *
  578. * Note that if multiple strategies are defined, they will be checked in order and the first one that
  579. * returns an Order will be used.
  580. *
  581. * @since 1.9.0
  582. * @default DefaultActiveOrderStrategy
  583. */
  584. activeOrderStrategy?: ActiveOrderStrategy<any> | Array<ActiveOrderStrategy<any>>;
  585. /**
  586. * @description
  587. * Defines how Orders will be split amongst multiple Channels in a multivendor scenario.
  588. *
  589. * @since 2.0.0
  590. * @default DefaultOrderSellerStrategy
  591. */
  592. orderSellerStrategy?: OrderSellerStrategy;
  593. /**
  594. * @description
  595. * Defines how we deal with guest checkouts.
  596. *
  597. * @since 2.0.0
  598. * @default DefaultGuestCheckoutStrategy
  599. */
  600. guestCheckoutStrategy?: GuestCheckoutStrategy;
  601. }
  602. /**
  603. * @description
  604. * The AssetOptions define how assets (images and other files) are named and stored, and how preview images are generated.
  605. *
  606. * **Note**: If you are using the `AssetServerPlugin`, it is not necessary to configure these options.
  607. *
  608. * @docsCategory assets
  609. * */
  610. export interface AssetOptions {
  611. /**
  612. * @description
  613. * Defines how asset files and preview images are named before being saved.
  614. *
  615. * @default DefaultAssetNamingStrategy
  616. */
  617. assetNamingStrategy?: AssetNamingStrategy;
  618. /**
  619. * @description
  620. * Defines the strategy used for storing uploaded binary files.
  621. *
  622. * @default NoAssetStorageStrategy
  623. */
  624. assetStorageStrategy?: AssetStorageStrategy;
  625. /**
  626. * @description
  627. * Defines the strategy used for creating preview images of uploaded assets.
  628. *
  629. * @default NoAssetPreviewStrategy
  630. */
  631. assetPreviewStrategy?: AssetPreviewStrategy;
  632. /**
  633. * @description
  634. * An array of the permitted file types that may be uploaded as Assets. Each entry
  635. * should be in the form of a valid
  636. * [unique file type specifier](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers)
  637. * i.e. either a file extension (".pdf") or a mime type ("image/*", "audio/mpeg" etc.).
  638. *
  639. * @default image, audio, video MIME types plus PDFs
  640. */
  641. permittedFileTypes?: string[];
  642. /**
  643. * @description
  644. * The max file size in bytes for uploaded assets.
  645. *
  646. * @default 20971520
  647. */
  648. uploadMaxFileSize?: number;
  649. }
  650. /**
  651. * @description
  652. * Options related to products and collections.
  653. *
  654. * @docsCategory products & stock
  655. */
  656. export interface CatalogOptions {
  657. /**
  658. * @description
  659. * Allows custom {@link CollectionFilter}s to be defined.
  660. *
  661. * @default defaultCollectionFilters
  662. */
  663. collectionFilters?: Array<CollectionFilter<any>>;
  664. /**
  665. * @description
  666. * Defines the strategy used to select the price of a ProductVariant, based on factors
  667. * such as the active Channel and active CurrencyCode.
  668. *
  669. * @since 2.0.0
  670. * @default DefaultProductVariantPriceSelectionStrategy
  671. */
  672. productVariantPriceSelectionStrategy?: ProductVariantPriceSelectionStrategy;
  673. /**
  674. * @description
  675. * Defines the strategy used for calculating the price of ProductVariants based
  676. * on the Channel settings and active tax Zone.
  677. *
  678. * @default DefaultTaxCalculationStrategy
  679. */
  680. productVariantPriceCalculationStrategy?: ProductVariantPriceCalculationStrategy;
  681. /**
  682. * @description
  683. * Defines the strategy which determines what happens to a ProductVariant's prices
  684. * when one of the prices gets updated. For instance, this can be used to synchronize
  685. * prices across multiple Channels.
  686. *
  687. * @default DefaultProductVariantPriceUpdateStrategy
  688. * @since 2.2.0
  689. */
  690. productVariantPriceUpdateStrategy?: ProductVariantPriceUpdateStrategy;
  691. /**
  692. * @description
  693. * Defines how the `ProductVariant.stockLevel` value is obtained. It is usually not desirable
  694. * to directly expose stock levels over a public API, as this could be considered a leak of
  695. * sensitive information. However, the storefront will usually want to display _some_ indication
  696. * of whether a given ProductVariant is in stock. The default StockDisplayStrategy will
  697. * display "IN_STOCK", "OUT_OF_STOCK" or "LOW_STOCK" rather than exposing the actual saleable
  698. * stock level.
  699. *
  700. * @default DefaultStockDisplayStrategy
  701. */
  702. stockDisplayStrategy?: StockDisplayStrategy;
  703. /**
  704. * @description
  705. * Defines the strategy used to determine which StockLocation should be used when performing
  706. * stock operations such as allocating and releasing stock as well as determining the
  707. * amount of stock available for sale.
  708. *
  709. * @default DefaultStockLocationStrategy
  710. * @since 2.0.0
  711. */
  712. stockLocationStrategy?: StockLocationStrategy;
  713. }
  714. /**
  715. * @docsCategory promotions
  716. */
  717. export interface PromotionOptions {
  718. /**
  719. * @description
  720. * An array of conditions which can be used to construct Promotions
  721. */
  722. promotionConditions?: Array<PromotionCondition<any>>;
  723. /**
  724. * @description
  725. * An array of actions which can be used to construct Promotions
  726. */
  727. promotionActions?: Array<PromotionAction<any>>;
  728. }
  729. /**
  730. * @docsCategory shipping
  731. * */
  732. export interface ShippingOptions {
  733. /**
  734. * @description
  735. * An array of available ShippingEligibilityCheckers for use in configuring ShippingMethods
  736. */
  737. shippingEligibilityCheckers?: Array<ShippingEligibilityChecker<any>>;
  738. /**
  739. * @description
  740. * An array of available ShippingCalculators for use in configuring ShippingMethods
  741. */
  742. shippingCalculators?: Array<ShippingCalculator<any>>;
  743. /**
  744. * @description
  745. * This strategy is used to assign a given {@link ShippingLine} to one or more {@link OrderLine}s of the Order.
  746. * This allows you to set multiple shipping methods for a single order, each assigned a different subset of
  747. * OrderLines.
  748. *
  749. * @since 2.0.0
  750. */
  751. shippingLineAssignmentStrategy?: ShippingLineAssignmentStrategy;
  752. /**
  753. * @description
  754. * Allows the definition of custom states and transition logic for the fulfillment process state machine.
  755. * Takes an array of objects implementing the {@link FulfillmentProcess} interface.
  756. *
  757. * @deprecated use `process`
  758. */
  759. customFulfillmentProcess?: Array<FulfillmentProcess<any>>;
  760. /**
  761. * @description
  762. * Allows the definition of custom states and transition logic for the fulfillment process state machine.
  763. * Takes an array of objects implementing the {@link FulfillmentProcess} interface.
  764. *
  765. * @since 2.0.0
  766. * @default defaultFulfillmentProcess
  767. */
  768. process?: Array<FulfillmentProcess<any>>;
  769. /**
  770. * @description
  771. * An array of available FulfillmentHandlers.
  772. */
  773. fulfillmentHandlers?: Array<FulfillmentHandler<any>>;
  774. }
  775. /**
  776. * @description
  777. * These credentials will be used to create the Superadmin user & administrator
  778. * when Vendure first bootstraps.
  779. *
  780. * @docsCategory auth
  781. */
  782. export interface SuperadminCredentials {
  783. /**
  784. * @description
  785. * The identifier to be used to create a superadmin account
  786. * @default 'superadmin'
  787. */
  788. identifier: string;
  789. /**
  790. * @description
  791. * The password to be used to create a superadmin account
  792. * @default 'superadmin'
  793. */
  794. password: string;
  795. }
  796. /**
  797. * @description
  798. * Defines payment-related options in the {@link VendureConfig}.
  799. *
  800. * @docsCategory payment
  801. * */
  802. export interface PaymentOptions {
  803. /**
  804. * @description
  805. * Defines which {@link PaymentMethodHandler}s are available when configuring
  806. * {@link PaymentMethod}s
  807. */
  808. paymentMethodHandlers: PaymentMethodHandler[];
  809. /**
  810. * @description
  811. * Defines which {@link PaymentMethodEligibilityChecker}s are available when configuring
  812. * {@link PaymentMethod}s
  813. */
  814. paymentMethodEligibilityCheckers?: PaymentMethodEligibilityChecker[];
  815. /**
  816. * @deprecated use `process`
  817. */
  818. customPaymentProcess?: Array<PaymentProcess<any>>;
  819. /**
  820. * @description
  821. * Allows the definition of custom states and transition logic for the payment process state machine.
  822. * Takes an array of objects implementing the {@link PaymentProcess} interface.
  823. *
  824. * @default defaultPaymentProcess
  825. * @since 2.0.0
  826. */
  827. process?: Array<PaymentProcess<any>>;
  828. /**
  829. * @description
  830. * Allows the definition of custom states and transition logic for the refund process state machine.
  831. * Takes an array of objects implementing the {@link RefundProcess} interface.
  832. *
  833. * @default defaultRefundProcess
  834. */
  835. refundProcess?: Array<RefundProcess<any>>;
  836. }
  837. /**
  838. * @docsCategory tax
  839. *
  840. * */
  841. export interface TaxOptions {
  842. /**
  843. * @description
  844. * Defines the strategy used to determine the applicable Zone used in tax calculations.
  845. *
  846. * @default DefaultTaxZoneStrategy
  847. */
  848. taxZoneStrategy?: TaxZoneStrategy;
  849. /**
  850. * @description
  851. * Defines the strategy used to calculate the TaxLines added to OrderItems.
  852. *
  853. * @default DefaultTaxLineCalculationStrategy
  854. */
  855. taxLineCalculationStrategy?: TaxLineCalculationStrategy;
  856. }
  857. /**
  858. * @description
  859. * Options related to importing & exporting data.
  860. *
  861. * @docsCategory import-export
  862. */
  863. export interface ImportExportOptions {
  864. /**
  865. * @description
  866. * The directory in which assets to be imported are located.
  867. *
  868. * @default __dirname
  869. */
  870. importAssetsDir?: string;
  871. /**
  872. * @description
  873. * This strategy determines how asset files get imported based on the path given in the
  874. * import CSV or via the {@link AssetImporter} `getAssets()` method.
  875. *
  876. * @since 1.7.0
  877. */
  878. assetImportStrategy?: AssetImportStrategy;
  879. }
  880. /**
  881. * @description
  882. * Options related to the built-in job queue.
  883. *
  884. * @docsCategory JobQueue
  885. */
  886. export interface JobQueueOptions {
  887. /**
  888. * @description
  889. * Defines how the jobs in the queue are persisted and accessed.
  890. *
  891. * @default InMemoryJobQueueStrategy
  892. */
  893. jobQueueStrategy?: JobQueueStrategy;
  894. jobBufferStorageStrategy?: JobBufferStorageStrategy;
  895. /**
  896. * @description
  897. * Defines the queues that will run in this process.
  898. * This can be used to configure only certain queues to run in this process.
  899. * If its empty all queues will be run. Note: this option is primarily intended
  900. * to apply to the Worker process. Jobs will _always_ get published to the queue
  901. * regardless of this setting, but this setting determines whether they get
  902. * _processed_ or not.
  903. */
  904. activeQueues?: string[];
  905. /**
  906. * @description
  907. * Prefixes all job queue names with the passed string. This is useful with multiple deployments
  908. * in cloud environments using services such as Amazon SQS or Google Cloud Tasks.
  909. *
  910. * For example, we might have a staging and a production deployment in the same account/project and
  911. * each one will need its own task queue. We can achieve this with a prefix.
  912. *
  913. * @since 1.5.0
  914. */
  915. prefix?: string;
  916. }
  917. /**
  918. * @description
  919. * Options relating to the internal handling of entities.
  920. *
  921. * @since 1.3.0
  922. * @docsCategory configuration
  923. * @docsPage EntityOptions
  924. * @docsWeight 0
  925. */
  926. export interface EntityOptions {
  927. /**
  928. * @description
  929. * Defines the strategy used for both storing the primary keys of entities
  930. * in the database, and the encoding & decoding of those ids when exposing
  931. * entities via the API. The default uses a simple auto-increment integer
  932. * strategy.
  933. *
  934. * :::caution
  935. * Note: changing from an integer-based strategy to a uuid-based strategy
  936. * on an existing Vendure database will lead to problems with broken foreign-key
  937. * references. To change primary key types like this, you'll need to start with
  938. * a fresh database.
  939. * :::
  940. *
  941. * @since 1.3.0
  942. * @default AutoIncrementIdStrategy
  943. */
  944. entityIdStrategy?: EntityIdStrategy<any>;
  945. /**
  946. * @description
  947. * An array of {@link EntityDuplicator} instances which are used to duplicate entities
  948. * when using the `duplicateEntity` mutation.
  949. *
  950. * @since 2.2.0
  951. * @default defaultEntityDuplicators
  952. */
  953. entityDuplicators?: Array<EntityDuplicator<any>>;
  954. /**
  955. * @description
  956. * Defines the strategy used to store and round monetary values.
  957. *
  958. * @since 2.0.0
  959. * @default DefaultMoneyStrategy
  960. */
  961. moneyStrategy?: MoneyStrategy;
  962. /**
  963. * @description
  964. * Channels get cached in-memory as they are accessed very frequently. This
  965. * setting determines how long the cache lives (in ms) until it is considered stale and
  966. * refreshed. For multi-instance deployments (e.g. serverless, load-balanced), a
  967. * smaller value here will prevent data inconsistencies between instances.
  968. *
  969. * @since 1.3.0
  970. * @default 30000
  971. */
  972. channelCacheTtl?: number;
  973. /**
  974. * @description
  975. * Zones get cached in-memory as they are accessed very frequently. This
  976. * setting determines how long the cache lives (in ms) until it is considered stale and
  977. * refreshed. For multi-instance deployments (e.g. serverless, load-balanced), a
  978. * smaller value here will prevent data inconsistencies between instances.
  979. *
  980. * @since 1.3.0
  981. * @default 30000
  982. */
  983. zoneCacheTtl?: number;
  984. /**
  985. * @description
  986. * TaxRates get cached in-memory as they are accessed very frequently. This
  987. * setting determines how long the cache lives (in ms) until it is considered stale and
  988. * refreshed. For multi-instance deployments (e.g. serverless, load-balanced), a
  989. * smaller value here will prevent data inconsistencies between instances.
  990. *
  991. * @since 1.9.0
  992. * @default 30000
  993. */
  994. taxRateCacheTtl?: number;
  995. /**
  996. * @description
  997. * Allows the metadata of the built-in TypeORM entities to be manipulated. This allows you
  998. * to do things like altering data types, adding indices etc. This is an advanced feature
  999. * which should be used with some caution as it will result in DB schema changes. For examples
  1000. * see {@link EntityMetadataModifier}.
  1001. *
  1002. * @since 1.6.0
  1003. * @default []
  1004. */
  1005. metadataModifiers?: EntityMetadataModifier[];
  1006. }
  1007. /**
  1008. * @description
  1009. * Options relating to system functions.
  1010. *
  1011. * @since 1.6.0
  1012. * @docsCategory configuration
  1013. */
  1014. export interface SystemOptions {
  1015. /**
  1016. * @description
  1017. * Defines an array of {@link HealthCheckStrategy} instances which are used by the `/health` endpoint to verify
  1018. * that any critical systems which the Vendure server depends on are also healthy.
  1019. *
  1020. * @default [TypeORMHealthCheckStrategy]
  1021. * @since 1.6.0
  1022. */
  1023. healthChecks?: HealthCheckStrategy[];
  1024. /**
  1025. * @description
  1026. * Defines an array of {@link ErrorHandlerStrategy} instances which are used to define logic to be executed
  1027. * when an error occurs, either on the server or the worker.
  1028. *
  1029. * @default []
  1030. * @since 2.2.0
  1031. */
  1032. errorHandlers?: ErrorHandlerStrategy[];
  1033. }
  1034. /**
  1035. * @description
  1036. * All possible configuration options are defined by the
  1037. * [`VendureConfig`](https://github.com/vendure-ecommerce/vendure/blob/master/server/src/config/vendure-config.ts) interface.
  1038. *
  1039. * @docsCategory configuration
  1040. * */
  1041. export interface VendureConfig {
  1042. /**
  1043. * @description
  1044. * Configuration for the GraphQL APIs, including hostname, port, CORS settings,
  1045. * middleware etc.
  1046. */
  1047. apiOptions: ApiOptions;
  1048. /**
  1049. * @description
  1050. * Configuration for the handling of Assets.
  1051. */
  1052. assetOptions?: AssetOptions;
  1053. /**
  1054. * @description
  1055. * Configuration for authorization.
  1056. */
  1057. authOptions: AuthOptions;
  1058. /**
  1059. * @description
  1060. * Configuration for Products and Collections.
  1061. */
  1062. catalogOptions?: CatalogOptions;
  1063. /**
  1064. * @description
  1065. * Defines custom fields which can be used to extend the built-in entities.
  1066. *
  1067. * @default {}
  1068. */
  1069. customFields?: CustomFields;
  1070. /**
  1071. * @description
  1072. * The connection options used by TypeORM to connect to the database.
  1073. * See the [TypeORM documentation](https://typeorm.io/#/connection-options) for a
  1074. * full description of all available options.
  1075. */
  1076. dbConnectionOptions: DataSourceOptions;
  1077. /**
  1078. * @description
  1079. * The token for the default channel. If not specified, a token
  1080. * will be randomly generated.
  1081. *
  1082. * @default null
  1083. */
  1084. defaultChannelToken?: string | null;
  1085. /**
  1086. * @description
  1087. * The default languageCode of the app.
  1088. *
  1089. * @default LanguageCode.en
  1090. */
  1091. defaultLanguageCode?: LanguageCode;
  1092. /**
  1093. * @description
  1094. * Defines the strategy used for both storing the primary keys of entities
  1095. * in the database, and the encoding & decoding of those ids when exposing
  1096. * entities via the API. The default uses a simple auto-increment integer
  1097. * strategy.
  1098. *
  1099. * @deprecated Use entityOptions.entityIdStrategy instead
  1100. * @default AutoIncrementIdStrategy
  1101. */
  1102. entityIdStrategy?: EntityIdStrategy<any>;
  1103. entityOptions?: EntityOptions;
  1104. /**
  1105. * @description
  1106. * Configuration settings for data import and export.
  1107. */
  1108. importExportOptions?: ImportExportOptions;
  1109. /**
  1110. * @description
  1111. * Configuration settings governing how orders are handled.
  1112. */
  1113. orderOptions?: OrderOptions;
  1114. /**
  1115. * @description
  1116. * Configures available payment processing methods.
  1117. */
  1118. paymentOptions: PaymentOptions;
  1119. /**
  1120. * @description
  1121. * An array of plugins.
  1122. *
  1123. * @default []
  1124. */
  1125. plugins?: Array<DynamicModule | Type<any>>;
  1126. /**
  1127. * @description
  1128. * Configures the Conditions and Actions available when creating Promotions.
  1129. */
  1130. promotionOptions?: PromotionOptions;
  1131. /**
  1132. * @description
  1133. * Configures the available checkers and calculators for ShippingMethods.
  1134. */
  1135. shippingOptions?: ShippingOptions;
  1136. /**
  1137. * @description
  1138. * Provide a logging service which implements the {@link VendureLogger} interface.
  1139. * Note that the logging of SQL queries is controlled separately by the
  1140. * `dbConnectionOptions.logging` property.
  1141. *
  1142. * @default DefaultLogger
  1143. */
  1144. logger?: VendureLogger;
  1145. /**
  1146. * @description
  1147. * Configures how taxes are calculated on products.
  1148. */
  1149. taxOptions?: TaxOptions;
  1150. /**
  1151. * @description
  1152. * Configures how the job queue is persisted and processed.
  1153. */
  1154. jobQueueOptions?: JobQueueOptions;
  1155. /**
  1156. * @description
  1157. * Configures system options
  1158. *
  1159. * @since 1.6.0
  1160. */
  1161. systemOptions?: SystemOptions;
  1162. }
  1163. /**
  1164. * @description
  1165. * This interface represents the VendureConfig object available at run-time, i.e. the user-supplied
  1166. * config values have been merged with the {@link defaultConfig} values.
  1167. *
  1168. * @docsCategory configuration
  1169. */
  1170. export interface RuntimeVendureConfig extends Required<VendureConfig> {
  1171. apiOptions: Required<ApiOptions>;
  1172. assetOptions: Required<AssetOptions>;
  1173. authOptions: Required<AuthOptions>;
  1174. catalogOptions: Required<CatalogOptions>;
  1175. customFields: Required<CustomFields>;
  1176. entityOptions: Required<Omit<EntityOptions, 'entityIdStrategy'>> & EntityOptions;
  1177. importExportOptions: Required<ImportExportOptions>;
  1178. jobQueueOptions: Required<JobQueueOptions>;
  1179. orderOptions: Required<OrderOptions>;
  1180. promotionOptions: Required<PromotionOptions>;
  1181. shippingOptions: Required<ShippingOptions>;
  1182. taxOptions: Required<TaxOptions>;
  1183. systemOptions: Required<SystemOptions>;
  1184. }
  1185. type DeepPartialSimple<T> = {
  1186. [P in keyof T]?:
  1187. | null
  1188. | (T[P] extends Array<infer U>
  1189. ? Array<DeepPartialSimple<U>>
  1190. : T[P] extends ReadonlyArray<infer X>
  1191. ? ReadonlyArray<DeepPartialSimple<X>>
  1192. : T[P] extends Type<any>
  1193. ? T[P]
  1194. : DeepPartialSimple<T[P]>);
  1195. };
  1196. export type PartialVendureConfig = DeepPartialSimple<VendureConfig>;