@inploi/sdk 2.9.1 → 3.0.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/README.md +23 -6
- package/cdn/index.js +1 -1
- package/dist/index.d.mts +105 -73
- package/dist/index.d.ts +105 -73
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as pt}from"./chunk-KC7FKSIJ.mjs";var Y="%c[inploi SDK]",z="color: #65BC67; font-weight: bold;",ge={warn:(...t)=>console.warn(Y,z,...t),error:(...t)=>console.error(Y,z,...t),info:(...t)=>console.info(Y,z,...t),log:(...t)=>console.log(Y,z,...t)},ve={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var dt=t=>t;function fe(t,n){if(!t)throw new Error(n)}function F(t,n){return n in t}var mn=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});var ut="Unauthenticated",mt="This action is unauthorized.",O=class extends Error{constructor(r,i){super(r);this.status=i,this.name="ErrorWithStatus"}},B=class extends O{constructor(n){super(n??"Not found"),this.name="NotFoundError",this.status=404}},U=class extends O{constructor(n,r){super(n??"You are not authorised to perform this action."),this.name="UnauthorisedError",this.status=r??401}},R=class extends O{constructor(r,i){let c=i?` in ${i}`:"";super(`Schema validation failed${c}`);this.issues=r;this.source=i;this.name="SchemaValidationError",this.status=400}},q=class extends O{constructor(r,i,c){super(r);this.data=c;this.name="ApiError",this.status=i??500}},gt=t=>t instanceof q&&t.data!==void 0,G=class extends O{constructor(r){super("Error parsing response into JSON.");this.response=r;this.name="ParsingError",this.status=r&&r.status>=300?r.status:500,this.contentType=new Headers(r?.headers).get("content-type")??void 0}};async function he(t){let r=new Headers(t.headers).get("content-type")?.replace(/;.*/,"").trim().toLowerCase();if(r&&r!=="application/json"&&!r.endsWith("+json"))throw new G(t);return t.json().catch(()=>{throw new G(t)})}var vt=["message","error","errors","exception","exceptions"];function ft(t){let n=[];if(typeof t=="object"&&t!==null){for(let r of vt)if(F(t,r)){let i=t[r];typeof i=="string"&&n.push(i),Array.isArray(i)&&i.every(c=>typeof c=="string")&&n.push(...i)}F(t,"integration_response")&&typeof t.integration_response=="object"&&t.integration_response!==null&&F(t.integration_response,"error")&&typeof t.integration_response.error=="object"&&t.integration_response.error!==null&&F(t.integration_response.error,"message")&&typeof t.integration_response.error.message=="string"&&n.push(t.integration_response.error.message)}return n.length===0&&n.push("Unknown error"),[...new Set(n)].join(", ")}function ye(t,n){if(n>=300){let r=ft(t);throw n===404?new B(r):r===ut?new U("You are not authenticated.",n):r===mt?new U(r,n):new q(r,n,t)}}var Pe=t=>{let n={Accept:"application/json","Content-Type":"application/json","x-publishable-key":t.publishableKey};return{fetch:async(r,i={})=>{let c={...i,headers:{...i.headers,...n}},l=await fetch(`${t.baseUrl}${r}`,c);if(l.status===404)throw new B;let d=await he(l);return ye(d,l.status),d}}},ke={NotFound:B,Unauthorised:U,SchemaValidation:R,Api:q,JsonParsing:G};function ht(t){return Object.values(ke).some(n=>t instanceof n)}var Re="2.9.1";var Q={sandbox:"https://api.staging.inploi.com",production:"https://api.inploi.com",_internal_local:"http://api.test"},Ce={sandbox:"https://talent-bank.staging.inploi.com",production:"https://talent-bank.inploi.com",_internal_local:"http://localhost:8787"},Le=Re;var C="isdk_session",Z=`${C}-candidate_id`,De=`${C}-consent`;var X=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16));var Ne=7*24*60*60*1e3,je=t=>{let n=new Date;return n.setTime(n.getTime()+Ne),`${C}=${t};expires=${n.toUTCString()};path=/`},St=(t,n)=>{let r=t.get("session_id");if(n||r)return r;let i=sessionStorage.getItem(`${C}-session_id`);return typeof i=="string"?i:null},bt=()=>{if(typeof window>"u")return null;try{let t=window.localStorage.getItem(Z);return typeof t=="string"&&t!==""?t:null}catch{return null}},_t=t=>{if(!(typeof window>"u"))try{t?window.localStorage.setItem(Z,t):window.localStorage.removeItem(Z)}catch{}},Tt=new RegExp(`(?:^|;\\s*)${C}=([^;]+)`),J=t=>{let n=t?t.headers.get("cookie"):document.cookie;return n?Tt.exec(n)?.[1]??null:null},Fe=()=>{try{let t=JSON.parse(window.localStorage.getItem(C)??"null");return typeof t!="object"||t===null||!("id"in t)||!("expires"in t)||typeof t.id!="string"||typeof t.expires!="number"?null:t.id!==""&&t.expires>Date.now()?t.id:null}catch{return null}},Oe=()=>J()??(new URL(location.href).searchParams.get("anonymous_id")?null:Fe()),xt=()=>location.protocol==="https:"&&window.self!==window.top?";SameSite=None;Secure;Partitioned":"",Be=t=>{if(document.cookie=je(t)+xt(),J()!==t)try{window.localStorage.setItem(C,JSON.stringify({id:t,expires:Date.now()+Ne}))}catch{}},Se=t=>{let n=t?t.url:location.href,{searchParams:r}=new URL(n);return{anonymous_id:t?J(t)??r.get("anonymous_id"):J()??r.get("anonymous_id")??Fe(),session_id:St(r,typeof window>"u")}},Ue=()=>{if(typeof window>"u")throw new Error("getOrCreateAnonymousId() can only be called in browser environment");let t=Se().anonymous_id;if(t)return t;let n=X(),r=Se().anonymous_id;return r||(Be(n),n)},Et=t=>typeof t!="object"||t===null?null:{anonymous_id:"anonymous_id"in t&&typeof t.anonymous_id=="string"?t.anonymous_id:null,session_id:"session_id"in t&&typeof t.session_id=="string"?t.session_id:null},It=t=>t==="about:client"?"":t,At={pathname:"/log",method:"POST",schema:{response:D(),body:D()}},qe=({rpcClient:t,logger:n,onEvent:r,talentBank:i,persistence:c="device"})=>{let l=null,d=0,u=0,v=p=>c==="none"?{anonymous_id:null,session_id:p?null:l}:Se(p),I=async(p,y)=>{try{let f={library:{name:"inploi-sdk",version:Le},page:y},A=v(p.request);c==="device"&&p.event==="IDENTIFY"&&!A.anonymous_id&&!p.request&&typeof window<"u"&&(A={...A,anonymous_id:Ue()});let Ie=c==="none"?null:bt();if(p.event==="IDENTIFY"&&i&&(A.anonymous_id||c==="none")){let $=p.properties,me=await i.identify({email:$.email??$.identifier,firstName:$.first_name,lastName:$.last_name,phone:$.phone_number,anonymousId:A.anonymous_id??X(),source:"sdk"});me?.candidateId&&c==="device"&&(Ie=me.candidateId,_t(me.candidateId))}let S={anonymous_id:A.anonymous_id,session_id:A.session_id,candidate_id:Ie,event:p.event,sent_at:new Date().toISOString(),context:f,properties:p.properties,custom_properties:p.customProperties},pe=c==="none"?null:p.request?J(p.request):Oe(),Ae=++d,ct=await t.request(At,{body:S,...p.keepalive&&{keepalive:!0}}),w=Et(ct);if(c==="none")return!p.request&&w?.session_id&&Ae>u&&(u=Ae,w.session_id!==S.session_id&&(l=w.session_id)),S.session_id=p.request?w?.session_id||null:l,r?.(S),{success:!0,data:S};let de=p.request?pe:Oe(),lt=de!==null&&de!==pe,ue=de??pe,we=!lt&&(!ue||!w?.anonymous_id||ue===w.anonymous_id);return we?(w?.anonymous_id&&(S.anonymous_id=w.anonymous_id),w?.session_id&&(S.session_id=w.session_id)):S.anonymous_id=ue,!p.request&&typeof window<"u"&&S.anonymous_id&&(we&&S.session_id&&sessionStorage.setItem(`${C}-session_id`,S.session_id.toString()),Be(S.anonymous_id)),r?.(S),{success:!0,data:S}}catch(f){return n.error("Failed to send log to API. Inspect error response of `log` for more information."),{success:!1,error:f}}},j=Promise.resolve();return{log:async p=>{fe(p.request||typeof window<"u","Cannot log on the server without a request. Please pass a request to `log`.");let y="request"in p&&p.request?{href:p.request.url,referrer:It(p.request.referrer),title:""}:{href:location.href,referrer:document.referrer,title:document.title};if(c==="none"&&p.event==="FLOW_NODE"&&p.properties&&"trigger"in p.properties&&(p.properties.trigger==="pagehide"||p.properties.trigger==="hidden")&&(p={...p,keepalive:!0}),c==="device"||p.request||l||p.keepalive)return I(p,y);let f=()=>I(p,y),A=j.then(f,f);return j=A,A},getHeaders:p=>{let y=new Headers;return c==="none"||!p?.anonymous_id||y.append("Set-Cookie",je(p.anonymous_id)),y},getSessionInfo:v}};import{stringify as wt}from"neoqs";function be(t,n,r){let i=t["~standard"].validate(n);if(i instanceof Promise)throw new TypeError("Async schema");if(i.issues)throw new R(i.issues,r);return i.value}function Pt(t,n,r){try{return{success:!0,output:be(t,n,r)}}catch(i){if(i instanceof R)return{success:!1,issues:i.issues,source:i.source};throw i}}var H=class{constructor(n){if(this.baseUrl=Q[n.environment],this.headers=new Headers({"Content-Type":"application/json",Accept:"application/json"}),n.apiKey.type==="secret"){if(typeof window<"u")throw new Error("Secret key cannot be used in a browser environment");this.headers.set("x-secret-key",n.apiKey.key)}else this.headers.set("x-publishable-key",n.apiKey.key);this.logger=n.logger,this._environment=n.environment}get environment(){return this._environment}getFetchParams(n,r){let i=r.validateIn??!0,{searchParams:c,body:l}=i?Ge(n,r):r,d=new URL(this.baseUrl),u=n.pathname;if("params"in r&&r.params)for(let[v,I]of Object.entries(r.params))u=u.replace(`:${v}`,String(I));return d.pathname=u,n.schema.searchParams&&(d.search=wt(c)),[d.toString(),{method:n.method,body:l?JSON.stringify(l):void 0,headers:this.headers,signal:r.signal,...r.keepalive&&{keepalive:!0}}]}async parseResponse(n,r){let i=await he(r.response);if(ye(i,r.response.status),!(r.validateOut??!0))return i;let l=Pt(n.schema.response,i,"response");if(!l.success)throw new R(l.issues,l.source);return l.output}async request(n,r){try{let i=this.getFetchParams(n,r),c=await fetch(...i);return await this.parseResponse(n,{response:c,validateOut:r.validateOut})}catch(i){throw i instanceof R?this.logger.error(i.message,i.issues):this.logger.error(i),i}}};function D(){return{"~standard":{vendor:"inploi",version:1,validate:t=>({value:t})}}}function ee(t){return t}function Ge(t,n){let r={searchParams:void 0,body:void 0,validateIn:!1};return t.schema.searchParams&&(r.searchParams=be(t.schema.searchParams,"searchParams"in n?n.searchParams:{})),t.schema.body&&(r.body=be(t.schema.body,"body"in n?n.body:{})),r}import*as s from"valibot";var kt=["agent","sdk","form","integration","migration"],Rt=["APPLIED","SHORTLISTED","INTERVIEWED","OFFERED","HIRED","REJECTED","WITHDRAWN"];var Ct=["screening","cv_match","interview","overall"],Lt=["PENDING","SCHEDULED","IN_PROGRESS","COMPLETED","CANCELLED"],Dt=["job","company"],Ot=["created_at","updated_at"],Nt=["asc","desc"],jt=["careers_site","chatbot","plugin_job_search","ats_import","referral","agency","other","unknown"],Ft=["submit","stage_transition","move_to_stage","shortlist","move_to_interview","make_offer","hire","withdraw","disqualify","reinstate","rate","score_written"],Bt=["user","system","automation","integration","candidate"],te=s.picklist(kt),P=s.picklist(Rt),E=s.pipe(s.string(),s.trim(),s.minLength(1),s.maxLength(100)),ne=s.picklist(Ct),Me=s.picklist(Lt),Dn=s.picklist(Dt),Ve=s.picklist(Ot),$e=s.picklist(Nt),W=s.pipe(s.string(),s.trim(),s.minLength(1),s.maxLength(100)),re=s.picklist(jt),Je=s.picklist(Ft),He=s.picklist(Bt);var _=s.variant("type",[s.object({type:s.literal("user"),id:s.pipe(s.string(),s.minLength(1)),email:s.pipe(s.string(),s.minLength(1)),name:s.pipe(s.string(),s.minLength(1))}),s.object({type:s.literal("system"),id:s.pipe(s.string(),s.minLength(1)),name:s.optional(s.string())}),s.object({type:s.literal("automation"),id:s.pipe(s.string(),s.minLength(1)),name:s.optional(s.string())}),s.object({type:s.literal("integration"),id:s.pipe(s.string(),s.minLength(1)),name:s.optional(s.string())}),s.object({type:s.literal("candidate"),id:s.pipe(s.string(),s.minLength(1)),email:s.optional(s.string())})]);import*as k from"valibot";var Ut=k.object({total:k.number(),page:k.number(),perPage:k.number(),lastPage:k.number()});function oe(t){return k.object({data:k.array(t),pagination:Ut})}import*as m from"valibot";var K=m.object({id:m.string(),email:m.nullable(m.string()),firstName:m.nullable(m.string()),lastName:m.nullable(m.string()),phone:m.nullable(m.string()),source:m.nullable(te),identifiedAt:m.nullable(m.string()),createdAt:m.string(),updatedAt:m.string()});import*as o from"valibot";import*as g from"valibot";var M=g.pipe(g.string(),g.minLength(1)),We=g.pipe(g.number(),g.integer(),g.minValue(1)),L=g.record(g.string(),g.unknown());import*as T from"valibot";var Ke=T.object({id:T.string(),applicationId:T.string(),status:Me,scheduledAt:T.nullable(T.string()),completedAt:T.nullable(T.string()),meta:T.nullable(L),createdAt:T.string(),updatedAt:T.string()});var _e=o.object({score:o.number(),reason:o.string(),confidence:o.number()}),Ye=o.object({id:o.string(),candidateId:o.string(),jobId:o.number(),stage:E,stageGroup:P,stageEnteredAt:o.string(),rating:o.nullable(o.number()),disqualifiedAt:o.nullable(o.string()),disqualificationReason:o.nullable(W),disqualificationNote:o.nullable(o.string()),source:re,sourceDetail:o.nullable(o.string()),sessionId:o.nullable(o.number()),externalApplicationId:o.nullable(o.string()),meta:o.nullable(L),context:o.nullable(L),scoredAt:o.nullable(o.string()),createdAt:o.string(),updatedAt:o.string()}),qt=o.object({id:o.string(),applicationId:o.string(),scoreType:ne,score:o.nullable(o.number()),reason:o.nullable(o.string()),categories:o.nullable(o.record(o.string(),_e)),scoredBy:o.nullable(o.string()),createdAt:o.string()}),ie=o.object({...Ye.entries,candidate:o.nullable(K),score:o.nullable(qt),interview:o.nullable(Ke)}),Gt=o.object({...K.entries,applications:o.array(Ye)}),ze=o.object({id:o.string(),applicationId:o.string(),action:Je,fromStage:o.nullable(E),fromStageGroup:o.nullable(P),toStage:o.nullable(E),toStageGroup:o.nullable(P),disqualificationReason:o.nullable(W),disqualificationNote:o.nullable(o.string()),actorId:o.nullable(o.string()),actorType:He,actorEmail:o.nullable(o.string()),actorName:o.nullable(o.string()),meta:o.nullable(L),schemaVersion:o.number(),createdAt:o.string()});import*as h from"valibot";var Qe=h.object({anonymousId:M,email:M,firstName:h.nullish(h.string()),lastName:h.nullish(h.string()),phone:h.nullish(h.string()),source:h.nullish(te)}),Ze=h.object({candidateId:h.string(),isNew:h.boolean()});import*as e from"valibot";var Mt=["stage_transition","move_to_stage","shortlist","move_to_interview","make_offer","hire","withdraw","disqualify","reinstate","rate"],ae=e.picklist(Mt),Xe=e.pipe(e.string(),e.transform(t=>t.split(",").map(n=>n.trim()).filter(n=>n.length>0))),Vt=e.pipe(Xe,e.array(E)),$t=e.pipe(Xe,e.array(P)),et=e.pipe(e.string(),e.transform(t=>t.split(",").map(n=>Number(n.trim())).filter(n=>Number.isInteger(n)&&n>0))),er=e.object({stages:e.optional(Vt),stage_groups:e.optional($t),job_id:e.optional(e.string()),job_ids:e.optional(et),candidate_id:e.optional(e.string()),is_disqualified:e.optional(e.picklist(["true","false"])),created_from:e.optional(e.string()),created_to:e.optional(e.string()),updated_from:e.optional(e.string()),updated_to:e.optional(e.string()),entered_stage_from:e.optional(e.string()),entered_stage_to:e.optional(e.string()),from:e.optional(e.string()),to:e.optional(e.string()),q:e.optional(e.string()),scored:e.optional(e.picklist(["true","false"])),sort:e.optional(Ve),order:e.optional($e),page:e.optional(e.string()),per_page:e.optional(e.string())}),tr=e.pipe(e.object({candidateId:M,jobId:We,meta:e.nullish(L),sessionId:e.nullish(e.number()),externalApplicationId:e.nullish(e.string()),context:e.nullish(L),source:e.nullish(re),sourceDetail:e.nullish(e.string()),stage:e.nullish(E),stageGroup:e.nullish(P),actor:e.nullish(_)}),e.check(t=>t.stage==null==(t.stageGroup==null),"stage and stageGroup must be supplied together")),tt=e.object({id:e.string(),stageGroup:e.string(),createdAt:e.string()}),nr=e.union([e.object({ok:e.literal(!0),duplicate:e.literal(!1),applicationId:e.string(),candidateId:e.string()}),e.object({ok:e.literal(!0),duplicate:e.literal(!0),existingApplication:tt})]),nt=e.object({isDuplicate:e.boolean(),existingApplication:e.optional(tt)}),rr=e.object({applicationId:M,scoreType:ne,score:e.number(),reason:e.nullish(e.string()),categories:e.nullish(e.record(e.string(),_e)),scoredBy:e.nullish(e.string()),actor:e.nullish(_)}),or=e.object({scoreId:e.string()}),ir=oe(ie);var sr=e.picklist(["already_in_target_stage","not_in_source_stage","disqualified"]),ar=e.array(ze),se=e.object({stage:e.nullish(E),note:e.nullish(e.string())}),Jt=e.object({stage:e.nullish(E),startDate:e.nullish(e.string()),note:e.nullish(e.string())}),Ht=e.variant("action",[e.object({action:e.literal("shortlist"),actor:_,meta:e.nullish(se)}),e.object({action:e.literal("move_to_interview"),actor:_,meta:e.nullish(se)}),e.object({action:e.literal("make_offer"),actor:_,meta:e.nullish(se)}),e.object({action:e.literal("hire"),actor:_,meta:e.nullish(Jt)}),e.object({action:e.literal("withdraw"),actor:_,meta:e.nullish(se)}),e.object({action:e.literal("move_to_stage"),actor:_,meta:e.object({stage:E,stageGroup:P,note:e.nullish(e.string())})}),e.object({action:e.literal("stage_transition"),actor:_,meta:e.object({toStage:E,toStageGroup:P,note:e.nullish(e.string())})}),e.object({action:e.literal("disqualify"),actor:_,meta:e.object({reason:W,note:e.nullish(e.string())})}),e.object({action:e.literal("reinstate"),actor:_,meta:e.object({toStage:E,toStageGroup:P,note:e.nullish(e.string())})}),e.object({action:e.literal("rate"),actor:_,meta:e.object({rating:e.nullable(e.pipe(e.number(),e.integer(),e.minValue(1),e.maxValue(5)))})})]),cr=e.object({applicationIds:e.pipe(e.array(e.string()),e.minLength(1)),body:Ht}),rt=e.picklist(["already_in_target_stage","not_in_source_stage","disqualified","already_disqualified"]),lr=e.variant("kind",[e.object({kind:e.literal("updated"),action:ae,application:ie}),e.object({kind:e.literal("skipped"),action:ae,applicationId:e.string(),reason:rt})]),pr=e.object({updated:e.array(e.object({kind:e.literal("updated"),action:ae,application:ie})),skipped:e.array(e.object({kind:e.literal("skipped"),action:ae,applicationId:e.string(),reason:rt})),failed:e.array(e.object({applicationId:e.string(),error:e.string()}))}),N=e.pipe(e.number(),e.integer(),e.minValue(0)),Wt=e.object({APPLIED:N,SHORTLISTED:N,INTERVIEWED:N,OFFERED:N,HIRED:N,REJECTED:N,WITHDRAWN:N}),dr=e.object({job_ids:et}),ur=e.object({counts:e.record(e.string(),Wt)});var hr=oe(K);import*as b from"valibot";var Sr=b.object({avg_score:b.nullable(b.number()),p90_score:b.nullable(b.number()),p85_score:b.nullable(b.number()),p80_score:b.nullable(b.number()),total_scores:b.number(),total_shortlists:b.number()});import*as ce from"valibot";var Te=({environment:t,publishableKey:n,logger:r})=>{let i=Ce[t];return{async checkDuplicate(c){try{let l=new URLSearchParams({email:c.email,scope:c.scope});c.scope==="job"&&c.jobId!=null&&l.set("job_id",String(c.jobId));let d=await fetch(`${i}/applications/check-duplicate?${l}`,{method:"GET",headers:{Accept:"application/json","x-publishable-key":n}});if(!d.ok)return r.error(`[TalentBankClient] checkDuplicate failed with status ${d.status}`),{isDuplicate:!1};let u=await d.json(),v=ce.safeParse(nt,u);return v.success?v.output:(r.error("[TalentBankClient] checkDuplicate response failed strict validation; falling back to isDuplicate flag"),typeof u=="object"&&u!=null&&typeof u.isDuplicate=="boolean"?{isDuplicate:u.isDuplicate}:{isDuplicate:!1})}catch(l){return r.error("[TalentBankClient] checkDuplicate failed:",l),{isDuplicate:!1}}},async identify(c){try{if(!c.anonymousId)return r.error("[TalentBankClient] identify skipped because anonymousId is missing"),null;let l={email:c.email,firstName:c.firstName,lastName:c.lastName,phone:c.phone,anonymousId:c.anonymousId,source:c.source??"sdk"},d=ce.safeParse(Qe,l);if(!d.success)return r.error("[TalentBankClient] identify received invalid input"),null;let u=await fetch(`${i}/identify`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","x-publishable-key":n},body:JSON.stringify(d.output)});if(!u.ok)return r.error(`[TalentBankClient] identify failed with status ${u.status}`),null;let v=ce.safeParse(Ze,await u.json());return v.success?v.output:(r.error("[TalentBankClient] identify returned an invalid response"),null)}catch(l){return r.error("[TalentBankClient] identify failed:",l),null}}}};function Kt({publishableKey:t,env:n,logger:r=ge,onEvent:i,persistence:c}){let l=Pe({baseUrl:Q[n],publishableKey:t}),d=r===!1?ve:r,u=new H({environment:n,apiKey:{type:"publishable",key:t},logger:d}),v=Te({environment:n,publishableKey:t,logger:d}),I=qe({rpcClient:u,logger:d,onEvent:i,talentBank:v,persistence:c});return{register:V=>V({logger:d,apiClient:l,analytics:I,rpcClient:u,publishableKey:t,env:n}),analytics:I,apiClient:l}}function xe(t){let n=JSON.stringify({message:t.message,acceptLabel:t.acceptLabel??"",declineLabel:t.declineLabel??""}),r=5381;for(let i=0;i<n.length;i++)r=r*33^n.charCodeAt(i);return(r>>>0).toString(36)}function Ee(t,n){return`${De}:${t}:${n}`}function Yt(t,n){if(typeof window>"u")return!1;try{let r=Ee(t,xe(n));return window.localStorage.getItem(r)==="accepted"}catch{return!1}}function zt(t,n){if(!(typeof window>"u"))try{let r=Ee(t,xe(n));window.localStorage.setItem(r,"accepted")}catch{}}function Qt(t){if(!(typeof document>"u")){if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",t,{once:!0});return}Promise.resolve().then(t)}}import*as a from"valibot";var ot=["DAILY","WEEKLY","MONTHLY"],Zt=a.record(a.string(),a.union([a.string(),a.array(a.string()),a.object({type:a.literal("provided"),lat:a.number(),lng:a.number(),radius:a.number(),unit:a.optional(a.picklist(["miles","km"])),label:a.optional(a.string())})])),Xt={pathname:"/job/:id",method:"GET",schema:{response:a.object({id:a.number(),external_id:a.nullish(a.string()),city:a.nullish(a.string()),town:a.nullish(a.string()),category:a.nullish(a.string())})}};async function en(t,{contact:n,job:r}){let i={};if(r){let c=await t.request(Xt,{params:{id:r.id}});if((r.id_type==="internal"?String(c.id):c.external_id)!==r.id)throw new Error("Job lookup returned a different role");for(let d of["city","town","category"]){let u=c[d]?.trim();u&&(i[d]=[u])}}await t.request(it,{body:{contact:n,alerts:"WEEKLY",filters:i}})}var it={pathname:"/search/save",method:"POST",schema:{response:D(),body:a.object({contact:a.object({email:a.pipe(a.optional(a.string()),a.string(),a.email()),first_name:a.optional(a.string()),last_name:a.optional(a.string())}),alerts:a.pipe(a.optional(a.string()),a.string(),a.picklist(ot)),filters:Zt})}};import*as x from"valibot";var st=async t=>{let n={method:"GET",pathname:"/search/filters",schema:{response:x.pipe(x.object({country:x.optional(x.array(x.object({value:x.string()})),[])}),x.transform(({country:r})=>r.map(({value:i})=>i))),searchParams:D()}};return t.request(n,{searchParams:{filters:{country:null}}})},le=new WeakMap,tn=t=>(le.has(t)||(le.set(t,void 0),st(t).then(async n=>{let{jobCountryCodes:r}=await import("./sdk.country-codes-W6HRF5SA.mjs");le.set(t,r(n).join(",")||void 0)}).catch(()=>{})),le.get(t)),at=(t,n)=>{let r=new Set,i=[];for(let c=0;c<Math.max(t.length,n.length);c++)for(let l of[t[c],n[c]]){if(!l)continue;let d=l.mapbox_id||l.full_address||[l.name,l.place_formatted].filter(Boolean).join(", ");if(!r.has(d)&&(r.add(d),i.push(l),i.length===5))return i}return i},nn=600,rn=async(t,n,r)=>{if(r?.throwIfAborted(),!n){let i=await t();return r?.throwIfAborted(),i}return new Promise((i,c)=>{let l,d,u,v=!1,I=()=>{v=!0,clearTimeout(u),r?.removeEventListener("abort",j)},j=()=>{I(),c(r?.reason)},V=()=>{I(),l?.status==="fulfilled"&&d?.status==="fulfilled"?i(at(l.value,d.value)):l?.status==="fulfilled"?i(l.value):d?.status==="fulfilled"?i(d.value):l?.status==="rejected"&&c(l.reason)},p=(y,f)=>{v||(y?l=f:d=f,l&&d?V():f.status==="fulfilled"&&f.value.length>0&&(u=setTimeout(V,nn)))};r?.addEventListener("abort",j,{once:!0});for(let y of[!0,!1])t(y?n:void 0).then(f=>p(y,{status:"fulfilled",value:f}),f=>p(y,{status:"rejected",reason:f}))})};export{q as ApiError,H as InploiRpcClient,ot as JOB_ALERT_FREQUENCIES,B as NotFoundError,G as ParsingError,R as SchemaValidationError,ke as SdkError,U as UnauthorisedError,tn as addressSearchCountry,at as blendAddressSuggestions,Ee as consentStorageKey,dt as createPlugin,Te as createTalentBankClient,ee as endpoint,X as generateUUID,Yt as getConsentAcceptance,st as getJobCountries,Ue as getOrCreateAnonymousId,xe as hashConsentConfig,Kt as initialiseSdk,ge as inploiBrandedLogger,gt as isApiErrorWithData,ht as isSdkError,pt as jobCountryCodes,ve as noLogging,Qt as ready,en as saveClosedRoleJobAlerts,it as saveSearchEndpoint,rn as searchAddressSuggestions,zt as setConsentAcceptance,D as typed,Ge as validateEndpointInputs};
|
|
1
|
+
import{a as lt}from"./chunk-KC7FKSIJ.mjs";var z="%c[inploi SDK]",Q="color: #65BC67; font-weight: bold;",me={warn:(...t)=>console.warn(z,Q,...t),error:(...t)=>console.error(z,Q,...t),info:(...t)=>console.info(z,Q,...t),log:(...t)=>console.log(z,Q,...t)},ge={info:()=>{},error:()=>{},log:()=>{},warn:()=>{}};var pt=t=>t;function ve(t,n){if(!t)throw new Error(n)}function F(t,n){return n in t}var mn=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});var dt="Unauthenticated",ut="This action is unauthorized.",O=class extends Error{constructor(r,o){super(r);this.status=o,this.name="ErrorWithStatus"}},B=class extends O{constructor(n){super(n??"Not found"),this.name="NotFoundError",this.status=404}},U=class extends O{constructor(n,r){super(n??"You are not authorised to perform this action."),this.name="UnauthorisedError",this.status=r??401}},P=class extends O{constructor(r,o){let l=o?` in ${o}`:"";super(`Schema validation failed${l}`);this.issues=r;this.source=o;this.name="SchemaValidationError",this.status=400}},q=class extends O{constructor(r,o,l){super(r);this.data=l;this.name="ApiError",this.status=o??500}},mt=t=>t instanceof q&&t.data!==void 0,G=class extends O{constructor(r){super("Error parsing response into JSON.");this.response=r;this.name="ParsingError",this.status=r&&r.status>=300?r.status:500,this.contentType=new Headers(r?.headers).get("content-type")??void 0}};async function fe(t){let r=new Headers(t.headers).get("content-type")?.replace(/;.*/,"").trim().toLowerCase();if(r&&r!=="application/json"&&!r.endsWith("+json"))throw new G(t);return t.json().catch(()=>{throw new G(t)})}var gt=["message","error","errors","exception","exceptions"];function vt(t){let n=[];if(typeof t=="object"&&t!==null){for(let r of gt)if(F(t,r)){let o=t[r];typeof o=="string"&&n.push(o),Array.isArray(o)&&o.every(l=>typeof l=="string")&&n.push(...o)}F(t,"integration_response")&&typeof t.integration_response=="object"&&t.integration_response!==null&&F(t.integration_response,"error")&&typeof t.integration_response.error=="object"&&t.integration_response.error!==null&&F(t.integration_response.error,"message")&&typeof t.integration_response.error.message=="string"&&n.push(t.integration_response.error.message)}return n.length===0&&n.push("Unknown error"),[...new Set(n)].join(", ")}function he(t,n){if(n>=300){let r=vt(t);throw n===404?new B(r):r===dt?new U("You are not authenticated.",n):r===ut?new U(r,n):new q(r,n,t)}}var xe=t=>{let n={Accept:"application/json","Content-Type":"application/json","x-publishable-key":t.publishableKey};return{fetch:async(r,o={})=>{let l={...o,headers:{...o.headers,...n}},c=await fetch(`${t.baseUrl}${r}`,l);if(c.status===404)throw new B;let d=await fe(c);return he(d,c.status),d}}},Ie={NotFound:B,Unauthorised:U,SchemaValidation:P,Api:q,JsonParsing:G};function ft(t){return Object.values(Ie).some(n=>t instanceof n)}var we="3.0.0";var Z={sandbox:"https://api.staging.inploi.com",production:"https://api.inploi.com",_internal_local:"http://api.test"},Pe={sandbox:"https://talent-bank.staging.inploi.com",production:"https://talent-bank.inploi.com",_internal_local:"http://localhost:8787"},Re=we;var R="isdk_session",ke=`${R}-candidate_id`,Ce=`${R}-consent`;var K=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16));var Oe=7*24*60*60*1e3,De=t=>{let n=new Date;return n.setTime(n.getTime()+Oe),`${R}=${t};expires=${n.toUTCString()};path=/`},yt=(t,n)=>{let r=t.get("session_id");if(n||r)return r;let o=sessionStorage.getItem(`${R}-session_id`);return typeof o=="string"?o:null},St=()=>{if(typeof window>"u")return null;try{let t=window.localStorage.getItem(ke);return typeof t=="string"&&t!==""?t:null}catch{return null}},bt=new RegExp(`(?:^|;\\s*)${R}=([^;]+)`),W=t=>{let n=t?t.headers.get("cookie"):document.cookie;return n?bt.exec(n)?.[1]??null:null},Ne=()=>{try{let t=JSON.parse(window.localStorage.getItem(R)??"null");return typeof t!="object"||t===null||!("id"in t)||!("expires"in t)||typeof t.id!="string"||typeof t.expires!="number"?null:t.id!==""&&t.expires>Date.now()?t.id:null}catch{return null}},Le=()=>W()??(new URL(location.href).searchParams.get("anonymous_id")?null:Ne()),_t=()=>location.protocol==="https:"&&window.self!==window.top?";SameSite=None;Secure;Partitioned":"",je=t=>{if(document.cookie=De(t)+_t(),W()!==t)try{window.localStorage.setItem(R,JSON.stringify({id:t,expires:Date.now()+Oe}))}catch{}},ye=t=>{let n=t?t.url:location.href,{searchParams:r}=new URL(n);return{anonymous_id:t?W(t)??r.get("anonymous_id"):W()??r.get("anonymous_id")??Ne(),session_id:yt(r,typeof window>"u")}},Fe=()=>{if(typeof window>"u")throw new Error("getOrCreateAnonymousId() can only be called in browser environment");let t=ye().anonymous_id;if(t)return t;let n=K(),r=ye().anonymous_id;return r||(je(n),n)},Tt=t=>typeof t!="object"||t===null?null:{anonymous_id:"anonymous_id"in t&&typeof t.anonymous_id=="string"?t.anonymous_id:null,session_id:"session_id"in t&&typeof t.session_id=="string"?t.session_id:null},At=t=>t==="about:client"?"":t,Et={pathname:"/log",method:"POST",schema:{response:C(),body:C()}},Be=({rpcClient:t,logger:n,onEvent:r,persistence:o="device",siteKind:l})=>{let c=null,d=null,u=0,f=0,E=p=>o==="none"?{anonymous_id:null,session_id:p?null:c}:ye(p),N=async(p,v,Y)=>{try{let j={library:{name:"inploi-sdk",version:Re},page:v},V=E(p.request),st=o==="none"?null:St(),y={anonymous_id:V.anonymous_id,session_id:V.session_id,candidate_id:st,event:p.event,sent_at:new Date().toISOString(),context:j,properties:p.properties,custom_properties:{...p.customProperties,...Y}},pe=o==="none"?null:p.request?W(p.request):Le(),Ae=++u,at=await t.request(Et,{body:y,...p.keepalive&&{keepalive:!0}}),x=Tt(at);if(o==="none")return!p.request&&x?.session_id&&Ae>f&&(f=Ae,x.session_id!==y.session_id&&(c=x.session_id)),y.session_id=p.request?x?.session_id||null:c,r?.(y),{success:!0,data:y};let de=p.request?pe:Le(),ct=de!==null&&de!==pe,ue=de??pe,Ee=!ct&&(!ue||!x?.anonymous_id||ue===x.anonymous_id);return Ee?(x?.anonymous_id&&(y.anonymous_id=x.anonymous_id),x?.session_id&&(y.session_id=x.session_id)):y.anonymous_id=ue,!p.request&&typeof window<"u"&&y.anonymous_id&&(Ee&&y.session_id&&sessionStorage.setItem(`${R}-session_id`,y.session_id.toString()),je(y.anonymous_id)),r?.(y),{success:!0,data:y}}catch(j){return n.error("Failed to send log to API. Inspect error response of `log` for more information."),{success:!1,error:j}}},L=Promise.resolve();return{log:async p=>{ve(p.request||typeof window<"u","Cannot log on the server without a request. Please pass a request to `log`.");let v="request"in p&&p.request?{href:p.request.url,referrer:At(p.request.referrer),title:""}:{href:location.href,referrer:document.referrer,title:document.title};o==="none"&&p.event==="FLOW_NODE"&&p.properties&&"trigger"in p.properties&&(p.properties.trigger==="pagehide"||p.properties.trigger==="hidden")&&(p={...p,keepalive:!0});let Y={event_id:K(),consent_lane:o,site_kind:l};if(o==="device"||p.request||c||p.keepalive)return N(p,v,Y);let j=()=>N(p,v,Y),V=L.then(j,j);return L=V,V},getHeaders:p=>{let v=new Headers;return o==="none"||!p?.anonymous_id||v.append("Set-Cookie",De(p.anonymous_id)),v},getSessionInfo:E,getOrCreateAnonymousId:()=>o==="none"?d??(d=K()):Fe()}};import{stringify as xt}from"neoqs";function Se(t,n,r){let o=t["~standard"].validate(n);if(o instanceof Promise)throw new TypeError("Async schema");if(o.issues)throw new P(o.issues,r);return o.value}function It(t,n,r){try{return{success:!0,output:Se(t,n,r)}}catch(o){if(o instanceof P)return{success:!1,issues:o.issues,source:o.source};throw o}}var J=class{constructor(n){if(this.baseUrl=Z[n.environment],this.headers=new Headers({"Content-Type":"application/json",Accept:"application/json"}),n.apiKey.type==="secret"){if(typeof window<"u")throw new Error("Secret key cannot be used in a browser environment");this.headers.set("x-secret-key",n.apiKey.key)}else this.headers.set("x-publishable-key",n.apiKey.key);this.logger=n.logger,this._environment=n.environment}get environment(){return this._environment}getFetchParams(n,r){let o=r.validateIn??!0,{searchParams:l,body:c}=o?Ue(n,r):r,d=new URL(this.baseUrl),u=n.pathname;if("params"in r&&r.params)for(let[f,E]of Object.entries(r.params))u=u.replace(`:${f}`,String(E));return d.pathname=u,n.schema.searchParams&&(d.search=xt(l)),[d.toString(),{method:n.method,body:c?JSON.stringify(c):void 0,headers:this.headers,signal:r.signal,...r.keepalive&&{keepalive:!0}}]}async parseResponse(n,r){let o=await fe(r.response);if(he(o,r.response.status),!(r.validateOut??!0))return o;let c=It(n.schema.response,o,"response");if(!c.success)throw new P(c.issues,c.source);return c.output}async request(n,r){try{let o=this.getFetchParams(n,r),l=await fetch(...o);return await this.parseResponse(n,{response:l,validateOut:r.validateOut})}catch(o){throw o instanceof P?this.logger.error(o.message,o.issues):this.logger.error(o),o}}};function C(){return{"~standard":{vendor:"inploi",version:1,validate:t=>({value:t})}}}function X(t){return t}function Ue(t,n){let r={searchParams:void 0,body:void 0,validateIn:!1};return t.schema.searchParams&&(r.searchParams=Se(t.schema.searchParams,"searchParams"in n?n.searchParams:{})),t.schema.body&&(r.body=Se(t.schema.body,"body"in n?n.body:{})),r}function wt({publishableKey:t,env:n,logger:r=me,onEvent:o,persistence:l,siteKind:c}){let d=xe({baseUrl:Z[n],publishableKey:t}),u=r===!1?ge:r,f=new J({environment:n,apiKey:{type:"publishable",key:t},logger:u}),E=Be({rpcClient:f,logger:u,onEvent:o,persistence:l,siteKind:c});return{register:L=>L({logger:u,apiClient:d,analytics:E,rpcClient:f,publishableKey:t,env:n}),analytics:E,apiClient:d}}var Pt={VIEW_PAGE:"A careers-site page shown (not a job page).",VIEW_JOB:"A job's own page shown; one per job id the page names.",PAGE_ENGAGEMENT:"A page view's attention summary, sent when the view is hidden or left.",VIEW_SEARCH:"A job search seen for two seconds.",SEARCH_SETTLE:"A searched query or filter with results, unchanged for five seconds.",SEARCH_PAGINATE:"A move to another page of search results.",SEARCH_JOB_CLICK:"A job opened from search results.",SAVE_JOB:"A job saved or unsaved by the candidate.",LINK_CLICK:"A tracked link clicked.",INTERACTION:"A tagged interaction (`tag` names it).",FLOW_START:"An application flow started.",FLOW_INTERACT:"The candidate's first answer in a flow.",FLOW_END:"An application flow ended.",FLOW_NODE:"The candidate's path through an application, summarised when it pauses or ends.",FLOW_SUBMIT:"An application submitted, with the outcome.",FLOW_REDIRECT:"A flow sent the candidate to an external apply page.",FEEDBACK:"A rating or comment.",ADDRESS_SHADOW_COMPARED:"Engineering telemetry: the address lookup's shadow comparison.",SUBMIT_FORM:"Declared but sent by nothing."};function be(t){let n=JSON.stringify({message:t.message,acceptLabel:t.acceptLabel??"",declineLabel:t.declineLabel??""}),r=5381;for(let o=0;o<n.length;o++)r=r*33^n.charCodeAt(o);return(r>>>0).toString(36)}function _e(t,n){return`${Ce}:${t}:${n}`}function Rt(t,n){if(typeof window>"u")return!1;try{let r=_e(t,be(n));return window.localStorage.getItem(r)==="accepted"}catch{return!1}}function kt(t,n){if(!(typeof window>"u"))try{let r=_e(t,be(n));window.localStorage.setItem(r,"accepted")}catch{}}import*as s from"valibot";var Ct=["agent","sdk","form","integration","migration"],Lt=["APPLIED","SHORTLISTED","INTERVIEWED","OFFERED","HIRED","REJECTED","WITHDRAWN"];var Ot=["screening","cv_match","interview","overall"],Dt=["PENDING","SCHEDULED","IN_PROGRESS","COMPLETED","CANCELLED"],Nt=["job","company"],jt=["created_at","updated_at"],Ft=["asc","desc"],Bt=["careers_site","chatbot","plugin_job_search","ats_import","referral","agency","other","unknown"],Ut=["submit","stage_transition","move_to_stage","shortlist","move_to_interview","make_offer","hire","withdraw","disqualify","reinstate","rate","score_written"],qt=["user","system","automation","integration","candidate"],ee=s.picklist(Ct),I=s.picklist(Lt),A=s.pipe(s.string(),s.trim(),s.minLength(1),s.maxLength(100)),te=s.picklist(Ot),qe=s.picklist(Dt),Wn=s.picklist(Nt),Ge=s.picklist(jt),Me=s.picklist(Ft),$=s.pipe(s.string(),s.trim(),s.minLength(1),s.maxLength(100)),ne=s.picklist(Bt),Ve=s.picklist(Ut),Ke=s.picklist(qt);var b=s.variant("type",[s.object({type:s.literal("user"),id:s.pipe(s.string(),s.minLength(1)),email:s.pipe(s.string(),s.minLength(1)),name:s.pipe(s.string(),s.minLength(1))}),s.object({type:s.literal("system"),id:s.pipe(s.string(),s.minLength(1)),name:s.optional(s.string())}),s.object({type:s.literal("automation"),id:s.pipe(s.string(),s.minLength(1)),name:s.optional(s.string())}),s.object({type:s.literal("integration"),id:s.pipe(s.string(),s.minLength(1)),name:s.optional(s.string())}),s.object({type:s.literal("candidate"),id:s.pipe(s.string(),s.minLength(1)),email:s.optional(s.string())})]);import*as w from"valibot";var Gt=w.object({total:w.number(),page:w.number(),perPage:w.number(),lastPage:w.number()});function re(t){return w.object({data:w.array(t),pagination:Gt})}import*as m from"valibot";var H=m.object({id:m.string(),email:m.nullable(m.string()),firstName:m.nullable(m.string()),lastName:m.nullable(m.string()),phone:m.nullable(m.string()),source:m.nullable(ee),identifiedAt:m.nullable(m.string()),createdAt:m.string(),updatedAt:m.string()});import*as i from"valibot";import*as g from"valibot";var M=g.pipe(g.string(),g.minLength(1)),We=g.pipe(g.number(),g.integer(),g.minValue(1)),k=g.record(g.string(),g.unknown());import*as _ from"valibot";var Je=_.object({id:_.string(),applicationId:_.string(),status:qe,scheduledAt:_.nullable(_.string()),completedAt:_.nullable(_.string()),meta:_.nullable(k),createdAt:_.string(),updatedAt:_.string()});var Te=i.object({score:i.number(),reason:i.string(),confidence:i.number()}),$e=i.object({id:i.string(),candidateId:i.string(),jobId:i.number(),stage:A,stageGroup:I,stageEnteredAt:i.string(),rating:i.nullable(i.number()),disqualifiedAt:i.nullable(i.string()),disqualificationReason:i.nullable($),disqualificationNote:i.nullable(i.string()),source:ne,sourceDetail:i.nullable(i.string()),sessionId:i.nullable(i.number()),externalApplicationId:i.nullable(i.string()),meta:i.nullable(k),context:i.nullable(k),scoredAt:i.nullable(i.string()),createdAt:i.string(),updatedAt:i.string()}),Mt=i.object({id:i.string(),applicationId:i.string(),scoreType:te,score:i.nullable(i.number()),reason:i.nullable(i.string()),categories:i.nullable(i.record(i.string(),Te)),scoredBy:i.nullable(i.string()),createdAt:i.string()}),oe=i.object({...$e.entries,candidate:i.nullable(H),score:i.nullable(Mt),interview:i.nullable(Je)}),Vt=i.object({...H.entries,applications:i.array($e)}),He=i.object({id:i.string(),applicationId:i.string(),action:Ve,fromStage:i.nullable(A),fromStageGroup:i.nullable(I),toStage:i.nullable(A),toStageGroup:i.nullable(I),disqualificationReason:i.nullable($),disqualificationNote:i.nullable(i.string()),actorId:i.nullable(i.string()),actorType:Ke,actorEmail:i.nullable(i.string()),actorName:i.nullable(i.string()),meta:i.nullable(k),schemaVersion:i.number(),createdAt:i.string()});import*as h from"valibot";var Ye=h.object({anonymousId:M,email:M,firstName:h.nullish(h.string()),lastName:h.nullish(h.string()),phone:h.nullish(h.string()),source:h.nullish(ee)}),ze=h.object({candidateId:h.string(),isNew:h.boolean()});import*as e from"valibot";var Kt=["stage_transition","move_to_stage","shortlist","move_to_interview","make_offer","hire","withdraw","disqualify","reinstate","rate"],se=e.picklist(Kt),Qe=e.pipe(e.string(),e.transform(t=>t.split(",").map(n=>n.trim()).filter(n=>n.length>0))),Wt=e.pipe(Qe,e.array(A)),Jt=e.pipe(Qe,e.array(I)),Ze=e.pipe(e.string(),e.transform(t=>t.split(",").map(n=>Number(n.trim())).filter(n=>Number.isInteger(n)&&n>0))),ur=e.object({stages:e.optional(Wt),stage_groups:e.optional(Jt),job_id:e.optional(e.string()),job_ids:e.optional(Ze),candidate_id:e.optional(e.string()),is_disqualified:e.optional(e.picklist(["true","false"])),created_from:e.optional(e.string()),created_to:e.optional(e.string()),updated_from:e.optional(e.string()),updated_to:e.optional(e.string()),entered_stage_from:e.optional(e.string()),entered_stage_to:e.optional(e.string()),from:e.optional(e.string()),to:e.optional(e.string()),q:e.optional(e.string()),scored:e.optional(e.picklist(["true","false"])),sort:e.optional(Ge),order:e.optional(Me),page:e.optional(e.string()),per_page:e.optional(e.string())}),mr=e.pipe(e.object({candidateId:M,jobId:We,meta:e.nullish(k),sessionId:e.nullish(e.number()),externalApplicationId:e.nullish(e.string()),context:e.nullish(k),source:e.nullish(ne),sourceDetail:e.nullish(e.string()),stage:e.nullish(A),stageGroup:e.nullish(I),actor:e.nullish(b)}),e.check(t=>t.stage==null==(t.stageGroup==null),"stage and stageGroup must be supplied together")),Xe=e.object({id:e.string(),stageGroup:e.string(),createdAt:e.string()}),gr=e.union([e.object({ok:e.literal(!0),duplicate:e.literal(!1),applicationId:e.string(),candidateId:e.string()}),e.object({ok:e.literal(!0),duplicate:e.literal(!0),existingApplication:Xe})]),et=e.object({isDuplicate:e.boolean(),existingApplication:e.optional(Xe)}),vr=e.object({applicationId:M,scoreType:te,score:e.number(),reason:e.nullish(e.string()),categories:e.nullish(e.record(e.string(),Te)),scoredBy:e.nullish(e.string()),actor:e.nullish(b)}),fr=e.object({scoreId:e.string()}),hr=re(oe);var yr=e.picklist(["already_in_target_stage","not_in_source_stage","disqualified"]),Sr=e.array(He),ie=e.object({stage:e.nullish(A),note:e.nullish(e.string())}),$t=e.object({stage:e.nullish(A),startDate:e.nullish(e.string()),note:e.nullish(e.string())}),Ht=e.variant("action",[e.object({action:e.literal("shortlist"),actor:b,meta:e.nullish(ie)}),e.object({action:e.literal("move_to_interview"),actor:b,meta:e.nullish(ie)}),e.object({action:e.literal("make_offer"),actor:b,meta:e.nullish(ie)}),e.object({action:e.literal("hire"),actor:b,meta:e.nullish($t)}),e.object({action:e.literal("withdraw"),actor:b,meta:e.nullish(ie)}),e.object({action:e.literal("move_to_stage"),actor:b,meta:e.object({stage:A,stageGroup:I,note:e.nullish(e.string())})}),e.object({action:e.literal("stage_transition"),actor:b,meta:e.object({toStage:A,toStageGroup:I,note:e.nullish(e.string())})}),e.object({action:e.literal("disqualify"),actor:b,meta:e.object({reason:$,note:e.nullish(e.string())})}),e.object({action:e.literal("reinstate"),actor:b,meta:e.object({toStage:A,toStageGroup:I,note:e.nullish(e.string())})}),e.object({action:e.literal("rate"),actor:b,meta:e.object({rating:e.nullable(e.pipe(e.number(),e.integer(),e.minValue(1),e.maxValue(5)))})})]),br=e.object({applicationIds:e.pipe(e.array(e.string()),e.minLength(1)),body:Ht}),tt=e.picklist(["already_in_target_stage","not_in_source_stage","disqualified","already_disqualified"]),_r=e.variant("kind",[e.object({kind:e.literal("updated"),action:se,application:oe}),e.object({kind:e.literal("skipped"),action:se,applicationId:e.string(),reason:tt})]),Tr=e.object({updated:e.array(e.object({kind:e.literal("updated"),action:se,application:oe})),skipped:e.array(e.object({kind:e.literal("skipped"),action:se,applicationId:e.string(),reason:tt})),failed:e.array(e.object({applicationId:e.string(),error:e.string()}))}),D=e.pipe(e.number(),e.integer(),e.minValue(0)),Yt=e.object({APPLIED:D,SHORTLISTED:D,INTERVIEWED:D,OFFERED:D,HIRED:D,REJECTED:D,WITHDRAWN:D}),Ar=e.object({job_ids:Ze}),Er=e.object({counts:e.record(e.string(),Yt)});var Rr=re(H);import*as S from"valibot";var Cr=S.object({avg_score:S.nullable(S.number()),p90_score:S.nullable(S.number()),p85_score:S.nullable(S.number()),p80_score:S.nullable(S.number()),total_scores:S.number(),total_shortlists:S.number()});import*as ae from"valibot";var zt=({environment:t,publishableKey:n,logger:r})=>{let o=Pe[t];return{async checkDuplicate(l){try{let c=new URLSearchParams({email:l.email,scope:l.scope});l.scope==="job"&&l.jobId!=null&&c.set("job_id",String(l.jobId));let d=await fetch(`${o}/applications/check-duplicate?${c}`,{method:"GET",headers:{Accept:"application/json","x-publishable-key":n}});if(!d.ok)return r.error(`[TalentBankClient] checkDuplicate failed with status ${d.status}`),{isDuplicate:!1};let u=await d.json(),f=ae.safeParse(et,u);return f.success?f.output:(r.error("[TalentBankClient] checkDuplicate response failed strict validation; falling back to isDuplicate flag"),typeof u=="object"&&u!=null&&typeof u.isDuplicate=="boolean"?{isDuplicate:u.isDuplicate}:{isDuplicate:!1})}catch(c){return r.error("[TalentBankClient] checkDuplicate failed:",c),{isDuplicate:!1}}},async identify(l){try{if(!l.anonymousId)return r.error("[TalentBankClient] identify skipped because anonymousId is missing"),null;let c={email:l.email,firstName:l.firstName,lastName:l.lastName,phone:l.phone,anonymousId:l.anonymousId,source:l.source??"sdk"},d=ae.safeParse(Ye,c);if(!d.success)return r.error("[TalentBankClient] identify received invalid input"),null;let u=await fetch(`${o}/identify`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","x-publishable-key":n},body:JSON.stringify(d.output)});if(!u.ok)return r.error(`[TalentBankClient] identify failed with status ${u.status}`),null;let f=ae.safeParse(ze,await u.json());return f.success?f.output:(r.error("[TalentBankClient] identify returned an invalid response"),null)}catch(c){return r.error("[TalentBankClient] identify failed:",c),null}}}};function Qt(t){if(!(typeof document>"u")){if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",t,{once:!0});return}Promise.resolve().then(t)}}import*as a from"valibot";var nt=["DAILY","WEEKLY","MONTHLY"],Zt=a.record(a.string(),a.union([a.string(),a.array(a.string()),a.object({type:a.literal("provided"),lat:a.number(),lng:a.number(),radius:a.number(),unit:a.optional(a.picklist(["miles","km"])),label:a.optional(a.string())})])),Xt={pathname:"/job/:id",method:"GET",schema:{response:a.object({id:a.number(),external_id:a.nullish(a.string()),city:a.nullish(a.string()),town:a.nullish(a.string()),category:a.nullish(a.string())})}};async function en(t,{contact:n,job:r}){let o={};if(r){let l=await t.request(Xt,{params:{id:r.id}});if((r.id_type==="internal"?String(l.id):l.external_id)!==r.id)throw new Error("Job lookup returned a different role");for(let d of["city","town","category"]){let u=l[d]?.trim();u&&(o[d]=[u])}}await t.request(rt,{body:{contact:n,alerts:"WEEKLY",filters:o}})}var rt={pathname:"/search/save",method:"POST",schema:{response:C(),body:a.object({contact:a.object({email:a.pipe(a.optional(a.string()),a.string(),a.email()),first_name:a.optional(a.string()),last_name:a.optional(a.string())}),alerts:a.pipe(a.optional(a.string()),a.string(),a.picklist(nt)),filters:Zt})}};import*as T from"valibot";var ot=async t=>{let n={method:"GET",pathname:"/search/filters",schema:{response:T.pipe(T.object({country:T.optional(T.array(T.object({value:T.string()})),[])}),T.transform(({country:r})=>r.map(({value:o})=>o))),searchParams:C()}};return t.request(n,{searchParams:{filters:{country:null}}})},ce=new WeakMap,tn=t=>(ce.has(t)||(ce.set(t,void 0),ot(t).then(async n=>{let{jobCountryCodes:r}=await import("./sdk.country-codes-W6HRF5SA.mjs");ce.set(t,r(n).join(",")||void 0)}).catch(()=>{})),ce.get(t)),it=(t,n)=>{let r=new Set,o=[];for(let l=0;l<Math.max(t.length,n.length);l++)for(let c of[t[l],n[l]]){if(!c)continue;let d=c.mapbox_id||c.full_address||[c.name,c.place_formatted].filter(Boolean).join(", ");if(!r.has(d)&&(r.add(d),o.push(c),o.length===5))return o}return o},nn=600,rn=async(t,n,r)=>{if(r?.throwIfAborted(),!n){let o=await t();return r?.throwIfAborted(),o}return new Promise((o,l)=>{let c,d,u,f=!1,E=()=>{f=!0,clearTimeout(u),r?.removeEventListener("abort",N)},N=()=>{E(),l(r?.reason)},L=()=>{E(),c?.status==="fulfilled"&&d?.status==="fulfilled"?o(it(c.value,d.value)):c?.status==="fulfilled"?o(c.value):d?.status==="fulfilled"?o(d.value):c?.status==="rejected"&&l(c.reason)},le=(p,v)=>{f||(p?c=v:d=v,c&&d?L():v.status==="fulfilled"&&v.value.length>0&&(u=setTimeout(L,nn)))};r?.addEventListener("abort",N,{once:!0});for(let p of[!0,!1])t(p?n:void 0).then(v=>le(p,{status:"fulfilled",value:v}),v=>le(p,{status:"rejected",reason:v}))})};export{Pt as ANALYTICS_EVENTS,q as ApiError,J as InploiRpcClient,nt as JOB_ALERT_FREQUENCIES,B as NotFoundError,G as ParsingError,P as SchemaValidationError,Ie as SdkError,U as UnauthorisedError,tn as addressSearchCountry,it as blendAddressSuggestions,_e as consentStorageKey,pt as createPlugin,zt as createTalentBankClient,X as endpoint,K as generateUUID,Rt as getConsentAcceptance,ot as getJobCountries,Fe as getOrCreateAnonymousId,be as hashConsentConfig,wt as initialiseSdk,me as inploiBrandedLogger,mt as isApiErrorWithData,ft as isSdkError,lt as jobCountryCodes,ge as noLogging,Qt as ready,en as saveClosedRoleJobAlerts,rt as saveSearchEndpoint,rn as searchAddressSuggestions,kt as setConsentAcceptance,C as typed,Ue as validateEndpointInputs};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|