@labdigital/commercetools-mock 1.5.0 → 1.6.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/README.md +5 -4
- package/dist/index.cjs +105 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -7
- package/dist/index.d.ts +29 -7
- package/dist/index.js +105 -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 +116 -52
- 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 +492 -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
|
|
@@ -4245,17 +4270,49 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
|
|
|
4245
4270
|
throw new Error("No valid action");
|
|
4246
4271
|
}
|
|
4247
4272
|
query(context, params = {}) {
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4273
|
+
let resources = this._storage.all(context.projectKey, "product").map((r) => this._searchService.transform(r, params.staged ?? false)).filter((p) => {
|
|
4274
|
+
if (!params.staged) {
|
|
4275
|
+
return p.published;
|
|
4276
|
+
}
|
|
4277
|
+
return true;
|
|
4253
4278
|
});
|
|
4279
|
+
if (params.where) {
|
|
4280
|
+
const variableMap = {};
|
|
4281
|
+
for (const [k, v] of Object.entries(params)) {
|
|
4282
|
+
if (k.startsWith("var.")) {
|
|
4283
|
+
variableMap[k.substring(4)] = v;
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
try {
|
|
4287
|
+
const filterFunc = parseQueryExpression(params.where);
|
|
4288
|
+
resources = resources.filter(
|
|
4289
|
+
(resource) => filterFunc(resource, variableMap)
|
|
4290
|
+
);
|
|
4291
|
+
} catch (err) {
|
|
4292
|
+
throw new CommercetoolsError(
|
|
4293
|
+
{
|
|
4294
|
+
code: "InvalidInput",
|
|
4295
|
+
message: err.message
|
|
4296
|
+
},
|
|
4297
|
+
400
|
|
4298
|
+
);
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4301
|
+
if (params.expand !== void 0) {
|
|
4302
|
+
resources = resources.map(
|
|
4303
|
+
(resource) => this._storage.expand(context.projectKey, resource, params.expand)
|
|
4304
|
+
);
|
|
4305
|
+
}
|
|
4306
|
+
const totalResults = resources.length;
|
|
4307
|
+
const offset = params.offset || 0;
|
|
4308
|
+
const limit = params.limit || 20;
|
|
4309
|
+
const results = resources.slice(offset, offset + limit);
|
|
4254
4310
|
return {
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4311
|
+
count: totalResults,
|
|
4312
|
+
total: results.length,
|
|
4313
|
+
offset,
|
|
4314
|
+
limit,
|
|
4315
|
+
results
|
|
4259
4316
|
};
|
|
4260
4317
|
}
|
|
4261
4318
|
search(context, query) {
|
|
@@ -5693,6 +5750,18 @@ var ProductProjectionService = class extends AbstractService {
|
|
|
5693
5750
|
extraRoutes(router) {
|
|
5694
5751
|
router.get("/search", this.search.bind(this));
|
|
5695
5752
|
}
|
|
5753
|
+
get(request, response) {
|
|
5754
|
+
const limit = this._parseParam(request.query.limit);
|
|
5755
|
+
const offset = this._parseParam(request.query.offset);
|
|
5756
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
5757
|
+
...request.query,
|
|
5758
|
+
expand: this._parseParam(request.query.expand),
|
|
5759
|
+
where: this._parseParam(request.query.where),
|
|
5760
|
+
limit: limit !== void 0 ? Number(limit) : void 0,
|
|
5761
|
+
offset: offset !== void 0 ? Number(offset) : void 0
|
|
5762
|
+
});
|
|
5763
|
+
return response.status(200).send(result);
|
|
5764
|
+
}
|
|
5696
5765
|
search(request, response) {
|
|
5697
5766
|
const resource = this.repository.search(
|
|
5698
5767
|
getRepositoryContext(request),
|
|
@@ -5826,6 +5895,18 @@ var ZoneService = class extends AbstractService {
|
|
|
5826
5895
|
}
|
|
5827
5896
|
};
|
|
5828
5897
|
|
|
5898
|
+
// src/services/attribute-group.ts
|
|
5899
|
+
var AttributeGroupService = class extends AbstractService {
|
|
5900
|
+
repository;
|
|
5901
|
+
constructor(parent, repository) {
|
|
5902
|
+
super(parent);
|
|
5903
|
+
this.repository = repository;
|
|
5904
|
+
}
|
|
5905
|
+
getBasePath() {
|
|
5906
|
+
return "attribute-groups";
|
|
5907
|
+
}
|
|
5908
|
+
};
|
|
5909
|
+
|
|
5829
5910
|
// src/services/index.ts
|
|
5830
5911
|
var createServices = (router, repos) => ({
|
|
5831
5912
|
category: new CategoryServices(router, repos["category"]),
|
|
@@ -5846,7 +5927,10 @@ var createServices = (router, repos) => ({
|
|
|
5846
5927
|
),
|
|
5847
5928
|
order: new OrderService(router, repos["order"]),
|
|
5848
5929
|
payment: new PaymentService(router, repos["payment"]),
|
|
5849
|
-
"standalone-price": new StandAlonePriceService(
|
|
5930
|
+
"standalone-price": new StandAlonePriceService(
|
|
5931
|
+
router,
|
|
5932
|
+
repos["standalone-price"]
|
|
5933
|
+
),
|
|
5850
5934
|
"my-cart": new MyCartService(router, repos["my-cart"]),
|
|
5851
5935
|
"my-order": new MyOrderService(router, repos["my-order"]),
|
|
5852
5936
|
"my-customer": new MyCustomerService(router, repos["my-customer"]),
|
|
@@ -5870,6 +5954,10 @@ var createServices = (router, repos) => ({
|
|
|
5870
5954
|
store: new StoreService(router, repos["store"]),
|
|
5871
5955
|
subscription: new SubscriptionService(router, repos["subscription"]),
|
|
5872
5956
|
"tax-category": new TaxCategoryService(router, repos["tax-category"]),
|
|
5957
|
+
"attribute-group": new AttributeGroupService(
|
|
5958
|
+
router,
|
|
5959
|
+
repos["attribute-group"]
|
|
5960
|
+
),
|
|
5873
5961
|
type: new TypeService(router, repos["type"]),
|
|
5874
5962
|
zone: new ZoneService(router, repos["zone"])
|
|
5875
5963
|
});
|