UNPKG

@sheerid/jslib-nightly

Version:

SheerID JavaScript Library

344 lines (342 loc) • 13.2 kB
/** * VERSION: 2.154.0-alpha.1 * BUILD_TIMESTAMP: 1763401515326 * BUILD_DATE: Mon Nov 17 2025 17:45:15 GMT+0000 (Coordinated Universal Time) * BUILD_COMMIT: 73f4468155aaed0f31ab0d59dc3394018b939b6d */ import { aw as y, l as v, ax as b, ay as M, R as w, g as C, az as j, aA as R, j as s, p as S, A as T, c as a, q as _, s as F, C as A, y as O, aB as D, aC as P, aD as k } from "../sheerid.js"; const z = { INLINE_IFRAME_CONTENT: "sid-inline-iframe" }, B = "SheerID Verification Form", V = { CLASS_NAMES: z }, W = (r) => { const e = new URL(r); return new URL(window.location.href).searchParams.forEach((i, o) => { e.searchParams.has(o) || e.searchParams.set(o, i); }), e.href; }, N = { className: V.CLASS_NAMES.INLINE_IFRAME_CONTENT, title: B }, H = (r) => { if (typeof r != "function") throw new Error(`Expected type "function", but received ${typeof r}`); }; class m extends y { containerElement; verificationUrl; isMobileDevice; iframe; verificationIframeUid; locale; hasLoaded = !1; onLoadEvents = []; onCleanupEvents = []; installType = "cdn_inline_iframe"; constructor(e, t) { super(), m.isValidHttpUrl(t) ? (this.containerElement = e, this.verificationUrl = new URL(W(t)), this.verificationIframeUid = m.createUniqueId()) : v.error("Invalid URL. Provide a proper URL: https://example.com/", "iframe url"); } cleanup() { this.onCleanupEvents.forEach((e) => e()); } static createUniqueId() { return Math.random().toString(36).substr(2, 9); } static isValidHttpUrl(e) { try { const t = new URL(e); return t.protocol === "http:" || t.protocol === "https:"; } catch { return !1; } } createIframe(e) { return this.iframe = document.createElement("iframe"), this.iframe.classList.add(e.className), this.iframe.title = e.title, this.iframe.src = this.getIframeUrl(), this.iframe.allow = "camera *;microphone *;geolocation *;clipboard-read *;clipboard-write *", this.iframe.onload = () => this.onLoad(), this.iframe; } getIframeUrl() { const e = new URL(this.verificationUrl); return e.searchParams.set("verificationIframeUid", this.verificationIframeUid), e.searchParams.set(b, window.location.href), e.searchParams.set(M, this.installType), this.locale && e.searchParams.set("locale", this.locale), e.toString(); } // If iFrame hasn't loaded yet, queue up the callback // otherwise call it immediately addOnLoadEvent(e) { try { H(e); } catch { v.error("Invalid callback provided to iFrame.onLoad()", "iframe addOnLoadEvent"); return; } this.hasLoaded ? e() : this.onLoadEvents.push(e); } onLoad() { this.hasLoaded = !0, this.onLoadEvents.forEach((e) => e()); } /** * Using this to add parent window message listeners gives us * - Event Cleanup for modals * - verification of origin, verificationIframeUid, and message data structure */ addWindowMessageListener(e) { const t = (i) => { this.verificationUrl.origin === i.origin && i.data.verificationIframeUid === this.verificationIframeUid && (i.data.action && i.data.action.type ? e(i.data.action) : i.data.action && i.data.height && e(i.data)); }; window.addEventListener("message", t), this.onCleanupEvents.push(() => window.removeEventListener("message", t)); } addActionListener() { this.addWindowMessageListener((e) => { e.type === "hook" && this.emit(e.hook.name, e.hook.data), (e.action && e.action === "updateHeight" || e.type === "updateHeight") && (this.iframe.scrolling = "no", this.iframe.style.height = `${e.height}px`); }); } setViewModel(e) { const t = { action: "setViewModel", viewModel: e }; this.addOnLoadEvent(() => { this.iframe.contentWindow.postMessage(t, this.verificationUrl.origin); }); } setOptions(e) { const t = { action: "setOptions", options: e }; if (!this.hasLoaded && e.locale) { this.locale = e.locale; const i = this.getIframeUrl(); i !== this.iframe.src && (this.iframe.src = i); } this.addOnLoadEvent(() => { this.iframe.contentWindow.postMessage(t, this.verificationUrl.origin); }); } setInstallType(e) { this.installType = e; } init(e = !0) { e && this.createIframe(N), this.addActionListener(), this.containerElement.appendChild(this.iframe); } } class Y extends m { constructor(e, t) { super(e, t), this.verificationUrl = new URL(this.getAffinityUrlWithUID(t)); } static createUniqueId() { return Math.random().toString(36).substr(2, 9); } getAffinityUrlWithUID(e) { const t = new URL(e); return t.searchParams.set("affinityIframeUid", this.verificationIframeUid), t.toString(); } addWindowMessageListener(e) { const t = (i) => { this.verificationUrl.origin === i.origin && i.data.affinityIframeUid === this.verificationIframeUid && i.data.action && i.data.action.type && e(i.data.action); }; window.addEventListener("message", t), this.onCleanupEvents.push(() => window.removeEventListener("message", t)); } createIframe(e) { return this.iframe = document.createElement("iframe"), this.iframe.classList.add(e.className), this.iframe.title = e.title, this.iframe.src = this.verificationUrl.href, this.iframe.allow = "camera;microphone", this.iframe.onload = () => this.onLoad(), this.iframe; } init() { this.createIframe({ ...N, title: "SheerID Affinity Offers" }), this.addActionListener(), this.containerElement.appendChild(this.iframe); } } function $(r, e) { const t = new Y(r, e); return t.init(), t; } const E = (r, e = "_top") => { window.open(r, e).focus(); }, q = () => { switch (O().restApi.serviceUrl) { case "https://services.sheerid.com": return "https://shr-id.com"; default: return "https://aa-preview.sheerid.net"; } }, G = ({ verificationService: r }) => { const { verificationResponse: e, programId: t, viewModel: i } = r, { verificationId: o, redirectUrl: h } = e, { config: u } = r.programTheme, c = w.useRef(null), U = !!h, f = e.rewardCode || "{rewardCode}", p = u.offerType === "noCode", { rewardDisplay: g } = u, x = !p && !!g.length, d = C( j ) || e.consumerInfoState, L = d === "consumerNotFound" || d === "consumerFoundNewFieldsAvailable", l = R(i, e), I = () => { D(P.SUCCESS_REDIRECT_CLICKED, { programId: t, locale: l, verificationId: o }), E(k(l, t, o), "_blank"); }; return w.useEffect(() => { c.current && (c.current.innerHTML = "", $( c.current, `${q()}/affinity/${l}/${t}/${o}` )); }, [c, t, o, l]), /* @__PURE__ */ s.jsxs("div", { id: "sid-step-success", className: "sid-success-container sid-l-container", role: "region", children: [ /* @__PURE__ */ s.jsxs("div", { className: "sid-header sid-l-horz-center sid-l-space-top-md", children: [ /* @__PURE__ */ s.jsx("div", { className: "sid-success-logo-container sid-l-horz-center", children: /* @__PURE__ */ s.jsx( S, { verificationService: r, fallbackLogo: /* @__PURE__ */ s.jsx( "img", { className: "sid-success-logo-default sid-l-lead-image", alt: "", src: "https://assets-resources.sheerid.com/common/images/2018/icons/circle-check.svg" } ) } ) }), /* @__PURE__ */ s.jsx(T, { align: "center", children: /* @__PURE__ */ s.jsx( a, { id: "step.success.title", defaultMessage: "Success! You've been verified.", tagName: "h1" } ) }), /* @__PURE__ */ s.jsx("div", { className: "sid-header__subtitle sid-l-horz-center", children: /* @__PURE__ */ s.jsx( a, { id: "step.success.subtitle", defaultMessage: "You are now eligible for this special offer.", tagName: "p" } ) }) ] }), x && /* @__PURE__ */ s.jsx("div", { className: "sid-l-horz-center sid-reward-container sid-l-space-top-md", children: g.map((n) => n !== _.TEXT ? /* @__PURE__ */ s.jsx( "img", { className: "sid-l-space-top-md sid-barcode", alt: f, src: F(o, "rewardCode", n) }, n ) : /* @__PURE__ */ s.jsxs("div", { children: [ /* @__PURE__ */ s.jsx( "div", { className: "sid-reward-code sid-l-space-top-md sid-h-jumbo-text sid-l-horz-center", role: "region", children: f } ), /* @__PURE__ */ s.jsx("div", { className: "sid-l-space-top-md sid-h-bold-text sid-l-horz-center", children: /* @__PURE__ */ s.jsx( A, { textToCopy: f, notificationText: /* @__PURE__ */ s.jsx(a, { id: "copied", defaultMessage: "Copied" }), children: /* @__PURE__ */ s.jsx( a, { id: "step.success.copyCouponCode", defaultMessage: "Copy coupon code" } ) } ) }) ] }, n)) }), /* @__PURE__ */ s.jsx( "div", { className: `sid-footer sid-success-footer sid-l-horz-center ${p ? "sid-l-space-top-md" : "sid-l-space-top-lg"}`, children: /* @__PURE__ */ s.jsx( a, { id: "step.success.emailNotification", defaultMessage: "We have sent you a confirmation email. Look for the email from verify@sheerid.com.", tagName: "p" } ) } ), U ? /* @__PURE__ */ s.jsx("div", { className: "sid-submit sid-success-submit sid-l-space-top-md", children: /* @__PURE__ */ s.jsx( "button", { type: "button", onClick: () => E(h), className: "sid-btn sid-success-redirect-btn sid-btn--dark", children: /* @__PURE__ */ s.jsx(a, { id: "step.success.redirectButtonText", defaultMessage: "Continue" }) } ) }) : "", /* @__PURE__ */ s.jsx( "div", { className: "sid-footer sid-success-verification-only-footer sid-l-horz-center sid-l-space-top-lg sid-h-small-text", role: "contentinfo", children: /* @__PURE__ */ s.jsx(a, { id: "companyName", defaultMessage: "{Company}", children: (n) => /* @__PURE__ */ s.jsx( a, { id: "step.success.verificationOnly", defaultMessage: ` SheerID handles verification only. Now that you've been approved, please direct all questions about the promotion terms to {companyName} customer service. `, values: { companyName: n }, tagName: "p" } ) }) } ), r.programTheme.affinityProgramEnabled && /* @__PURE__ */ s.jsx( "div", { ref: c, id: "sid-affinity-iframe", className: "sid-affinity-container sid-l-full-width sid-l-space-top-lg" } ), L && /* @__PURE__ */ s.jsxs("div", { className: "sid-remember-me-footer-container", children: [ /* @__PURE__ */ s.jsx("div", { className: "sid-remember-me-title", children: d === "consumerNotFound" ? /* @__PURE__ */ s.jsx( a, { id: "step.success.rememberMe.consumerNotFound.title", defaultMessage: "Save your info for 1-click verification" } ) : /* @__PURE__ */ s.jsx( a, { id: "step.success.rememberMe.consumerFound.title", defaultMessage: "Update Your Profile" } ) }), /* @__PURE__ */ s.jsx("div", { className: "sid-remember-me-description", children: d === "consumerNotFound" ? /* @__PURE__ */ s.jsx(a, { id: "companyName", defaultMessage: "{Company}", children: (n) => /* @__PURE__ */ s.jsx( a, { id: "step.success.rememberMe.consumerNotFound.description", defaultMessage: "Get faster access to future offers with {companyName} and other brands using SheerID's Remember Me service.", values: { companyName: n } } ) }) : /* @__PURE__ */ s.jsx(a, { id: "companyName", defaultMessage: "{Company}", children: (n) => /* @__PURE__ */ s.jsx( a, { id: "step.success.rememberMe.consumerFound.description", defaultMessage: "Save new info for future offers with {companyName} and other brands using SheerID's Remember Me service.", values: { companyName: n } } ) }) }), /* @__PURE__ */ s.jsx( "button", { type: "button", onClick: I, className: "sid-btn sid-remember-me-redirect-btn", children: d === "consumerNotFound" ? /* @__PURE__ */ s.jsx( a, { id: "step.success.rememberMe.consumerNotFound.button", defaultMessage: "Enroll Now" } ) : /* @__PURE__ */ s.jsx( a, { id: "step.success.rememberMe.consumerFound.button", defaultMessage: "Save to Remember Me" } ) } ) ] }) ] }); }, X = G; export { X as default };