@labdigital/commercetools-mock 1.5.0 → 1.6.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/README.md +5 -4
- package/dist/index.cjs +117 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +117 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +90 -90
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -393
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +135 -50
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -151
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +502 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
package/README.md
CHANGED
|
@@ -14,7 +14,8 @@ yarn add --dev @labdigital/commercetools-mock
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Docker image
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
This codebase is also available as a docker image where it provides a runnable http server exposing the mocked endpoints. See
|
|
18
19
|
https://github.com/labd/commercetools-mock-server
|
|
19
20
|
|
|
20
21
|
## Example
|
|
@@ -70,10 +71,10 @@ Implement the following:
|
|
|
70
71
|
- Add new service to src/storage.ts InMemoryStorage
|
|
71
72
|
- Adjust src/types.ts RepositoryMap and possibly serviceTypes
|
|
72
73
|
|
|
73
|
-
|
|
74
74
|
## Releasing
|
|
75
|
+
|
|
75
76
|
This codebases use [@changesets](https://github.com/changesets/changesets) for release and version management
|
|
77
|
+
|
|
76
78
|
- Create a new changeset using `pnpm changeset`
|
|
77
|
-
- Push the changes to the `main` branch.
|
|
79
|
+
- Push the changes to the `main` branch.
|
|
78
80
|
- GitHub actions will create a release PR. When the release is ready merge the release branch
|
|
79
|
-
|
package/dist/index.cjs
CHANGED
|
@@ -231,10 +231,13 @@ var TokenTypes = class {
|
|
|
231
231
|
}
|
|
232
232
|
peek(source, position) {
|
|
233
233
|
const s = source.substr(position);
|
|
234
|
-
return first(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
return first(
|
|
235
|
+
this.tokenTypes.filter((tt) => tt.enabled),
|
|
236
|
+
(tt) => {
|
|
237
|
+
tt.regex.lastIndex = 0;
|
|
238
|
+
return tt.regex.exec(s);
|
|
239
|
+
}
|
|
240
|
+
);
|
|
238
241
|
}
|
|
239
242
|
token(type, pattern, skip = false) {
|
|
240
243
|
this.tokenTypes.push({
|
|
@@ -679,7 +682,7 @@ var validateSymbol = (val) => {
|
|
|
679
682
|
};
|
|
680
683
|
var resolveSymbol = (val, vars) => {
|
|
681
684
|
if (val.type === "var") {
|
|
682
|
-
if (!(val.value in vars)) {
|
|
685
|
+
if (!(val.value in (vars ?? {}))) {
|
|
683
686
|
throw new PredicateError(`Missing parameter value for ${val.value}`);
|
|
684
687
|
}
|
|
685
688
|
return vars[val.value];
|
|
@@ -776,7 +779,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
776
779
|
return (obj, vars) => {
|
|
777
780
|
const value = resolveValue(obj, left);
|
|
778
781
|
if (value) {
|
|
779
|
-
return expr(value);
|
|
782
|
+
return expr(value, vars);
|
|
780
783
|
}
|
|
781
784
|
return false;
|
|
782
785
|
};
|
|
@@ -1753,8 +1756,30 @@ var AttributeGroupRepository = class extends AbstractResourceRepository {
|
|
|
1753
1756
|
return "attribute-group";
|
|
1754
1757
|
}
|
|
1755
1758
|
create(context, draft) {
|
|
1756
|
-
|
|
1759
|
+
const resource = {
|
|
1760
|
+
...getBaseResourceProperties(),
|
|
1761
|
+
name: draft.name,
|
|
1762
|
+
description: draft.description,
|
|
1763
|
+
key: draft.key,
|
|
1764
|
+
attributes: draft.attributes
|
|
1765
|
+
};
|
|
1766
|
+
this.saveNew(context, resource);
|
|
1767
|
+
return resource;
|
|
1757
1768
|
}
|
|
1769
|
+
actions = {
|
|
1770
|
+
setAttributes: (_context, resource, { attributes }) => {
|
|
1771
|
+
resource.attributes = attributes;
|
|
1772
|
+
},
|
|
1773
|
+
changeName: (_context, resource, { name }) => {
|
|
1774
|
+
resource.name = name;
|
|
1775
|
+
},
|
|
1776
|
+
setDescription: (_context, resource, { description }) => {
|
|
1777
|
+
resource.description = description;
|
|
1778
|
+
},
|
|
1779
|
+
setKey: (_context, resource, { key }) => {
|
|
1780
|
+
resource.key = key;
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1758
1783
|
};
|
|
1759
1784
|
|
|
1760
1785
|
// src/repositories/business-unit.ts
|
|
@@ -4244,18 +4269,62 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
|
|
|
4244
4269
|
create(context, draft) {
|
|
4245
4270
|
throw new Error("No valid action");
|
|
4246
4271
|
}
|
|
4272
|
+
get(context, id, params = {}) {
|
|
4273
|
+
const resource = this._storage.get(
|
|
4274
|
+
context.projectKey,
|
|
4275
|
+
"product",
|
|
4276
|
+
id,
|
|
4277
|
+
params
|
|
4278
|
+
);
|
|
4279
|
+
if (resource) {
|
|
4280
|
+
return this._searchService.transform(resource, false);
|
|
4281
|
+
}
|
|
4282
|
+
return null;
|
|
4283
|
+
}
|
|
4247
4284
|
query(context, params = {}) {
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4285
|
+
let resources = this._storage.all(context.projectKey, "product").map((r) => this._searchService.transform(r, params.staged ?? false)).filter((p) => {
|
|
4286
|
+
if (!params.staged) {
|
|
4287
|
+
return p.published;
|
|
4288
|
+
}
|
|
4289
|
+
return true;
|
|
4253
4290
|
});
|
|
4291
|
+
if (params.where) {
|
|
4292
|
+
const variableMap = {};
|
|
4293
|
+
for (const [k, v] of Object.entries(params)) {
|
|
4294
|
+
if (k.startsWith("var.")) {
|
|
4295
|
+
variableMap[k.substring(4)] = v;
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
try {
|
|
4299
|
+
const filterFunc = parseQueryExpression(params.where);
|
|
4300
|
+
resources = resources.filter(
|
|
4301
|
+
(resource) => filterFunc(resource, variableMap)
|
|
4302
|
+
);
|
|
4303
|
+
} catch (err) {
|
|
4304
|
+
throw new CommercetoolsError(
|
|
4305
|
+
{
|
|
4306
|
+
code: "InvalidInput",
|
|
4307
|
+
message: err.message
|
|
4308
|
+
},
|
|
4309
|
+
400
|
|
4310
|
+
);
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
if (params.expand !== void 0) {
|
|
4314
|
+
resources = resources.map(
|
|
4315
|
+
(resource) => this._storage.expand(context.projectKey, resource, params.expand)
|
|
4316
|
+
);
|
|
4317
|
+
}
|
|
4318
|
+
const totalResults = resources.length;
|
|
4319
|
+
const offset = params.offset || 0;
|
|
4320
|
+
const limit = params.limit || 20;
|
|
4321
|
+
const results = resources.slice(offset, offset + limit);
|
|
4254
4322
|
return {
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4323
|
+
count: totalResults,
|
|
4324
|
+
total: results.length,
|
|
4325
|
+
offset,
|
|
4326
|
+
limit,
|
|
4327
|
+
results
|
|
4259
4328
|
};
|
|
4260
4329
|
}
|
|
4261
4330
|
search(context, query) {
|
|
@@ -5693,6 +5762,18 @@ var ProductProjectionService = class extends AbstractService {
|
|
|
5693
5762
|
extraRoutes(router) {
|
|
5694
5763
|
router.get("/search", this.search.bind(this));
|
|
5695
5764
|
}
|
|
5765
|
+
get(request, response) {
|
|
5766
|
+
const limit = this._parseParam(request.query.limit);
|
|
5767
|
+
const offset = this._parseParam(request.query.offset);
|
|
5768
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
5769
|
+
...request.query,
|
|
5770
|
+
expand: this._parseParam(request.query.expand),
|
|
5771
|
+
where: this._parseParam(request.query.where),
|
|
5772
|
+
limit: limit !== void 0 ? Number(limit) : void 0,
|
|
5773
|
+
offset: offset !== void 0 ? Number(offset) : void 0
|
|
5774
|
+
});
|
|
5775
|
+
return response.status(200).send(result);
|
|
5776
|
+
}
|
|
5696
5777
|
search(request, response) {
|
|
5697
5778
|
const resource = this.repository.search(
|
|
5698
5779
|
getRepositoryContext(request),
|
|
@@ -5826,6 +5907,18 @@ var ZoneService = class extends AbstractService {
|
|
|
5826
5907
|
}
|
|
5827
5908
|
};
|
|
5828
5909
|
|
|
5910
|
+
// src/services/attribute-group.ts
|
|
5911
|
+
var AttributeGroupService = class extends AbstractService {
|
|
5912
|
+
repository;
|
|
5913
|
+
constructor(parent, repository) {
|
|
5914
|
+
super(parent);
|
|
5915
|
+
this.repository = repository;
|
|
5916
|
+
}
|
|
5917
|
+
getBasePath() {
|
|
5918
|
+
return "attribute-groups";
|
|
5919
|
+
}
|
|
5920
|
+
};
|
|
5921
|
+
|
|
5829
5922
|
// src/services/index.ts
|
|
5830
5923
|
var createServices = (router, repos) => ({
|
|
5831
5924
|
category: new CategoryServices(router, repos["category"]),
|
|
@@ -5846,7 +5939,10 @@ var createServices = (router, repos) => ({
|
|
|
5846
5939
|
),
|
|
5847
5940
|
order: new OrderService(router, repos["order"]),
|
|
5848
5941
|
payment: new PaymentService(router, repos["payment"]),
|
|
5849
|
-
"standalone-price": new StandAlonePriceService(
|
|
5942
|
+
"standalone-price": new StandAlonePriceService(
|
|
5943
|
+
router,
|
|
5944
|
+
repos["standalone-price"]
|
|
5945
|
+
),
|
|
5850
5946
|
"my-cart": new MyCartService(router, repos["my-cart"]),
|
|
5851
5947
|
"my-order": new MyOrderService(router, repos["my-order"]),
|
|
5852
5948
|
"my-customer": new MyCustomerService(router, repos["my-customer"]),
|
|
@@ -5870,6 +5966,10 @@ var createServices = (router, repos) => ({
|
|
|
5870
5966
|
store: new StoreService(router, repos["store"]),
|
|
5871
5967
|
subscription: new SubscriptionService(router, repos["subscription"]),
|
|
5872
5968
|
"tax-category": new TaxCategoryService(router, repos["tax-category"]),
|
|
5969
|
+
"attribute-group": new AttributeGroupService(
|
|
5970
|
+
router,
|
|
5971
|
+
repos["attribute-group"]
|
|
5972
|
+
),
|
|
5873
5973
|
type: new TypeService(router, repos["type"]),
|
|
5874
5974
|
zone: new ZoneService(router, repos["zone"])
|
|
5875
5975
|
});
|