@ecodev/natural 68.0.3 → 68.0.4
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.
|
@@ -11508,11 +11508,15 @@ const naturalProviders = [
|
|
|
11508
11508
|
localStorageProvider,
|
|
11509
11509
|
];
|
|
11510
11510
|
|
|
11511
|
+
// Keep those strings obfuscated, to make it harder to CTRL+F things in compiled code
|
|
11512
|
+
const cannotSignAGraphQLQueryThatIsUsingFormDataButThatIsMissingTheKeyOperations = atob('Q2Fubm90IHNpZ24gYSBHcmFwaFFMIHF1ZXJ5IHRoYXQgaXMgdXNpbmcgRm9ybURhdGEgYnV0IHRoYXQgaXMgbWlzc2luZyB0aGUga2V5IGBvcGVyYXRpb25zYA==');
|
|
11513
|
+
const graphqlQuerySignerRequiresANonEmptyKeyConfigureItInLocalPphpUnderSignedQueries = atob('Z3JhcGhxbFF1ZXJ5U2lnbmVyIHJlcXVpcmVzIGEgbm9uLWVtcHR5IGtleS4gQ29uZmlndXJlIGl0IGluIGxvY2FsLnBocCB1bmRlciBzaWduZWRRdWVyaWVzLg==');
|
|
11514
|
+
const xSignature = atob('WC1TaWduYXR1cmU=');
|
|
11511
11515
|
function getOperations(req) {
|
|
11512
11516
|
if (req.body instanceof FormData) {
|
|
11513
11517
|
const operations = req.body.get('operations');
|
|
11514
11518
|
if (typeof operations !== 'string') {
|
|
11515
|
-
throw new Error(
|
|
11519
|
+
throw new Error(cannotSignAGraphQLQueryThatIsUsingFormDataButThatIsMissingTheKeyOperations);
|
|
11516
11520
|
}
|
|
11517
11521
|
return operations;
|
|
11518
11522
|
}
|
|
@@ -11529,20 +11533,32 @@ function graphqlQuerySigner(key) {
|
|
|
11529
11533
|
// Validates the configuration exactly 1 time (not for
|
|
11530
11534
|
// every query), and if not reject **all** HTTP requests
|
|
11531
11535
|
if (!key) {
|
|
11532
|
-
return () =>
|
|
11536
|
+
return () => {
|
|
11537
|
+
return throwError(() => new Error(graphqlQuerySignerRequiresANonEmptyKeyConfigureItInLocalPphpUnderSignedQueries));
|
|
11538
|
+
};
|
|
11533
11539
|
}
|
|
11534
11540
|
return (req, next) => {
|
|
11535
11541
|
const mustSign = req.method === 'POST' && /\/graphql(\?|$)/.exec(req.url);
|
|
11536
11542
|
if (!mustSign) {
|
|
11537
11543
|
return next(req);
|
|
11538
11544
|
}
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11545
|
+
return of(req).pipe(map$1(req => {
|
|
11546
|
+
const timestamp = Math.round(Date.now() / 1000);
|
|
11547
|
+
const operations = getOperations(req);
|
|
11548
|
+
return {
|
|
11549
|
+
operations: operations,
|
|
11550
|
+
timestamp: timestamp,
|
|
11551
|
+
payload: timestamp + operations,
|
|
11552
|
+
};
|
|
11553
|
+
}), switchMap(async (data) => {
|
|
11554
|
+
return {
|
|
11555
|
+
...data,
|
|
11556
|
+
hash: await hmacSha256(key, data.payload),
|
|
11557
|
+
};
|
|
11558
|
+
}), switchMap(data => {
|
|
11559
|
+
const header = `v1.${data.timestamp}.${data.hash}`;
|
|
11544
11560
|
const signedRequest = req.clone({
|
|
11545
|
-
headers: req.headers.set(
|
|
11561
|
+
headers: req.headers.set(xSignature, header),
|
|
11546
11562
|
});
|
|
11547
11563
|
return next(signedRequest);
|
|
11548
11564
|
}));
|