@ecodev/natural 65.0.5 → 65.0.8
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.
|
@@ -11356,11 +11356,15 @@ const naturalProviders = [
|
|
|
11356
11356
|
localStorageProvider,
|
|
11357
11357
|
];
|
|
11358
11358
|
|
|
11359
|
+
// Keep those strings obfuscated, to make it harder to CTRL+F things in compiled code
|
|
11360
|
+
const cannotSignAGraphQLQueryThatIsUsingFormDataButThatIsMissingTheKeyOperations = atob('Q2Fubm90IHNpZ24gYSBHcmFwaFFMIHF1ZXJ5IHRoYXQgaXMgdXNpbmcgRm9ybURhdGEgYnV0IHRoYXQgaXMgbWlzc2luZyB0aGUga2V5IGBvcGVyYXRpb25zYA==');
|
|
11361
|
+
const graphqlQuerySignerRequiresANonEmptyKeyConfigureItInLocalPphpUnderSignedQueries = atob('Z3JhcGhxbFF1ZXJ5U2lnbmVyIHJlcXVpcmVzIGEgbm9uLWVtcHR5IGtleS4gQ29uZmlndXJlIGl0IGluIGxvY2FsLnBocCB1bmRlciBzaWduZWRRdWVyaWVzLg==');
|
|
11362
|
+
const xSignature = atob('WC1TaWduYXR1cmU=');
|
|
11359
11363
|
function getOperations(req) {
|
|
11360
11364
|
if (req.body instanceof FormData) {
|
|
11361
11365
|
const operations = req.body.get('operations');
|
|
11362
11366
|
if (typeof operations !== 'string') {
|
|
11363
|
-
throw new Error(
|
|
11367
|
+
throw new Error(cannotSignAGraphQLQueryThatIsUsingFormDataButThatIsMissingTheKeyOperations);
|
|
11364
11368
|
}
|
|
11365
11369
|
return operations;
|
|
11366
11370
|
}
|
|
@@ -11377,20 +11381,32 @@ function graphqlQuerySigner(key) {
|
|
|
11377
11381
|
// Validates the configuration exactly 1 time (not for
|
|
11378
11382
|
// every query), and if not reject **all** HTTP requests
|
|
11379
11383
|
if (!key) {
|
|
11380
|
-
return () =>
|
|
11384
|
+
return () => {
|
|
11385
|
+
return throwError(() => new Error(graphqlQuerySignerRequiresANonEmptyKeyConfigureItInLocalPphpUnderSignedQueries));
|
|
11386
|
+
};
|
|
11381
11387
|
}
|
|
11382
11388
|
return (req, next) => {
|
|
11383
11389
|
const mustSign = req.method === 'POST' && /\/graphql(\?|$)/.exec(req.url);
|
|
11384
11390
|
if (!mustSign) {
|
|
11385
11391
|
return next(req);
|
|
11386
11392
|
}
|
|
11387
|
-
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11393
|
+
return of(req).pipe(map$1(req => {
|
|
11394
|
+
const timestamp = Math.round(Date.now() / 1000);
|
|
11395
|
+
const operations = getOperations(req);
|
|
11396
|
+
return {
|
|
11397
|
+
operations: operations,
|
|
11398
|
+
timestamp: timestamp,
|
|
11399
|
+
payload: timestamp + operations,
|
|
11400
|
+
};
|
|
11401
|
+
}), switchMap(async (data) => {
|
|
11402
|
+
return {
|
|
11403
|
+
...data,
|
|
11404
|
+
hash: await hmacSha256(key, data.payload),
|
|
11405
|
+
};
|
|
11406
|
+
}), switchMap(data => {
|
|
11407
|
+
const header = `v1.${data.timestamp}.${data.hash}`;
|
|
11392
11408
|
const signedRequest = req.clone({
|
|
11393
|
-
headers: req.headers.set(
|
|
11409
|
+
headers: req.headers.set(xSignature, header),
|
|
11394
11410
|
});
|
|
11395
11411
|
return next(signedRequest);
|
|
11396
11412
|
}));
|