@labdigital/commercetools-mock 2.17.1 → 2.18.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.cjs +4351 -4099
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -413
- package/dist/index.d.ts +266 -413
- package/dist/index.js +4351 -4099
- package/dist/index.js.map +1 -1
- package/package.json +47 -47
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +86 -86
- package/src/oauth/server.ts +158 -144
- package/src/oauth/store.ts +44 -43
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/schemas/update-request.ts +12 -0
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +85 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +23 -36
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +66 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +29 -24
- package/src/services/project.ts +22 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/validate.ts +18 -0
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -5,282 +5,282 @@
|
|
|
5
5
|
import type {
|
|
6
6
|
ProductProjection,
|
|
7
7
|
ProductVariant,
|
|
8
|
-
} from
|
|
9
|
-
import { nestedLookup } from
|
|
10
|
-
import type { Writable } from
|
|
11
|
-
import { Lexer, Parser } from
|
|
8
|
+
} from "@commercetools/platform-sdk";
|
|
9
|
+
import { nestedLookup } from "../helpers";
|
|
10
|
+
import type { Writable } from "../types";
|
|
11
|
+
import { Lexer, Parser } from "./parser";
|
|
12
12
|
|
|
13
|
-
type MatchFunc = (target: any) => boolean
|
|
13
|
+
type MatchFunc = (target: any) => boolean;
|
|
14
14
|
|
|
15
15
|
type ProductProjectionFilter = (
|
|
16
16
|
p: Writable<ProductProjection>,
|
|
17
|
-
markMatchingVariants: boolean
|
|
18
|
-
) => boolean
|
|
17
|
+
markMatchingVariants: boolean,
|
|
18
|
+
) => boolean;
|
|
19
19
|
|
|
20
20
|
type TypeSymbol = {
|
|
21
|
-
type:
|
|
22
|
-
kind:
|
|
23
|
-
value: any
|
|
24
|
-
}
|
|
21
|
+
type: "Symbol";
|
|
22
|
+
kind: "int" | "string" | "any";
|
|
23
|
+
value: any;
|
|
24
|
+
};
|
|
25
25
|
|
|
26
26
|
type RangeExpressionSet = {
|
|
27
|
-
source: string
|
|
28
|
-
type:
|
|
29
|
-
children?: RangeExpression[]
|
|
30
|
-
}
|
|
27
|
+
source: string;
|
|
28
|
+
type: "RangeExpression";
|
|
29
|
+
children?: RangeExpression[];
|
|
30
|
+
};
|
|
31
31
|
|
|
32
32
|
type FilterExpressionSet = {
|
|
33
|
-
source: string
|
|
34
|
-
type:
|
|
35
|
-
children?: FilterExpression[]
|
|
36
|
-
}
|
|
33
|
+
source: string;
|
|
34
|
+
type: "FilterExpression";
|
|
35
|
+
children?: FilterExpression[];
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
type TermExpressionSet = {
|
|
39
|
-
source: string
|
|
40
|
-
type:
|
|
41
|
-
}
|
|
39
|
+
source: string;
|
|
40
|
+
type: "TermExpression";
|
|
41
|
+
};
|
|
42
42
|
|
|
43
43
|
type ExpressionSet =
|
|
44
44
|
| RangeExpressionSet
|
|
45
45
|
| FilterExpressionSet
|
|
46
|
-
| TermExpressionSet
|
|
46
|
+
| TermExpressionSet;
|
|
47
47
|
|
|
48
48
|
export type RangeExpression = {
|
|
49
|
-
type:
|
|
50
|
-
start?: number
|
|
51
|
-
stop?: number
|
|
52
|
-
match: (obj: any) => boolean
|
|
53
|
-
}
|
|
49
|
+
type: "RangeExpression";
|
|
50
|
+
start?: number;
|
|
51
|
+
stop?: number;
|
|
52
|
+
match: (obj: any) => boolean;
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
export type FilterExpression = {
|
|
56
|
-
type:
|
|
57
|
-
match: (obj: any) => boolean
|
|
58
|
-
}
|
|
56
|
+
type: "FilterExpression";
|
|
57
|
+
match: (obj: any) => boolean;
|
|
58
|
+
};
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Returns a function (ProductProjectionFilter).
|
|
62
62
|
* NOTE: The filter can alter the resources in-place (FIXME)
|
|
63
63
|
*/
|
|
64
64
|
export const parseFilterExpression = (
|
|
65
|
-
filter: string
|
|
65
|
+
filter: string,
|
|
66
66
|
): ProductProjectionFilter => {
|
|
67
|
-
const exprFunc = generateMatchFunc(filter)
|
|
68
|
-
const [source] = filter.split(
|
|
67
|
+
const exprFunc = generateMatchFunc(filter);
|
|
68
|
+
const [source] = filter.split(":", 1);
|
|
69
69
|
|
|
70
|
-
if (source.startsWith(
|
|
71
|
-
return filterVariants(source, exprFunc)
|
|
70
|
+
if (source.startsWith("variants.")) {
|
|
71
|
+
return filterVariants(source, exprFunc);
|
|
72
72
|
}
|
|
73
|
-
return filterProduct(source, exprFunc)
|
|
74
|
-
}
|
|
73
|
+
return filterProduct(source, exprFunc);
|
|
74
|
+
};
|
|
75
75
|
|
|
76
76
|
const getLexer = (value: string) =>
|
|
77
77
|
new Lexer(value)
|
|
78
|
-
.token(
|
|
79
|
-
.token(
|
|
80
|
-
.token(
|
|
81
|
-
.token(
|
|
82
|
-
.token(
|
|
83
|
-
|
|
84
|
-
.token(
|
|
85
|
-
.token(
|
|
86
|
-
.token(
|
|
87
|
-
.token(
|
|
88
|
-
|
|
89
|
-
.token(
|
|
90
|
-
.token(
|
|
91
|
-
.token(
|
|
92
|
-
.token(
|
|
93
|
-
.token(
|
|
78
|
+
.token("MISSING", /missing(?![-_a-z0-9]+)/i)
|
|
79
|
+
.token("EXISTS", /exists(?![-_a-z0-9]+)/i)
|
|
80
|
+
.token("RANGE", /range(?![-_a-z0-9]+)/i)
|
|
81
|
+
.token("TO", /to(?![-_a-z0-9]+)/i)
|
|
82
|
+
.token("IDENTIFIER", /[-_.a-z]+/i)
|
|
83
|
+
|
|
84
|
+
.token("FLOAT", /\d+\.\d+/)
|
|
85
|
+
.token("INT", /\d+/)
|
|
86
|
+
.token("STRING", /"((?:\\.|[^"\\])*)"/)
|
|
87
|
+
.token("STRING", /'((?:\\.|[^'\\])*)'/)
|
|
88
|
+
|
|
89
|
+
.token("COMMA", ",")
|
|
90
|
+
.token("STAR", "*")
|
|
91
|
+
.token("(", "(")
|
|
92
|
+
.token(":", ":")
|
|
93
|
+
.token(")", ")")
|
|
94
94
|
.token('"', '"')
|
|
95
|
-
.token(
|
|
95
|
+
.token("WS", /\s+/, true); // skip
|
|
96
96
|
|
|
97
97
|
const parseFilter = (filter: string): ExpressionSet => {
|
|
98
|
-
const lexer = getLexer(filter)
|
|
98
|
+
const lexer = getLexer(filter);
|
|
99
99
|
const parser = new Parser(lexer)
|
|
100
100
|
.builder()
|
|
101
|
-
.nud(
|
|
102
|
-
.led(
|
|
103
|
-
const parsed: any = parser.parse({ terminals: [bp - 1] })
|
|
101
|
+
.nud("IDENTIFIER", 100, (t) => t.token.match)
|
|
102
|
+
.led(":", 100, ({ left, bp }) => {
|
|
103
|
+
const parsed: any = parser.parse({ terminals: [bp - 1] });
|
|
104
104
|
const expressions: RangeExpression[] | FilterExpression[] | TypeSymbol[] =
|
|
105
|
-
!Array.isArray(parsed) ? [parsed] : parsed
|
|
105
|
+
!Array.isArray(parsed) ? [parsed] : parsed;
|
|
106
106
|
|
|
107
107
|
// Make sure we only have one type of expression (cannot mix)
|
|
108
|
-
const unique = new Set(expressions.map((expr) => expr.type))
|
|
108
|
+
const unique = new Set(expressions.map((expr) => expr.type));
|
|
109
109
|
if (unique.size > 1) {
|
|
110
|
-
throw new Error(
|
|
110
|
+
throw new Error("Invalid expression");
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// Convert plain symbols to a filter expression. For example
|
|
114
114
|
// variants.attribute.foobar:4 where 4 is a Symbol should result
|
|
115
115
|
// in a comparison
|
|
116
|
-
if (expressions.some((expr) => expr.type ==
|
|
116
|
+
if (expressions.some((expr) => expr.type == "Symbol")) {
|
|
117
117
|
return {
|
|
118
118
|
source: left as string,
|
|
119
|
-
type:
|
|
119
|
+
type: "FilterExpression",
|
|
120
120
|
children: expressions.map((e): FilterExpression => {
|
|
121
|
-
if (e.type !=
|
|
122
|
-
throw new Error(
|
|
121
|
+
if (e.type != "Symbol") {
|
|
122
|
+
throw new Error("Invalid expression");
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
return {
|
|
126
|
-
type:
|
|
126
|
+
type: "FilterExpression",
|
|
127
127
|
match: (obj: any): boolean => obj === e.value,
|
|
128
|
-
}
|
|
128
|
+
};
|
|
129
129
|
}),
|
|
130
|
-
}
|
|
130
|
+
};
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
return {
|
|
134
134
|
source: left,
|
|
135
135
|
type: expressions[0].type,
|
|
136
136
|
children: expressions,
|
|
137
|
-
}
|
|
137
|
+
};
|
|
138
138
|
})
|
|
139
139
|
.nud(
|
|
140
|
-
|
|
140
|
+
"STRING",
|
|
141
141
|
20,
|
|
142
142
|
(t) =>
|
|
143
143
|
({
|
|
144
|
-
type:
|
|
145
|
-
kind:
|
|
144
|
+
type: "Symbol",
|
|
145
|
+
kind: "string",
|
|
146
146
|
// @ts-ignore
|
|
147
147
|
value: t.token.groups[1],
|
|
148
|
-
}) as TypeSymbol
|
|
148
|
+
}) as TypeSymbol,
|
|
149
149
|
)
|
|
150
150
|
.nud(
|
|
151
|
-
|
|
151
|
+
"INT",
|
|
152
152
|
5,
|
|
153
153
|
(t) =>
|
|
154
154
|
({
|
|
155
|
-
type:
|
|
156
|
-
kind:
|
|
155
|
+
type: "Symbol",
|
|
156
|
+
kind: "int",
|
|
157
157
|
value: parseInt(t.token.match, 10),
|
|
158
|
-
}) as TypeSymbol
|
|
158
|
+
}) as TypeSymbol,
|
|
159
159
|
)
|
|
160
|
-
.nud(
|
|
161
|
-
type:
|
|
162
|
-
kind:
|
|
160
|
+
.nud("STAR", 5, (_) => ({
|
|
161
|
+
type: "Symbol",
|
|
162
|
+
kind: "any",
|
|
163
163
|
value: null,
|
|
164
164
|
}))
|
|
165
165
|
.nud(
|
|
166
|
-
|
|
166
|
+
"EXISTS",
|
|
167
167
|
10,
|
|
168
168
|
({ bp }) =>
|
|
169
169
|
({
|
|
170
|
-
type:
|
|
170
|
+
type: "FilterExpression",
|
|
171
171
|
match: (obj: any): boolean => obj !== undefined,
|
|
172
|
-
}) as FilterExpression
|
|
172
|
+
}) as FilterExpression,
|
|
173
173
|
)
|
|
174
174
|
.nud(
|
|
175
|
-
|
|
175
|
+
"MISSING",
|
|
176
176
|
10,
|
|
177
177
|
({ bp }) =>
|
|
178
178
|
({
|
|
179
|
-
type:
|
|
179
|
+
type: "FilterExpression",
|
|
180
180
|
match: (obj: any): boolean => obj === undefined,
|
|
181
|
-
}) as FilterExpression
|
|
181
|
+
}) as FilterExpression,
|
|
182
182
|
)
|
|
183
|
-
.led(
|
|
184
|
-
const expr: any = parser.parse({ terminals: [bp - 1] })
|
|
183
|
+
.led("COMMA", 200, ({ left, token, bp }) => {
|
|
184
|
+
const expr: any = parser.parse({ terminals: [bp - 1] });
|
|
185
185
|
if (Array.isArray(expr)) {
|
|
186
|
-
return [left, ...expr]
|
|
186
|
+
return [left, ...expr];
|
|
187
187
|
} else {
|
|
188
|
-
return [left, expr]
|
|
188
|
+
return [left, expr];
|
|
189
189
|
}
|
|
190
190
|
})
|
|
191
|
-
.nud(
|
|
192
|
-
const expr: any = parser.parse({ terminals: [
|
|
193
|
-
lexer.expect(
|
|
194
|
-
return expr
|
|
191
|
+
.nud("(", 100, (t) => {
|
|
192
|
+
const expr: any = parser.parse({ terminals: [")"] });
|
|
193
|
+
lexer.expect(")");
|
|
194
|
+
return expr;
|
|
195
195
|
})
|
|
196
|
-
.bp(
|
|
197
|
-
.led(
|
|
198
|
-
const expr: any = parser.parse({ terminals: [bp - 1] })
|
|
196
|
+
.bp(")", 0)
|
|
197
|
+
.led("TO", 20, ({ left, bp }) => {
|
|
198
|
+
const expr: any = parser.parse({ terminals: [bp - 1] });
|
|
199
199
|
return {
|
|
200
200
|
start: left.value,
|
|
201
201
|
stop: expr.value,
|
|
202
|
-
}
|
|
202
|
+
};
|
|
203
203
|
})
|
|
204
|
-
.nud(
|
|
205
|
-
let ranges: any = parser.parse()
|
|
204
|
+
.nud("RANGE", 20, ({ bp }) => {
|
|
205
|
+
let ranges: any = parser.parse();
|
|
206
206
|
|
|
207
207
|
// If multiple ranges are defined we receive an array of ranges. So let's
|
|
208
208
|
// make sure we always have an array
|
|
209
209
|
if (!Array.isArray(ranges)) {
|
|
210
|
-
ranges = [ranges]
|
|
210
|
+
ranges = [ranges];
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
// Return a list of functions which matches the ranges. These functions
|
|
214
214
|
// are processed as an OR clause
|
|
215
215
|
return ranges.map((range: any) => {
|
|
216
|
-
let func: (obj: any) => boolean
|
|
216
|
+
let func: (obj: any) => boolean;
|
|
217
217
|
|
|
218
218
|
if (range.start !== null && range.stop !== null) {
|
|
219
|
-
func = (obj: any): boolean => obj >= range.start && obj <= range.stop
|
|
219
|
+
func = (obj: any): boolean => obj >= range.start && obj <= range.stop;
|
|
220
220
|
} else if (range.start === null && range.stop !== null) {
|
|
221
|
-
func = (obj: any): boolean => obj <= range.stop
|
|
221
|
+
func = (obj: any): boolean => obj <= range.stop;
|
|
222
222
|
} else if (range.start !== null && range.stop === null) {
|
|
223
|
-
func = (obj: any): boolean => obj >= range.start
|
|
223
|
+
func = (obj: any): boolean => obj >= range.start;
|
|
224
224
|
} else {
|
|
225
|
-
func = (obj: any): boolean => true
|
|
225
|
+
func = (obj: any): boolean => true;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
return {
|
|
229
|
-
type:
|
|
229
|
+
type: "RangeExpression",
|
|
230
230
|
start: range.start,
|
|
231
231
|
stop: range.stop,
|
|
232
232
|
match: func,
|
|
233
|
-
} as RangeExpression
|
|
234
|
-
})
|
|
233
|
+
} as RangeExpression;
|
|
234
|
+
});
|
|
235
235
|
})
|
|
236
|
-
.build()
|
|
236
|
+
.build();
|
|
237
237
|
|
|
238
|
-
return parser.parse()
|
|
239
|
-
}
|
|
238
|
+
return parser.parse();
|
|
239
|
+
};
|
|
240
240
|
|
|
241
241
|
const generateMatchFunc = (filter: string) => {
|
|
242
|
-
const result = parseFilter(filter)
|
|
242
|
+
const result = parseFilter(filter);
|
|
243
243
|
if (!result) {
|
|
244
244
|
// const lines = filter.split('\n')
|
|
245
245
|
// const column = lines[lines.length - 1].length
|
|
246
|
-
throw new Error(`Syntax error while parsing '${filter}'.`)
|
|
246
|
+
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
247
247
|
}
|
|
248
|
-
if (result.type ==
|
|
249
|
-
throw new Error(`Syntax error while parsing '${filter}'.`)
|
|
248
|
+
if (result.type == "TermExpression") {
|
|
249
|
+
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
return (obj: any) => {
|
|
253
|
-
if (!result.children) return false
|
|
254
|
-
return result.children.some((c) => c.match(obj))
|
|
255
|
-
}
|
|
256
|
-
}
|
|
253
|
+
if (!result.children) return false;
|
|
254
|
+
return result.children.some((c) => c.match(obj));
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
257
|
|
|
258
258
|
export const generateFacetFunc = (filter: string): ExpressionSet => {
|
|
259
|
-
if (!filter.includes(
|
|
259
|
+
if (!filter.includes(":")) {
|
|
260
260
|
return {
|
|
261
261
|
source: filter,
|
|
262
|
-
type:
|
|
263
|
-
}
|
|
262
|
+
type: "TermExpression",
|
|
263
|
+
};
|
|
264
264
|
}
|
|
265
|
-
return parseFilter(filter)
|
|
266
|
-
}
|
|
265
|
+
return parseFilter(filter);
|
|
266
|
+
};
|
|
267
267
|
|
|
268
268
|
const filterProduct =
|
|
269
269
|
(source: string, exprFunc: MatchFunc): ProductProjectionFilter =>
|
|
270
270
|
(p: ProductProjection, markMatchingVariants: boolean): boolean => {
|
|
271
|
-
const value = nestedLookup(p, source)
|
|
272
|
-
return exprFunc(value)
|
|
273
|
-
}
|
|
271
|
+
const value = nestedLookup(p, source);
|
|
272
|
+
return exprFunc(value);
|
|
273
|
+
};
|
|
274
274
|
|
|
275
275
|
const filterVariants =
|
|
276
276
|
(source: string, exprFunc: MatchFunc): ProductProjectionFilter =>
|
|
277
277
|
(p: ProductProjection, markMatchingVariants: boolean): boolean => {
|
|
278
|
-
const [, ...paths] = source.split(
|
|
279
|
-
const path = paths.join(
|
|
278
|
+
const [, ...paths] = source.split(".");
|
|
279
|
+
const path = paths.join(".");
|
|
280
280
|
|
|
281
|
-
const variants = getVariants(p) as Writable<ProductVariant>[]
|
|
281
|
+
const variants = getVariants(p) as Writable<ProductVariant>[];
|
|
282
282
|
for (const variant of variants) {
|
|
283
|
-
const value = resolveVariantValue(variant, path)
|
|
283
|
+
const value = resolveVariantValue(variant, path);
|
|
284
284
|
|
|
285
285
|
if (exprFunc(value)) {
|
|
286
286
|
// If markMatchingVariants parameter is true those ProductVariants that
|
|
@@ -288,47 +288,49 @@ const filterVariants =
|
|
|
288
288
|
// set to true. For the other variants in the same product projection
|
|
289
289
|
// this field is set to false.
|
|
290
290
|
if (markMatchingVariants) {
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
for (const v of variants) {
|
|
292
|
+
v.isMatchingVariant = false;
|
|
293
|
+
}
|
|
294
|
+
variant.isMatchingVariant = true;
|
|
293
295
|
}
|
|
294
|
-
return true
|
|
296
|
+
return true;
|
|
295
297
|
}
|
|
296
298
|
}
|
|
297
299
|
|
|
298
|
-
return false
|
|
299
|
-
}
|
|
300
|
+
return false;
|
|
301
|
+
};
|
|
300
302
|
|
|
301
303
|
export const resolveVariantValue = (obj: ProductVariant, path: string): any => {
|
|
302
304
|
if (path === undefined) {
|
|
303
|
-
return obj
|
|
305
|
+
return obj;
|
|
304
306
|
}
|
|
305
|
-
if (path.startsWith(
|
|
306
|
-
path = path.substring(path.indexOf(
|
|
307
|
+
if (path.startsWith("variants.")) {
|
|
308
|
+
path = path.substring(path.indexOf(".") + 1);
|
|
307
309
|
}
|
|
308
310
|
|
|
309
|
-
if (path.startsWith(
|
|
310
|
-
const [, attrName, ...rest] = path.split(
|
|
311
|
+
if (path.startsWith("attributes.")) {
|
|
312
|
+
const [, attrName, ...rest] = path.split(".");
|
|
311
313
|
if (!obj.attributes) {
|
|
312
|
-
return undefined
|
|
314
|
+
return undefined;
|
|
313
315
|
}
|
|
314
316
|
|
|
315
317
|
for (const attr of obj.attributes) {
|
|
316
318
|
if (attr.name === attrName) {
|
|
317
|
-
return nestedLookup(attr.value, rest.join(
|
|
319
|
+
return nestedLookup(attr.value, rest.join("."));
|
|
318
320
|
}
|
|
319
321
|
}
|
|
320
322
|
}
|
|
321
323
|
|
|
322
|
-
if (path ===
|
|
324
|
+
if (path === "price.centAmount") {
|
|
323
325
|
return obj.prices && obj.prices.length > 0
|
|
324
326
|
? obj.prices[0].value.centAmount
|
|
325
|
-
: undefined
|
|
327
|
+
: undefined;
|
|
326
328
|
}
|
|
327
329
|
|
|
328
|
-
return nestedLookup(obj, path)
|
|
329
|
-
}
|
|
330
|
+
return nestedLookup(obj, path);
|
|
331
|
+
};
|
|
330
332
|
|
|
331
333
|
export const getVariants = (p: ProductProjection): ProductVariant[] => [
|
|
332
334
|
p.masterVariant,
|
|
333
335
|
...(p.variants ?? []),
|
|
334
|
-
]
|
|
336
|
+
];
|
package/src/lib/proxy.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export const copyHeaders = (headers: Headers) => {
|
|
2
|
-
const validHeaders = [
|
|
3
|
-
const result: Record<string, string> = {}
|
|
2
|
+
const validHeaders = ["accept", "host", "authorization", "content-type"];
|
|
3
|
+
const result: Record<string, string> = {};
|
|
4
4
|
|
|
5
5
|
for (const [key, value] of headers.entries()) {
|
|
6
6
|
if (validHeaders.includes(key.toLowerCase())) {
|
|
7
|
-
result[key] = value
|
|
7
|
+
result[key] = value;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
return result
|
|
12
|
-
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
package/src/oauth/errors.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface InvalidClientError {
|
|
2
|
-
readonly code:
|
|
3
|
-
readonly message: string
|
|
2
|
+
readonly code: "invalid_client";
|
|
3
|
+
readonly message: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface UnsupportedGrantType {
|
|
7
|
-
readonly code:
|
|
8
|
-
readonly message: string
|
|
7
|
+
readonly code: "unsupported_grant_type";
|
|
8
|
+
readonly message: string;
|
|
9
9
|
}
|
package/src/oauth/helpers.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Request } from
|
|
1
|
+
import { Request } from "express";
|
|
2
2
|
|
|
3
3
|
export const getBearerToken = (request: Request): string | undefined => {
|
|
4
|
-
const authHeader = request.header(
|
|
5
|
-
const match = authHeader?.match(/^Bearer\s(?<token>[^\s]+)$/)
|
|
4
|
+
const authHeader = request.header("Authorization");
|
|
5
|
+
const match = authHeader?.match(/^Bearer\s(?<token>[^\s]+)$/);
|
|
6
6
|
if (match) {
|
|
7
|
-
return match.groups?.token
|
|
7
|
+
return match.groups?.token;
|
|
8
8
|
}
|
|
9
|
-
return undefined
|
|
10
|
-
}
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|