@ecodev/natural 68.0.3 → 68.1.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.
@@ -11508,11 +11508,16 @@ 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=');
11515
+ const v1 = atob('djE=');
11511
11516
  function getOperations(req) {
11512
11517
  if (req.body instanceof FormData) {
11513
11518
  const operations = req.body.get('operations');
11514
11519
  if (typeof operations !== 'string') {
11515
- throw new Error('Cannot sign a GraphQL query that is using FormData but that is missing the key `operations`');
11520
+ throw new Error(cannotSignAGraphQLQueryThatIsUsingFormDataButThatIsMissingTheKeyOperations);
11516
11521
  }
11517
11522
  return operations;
11518
11523
  }
@@ -11529,20 +11534,32 @@ function graphqlQuerySigner(key) {
11529
11534
  // Validates the configuration exactly 1 time (not for
11530
11535
  // every query), and if not reject **all** HTTP requests
11531
11536
  if (!key) {
11532
- return () => throwError(() => new Error('graphqlQuerySigner requires a non-empty key. Configure it in local.php under signedQueries.'));
11537
+ return () => {
11538
+ return throwError(() => new Error(graphqlQuerySignerRequiresANonEmptyKeyConfigureItInLocalPphpUnderSignedQueries));
11539
+ };
11533
11540
  }
11534
11541
  return (req, next) => {
11535
11542
  const mustSign = req.method === 'POST' && /\/graphql(\?|$)/.exec(req.url);
11536
11543
  if (!mustSign) {
11537
11544
  return next(req);
11538
11545
  }
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}`;
11546
+ return of(req).pipe(map$1(req => {
11547
+ const timestamp = Math.round(Date.now() / 1000);
11548
+ const operations = getOperations(req);
11549
+ return {
11550
+ operations: operations,
11551
+ timestamp: timestamp,
11552
+ payload: timestamp + operations,
11553
+ };
11554
+ }), switchMap(async (data) => {
11555
+ return {
11556
+ ...data,
11557
+ hash: await hmacSha256(key, data.payload),
11558
+ };
11559
+ }), switchMap(data => {
11560
+ const header = `${v1}.${data.timestamp}.${data.hash}`;
11544
11561
  const signedRequest = req.clone({
11545
- headers: req.headers.set('X-Signature', header),
11562
+ headers: req.headers.set(xSignature, header),
11546
11563
  });
11547
11564
  return next(signedRequest);
11548
11565
  }));