UNPKG

@sheerid/jslib-nightly

Version:

SheerID JavaScript Library

342 lines (340 loc) • 13.3 kB
/** * VERSION: 2.230.0-alpha.0 * BUILD_TIMESTAMP: 1778694684677 * BUILD_DATE: Wed May 13 2026 17:51:24 GMT+0000 (Coordinated Universal Time) * BUILD_COMMIT: 7af1c105d5485ac4ed1190c56d492bb4590667a9 */ import { af as y, l as v, ag as b, ah as M, R as w, ai as j, aj as C, ak as R, j as s, L as S, I as T, F as a, t as _, v as F, al as O, E as A, am as D, e as P } from "../sheerid.js"; import { C as k } from "./CopyToClipboardComponent-H3bJGcOM.js"; const z = (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; }, V = { INLINE_IFRAME_CONTENT: "sid-inline-iframe" }, W = "SheerID Verification Form", H = { CLASS_NAMES: V }, N = { className: H.CLASS_NAMES.INLINE_IFRAME_CONTENT, title: W }, Y = (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(z(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 { Y(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 $ 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 B(r, e) { const t = new $(r, e); return t.init(), t; } const E = (r, e = "_top") => { window.open(r, e).focus(); }, G = () => { const e = P().restApi.serviceUrl; return e.includes("services.sheerid.com") || e.includes("my.sheerid.com") ? "https://shr-id.com" : "https://aa-preview.sheerid.net"; }, q = ({ 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, L = !p && !!g.length, d = j( C ) || e.consumerInfoState, I = d === "consumerNotFound" || d === "consumerFoundNewFieldsAvailable", l = R(i, e), x = () => { O(A.SUCCESS_REDIRECT_CLICKED, { programId: t, locale: l, verificationId: o }), E(D(l, t, o), "_blank"); }; return w.useEffect(() => { c.current && (c.current.innerHTML = "", B( c.current, `${G()}/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" } ) }) ] }), L && /* @__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( k, { 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 with redemption instructions. Look for the email from {email}.", tagName: "p", values: { email: "verify@sheerid.com" } } ) } ), 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" } ), I && /* @__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: x, 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" } ) } ) ] }) ] }); }, J = q; export { J as default };