@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('Cannot sign a GraphQL query that is using FormData but that is missing the key `operations`');
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 () => throwError(() => new Error('graphqlQuerySigner requires a non-empty key. Configure it in local.php under signedQueries.'));
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
- const operations = getOperations(req);
11540
- const timestamp = Math.round(Date.now() / 1000);
11541
- const payload = timestamp + operations;
11542
- return from(hmacSha256(key, payload)).pipe(switchMap(hash => {
11543
- const header = `v1.${timestamp}.${hash}`;
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('X-Signature', header),
11561
+ headers: req.headers.set(xSignature, header),
11546
11562
  });
11547
11563
  return next(signedRequest);
11548
11564
  }));