-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipping-method.ts
584 lines (582 loc) · 16.2 KB
/
shipping-method.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/**
* Code generated by [commercetools RMF-Codegen](https://github.com/commercetools/rmf-codegen). DO NOT EDIT.
* Please don't change this file manually but run `rmf-codegen generate raml_file_path -o output_path -t typescript_client` to update it.
* For more information about the commercetools platform APIs, visit https://docs.commercetools.com/.
*/
import { BaseResource, CreatedBy, LastModifiedBy, LocalizedString, TypedMoney, _Money } from './common.js'
import { TaxCategoryReference, TaxCategoryResourceIdentifier } from './tax-category.js'
import { CustomFields, CustomFieldsDraft, FieldContainer, TypeResourceIdentifier } from './type.js'
import { ZoneReference, ZoneResourceIdentifier } from './zone.js'
export interface PriceFunction {
/**
* Currency code compliant to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217).
*
*
*/
readonly currencyCode: string
/**
* To calculate a Price based on the score, use `+`, `-`, `*` and parentheses. The score is inserted with `x`. The function returns the cent amount.
*
* For example, to charge $1.99 for a score of `1`, $3.99 for a score of `2`, \$5.99 for a score of `3` and onwards, the function is: `(200 * x) - 1)`. To charge $4.50, $6.00, and \$7.50 for express shipping, the function is: `(150 * x) + 300`.
*
*
*/
readonly function: string
}
export interface ShippingMethod extends BaseResource {
/**
* Unique identifier of the ShippingMethod.
*
*/
readonly id: string
/**
* Current version of the ShippingMethod.
*
*/
readonly version: number
/**
* Date and time (UTC) the ShippingMethod was initially created.
*
*/
readonly createdAt: string
/**
* Date and time (UTC) the ShippingMethod was last updated.
*
*/
readonly lastModifiedAt: string
/**
* Present on resources created after 1 February 2019 except for [events not tracked](/client-logging#events-tracked).
*
*
*/
readonly lastModifiedBy?: LastModifiedBy
/**
* Present on resources created after 1 February 2019 except for [events not tracked](/client-logging#events-tracked).
*
*
*/
readonly createdBy?: CreatedBy
/**
* User-defined unique identifier of the ShippingMethod.
*
*/
readonly key?: string
/**
* Name of the ShippingMethod.
*
*/
readonly name: string
/**
* Localized name of the ShippingMethod.
*
*/
readonly localizedName?: LocalizedString
/**
* Description of the ShippingMethod.
* @deprecated
*/
readonly description?: string
/**
* Localized description of the ShippingMethod.
*
*/
readonly localizedDescription?: LocalizedString
/**
* [TaxCategory](ctp:api:type:TaxCategory) of all ZoneRates of the ShippingMethod.
*
*
*/
readonly taxCategory: TaxCategoryReference
/**
* Defines [ShippingRates](ctp:api:type:ShippingRate) (prices) for specific Zones.
*
*/
readonly zoneRates: ZoneRate[]
/**
* If `true` this ShippingMethod is the [Project](ctp:api:type:Project)'s default ShippingMethod.
*
*/
readonly isDefault: boolean
/**
* Valid [Cart predicate](/projects/predicates#cart-predicates) to select a ShippingMethod for a Cart.
*
*
*/
readonly predicate?: string
/**
* Custom Fields of the ShippingMethod.
*
*/
readonly custom?: CustomFields
}
export interface ShippingMethodDraft {
/**
* User-defined unique identifier for the ShippingMethod.
*
*
*/
readonly key?: string
/**
* Name of the ShippingMethod.
*
*/
readonly name: string
/**
* Localized name of the ShippingMethod.
*
*/
readonly localizedName?: LocalizedString
/**
* Description of the ShippingMethod.
* @deprecated
*/
readonly description?: string
/**
* Localized description of the ShippingMethod.
*
*/
readonly localizedDescription?: LocalizedString
/**
* [TaxCategory](ctp:api:type:TaxCategory) for all ZoneRates of the ShippingMethod.
*
*
*/
readonly taxCategory: TaxCategoryResourceIdentifier
/**
* Defines [ShippingRates](ctp:api:type:ShippingRate) (prices) for specific zones.
*
*/
readonly zoneRates: ZoneRateDraft[]
/**
* If `true` the ShippingMethod will be the [Project](ctp:api:type:Project)'s default ShippingMethod.
*
*/
readonly isDefault: boolean
/**
* Valid [Cart predicate](/projects/predicates#cart-predicates) to select a ShippingMethod for a Cart.
*
*
*/
readonly predicate?: string
/**
* Custom Fields for the ShippingMethod.
*
*/
readonly custom?: CustomFieldsDraft
}
/**
* [PagedQueryResult](/general-concepts#pagedqueryresult) with `results` containing an array of [ShippingMethod](ctp:api:type:ShippingMethod).
*
*/
export interface ShippingMethodPagedQueryResponse {
/**
* Number of [results requested](/../api/general-concepts#limit).
*
*
*/
readonly limit?: number
/**
* Actual number of results returned.
*
*
*/
readonly count: number
/**
* Total number of results matching the query.
* This number is an estimation that is not [strongly consistent](/../api/general-concepts#strong-consistency).
* This field is returned by default.
* For improved performance, calculating this field can be deactivated by using the query parameter `withTotal=false`.
* When the results are filtered with a [Query Predicate](/../api/predicates/query), `total` is subject to a [limit](/../api/limits#queries).
*
*
*/
readonly total?: number
/**
* Number of [elements skipped](/../api/general-concepts#offset).
*
*
*/
readonly offset?: number
/**
* [Shipping Methods](ctp:api:type:ShippingMethod) matching the query.
*
*
*/
readonly results: ShippingMethod[]
}
/**
* [Reference](ctp:api:type:Reference) to a [ShippingMethod](ctp:api:type:ShippingMethod).
*
*/
export interface ShippingMethodReference {
readonly typeId: 'shipping-method'
/**
* Unique identifier of the referenced [ShippingMethod](ctp:api:type:ShippingMethod).
*
*
*/
readonly id: string
/**
* Contains the representation of the expanded ShippingMethod. Only present in responses to requests with [Reference Expansion](/../api/general-concepts#reference-expansion) for ShippingMethods.
*
*
*/
readonly obj?: ShippingMethod
}
/**
* [ResourceIdentifier](ctp:api:type:ResourceIdentifier) to a [ShippingMethod](ctp:api:type:ShippingMethod).
*
*/
export interface ShippingMethodResourceIdentifier {
readonly typeId: 'shipping-method'
/**
* Unique identifier of the referenced [ShippingMethod](ctp:api:type:ShippingMethod). Either `id` or `key` is required.
*
*
*/
readonly id?: string
/**
* User-defined unique identifier of the referenced [ShippingMethod](ctp:api:type:ShippingMethod). Either `id` or `key` is required.
*
*
*/
readonly key?: string
}
export interface ShippingMethodUpdate {
/**
* Expected version of the ShippingMethod on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.
*
*
*/
readonly version: number
/**
* Update actions to be performed on the [ShippingMethod](/projects/shippingMethods#shippingmethod).
*
*
*/
readonly actions: ShippingMethodUpdateAction[]
}
export type ShippingMethodUpdateAction =
| ShippingMethodAddShippingRateAction
| ShippingMethodAddZoneAction
| ShippingMethodChangeIsDefaultAction
| ShippingMethodChangeNameAction
| ShippingMethodChangeTaxCategoryAction
| ShippingMethodRemoveShippingRateAction
| ShippingMethodRemoveZoneAction
| ShippingMethodSetCustomFieldAction
| ShippingMethodSetCustomTypeAction
| ShippingMethodSetDescriptionAction
| ShippingMethodSetKeyAction
| ShippingMethodSetLocalizedDescriptionAction
| ShippingMethodSetLocalizedNameAction
| ShippingMethodSetPredicateAction
export interface ShippingRate {
/**
* Currency amount of the ShippingRate.
*
*/
readonly price: TypedMoney
/**
* Shipping is free if the sum of the (Custom) Line Item Prices reaches the specified value.
*
*/
readonly freeAbove?: TypedMoney
/**
* `true` if the ShippingRate matches given [Cart](ctp:api:type:Cart) or [Location](ctp:api:type:Location).
* Only appears in response to requests for [Get ShippingMethods for a Cart](ctp:api:endpoint:/{projectKey}/shipping-methods/matching-cart:GET) or
* [Get ShippingMethods for a Location](ctp:api:endpoint:/{projectKey}/shipping-methods/matching-location:GET).
*
*
*/
readonly isMatching?: boolean
/**
* Price tiers for the ShippingRate.
*
*/
readonly tiers: ShippingRatePriceTier[]
}
export interface ShippingRateDraft {
/**
* Money value of the ShippingRate.
*
*/
readonly price: _Money
/**
* Shipping is free if the sum of the (Custom) Line Item Prices reaches the specified value.
*
*/
readonly freeAbove?: _Money
/**
* Price tiers for the ShippingRate.
*
*/
readonly tiers?: ShippingRatePriceTier[]
}
export type ShippingRatePriceTier = CartClassificationTier | CartScoreTier | CartValueTier
/**
* Used when the ShippingRate maps to an abstract Cart categorization expressed by strings (for example, `Light`, `Medium`, or `Heavy`).
*
*/
export interface CartClassificationTier {
readonly type: 'CartClassification'
/**
* `key` selected from the `values` of the [CartClassificationType](/projects/project#cartclassificationtype) configured in the Project.
*
*
*/
readonly value: string
/**
* Fixed shipping rate for the selected classification.
*
*
*/
readonly price: _Money
/**
* Appears in response to [Get ShippingMethods for a Cart](ctp:api:endpoint:/{projectKey}/shipping-methods/matching-cart:GET) if the shipping rate matches the search query.
*
*
*/
readonly isMatching?: boolean
}
/**
* Used when the ShippingRate maps to an abstract Cart categorization expressed by integers (such as shipping scores or weight ranges).
* Either `price` or `priceFunction` is required.
*
*/
export interface CartScoreTier {
readonly type: 'CartScore'
/**
* Abstract value for categorizing a Cart. The range starts at `0`. The default price covers `0`, tiers start at `1`. See [Using Tiered Shipping Rates](/../tutorials/shipping-rate) for details and examples.
*
*
*/
readonly score: number
/**
* Defines a fixed price for the `score`.
*
*
*/
readonly price?: _Money
/**
* Dynamically calculates a Price for a range of scores.
*
*
*/
readonly priceFunction?: PriceFunction
/**
* Appears in response to [Get ShippingMethods for a Cart](ctp:api:endpoint:/{projectKey}/shipping-methods/matching-cart:GET) if the shipping rate matches the search query.
*
*
*/
readonly isMatching?: boolean
}
/**
* Used when the ShippingRate maps to the sum of [LineItem](ctp:api:type:LineItem) Prices.
* The value of the Cart is used to select a tier.
* If chosen, it is not possible to set a value for the `shippingRateInput` on the [Cart](ctp:api:type:Cart).
* Tiers contain the `centAmount` (a value of `100` in the currency `USD` corresponds to `$ 1.00`), and start at `1`.'
*
*/
export interface CartValueTier {
readonly type: 'CartValue'
/**
* Minimum total price of a Cart for which a shipping rate applies.
*
*
*/
readonly minimumCentAmount: number
/**
* Fixed shipping rate Price for a CartValue.
*
*
*/
readonly price: _Money
/**
* Appears in response to [Get ShippingMethods for a Cart](ctp:api:endpoint:/{projectKey}/shipping-methods/matching-cart:GET) if the shipping rate matches the search query.
*
*
*/
readonly isMatching?: boolean
}
export type ShippingRateTierType = 'CartClassification' | 'CartScore' | 'CartValue' | string
/**
* Defines shipping rates in different currencies for a specific [Zone](ctp:api:type:Zone).
*
*/
export interface ZoneRate {
/**
* [Zone](ctp:api:type:Zone) for which the shipping rates are valid.
*
*
*/
readonly zone: ZoneReference
/**
* Shipping rates defined per currency.
*
*
*/
readonly shippingRates: ShippingRate[]
}
export interface ZoneRateDraft {
/**
* Sets the [Zone](ctp:api:type:Zone) for which the shippng rates are valid.
*
*
*/
readonly zone: ZoneResourceIdentifier
/**
* Shipping rates for the `currencies` configured in the [Project](ctp:api:type:Project). The array must not contain two ShippingRates with the same [CurrencyCode](ctp:api:type:CurrencyCode).
*
*
*/
readonly shippingRates: ShippingRateDraft[]
}
export interface ShippingMethodAddShippingRateAction {
readonly action: 'addShippingRate'
/**
* [Zone](ctp:api:type:Zone) to which the ShippingRate should be added.
*
*
*/
readonly zone: ZoneResourceIdentifier
/**
* Value to add to `shippingRates`.
*
*/
readonly shippingRate: ShippingRateDraft
}
export interface ShippingMethodAddZoneAction {
readonly action: 'addZone'
/**
* Value to add to `zoneRates`.
*
*
*/
readonly zone: ZoneResourceIdentifier
}
export interface ShippingMethodChangeIsDefaultAction {
readonly action: 'changeIsDefault'
/**
* Value to set. Only one ShippingMethod can be default in a [Project](ctp:api:type:Project).
*
*
*/
readonly isDefault: boolean
}
export interface ShippingMethodChangeNameAction {
readonly action: 'changeName'
/**
* Value to set. Must not be empty.
*
*/
readonly name: string
}
export interface ShippingMethodChangeTaxCategoryAction {
readonly action: 'changeTaxCategory'
/**
* Value to set.
*
*/
readonly taxCategory: TaxCategoryResourceIdentifier
}
export interface ShippingMethodRemoveShippingRateAction {
readonly action: 'removeShippingRate'
/**
* [Zone](ctp:api:type:Zone) from which the ShippingRate should be removed.
*
*
*/
readonly zone: ZoneResourceIdentifier
/**
* Value to remove from `shippingRates`.
*
*/
readonly shippingRate: ShippingRateDraft
}
export interface ShippingMethodRemoveZoneAction {
readonly action: 'removeZone'
/**
* Value to remove from `zoneRates`.
*
*
*/
readonly zone: ZoneResourceIdentifier
}
/**
* This action sets, overwrites, or removes any existing [Custom Field](/projects/custom-fields) for an existing ShippingMethod.
*
*/
export interface ShippingMethodSetCustomFieldAction {
readonly action: 'setCustomField'
/**
* Name of the [Custom Field](/../api/projects/custom-fields).
*
*
*/
readonly name: string
/**
* If `value` is absent or `null`, this field will be removed if it exists.
* Removing a field that does not exist returns an [InvalidOperation](ctp:api:type:InvalidOperationError) error.
* If `value` is provided, it is set for the field defined by `name`.
*
*
*/
readonly value?: any
}
export interface ShippingMethodSetCustomTypeAction {
readonly action: 'setCustomType'
/**
* Defines the [Type](ctp:api:type:Type) that extends the ShippingMethod with [Custom Fields](/../api/projects/custom-fields).
* If absent, any existing Type and Custom Fields are removed from the ShippingMethod.
*
*
*/
readonly type?: TypeResourceIdentifier
/**
* Sets the [Custom Fields](/../api/projects/custom-fields) fields for the ShippingMethod.
*
*
*/
readonly fields?: FieldContainer
}
export interface ShippingMethodSetDescriptionAction {
readonly action: 'setDescription'
/**
* Value to set. If empty, any existing value will be removed.
*
*/
readonly description?: string
}
export interface ShippingMethodSetKeyAction {
readonly action: 'setKey'
/**
* If `key` is absent or `null`, the existing key, if any, will be removed.
*
*/
readonly key?: string
}
export interface ShippingMethodSetLocalizedDescriptionAction {
readonly action: 'setLocalizedDescription'
/**
* Value to set. If empty, any existing value will be removed.
*
*/
readonly localizedDescription?: LocalizedString
}
export interface ShippingMethodSetLocalizedNameAction {
readonly action: 'setLocalizedName'
/**
* Value to set. If empty, any existing value will be removed.
*
*/
readonly localizedName?: LocalizedString
}
export interface ShippingMethodSetPredicateAction {
readonly action: 'setPredicate'
/**
* A valid [Cart predicate](/projects/predicates#cart-predicates). If `predicate` is absent or `null`, it is removed if it exists.
*
*/
readonly predicate?: string
}