UNPKG

@sheerid/jslib-nightly

Version:

SheerID JavaScript Library

350 lines (348 loc) • 13.5 kB
/** * WARNING: This file is intended to be used within MySheerID. * This file is not intended for use in other contexts and there are no guarantees about its behavior outside of MySheerID. */ /** * VERSION: 2.113.0-alpha.0 * BUILD_TIMESTAMP: 1750184650058 * BUILD_DATE: Tue Jun 17 2025 18:24:10 GMT+0000 (Coordinated Universal Time) * BUILD_COMMIT: 896154e79f58fffa6d52f3ed37f2db760a63df88 */ var b = Object.defineProperty; var I = (a, t, e) => t in a ? b(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e; var c = (a, t, e) => I(a, typeof t != "symbol" ? t + "" : t, e); import { aE as M, l as w, aF as j, aG as R, R as N, aH as C, aI as S, aJ as T, j as s, L as F, A as _, b as o, n as A, o as O, C as $, aK as D, v as k } from "../_mysheerid-preview.js"; const P = { INLINE_IFRAME_CONTENT: "sid-inline-iframe" }, H = "SheerID Verification Form", z = { CLASS_NAMES: P }, V = (a) => { const t = new URL(a); return new URL(window.location.href).searchParams.forEach((i, r) => { t.searchParams.has(r) || t.searchParams.set(r, i); }), t.href; }, E = { className: z.CLASS_NAMES.INLINE_IFRAME_CONTENT, title: H }, W = (a) => { if (typeof a != "function") throw new Error(`Expected type "function", but received ${typeof a}`); }; class m extends M { constructor(e, i) { super(); c(this, "containerElement"); c(this, "verificationUrl"); c(this, "isMobileDevice"); c(this, "iframe"); c(this, "verificationIframeUid"); c(this, "hasLoaded", !1); c(this, "onLoadEvents", []); c(this, "onCleanupEvents", []); c(this, "installType", "cdn_inline_iframe"); m.isValidHttpUrl(i) ? (this.containerElement = e, this.verificationUrl = new URL(V(i)), this.verificationIframeUid = m.createUniqueId()) : w.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 i = new URL(e); return i.protocol === "http:" || i.protocol === "https:"; } catch { return !1; } } createIframe(e) { this.iframe = document.createElement("iframe"), this.iframe.classList.add(e.className), this.iframe.title = e.title; let i = "?"; return this.verificationUrl.search && (i = "&"), this.iframe.src = `${this.verificationUrl.href}${i}verificationIframeUid=${this.verificationIframeUid}&${j}=${encodeURIComponent( window.location.href )}&${R}=${this.installType}`, this.iframe.allow = "camera *;microphone *;geolocation *;clipboard-read *;clipboard-write *", this.iframe.onload = () => this.onLoad(), this.iframe; } // If iFrame hasn't loaded yet, queue up the callback // otherwise call it immediately addOnLoadEvent(e) { try { W(e); } catch { w.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 i = (r) => { this.verificationUrl.origin === r.origin && r.data.verificationIframeUid === this.verificationIframeUid && (r.data.action && r.data.action.type ? e(r.data.action) : r.data.action && r.data.height && e(r.data)); }; window.addEventListener("message", i), this.onCleanupEvents.push(() => window.removeEventListener("message", i)); } 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 i = { action: "setViewModel", viewModel: e }; this.addOnLoadEvent(() => { this.iframe.contentWindow.postMessage(i, this.verificationUrl.origin); }); } setOptions(e) { const i = { action: "setOptions", options: e }; this.addOnLoadEvent(() => { this.iframe.contentWindow.postMessage(i, this.verificationUrl.origin); }); } setInstallType(e) { this.installType = e; } init(e = !0) { e && this.createIframe(E), this.addActionListener(), this.containerElement.appendChild(this.iframe); } } class B extends m { constructor(t, e) { super(t, e), this.verificationUrl = new URL(this.getAffinityUrlWithUID(e)); } static createUniqueId() { return Math.random().toString(36).substr(2, 9); } getAffinityUrlWithUID(t) { const e = new URL(t); return e.searchParams.set("affinityIframeUid", this.verificationIframeUid), e.toString(); } addWindowMessageListener(t) { const e = (i) => { this.verificationUrl.origin === i.origin && i.data.affinityIframeUid === this.verificationIframeUid && i.data.action && i.data.action.type && t(i.data.action); }; window.addEventListener("message", e), this.onCleanupEvents.push(() => window.removeEventListener("message", e)); } createIframe(t) { return this.iframe = document.createElement("iframe"), this.iframe.classList.add(t.className), this.iframe.title = t.title, this.iframe.src = this.verificationUrl.href, this.iframe.allow = "camera;microphone", this.iframe.onload = () => this.onLoad(), this.iframe; } init() { this.createIframe({ ...E, title: "SheerID Affinity Offers" }), this.addActionListener(), this.containerElement.appendChild(this.iframe); } } function G(a, t) { const e = new B(a, t); return e.init(), e; } const y = (a, t = "_top") => { window.open(a, t).focus(); }, Y = () => { switch (k().restApi.serviceUrl) { case "https://services.sheerid.com": return "https://shr-id.com"; default: return "https://aa-preview.sheerid.net"; } }, q = ({ verificationService: a }) => { const { verificationResponse: t, programId: e, viewModel: i } = a, { verificationId: r, redirectUrl: u } = t, { config: p } = a.programTheme, d = N.useRef(null), U = !!u, f = t.rewardCode || "{rewardCode}", g = p.offerType === "noCode", { rewardDisplay: v } = p, x = !g && !!v.length, l = C( S ) || t.consumerInfoState, L = l === "consumerNotFound" || l === "consumerFoundNewFieldsAvailable", h = T(i, t); return N.useEffect(() => { d.current && (d.current.innerHTML = "", G( d.current, `${Y()}/affinity/${h}/${e}/${r}` )); }, [d, e, r, h]), /* @__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( F, { verificationService: a, 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(_, { align: "center", children: /* @__PURE__ */ s.jsx( o, { 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( o, { id: "step.success.subtitle", defaultMessage: `Here is your personal coupon code. It is unique to you and can only be used once.`, tagName: "p" } ) }) ] }), x && /* @__PURE__ */ s.jsx("div", { className: "sid-l-horz-center sid-reward-container sid-l-space-top-md", children: v.map((n) => n !== A.TEXT ? /* @__PURE__ */ s.jsx( "img", { className: "sid-l-space-top-md sid-barcode", alt: f, src: O(r, "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( $, { textToCopy: f, notificationText: /* @__PURE__ */ s.jsx(o, { id: "copied", defaultMessage: "Copied" }), children: /* @__PURE__ */ s.jsx( o, { id: "step.success.copyCouponCode", defaultMessage: "Copy Coupon code" } ) } ) }) ] }, n)) }), /* @__PURE__ */ s.jsx( "div", { className: `sid-footer sid-success-footer sid-l-horz-center ${g ? "sid-l-space-top-md" : "sid-l-space-top-lg"}`, children: /* @__PURE__ */ s.jsx( o, { id: "step.success.emailNotification", defaultMessage: "We have emailed you a copy so you can use your code now or later. 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: () => y(u), className: "sid-btn sid-success-redirect-btn sid-btn--dark", children: /* @__PURE__ */ s.jsx( o, { id: "step.success.redirectButtonText", defaultMessage: "Use code now" } ) } ) }) : "", /* @__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(o, { id: "companyName", defaultMessage: "{Company}", children: (n) => /* @__PURE__ */ s.jsx( o, { 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" } ) }) } ), a.programTheme.affinityProgramEnabled && /* @__PURE__ */ s.jsx( "div", { ref: d, 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: l === "consumerNotFound" ? /* @__PURE__ */ s.jsx( o, { id: "step.success.rememberMe.consumerNotFound.title", defaultMessage: "Save your info for 1-click verification" } ) : /* @__PURE__ */ s.jsx( o, { id: "step.success.rememberMe.consumerFound.title", defaultMessage: "Update Your Profile" } ) }), /* @__PURE__ */ s.jsx("div", { className: "sid-remember-me-description", children: l === "consumerNotFound" ? /* @__PURE__ */ s.jsx(o, { id: "companyName", defaultMessage: "{Company}", children: (n) => /* @__PURE__ */ s.jsx( o, { 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(o, { id: "companyName", defaultMessage: "{Company}", children: (n) => /* @__PURE__ */ s.jsx( o, { 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: () => y( D(h, e, r), "_blank" ), className: "sid-btn sid-remember-me-redirect-btn", children: l === "consumerNotFound" ? /* @__PURE__ */ s.jsx( o, { id: "step.success.rememberMe.consumerNotFound.button", defaultMessage: "Enroll Now" } ) : /* @__PURE__ */ s.jsx( o, { id: "step.success.rememberMe.consumerFound.button", defaultMessage: "Save to Remember Me" } ) } ) ] }) ] }); }, X = q; export { X as default };