@labdigital/commercetools-mock 1.2.0 → 1.3.1
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 +5827 -5596
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +344 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +344 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -39
- 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/predicateParser.ts +2 -2
- package/src/lib/projectionSearchFilter.test.ts +2 -1
- package/src/lib/projectionSearchFilter.ts +4 -4
- 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 +90 -13
- 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 +2 -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.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/commercetools--mock.esm.js",
|
|
@@ -13,7 +13,8 @@
|
|
|
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": {
|
|
@@ -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', () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* See https://docs.commercetools.com/api/predicates/query
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import Lexer from 'perplex'
|
|
8
8
|
import { ITokenPosition, Parser } from 'pratt'
|
|
9
9
|
import { haversineDistance } from './haversine'
|
|
10
10
|
|
|
@@ -104,7 +104,7 @@ const resolveValue = (obj: any, val: TypeSymbol): any => {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
const getLexer = (value: string) =>
|
|
107
|
-
new
|
|
107
|
+
new Lexer<string>(value)
|
|
108
108
|
|
|
109
109
|
.token('AND', /and(?![-_a-z0-9]+)/i)
|
|
110
110
|
.token('OR', /or(?![-_a-z0-9]+)/i)
|
|
@@ -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,11 +2,11 @@
|
|
|
2
2
|
* This module implements the commercetools product projection filter expression.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
|
|
6
|
-
import
|
|
5
|
+
import type { ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
|
|
6
|
+
import Lexer from 'perplex'
|
|
7
7
|
import Parser from 'pratt'
|
|
8
|
-
import { Writable } from '../types'
|
|
9
8
|
import { nestedLookup } from '../helpers'
|
|
9
|
+
import type { Writable } from '../types'
|
|
10
10
|
|
|
11
11
|
type MatchFunc = (target: any) => boolean
|
|
12
12
|
|
|
@@ -72,7 +72,7 @@ export const parseFilterExpression = (
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const getLexer = (value: string) =>
|
|
75
|
-
new
|
|
75
|
+
new Lexer<string>(value)
|
|
76
76
|
.token('MISSING', /missing(?![-_a-z0-9]+)/i)
|
|
77
77
|
.token('EXISTS', /exists(?![-_a-z0-9]+)/i)
|
|
78
78
|
.token('RANGE', /range(?![-_a-z0-9]+)/i)
|
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',
|
|
@@ -150,12 +158,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
150
158
|
)
|
|
151
159
|
if (alreadyAdded) {
|
|
152
160
|
// increase quantity and update total price
|
|
153
|
-
resource.lineItems.
|
|
161
|
+
resource.lineItems.forEach((x) => {
|
|
154
162
|
if (x.productId === product?.id && x.variant.id === variant?.id) {
|
|
155
163
|
x.quantity += quantity
|
|
156
164
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
157
165
|
}
|
|
158
|
-
return x
|
|
159
166
|
})
|
|
160
167
|
} else {
|
|
161
168
|
// add line item
|
|
@@ -191,6 +198,7 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
191
198
|
perMethodTaxRate: [],
|
|
192
199
|
totalPrice: {
|
|
193
200
|
...price.value,
|
|
201
|
+
type: 'centPrecision',
|
|
194
202
|
centAmount: price.value.centAmount * quantity,
|
|
195
203
|
},
|
|
196
204
|
quantity,
|
|
@@ -204,6 +212,53 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
204
212
|
// Update cart total price
|
|
205
213
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource)
|
|
206
214
|
},
|
|
215
|
+
changeLineItemQuantity: (
|
|
216
|
+
context: RepositoryContext,
|
|
217
|
+
resource: Writable<Cart>,
|
|
218
|
+
{ lineItemId, lineItemKey, quantity }: CartChangeLineItemQuantityAction
|
|
219
|
+
) => {
|
|
220
|
+
let lineItem: Writable<LineItem> | undefined
|
|
221
|
+
|
|
222
|
+
if (lineItemId) {
|
|
223
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId)
|
|
224
|
+
if (!lineItem) {
|
|
225
|
+
throw new CommercetoolsError<GeneralError>({
|
|
226
|
+
code: 'General',
|
|
227
|
+
message: `A line item with ID '${lineItemId}' not found.`,
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
} else if (lineItemKey) {
|
|
231
|
+
lineItem = resource.lineItems.find((x) => x.id === lineItemId)
|
|
232
|
+
if (!lineItem) {
|
|
233
|
+
throw new CommercetoolsError<GeneralError>({
|
|
234
|
+
code: 'General',
|
|
235
|
+
message: `A line item with Key '${lineItemKey}' not found.`,
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
throw new CommercetoolsError<GeneralError>({
|
|
240
|
+
code: 'General',
|
|
241
|
+
message: `Either lineItemid or lineItemKey needs to be provided.`,
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (quantity === 0) {
|
|
246
|
+
// delete line item
|
|
247
|
+
resource.lineItems = resource.lineItems.filter(
|
|
248
|
+
(x) => x.id !== lineItemId
|
|
249
|
+
)
|
|
250
|
+
} else {
|
|
251
|
+
resource.lineItems.forEach((x) => {
|
|
252
|
+
if (x.id === lineItemId && quantity) {
|
|
253
|
+
x.quantity = quantity
|
|
254
|
+
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Update cart total price
|
|
260
|
+
resource.totalPrice.centAmount = calculateCartTotalPrice(resource)
|
|
261
|
+
},
|
|
207
262
|
removeLineItem: (
|
|
208
263
|
context: RepositoryContext,
|
|
209
264
|
resource: Writable<Cart>,
|
|
@@ -226,12 +281,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
226
281
|
)
|
|
227
282
|
} else {
|
|
228
283
|
// decrease quantity and update total price
|
|
229
|
-
resource.lineItems.
|
|
284
|
+
resource.lineItems.forEach((x) => {
|
|
230
285
|
if (x.id === lineItemId && quantity) {
|
|
231
286
|
x.quantity -= quantity
|
|
232
287
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
233
288
|
}
|
|
234
|
-
return x
|
|
235
289
|
})
|
|
236
290
|
}
|
|
237
291
|
|
|
@@ -243,7 +297,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
243
297
|
resource: Writable<Cart>,
|
|
244
298
|
{ address }: CartSetBillingAddressAction
|
|
245
299
|
) => {
|
|
246
|
-
resource.billingAddress =
|
|
300
|
+
resource.billingAddress = createAddress(
|
|
301
|
+
address,
|
|
302
|
+
context.projectKey,
|
|
303
|
+
this._storage
|
|
304
|
+
)
|
|
247
305
|
},
|
|
248
306
|
setShippingMethod: (
|
|
249
307
|
context: RepositoryContext,
|
|
@@ -319,7 +377,7 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
319
377
|
typeId: 'type',
|
|
320
378
|
id: resolvedType.id,
|
|
321
379
|
},
|
|
322
|
-
fields: fields ||
|
|
380
|
+
fields: fields || {}
|
|
323
381
|
}
|
|
324
382
|
}
|
|
325
383
|
},
|
|
@@ -335,7 +393,24 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
335
393
|
resource: Writable<Cart>,
|
|
336
394
|
{ address }: CartSetShippingAddressAction
|
|
337
395
|
) => {
|
|
338
|
-
|
|
396
|
+
if (!address) {
|
|
397
|
+
resource.shippingAddress = undefined
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
let custom: CustomFields | undefined = undefined
|
|
402
|
+
if ((address as Address & AddressDraft).custom) {
|
|
403
|
+
custom = createCustomFields(
|
|
404
|
+
(address as Address & AddressDraft).custom,
|
|
405
|
+
context.projectKey,
|
|
406
|
+
this._storage
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
resource.shippingAddress = {
|
|
411
|
+
...address,
|
|
412
|
+
custom: custom,
|
|
413
|
+
}
|
|
339
414
|
},
|
|
340
415
|
}
|
|
341
416
|
draftLineItemtoLineItem = (
|
|
@@ -412,7 +487,9 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
412
487
|
variant,
|
|
413
488
|
price: price,
|
|
414
489
|
totalPrice: {
|
|
415
|
-
|
|
490
|
+
type: 'centPrecision',
|
|
491
|
+
currencyCode: price.value.currencyCode,
|
|
492
|
+
fractionDigits: price.value.fractionDigits,
|
|
416
493
|
centAmount: price.value.centAmount * quant,
|
|
417
494
|
},
|
|
418
495
|
taxedPricePortions: [],
|
|
@@ -434,7 +511,7 @@ const selectPrice = ({
|
|
|
434
511
|
prices: Price[] | undefined
|
|
435
512
|
currency: string
|
|
436
513
|
country: string | undefined
|
|
437
|
-
}) => {
|
|
514
|
+
}): Price | undefined => {
|
|
438
515
|
if (!prices) {
|
|
439
516
|
return undefined
|
|
440
517
|
}
|
|
@@ -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')
|