@labdigital/commercetools-mock 1.1.3 → 1.3.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.
- package/dist/index.d.mts +602 -0
- package/dist/index.d.ts +43 -26
- package/dist/index.global.js +6322 -6084
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +347 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +343 -163
- package/dist/index.mjs.map +1 -1
- package/package.json +35 -41
- package/src/index.test.ts +2 -1
- package/src/lib/haversine.test.ts +1 -0
- package/src/lib/predicateParser.test.ts +2 -1
- package/src/lib/projectionSearchFilter.test.ts +2 -1
- package/src/lib/projectionSearchFilter.ts +2 -2
- package/src/oauth/server.ts +3 -4
- package/src/priceSelector.test.ts +2 -1
- package/src/priceSelector.ts +2 -2
- package/src/product-projection-search.ts +8 -8
- package/src/projectAPI.test.ts +1 -0
- package/src/repositories/abstract.ts +1 -1
- package/src/repositories/associate-role.ts +11 -0
- package/src/repositories/attribute-group.ts +11 -0
- package/src/repositories/business-unit.ts +11 -0
- package/src/repositories/cart-discount.ts +11 -4
- package/src/repositories/cart.ts +91 -9
- package/src/repositories/category.ts +3 -3
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +3 -3
- package/src/repositories/customer-group.ts +3 -3
- package/src/repositories/customer.ts +4 -3
- package/src/repositories/discount-code.ts +3 -3
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.ts +3 -3
- package/src/repositories/helpers.ts +49 -6
- package/src/repositories/index.ts +6 -0
- package/src/repositories/inventory-entry.ts +4 -4
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +2 -2
- package/src/repositories/order.test.ts +10 -39
- package/src/repositories/order.ts +31 -16
- package/src/repositories/payment.ts +8 -7
- package/src/repositories/product-discount.ts +2 -2
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-selection.ts +3 -2
- package/src/repositories/product-type.ts +2 -2
- package/src/repositories/product.ts +4 -9
- package/src/repositories/project.ts +2 -2
- package/src/repositories/quote-request.ts +2 -2
- package/src/repositories/quote.ts +2 -2
- package/src/repositories/review.ts +2 -2
- package/src/repositories/shipping-method.ts +10 -2
- package/src/repositories/shopping-list.ts +19 -13
- package/src/repositories/staged-quote.ts +2 -2
- package/src/repositories/standalone-price.ts +3 -3
- package/src/repositories/state.ts +2 -2
- package/src/repositories/store.ts +3 -2
- package/src/repositories/subscription.ts +1 -1
- package/src/repositories/tax-category.ts +2 -2
- package/src/repositories/type.ts +2 -2
- package/src/repositories/zone.ts +2 -2
- package/src/services/abstract.ts +2 -2
- package/src/services/cart.test.ts +2 -1
- package/src/services/cart.ts +4 -4
- package/src/services/category.test.ts +2 -1
- package/src/services/custom-object.test.ts +2 -1
- package/src/services/custom-object.ts +3 -3
- package/src/services/customer.test.ts +1 -0
- package/src/services/inventory-entry.test.ts +2 -1
- package/src/services/my-cart.test.ts +7 -3
- package/src/services/my-customer.test.ts +4 -2
- package/src/services/my-payment.test.ts +2 -1
- package/src/services/order.test.ts +2 -1
- package/src/services/payment.test.ts +2 -1
- package/src/services/product-projection.test.ts +3 -2
- package/src/services/product-type.test.ts +2 -1
- package/src/services/product.test.ts +2 -1
- package/src/services/project.ts +1 -1
- package/src/services/shipping-method.test.ts +2 -1
- package/src/services/standalone-price.test.ts +255 -244
- package/src/services/state.test.ts +2 -1
- package/src/services/store.test.ts +6 -1
- package/src/services/tax-category.test.ts +2 -1
- package/src/storage/abstract.ts +1 -1
- package/src/storage/in-memory.ts +7 -1
- package/src/types.ts +7 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
3
|
"author": "Michael van Tellingen",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/commercetools--mock.esm.js",
|
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"require": "./dist/index.js",
|
|
16
|
-
"import": "./dist/index.mjs"
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
20
|
"engines": {
|
|
20
21
|
"node": ">=16",
|
|
21
|
-
"pnpm": ">=8.
|
|
22
|
+
"pnpm": ">=8.6.5"
|
|
22
23
|
},
|
|
23
|
-
"packageManager": "pnpm@8.
|
|
24
|
+
"packageManager": "pnpm@8.6.5",
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "public"
|
|
26
27
|
},
|
|
@@ -31,56 +32,48 @@
|
|
|
31
32
|
"trailingComma": "es5"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@types/lodash.isequal": "^4.5.6",
|
|
35
35
|
"basic-auth": "^2.0.1",
|
|
36
|
-
"body-parser": "^1.20.
|
|
37
|
-
"deep-equal": "^2.
|
|
38
|
-
"express": "^4.
|
|
36
|
+
"body-parser": "^1.20.2",
|
|
37
|
+
"deep-equal": "^2.2.2",
|
|
38
|
+
"express": "^4.18.2",
|
|
39
39
|
"lodash.isequal": "^4.5.0",
|
|
40
40
|
"morgan": "^1.10.0",
|
|
41
|
-
"nock": "^13.2
|
|
41
|
+
"nock": "^13.3.2",
|
|
42
42
|
"perplex": "^0.11.0",
|
|
43
43
|
"pratt": "^0.7.0",
|
|
44
|
-
"supertest": "^6.
|
|
45
|
-
"
|
|
46
|
-
"uuid": "^8.3.2"
|
|
44
|
+
"supertest": "^6.3.3",
|
|
45
|
+
"uuid": "^9.0.0"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@babel/preset-env": "^7.18.9",
|
|
50
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
51
48
|
"@changesets/changelog-github": "^0.4.8",
|
|
52
|
-
"@changesets/cli": "^2.26.
|
|
53
|
-
"@commercetools/platform-sdk": "4.
|
|
54
|
-
"@labdigital/eslint-config-node": "0.0.5",
|
|
49
|
+
"@changesets/cli": "^2.26.2",
|
|
50
|
+
"@commercetools/platform-sdk": "4.11.0",
|
|
55
51
|
"@types/basic-auth": "^1.1.3",
|
|
56
52
|
"@types/body-parser": "^1.19.2",
|
|
57
53
|
"@types/deep-equal": "^1.0.1",
|
|
58
|
-
"@types/express": "^4.17.
|
|
59
|
-
"@types/express-serve-static-core": "^4.17.
|
|
60
|
-
"@types/
|
|
61
|
-
"@types/morgan": "^1.9.
|
|
54
|
+
"@types/express": "^4.17.17",
|
|
55
|
+
"@types/express-serve-static-core": "^4.17.35",
|
|
56
|
+
"@types/lodash.isequal": "^4.5.6",
|
|
57
|
+
"@types/morgan": "^1.9.4",
|
|
62
58
|
"@types/node": "*",
|
|
63
59
|
"@types/qs": "^6.9.7",
|
|
64
|
-
"@types/supertest": "^2.0.
|
|
65
|
-
"@types/uuid": "^
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
67
|
-
"@typescript-eslint/parser": "^
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"eslint
|
|
60
|
+
"@types/supertest": "^2.0.12",
|
|
61
|
+
"@types/uuid": "^9.0.2",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^6.2.0",
|
|
63
|
+
"@typescript-eslint/parser": "^6.2.0",
|
|
64
|
+
"@vitest/coverage-v8": "^0.33.0",
|
|
65
|
+
"esbuild": "^0.18.17",
|
|
66
|
+
"eslint": "^8.46.0",
|
|
67
|
+
"eslint-plugin-unused-imports": "^3.0.0",
|
|
71
68
|
"got": "^11.8.3",
|
|
72
|
-
"husky": "^
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"typescript": "^4.7.4"
|
|
81
|
-
},
|
|
82
|
-
"peerDependencies": {
|
|
83
|
-
"@commercetools/platform-sdk": "^2.4.1"
|
|
69
|
+
"husky": "^8.0.3",
|
|
70
|
+
"prettier": "^3.0.0",
|
|
71
|
+
"timekeeper": "^2.3.1",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"tslib": "^2.6.1",
|
|
74
|
+
"tsup": "^7.1.0",
|
|
75
|
+
"typescript": "^5.1.6",
|
|
76
|
+
"vitest": "^0.33.0"
|
|
84
77
|
},
|
|
85
78
|
"scripts": {
|
|
86
79
|
"start": "tsup src/server.ts --watch --onSuccess 'node dist/server.js'",
|
|
@@ -88,7 +81,8 @@
|
|
|
88
81
|
"build:server": "esbuild src/server.ts --bundle --outfile=dist/server.js --platform=node",
|
|
89
82
|
"publish:ci": "pnpm build && pnpm changeset publish",
|
|
90
83
|
"check": "eslint src && tsc",
|
|
91
|
-
"test": "
|
|
84
|
+
"test": "vitest run",
|
|
85
|
+
"test:ci": "vitest run --coverage",
|
|
92
86
|
"lint": "eslint src"
|
|
93
87
|
}
|
|
94
88
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { InvalidTokenError } from '@commercetools/platform-sdk'
|
|
1
|
+
import { type InvalidTokenError } from '@commercetools/platform-sdk'
|
|
2
2
|
import { CommercetoolsMock } from './index'
|
|
3
|
+
import { afterEach, beforeEach, expect, test } from 'vitest'
|
|
3
4
|
import nock from 'nock'
|
|
4
5
|
import got from 'got'
|
|
5
6
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { VariableMap } from '@commercetools/platform-sdk'
|
|
1
|
+
import type { VariableMap } from '@commercetools/platform-sdk'
|
|
2
|
+
import { describe, expect, test } from 'vitest'
|
|
2
3
|
import { parseQueryExpression, PredicateError } from './predicateParser'
|
|
3
4
|
|
|
4
5
|
describe('Predicate filter', () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ProductProjection } from '@commercetools/platform-sdk'
|
|
1
|
+
import type { ProductProjection } from '@commercetools/platform-sdk'
|
|
2
|
+
import { describe, expect, test } from 'vitest'
|
|
2
3
|
import { cloneObject } from '../helpers'
|
|
3
4
|
import { applyPriceSelector } from '../priceSelector'
|
|
4
5
|
import { parseFilterExpression } from './projectionSearchFilter'
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* This module implements the commercetools product projection filter expression.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
|
|
5
|
+
import type { ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
|
|
6
6
|
import perplex from 'perplex'
|
|
7
7
|
import Parser from 'pratt'
|
|
8
|
-
import { Writable } from '../types'
|
|
8
|
+
import type { Writable } from '../types'
|
|
9
9
|
import { nestedLookup } from '../helpers'
|
|
10
10
|
|
|
11
11
|
type MatchFunc = (target: any) => boolean
|
package/src/oauth/server.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import auth from 'basic-auth'
|
|
2
2
|
import bodyParser from 'body-parser'
|
|
3
|
-
import express, { NextFunction, Request, Response } from 'express'
|
|
3
|
+
import express, { type NextFunction, type Request, type Response } from 'express'
|
|
4
4
|
import {
|
|
5
|
-
AccessDeniedError,
|
|
6
5
|
InvalidTokenError,
|
|
7
6
|
} from '@commercetools/platform-sdk'
|
|
8
7
|
import { CommercetoolsError, InvalidRequestError } from '../exceptions'
|
|
@@ -29,9 +28,9 @@ export class OAuth2Server {
|
|
|
29
28
|
const token = getBearerToken(request)
|
|
30
29
|
if (!token) {
|
|
31
30
|
next(
|
|
32
|
-
new CommercetoolsError<
|
|
31
|
+
new CommercetoolsError<InvalidTokenError>(
|
|
33
32
|
{
|
|
34
|
-
code: '
|
|
33
|
+
code: 'invalid_token',
|
|
35
34
|
message:
|
|
36
35
|
'This endpoint requires an access token. You can get one from the authorization server.',
|
|
37
36
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ProductProjection } from '@commercetools/platform-sdk'
|
|
1
|
+
import type { ProductProjection } from '@commercetools/platform-sdk'
|
|
2
|
+
import { beforeEach, describe, expect, test } from 'vitest'
|
|
2
3
|
import { applyPriceSelector } from './priceSelector'
|
|
3
4
|
|
|
4
5
|
describe('priceSelector', () => {
|
package/src/priceSelector.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
InvalidInputError,
|
|
3
3
|
Price,
|
|
4
4
|
ProductProjection,
|
|
5
5
|
ProductVariant,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { CommercetoolsError } from './exceptions'
|
|
8
|
-
import { Writable } from './types'
|
|
8
|
+
import type { Writable } from './types'
|
|
9
9
|
|
|
10
10
|
export type PriceSelector = {
|
|
11
11
|
currency?: string
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
FacetResults,
|
|
3
|
+
FilteredFacetResult,
|
|
2
4
|
InvalidInputError,
|
|
3
|
-
ProductProjectionPagedSearchResponse,
|
|
4
5
|
Product,
|
|
5
6
|
ProductProjection,
|
|
7
|
+
ProductProjectionPagedSearchResponse,
|
|
6
8
|
QueryParam,
|
|
7
|
-
FacetResults,
|
|
8
|
-
TermFacetResult,
|
|
9
9
|
RangeFacetResult,
|
|
10
|
-
|
|
10
|
+
TermFacetResult,
|
|
11
11
|
} from '@commercetools/platform-sdk'
|
|
12
|
-
import { nestedLookup } from './helpers'
|
|
13
|
-
import { Writable } from './types'
|
|
14
12
|
import { CommercetoolsError } from './exceptions'
|
|
13
|
+
import { nestedLookup } from './helpers'
|
|
15
14
|
import {
|
|
16
15
|
FilterExpression,
|
|
16
|
+
RangeExpression,
|
|
17
17
|
generateFacetFunc,
|
|
18
18
|
getVariants,
|
|
19
19
|
parseFilterExpression,
|
|
20
|
-
RangeExpression,
|
|
21
20
|
resolveVariantValue,
|
|
22
21
|
} from './lib/projectionSearchFilter'
|
|
23
22
|
import { applyPriceSelector } from './priceSelector'
|
|
24
23
|
import { AbstractStorage } from './storage'
|
|
24
|
+
import type { Writable } from './types'
|
|
25
25
|
|
|
26
26
|
export type ProductProjectionSearchParams = {
|
|
27
27
|
fuzzy?: boolean
|
package/src/projectAPI.test.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AssociateRole } from '@commercetools/platform-sdk'
|
|
2
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
3
|
+
|
|
4
|
+
export class AssociateRoleRepository extends AbstractResourceRepository<'associate-role'> {
|
|
5
|
+
getTypeId() {
|
|
6
|
+
return 'associate-role' as const
|
|
7
|
+
}
|
|
8
|
+
create(context: RepositoryContext, draft: any): AssociateRole {
|
|
9
|
+
throw new Error('Method not implemented.')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AttributeGroup } from '@commercetools/platform-sdk'
|
|
2
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
3
|
+
|
|
4
|
+
export class AttributeGroupRepository extends AbstractResourceRepository<'attribute-group'> {
|
|
5
|
+
getTypeId() {
|
|
6
|
+
return 'attribute-group' as const
|
|
7
|
+
}
|
|
8
|
+
create(context: RepositoryContext, draft: any): AttributeGroup {
|
|
9
|
+
throw new Error('Method not implemented.')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BusinessUnit } from '@commercetools/platform-sdk'
|
|
2
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
3
|
+
|
|
4
|
+
export class BusinessUnitRepository extends AbstractResourceRepository<'business-unit'> {
|
|
5
|
+
getTypeId() {
|
|
6
|
+
return 'business-unit' as const
|
|
7
|
+
}
|
|
8
|
+
create(context: RepositoryContext, draft: any): BusinessUnit {
|
|
9
|
+
throw new Error('Method not implemented.')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CartDiscount,
|
|
3
3
|
CartDiscountChangeIsActiveAction,
|
|
4
4
|
CartDiscountChangeSortOrderAction,
|
|
@@ -15,10 +15,13 @@ import {
|
|
|
15
15
|
CartDiscountValueGiftLineItem,
|
|
16
16
|
CartDiscountValueRelative,
|
|
17
17
|
} from '@commercetools/platform-sdk'
|
|
18
|
-
import { Writable } from 'types'
|
|
18
|
+
import type { Writable } from 'types'
|
|
19
19
|
import { getBaseResourceProperties } from '../helpers'
|
|
20
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
21
|
-
import {
|
|
20
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
21
|
+
import {
|
|
22
|
+
createTypedMoney,
|
|
23
|
+
getStoreKeyReference,
|
|
24
|
+
} from './helpers'
|
|
22
25
|
|
|
23
26
|
export class CartDiscountRepository extends AbstractResourceRepository<'cart-discount'> {
|
|
24
27
|
getTypeId() {
|
|
@@ -33,6 +36,10 @@ export class CartDiscountRepository extends AbstractResourceRepository<'cart-dis
|
|
|
33
36
|
cartPredicate: draft.cartPredicate,
|
|
34
37
|
isActive: draft.isActive || false,
|
|
35
38
|
name: draft.name,
|
|
39
|
+
stores:
|
|
40
|
+
draft.stores?.map((s) =>
|
|
41
|
+
getStoreKeyReference(s, context.projectKey, this._storage)
|
|
42
|
+
) ?? [],
|
|
36
43
|
references: [],
|
|
37
44
|
target: draft.target,
|
|
38
45
|
requiresDiscountCode: draft.requiresDiscountCode || false,
|
package/src/repositories/cart.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
Address,
|
|
3
|
+
AddressDraft,
|
|
2
4
|
Cart,
|
|
3
5
|
CartAddLineItemAction,
|
|
6
|
+
CartChangeLineItemQuantityAction,
|
|
4
7
|
CartDraft,
|
|
5
8
|
CartRemoveLineItemAction,
|
|
6
9
|
CartSetBillingAddressAction,
|
|
@@ -11,6 +14,7 @@ import {
|
|
|
11
14
|
CartSetLocaleAction,
|
|
12
15
|
CartSetShippingAddressAction,
|
|
13
16
|
CartSetShippingMethodAction,
|
|
17
|
+
CustomFields,
|
|
14
18
|
GeneralError,
|
|
15
19
|
LineItem,
|
|
16
20
|
LineItemDraft,
|
|
@@ -22,9 +26,9 @@ import {
|
|
|
22
26
|
import { v4 as uuidv4 } from 'uuid'
|
|
23
27
|
import { CommercetoolsError } from '../exceptions'
|
|
24
28
|
import { getBaseResourceProperties } from '../helpers'
|
|
25
|
-
import { Writable } from '../types'
|
|
26
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
27
|
-
import { createCustomFields } from './helpers'
|
|
29
|
+
import type { Writable } from '../types'
|
|
30
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
31
|
+
import { createAddress, createCustomFields } from './helpers'
|
|
28
32
|
|
|
29
33
|
export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
30
34
|
getTypeId() {
|
|
@@ -47,6 +51,10 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
47
51
|
cartState: 'Active',
|
|
48
52
|
country: draft.country,
|
|
49
53
|
customLineItems: [],
|
|
54
|
+
directDiscounts: [],
|
|
55
|
+
discountCodes: [],
|
|
56
|
+
inventoryMode: 'None',
|
|
57
|
+
itemShippingAddresses: [],
|
|
50
58
|
lineItems,
|
|
51
59
|
locale: draft.locale,
|
|
52
60
|
taxCalculationMode: draft.taxCalculationMode ?? 'LineItemLevel',
|
|
@@ -191,6 +199,7 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
191
199
|
perMethodTaxRate: [],
|
|
192
200
|
totalPrice: {
|
|
193
201
|
...price.value,
|
|
202
|
+
type: 'centPrecision',
|
|
194
203
|
centAmount: price.value.centAmount * quantity,
|
|
195
204
|
},
|
|
196
205
|
quantity,
|
|
@@ -204,6 +213,56 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
204
213
|
// Update cart total price
|
|
205
214
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource)
|
|
206
215
|
},
|
|
216
|
+
changeLineItemQuantity: (
|
|
217
|
+
context: RepositoryContext,
|
|
218
|
+
resource: Writable<Cart>,
|
|
219
|
+
{ lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction
|
|
220
|
+
) => {
|
|
221
|
+
let lineItem: Writable<LineItem> | undefined
|
|
222
|
+
|
|
223
|
+
if (lineItemId) {
|
|
224
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId)
|
|
225
|
+
if (!lineItem) {
|
|
226
|
+
throw new CommercetoolsError<GeneralError>({
|
|
227
|
+
code: 'General',
|
|
228
|
+
message: `A line item with ID '${lineItemId}' not found.`,
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
} else if (lineItemKey) {
|
|
232
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId)
|
|
233
|
+
if (!lineItem) {
|
|
234
|
+
throw new CommercetoolsError<GeneralError>({
|
|
235
|
+
code: 'General',
|
|
236
|
+
message: `A line item with Key '${lineItemKey}' not found.`,
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
throw new CommercetoolsError<GeneralError>({
|
|
241
|
+
code: 'General',
|
|
242
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`,
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const shouldDelete = !quantity || quantity >= lineItem.quantity
|
|
247
|
+
if (shouldDelete) {
|
|
248
|
+
// delete line item
|
|
249
|
+
resource.lineItems = resource.lineItems.filter(
|
|
250
|
+
(x) => x.id !== lineItemId
|
|
251
|
+
)
|
|
252
|
+
} else {
|
|
253
|
+
// decrease quantity and update total price
|
|
254
|
+
resource.lineItems.map((x) => {
|
|
255
|
+
if (x.id === lineItemId && quantity) {
|
|
256
|
+
x.quantity -= quantity
|
|
257
|
+
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
258
|
+
}
|
|
259
|
+
return x
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Update cart total price
|
|
264
|
+
resource.totalPrice.centAmount = calculateCartTotalPrice(resource)
|
|
265
|
+
},
|
|
207
266
|
removeLineItem: (
|
|
208
267
|
context: RepositoryContext,
|
|
209
268
|
resource: Writable<Cart>,
|
|
@@ -243,7 +302,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
243
302
|
resource: Writable<Cart>,
|
|
244
303
|
{ address }: CartSetBillingAddressAction
|
|
245
304
|
) => {
|
|
246
|
-
resource.billingAddress =
|
|
305
|
+
resource.billingAddress = createAddress(
|
|
306
|
+
address,
|
|
307
|
+
context.projectKey,
|
|
308
|
+
this._storage
|
|
309
|
+
)
|
|
247
310
|
},
|
|
248
311
|
setShippingMethod: (
|
|
249
312
|
context: RepositoryContext,
|
|
@@ -319,7 +382,7 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
319
382
|
typeId: 'type',
|
|
320
383
|
id: resolvedType.id,
|
|
321
384
|
},
|
|
322
|
-
fields: fields ||
|
|
385
|
+
fields: fields || {}
|
|
323
386
|
}
|
|
324
387
|
}
|
|
325
388
|
},
|
|
@@ -335,7 +398,24 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
335
398
|
resource: Writable<Cart>,
|
|
336
399
|
{ address }: CartSetShippingAddressAction
|
|
337
400
|
) => {
|
|
338
|
-
|
|
401
|
+
if (!address) {
|
|
402
|
+
resource.shippingAddress = undefined
|
|
403
|
+
return
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
let custom: CustomFields | undefined = undefined
|
|
407
|
+
if ((address as Address & AddressDraft).custom) {
|
|
408
|
+
custom = createCustomFields(
|
|
409
|
+
(address as Address & AddressDraft).custom,
|
|
410
|
+
context.projectKey,
|
|
411
|
+
this._storage
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
resource.shippingAddress = {
|
|
416
|
+
...address,
|
|
417
|
+
custom: custom,
|
|
418
|
+
}
|
|
339
419
|
},
|
|
340
420
|
}
|
|
341
421
|
draftLineItemtoLineItem = (
|
|
@@ -412,7 +492,9 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
412
492
|
variant,
|
|
413
493
|
price: price,
|
|
414
494
|
totalPrice: {
|
|
415
|
-
|
|
495
|
+
type: 'centPrecision',
|
|
496
|
+
currencyCode: price.value.currencyCode,
|
|
497
|
+
fractionDigits: price.value.fractionDigits,
|
|
416
498
|
centAmount: price.value.centAmount * quant,
|
|
417
499
|
},
|
|
418
500
|
taxedPricePortions: [],
|
|
@@ -434,7 +516,7 @@ const selectPrice = ({
|
|
|
434
516
|
prices: Price[] | undefined
|
|
435
517
|
currency: string
|
|
436
518
|
country: string | undefined
|
|
437
|
-
}) => {
|
|
519
|
+
}): Price | undefined => {
|
|
438
520
|
if (!prices) {
|
|
439
521
|
return undefined
|
|
440
522
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Category,
|
|
3
3
|
CategoryChangeAssetNameAction,
|
|
4
4
|
CategoryChangeSlugAction,
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
} from '@commercetools/platform-sdk'
|
|
16
16
|
import { v4 as uuidv4 } from 'uuid'
|
|
17
17
|
import { getBaseResourceProperties } from '../helpers'
|
|
18
|
-
import { Writable } from '../types'
|
|
19
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
18
|
+
import type { Writable } from '../types'
|
|
19
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
20
20
|
import { createCustomFields } from './helpers'
|
|
21
21
|
|
|
22
22
|
export class CategoryRepository extends AbstractResourceRepository<'category'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Channel,
|
|
3
3
|
ChannelChangeDescriptionAction,
|
|
4
4
|
ChannelChangeKeyAction,
|
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
ChannelUpdateAction,
|
|
12
12
|
} from '@commercetools/platform-sdk'
|
|
13
13
|
import { getBaseResourceProperties } from '../helpers'
|
|
14
|
-
import { Writable } from '../types'
|
|
15
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
14
|
+
import type { Writable } from '../types'
|
|
15
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
16
16
|
import { createAddress, createCustomFields } from './helpers'
|
|
17
17
|
|
|
18
18
|
export class ChannelRepository extends AbstractResourceRepository<'channel'> {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CustomObject,
|
|
3
3
|
CustomObjectDraft,
|
|
4
4
|
InvalidOperationError,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
6
|
import { CommercetoolsError } from '../exceptions'
|
|
7
7
|
import { cloneObject, getBaseResourceProperties } from '../helpers'
|
|
8
|
-
import { Writable } from '../types'
|
|
9
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
|
+
import type { Writable } from '../types'
|
|
9
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
10
10
|
import { checkConcurrentModification } from './errors'
|
|
11
11
|
|
|
12
12
|
export class CustomObjectRepository extends AbstractResourceRepository<'key-value-document'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CustomerGroup,
|
|
3
3
|
CustomerGroupChangeNameAction,
|
|
4
4
|
CustomerGroupDraft,
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
CustomerGroupSetCustomTypeAction,
|
|
7
7
|
CustomerGroupSetKeyAction,
|
|
8
8
|
} from '@commercetools/platform-sdk'
|
|
9
|
-
import { Writable } from 'types'
|
|
9
|
+
import type { Writable } from 'types'
|
|
10
10
|
import { getBaseResourceProperties } from '../helpers'
|
|
11
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
11
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
12
12
|
import { createCustomFields } from './helpers'
|
|
13
13
|
|
|
14
14
|
export class CustomerGroupRepository extends AbstractResourceRepository<'customer-group'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Customer,
|
|
3
3
|
CustomerChangeEmailAction,
|
|
4
4
|
CustomerDraft,
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
InvalidInputError,
|
|
7
7
|
InvalidJsonInputError,
|
|
8
8
|
} from '@commercetools/platform-sdk'
|
|
9
|
-
import { Writable } from 'types'
|
|
9
|
+
import type { Writable } from 'types'
|
|
10
10
|
import { CommercetoolsError } from '../exceptions'
|
|
11
11
|
import { getBaseResourceProperties } from '../helpers'
|
|
12
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
12
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
13
13
|
|
|
14
14
|
export class CustomerRepository extends AbstractResourceRepository<'customer'> {
|
|
15
15
|
getTypeId() {
|
|
@@ -19,6 +19,7 @@ export class CustomerRepository extends AbstractResourceRepository<'customer'> {
|
|
|
19
19
|
create(context: RepositoryContext, draft: CustomerDraft): Customer {
|
|
20
20
|
const resource: Customer = {
|
|
21
21
|
...getBaseResourceProperties(),
|
|
22
|
+
authenticationMode: draft.authenticationMode || 'Password',
|
|
22
23
|
email: draft.email,
|
|
23
24
|
password: draft.password
|
|
24
25
|
? Buffer.from(draft.password).toString('base64')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CartDiscountReference,
|
|
3
3
|
DiscountCode,
|
|
4
4
|
DiscountCodeChangeCartDiscountsAction,
|
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
DiscountCodeUpdateAction,
|
|
18
18
|
} from '@commercetools/platform-sdk'
|
|
19
19
|
import { getBaseResourceProperties } from '../helpers'
|
|
20
|
-
import { Writable } from '../types'
|
|
21
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
20
|
+
import type { Writable } from '../types'
|
|
21
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
22
22
|
import { createCustomFields } from './helpers'
|
|
23
23
|
|
|
24
24
|
export class DiscountCodeRepository extends AbstractResourceRepository<'discount-code'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Extension,
|
|
3
3
|
ExtensionChangeDestinationAction,
|
|
4
4
|
ExtensionChangeTriggersAction,
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
} from '@commercetools/platform-sdk'
|
|
10
10
|
import { getBaseResourceProperties } from '../helpers'
|
|
11
11
|
import { maskSecretValue } from '../lib/masking'
|
|
12
|
-
import { Writable } from '../types'
|
|
13
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
12
|
+
import type { Writable } from '../types'
|
|
13
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
14
14
|
|
|
15
15
|
export class ExtensionRepository extends AbstractResourceRepository<'extension'> {
|
|
16
16
|
getTypeId() {
|