@patchstack/connect 0.5.1 → 0.5.2

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/protect.js CHANGED
@@ -4480,6 +4480,33 @@ function createSupabaseGuard({ protection, supabaseUrl, fetchImpl = fetch }) {
4480
4480
  };
4481
4481
  }
4482
4482
 
4483
+ // src/protect/verify-sentinel.js
4484
+ var VERIFY_HEADER = "x-patchstack-verify";
4485
+ var CHALLENGE = "PATCHSTACK_VERIFY_CHALLENGE";
4486
+ function configuredChallenge() {
4487
+ const value = typeof process !== "undefined" ? process.env?.[CHALLENGE] : void 0;
4488
+ return typeof value === "string" && value.length >= 32 ? value : null;
4489
+ }
4490
+ function sameValue(a, b) {
4491
+ if (typeof a !== "string" || typeof b !== "string" || a.length !== b.length) return false;
4492
+ let differs = 0;
4493
+ for (let i = 0; i < a.length; i += 1) differs |= a.charCodeAt(i) ^ b.charCodeAt(i);
4494
+ return differs === 0;
4495
+ }
4496
+ async function sentinelAnswer(offered) {
4497
+ const challenge = configuredChallenge();
4498
+ if (challenge === null || !sameValue(challenge, typeof offered === "string" ? offered : null)) return null;
4499
+ const subtle = globalThis.crypto?.subtle;
4500
+ if (!subtle || typeof subtle.digest !== "function" || typeof TextEncoder === "undefined") return null;
4501
+ try {
4502
+ const bytes = new TextEncoder().encode(`patchstack-verify:${challenge}`);
4503
+ const digest = await subtle.digest("SHA-256", bytes);
4504
+ return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
4505
+ } catch {
4506
+ return null;
4507
+ }
4508
+ }
4509
+
4483
4510
  // src/protect/runtime.js
4484
4511
  function createServerFnGuard({ protection }) {
4485
4512
  const guard = protection.fetchGuard();
@@ -5816,8 +5843,10 @@ function nodeRequestMeta(req, client) {
5816
5843
  export {
5817
5844
  GUARD_PATH,
5818
5845
  PulseRuleClient,
5846
+ VERIFY_HEADER,
5819
5847
  createProtection,
5820
5848
  createServerFnGuard,
5821
- createSupabaseGuard
5849
+ createSupabaseGuard,
5850
+ sentinelAnswer
5822
5851
  };
5823
5852
  //# sourceMappingURL=protect.js.map