@hiofu/apply-sdk 0.1.4 → 0.1.6-beta.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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HiofuClient, a as HiofuScope, b as HiofuApplyResult, c as HiofuConfig, d as HiofuEvent, e as HiofuManagementConfig, f as HiofuManagementListRolesParams, g as HiofuManagementPaginatedResult, h as HiofuManagementRoleListItem, i as HiofuManagementRole, j as HiofuManagementCreateRoleInput, k as HiofuManagementUpdateRoleInput, l as HiofuManagementRoleStatus, m as HiofuManagementDeveloperSettings, n as HiofuManagementSaveRoleMappingInput, o as HiofuManagementAddRedirectUriInput, p as HiofuApplyOptions, q as HiofuTokenSet } from './client-Ct5xyQMk.js';
2
- export { D as DEFAULT_APPLY_SCOPES, r as DEFAULT_AUTHORIZE_SCOPES, s as HiofuApplyRole, t as HiofuManagementEnvironment, u as HiofuManagementEnvironmentMode, v as HiofuManagementRedirectUri, w as HiofuManagementRoleDimension, x as HiofuManagementRoleDimensionSkill, y as HiofuManagementRoleMapping, z as HiofuPartner } from './client-Ct5xyQMk.js';
1
+ import { d as HiofuClient, y as HiofuScope, b as HiofuApplyResult, e as HiofuConfig, f as HiofuEvent, h as HiofuManagementConfig, m as HiofuManagementListRolesParams, n as HiofuManagementPaginatedResult, s as HiofuManagementRoleListItem, p as HiofuManagementRole, i as HiofuManagementCreateRoleInput, w as HiofuManagementUpdateRoleInput, u as HiofuManagementRoleStatus, j as HiofuManagementDeveloperSettings, v as HiofuManagementSaveRoleMappingInput, g as HiofuManagementAddRedirectUriInput, H as HiofuApplyOptions, z as HiofuTokenSet } from './client-7yPni-fK.js';
2
+ export { D as DEFAULT_APPLY_SCOPES, a as DEFAULT_AUTHORIZE_SCOPES, c as HiofuApplyRole, k as HiofuManagementEnvironment, l as HiofuManagementEnvironmentMode, o as HiofuManagementRedirectUri, q as HiofuManagementRoleDimension, r as HiofuManagementRoleDimensionSkill, t as HiofuManagementRoleMapping, x as HiofuPartner } from './client-7yPni-fK.js';
3
3
 
4
4
  /**
5
5
  * Scan the document for `[data-hiofu-apply]` buttons and wire them up to call
@@ -48,10 +48,12 @@ declare class HiofuApplyError extends Error {
48
48
  });
49
49
  }
50
50
  interface HiofuCreateApplyClientConfig {
51
- environment: HiofuEnvironment;
52
- /** Publishable partner key: pk_test_* for sandbox, pk_live_* for production. */
51
+ /** Inferred from publicKey prefix when omitted. */
52
+ environment?: HiofuEnvironment;
53
+ /** Publishable key: pk_test_* for sandbox, pk_live_* for production. */
53
54
  publicKey: string;
54
- redirectUri: string;
55
+ /** Defaults to the HIOFU-hosted callback when omitted. */
56
+ redirectUri?: string;
55
57
  scopes?: HiofuScope[];
56
58
  applyScopes?: HiofuScope[];
57
59
  storage?: HiofuConfig["storage"];
@@ -67,9 +69,12 @@ interface HiofuCreateApplyClientConfig {
67
69
  /** Internal/testing override. Partners should use `environment`. */
68
70
  apiBase?: string;
69
71
  }
70
- interface HiofuApplyPayload {
72
+ interface HiofuApplyPayloadBase {
71
73
  externalEmployerId?: string;
72
- externalJobId: string;
74
+ /**
75
+ * Backwards-compatible alias for jobId. Prefer jobId in new integrations.
76
+ */
77
+ externalJobId?: string;
73
78
  role: {
74
79
  title: string;
75
80
  description?: string;
@@ -88,6 +93,13 @@ interface HiofuApplyPayload {
88
93
  scopes?: HiofuScope[];
89
94
  partnerTags?: Record<string, string>;
90
95
  }
96
+ type HiofuApplyPayload = HiofuApplyPayloadBase & ({
97
+ jobId: string;
98
+ externalJobId?: string;
99
+ } | {
100
+ jobId?: string;
101
+ externalJobId: string;
102
+ });
91
103
  interface HiofuNormalizedApplyResult {
92
104
  applicationId: string;
93
105
  partnerApplicationId?: string;
@@ -1 +1 @@
1
- "use strict";var Hiofu=(()=>{var ee=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var We=(e,t)=>{for(var o in t)ee(e,o,{get:t[o],enumerable:!0})},Ye=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ve(t))!Ge.call(e,n)&&n!==o&&ee(e,n,{get:()=>t[n],enumerable:!(i=Je(t,n))||i.enumerable});return e};var Ze=e=>Ye(ee({},"__esModule",{value:!0}),e);var yt={};We(yt,{DEFAULT_APPLY_SCOPES:()=>ce,DEFAULT_AUTHORIZE_SCOPES:()=>ue,HIOFU_BRAND_COLOR:()=>pe,HIOFU_BRAND_SOFT:()=>Oe,HIOFU_BUTTON_LABEL:()=>Ue,HIOFU_FONT_FAMILY:()=>Y,HIOFU_FONT_URL:()=>Ne,HIOFU_TAGLINE:()=>Be,HIOFU_WORDMARK:()=>Me,Hiofu:()=>ht,HiofuApiError:()=>M,HiofuApplyError:()=>T,HiofuClient:()=>S,HiofuConfigurationError:()=>v,HiofuManagementClient:()=>$,HiofuPopupError:()=>U,autoBind:()=>j,bootstrapFromScriptTag:()=>X,createApplyClient:()=>je,createManagementClient:()=>$e,hiofuLogoSvg:()=>Le,isAutoBound:()=>Fe});var A="https://api.hiofu.com/api",M=class extends Error{constructor(o,i,n){super(o);this.status=i;this.body=n}};async function k(e,t={}){let o=new Headers(t.headers);o.set("Content-Type","application/json"),t.token&&o.set("Authorization",`Bearer ${t.token}`);let i=await fetch(e,{...t,headers:o}),n=await i.text(),s=n;try{s=n?JSON.parse(n):null}catch{}if(!i.ok){let r=s?.message?.toString()??`Request failed (${i.status})`;throw new M(r,i.status,s)}return s}async function te(e,t){let o=e.apiBase??A,i=await k(`${o}/oauth/token`,{method:"POST",body:JSON.stringify({grant_type:"authorization_code",client_id:e.clientId,code:t.code,code_verifier:t.verifier,redirect_uri:t.redirectUri})});return{accessToken:i.data.access_token,refreshToken:i.data.refresh_token??null,expiresAt:Date.now()+i.data.expires_in*1e3,scopes:i.data.scope.split(" ").filter(Boolean)}}async function be(e,t){let o=e.apiBase??A,i=await k(`${o}/oauth/token`,{method:"POST",body:JSON.stringify({grant_type:"refresh_token",client_id:e.clientId,refresh_token:t})});return{accessToken:i.data.access_token,refreshToken:i.data.refresh_token??null,expiresAt:Date.now()+i.data.expires_in*1e3,scopes:i.data.scope.split(" ").filter(Boolean)}}async function He(e,t){let o=e.apiBase??A;await k(`${o}/oauth/revoke`,{method:"POST",body:JSON.stringify({token:t,client_id:e.clientId})})}async function we(e,t){let o=e.apiBase??A;return k(`${o}/v1/partner/me`,{token:t})}async function ve(e,t){let o=e.apiBase??A;return k(`${o}/v1/partner/me/full`,{token:t})}async function _e(e,t,o){let i=e.apiBase??A;return k(`${i}/v1/partner/applications`,{method:"POST",token:t,headers:o.idempotencyKey?{"Idempotency-Key":o.idempotencyKey}:void 0,body:JSON.stringify(o)})}var v=class extends Error{constructor(t,o,i){super(o),this.name="HiofuConfigurationError",this.code=t,this.details=i}},Xe=new Set(["https://hiofu.com","https://www.hiofu.com","https://api.hiofu.com"]),Qe=new Set(["https://sandbox.hiofu.com","https://api.sandbox.hiofu.com"]);function et(e){if(e.startsWith("pk_test_"))return"test";if(e.startsWith("pk_live_"))return"live";throw new v("hiofu.configuration_error","Hiofu clientId must start with pk_test_ or pk_live_.",{clientIdPrefix:e.slice(0,8)})}function Se(e){let t;try{t=new URL(e)}catch{throw new v("hiofu.configuration_error","Hiofu origin and API URLs must be absolute URLs.",{value:e})}return["localhost","127.0.0.1","0.0.0.0"].includes(t.hostname)?"local":Qe.has(t.origin)?"sandbox":Xe.has(t.origin)?"production":"unknown"}function xe(e,t,o,i){if(!(t==="local"||t==="unknown")){if(e==="test"&&t==="production")throw new v("hiofu.environment_mismatch","pk_test_* client IDs must use sandbox Hiofu origins, not production.",{field:o,value:i,expected:"sandbox",received:"production"});if(e==="live"&&t==="sandbox")throw new v("hiofu.environment_mismatch","pk_live_* client IDs must use production Hiofu origins, not sandbox.",{field:o,value:i,expected:"production",received:"sandbox"})}}function Ie(e){let t=et(e.clientId);xe(t,Se(e.hiofuOrigin),"hiofuOrigin",e.hiofuOrigin),xe(t,Se(e.apiBase),"apiBase",e.apiBase)}var Ae="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";function oe(e=64){if(e<43||e>128)throw new Error("PKCE verifier length must be 43..128");let t=globalThis.crypto;if(!t?.getRandomValues)throw new Error("Secure random generation is unavailable in this browser.");let o=new Uint8Array(e);t.getRandomValues(o);let i="";for(let n=0;n<e;n++)i+=Ae[o[n]%Ae.length];return i}function tt(e){let t=new Uint8Array(e),o="";for(let i of t)o+=String.fromCharCode(i);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var ot=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function _(e,t){return e>>>t|e<<32-t}function it(e){let t=e.length+1+8;for(;t%64!==0;)t++;let o=new Uint8Array(t);o.set(e),o[e.length]=128;let i=new DataView(o.buffer),n=e.length*8;i.setUint32(t-8,Math.floor(n/4294967296)),i.setUint32(t-4,n>>>0);let s=1779033703,r=3144134277,f=1013904242,p=2773480762,d=1359893119,y=2600822924,l=528734635,h=1541459225,c=new Uint32Array(64);for(let R=0;R<t;R+=64){for(let u=0;u<16;u++)c[u]=i.getUint32(R+u*4);for(let u=16;u<64;u++){let O=_(c[u-15],7)^_(c[u-15],18)^c[u-15]>>>3,H=_(c[u-2],17)^_(c[u-2],19)^c[u-2]>>>10;c[u]=c[u-16]+O+c[u-7]+H>>>0}let m=s,E=r,x=f,b=p,C=d,I=y,w=l,P=h;for(let u=0;u<64;u++){let O=_(C,6)^_(C,11)^_(C,25),H=C&I^~C&w,z=P+O+H+ot[u]+c[u]>>>0,Q=_(m,2)^_(m,13)^_(m,22),K=m&E^m&x^E&x,q=Q+K>>>0;P=w,w=I,I=C,C=b+z>>>0,b=x,x=E,E=m,m=z+q>>>0}s=s+m>>>0,r=r+E>>>0,f=f+x>>>0,p=p+b>>>0,d=d+C>>>0,y=y+I>>>0,l=l+w>>>0,h=h+P>>>0}let g=new ArrayBuffer(32),L=new DataView(g);return[s,r,f,p,d,y,l,h].forEach((R,m)=>{L.setUint32(m*4,R)}),g}async function ke(e){let t=new TextEncoder().encode(e),o=globalThis.crypto?.subtle?.digest?await globalThis.crypto.subtle.digest("SHA-256",t):it(t);return tt(o)}function Te(e=43){return oe(e)}var nt="https://hiofu.com",rt=5*6e4,U=class extends Error{constructor(t,o){super(o),this.name="HiofuPopupError",this.reason=t}};function st(e,t){if(e.redirectUri)return e.redirectUri;let o=new URL(t).origin;return typeof window<"u"&&window.location.origin&&window.location.origin!==o?new URL("/oauth/callback.html",window.location.origin).toString():`${o}/oauth/callback-shim`}async function ie(e,t,o,i){let n=e.hiofuOrigin??nt,s=new URL(n).origin,r=st(e,n),f=e.authorizeTimeoutMs??rt,p=oe(),d=await ke(p),y=Te(),l=new URL(`${n}/oauth/consent`);l.searchParams.set("client_id",e.clientId),l.searchParams.set("redirect_uri",r),l.searchParams.set("scope",t.join(" ")),l.searchParams.set("state",y),l.searchParams.set("code_challenge",d),l.searchParams.set("code_challenge_method","S256"),l.searchParams.set("popup","1"),l.searchParams.set("sdk","apply"),o?.jobId&&l.searchParams.set("job_id",o.jobId),o?.jobTitle&&l.searchParams.set("job_title",o.jobTitle),o?.employerId&&l.searchParams.set("employer_id",o.employerId),o?.employerName&&l.searchParams.set("employer_name",o.employerName),o?.variationId&&l.searchParams.set("variation_id",o.variationId);let h=480,c=720,g=window.screenX+(window.outerWidth-h)/2,L=window.screenY+(window.outerHeight-c)/2,R=`popup=yes,width=${h},height=${c},left=${g},top=${L},scrollbars=yes`,m=window.open(l.toString(),"hiofu_apply",R);if(!m)throw new Error("Popup blocked. Allow popups for this site to continue.");i?.onPopupOpened?.({redirectUri:r});try{localStorage.removeItem("hiofu_oauth_result")}catch{}return new Promise((E,x)=>{let b=!1,C=null,I=null,w=null,P=!1,u=!1,O=()=>{if(b=!0,window.removeEventListener("message",K),window.removeEventListener("storage",q),window.removeEventListener("blur",ge),window.removeEventListener("focus",ye),document.removeEventListener("visibilitychange",he),window.clearInterval(ze),C&&clearTimeout(C),I&&clearTimeout(I),w)try{w.close()}catch{}try{localStorage.removeItem("hiofu_oauth_result")}catch{}},H=(a,B)=>{if(b||!a||a.type!=="hiofu_oauth")return;let D=a.state===y;if(i?.onPopupResultReceived?.({channel:B,hasCode:!!a.code,hasError:!!a.error,stateMatches:D,error:a.error??null,variationId:a.variationId??null}),!!D){if(a.error){O();try{m.close()}catch{}i?.onPopupClosed?.(a.error==="access_denied"?"denied":"completed"),x(new Error(a.error));return}if(a.code){O();try{m.close()}catch{}i?.onPopupClosed?.("completed"),E({code:a.code,state:y,verifier:p,redirectUri:r,variationId:a.variationId??null})}}},z=new URL(r).origin,Q=new Set([s,z]),K=a=>{b||Q.has(a.origin)&&H(a.data,"message")},q=a=>{if(!b&&!(a.key!=="hiofu_oauth_result"||!a.newValue))try{H(JSON.parse(a.newValue),"storage")}catch{}},ge=()=>{P=!0},he=()=>{document.visibilityState==="hidden"&&(P=!0)};if(typeof BroadcastChannel<"u")try{w=new BroadcastChannel("hiofu_oauth"),w.onmessage=a=>{b||H(a.data,"broadcast")}}catch{w=null}let ye=()=>{b||(P&&(u=!0),C&&clearTimeout(C),C=setTimeout(()=>{try{let a=localStorage.getItem("hiofu_oauth_result");if(a){H(JSON.parse(a),"focus_storage");return}}catch{}},3e3))};window.addEventListener("message",K),window.addEventListener("storage",q),window.addEventListener("blur",ge),window.addEventListener("focus",ye),document.addEventListener("visibilitychange",he);let ze=window.setInterval(()=>{if(!b){try{let a=m.location.href;if(a){let B=new URL(a),D=B.searchParams.get("code"),Ke=B.searchParams.get("state"),Ce=B.searchParams.get("error"),qe=B.searchParams.get("variation_id");if(D||Ce){H({type:"hiofu_oauth",code:D,state:Ke,error:Ce,variationId:qe},"poll_url");return}}}catch{}try{let a=localStorage.getItem("hiofu_oauth_result");if(a){H(JSON.parse(a),"poll_storage");return}}catch{}if(m.closed&&u)try{let a=localStorage.getItem("hiofu_oauth_result");a&&H(JSON.parse(a),"close_check")}catch{}}},500);I=window.setTimeout(()=>{if(!b){O();try{m.close()}catch{}i?.onPopupClosed?.("timed_out"),x(new U("timed_out","Authorization timed out. Please try again."))}},f)})}var Re=0;function J(e="hiofu"){let t=globalThis.crypto;if(typeof t?.randomUUID=="function")return`${e}_${t.randomUUID()}`;if(typeof t?.getRandomValues=="function"){let i=new Uint8Array(16);t.getRandomValues(i);let n=Array.from(i,s=>s.toString(16).padStart(2,"0")).join("");return`${e}_${Date.now()}_${n}`}Re+=1;let o=typeof globalThis.performance?.now=="function"?Math.floor(globalThis.performance.now()*1e3):0;return`${e}_${Date.now()}_${o}_${Re}`}var re=new Map;function se(e){return`hiofu:${e}:token`}function at(){return typeof window>"u"?"server":window.location?.origin||"unknown-origin"}function ae(e){return`hiofu:${at()}:${e}:token`}function Ee(e){try{return JSON.parse(e)}catch{return null}}function ne(e){return{...e,refreshToken:null}}function V(e,t){if(t==="memory")return re.get(e)??null;if(typeof window>"u")return null;try{let o=ae(e),i=window.sessionStorage.getItem(o);if(i){let p=Ee(i);return p?ne(p):null}let n=se(e),s=window.sessionStorage.getItem(n);if(!s)return null;let r=Ee(s);if(!r)return null;let f=ne(r);return window.sessionStorage.setItem(o,JSON.stringify(f)),window.sessionStorage.removeItem(n),f}catch{return null}}function G(e,t,o){if(t==="memory"){re.set(e,o);return}if(!(typeof window>"u"))try{window.sessionStorage.setItem(ae(e),JSON.stringify(ne(o))),window.sessionStorage.removeItem(se(e))}catch{}}function le(e,t){if(t==="memory"){re.delete(e);return}if(!(typeof window>"u"))try{window.sessionStorage.removeItem(ae(e)),window.sessionStorage.removeItem(se(e))}catch{}}var ue=["profile.basic"],ce=["applications.write","passport.snapshot"];function Pe(e){return[...new Set(e)]}function lt(e){let t=[...e];return t.includes("applications.write")||t.push("applications.write"),t.includes("passport.snapshot")||t.push("passport.snapshot"),Pe(t)}function ut(){return J()}function W(e){return{expiresAt:e.expiresAt,scopes:[...e.scopes]}}var S=class{constructor(t){this.listeners=new Set;if(!t.clientId)throw new Error("HiofuClient: clientId is required");this.config={...t,hiofuOrigin:t.hiofuOrigin??"https://hiofu.com",apiBase:t.apiBase??"https://api.hiofu.com/api",storage:t.storage??"memory",authorizeTimeoutMs:t.authorizeTimeoutMs??5*6e4},Ie(this.config)}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}emit(t){try{this.config.onEvent?.(t)}catch{}for(let o of this.listeners)try{o(t)}catch{}}async getAccessToken(){let t=V(this.config.clientId,this.config.storage);if(!t)return null;if(t.expiresAt-3e4>Date.now())return t.accessToken;if(!t.refreshToken)return null;try{let o=await be(this.config,t.refreshToken);return G(this.config.clientId,this.config.storage,o),this.emit({type:"token_issued",token:W(o)}),o.accessToken}catch{return le(this.config.clientId,this.config.storage),null}}async authorize(t=this.config.scopes??ue,o){let i=await ie(this.config,Pe(t),o,{onPopupOpened:({redirectUri:r})=>{this.emit({type:"popup_opened",redirectUri:r})},onPopupClosed:r=>{this.emit({type:"popup_closed",reason:r})},onPopupResultReceived:r=>{this.emit({type:"popup_result_received",...r})}}),n=await te(this.config,{code:i.code,verifier:i.verifier,redirectUri:i.redirectUri});G(this.config.clientId,this.config.storage,n);let s=W(n);return this.emit({type:"token_issued",token:s}),s}async apply(t){this.emit({type:"apply_started",input:{jobId:t.jobId,jobTitle:t.jobTitle,employerId:t.employerId,employerName:t.employerName,variationId:t.variationId??void 0}});try{let o=await this.getAccessToken(),i=V(this.config.clientId,this.config.storage),n=lt(t.scopes??this.config.applyScopes??this.config.scopes??ce),s=i&&n.every(l=>i.scopes.includes(l)),r=!t.variationId,f=t.idempotencyKey?.trim()||ut(),p=t.variationId??null;if(!o||!s||r){let l=await ie(this.config,n,{jobId:t.jobId,jobTitle:t.jobTitle,employerId:t.employerId,employerName:t.employerName,variationId:t.variationId},{onPopupOpened:({redirectUri:c})=>{this.emit({type:"popup_opened",redirectUri:c})},onPopupClosed:c=>{this.emit({type:"popup_closed",reason:c})},onPopupResultReceived:c=>{this.emit({type:"popup_result_received",...c})}}),h=await te(this.config,{code:l.code,verifier:l.verifier,redirectUri:l.redirectUri});G(this.config.clientId,this.config.storage,h),this.emit({type:"token_issued",token:W(h)}),i=h,o=h.accessToken,p=l.variationId??t.variationId??null}this.emit({type:"apply_submitting",idempotencyKey:f,variationId:p});let d=await _e(this.config,o,{jobId:t.jobId,jobTitle:t.jobTitle,employerId:t.employerId,employerName:t.employerName,role:t.role,variationId:p??void 0,idempotencyKey:f}),y={application:d.data.application,authorization:W(i),idempotencyKey:f,sharedView:d.data.sharedView??(p?{type:"variation",label:null}:{type:"full_passport",label:null}),versionNumber:d.data.versionNumber??null,profile:d.data.profile??null,evidence:d.data.evidence??null,snapshot:d.data.snapshot??null,delivery:d.data.delivery??null};return this.emit({type:"apply_success",result:y}),y}catch(o){let i=o instanceof Error?o:new Error(String(o));throw this.emit({type:"apply_error",error:i}),i}}async getProfile(t="basic"){let o=await this.getAccessToken();if(!o)throw new Error("Not authorised. Call authorize() or apply().");return t==="full"?ve(this.config,o):we(this.config,o)}async logout(){let t=V(this.config.clientId,this.config.storage);if(t?.accessToken)try{await He(this.config,t.accessToken)}catch{}le(this.config.clientId,this.config.storage)}};var pe="#667eea",Oe="#eaf4ff",Me="HIOFU",Ue="Apply with HSP1",Be="Skills Passport Platform",Y="'Geist', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",Ne="https://fonts.googleapis.com/css2?family=Geist:wght@400;600&display=swap";function Le({size:e=24,color:t=pe}={}){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4000 4000" width="${e}" height="${e}" fill="none" aria-hidden="true"><path fill="${t}" transform="translate(1034,1034)" d="M0 0 C212.85 0 425.7 0 645 0 C645 212.52 645 425.04 645 644 C856.89636356 643.96037473 856.89636356 643.96037473 1068.79272461 643.90991211 C1109.66711426 643.90539551 1109.66711426 643.90539551 1128.76930237 643.90455627 C1143.06830418 643.90355843 1157.3673013 643.89923459 1171.66630179 643.89332657 C1186.22879895 643.88739059 1200.79129313 643.88515942 1215.35379145 643.88655505 C1224.02511491 643.88727558 1232.69642734 643.8852541 1241.36774878 643.8791924 C1247.08119714 643.87546737 1252.79463809 643.87531229 1258.50808695 643.87816466 C1261.76999766 643.87968819 1265.03188252 643.87902557 1268.29379189 643.87511742 C1271.80233562 643.87115732 1275.31082282 643.87323457 1278.8193655 643.87695217 C1279.84998128 643.87432515 1280.88059705 643.87169812 1281.94244361 643.86899149 C1282.86776725 643.87123879 1283.7930909 643.8734861 1284.74645466 643.8758015 C1285.54991085 643.87564552 1286.35336705 643.87548954 1287.1811704 643.87532884 C1289 644 1289 644 1290 645 C1290.09699984 646.41513221 1290.12447387 647.83509264 1290.1241985 649.25354534 C1290.1264458 650.17886899 1290.12869311 651.10419264 1290.13100851 652.05755639 C1290.12706797 653.60348006 1290.12706797 653.60348006 1290.12304783 655.1806345 C1290.12477845 656.81393262 1290.12477845 656.81393262 1290.12654402 658.48022666 C1290.12921807 662.17649429 1290.12468308 665.87271951 1290.12025452 669.56898499 C1290.12069145 672.21977348 1290.12152514 674.87055912 1290.12284851 677.52134705 C1290.12493343 683.3176645 1290.12326705 689.11397171 1290.11921513 694.91028798 C1290.11313165 703.64128822 1290.11284368 712.37228222 1290.11368043 721.1032842 C1290.11492471 735.73246789 1290.11162001 750.36164711 1290.10557556 764.99082947 C1290.09741702 784.77151653 1290.09547353 804.55219592 1290.09460449 824.33288574 C1290.08934731 871.90942474 1290.07538629 919.48596246 1290.0625 967.0625 C1290.041875 1073.301875 1290.02125 1179.54125 1290 1289 C1502.52 1289 1715.04 1289 1934 1289 C1934 1501.85 1934 1714.7 1934 1934 C1721.15 1934 1508.3 1934 1289 1934 C1288.625 1772.5 1288.625 1772.5 1288.52197266 1721.65039062 C1288.48202947 1706.50774795 1288.48202947 1706.50774795 1288.43954468 1691.3651123 C1288.42080214 1684.66068632 1288.40721862 1677.95627536 1288.39730835 1671.25183105 C1288.38581716 1663.49036763 1288.36742107 1655.72895444 1288.34107121 1647.96752676 C1288.3278415 1644.01067253 1288.31732704 1640.05387476 1288.31574559 1636.09699726 C1288.30745247 1620.60432768 1288.04882577 1605.17510698 1287.08163452 1589.70935059 C1287.00124612 1588.42143317 1286.92085773 1587.13351575 1286.83803332 1585.80657053 C1282.06455978 1515.63263785 1252.40600162 1448.19883165 1205.11328125 1396.33203125 C1203.22623463 1394.24965264 1201.38941767 1392.13496936 1199.5625 1390 C1192.95235187 1382.42587194 1185.71742314 1375.4353351 1178 1369 C1177.46697266 1368.55317871 1176.93394531 1368.10635742 1176.38476562 1367.64599609 C1159.24283074 1353.32553103 1141.43739688 1341.01413992 1122 1330 C1121.33468262 1329.61505371 1120.66936523 1329.23010742 1119.98388672 1328.83349609 C1079.10735154 1305.20781221 1028.19860917 1291.13249309 980.95703125 1290.76171875 C979.92285568 1290.7519249 978.88868011 1290.74213104 977.82316589 1290.73204041 C954.89597459 1290.55972646 932.58691104 1290.71914018 910 1295 C908.85321777 1295.21430664 907.70643555 1295.42861328 906.52490234 1295.64941406 C850.7227533 1306.40136369 798.57630888 1331.24788422 756 1369 C755.03191406 1369.85722656 754.06382812 1370.71445313 753.06640625 1371.59765625 C741.20418581 1382.29413391 729.84647149 1393.39927075 720 1406 C719.04945705 1407.16357244 718.09615669 1408.32489584 717.140625 1409.484375 C710.17564591 1417.97433671 703.86187772 1426.7156136 698 1436 C697.63342285 1436.57621094 697.2668457 1437.15242188 696.88916016 1437.74609375 C667.61100204 1484.08675854 650.28720896 1537.03647257 646.91055298 1591.7442627 C646.86805293 1592.4281217 646.82555287 1593.11198071 646.78176494 1593.81656271 C645.83996196 1609.26927039 645.68958126 1624.69941296 645.68335578 1640.17642534 C645.67948705 1644.19779951 645.66412082 1648.21913577 645.6503849 1652.24048615 C645.62553662 1659.99201109 645.61033146 1667.74352268 645.59880099 1675.49507764 C645.58498323 1684.49056295 645.55865582 1693.48598508 645.5324707 1702.48144531 C645.46955608 1726.15427147 645.42326434 1749.82713944 645.375 1773.5 C645.25125 1826.465 645.1275 1879.43 645 1934 C432.15 1934 219.3 1934 0 1934 C0 1721.15 0 1508.3 0 1289 C160.5625 1288.625 160.5625 1288.625 211.12329102 1288.52197266 C226.17547199 1288.48203099 226.17547199 1288.48203099 241.22764587 1288.43954468 C247.89378247 1288.42079659 254.55990392 1288.407216 261.22605896 1288.39730835 C268.94216177 1288.38582173 276.65821399 1288.36743205 284.37428081 1288.34107121 C288.30848121 1288.32783468 292.24262471 1288.31732587 296.17684853 1288.31574559 C311.39652544 1288.3075441 326.56079366 1288.06692488 341.75254822 1287.08944702 C342.99136232 1287.01010599 344.23017642 1286.93076495 345.50653034 1286.84901965 C387.02631279 1283.93222903 427.79434077 1272.55595424 465 1254 C466.31967773 1253.35925537 466.31967773 1253.35925537 467.66601562 1252.70556641 C492.1979482 1240.77197411 514.44418239 1224.84575596 535 1207 C535.80695312 1206.30648437 536.61390625 1205.61296875 537.4453125 1204.8984375 C549.58245126 1194.2424411 561.09572755 1182.76471215 571 1170 C571.94755571 1168.83872009 572.89829595 1167.68003411 573.8515625 1166.5234375 C580.82061869 1158.03191742 587.13612786 1149.28754528 593 1140 C593.36657715 1139.42378906 593.7331543 1138.84757812 594.11083984 1138.25390625 C623.52719041 1091.69451424 642.93520462 1035.77851825 643.203125 980.33984375 C643.21018463 979.36022675 643.21724426 978.38060974 643.22451782 977.37130737 C643.46827251 947.05917734 643.46827251 947.05917734 640 917 C639.79600586 915.85160645 639.59201172 914.70321289 639.38183594 913.52001953 C624.33070602 831.13315773 579.21845208 754.47206937 510.04174805 705.98974609 C499.64395414 698.85804342 488.92923007 692.28184987 478 686 C477.31856934 685.60361328 476.63713867 685.20722656 475.93505859 684.79882812 C421.32602944 653.31303265 359.70138388 645.90857123 297.84687839 645.79942851 C293.78017846 645.79117312 289.71349636 645.77734735 285.64680958 645.76427555 C277.78419488 645.73981035 269.92157578 645.72012322 262.05894377 645.70219031 C252.94736361 645.6811969 243.83580796 645.65411741 234.72424316 645.6270752 C210.71200946 645.55876501 186.69975307 645.4986243 162.6875 645.4375 C109.000625 645.293125 55.31375 645.14875 0 645 C0 432.15 0 219.3 0 0 Z"/><path fill="${t}" opacity="0.55" transform="translate(2665.2273972332478,1033.88392727077)" d="M0 0 C4.13109652 0.00441336 8.26219201 0.00290235 12.39329025 0.00218208 C20.38739589 0.0016536 28.38149015 0.00623972 36.37559288 0.01268341 C45.6357789 0.01992215 54.89595822 0.02068027 64.15614769 0.02146824 C88.56996783 0.02670501 112.98378547 0.04066624 137.39760277 0.05357273 C191.97135277 0.07419773 246.54510277 0.09482273 302.77260277 0.11607273 C302.77260277 212.96607273 302.77260277 425.81607273 302.77260277 645.11607273 C245.88885277 645.17794773 189.00510277 645.23982273 130.39760277 645.30357273 C112.46625999 645.33088474 94.53491722 645.35819675 76.06020042 645.3863364 C54.08778831 645.39988621 54.08778831 645.39988621 43.78685448 645.40240391 C36.62463329 645.40518787 29.46248328 645.41613414 22.30028221 645.43279941 C14.01926219 645.45203915 5.73830981 645.46054737 -2.54273266 645.45640758 C-6.76923774 645.45461797 -10.99559212 645.457241 -15.22206882 645.47371812 C-38.9778459 645.56183254 -62.35832648 644.49213945 -85.66489723 639.42857273 C-86.85824684 639.17366062 -88.05159645 638.91874851 -89.28110817 638.65611179 C-116.04222495 632.75696648 -142.12677201 623.98604368 -166.36020973 611.0960532 C-168.27037284 610.09351728 -170.198279 609.13534185 -172.13364723 608.18247898 C-189.97415333 599.26222593 -206.80822277 587.75093662 -222.22739723 575.11607273 C-222.73706032 574.70115574 -223.24672341 574.28623874 -223.77183083 573.85874851 C-243.26481687 557.928418 -261.11849809 540.28009887 -276.22739723 520.11607273 C-277.12709111 518.93635037 -278.02683124 517.75666329 -278.92661598 516.57701023 C-286.30270586 506.80899554 -292.90835946 496.59425731 -299.22739723 486.11607273 C-299.65907204 485.40144871 -300.09074684 484.68682468 -300.5355027 483.95054539 C-326.42724396 440.54826299 -342.06636784 387.5809744 -342.46567848 336.97544773 C-342.48036926 335.4263068 -342.48036926 335.4263068 -342.49535683 333.84587009 C-342.66772841 310.94951731 -342.5024975 288.67259489 -338.22739723 266.11607273 C-337.90593727 264.39589939 -337.90593727 264.39589939 -337.57798317 262.64097507 C-332.85158743 238.11118756 -325.49772666 214.57345459 -315.38853005 191.7391196 C-314.36606186 189.42932183 -313.36859721 187.11059599 -312.37583473 184.78794773 C-297.62667222 151.13976141 -274.6137392 121.36945591 -249.22739723 95.11607273 C-248.74754372 94.61962253 -248.2676902 94.12317234 -247.77329567 93.6116782 C-242.48368784 88.16894019 -237.05255716 82.9797985 -231.22739723 78.11607273 C-230.70500466 77.67456882 -230.18261208 77.23306492 -229.64438942 76.7781821 C-213.69661083 63.34013123 -196.8285241 51.45493394 -178.5511277 41.3953696 C-177.02513958 40.55525847 -175.50316193 39.70781288 -173.98569801 38.85240085 C-120.15120122 8.53576352 -60.86821967 -0.08189714 0 0 Z"/></svg>`}var fe=!1,F=null;function de(e){if(!e)return;let t=e.split(/[\s,]+/).map(o=>o.trim()).filter(Boolean);return t.length?t:void 0}function De(e){if(!e)return;let t=e.split(",").map(o=>o.trim()).filter(Boolean);return t.length?t:void 0}function Z(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function j(e){if(typeof document>"u")return()=>{};F&&F();let t=async i=>{let n=i.target?.closest("[data-hiofu-apply]");if(!n)return;i.preventDefault();let s=n.getAttribute("data-job-id"),r=n.getAttribute("data-job-title"),f=n.getAttribute("data-employer-id"),p=n.getAttribute("data-employer-name"),d=n.getAttribute("data-external-role-id"),y=n.getAttribute("data-external-employer-id"),l=n.getAttribute("data-hiofu-variation-id")??void 0,h=n.getAttribute("data-hiofu-idempotency-key")??void 0,c=de(n.getAttribute("data-hiofu-scopes"));if(!s||!r){let g=new Error("data-job-id and data-job-title are required");n.dispatchEvent(new CustomEvent("hiofu:apply:error",{bubbles:!0,detail:g}));return}n.setAttribute("data-hiofu-loading","1");try{let g={jobId:s,jobTitle:r};f&&(g.employerId=f),p&&(g.employerName=p),l&&(g.variationId=l),h&&(g.idempotencyKey=h),c&&(g.scopes=c),(d||y)&&(g.role={externalRoleId:d??s,externalEmployerId:y??f??void 0,title:n.getAttribute("data-role-title")??r,description:n.getAttribute("data-role-description")??void 0,department:n.getAttribute("data-role-department")??void 0,locations:De(n.getAttribute("data-role-locations")),jobTypes:De(n.getAttribute("data-role-job-types")),salaryMin:Z(n.getAttribute("data-role-salary-min")),salaryMax:Z(n.getAttribute("data-role-salary-max")),salaryCurrency:n.getAttribute("data-role-salary-currency")??void 0,experienceMin:Z(n.getAttribute("data-role-experience-min")),experienceMax:Z(n.getAttribute("data-role-experience-max"))});let L=await e.apply(g);n.dispatchEvent(new CustomEvent("hiofu:apply:success",{bubbles:!0,detail:L}))}catch(g){n.dispatchEvent(new CustomEvent("hiofu:apply:error",{bubbles:!0,detail:g}))}finally{n.removeAttribute("data-hiofu-loading")}};document.querySelectorAll("[data-hiofu-apply]").forEach(i=>{i.style.fontFamily=Y}),document.addEventListener("click",t),fe=!0;let o=()=>{document.removeEventListener("click",t),fe=!1,F===o&&(F=null)};return F=o,o}function Fe(){return fe}function X(){if(typeof document>"u")return null;let e=document.currentScript;if(!e)return null;let t=e.getAttribute("data-client-id");if(!t)return null;let o={clientId:t,hiofuOrigin:e.getAttribute("data-hiofu-origin")??void 0,apiBase:e.getAttribute("data-api-base")??void 0,redirectUri:e.getAttribute("data-redirect-uri")??void 0,scopes:de(e.getAttribute("data-scopes")),applyScopes:de(e.getAttribute("data-apply-scopes"))},i=new S(o);return j(i),i}var T=class extends Error{constructor(t){super(t.message),this.name="HiofuApplyError",this.code=t.code,this.correlationId=t.correlationId,this.retryable=t.retryable,this.cause=t.cause}},ct={sandbox:{hiofuOrigin:"https://sandbox.hiofu.com",apiBase:"https://api.sandbox.hiofu.com/api"},production:{hiofuOrigin:"https://hiofu.com",apiBase:"https://api.hiofu.com/api"}};function me(){return J()}function pt(e,t){if(e==="sandbox"&&!t.startsWith("pk_test_"))throw new T({code:"environment_mismatch",message:"Sandbox integrations must use a pk_test_* publishable key.",correlationId:me(),retryable:!1});if(e==="production"&&!t.startsWith("pk_live_"))throw new T({code:"environment_mismatch",message:"Production integrations must use a pk_live_* publishable key.",correlationId:me(),retryable:!1})}function ft(e){let t=e.role.locations??(e.role.location?[e.role.location]:void 0),o={jobId:e.externalJobId,jobTitle:e.jobTitle??e.role.title,scopes:e.scopes,variationId:e.variationId,idempotencyKey:e.idempotencyKey,role:{externalRoleId:e.externalJobId,title:e.role.title,description:e.role.description,locations:t,metadata:{...e.role.metadata??{},...e.role.skills?{skills:e.role.skills}:{},...e.role.salary?{salary:e.role.salary}:{},...e.role.dimensions?{dimensions:e.role.dimensions}:{},...e.callbackState?{callbackState:e.callbackState}:{},...e.partnerTags?{partnerTags:e.partnerTags}:{}}}};return e.externalEmployerId&&(o.employerId=e.externalEmployerId,o.role.externalEmployerId=e.externalEmployerId),e.employerName&&(o.employerName=e.employerName),o}function dt(e,t,o){let i=e.application.submittedAt instanceof Date?e.application.submittedAt.toISOString():e.application.submittedAt??new Date().toISOString();return{applicationId:e.application.id,partnerApplicationId:o,hiofuRoleId:e.application.jobId??"",status:e.application.status,environment:t,submittedAt:String(i),raw:e}}function mt(e,t){if(e instanceof T)return e;let o=e instanceof Error?e.message:String(e),i="submit_failed",n=!1;if(e instanceof v)i=e.code==="hiofu.environment_mismatch"?"environment_mismatch":"configuration_error";else if(e instanceof U)e.reason==="timed_out"?i="timeout":i="popup_closed",n=!0;else if(/popup blocked/i.test(o))i="popup_blocked",n=!0;else if(/authorization popup closed|popup closed/i.test(o))i="popup_closed",n=!0;else if(/timed out/i.test(o))i="timeout",n=!0;else if(/unknown or inactive client|redirect_uri not registered|partner is not approved|must accept dpa|unknown scope|scope\(s\) not permitted|pkce/i.test(o))i="configuration_error";else if(/access_denied|consent/i.test(o))i="consent_required";else if(e instanceof M){let s=e.body,r=s?.code??s?.error?.code??"";e.status===401||e.status===403?i="auth_failed":/role/i.test(r)||/role/i.test(o)?i="role_mapping_failed":(i="submit_failed",n=e.status>=500)}return new T({code:i,message:o,correlationId:t,retryable:n,cause:e})}function je(e){pt(e.environment,e.publicKey);let t=ct[e.environment],o=new S({clientId:e.publicKey,hiofuOrigin:e.hiofuOrigin??t.hiofuOrigin,apiBase:e.apiBase??t.apiBase,redirectUri:e.redirectUri,scopes:e.scopes,applyScopes:e.applyScopes,storage:e.storage,authorizeTimeoutMs:e.popupOptions?.timeoutMs,onEvent:e.onEvent});return{rawClient:o,authorize(i){return o.authorize(i)},getAccessToken(){return o.getAccessToken()},logout(){return o.logout()},async apply(i){let n=me();try{let s=await o.apply(ft(i)),r=dt(s,e.environment,i.idempotencyKey);return e.onComplete?.(r),r}catch(s){let r=mt(s,n);throw r.code==="consent_required"?e.onCancel?.({reason:"user_cancelled",correlationId:n}):r.code==="popup_closed"?e.onCancel?.({reason:"popup_closed",correlationId:n}):r.code==="timeout"&&e.onCancel?.({reason:"timeout",correlationId:n}),e.onError?.(r),r}}}}function gt(e){if(!e)return"";let t=new URLSearchParams;typeof e.page=="number"&&t.set("page",String(e.page)),typeof e.limit=="number"&&t.set("limit",String(e.limit)),e.status&&t.set("status",e.status),e.search?.trim()&&t.set("search",e.search.trim());let o=t.toString();return o?`?${o}`:""}var $=class{constructor(t={}){this.config=t}async request(t,o={}){let i=this.config.apiBase??A,n=new Headers(this.config.headers);return o.headers&&new Headers(o.headers).forEach((s,r)=>{n.set(r,s)}),k(`${i}${t}`,{...o,headers:n,token:this.config.accessToken,credentials:this.config.credentials??(this.config.accessToken?void 0:"include")})}async listRoles(t){return this.request(`/employer-roles${gt(t)}`)}async getRole(t){return(await this.request(`/employer-roles/${t}`)).data}async createRole(t){return(await this.request("/employer-roles",{method:"POST",body:JSON.stringify(t)})).data}async updateRole(t,o){return(await this.request(`/employer-roles/${t}`,{method:"PATCH",body:JSON.stringify(o)})).data}async updateRoleStatus(t,o){return(await this.request(`/employer-roles/${t}/status`,{method:"PATCH",body:JSON.stringify({status:o})})).data}async getDeveloperSettings(){return(await this.request("/employers/developer/apply-sdk")).data}async issuePublishableKey(){return(await this.request("/employers/developer/apply-sdk",{method:"POST"})).data}async saveRoleMapping(t){let o=null;return(!t.title||!t.description||!t.locations)&&(o=await this.getRole(t.employerRoleId)),(await this.request("/employers/developer/apply-sdk/role-mappings",{method:"POST",body:JSON.stringify({mode:t.mode,externalRoleId:t.externalRoleId,externalEmployerId:t.externalEmployerId,employerRoleId:t.employerRoleId,title:t.title??o?.title,description:t.description??o?.description??void 0,locations:t.locations??o?.locations??void 0,metadata:t.metadata})})).data}async addRedirectUri(t){return(await this.request("/employers/developer/apply-sdk/redirect-uris",{method:"POST",body:JSON.stringify(t)})).data}async removeRedirectUri(t){return(await this.request(`/employers/developer/apply-sdk/redirect-uris/${t}`,{method:"DELETE"})).data}};function $e(e={}){return new $(e)}var N=null,ht={init(e){return N=new S(e),j(N),N},client(){if(!N)throw new Error("Hiofu.init({ clientId }) was not called");return N},apply(e){return this.client().apply(e)},authorize(e){return this.client().authorize(e)},getAccessToken(){return this.client().getAccessToken()},logout(){return this.client().logout()}};if(typeof document<"u"){let e=X();e&&(N=e)}return Ze(yt);})();
1
+ "use strict";var Hiofu=(()=>{var te=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var Ze=(e,t)=>{for(var o in t)te(e,o,{get:t[o],enumerable:!0})},Xe=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ge(t))!Ye.call(e,n)&&n!==o&&te(e,n,{get:()=>t[n],enumerable:!(i=We(t,n))||i.enumerable});return e};var Qe=e=>Xe(te({},"__esModule",{value:!0}),e);var Ht={};Ze(Ht,{DEFAULT_APPLY_SCOPES:()=>pe,DEFAULT_AUTHORIZE_SCOPES:()=>ce,HIOFU_BRAND_COLOR:()=>de,HIOFU_BRAND_SOFT:()=>Ue,HIOFU_BUTTON_LABEL:()=>Ne,HIOFU_FONT_FAMILY:()=>G,HIOFU_FONT_URL:()=>je,HIOFU_TAGLINE:()=>Le,HIOFU_WORDMARK:()=>Be,Hiofu:()=>Ct,HiofuApiError:()=>L,HiofuApplyError:()=>A,HiofuClient:()=>I,HiofuConfigurationError:()=>_,HiofuManagementClient:()=>z,HiofuPopupError:()=>O,autoBind:()=>$,bootstrapFromScriptTag:()=>Z,createApplyClient:()=>ze,createManagementClient:()=>Ke,hiofuLogoSvg:()=>Fe,isAutoBound:()=>$e});var E="https://api.hiofu.com/api",L=class extends Error{constructor(o,i,n){super(o);this.status=i;this.body=n}};async function P(e,t={}){let o=new Headers(t.headers);o.set("Content-Type","application/json"),t.token&&o.set("Authorization",`Bearer ${t.token}`);let i=await fetch(e,{...t,headers:o}),n=await i.text(),r=n;try{r=n?JSON.parse(n):null}catch{}if(!i.ok){let s=r?.message?.toString()??`Request failed (${i.status})`;throw new L(s,i.status,r)}return r}async function oe(e,t){let o=e.apiBase??E,i=await P(`${o}/oauth/token`,{method:"POST",body:JSON.stringify({grant_type:"authorization_code",client_id:e.clientId,code:t.code,code_verifier:t.verifier,redirect_uri:t.redirectUri})});return{accessToken:i.data.access_token,refreshToken:i.data.refresh_token??null,expiresAt:Date.now()+i.data.expires_in*1e3,scopes:i.data.scope.split(" ").filter(Boolean)}}async function we(e,t){let o=e.apiBase??E,i=await P(`${o}/oauth/token`,{method:"POST",body:JSON.stringify({grant_type:"refresh_token",client_id:e.clientId,refresh_token:t})});return{accessToken:i.data.access_token,refreshToken:i.data.refresh_token??null,expiresAt:Date.now()+i.data.expires_in*1e3,scopes:i.data.scope.split(" ").filter(Boolean)}}async function ve(e,t){let o=e.apiBase??E;await P(`${o}/oauth/revoke`,{method:"POST",body:JSON.stringify({token:t,client_id:e.clientId})})}async function _e(e,t){let o=e.apiBase??E;return P(`${o}/v1/partner/me`,{token:t})}async function xe(e,t){let o=e.apiBase??E;return P(`${o}/v1/partner/me/full`,{token:t})}async function Ie(e,t,o){let i=e.apiBase??E;return P(`${i}/v1/partner/applications`,{method:"POST",token:t,headers:o.idempotencyKey?{"Idempotency-Key":o.idempotencyKey}:void 0,body:JSON.stringify(o)})}var _=class extends Error{constructor(t,o,i){super(o),this.name="HiofuConfigurationError",this.code=t,this.details=i}},et=new Set(["https://hiofu.com","https://www.hiofu.com","https://api.hiofu.com"]),tt=new Set(["https://sandbox.hiofu.com","https://api.sandbox.hiofu.com"]);function ot(e){if(e.startsWith("pk_test_"))return"test";if(e.startsWith("pk_live_"))return"live";throw new _("hiofu.configuration_error","Hiofu clientId must start with pk_test_ or pk_live_.",{clientIdPrefix:e.slice(0,8)})}function Se(e){let t;try{t=new URL(e)}catch{throw new _("hiofu.configuration_error","Hiofu origin and API URLs must be absolute URLs.",{value:e})}return["localhost","127.0.0.1","0.0.0.0"].includes(t.hostname)?"local":tt.has(t.origin)?"sandbox":et.has(t.origin)?"production":"unknown"}function Ae(e,t,o,i){if(!(t==="local"||t==="unknown")){if(e==="test"&&t==="production")throw new _("hiofu.environment_mismatch","pk_test_* client IDs must use sandbox Hiofu origins, not production.",{field:o,value:i,expected:"sandbox",received:"production"});if(e==="live"&&t==="sandbox")throw new _("hiofu.environment_mismatch","pk_live_* client IDs must use production Hiofu origins, not sandbox.",{field:o,value:i,expected:"production",received:"sandbox"})}}function Te(e){let t=ot(e.clientId);Ae(t,Se(e.hiofuOrigin),"hiofuOrigin",e.hiofuOrigin),Ae(t,Se(e.apiBase),"apiBase",e.apiBase)}var ke="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";function ie(e=64){if(e<43||e>128)throw new Error("PKCE verifier length must be 43..128");let t=globalThis.crypto;if(!t?.getRandomValues)throw new Error("Secure random generation is unavailable in this browser.");let o=new Uint8Array(e);t.getRandomValues(o);let i="";for(let n=0;n<e;n++)i+=ke[o[n]%ke.length];return i}function it(e){let t=new Uint8Array(e),o="";for(let i of t)o+=String.fromCharCode(i);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var nt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function x(e,t){return e>>>t|e<<32-t}function rt(e){let t=e.length+1+8;for(;t%64!==0;)t++;let o=new Uint8Array(t);o.set(e),o[e.length]=128;let i=new DataView(o.buffer),n=e.length*8;i.setUint32(t-8,Math.floor(n/4294967296)),i.setUint32(t-4,n>>>0);let r=1779033703,s=3144134277,a=1013904242,m=2773480762,C=1359893119,f=2600822924,l=528734635,h=1541459225,p=new Uint32Array(64);for(let M=0;M<t;M+=64){for(let c=0;c<16;c++)p[c]=i.getUint32(M+c*4);for(let c=16;c<64;c++){let k=x(p[c-15],7)^x(p[c-15],18)^p[c-15]>>>3,R=x(p[c-2],17)^x(p[c-2],19)^p[c-2]>>>10;p[c]=p[c-16]+k+p[c-7]+R>>>0}let g=r,U=s,S=a,b=m,y=C,T=f,H=l,B=h;for(let c=0;c<64;c++){let k=x(y,6)^x(y,11)^x(y,25),R=y&T^~y&H,w=B+k+R+nt[c]+p[c]>>>0,Q=x(g,2)^x(g,13)^x(g,22),ee=g&U^g&S^U&S,K=Q+ee>>>0;B=H,H=T,T=y,y=b+w>>>0,b=S,S=U,U=g,g=w+K>>>0}r=r+g>>>0,s=s+U>>>0,a=a+S>>>0,m=m+b>>>0,C=C+y>>>0,f=f+T>>>0,l=l+H>>>0,h=h+B>>>0}let d=new ArrayBuffer(32),F=new DataView(d);return[r,s,a,m,C,f,l,h].forEach((M,g)=>{F.setUint32(g*4,M)}),d}async function Re(e){let t=new TextEncoder().encode(e),o=globalThis.crypto?.subtle?.digest?await globalThis.crypto.subtle.digest("SHA-256",t):rt(t);return it(o)}function Ee(e=43){return ie(e)}var st="https://hiofu.com",at=5*6e4,O=class extends Error{constructor(t,o){super(o),this.name="HiofuPopupError",this.reason=t}};function lt(e,t){return e.redirectUri?e.redirectUri:`${new URL(t).origin}/oauth/callback-shim`}async function ne(e,t,o,i){let n=e.hiofuOrigin??st,r=new URL(n).origin,s=lt(e,n),a=e.authorizeTimeoutMs??at,m=ie(),C=await Re(m),f=Ee(),l=new URL(`${n}/oauth/consent`);l.searchParams.set("client_id",e.clientId),l.searchParams.set("redirect_uri",s),window.location?.origin&&l.searchParams.set("opener_origin",window.location.origin),l.searchParams.set("scope",t.join(" ")),l.searchParams.set("state",f),l.searchParams.set("code_challenge",C),l.searchParams.set("code_challenge_method","S256"),l.searchParams.set("popup","1"),l.searchParams.set("sdk","apply"),o?.jobId&&l.searchParams.set("job_id",o.jobId),o?.jobTitle&&l.searchParams.set("job_title",o.jobTitle),o?.employerId&&l.searchParams.set("employer_id",o.employerId),o?.employerName&&l.searchParams.set("employer_name",o.employerName),o?.variationId&&l.searchParams.set("variation_id",o.variationId);let h=480,p=720,d=window.screenX+(window.outerWidth-h)/2,F=window.screenY+(window.outerHeight-p)/2,M=`popup=yes,width=${h},height=${p},left=${d},top=${F},scrollbars=yes`,g=window.open(l.toString(),"hiofu_apply",M);if(!g)throw new Error("Popup blocked. Allow popups for this site to continue.");i?.onPopupOpened?.({redirectUri:s});try{localStorage.removeItem("hiofu_oauth_result")}catch{}return new Promise((U,S)=>{let b=!1,y=null,T=null,H=null,B=!1,c=!1,k=null,R=()=>{if(b=!0,window.removeEventListener("message",K),window.removeEventListener("storage",ge),window.removeEventListener("blur",he),window.removeEventListener("focus",be),document.removeEventListener("visibilitychange",ye),window.clearInterval(qe),y&&clearTimeout(y),T&&clearTimeout(T),H)try{H.close()}catch{}try{localStorage.removeItem("hiofu_oauth_result")}catch{}},w=(u,v)=>{if(b||!u||u.type!=="hiofu_oauth")return;let N=u.state===f;if(i?.onPopupResultReceived?.({channel:v,hasCode:!!u.code,hasError:!!u.error,stateMatches:N,error:u.error??null,variationId:u.variationId??null}),!!N){if(u.error){R();try{g.close()}catch{}i?.onPopupClosed?.(u.error==="access_denied"?"denied":"completed"),S(new Error(u.error));return}if(u.code){R();try{g.close()}catch{}i?.onPopupClosed?.("completed"),U({code:u.code,state:f,verifier:m,redirectUri:s,variationId:u.variationId??null})}}},Q=new URL(s).origin,ee=new Set([r,Q]),K=u=>{b||ee.has(u.origin)&&w(u.data,"message")},ge=u=>{if(!b&&!(u.key!=="hiofu_oauth_result"||!u.newValue))try{w(JSON.parse(u.newValue),"storage")}catch{}},he=()=>{B=!0},ye=()=>{document.visibilityState==="hidden"&&(B=!0)};if(typeof BroadcastChannel<"u")try{H=new BroadcastChannel("hiofu_oauth"),H.onmessage=u=>{b||w(u.data,"broadcast")}}catch{H=null}let be=()=>{b||(B&&(c=!0),y&&clearTimeout(y),y=setTimeout(()=>{try{let u=localStorage.getItem("hiofu_oauth_result");if(u){w(JSON.parse(u),"focus_storage");return}}catch{}},3e3))};window.addEventListener("message",K),window.addEventListener("storage",ge),window.addEventListener("blur",he),window.addEventListener("focus",be),document.addEventListener("visibilitychange",ye);let qe=window.setInterval(()=>{if(b)return;try{let v=g.location.href;if(v){let N=new URL(v),Ce=N.searchParams.get("code"),Je=N.searchParams.get("state"),He=N.searchParams.get("error"),Ve=N.searchParams.get("variation_id");if(Ce||He){w({type:"hiofu_oauth",code:Ce,state:Je,error:He,variationId:Ve},"poll_url");return}}}catch{}try{let v=localStorage.getItem("hiofu_oauth_result");if(v){w(JSON.parse(v),"poll_storage");return}}catch{}if(g.closed?k??(k=Date.now()):k=null,g.closed&&k!==null&&c&&document.hasFocus()&&Date.now()-k>5e3){try{let v=localStorage.getItem("hiofu_oauth_result");v&&w(JSON.parse(v),"close_check")}catch{}b||(R(),i?.onPopupClosed?.("user_closed"),S(new O("user_closed","Authorization popup closed before HIOFU could complete the request. Please try again.")))}},500);T=window.setTimeout(()=>{if(!b){R();try{g.close()}catch{}i?.onPopupClosed?.("timed_out"),S(new O("timed_out","Authorization timed out. Please try again."))}},a)})}var Pe=0;function q(e="hiofu"){let t=globalThis.crypto;if(typeof t?.randomUUID=="function")return`${e}_${t.randomUUID()}`;if(typeof t?.getRandomValues=="function"){let i=new Uint8Array(16);t.getRandomValues(i);let n=Array.from(i,r=>r.toString(16).padStart(2,"0")).join("");return`${e}_${Date.now()}_${n}`}Pe+=1;let o=typeof globalThis.performance?.now=="function"?Math.floor(globalThis.performance.now()*1e3):0;return`${e}_${Date.now()}_${o}_${Pe}`}var se=new Map;function ae(e){return`hiofu:${e}:token`}function ut(){return typeof window>"u"?"server":window.location?.origin||"unknown-origin"}function le(e){return`hiofu:${ut()}:${e}:token`}function Oe(e){try{return JSON.parse(e)}catch{return null}}function re(e){return{...e,refreshToken:null}}function J(e,t){if(t==="memory")return se.get(e)??null;if(typeof window>"u")return null;try{let o=le(e),i=window.sessionStorage.getItem(o);if(i){let m=Oe(i);return m?re(m):null}let n=ae(e),r=window.sessionStorage.getItem(n);if(!r)return null;let s=Oe(r);if(!s)return null;let a=re(s);return window.sessionStorage.setItem(o,JSON.stringify(a)),window.sessionStorage.removeItem(n),a}catch{return null}}function V(e,t,o){if(t==="memory"){se.set(e,o);return}if(!(typeof window>"u"))try{window.sessionStorage.setItem(le(e),JSON.stringify(re(o))),window.sessionStorage.removeItem(ae(e))}catch{}}function ue(e,t){if(t==="memory"){se.delete(e);return}if(!(typeof window>"u"))try{window.sessionStorage.removeItem(le(e)),window.sessionStorage.removeItem(ae(e))}catch{}}var ce=["profile.basic"],pe=["applications.write","passport.snapshot"];function Me(e){return[...new Set(e)]}function ct(e){let t=[...e];return t.includes("applications.write")||t.push("applications.write"),t.includes("passport.snapshot")||t.push("passport.snapshot"),Me(t)}function pt(){return q()}function W(e){return{expiresAt:e.expiresAt,scopes:[...e.scopes]}}var I=class{constructor(t){this.listeners=new Set;if(!t.clientId)throw new Error("HiofuClient: clientId is required");let o=t.clientId.startsWith("pk_test_"),i=o?"https://sandbox.hiofu.com":"https://hiofu.com",n=o?"https://api.sandbox.hiofu.com/api":"https://api.hiofu.com/api";this.config={...t,hiofuOrigin:t.hiofuOrigin??i,apiBase:t.apiBase??n,storage:t.storage??"memory",authorizeTimeoutMs:t.authorizeTimeoutMs??5*6e4},Te(this.config)}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}emit(t){try{this.config.onEvent?.(t)}catch{}for(let o of this.listeners)try{o(t)}catch{}}async getAccessToken(){let t=J(this.config.clientId,this.config.storage);if(!t)return null;if(t.expiresAt-3e4>Date.now())return t.accessToken;if(!t.refreshToken)return null;try{let o=await we(this.config,t.refreshToken);return V(this.config.clientId,this.config.storage,o),this.emit({type:"token_issued",token:W(o)}),o.accessToken}catch{return ue(this.config.clientId,this.config.storage),null}}async authorize(t=this.config.scopes??ce,o){let i=await ne(this.config,Me(t),o,{onPopupOpened:({redirectUri:s})=>{this.emit({type:"popup_opened",redirectUri:s})},onPopupClosed:s=>{this.emit({type:"popup_closed",reason:s})},onPopupResultReceived:s=>{this.emit({type:"popup_result_received",...s})}}),n=await oe(this.config,{code:i.code,verifier:i.verifier,redirectUri:i.redirectUri});V(this.config.clientId,this.config.storage,n);let r=W(n);return this.emit({type:"token_issued",token:r}),r}async apply(t){this.emit({type:"apply_started",input:{jobId:t.jobId,jobTitle:t.jobTitle,employerId:t.employerId,employerName:t.employerName,variationId:t.variationId??void 0}});try{let o=await this.getAccessToken(),i=J(this.config.clientId,this.config.storage),n=ct(t.scopes??this.config.applyScopes??this.config.scopes??pe),r=i&&n.every(h=>i.scopes.includes(h)),s=!t.variationId,a=t.idempotencyKey?.trim()||pt(),m=t.variationId??null;if(!o||!r||s){let h=await ne(this.config,n,{jobId:t.jobId,jobTitle:t.jobTitle,employerId:t.employerId,employerName:t.employerName,variationId:t.variationId},{onPopupOpened:({redirectUri:d})=>{this.emit({type:"popup_opened",redirectUri:d})},onPopupClosed:d=>{this.emit({type:"popup_closed",reason:d})},onPopupResultReceived:d=>{this.emit({type:"popup_result_received",...d})}}),p=await oe(this.config,{code:h.code,verifier:h.verifier,redirectUri:h.redirectUri});V(this.config.clientId,this.config.storage,p),this.emit({type:"token_issued",token:W(p)}),i=p,o=p.accessToken,m=h.variationId??t.variationId??null}this.emit({type:"apply_submitting",idempotencyKey:a,variationId:m});let C=t.role?{...t.role,externalRoleId:t.role.externalRoleId||t.jobId,title:t.role.title||t.jobTitle,externalEmployerId:t.role.externalEmployerId||t.employerId||void 0}:{externalRoleId:t.jobId,title:t.jobTitle},f=await Ie(this.config,o,{jobId:t.jobId,jobTitle:t.jobTitle,employerId:t.employerId,employerName:t.employerName,role:C,variationId:m??void 0,idempotencyKey:a}),l={application:f.data.application,authorization:W(i),idempotencyKey:a,sharedView:f.data.sharedView??(m?{type:"variation",label:null}:{type:"full_passport",label:null}),versionNumber:f.data.versionNumber??null,profile:f.data.profile??null,evidence:f.data.evidence??null,snapshot:f.data.snapshot??null,delivery:f.data.delivery??null};return this.emit({type:"apply_success",result:l}),l}catch(o){let i=o instanceof Error?o:new Error(String(o));throw this.emit({type:"apply_error",error:i}),i}}async getProfile(t="basic"){let o=await this.getAccessToken();if(!o)throw new Error("Not authorised. Call authorize() or apply().");return t==="full"?xe(this.config,o):_e(this.config,o)}async logout(){let t=J(this.config.clientId,this.config.storage);if(t?.accessToken)try{await ve(this.config,t.accessToken)}catch{}ue(this.config.clientId,this.config.storage)}};var de="#667eea",Ue="#eaf4ff",Be="HIOFU",Ne="Apply with HSP1",Le="Skills Passport Platform",G="'Geist', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",je="https://fonts.googleapis.com/css2?family=Geist:wght@400;600&display=swap";function Fe({size:e=24,color:t=de}={}){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4000 4000" width="${e}" height="${e}" fill="none" aria-hidden="true"><path fill="${t}" transform="translate(1034,1034)" d="M0 0 C212.85 0 425.7 0 645 0 C645 212.52 645 425.04 645 644 C856.89636356 643.96037473 856.89636356 643.96037473 1068.79272461 643.90991211 C1109.66711426 643.90539551 1109.66711426 643.90539551 1128.76930237 643.90455627 C1143.06830418 643.90355843 1157.3673013 643.89923459 1171.66630179 643.89332657 C1186.22879895 643.88739059 1200.79129313 643.88515942 1215.35379145 643.88655505 C1224.02511491 643.88727558 1232.69642734 643.8852541 1241.36774878 643.8791924 C1247.08119714 643.87546737 1252.79463809 643.87531229 1258.50808695 643.87816466 C1261.76999766 643.87968819 1265.03188252 643.87902557 1268.29379189 643.87511742 C1271.80233562 643.87115732 1275.31082282 643.87323457 1278.8193655 643.87695217 C1279.84998128 643.87432515 1280.88059705 643.87169812 1281.94244361 643.86899149 C1282.86776725 643.87123879 1283.7930909 643.8734861 1284.74645466 643.8758015 C1285.54991085 643.87564552 1286.35336705 643.87548954 1287.1811704 643.87532884 C1289 644 1289 644 1290 645 C1290.09699984 646.41513221 1290.12447387 647.83509264 1290.1241985 649.25354534 C1290.1264458 650.17886899 1290.12869311 651.10419264 1290.13100851 652.05755639 C1290.12706797 653.60348006 1290.12706797 653.60348006 1290.12304783 655.1806345 C1290.12477845 656.81393262 1290.12477845 656.81393262 1290.12654402 658.48022666 C1290.12921807 662.17649429 1290.12468308 665.87271951 1290.12025452 669.56898499 C1290.12069145 672.21977348 1290.12152514 674.87055912 1290.12284851 677.52134705 C1290.12493343 683.3176645 1290.12326705 689.11397171 1290.11921513 694.91028798 C1290.11313165 703.64128822 1290.11284368 712.37228222 1290.11368043 721.1032842 C1290.11492471 735.73246789 1290.11162001 750.36164711 1290.10557556 764.99082947 C1290.09741702 784.77151653 1290.09547353 804.55219592 1290.09460449 824.33288574 C1290.08934731 871.90942474 1290.07538629 919.48596246 1290.0625 967.0625 C1290.041875 1073.301875 1290.02125 1179.54125 1290 1289 C1502.52 1289 1715.04 1289 1934 1289 C1934 1501.85 1934 1714.7 1934 1934 C1721.15 1934 1508.3 1934 1289 1934 C1288.625 1772.5 1288.625 1772.5 1288.52197266 1721.65039062 C1288.48202947 1706.50774795 1288.48202947 1706.50774795 1288.43954468 1691.3651123 C1288.42080214 1684.66068632 1288.40721862 1677.95627536 1288.39730835 1671.25183105 C1288.38581716 1663.49036763 1288.36742107 1655.72895444 1288.34107121 1647.96752676 C1288.3278415 1644.01067253 1288.31732704 1640.05387476 1288.31574559 1636.09699726 C1288.30745247 1620.60432768 1288.04882577 1605.17510698 1287.08163452 1589.70935059 C1287.00124612 1588.42143317 1286.92085773 1587.13351575 1286.83803332 1585.80657053 C1282.06455978 1515.63263785 1252.40600162 1448.19883165 1205.11328125 1396.33203125 C1203.22623463 1394.24965264 1201.38941767 1392.13496936 1199.5625 1390 C1192.95235187 1382.42587194 1185.71742314 1375.4353351 1178 1369 C1177.46697266 1368.55317871 1176.93394531 1368.10635742 1176.38476562 1367.64599609 C1159.24283074 1353.32553103 1141.43739688 1341.01413992 1122 1330 C1121.33468262 1329.61505371 1120.66936523 1329.23010742 1119.98388672 1328.83349609 C1079.10735154 1305.20781221 1028.19860917 1291.13249309 980.95703125 1290.76171875 C979.92285568 1290.7519249 978.88868011 1290.74213104 977.82316589 1290.73204041 C954.89597459 1290.55972646 932.58691104 1290.71914018 910 1295 C908.85321777 1295.21430664 907.70643555 1295.42861328 906.52490234 1295.64941406 C850.7227533 1306.40136369 798.57630888 1331.24788422 756 1369 C755.03191406 1369.85722656 754.06382812 1370.71445313 753.06640625 1371.59765625 C741.20418581 1382.29413391 729.84647149 1393.39927075 720 1406 C719.04945705 1407.16357244 718.09615669 1408.32489584 717.140625 1409.484375 C710.17564591 1417.97433671 703.86187772 1426.7156136 698 1436 C697.63342285 1436.57621094 697.2668457 1437.15242188 696.88916016 1437.74609375 C667.61100204 1484.08675854 650.28720896 1537.03647257 646.91055298 1591.7442627 C646.86805293 1592.4281217 646.82555287 1593.11198071 646.78176494 1593.81656271 C645.83996196 1609.26927039 645.68958126 1624.69941296 645.68335578 1640.17642534 C645.67948705 1644.19779951 645.66412082 1648.21913577 645.6503849 1652.24048615 C645.62553662 1659.99201109 645.61033146 1667.74352268 645.59880099 1675.49507764 C645.58498323 1684.49056295 645.55865582 1693.48598508 645.5324707 1702.48144531 C645.46955608 1726.15427147 645.42326434 1749.82713944 645.375 1773.5 C645.25125 1826.465 645.1275 1879.43 645 1934 C432.15 1934 219.3 1934 0 1934 C0 1721.15 0 1508.3 0 1289 C160.5625 1288.625 160.5625 1288.625 211.12329102 1288.52197266 C226.17547199 1288.48203099 226.17547199 1288.48203099 241.22764587 1288.43954468 C247.89378247 1288.42079659 254.55990392 1288.407216 261.22605896 1288.39730835 C268.94216177 1288.38582173 276.65821399 1288.36743205 284.37428081 1288.34107121 C288.30848121 1288.32783468 292.24262471 1288.31732587 296.17684853 1288.31574559 C311.39652544 1288.3075441 326.56079366 1288.06692488 341.75254822 1287.08944702 C342.99136232 1287.01010599 344.23017642 1286.93076495 345.50653034 1286.84901965 C387.02631279 1283.93222903 427.79434077 1272.55595424 465 1254 C466.31967773 1253.35925537 466.31967773 1253.35925537 467.66601562 1252.70556641 C492.1979482 1240.77197411 514.44418239 1224.84575596 535 1207 C535.80695312 1206.30648437 536.61390625 1205.61296875 537.4453125 1204.8984375 C549.58245126 1194.2424411 561.09572755 1182.76471215 571 1170 C571.94755571 1168.83872009 572.89829595 1167.68003411 573.8515625 1166.5234375 C580.82061869 1158.03191742 587.13612786 1149.28754528 593 1140 C593.36657715 1139.42378906 593.7331543 1138.84757812 594.11083984 1138.25390625 C623.52719041 1091.69451424 642.93520462 1035.77851825 643.203125 980.33984375 C643.21018463 979.36022675 643.21724426 978.38060974 643.22451782 977.37130737 C643.46827251 947.05917734 643.46827251 947.05917734 640 917 C639.79600586 915.85160645 639.59201172 914.70321289 639.38183594 913.52001953 C624.33070602 831.13315773 579.21845208 754.47206937 510.04174805 705.98974609 C499.64395414 698.85804342 488.92923007 692.28184987 478 686 C477.31856934 685.60361328 476.63713867 685.20722656 475.93505859 684.79882812 C421.32602944 653.31303265 359.70138388 645.90857123 297.84687839 645.79942851 C293.78017846 645.79117312 289.71349636 645.77734735 285.64680958 645.76427555 C277.78419488 645.73981035 269.92157578 645.72012322 262.05894377 645.70219031 C252.94736361 645.6811969 243.83580796 645.65411741 234.72424316 645.6270752 C210.71200946 645.55876501 186.69975307 645.4986243 162.6875 645.4375 C109.000625 645.293125 55.31375 645.14875 0 645 C0 432.15 0 219.3 0 0 Z"/><path fill="${t}" opacity="0.55" transform="translate(2665.2273972332478,1033.88392727077)" d="M0 0 C4.13109652 0.00441336 8.26219201 0.00290235 12.39329025 0.00218208 C20.38739589 0.0016536 28.38149015 0.00623972 36.37559288 0.01268341 C45.6357789 0.01992215 54.89595822 0.02068027 64.15614769 0.02146824 C88.56996783 0.02670501 112.98378547 0.04066624 137.39760277 0.05357273 C191.97135277 0.07419773 246.54510277 0.09482273 302.77260277 0.11607273 C302.77260277 212.96607273 302.77260277 425.81607273 302.77260277 645.11607273 C245.88885277 645.17794773 189.00510277 645.23982273 130.39760277 645.30357273 C112.46625999 645.33088474 94.53491722 645.35819675 76.06020042 645.3863364 C54.08778831 645.39988621 54.08778831 645.39988621 43.78685448 645.40240391 C36.62463329 645.40518787 29.46248328 645.41613414 22.30028221 645.43279941 C14.01926219 645.45203915 5.73830981 645.46054737 -2.54273266 645.45640758 C-6.76923774 645.45461797 -10.99559212 645.457241 -15.22206882 645.47371812 C-38.9778459 645.56183254 -62.35832648 644.49213945 -85.66489723 639.42857273 C-86.85824684 639.17366062 -88.05159645 638.91874851 -89.28110817 638.65611179 C-116.04222495 632.75696648 -142.12677201 623.98604368 -166.36020973 611.0960532 C-168.27037284 610.09351728 -170.198279 609.13534185 -172.13364723 608.18247898 C-189.97415333 599.26222593 -206.80822277 587.75093662 -222.22739723 575.11607273 C-222.73706032 574.70115574 -223.24672341 574.28623874 -223.77183083 573.85874851 C-243.26481687 557.928418 -261.11849809 540.28009887 -276.22739723 520.11607273 C-277.12709111 518.93635037 -278.02683124 517.75666329 -278.92661598 516.57701023 C-286.30270586 506.80899554 -292.90835946 496.59425731 -299.22739723 486.11607273 C-299.65907204 485.40144871 -300.09074684 484.68682468 -300.5355027 483.95054539 C-326.42724396 440.54826299 -342.06636784 387.5809744 -342.46567848 336.97544773 C-342.48036926 335.4263068 -342.48036926 335.4263068 -342.49535683 333.84587009 C-342.66772841 310.94951731 -342.5024975 288.67259489 -338.22739723 266.11607273 C-337.90593727 264.39589939 -337.90593727 264.39589939 -337.57798317 262.64097507 C-332.85158743 238.11118756 -325.49772666 214.57345459 -315.38853005 191.7391196 C-314.36606186 189.42932183 -313.36859721 187.11059599 -312.37583473 184.78794773 C-297.62667222 151.13976141 -274.6137392 121.36945591 -249.22739723 95.11607273 C-248.74754372 94.61962253 -248.2676902 94.12317234 -247.77329567 93.6116782 C-242.48368784 88.16894019 -237.05255716 82.9797985 -231.22739723 78.11607273 C-230.70500466 77.67456882 -230.18261208 77.23306492 -229.64438942 76.7781821 C-213.69661083 63.34013123 -196.8285241 51.45493394 -178.5511277 41.3953696 C-177.02513958 40.55525847 -175.50316193 39.70781288 -173.98569801 38.85240085 C-120.15120122 8.53576352 -60.86821967 -0.08189714 0 0 Z"/></svg>`}var fe=!1,D=null;function me(e){if(!e)return;let t=e.split(/[\s,]+/).map(o=>o.trim()).filter(Boolean);return t.length?t:void 0}function De(e){if(!e)return;let t=e.split(",").map(o=>o.trim()).filter(Boolean);return t.length?t:void 0}function Y(e){if(!e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function $(e){if(typeof document>"u")return()=>{};D&&D();let t=async i=>{let n=i.target?.closest("[data-hiofu-apply]");if(!n)return;i.preventDefault();let r=n.getAttribute("data-job-id"),s=n.getAttribute("data-job-title"),a=n.getAttribute("data-employer-id"),m=n.getAttribute("data-employer-name"),C=n.getAttribute("data-external-role-id"),f=n.getAttribute("data-external-employer-id"),l=n.getAttribute("data-hiofu-variation-id")??void 0,h=n.getAttribute("data-hiofu-idempotency-key")??void 0,p=me(n.getAttribute("data-hiofu-scopes"));if(!r||!s){let d=new Error("data-job-id and data-job-title are required");n.dispatchEvent(new CustomEvent("hiofu:apply:error",{bubbles:!0,detail:d}));return}n.setAttribute("data-hiofu-loading","1");try{let d={jobId:r,jobTitle:s};a&&(d.employerId=a),m&&(d.employerName=m),l&&(d.variationId=l),h&&(d.idempotencyKey=h),p&&(d.scopes=p),(C||f)&&(d.role={externalRoleId:C??r,externalEmployerId:f??a??void 0,title:n.getAttribute("data-role-title")??s,description:n.getAttribute("data-role-description")??void 0,department:n.getAttribute("data-role-department")??void 0,locations:De(n.getAttribute("data-role-locations")),jobTypes:De(n.getAttribute("data-role-job-types")),salaryMin:Y(n.getAttribute("data-role-salary-min")),salaryMax:Y(n.getAttribute("data-role-salary-max")),salaryCurrency:n.getAttribute("data-role-salary-currency")??void 0,experienceMin:Y(n.getAttribute("data-role-experience-min")),experienceMax:Y(n.getAttribute("data-role-experience-max"))});let F=await e.apply(d);n.dispatchEvent(new CustomEvent("hiofu:apply:success",{bubbles:!0,detail:F}))}catch(d){n.dispatchEvent(new CustomEvent("hiofu:apply:error",{bubbles:!0,detail:d}))}finally{n.removeAttribute("data-hiofu-loading")}};document.querySelectorAll("[data-hiofu-apply]").forEach(i=>{i.style.fontFamily=G}),document.addEventListener("click",t),fe=!0;let o=()=>{document.removeEventListener("click",t),fe=!1,D===o&&(D=null)};return D=o,o}function $e(){return fe}function Z(){if(typeof document>"u")return null;let e=document.currentScript;if(!e)return null;let t=e.getAttribute("data-client-id");if(!t)return null;let o={clientId:t,hiofuOrigin:e.getAttribute("data-hiofu-origin")??void 0,apiBase:e.getAttribute("data-api-base")??void 0,redirectUri:e.getAttribute("data-redirect-uri")??void 0,scopes:me(e.getAttribute("data-scopes")),applyScopes:me(e.getAttribute("data-apply-scopes"))},i=new I(o);return $(i),i}var A=class extends Error{constructor(t){super(t.message),this.name="HiofuApplyError",this.code=t.code,this.correlationId=t.correlationId,this.retryable=t.retryable,this.cause=t.cause}};function dt(e){return e.startsWith("pk_test_")?"sandbox":e.startsWith("pk_live_")?"production":null}var ft={sandbox:{hiofuOrigin:"https://sandbox.hiofu.com",apiBase:"https://api.sandbox.hiofu.com/api"},production:{hiofuOrigin:"https://hiofu.com",apiBase:"https://api.hiofu.com/api"}};function X(){return q()}function mt(e,t){if(e==="sandbox"&&!t.startsWith("pk_test_"))throw new A({code:"environment_mismatch",message:"Sandbox integrations must use a pk_test_* publishable key.",correlationId:X(),retryable:!1});if(e==="production"&&!t.startsWith("pk_live_"))throw new A({code:"environment_mismatch",message:"Production integrations must use a pk_live_* publishable key.",correlationId:X(),retryable:!1})}function gt(e){let t=e.jobId??e.externalJobId;if(!t)throw new A({code:"configuration_error",message:"HIOFU Apply requires a jobId.",correlationId:X(),retryable:!1});let o=e.role.locations??(e.role.location?[e.role.location]:void 0),i={jobId:t,jobTitle:e.jobTitle??e.role.title,scopes:e.scopes,variationId:e.variationId,idempotencyKey:e.idempotencyKey,role:{externalRoleId:t,title:e.role.title,description:e.role.description,locations:o,metadata:{...e.role.metadata??{},...e.role.skills?{skills:e.role.skills}:{},...e.role.salary?{salary:e.role.salary}:{},...e.role.dimensions?{dimensions:e.role.dimensions}:{},...e.callbackState?{callbackState:e.callbackState}:{},...e.partnerTags?{partnerTags:e.partnerTags}:{}}}};return e.externalEmployerId&&(i.employerId=e.externalEmployerId,i.role.externalEmployerId=e.externalEmployerId),e.employerName&&(i.employerName=e.employerName),i}function ht(e,t,o){let i=e.application.submittedAt instanceof Date?e.application.submittedAt.toISOString():e.application.submittedAt??new Date().toISOString();return{applicationId:e.application.id,partnerApplicationId:o,hiofuRoleId:e.application.jobId??"",status:e.application.status,environment:t,submittedAt:String(i),raw:e}}function yt(e,t){if(e instanceof A)return e;let o=e instanceof Error?e.message:String(e),i="submit_failed",n=!1;if(e instanceof _)i=e.code==="hiofu.environment_mismatch"?"environment_mismatch":"configuration_error";else if(e instanceof O)e.reason==="timed_out"?i="timeout":i="popup_closed",n=!0;else if(/popup blocked/i.test(o))i="popup_blocked",n=!0;else if(/authorization popup closed|popup closed/i.test(o))i="popup_closed",n=!0;else if(/timed out/i.test(o))i="timeout",n=!0;else if(/unknown or inactive client|redirect_uri not registered|partner is not approved|must accept dpa|unknown scope|scope\(s\) not permitted|pkce/i.test(o))i="configuration_error";else if(/access_denied|consent/i.test(o))i="consent_required";else if(e instanceof L){let r=e.body,s=r?.code??r?.error?.code??"";e.status===401||e.status===403?i="auth_failed":/role/i.test(s)||/role/i.test(o)?i="role_mapping_failed":(i="submit_failed",n=e.status>=500)}return new A({code:i,message:o,correlationId:t,retryable:n,cause:e})}function ze(e){let t=e.environment??dt(e.publicKey)??"sandbox";mt(t,e.publicKey);let o=ft[t],i=new I({clientId:e.publicKey,hiofuOrigin:e.hiofuOrigin??o.hiofuOrigin,apiBase:e.apiBase??o.apiBase,redirectUri:e.redirectUri,scopes:e.scopes,applyScopes:e.applyScopes,storage:e.storage,authorizeTimeoutMs:e.popupOptions?.timeoutMs,onEvent:e.onEvent});return{rawClient:i,authorize(n){return i.authorize(n)},getAccessToken(){return i.getAccessToken()},logout(){return i.logout()},async apply(n){let r=X();try{let s=await i.apply(gt(n)),a=ht(s,t,n.idempotencyKey);return e.onComplete?.(a),a}catch(s){let a=yt(s,r);throw a.code==="consent_required"?e.onCancel?.({reason:"user_cancelled",correlationId:r}):a.code==="popup_closed"?e.onCancel?.({reason:"popup_closed",correlationId:r}):a.code==="timeout"&&e.onCancel?.({reason:"timeout",correlationId:r}),e.onError?.(a),a}}}}function bt(e){if(!e)return"";let t=new URLSearchParams;typeof e.page=="number"&&t.set("page",String(e.page)),typeof e.limit=="number"&&t.set("limit",String(e.limit)),e.status&&t.set("status",e.status),e.search?.trim()&&t.set("search",e.search.trim());let o=t.toString();return o?`?${o}`:""}var z=class{constructor(t={}){this.config=t}async request(t,o={}){let i=this.config.apiBase??E,n=new Headers(this.config.headers);return o.headers&&new Headers(o.headers).forEach((r,s)=>{n.set(s,r)}),P(`${i}${t}`,{...o,headers:n,token:this.config.accessToken,credentials:this.config.credentials??(this.config.accessToken?void 0:"include")})}async listRoles(t){return this.request(`/employer-roles${bt(t)}`)}async getRole(t){return(await this.request(`/employer-roles/${t}`)).data}async createRole(t){return(await this.request("/employer-roles",{method:"POST",body:JSON.stringify(t)})).data}async updateRole(t,o){return(await this.request(`/employer-roles/${t}`,{method:"PATCH",body:JSON.stringify(o)})).data}async updateRoleStatus(t,o){return(await this.request(`/employer-roles/${t}/status`,{method:"PATCH",body:JSON.stringify({status:o})})).data}async getDeveloperSettings(){return(await this.request("/employers/developer/apply-sdk")).data}async issuePublishableKey(){return(await this.request("/employers/developer/apply-sdk",{method:"POST"})).data}async saveRoleMapping(t){let o=null;return(!t.title||!t.description||!t.locations)&&(o=await this.getRole(t.employerRoleId)),(await this.request("/employers/developer/apply-sdk/role-mappings",{method:"POST",body:JSON.stringify({mode:t.mode,externalRoleId:t.externalRoleId,externalEmployerId:t.externalEmployerId,employerRoleId:t.employerRoleId,title:t.title??o?.title,description:t.description??o?.description??void 0,locations:t.locations??o?.locations??void 0,metadata:t.metadata})})).data}async addRedirectUri(t){return(await this.request("/employers/developer/apply-sdk/redirect-uris",{method:"POST",body:JSON.stringify(t)})).data}async removeRedirectUri(t){return(await this.request(`/employers/developer/apply-sdk/redirect-uris/${t}`,{method:"DELETE"})).data}};function Ke(e={}){return new z(e)}var j=null,Ct={init(e){return j=new I(e),$(j),j},client(){if(!j)throw new Error("Hiofu.init({ clientId }) was not called");return j},apply(e){return this.client().apply(e)},authorize(e){return this.client().authorize(e)},getAccessToken(){return this.client().getAccessToken()},logout(){return this.client().logout()}};if(typeof document<"u"){let e=Z();e&&(j=e)}return Qe(Ht);})();
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  createRandomId,
17
17
  hiofuLogoSvg,
18
18
  jsonFetch
19
- } from "./chunk-MFY3F4OY.js";
19
+ } from "./chunk-7JEEWWEX.js";
20
20
 
21
21
  // src/auto-bind.ts
22
22
  var bound = false;
@@ -165,6 +165,11 @@ var HiofuApplyError = class extends Error {
165
165
  this.cause = args.cause;
166
166
  }
167
167
  };
168
+ function inferEnvironment(publicKey) {
169
+ if (publicKey.startsWith("pk_test_")) return "sandbox";
170
+ if (publicKey.startsWith("pk_live_")) return "production";
171
+ return null;
172
+ }
168
173
  var ENDPOINTS = {
169
174
  sandbox: {
170
175
  hiofuOrigin: "https://sandbox.hiofu.com",
@@ -197,15 +202,24 @@ function assertPublicKey(environment, publicKey) {
197
202
  }
198
203
  }
199
204
  function toApplyOptions(payload) {
205
+ const jobId = payload.jobId ?? payload.externalJobId;
206
+ if (!jobId) {
207
+ throw new HiofuApplyError({
208
+ code: "configuration_error",
209
+ message: "HIOFU Apply requires a jobId.",
210
+ correlationId: createCorrelationId(),
211
+ retryable: false
212
+ });
213
+ }
200
214
  const locations = payload.role.locations ?? (payload.role.location ? [payload.role.location] : void 0);
201
215
  const options = {
202
- jobId: payload.externalJobId,
216
+ jobId,
203
217
  jobTitle: payload.jobTitle ?? payload.role.title,
204
218
  scopes: payload.scopes,
205
219
  variationId: payload.variationId,
206
220
  idempotencyKey: payload.idempotencyKey,
207
221
  role: {
208
- externalRoleId: payload.externalJobId,
222
+ externalRoleId: jobId,
209
223
  title: payload.role.title,
210
224
  description: payload.role.description,
211
225
  locations,
@@ -290,8 +304,9 @@ function toApplyError(error, correlationId) {
290
304
  });
291
305
  }
292
306
  function createApplyClient(config) {
293
- assertPublicKey(config.environment, config.publicKey);
294
- const endpoints = ENDPOINTS[config.environment];
307
+ const resolvedEnvironment = config.environment ?? inferEnvironment(config.publicKey) ?? "sandbox";
308
+ assertPublicKey(resolvedEnvironment, config.publicKey);
309
+ const endpoints = ENDPOINTS[resolvedEnvironment];
295
310
  const client = new HiofuClient({
296
311
  clientId: config.publicKey,
297
312
  hiofuOrigin: config.hiofuOrigin ?? endpoints.hiofuOrigin,
@@ -320,7 +335,7 @@ function createApplyClient(config) {
320
335
  const result = await client.apply(toApplyOptions(payload));
321
336
  const normalized = toNormalizedResult(
322
337
  result,
323
- config.environment,
338
+ resolvedEnvironment,
324
339
  payload.idempotencyKey
325
340
  );
326
341
  config.onComplete?.(normalized);
package/dist/react.cjs CHANGED
@@ -382,9 +382,6 @@ var HiofuPopupError = class extends Error {
382
382
  function resolveRedirectUri(config, hiofuOrigin) {
383
383
  if (config.redirectUri) return config.redirectUri;
384
384
  const hiofuBaseOrigin = new URL(hiofuOrigin).origin;
385
- if (typeof window !== "undefined" && window.location.origin && window.location.origin !== hiofuBaseOrigin) {
386
- return new URL("/oauth/callback.html", window.location.origin).toString();
387
- }
388
385
  return `${hiofuBaseOrigin}/oauth/callback-shim`;
389
386
  }
390
387
  async function authorize(config, scopes, context, callbacks) {
@@ -398,6 +395,9 @@ async function authorize(config, scopes, context, callbacks) {
398
395
  const url = new URL(`${hiofuOrigin}/oauth/consent`);
399
396
  url.searchParams.set("client_id", config.clientId);
400
397
  url.searchParams.set("redirect_uri", redirectUri);
398
+ if (window.location?.origin) {
399
+ url.searchParams.set("opener_origin", window.location.origin);
400
+ }
401
401
  url.searchParams.set("scope", scopes.join(" "));
402
402
  url.searchParams.set("state", state);
403
403
  url.searchParams.set("code_challenge", challenge);
@@ -433,6 +433,7 @@ async function authorize(config, scopes, context, callbacks) {
433
433
  let channel = null;
434
434
  let openerLostAttention = false;
435
435
  let openerRegainedAttention = false;
436
+ let popupClosedAt = null;
436
437
  const cleanup = () => {
437
438
  settled = true;
438
439
  window.removeEventListener("message", onMessage);
@@ -582,14 +583,28 @@ async function authorize(config, scopes, context, callbacks) {
582
583
  }
583
584
  } catch {
584
585
  }
585
- if (popup.closed && openerRegainedAttention) {
586
+ if (popup.closed) {
587
+ popupClosedAt ?? (popupClosedAt = Date.now());
588
+ } else {
589
+ popupClosedAt = null;
590
+ }
591
+ const canTreatAsClosed = popup.closed && popupClosedAt !== null && openerRegainedAttention && document.hasFocus() && Date.now() - popupClosedAt > 5e3;
592
+ if (canTreatAsClosed) {
586
593
  try {
587
594
  const raw = localStorage.getItem("hiofu_oauth_result");
588
- if (raw) {
589
- handleResult(JSON.parse(raw), "close_check");
590
- }
595
+ if (raw) handleResult(JSON.parse(raw), "close_check");
591
596
  } catch {
592
597
  }
598
+ if (!settled) {
599
+ cleanup();
600
+ callbacks?.onPopupClosed?.("user_closed");
601
+ reject(
602
+ new HiofuPopupError(
603
+ "user_closed",
604
+ "Authorization popup closed before HIOFU could complete the request. Please try again."
605
+ )
606
+ );
607
+ }
593
608
  }
594
609
  }, 500);
595
610
  overallTimeout = window.setTimeout(() => {
@@ -743,10 +758,13 @@ var HiofuClient = class {
743
758
  if (!config.clientId) {
744
759
  throw new Error("HiofuClient: clientId is required");
745
760
  }
761
+ const isSandboxKey = config.clientId.startsWith("pk_test_");
762
+ const defaultOrigin = isSandboxKey ? "https://sandbox.hiofu.com" : "https://hiofu.com";
763
+ const defaultApiBase = isSandboxKey ? "https://api.sandbox.hiofu.com/api" : "https://api.hiofu.com/api";
746
764
  this.config = {
747
765
  ...config,
748
- hiofuOrigin: config.hiofuOrigin ?? "https://hiofu.com",
749
- apiBase: config.apiBase ?? "https://api.hiofu.com/api",
766
+ hiofuOrigin: config.hiofuOrigin ?? defaultOrigin,
767
+ apiBase: config.apiBase ?? defaultApiBase,
750
768
  storage: config.storage ?? "memory",
751
769
  authorizeTimeoutMs: config.authorizeTimeoutMs ?? 5 * 6e4
752
770
  };
@@ -868,12 +886,21 @@ var HiofuClient = class {
868
886
  idempotencyKey,
869
887
  variationId: selectedVariationId
870
888
  });
889
+ const resolvedRole = opts.role ? {
890
+ ...opts.role,
891
+ externalRoleId: opts.role.externalRoleId || opts.jobId,
892
+ title: opts.role.title || opts.jobTitle,
893
+ externalEmployerId: opts.role.externalEmployerId || opts.employerId || void 0
894
+ } : {
895
+ externalRoleId: opts.jobId,
896
+ title: opts.jobTitle
897
+ };
871
898
  const json = await submitApplication(this.config, access, {
872
899
  jobId: opts.jobId,
873
900
  jobTitle: opts.jobTitle,
874
901
  employerId: opts.employerId,
875
902
  employerName: opts.employerName,
876
- role: opts.role,
903
+ role: resolvedRole,
877
904
  variationId: selectedVariationId ?? void 0,
878
905
  idempotencyKey
879
906
  });
@@ -936,6 +963,9 @@ function useHiofu() {
936
963
  }
937
964
  return client;
938
965
  }
966
+ function useHiofuOptional() {
967
+ return (0, import_react.useContext)(Ctx);
968
+ }
939
969
  function useHiofuApply() {
940
970
  const client = useHiofu();
941
971
  const [status, setStatus] = (0, import_react.useState)("idle");
@@ -1035,11 +1065,23 @@ var HIOFU_APPLY_BUTTON_LOGO_COLOR = {
1035
1065
  secondary: HIOFU_BRAND_COLOR,
1036
1066
  ghost: "#312e81"
1037
1067
  };
1068
+ function hiofuSpinnerSvg({
1069
+ size = 24,
1070
+ color
1071
+ }) {
1072
+ return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" role="img" aria-label="Loading" xmlns="http://www.w3.org/2000/svg">
1073
+ <circle cx="12" cy="12" r="9" stroke="${color}" stroke-opacity="0.28" stroke-width="3"/>
1074
+ <path d="M21 12a9 9 0 0 0-9-9" stroke="${color}" stroke-width="3" stroke-linecap="round">
1075
+ <animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="0.75s" repeatCount="indefinite"/>
1076
+ </path>
1077
+ </svg>`;
1078
+ }
1038
1079
  function HiofuApplyButton({
1039
1080
  options,
1081
+ clientId,
1040
1082
  variant = "primary",
1041
1083
  label = HIOFU_BUTTON_LABEL,
1042
- authorisingLabel = "Opening HSP1 review...",
1084
+ authorisingLabel = "Waiting for HSP1 approval...",
1043
1085
  submittingLabel = "Submitting application...",
1044
1086
  successLabel = "Application submitted",
1045
1087
  showLogo = true,
@@ -1054,7 +1096,17 @@ function HiofuApplyButton({
1054
1096
  onError,
1055
1097
  ...buttonProps
1056
1098
  }) {
1057
- const client = useHiofu();
1099
+ const contextClient = useHiofuOptional();
1100
+ const standaloneClient = (0, import_react.useMemo)(
1101
+ () => clientId && !contextClient ? new HiofuClient({ clientId }) : null,
1102
+ [clientId, contextClient]
1103
+ );
1104
+ const client = contextClient ?? standaloneClient;
1105
+ if (!client) {
1106
+ throw new Error(
1107
+ "HiofuApplyButton: provide a clientId prop or wrap in <HiofuProvider>"
1108
+ );
1109
+ }
1058
1110
  const [status, setStatus] = (0, import_react.useState)("idle");
1059
1111
  const [hovered, setHovered] = (0, import_react.useState)(false);
1060
1112
  const busy = status === "authorising" || status === "submitting";
@@ -1138,7 +1190,7 @@ function HiofuApplyButton({
1138
1190
  showLogo ? (0, import_react.createElement)("span", {
1139
1191
  "aria-hidden": true,
1140
1192
  dangerouslySetInnerHTML: {
1141
- __html: hiofuLogoSvg({ size: 24, color: logoColor })
1193
+ __html: busy ? hiofuSpinnerSvg({ size: 24, color: logoColor }) : hiofuLogoSvg({ size: 24, color: logoColor })
1142
1194
  },
1143
1195
  style: {
1144
1196
  alignItems: "center",
package/dist/react.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ButtonHTMLAttributes, ReactNode, MouseEvent } from 'react';
3
- import { p as HiofuApplyOptions, b as HiofuApplyResult, c as HiofuConfig, H as HiofuClient } from './client-Ct5xyQMk.cjs';
3
+ import { H as HiofuApplyOptions, b as HiofuApplyResult, e as HiofuConfig, d as HiofuClient } from './client-7yPni-fK.cjs';
4
4
 
5
5
  interface HiofuProviderProps {
6
6
  config: HiofuConfig;
@@ -21,6 +21,8 @@ declare const HIOFU_APPLY_BUTTON_BASE_STYLE: CSSProperties;
21
21
  declare const HIOFU_APPLY_BUTTON_VARIANTS: Record<HiofuApplyButtonVariant, CSSProperties>;
22
22
  interface HiofuApplyButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onError"> {
23
23
  options: HiofuApplyOptions;
24
+ /** When provided, the button creates its own client and works without HiofuProvider. */
25
+ clientId?: string;
24
26
  variant?: HiofuApplyButtonVariant;
25
27
  label?: ReactNode;
26
28
  authorisingLabel?: ReactNode;
@@ -30,7 +32,7 @@ interface HiofuApplyButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElem
30
32
  onSuccess?: (result: HiofuApplyResult) => void;
31
33
  onError?: (error: Error) => void;
32
34
  }
33
- declare function HiofuApplyButton({ options, variant, label, authorisingLabel, submittingLabel, successLabel, showLogo, children, disabled, style, type, onClick, onMouseEnter, onMouseLeave, onSuccess, onError, ...buttonProps }: HiofuApplyButtonProps): react.DetailedReactHTMLElement<{
35
+ declare function HiofuApplyButton({ options, clientId, variant, label, authorisingLabel, submittingLabel, successLabel, showLogo, children, disabled, style, type, onClick, onMouseEnter, onMouseLeave, onSuccess, onError, ...buttonProps }: HiofuApplyButtonProps): react.DetailedReactHTMLElement<{
34
36
  "aria-busy": true | undefined;
35
37
  disabled: boolean;
36
38
  onClick: (event: MouseEvent<HTMLButtonElement>) => Promise<void>;
@@ -43,6 +45,7 @@ declare function HiofuApplyButton({ options, variant, label, authorisingLabel, s
43
45
  title?: string | undefined | undefined;
44
46
  value?: string | number | readonly string[] | undefined;
45
47
  hidden?: boolean | undefined | undefined;
48
+ color?: string | undefined | undefined;
46
49
  formAction?: string | ((formData: FormData) => void | Promise<void>) | undefined;
47
50
  formEncType?: string | undefined | undefined;
48
51
  formMethod?: string | undefined | undefined;
@@ -83,7 +86,6 @@ declare function HiofuApplyButton({ options, variant, label, authorisingLabel, s
83
86
  vocab?: string | undefined | undefined;
84
87
  autoCorrect?: string | undefined | undefined;
85
88
  autoSave?: string | undefined | undefined;
86
- color?: string | undefined | undefined;
87
89
  itemProp?: string | undefined | undefined;
88
90
  itemScope?: boolean | undefined | undefined;
89
91
  itemType?: string | undefined | undefined;
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ButtonHTMLAttributes, ReactNode, MouseEvent } from 'react';
3
- import { p as HiofuApplyOptions, b as HiofuApplyResult, c as HiofuConfig, H as HiofuClient } from './client-Ct5xyQMk.js';
3
+ import { H as HiofuApplyOptions, b as HiofuApplyResult, e as HiofuConfig, d as HiofuClient } from './client-7yPni-fK.js';
4
4
 
5
5
  interface HiofuProviderProps {
6
6
  config: HiofuConfig;
@@ -21,6 +21,8 @@ declare const HIOFU_APPLY_BUTTON_BASE_STYLE: CSSProperties;
21
21
  declare const HIOFU_APPLY_BUTTON_VARIANTS: Record<HiofuApplyButtonVariant, CSSProperties>;
22
22
  interface HiofuApplyButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onError"> {
23
23
  options: HiofuApplyOptions;
24
+ /** When provided, the button creates its own client and works without HiofuProvider. */
25
+ clientId?: string;
24
26
  variant?: HiofuApplyButtonVariant;
25
27
  label?: ReactNode;
26
28
  authorisingLabel?: ReactNode;
@@ -30,7 +32,7 @@ interface HiofuApplyButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElem
30
32
  onSuccess?: (result: HiofuApplyResult) => void;
31
33
  onError?: (error: Error) => void;
32
34
  }
33
- declare function HiofuApplyButton({ options, variant, label, authorisingLabel, submittingLabel, successLabel, showLogo, children, disabled, style, type, onClick, onMouseEnter, onMouseLeave, onSuccess, onError, ...buttonProps }: HiofuApplyButtonProps): react.DetailedReactHTMLElement<{
35
+ declare function HiofuApplyButton({ options, clientId, variant, label, authorisingLabel, submittingLabel, successLabel, showLogo, children, disabled, style, type, onClick, onMouseEnter, onMouseLeave, onSuccess, onError, ...buttonProps }: HiofuApplyButtonProps): react.DetailedReactHTMLElement<{
34
36
  "aria-busy": true | undefined;
35
37
  disabled: boolean;
36
38
  onClick: (event: MouseEvent<HTMLButtonElement>) => Promise<void>;
@@ -43,6 +45,7 @@ declare function HiofuApplyButton({ options, variant, label, authorisingLabel, s
43
45
  title?: string | undefined | undefined;
44
46
  value?: string | number | readonly string[] | undefined;
45
47
  hidden?: boolean | undefined | undefined;
48
+ color?: string | undefined | undefined;
46
49
  formAction?: string | ((formData: FormData) => void | Promise<void>) | undefined;
47
50
  formEncType?: string | undefined | undefined;
48
51
  formMethod?: string | undefined | undefined;
@@ -83,7 +86,6 @@ declare function HiofuApplyButton({ options, variant, label, authorisingLabel, s
83
86
  vocab?: string | undefined | undefined;
84
87
  autoCorrect?: string | undefined | undefined;
85
88
  autoSave?: string | undefined | undefined;
86
- color?: string | undefined | undefined;
87
89
  itemProp?: string | undefined | undefined;
88
90
  itemScope?: boolean | undefined | undefined;
89
91
  itemType?: string | undefined | undefined;
package/dist/react.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  HIOFU_FONT_FAMILY,
6
6
  HiofuClient,
7
7
  hiofuLogoSvg
8
- } from "./chunk-MFY3F4OY.js";
8
+ } from "./chunk-7JEEWWEX.js";
9
9
 
10
10
  // src/react.ts
11
11
  import {
@@ -39,6 +39,9 @@ function useHiofu() {
39
39
  }
40
40
  return client;
41
41
  }
42
+ function useHiofuOptional() {
43
+ return useContext(Ctx);
44
+ }
42
45
  function useHiofuApply() {
43
46
  const client = useHiofu();
44
47
  const [status, setStatus] = useState("idle");
@@ -138,11 +141,23 @@ var HIOFU_APPLY_BUTTON_LOGO_COLOR = {
138
141
  secondary: HIOFU_BRAND_COLOR,
139
142
  ghost: "#312e81"
140
143
  };
144
+ function hiofuSpinnerSvg({
145
+ size = 24,
146
+ color
147
+ }) {
148
+ return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" role="img" aria-label="Loading" xmlns="http://www.w3.org/2000/svg">
149
+ <circle cx="12" cy="12" r="9" stroke="${color}" stroke-opacity="0.28" stroke-width="3"/>
150
+ <path d="M21 12a9 9 0 0 0-9-9" stroke="${color}" stroke-width="3" stroke-linecap="round">
151
+ <animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="0.75s" repeatCount="indefinite"/>
152
+ </path>
153
+ </svg>`;
154
+ }
141
155
  function HiofuApplyButton({
142
156
  options,
157
+ clientId,
143
158
  variant = "primary",
144
159
  label = HIOFU_BUTTON_LABEL,
145
- authorisingLabel = "Opening HSP1 review...",
160
+ authorisingLabel = "Waiting for HSP1 approval...",
146
161
  submittingLabel = "Submitting application...",
147
162
  successLabel = "Application submitted",
148
163
  showLogo = true,
@@ -157,7 +172,17 @@ function HiofuApplyButton({
157
172
  onError,
158
173
  ...buttonProps
159
174
  }) {
160
- const client = useHiofu();
175
+ const contextClient = useHiofuOptional();
176
+ const standaloneClient = useMemo(
177
+ () => clientId && !contextClient ? new HiofuClient({ clientId }) : null,
178
+ [clientId, contextClient]
179
+ );
180
+ const client = contextClient ?? standaloneClient;
181
+ if (!client) {
182
+ throw new Error(
183
+ "HiofuApplyButton: provide a clientId prop or wrap in <HiofuProvider>"
184
+ );
185
+ }
161
186
  const [status, setStatus] = useState("idle");
162
187
  const [hovered, setHovered] = useState(false);
163
188
  const busy = status === "authorising" || status === "submitting";
@@ -241,7 +266,7 @@ function HiofuApplyButton({
241
266
  showLogo ? createElement("span", {
242
267
  "aria-hidden": true,
243
268
  dangerouslySetInnerHTML: {
244
- __html: hiofuLogoSvg({ size: 24, color: logoColor })
269
+ __html: busy ? hiofuSpinnerSvg({ size: 24, color: logoColor }) : hiofuLogoSvg({ size: 24, color: logoColor })
245
270
  },
246
271
  style: {
247
272
  alignItems: "center",