@labdigital/commercetools-mock 2.16.1 → 2.17.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 +30 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/oauth/server.test.ts +52 -9
- package/src/oauth/server.ts +8 -2
- package/src/oauth/store.ts +8 -4
- package/src/repositories/cart.ts +12 -0
- package/src/services/cart.test.ts +50 -0
- package/src/services/customer.ts +16 -1
package/dist/index.cjs
CHANGED
|
@@ -1332,7 +1332,7 @@ var OAuth2Store = class {
|
|
|
1332
1332
|
this.addToken(token);
|
|
1333
1333
|
return token;
|
|
1334
1334
|
}
|
|
1335
|
-
getAnonymousToken(
|
|
1335
|
+
getAnonymousToken(projectKey, anonymousId, scope) {
|
|
1336
1336
|
if (!anonymousId) {
|
|
1337
1337
|
anonymousId = (0, import_uuid2.v4)();
|
|
1338
1338
|
}
|
|
@@ -1341,18 +1341,18 @@ var OAuth2Store = class {
|
|
|
1341
1341
|
token_type: "Bearer",
|
|
1342
1342
|
expires_in: 172800,
|
|
1343
1343
|
scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`,
|
|
1344
|
-
refresh_token:
|
|
1344
|
+
refresh_token: `${projectKey}:${(0, import_crypto.randomBytes)(16).toString("base64")}`
|
|
1345
1345
|
};
|
|
1346
1346
|
this.addToken(token);
|
|
1347
1347
|
return token;
|
|
1348
1348
|
}
|
|
1349
|
-
getCustomerToken(
|
|
1349
|
+
getCustomerToken(projectKey, customerId, scope) {
|
|
1350
1350
|
const token = {
|
|
1351
1351
|
access_token: (0, import_crypto.randomBytes)(16).toString("base64"),
|
|
1352
1352
|
token_type: "Bearer",
|
|
1353
1353
|
expires_in: 172800,
|
|
1354
1354
|
scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`,
|
|
1355
|
-
refresh_token:
|
|
1355
|
+
refresh_token: `${projectKey}:${(0, import_crypto.randomBytes)(16).toString("base64")}`
|
|
1356
1356
|
};
|
|
1357
1357
|
this.addToken(token);
|
|
1358
1358
|
return token;
|
|
@@ -1557,6 +1557,7 @@ var OAuth2Server = class {
|
|
|
1557
1557
|
}
|
|
1558
1558
|
}
|
|
1559
1559
|
async customerTokenHandler(request, response, next) {
|
|
1560
|
+
const projectKey = request.params.projectKey;
|
|
1560
1561
|
const grantType = request.query.grant_type || request.body.grant_type;
|
|
1561
1562
|
if (!grantType) {
|
|
1562
1563
|
return next(
|
|
@@ -1593,7 +1594,7 @@ var OAuth2Server = class {
|
|
|
1593
1594
|
);
|
|
1594
1595
|
}
|
|
1595
1596
|
const customer = result.results[0];
|
|
1596
|
-
const token = this.store.getCustomerToken(
|
|
1597
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
1597
1598
|
return response.status(200).send(token);
|
|
1598
1599
|
}
|
|
1599
1600
|
}
|
|
@@ -1609,6 +1610,7 @@ var OAuth2Server = class {
|
|
|
1609
1610
|
);
|
|
1610
1611
|
}
|
|
1611
1612
|
async anonymousTokenHandler(request, response, next) {
|
|
1613
|
+
const projectKey = request.params.projectKey;
|
|
1612
1614
|
const grantType = request.query.grant_type || request.body.grant_type;
|
|
1613
1615
|
if (!grantType) {
|
|
1614
1616
|
return next(
|
|
@@ -1624,7 +1626,11 @@ var OAuth2Server = class {
|
|
|
1624
1626
|
if (grantType === "client_credentials") {
|
|
1625
1627
|
const scope = request.query.scope?.toString() || request.body.scope?.toString();
|
|
1626
1628
|
const anonymous_id = void 0;
|
|
1627
|
-
const token = this.store.getAnonymousToken(
|
|
1629
|
+
const token = this.store.getAnonymousToken(
|
|
1630
|
+
projectKey,
|
|
1631
|
+
anonymous_id,
|
|
1632
|
+
scope
|
|
1633
|
+
);
|
|
1628
1634
|
return response.status(200).send(token);
|
|
1629
1635
|
}
|
|
1630
1636
|
}
|
|
@@ -2603,6 +2609,12 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
2603
2609
|
};
|
|
2604
2610
|
}
|
|
2605
2611
|
},
|
|
2612
|
+
setDirectDiscounts: (context, resource, { discounts }) => {
|
|
2613
|
+
resource.directDiscounts = discounts.map((discount) => ({
|
|
2614
|
+
...discount,
|
|
2615
|
+
id: (0, import_uuid4.v4)()
|
|
2616
|
+
}));
|
|
2617
|
+
},
|
|
2606
2618
|
setLocale: (context, resource, { locale }) => {
|
|
2607
2619
|
resource.locale = locale;
|
|
2608
2620
|
},
|
|
@@ -7130,6 +7142,18 @@ var CustomerService = class extends AbstractService {
|
|
|
7130
7142
|
getBasePath() {
|
|
7131
7143
|
return "customers";
|
|
7132
7144
|
}
|
|
7145
|
+
post(request, response) {
|
|
7146
|
+
const draft = request.body;
|
|
7147
|
+
const resource = this.repository.create(
|
|
7148
|
+
getRepositoryContext(request),
|
|
7149
|
+
draft
|
|
7150
|
+
);
|
|
7151
|
+
const expanded = this._expandWithId(request, resource.id);
|
|
7152
|
+
const result = {
|
|
7153
|
+
customer: expanded
|
|
7154
|
+
};
|
|
7155
|
+
return response.status(this.createStatusCode).send(result);
|
|
7156
|
+
}
|
|
7133
7157
|
extraRoutes(parent) {
|
|
7134
7158
|
parent.post("/password-token", (request, response) => {
|
|
7135
7159
|
const customer = this.repository.query(getRepositoryContext(request), {
|