shared-types.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // tslint:disable:no-shadowed-variable
  2. // prettier-ignore
  3. /**
  4. * A recursive implementation of the Partial<T> type.
  5. * Source: https://stackoverflow.com/a/49936686/772859
  6. */
  7. export type DeepPartial<T> = {
  8. [P in keyof T]?: null | (T[P] extends Array<infer U>
  9. ? Array<DeepPartial<U>>
  10. : T[P] extends ReadonlyArray<infer U>
  11. ? ReadonlyArray<DeepPartial<U>>
  12. : DeepPartial<T[P]>)
  13. };
  14. // tslint:enable:no-shadowed-variable
  15. /**
  16. * A type representing the type rather than instance of a class.
  17. */
  18. export interface Type<T> extends Function {
  19. new (...args: any[]): T;
  20. }
  21. /**
  22. * A type describing the shape of a paginated list response
  23. */
  24. export type PaginatedList<T> = {
  25. items: T[];
  26. totalItems: number;
  27. };
  28. /**
  29. * @description
  30. * An entity ID. Depending on the configured {@link EntityIdStrategy}, it will be either
  31. * a `string` or a `number`;
  32. *
  33. * @docsCategory entities
  34. * @docsWeight 0
  35. */
  36. export type ID = string | number;
  37. /**
  38. * @description
  39. * A data type for a custom field.
  40. *
  41. * @docsCategory custom-fields
  42. */
  43. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  44. /**
  45. * @description
  46. * Configures a custom field on an entity in the {@link CustomFields} config object.
  47. *
  48. * @docsCategory custom-fields
  49. */
  50. export interface CustomFieldConfig {
  51. name: string;
  52. type: CustomFieldType;
  53. }
  54. /**
  55. * @description
  56. * Most entities can have additional fields added to them by defining an array of {@link CustomFieldConfig}
  57. * objects on against the corresponding key.
  58. *
  59. * @example
  60. * ```TypeScript
  61. * bootstrap({
  62. * // ...
  63. * customFields: {
  64. * Product: [
  65. * { name: 'infoUrl', type: 'string' },
  66. * { name: 'downloadable', type: 'boolean' },
  67. * { name: 'shortName', type: 'localeString' },
  68. * ],
  69. * User: [
  70. * { name: 'socialLoginToken', type: 'string' },
  71. * ],
  72. * },
  73. * })
  74. * ```
  75. *
  76. * @docsCategory custom-fields
  77. */
  78. export interface CustomFields {
  79. Address?: CustomFieldConfig[];
  80. Collection?: CustomFieldConfig[];
  81. Customer?: CustomFieldConfig[];
  82. Facet?: CustomFieldConfig[];
  83. FacetValue?: CustomFieldConfig[];
  84. GlobalSettings?: CustomFieldConfig[];
  85. OrderLine?: CustomFieldConfig[];
  86. Product?: CustomFieldConfig[];
  87. ProductOption?: CustomFieldConfig[];
  88. ProductOptionGroup?: CustomFieldConfig[];
  89. ProductVariant?: CustomFieldConfig[];
  90. User?: CustomFieldConfig[];
  91. }
  92. /**
  93. * This interface should be implemented by any entity which can be extended
  94. * with custom fields.
  95. */
  96. export interface HasCustomFields {
  97. customFields: CustomFieldsObject;
  98. }
  99. export type MayHaveCustomFields = Partial<HasCustomFields>;
  100. export type CustomFieldsObject = { [key: string]: any; };
  101. /**
  102. * This interface describes the shape of the JSON config file used by the Admin UI.
  103. */
  104. export interface AdminUiConfig {
  105. apiHost: string | 'auto';
  106. apiPort: number | 'auto';
  107. adminApiPath: string;
  108. }