@sixtyninecommerce/admin 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +4347 -171
  2. package/dist/catalog/assets.d.ts +120 -8
  3. package/dist/catalog/assets.js +98 -12
  4. package/dist/catalog/collections.d.ts +279 -14
  5. package/dist/catalog/collections.js +246 -15
  6. package/dist/catalog/index.d.ts +9 -2
  7. package/dist/catalog/index.js +4 -0
  8. package/dist/catalog/products.d.ts +159 -19
  9. package/dist/catalog/products.js +88 -13
  10. package/dist/catalog/properties.d.ts +102 -14
  11. package/dist/catalog/properties.js +13 -0
  12. package/dist/catalog/recommendations.d.ts +261 -0
  13. package/dist/catalog/recommendations.js +145 -0
  14. package/dist/catalog/reviews.d.ts +368 -0
  15. package/dist/catalog/reviews.js +318 -0
  16. package/dist/catalog/types.d.ts +17 -1
  17. package/dist/catalog/types.js +10 -0
  18. package/dist/catalog/variant-find.d.ts +136 -0
  19. package/dist/catalog/variant-find.js +239 -0
  20. package/dist/catalog/variants.d.ts +233 -26
  21. package/dist/catalog/variants.js +125 -7
  22. package/dist/catalog/visibility.d.ts +20 -5
  23. package/dist/catalog/visibility.js +19 -1
  24. package/dist/client.d.ts +95 -9
  25. package/dist/client.js +35 -7
  26. package/dist/content/assets.d.ts +286 -0
  27. package/dist/content/assets.js +181 -0
  28. package/dist/content/items.d.ts +269 -0
  29. package/dist/content/items.js +170 -0
  30. package/dist/content/types.d.ts +282 -0
  31. package/dist/content/types.js +100 -0
  32. package/dist/customers/age-verification.d.ts +66 -0
  33. package/dist/customers/age-verification.js +79 -0
  34. package/dist/customers/credit.d.ts +263 -0
  35. package/dist/customers/credit.js +244 -0
  36. package/dist/customers/delivery-preferences.d.ts +120 -0
  37. package/dist/customers/delivery-preferences.js +97 -0
  38. package/dist/customers/groups.d.ts +207 -0
  39. package/dist/customers/groups.js +438 -0
  40. package/dist/customers/index.d.ts +447 -37
  41. package/dist/customers/index.js +313 -40
  42. package/dist/customers/invitation-status.d.ts +57 -0
  43. package/dist/customers/invitation-status.js +21 -0
  44. package/dist/customers/notes.d.ts +67 -0
  45. package/dist/customers/notes.js +51 -0
  46. package/dist/customers/notification-recipients.d.ts +97 -0
  47. package/dist/customers/notification-recipients.js +84 -0
  48. package/dist/customers/saved-lists.d.ts +42 -0
  49. package/dist/customers/saved-lists.js +61 -0
  50. package/dist/customers/vat.d.ts +83 -0
  51. package/dist/customers/vat.js +46 -0
  52. package/dist/customers/wire.d.ts +20 -0
  53. package/dist/customers/wire.js +35 -0
  54. package/dist/documents/ar.d.ts +307 -0
  55. package/dist/documents/ar.js +254 -0
  56. package/dist/documents/index.d.ts +731 -21
  57. package/dist/documents/index.js +436 -24
  58. package/dist/documents/pdf.d.ts +2 -0
  59. package/dist/documents/pdf.js +11 -0
  60. package/dist/fulfillments/create.d.ts +167 -0
  61. package/dist/fulfillments/create.js +216 -0
  62. package/dist/fulfillments/index.d.ts +44 -10
  63. package/dist/fulfillments/index.js +11 -2
  64. package/dist/fulfillments/payment-policy.d.ts +64 -0
  65. package/dist/fulfillments/payment-policy.js +140 -0
  66. package/dist/fulfillments/warehouse.d.ts +724 -0
  67. package/dist/fulfillments/warehouse.js +914 -0
  68. package/dist/geo/index.d.ts +119 -0
  69. package/dist/geo/index.js +107 -0
  70. package/dist/index.d.ts +123 -35
  71. package/dist/index.js +45 -12
  72. package/dist/integrations/afas-actions.d.ts +234 -0
  73. package/dist/integrations/afas-actions.js +310 -0
  74. package/dist/integrations/afas-types.d.ts +483 -0
  75. package/dist/integrations/afas-types.js +5 -0
  76. package/dist/integrations/afas.d.ts +234 -0
  77. package/dist/integrations/afas.js +290 -0
  78. package/dist/integrations/connections.d.ts +103 -0
  79. package/dist/integrations/connections.js +55 -0
  80. package/dist/integrations/esp.d.ts +313 -0
  81. package/dist/integrations/esp.js +169 -0
  82. package/dist/integrations/exact-online-types.d.ts +423 -0
  83. package/dist/integrations/exact-online-types.js +6 -0
  84. package/dist/integrations/exact-online.d.ts +248 -0
  85. package/dist/integrations/exact-online.js +376 -0
  86. package/dist/integrations/index.d.ts +29 -3
  87. package/dist/integrations/index.js +18 -3
  88. package/dist/integrations/pipeline-keys.d.ts +13 -0
  89. package/dist/integrations/pipeline-keys.js +22 -0
  90. package/dist/integrations/pipelines.d.ts +15 -14
  91. package/dist/integrations/pipelines.js +6 -22
  92. package/dist/integrations/types.d.ts +146 -0
  93. package/dist/locations/index.d.ts +66 -0
  94. package/dist/locations/index.js +31 -0
  95. package/dist/meta/index.d.ts +162 -0
  96. package/dist/orders/cancel-with-money.d.ts +227 -0
  97. package/dist/orders/cancel-with-money.js +153 -0
  98. package/dist/orders/commit-edit.d.ts +7 -1
  99. package/dist/orders/commit-edit.js +5 -1
  100. package/dist/orders/drafts.d.ts +800 -0
  101. package/dist/orders/drafts.js +771 -0
  102. package/dist/orders/fields.d.ts +245 -0
  103. package/dist/orders/fields.js +188 -0
  104. package/dist/orders/get.d.ts +29 -19
  105. package/dist/orders/get.js +17 -8
  106. package/dist/orders/index.d.ts +49 -9
  107. package/dist/orders/index.js +22 -2
  108. package/dist/orders/lifecycle.d.ts +128 -0
  109. package/dist/orders/lifecycle.js +158 -0
  110. package/dist/orders/line-price-preview.d.ts +7 -2
  111. package/dist/orders/list.d.ts +222 -0
  112. package/dist/orders/list.js +377 -0
  113. package/dist/orders/manual-pricing.d.ts +5 -0
  114. package/dist/orders/order-entry.d.ts +20 -7
  115. package/dist/orders/plan-edit.d.ts +1 -1
  116. package/dist/orders/plan-edit.js +4 -1
  117. package/dist/orders/settings.d.ts +201 -0
  118. package/dist/orders/settings.js +325 -0
  119. package/dist/orders/status.d.ts +159 -13
  120. package/dist/orders/status.js +21 -0
  121. package/dist/orders/surcharges.d.ts +8 -1
  122. package/dist/orders/surcharges.js +3 -2
  123. package/dist/payments/account-credit.d.ts +30 -0
  124. package/dist/payments/account-credit.js +19 -0
  125. package/dist/payments/ar.d.ts +292 -0
  126. package/dist/payments/ar.js +223 -0
  127. package/dist/payments/connected-account.d.ts +47 -0
  128. package/dist/payments/connected-account.js +61 -0
  129. package/dist/payments/credit-noted-fields.d.ts +12 -0
  130. package/dist/payments/credit-noted-fields.js +37 -0
  131. package/dist/payments/index.d.ts +257 -11
  132. package/dist/payments/index.js +131 -1
  133. package/dist/payments/methods.d.ts +303 -8
  134. package/dist/payments/methods.js +337 -7
  135. package/dist/payments/mollie-methods.d.ts +159 -0
  136. package/dist/payments/mollie-methods.js +141 -0
  137. package/dist/payments/payment-links.d.ts +180 -0
  138. package/dist/payments/payment-links.js +97 -0
  139. package/dist/payments/provider-keys.d.ts +150 -0
  140. package/dist/payments/provider-keys.js +118 -0
  141. package/dist/payments/providers.d.ts +86 -11
  142. package/dist/payments/providers.js +29 -0
  143. package/dist/payments/requests.d.ts +144 -0
  144. package/dist/payments/requests.js +92 -0
  145. package/dist/payments/store-credit-fields.d.ts +15 -0
  146. package/dist/payments/store-credit-fields.js +51 -0
  147. package/dist/pickups/index.d.ts +104 -0
  148. package/dist/pickups/index.js +105 -0
  149. package/dist/platform/channels.d.ts +132 -0
  150. package/dist/platform/channels.js +128 -0
  151. package/dist/platform/geo.d.ts +123 -0
  152. package/dist/platform/geo.js +144 -0
  153. package/dist/platform/tax.d.ts +154 -0
  154. package/dist/platform/tax.js +139 -0
  155. package/dist/pos/anomalies.d.ts +158 -0
  156. package/dist/pos/anomalies.js +64 -0
  157. package/dist/pos/assisted-selling.d.ts +79 -0
  158. package/dist/pos/assisted-selling.js +38 -0
  159. package/dist/pos/exchanges.d.ts +103 -0
  160. package/dist/pos/exchanges.js +22 -0
  161. package/dist/pos/gift-cards.d.ts +135 -0
  162. package/dist/pos/gift-cards.js +47 -0
  163. package/dist/pos/index.d.ts +2125 -32
  164. package/dist/pos/index.js +742 -4
  165. package/dist/pos/no-receipt.d.ts +94 -0
  166. package/dist/pos/no-receipt.js +25 -0
  167. package/dist/pos/offline-sales.d.ts +187 -0
  168. package/dist/pos/offline-sales.js +116 -0
  169. package/dist/pos/pay-by-link.d.ts +143 -0
  170. package/dist/pos/pay-by-link.js +57 -0
  171. package/dist/pos/quick-keys.d.ts +103 -0
  172. package/dist/pos/quick-keys.js +45 -0
  173. package/dist/pos/reports.d.ts +360 -0
  174. package/dist/pos/reports.js +62 -0
  175. package/dist/pos/returns.d.ts +217 -0
  176. package/dist/pos/returns.js +53 -0
  177. package/dist/pricing/bulk-coupons.d.ts +139 -0
  178. package/dist/pricing/bulk-coupons.js +112 -0
  179. package/dist/pricing/index.d.ts +174 -4
  180. package/dist/pricing/index.js +174 -1
  181. package/dist/pricing/price-lists.d.ts +604 -0
  182. package/dist/pricing/price-lists.js +600 -0
  183. package/dist/purchasing/alerts.d.ts +89 -0
  184. package/dist/purchasing/alerts.js +62 -0
  185. package/dist/purchasing/cost.d.ts +110 -0
  186. package/dist/purchasing/cost.js +86 -0
  187. package/dist/purchasing/index.d.ts +36 -0
  188. package/dist/purchasing/index.js +16 -0
  189. package/dist/purchasing/purchase-orders.d.ts +548 -0
  190. package/dist/purchasing/purchase-orders.js +491 -0
  191. package/dist/purchasing/replenishment.d.ts +281 -0
  192. package/dist/purchasing/replenishment.js +240 -0
  193. package/dist/purchasing/settings.d.ts +152 -0
  194. package/dist/purchasing/settings.js +181 -0
  195. package/dist/purchasing/suppliers.d.ts +476 -0
  196. package/dist/purchasing/suppliers.js +438 -0
  197. package/dist/quotes/index.d.ts +501 -0
  198. package/dist/quotes/index.js +439 -0
  199. package/dist/reports/index.d.ts +71 -8
  200. package/dist/reports/index.js +74 -11
  201. package/dist/returns/index.d.ts +614 -21
  202. package/dist/returns/index.js +695 -11
  203. package/dist/search/index.d.ts +76 -1
  204. package/dist/search/index.js +63 -0
  205. package/dist/shipping/definitions.d.ts +29 -0
  206. package/dist/shipping/definitions.js +47 -0
  207. package/dist/shipping/fulfillment-profiles.d.ts +174 -0
  208. package/dist/shipping/fulfillment-profiles.js +104 -0
  209. package/dist/shipping/hendriks.d.ts +97 -0
  210. package/dist/shipping/hendriks.js +50 -0
  211. package/dist/shipping/index.d.ts +48 -0
  212. package/dist/shipping/index.js +25 -0
  213. package/dist/shipping/methods.d.ts +198 -0
  214. package/dist/shipping/methods.js +240 -0
  215. package/dist/shipping/myparcel.d.ts +254 -0
  216. package/dist/shipping/myparcel.js +178 -0
  217. package/dist/shipping/parcel-count-suggestion.d.ts +2 -0
  218. package/dist/shipping/parcel-rule.d.ts +6 -5
  219. package/dist/shipping/parcel-rule.js +21 -23
  220. package/dist/shipping/rate-tables.d.ts +179 -0
  221. package/dist/shipping/rate-tables.js +184 -0
  222. package/dist/stock/index.d.ts +10 -3
  223. package/dist/stock/index.js +3 -0
  224. package/dist/stock/locations.d.ts +144 -0
  225. package/dist/stock/locations.js +168 -0
  226. package/dist/stock/transfers.d.ts +216 -43
  227. package/dist/stock/transfers.js +140 -13
  228. package/dist/stored-value/index.d.ts +214 -4
  229. package/dist/stored-value/index.js +152 -0
  230. package/dist/subscriptions/index.d.ts +682 -0
  231. package/dist/subscriptions/index.js +815 -0
  232. package/dist/tax/index.d.ts +76 -1
  233. package/dist/tax/index.js +50 -0
  234. package/dist/tenant/email-style.d.ts +102 -0
  235. package/dist/tenant/email-style.js +72 -0
  236. package/dist/tenant/email-templates.d.ts +66 -0
  237. package/dist/tenant/email-templates.js +54 -0
  238. package/dist/tenant/notifications.d.ts +23 -17
  239. package/dist/tenant/settings-sources.d.ts +1 -1
  240. package/dist/tenant/time-zone.d.ts +17 -0
  241. package/dist/tenant/time-zone.js +11 -0
  242. package/dist/types.d.ts +50 -3
  243. package/dist/users/index.d.ts +3 -0
  244. package/dist/users/index.js +2 -0
  245. package/dist/users/warehouses.d.ts +50 -0
  246. package/dist/users/warehouses.js +51 -0
  247. package/package.json +2 -2
@@ -19,6 +19,11 @@ export interface Asset {
19
19
  y: number;
20
20
  } | null;
21
21
  tags: string[];
22
+ /**
23
+ * The image's alt text: the store's default-language description
24
+ * ({@link AssetDescriptionsModule}); null when it has none.
25
+ */
26
+ altText: string | null;
22
27
  /** The store's own asset, or its organization's; see {@link CatalogueOwnership}. */
23
28
  catalogueOwnership: CatalogueOwnership;
24
29
  }
@@ -92,11 +97,79 @@ export interface AssetDescriptionsModule {
92
97
  */
93
98
  set(assetId: string, descriptions: readonly AssetDescription[], options?: Call): Promise<AssetDescriptionsResult>;
94
99
  }
100
+ /** What an asset list can be sorted by. */
101
+ export type AssetSortField = 'createdAt' | 'updatedAt' | 'name' | 'fileSize' | 'id';
102
+ export declare const ASSET_SORT_FIELDS: readonly AssetSortField[];
95
103
  export interface AssetListOptions extends ListOptions {
96
104
  /** Case-insensitive substring of the name. */
97
105
  name?: string;
98
106
  /** Assets carrying ALL of these tags. */
99
107
  tags?: string[];
108
+ /**
109
+ * Only these assets. An id the store does not hold is left out, never an error; an empty list
110
+ * answers an empty page without asking the engine.
111
+ */
112
+ ids?: readonly string[];
113
+ /**
114
+ * ONE sort key; the engine's own order when omitted. `createdAt` `DESC` lists the newest
115
+ * upload first. Anything else is refused before sending (`ValidationError`,
116
+ * `INVALID_ASSET_SORT`).
117
+ */
118
+ sort?: {
119
+ field: AssetSortField;
120
+ direction: 'ASC' | 'DESC';
121
+ };
122
+ }
123
+ /** A tag of the store's asset library. Tags belong to one store. */
124
+ export interface AssetTag {
125
+ id: string;
126
+ value: string;
127
+ createdAt: string;
128
+ updatedAt: string;
129
+ }
130
+ export interface AssetTagListOptions extends ListOptions {
131
+ /** Case-insensitive substring of the value. */
132
+ value?: string;
133
+ }
134
+ /**
135
+ * The store's asset tags: the registry an asset's `tags` draw from. Setting `tags` on an
136
+ * asset's own `create` / `update` adds a value the store does not have yet; these methods manage
137
+ * the values themselves.
138
+ *
139
+ * Reads need `ReadAsset`, `ReadTag` or `ReadSettings`; each write the permission it names, or the
140
+ * matching `…Settings` one.
141
+ */
142
+ export interface AssetTagsModule {
143
+ /**
144
+ * The store's tags, a page at a time.
145
+ *
146
+ * @effect read
147
+ * @permission ReadTag
148
+ */
149
+ list(options?: AssetTagListOptions): Promise<Page<AssetTag>>;
150
+ /**
151
+ * Adds a tag value to the store.
152
+ *
153
+ * @effect write
154
+ * @permission CreateTag
155
+ */
156
+ create(value: string, options?: Call): Promise<AssetTag>;
157
+ /**
158
+ * Renames a tag: every asset of the store carrying it now carries the new value.
159
+ *
160
+ * @effect write
161
+ * @permission UpdateTag
162
+ */
163
+ update(id: string, value: string, options?: Call): Promise<AssetTag>;
164
+ /**
165
+ * Removes the tag from the store and from every asset carrying it. Nothing in the SDK brings it
166
+ * back. A refusal the engine answers as a `DeletionResponse` is `ConflictError`
167
+ * (`TAG_NOT_DELETED`).
168
+ *
169
+ * @effect destructive
170
+ * @permission DeleteTag
171
+ */
172
+ delete(id: string, options?: Call): Promise<void>;
100
173
  }
101
174
  /**
102
175
  * The asset library. Assign an asset to a product, variant or collection with
@@ -114,10 +187,42 @@ export interface AssetListOptions extends ListOptions {
114
187
  export interface AssetsModule {
115
188
  /** An image's descriptions (its alt text per language) in the store. */
116
189
  descriptions: AssetDescriptionsModule;
190
+ /** The store's asset tags. */
191
+ tags: AssetTagsModule;
192
+ /**
193
+ * The store's assets, a page at a time.
194
+ *
195
+ * @effect read
196
+ * @permission ReadAsset
197
+ */
117
198
  list(options?: AssetListOptions): Promise<Page<Asset>>;
199
+ /**
200
+ * One asset, or null when the store holds none with that id.
201
+ *
202
+ * @effect read
203
+ * @permission ReadAsset
204
+ */
118
205
  get(id: string, options?: Call): Promise<Asset | null>;
206
+ /**
207
+ * Uploads one file as an asset of the store. Never retried.
208
+ *
209
+ * @effect write
210
+ * @permission CreateAsset
211
+ */
119
212
  create(input: CreateAssetInput, options?: Call): Promise<Asset>;
213
+ /**
214
+ * @effect write
215
+ * @permission UpdateAsset
216
+ */
120
217
  update(input: UpdateAssetInput, options?: Call): Promise<Asset>;
218
+ /**
219
+ * Removes the asset. One still featured by a product or collection is refused
220
+ * (`ASSET_NOT_DELETED`) unless `force` is set, which takes it off them too. Nothing in the SDK
221
+ * brings it back.
222
+ *
223
+ * @effect destructive
224
+ * @permission DeleteAsset
225
+ */
121
226
  delete(id: string, options?: Call & {
122
227
  force?: boolean;
123
228
  }): Promise<void>;
@@ -126,21 +231,28 @@ export interface AssetsModule {
126
231
  * An asset's own fields, without `catalogueOwnership`: what a read outside the catalogue (the
127
232
  * settings images) selects, so it keeps working against an engine older than the field.
128
233
  */
129
- export declare const ASSET_FILE_FIELDS = "\n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n";
130
- export declare const ASSET_FIELDS = "\n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n";
131
- export declare const ASSETS_QUERY = "\n query CatalogAssets($options: AssetListOptions) {\n assets(options: $options) {\n items { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n totalItems\n }\n }\n";
132
- export declare const ASSET_QUERY = "\n query CatalogAsset($id: ID!) {\n asset(id: $id) { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n }\n";
133
- export declare const CREATE_ASSETS_MUTATION = "\n mutation CatalogCreateAssets($input: [CreateAssetInput!]!) {\n createAssets(input: $input) {\n ... on Asset { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n ... on ErrorResult {\n errorCode\n message\n }\n }\n }\n";
134
- export declare const UPDATE_ASSET_MUTATION = "\n mutation CatalogUpdateAsset($input: UpdateAssetInput!) {\n updateAsset(input: $input) { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n }\n";
234
+ export declare const ASSET_FILE_FIELDS = "\n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n customFields {\n altText\n }\n";
235
+ export declare const ASSET_FIELDS = "\n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n customFields {\n altText\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n";
236
+ export declare const ASSETS_QUERY = "\n query CatalogAssets($options: AssetListOptions) {\n assets(options: $options) {\n items { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n customFields {\n altText\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n totalItems\n }\n }\n";
237
+ export declare const ASSET_QUERY = "\n query CatalogAsset($id: ID!) {\n asset(id: $id) { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n customFields {\n altText\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n }\n";
238
+ export declare const CREATE_ASSETS_MUTATION = "\n mutation CatalogCreateAssets($input: [CreateAssetInput!]!) {\n createAssets(input: $input) {\n ... on Asset { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n customFields {\n altText\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n ... on ErrorResult {\n errorCode\n message\n }\n }\n }\n";
239
+ export declare const UPDATE_ASSET_MUTATION = "\n mutation CatalogUpdateAsset($input: UpdateAssetInput!) {\n updateAsset(input: $input) { \n \n id\n createdAt\n updatedAt\n name\n type\n mimeType\n fileSize\n width\n height\n source\n preview\n focalPoint {\n x\n y\n }\n tags {\n value\n }\n customFields {\n altText\n }\n\n \n catalogueOwnership {\n state\n organizationName\n editableHere\n }\n\n }\n }\n";
135
240
  export declare const DELETE_ASSET_MUTATION = "\n mutation CatalogDeleteAsset($input: DeleteAssetInput!) {\n deleteAsset(input: $input) { \n result\n message\n }\n }\n";
241
+ export declare const TAGS_QUERY = "\n query CatalogAssetTags($options: TagListOptions) {\n tags(options: $options) {\n items { \n id\n value\n createdAt\n updatedAt\n }\n totalItems\n }\n }\n";
242
+ export declare const CREATE_TAG_MUTATION = "\n mutation CatalogCreateTag($input: CreateTagInput!) {\n createTag(input: $input) { \n id\n value\n createdAt\n updatedAt\n }\n }\n";
243
+ export declare const UPDATE_TAG_MUTATION = "\n mutation CatalogUpdateTag($input: UpdateTagInput!) {\n updateTag(input: $input) { \n id\n value\n createdAt\n updatedAt\n }\n }\n";
244
+ export declare const DELETE_TAG_MUTATION = "\n mutation CatalogDeleteTag($id: ID!) {\n deleteTag(id: $id) { \n result\n message\n }\n }\n";
136
245
  export declare const SET_ASSET_DESCRIPTIONS_MUTATION = "\n mutation CatalogSetAssetDescriptions(\n $assetId: ID!\n $descriptions: [AssetDescriptionInput!]!\n ) {\n setAssetDescriptions(assetId: $assetId, descriptions: $descriptions) {\n assetId\n descriptions {\n languageCode\n description\n }\n altText\n }\n }\n";
137
246
  /** An asset as {@link ASSET_FILE_FIELDS} reads it: no `catalogueOwnership`. */
138
247
  export type AssetFile = Omit<Asset, 'catalogueOwnership'>;
139
- /** An asset as the Admin API answers it: tags as objects. */
140
- export type WireOf<T extends AssetFile> = Omit<T, 'tags'> & {
248
+ /** An asset as the Admin API answers it: tags as objects, the alt text a custom field. */
249
+ export type WireOf<T extends AssetFile> = Omit<T, 'tags' | 'altText'> & {
141
250
  tags: Array<{
142
251
  value: string;
143
252
  }>;
253
+ customFields?: {
254
+ altText?: string | null;
255
+ } | null;
144
256
  };
145
257
  export declare function toAsset(wire: WireOf<Asset>): Asset;
146
258
  export declare function toAsset(wire: WireOf<AssetFile>): AssetFile;
@@ -1,5 +1,12 @@
1
- import { UpstreamError, ValidationError } from '@sixtyninecommerce/core';
2
- import { assertDeleted, CATALOGUE_OWNERSHIP_FIELDS, DELETION_FIELDS, fieldOf, unwrapResult, vendureListPage, } from './types.js';
1
+ import { pageFromVendureList, UpstreamError, ValidationError, } from '@sixtyninecommerce/core';
2
+ import { assertDeleted, CATALOGUE_OWNERSHIP_FIELDS, DEFAULT_PAGE_SIZE, DELETION_FIELDS, fieldOf, unwrapResult, vendureListPage, } from './types.js';
3
+ export const ASSET_SORT_FIELDS = [
4
+ 'createdAt',
5
+ 'updatedAt',
6
+ 'name',
7
+ 'fileSize',
8
+ 'id',
9
+ ];
3
10
  /**
4
11
  * An asset's own fields, without `catalogueOwnership`: what a read outside the catalogue (the
5
12
  * settings images) selects, so it keeps working against an engine older than the field.
@@ -23,6 +30,9 @@ export const ASSET_FILE_FIELDS = /* GraphQL */ `
23
30
  tags {
24
31
  value
25
32
  }
33
+ customFields {
34
+ altText
35
+ }
26
36
  `;
27
37
  export const ASSET_FIELDS = /* GraphQL */ `
28
38
  ${ASSET_FILE_FIELDS}
@@ -62,6 +72,35 @@ export const DELETE_ASSET_MUTATION = /* GraphQL */ `
62
72
  deleteAsset(input: $input) { ${DELETION_FIELDS} }
63
73
  }
64
74
  `;
75
+ const TAG_FIELDS = /* GraphQL */ `
76
+ id
77
+ value
78
+ createdAt
79
+ updatedAt
80
+ `;
81
+ export const TAGS_QUERY = /* GraphQL */ `
82
+ query CatalogAssetTags($options: TagListOptions) {
83
+ tags(options: $options) {
84
+ items { ${TAG_FIELDS} }
85
+ totalItems
86
+ }
87
+ }
88
+ `;
89
+ export const CREATE_TAG_MUTATION = /* GraphQL */ `
90
+ mutation CatalogCreateTag($input: CreateTagInput!) {
91
+ createTag(input: $input) { ${TAG_FIELDS} }
92
+ }
93
+ `;
94
+ export const UPDATE_TAG_MUTATION = /* GraphQL */ `
95
+ mutation CatalogUpdateTag($input: UpdateTagInput!) {
96
+ updateTag(input: $input) { ${TAG_FIELDS} }
97
+ }
98
+ `;
99
+ export const DELETE_TAG_MUTATION = /* GraphQL */ `
100
+ mutation CatalogDeleteTag($id: ID!) {
101
+ deleteTag(id: $id) { ${DELETION_FIELDS} }
102
+ }
103
+ `;
65
104
  export const SET_ASSET_DESCRIPTIONS_MUTATION = /* GraphQL */ `
66
105
  mutation CatalogSetAssetDescriptions(
67
106
  $assetId: ID!
@@ -78,7 +117,39 @@ export const SET_ASSET_DESCRIPTIONS_MUTATION = /* GraphQL */ `
78
117
  }
79
118
  `;
80
119
  export function toAsset(wire) {
81
- return { ...wire, tags: wire.tags.map((tag) => tag.value) };
120
+ const { customFields, ...rest } = wire;
121
+ return {
122
+ ...rest,
123
+ tags: wire.tags.map((tag) => tag.value),
124
+ altText: customFields?.altText ?? null,
125
+ };
126
+ }
127
+ function invalidSort(sort) {
128
+ return new ValidationError({
129
+ code: 'INVALID_ASSET_SORT',
130
+ message: `sort must name one of ${ASSET_SORT_FIELDS.join(', ')} and the direction ASC or DESC; got ${JSON.stringify(sort)}. Nothing was sent.`,
131
+ status: 400,
132
+ service: 'vendure',
133
+ });
134
+ }
135
+ /** The `AssetListOptions` the engine takes, minus paging; refuses an unknown sort. */
136
+ function assetListOptionsOf(options) {
137
+ const sort = options?.sort;
138
+ if (sort !== undefined &&
139
+ (!ASSET_SORT_FIELDS.includes(sort.field) ||
140
+ (sort.direction !== 'ASC' && sort.direction !== 'DESC'))) {
141
+ throw invalidSort(sort);
142
+ }
143
+ const filter = {};
144
+ if (options?.name !== undefined)
145
+ filter.name = { contains: options.name };
146
+ if (options?.ids !== undefined)
147
+ filter.id = { in: [...options.ids] };
148
+ return {
149
+ ...(Object.keys(filter).length > 0 ? { filter } : {}),
150
+ ...(options?.tags !== undefined ? { tags: options.tags, tagsOperator: 'AND' } : {}),
151
+ ...(sort === undefined ? {} : { sort: { [sort.field]: sort.direction } }),
152
+ };
82
153
  }
83
154
  /** A `File` without depending on the DOM lib: anything Blob-like carrying a `name`. */
84
155
  function nameOf(file) {
@@ -106,16 +177,31 @@ export function createAssetsModule(transport) {
106
177
  })),
107
178
  }, options),
108
179
  },
109
- list: (options) => vendureListPage(transport, ASSETS_QUERY, 'assets', (skip, take) => ({
110
- options: {
111
- skip,
112
- take,
113
- ...(options?.name !== undefined
114
- ? { filter: { name: { contains: options.name } } }
115
- : {}),
116
- ...(options?.tags !== undefined ? { tags: options.tags, tagsOperator: 'AND' } : {}),
180
+ tags: {
181
+ list: (options) => vendureListPage(transport, TAGS_QUERY, 'tags', (skip, take) => ({
182
+ options: {
183
+ skip,
184
+ take,
185
+ ...(options?.value !== undefined
186
+ ? { filter: { value: { contains: options.value } } }
187
+ : {}),
188
+ },
189
+ }), options),
190
+ create: (value, options) => fieldOf(transport, CREATE_TAG_MUTATION, 'createTag', { input: { value } }, options),
191
+ update: (id, value, options) => fieldOf(transport, UPDATE_TAG_MUTATION, 'updateTag', { input: { id, value } }, options),
192
+ async delete(id, options) {
193
+ const response = await fieldOf(transport, DELETE_TAG_MUTATION, 'deleteTag', { id }, options);
194
+ assertDeleted('TAG_NOT_DELETED', [response]);
117
195
  },
118
- }), options, toAsset),
196
+ },
197
+ async list(options) {
198
+ // Checked before anything is sent: an unknown sort never reaches the engine.
199
+ const listOptions = assetListOptionsOf(options);
200
+ if (options?.ids !== undefined && options.ids.length === 0) {
201
+ return pageFromVendureList({ items: [], totalItems: 0 }, 0, options.limit ?? DEFAULT_PAGE_SIZE, () => Promise.reject(new Error('an empty page has no next page')));
202
+ }
203
+ return vendureListPage(transport, ASSETS_QUERY, 'assets', (skip, take) => ({ options: { skip, take, ...listOptions } }), options, toAsset);
204
+ },
119
205
  async get(id, options) {
120
206
  const wire = await fieldOf(transport, ASSET_QUERY, 'asset', { id }, options);
121
207
  return wire ? toAsset(wire) : null;