shared-types.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // tslint:disable:no-shadowed-variable
  2. // prettier-ignore
  3. import { LanguageCode } from './generated-types';
  4. /**
  5. * A recursive implementation of the Partial<T> type.
  6. * Source: https://stackoverflow.com/a/49936686/772859
  7. */
  8. export type DeepPartial<T> = {
  9. [P in keyof T]?:
  10. | null
  11. | (T[P] extends Array<infer U>
  12. ? Array<DeepPartial<U>>
  13. : T[P] extends ReadonlyArray<infer U>
  14. ? ReadonlyArray<DeepPartial<U>>
  15. : DeepPartial<T[P]>)
  16. };
  17. // tslint:enable:no-shadowed-variable
  18. // tslint:disable:ban-types
  19. /**
  20. * A recursive implementation of Required<T>.
  21. * Source: https://github.com/microsoft/TypeScript/issues/15012#issuecomment-365453623
  22. */
  23. export type DeepRequired<T, U extends object | undefined = undefined> = T extends object
  24. ? {
  25. [P in keyof T]-?: NonNullable<T[P]> extends NonNullable<U | Function | Type<any>>
  26. ? NonNullable<T[P]>
  27. : DeepRequired<NonNullable<T[P]>, U>
  28. }
  29. : T;
  30. // tslint:enable:ban-types
  31. /**
  32. * A type representing the type rather than instance of a class.
  33. */
  34. export interface Type<T> extends Function {
  35. // tslint:disable-next-line:callable-types
  36. new (...args: any[]): T;
  37. }
  38. /**
  39. * A type describing the shape of a paginated list response
  40. */
  41. export type PaginatedList<T> = {
  42. items: T[];
  43. totalItems: number;
  44. };
  45. /**
  46. * @description
  47. * An entity ID. Depending on the configured {@link EntityIdStrategy}, it will be either
  48. * a `string` or a `number`;
  49. *
  50. * @docsCategory common
  51. */
  52. export type ID = string | number;
  53. /**
  54. * @description
  55. * A data type for a custom field. The CustomFieldType determines the data types used in the generated
  56. * database columns and GraphQL fields as follows (key: m = MySQL, p = Postgres, s = SQLite):
  57. *
  58. * Type | DB type | GraphQL type
  59. * ----- |--------- |---------------
  60. * string | varchar | String
  61. * localeString | varchar | String
  62. * int | int | Int
  63. * float | double precision | Float
  64. * boolean | tinyint (m), bool (p), boolean (s) | Boolean
  65. * datetime | datetime (m,s), timestamp (p) | DateTime
  66. *
  67. * Additionally, the CustomFieldType also dictates which [configuration options](/docs/typescript-api/custom-fields/#configuration-options)
  68. * are available for that custom field.
  69. *
  70. * @docsCategory custom-fields
  71. */
  72. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  73. /**
  74. * @description
  75. * Certain entities (those which implement {@link ConfigurableOperationDef}) allow arbitrary
  76. * configuration arguments to be specified which can then be set in the admin-ui and used in
  77. * the business logic of the app. These are the valid data types of such arguments.
  78. * The data type influences:
  79. *
  80. * 1. How the argument form field is rendered in the admin-ui
  81. * 2. The JavaScript type into which the value is coerced before being passed to the business logic.
  82. *
  83. * @docsCategory common
  84. * @docsPage Configurable Operations
  85. */
  86. export type ConfigArgType = 'string' | 'int' | 'float' | 'boolean' | 'datetime' | 'facetValueIds';
  87. export type ConfigArgSubset<T extends ConfigArgType> = T;
  88. export type CustomFieldsObject = { [key: string]: any };
  89. /**
  90. * @description
  91. * This interface describes JSON config file (vendure-ui-config.json) used by the Admin UI.
  92. * The values are loaded at run-time by the Admin UI app, and allow core configuration to be
  93. * managed without the need to re-build the application.
  94. *
  95. * @docsCategory AdminUiPlugin
  96. */
  97. export interface AdminUiConfig {
  98. /**
  99. * @description
  100. * The hostname of the Vendure server which the admin ui will be making API calls
  101. * to. If set to "auto", the Admin UI app will determine the hostname from the
  102. * current location (i.e. `window.location.hostname`).
  103. *
  104. * @default 'http://localhost'
  105. */
  106. apiHost: string | 'auto';
  107. /**
  108. * @description
  109. * The port of the Vendure server which the admin ui will be making API calls
  110. * to. If set to "auto", the Admin UI app will determine the port from the
  111. * current location (i.e. `window.location.port`).
  112. *
  113. * @default 3000
  114. */
  115. apiPort: number | 'auto';
  116. /**
  117. * @description
  118. * The path to the GraphQL Admin API.
  119. *
  120. * @default 'admin-api'
  121. */
  122. adminApiPath: string;
  123. /**
  124. * @description
  125. * Whether to use cookies or bearer tokens to track sessions.
  126. * Should match the setting of in the server's `tokenMethod` config
  127. * option.
  128. *
  129. * @default 'cookie'
  130. */
  131. tokenMethod: 'cookie' | 'bearer';
  132. /**
  133. * @description
  134. * The header used when using the 'bearer' auth method. Should match the
  135. * setting of the server's `authOptions.authTokenHeaderKey` config
  136. * option.
  137. *
  138. * @default 'vendure-auth-token'
  139. */
  140. authTokenHeaderKey: string;
  141. /**
  142. * @description
  143. * The default language for the Admin UI. Must be one of the
  144. * items specified in the `availableLanguages` property.
  145. *
  146. * @default LanguageCode.en
  147. */
  148. defaultLanguage: LanguageCode;
  149. /**
  150. * @description
  151. * An array of languages for which translations exist for the Admin UI.
  152. *
  153. * @default [LanguageCode.en, LanguageCode.es]
  154. */
  155. availableLanguages: LanguageCode[];
  156. }
  157. /**
  158. * @description
  159. * Configures the path to a custom-build of the Admin UI app.
  160. *
  161. * @docsCategory common
  162. */
  163. export interface AdminUiAppConfig {
  164. /**
  165. * @description
  166. * The path to the compiled admin ui app files. If not specified, an internal
  167. * default build is used. This path should contain the `vendure-ui-config.json` file,
  168. * index.html, the compiled js bundles etc.
  169. */
  170. path: string;
  171. /**
  172. * @description
  173. * The function which will be invoked to start the app compilation process.
  174. */
  175. compile?: () => Promise<void>;
  176. }
  177. /**
  178. * @description
  179. * Information about the Admin UI app dev server.
  180. *
  181. * @docsCategory common
  182. */
  183. export interface AdminUiAppDevModeConfig {
  184. /**
  185. * @description
  186. * The path to the uncompiled ui app source files. This path should contain the `vendure-ui-config.json` file.
  187. */
  188. sourcePath: string;
  189. /**
  190. * @description
  191. * The port on which the dev server is listening. Overrides the value set by `AdminUiOptions.port`.
  192. */
  193. port: number;
  194. /**
  195. * @description
  196. * The function which will be invoked to start the app compilation process.
  197. */
  198. compile: () => Promise<void>;
  199. }