UNPKG

@sheerid/jslib-nightly

Version:

SheerID JavaScript Library

356 lines (354 loc) • 13.8 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.130.0-alpha.4 * BUILD_TIMESTAMP: 1759000347595 * BUILD_DATE: Sat Sep 27 2025 19:12:27 GMT+0000 (Coordinated Universal Time) * BUILD_COMMIT: be6ef87ab40e8747994d32363389cf39e36a4326 */ var I = Object.defineProperty; var b = (a, t, e) => t in a ? I(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e; var n = (a, t, e) => b(a, typeof t != "symbol" ? t + "" : t, e); import { aF as M, l as w, aG as j, aH as R, R as N, aI as C, aJ as S, aK as T, j as s, L as F, A as _, b as o, o as A, p as O, C as P, aL as D, w as k } from "../_mysheerid-preview.js"; const H = { INLINE_IFRAME_CONTENT: "sid-inline-iframe" }, z = "SheerID Verification Form", V = { CLASS_NAMES: H }, W = (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; }, y = { className: V.CLASS_NAMES.INLINE_IFRAME_CONTENT, title: z }, B = (a) => { if (typeof a != "function") throw new Error(`Expected type "function", but received ${typeof a}`); }; class m extends M { constructor(e, i) { super(); n(this, "containerElement"); n(this, "verificationUrl"); n(this, "isMobileDevice"); n(this, "iframe"); n(this, "verificationIframeUid"); n(this, "locale"); n(this, "hasLoaded", !1); n(this, "onLoadEvents", []); n(this, "onCleanupEvents", []); n(this, "installType", "cdn_inline_iframe"); m.isValidHttpUrl(i) ? (this.containerElement = e, this.verificationUrl = new URL(W(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) { 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(j, window.location.href), e.searchParams.set(R, 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 { B(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 }; if (!this.hasLoaded && e.locale) { this.locale = e.locale; const r = this.getIframeUrl(); r !== this.iframe.src && (this.iframe.src = r); } this.addOnLoadEvent(() => { this.iframe.contentWindow.postMessage(i, this.verificationUrl.origin); }); } setInstallType(e) { this.installType = e; } init(e = !0) { e && this.createIframe(y), this.addActionListener(), this.containerElement.appendChild(this.iframe); } } class $ 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({ ...y, title: "SheerID Affinity Offers" }), this.addActionListener(), this.containerElement.appendChild(this.iframe); } } function G(a, t) { const e = new $(a, t); return e.init(), e; } const U = (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), E = !!u, f = t.rewardCode || "{rewardCode}", g = p.offerType === "noCode", { rewardDisplay: v } = p, L = !g && !!v.length, l = C( S ) || t.consumerInfoState, x = 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" } ) }) ] }), L && /* @__PURE__ */ s.jsx("div", { className: "sid-l-horz-center sid-reward-container sid-l-space-top-md", children: v.map((c) => c !== A.TEXT ? /* @__PURE__ */ s.jsx( "img", { className: "sid-l-space-top-md sid-barcode", alt: f, src: O(r, "rewardCode", c) }, c ) : /* @__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( P, { textToCopy: f, notificationText: /* @__PURE__ */ s.jsx(o, { id: "copied", defaultMessage: "Copied" }), children: /* @__PURE__ */ s.jsx( o, { id: "step.success.copyCouponCode", defaultMessage: "Copy Coupon code" } ) } ) }) ] }, c)) }), /* @__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" } ) } ), E ? /* @__PURE__ */ s.jsx("div", { className: "sid-submit sid-success-submit sid-l-space-top-md", children: /* @__PURE__ */ s.jsx( "button", { type: "button", onClick: () => U(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: (c) => /* @__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: c }, 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" } ), x && /* @__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: (c) => /* @__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: c } } ) }) : /* @__PURE__ */ s.jsx(o, { id: "companyName", defaultMessage: "{Company}", children: (c) => /* @__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: c } } ) }) }), /* @__PURE__ */ s.jsx( "button", { type: "button", onClick: () => U( 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 };