glitchgrab 1.56.0 → 1.57.0

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/index.mjs CHANGED
@@ -665,6 +665,36 @@ async function sendFeedback(payload, baseUrl) {
665
665
  return null;
666
666
  }
667
667
  }
668
+ async function sendLead(token, lead, baseUrl) {
669
+ var _a, _b;
670
+ try {
671
+ const url = `${baseUrl != null ? baseUrl : DEFAULT_BASE_URL}/api/v1/sdk/leads`;
672
+ const body = JSON.stringify(lead);
673
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
674
+ try {
675
+ const response = await fetch(url, {
676
+ method: "POST",
677
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
678
+ body
679
+ });
680
+ if (response.ok) {
681
+ const envelope = await response.json();
682
+ return { success: envelope.success, id: (_a = envelope.data) == null ? void 0 : _a.leadId, created: (_b = envelope.data) == null ? void 0 : _b.created };
683
+ }
684
+ if (response.status >= 400 && response.status < 500 && response.status !== 429) {
685
+ return null;
686
+ }
687
+ } catch (e) {
688
+ }
689
+ if (attempt < MAX_RETRIES - 1) {
690
+ await new Promise((resolve) => setTimeout(resolve, RETRY_BASE_MS * Math.pow(2, attempt)));
691
+ }
692
+ }
693
+ return null;
694
+ } catch (e) {
695
+ return null;
696
+ }
697
+ }
668
698
  function signedFields(identity) {
669
699
  if (!(identity == null ? void 0 : identity.signature) || !identity.userId) return {};
670
700
  return { userId: identity.userId, signature: identity.signature };
@@ -9073,6 +9103,17 @@ function GlitchgrabProviderInner({
9073
9103
  },
9074
9104
  [token, baseUrl, session]
9075
9105
  );
9106
+ const submitLead = useCallback3(
9107
+ async (lead) => {
9108
+ try {
9109
+ const context = captureContext(visitedPagesRef.current);
9110
+ return await sendLead(token, { ...lead, pageUrl: context.url }, baseUrl);
9111
+ } catch (e) {
9112
+ return null;
9113
+ }
9114
+ },
9115
+ [token, baseUrl]
9116
+ );
9076
9117
  const openFeedbackDialog = useCallback3(() => {
9077
9118
  if (typeof window !== "undefined") {
9078
9119
  window.dispatchEvent(
@@ -9250,6 +9291,7 @@ function GlitchgrabProviderInner({
9250
9291
  setContext: setContext2,
9251
9292
  setContexts: setContexts2,
9252
9293
  sendFeedback: feedback,
9294
+ submitLead,
9253
9295
  openFeedbackDialog,
9254
9296
  addBreadcrumb: addBreadcrumb2,
9255
9297
  openReportDialog,
@@ -9714,6 +9756,7 @@ export {
9714
9756
  matchesShortcut,
9715
9757
  sanitizeUrl,
9716
9758
  sendFeedback,
9759
+ sendLead,
9717
9760
  sendReport,
9718
9761
  setContext,
9719
9762
  setContexts,