@labdigital/commercetools-mock 2.17.0 → 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 +24 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -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/services/customer.ts +16 -1
package/dist/index.d.cts
CHANGED
|
@@ -16,8 +16,8 @@ declare class OAuth2Store {
|
|
|
16
16
|
constructor(validate?: boolean);
|
|
17
17
|
addToken(token: Token): void;
|
|
18
18
|
getClientToken(clientId: string, clientSecret: string, scope?: string): Token;
|
|
19
|
-
getAnonymousToken(
|
|
20
|
-
getCustomerToken(
|
|
19
|
+
getAnonymousToken(projectKey: string, anonymousId: string | undefined, scope: string): Token;
|
|
20
|
+
getCustomerToken(projectKey: string, customerId: string, scope: string): Token;
|
|
21
21
|
refreshToken(clientId: string, clientSecret: string, refreshToken: string): {
|
|
22
22
|
access_token: string;
|
|
23
23
|
token_type: "Bearer";
|
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ declare class OAuth2Store {
|
|
|
16
16
|
constructor(validate?: boolean);
|
|
17
17
|
addToken(token: Token): void;
|
|
18
18
|
getClientToken(clientId: string, clientSecret: string, scope?: string): Token;
|
|
19
|
-
getAnonymousToken(
|
|
20
|
-
getCustomerToken(
|
|
19
|
+
getAnonymousToken(projectKey: string, anonymousId: string | undefined, scope: string): Token;
|
|
20
|
+
getCustomerToken(projectKey: string, customerId: string, scope: string): Token;
|
|
21
21
|
refreshToken(clientId: string, clientSecret: string, refreshToken: string): {
|
|
22
22
|
access_token: string;
|
|
23
23
|
token_type: "Bearer";
|
package/dist/index.js
CHANGED
|
@@ -1295,7 +1295,7 @@ var OAuth2Store = class {
|
|
|
1295
1295
|
this.addToken(token);
|
|
1296
1296
|
return token;
|
|
1297
1297
|
}
|
|
1298
|
-
getAnonymousToken(
|
|
1298
|
+
getAnonymousToken(projectKey, anonymousId, scope) {
|
|
1299
1299
|
if (!anonymousId) {
|
|
1300
1300
|
anonymousId = uuidv42();
|
|
1301
1301
|
}
|
|
@@ -1304,18 +1304,18 @@ var OAuth2Store = class {
|
|
|
1304
1304
|
token_type: "Bearer",
|
|
1305
1305
|
expires_in: 172800,
|
|
1306
1306
|
scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`,
|
|
1307
|
-
refresh_token:
|
|
1307
|
+
refresh_token: `${projectKey}:${randomBytes(16).toString("base64")}`
|
|
1308
1308
|
};
|
|
1309
1309
|
this.addToken(token);
|
|
1310
1310
|
return token;
|
|
1311
1311
|
}
|
|
1312
|
-
getCustomerToken(
|
|
1312
|
+
getCustomerToken(projectKey, customerId, scope) {
|
|
1313
1313
|
const token = {
|
|
1314
1314
|
access_token: randomBytes(16).toString("base64"),
|
|
1315
1315
|
token_type: "Bearer",
|
|
1316
1316
|
expires_in: 172800,
|
|
1317
1317
|
scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`,
|
|
1318
|
-
refresh_token:
|
|
1318
|
+
refresh_token: `${projectKey}:${randomBytes(16).toString("base64")}`
|
|
1319
1319
|
};
|
|
1320
1320
|
this.addToken(token);
|
|
1321
1321
|
return token;
|
|
@@ -1520,6 +1520,7 @@ var OAuth2Server = class {
|
|
|
1520
1520
|
}
|
|
1521
1521
|
}
|
|
1522
1522
|
async customerTokenHandler(request, response, next) {
|
|
1523
|
+
const projectKey = request.params.projectKey;
|
|
1523
1524
|
const grantType = request.query.grant_type || request.body.grant_type;
|
|
1524
1525
|
if (!grantType) {
|
|
1525
1526
|
return next(
|
|
@@ -1556,7 +1557,7 @@ var OAuth2Server = class {
|
|
|
1556
1557
|
);
|
|
1557
1558
|
}
|
|
1558
1559
|
const customer = result.results[0];
|
|
1559
|
-
const token = this.store.getCustomerToken(
|
|
1560
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
1560
1561
|
return response.status(200).send(token);
|
|
1561
1562
|
}
|
|
1562
1563
|
}
|
|
@@ -1572,6 +1573,7 @@ var OAuth2Server = class {
|
|
|
1572
1573
|
);
|
|
1573
1574
|
}
|
|
1574
1575
|
async anonymousTokenHandler(request, response, next) {
|
|
1576
|
+
const projectKey = request.params.projectKey;
|
|
1575
1577
|
const grantType = request.query.grant_type || request.body.grant_type;
|
|
1576
1578
|
if (!grantType) {
|
|
1577
1579
|
return next(
|
|
@@ -1587,7 +1589,11 @@ var OAuth2Server = class {
|
|
|
1587
1589
|
if (grantType === "client_credentials") {
|
|
1588
1590
|
const scope = request.query.scope?.toString() || request.body.scope?.toString();
|
|
1589
1591
|
const anonymous_id = void 0;
|
|
1590
|
-
const token = this.store.getAnonymousToken(
|
|
1592
|
+
const token = this.store.getAnonymousToken(
|
|
1593
|
+
projectKey,
|
|
1594
|
+
anonymous_id,
|
|
1595
|
+
scope
|
|
1596
|
+
);
|
|
1591
1597
|
return response.status(200).send(token);
|
|
1592
1598
|
}
|
|
1593
1599
|
}
|
|
@@ -7099,6 +7105,18 @@ var CustomerService = class extends AbstractService {
|
|
|
7099
7105
|
getBasePath() {
|
|
7100
7106
|
return "customers";
|
|
7101
7107
|
}
|
|
7108
|
+
post(request, response) {
|
|
7109
|
+
const draft = request.body;
|
|
7110
|
+
const resource = this.repository.create(
|
|
7111
|
+
getRepositoryContext(request),
|
|
7112
|
+
draft
|
|
7113
|
+
);
|
|
7114
|
+
const expanded = this._expandWithId(request, resource.id);
|
|
7115
|
+
const result = {
|
|
7116
|
+
customer: expanded
|
|
7117
|
+
};
|
|
7118
|
+
return response.status(this.createStatusCode).send(result);
|
|
7119
|
+
}
|
|
7102
7120
|
extraRoutes(parent) {
|
|
7103
7121
|
parent.post("/password-token", (request, response) => {
|
|
7104
7122
|
const customer = this.repository.query(getRepositoryContext(request), {
|