@hiofu/apply-sdk 0.1.1 → 0.1.4
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 +144 -80
- package/dist/{chunk-XEXQY3NM.js → chunk-MFY3F4OY.js} +210 -8
- package/dist/{client-BD0-Mbnq.d.cts → client-Ct5xyQMk.d.cts} +153 -5
- package/dist/{client-BD0-Mbnq.d.ts → client-Ct5xyQMk.d.ts} +153 -5
- package/dist/index.cjs +360 -19
- package/dist/index.d.cts +28 -5
- package/dist/index.d.ts +28 -5
- package/dist/index.global.js +1 -1
- package/dist/index.js +190 -29
- package/dist/react.cjs +358 -7
- package/dist/react.d.cts +307 -3
- package/dist/react.d.ts +307 -3
- package/dist/react.js +170 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -34,9 +34,12 @@ __export(src_exports, {
|
|
|
34
34
|
HiofuApplyError: () => HiofuApplyError,
|
|
35
35
|
HiofuClient: () => HiofuClient,
|
|
36
36
|
HiofuConfigurationError: () => HiofuConfigurationError,
|
|
37
|
+
HiofuManagementClient: () => HiofuManagementClient,
|
|
38
|
+
HiofuPopupError: () => HiofuPopupError,
|
|
37
39
|
autoBind: () => autoBind,
|
|
38
40
|
bootstrapFromScriptTag: () => bootstrapFromScriptTag,
|
|
39
41
|
createApplyClient: () => createApplyClient,
|
|
42
|
+
createManagementClient: () => createManagementClient,
|
|
40
43
|
hiofuLogoSvg: () => hiofuLogoSvg,
|
|
41
44
|
isAutoBound: () => isAutoBound
|
|
42
45
|
});
|
|
@@ -205,8 +208,12 @@ function generateVerifier(length = 64) {
|
|
|
205
208
|
if (length < 43 || length > 128) {
|
|
206
209
|
throw new Error("PKCE verifier length must be 43..128");
|
|
207
210
|
}
|
|
211
|
+
const cryptoApi = globalThis.crypto;
|
|
212
|
+
if (!cryptoApi?.getRandomValues) {
|
|
213
|
+
throw new Error("Secure random generation is unavailable in this browser.");
|
|
214
|
+
}
|
|
208
215
|
const buf = new Uint8Array(length);
|
|
209
|
-
|
|
216
|
+
cryptoApi.getRandomValues(buf);
|
|
210
217
|
let out = "";
|
|
211
218
|
for (let i = 0; i < length; i++) {
|
|
212
219
|
out += CHARSET[buf[i] % CHARSET.length];
|
|
@@ -219,9 +226,146 @@ function base64urlEncode(bytes) {
|
|
|
219
226
|
for (const b of u8) str += String.fromCharCode(b);
|
|
220
227
|
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
221
228
|
}
|
|
229
|
+
var SHA256_K = new Uint32Array([
|
|
230
|
+
1116352408,
|
|
231
|
+
1899447441,
|
|
232
|
+
3049323471,
|
|
233
|
+
3921009573,
|
|
234
|
+
961987163,
|
|
235
|
+
1508970993,
|
|
236
|
+
2453635748,
|
|
237
|
+
2870763221,
|
|
238
|
+
3624381080,
|
|
239
|
+
310598401,
|
|
240
|
+
607225278,
|
|
241
|
+
1426881987,
|
|
242
|
+
1925078388,
|
|
243
|
+
2162078206,
|
|
244
|
+
2614888103,
|
|
245
|
+
3248222580,
|
|
246
|
+
3835390401,
|
|
247
|
+
4022224774,
|
|
248
|
+
264347078,
|
|
249
|
+
604807628,
|
|
250
|
+
770255983,
|
|
251
|
+
1249150122,
|
|
252
|
+
1555081692,
|
|
253
|
+
1996064986,
|
|
254
|
+
2554220882,
|
|
255
|
+
2821834349,
|
|
256
|
+
2952996808,
|
|
257
|
+
3210313671,
|
|
258
|
+
3336571891,
|
|
259
|
+
3584528711,
|
|
260
|
+
113926993,
|
|
261
|
+
338241895,
|
|
262
|
+
666307205,
|
|
263
|
+
773529912,
|
|
264
|
+
1294757372,
|
|
265
|
+
1396182291,
|
|
266
|
+
1695183700,
|
|
267
|
+
1986661051,
|
|
268
|
+
2177026350,
|
|
269
|
+
2456956037,
|
|
270
|
+
2730485921,
|
|
271
|
+
2820302411,
|
|
272
|
+
3259730800,
|
|
273
|
+
3345764771,
|
|
274
|
+
3516065817,
|
|
275
|
+
3600352804,
|
|
276
|
+
4094571909,
|
|
277
|
+
275423344,
|
|
278
|
+
430227734,
|
|
279
|
+
506948616,
|
|
280
|
+
659060556,
|
|
281
|
+
883997877,
|
|
282
|
+
958139571,
|
|
283
|
+
1322822218,
|
|
284
|
+
1537002063,
|
|
285
|
+
1747873779,
|
|
286
|
+
1955562222,
|
|
287
|
+
2024104815,
|
|
288
|
+
2227730452,
|
|
289
|
+
2361852424,
|
|
290
|
+
2428436474,
|
|
291
|
+
2756734187,
|
|
292
|
+
3204031479,
|
|
293
|
+
3329325298
|
|
294
|
+
]);
|
|
295
|
+
function rightRotate(value, shift) {
|
|
296
|
+
return value >>> shift | value << 32 - shift;
|
|
297
|
+
}
|
|
298
|
+
function sha256Fallback(data) {
|
|
299
|
+
let paddedLength = data.length + 1 + 8;
|
|
300
|
+
while (paddedLength % 64 !== 0) paddedLength++;
|
|
301
|
+
const padded = new Uint8Array(paddedLength);
|
|
302
|
+
padded.set(data);
|
|
303
|
+
padded[data.length] = 128;
|
|
304
|
+
const view = new DataView(padded.buffer);
|
|
305
|
+
const bitLength = data.length * 8;
|
|
306
|
+
view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
|
|
307
|
+
view.setUint32(paddedLength - 4, bitLength >>> 0);
|
|
308
|
+
let h0 = 1779033703;
|
|
309
|
+
let h1 = 3144134277;
|
|
310
|
+
let h2 = 1013904242;
|
|
311
|
+
let h3 = 2773480762;
|
|
312
|
+
let h4 = 1359893119;
|
|
313
|
+
let h5 = 2600822924;
|
|
314
|
+
let h6 = 528734635;
|
|
315
|
+
let h7 = 1541459225;
|
|
316
|
+
const w = new Uint32Array(64);
|
|
317
|
+
for (let offset = 0; offset < paddedLength; offset += 64) {
|
|
318
|
+
for (let i = 0; i < 16; i++) {
|
|
319
|
+
w[i] = view.getUint32(offset + i * 4);
|
|
320
|
+
}
|
|
321
|
+
for (let i = 16; i < 64; i++) {
|
|
322
|
+
const s0 = rightRotate(w[i - 15], 7) ^ rightRotate(w[i - 15], 18) ^ w[i - 15] >>> 3;
|
|
323
|
+
const s1 = rightRotate(w[i - 2], 17) ^ rightRotate(w[i - 2], 19) ^ w[i - 2] >>> 10;
|
|
324
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
|
|
325
|
+
}
|
|
326
|
+
let a = h0;
|
|
327
|
+
let b = h1;
|
|
328
|
+
let c = h2;
|
|
329
|
+
let d = h3;
|
|
330
|
+
let e = h4;
|
|
331
|
+
let f = h5;
|
|
332
|
+
let g = h6;
|
|
333
|
+
let h = h7;
|
|
334
|
+
for (let i = 0; i < 64; i++) {
|
|
335
|
+
const s1 = rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25);
|
|
336
|
+
const ch = e & f ^ ~e & g;
|
|
337
|
+
const temp1 = h + s1 + ch + SHA256_K[i] + w[i] >>> 0;
|
|
338
|
+
const s0 = rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22);
|
|
339
|
+
const maj = a & b ^ a & c ^ b & c;
|
|
340
|
+
const temp2 = s0 + maj >>> 0;
|
|
341
|
+
h = g;
|
|
342
|
+
g = f;
|
|
343
|
+
f = e;
|
|
344
|
+
e = d + temp1 >>> 0;
|
|
345
|
+
d = c;
|
|
346
|
+
c = b;
|
|
347
|
+
b = a;
|
|
348
|
+
a = temp1 + temp2 >>> 0;
|
|
349
|
+
}
|
|
350
|
+
h0 = h0 + a >>> 0;
|
|
351
|
+
h1 = h1 + b >>> 0;
|
|
352
|
+
h2 = h2 + c >>> 0;
|
|
353
|
+
h3 = h3 + d >>> 0;
|
|
354
|
+
h4 = h4 + e >>> 0;
|
|
355
|
+
h5 = h5 + f >>> 0;
|
|
356
|
+
h6 = h6 + g >>> 0;
|
|
357
|
+
h7 = h7 + h >>> 0;
|
|
358
|
+
}
|
|
359
|
+
const output = new ArrayBuffer(32);
|
|
360
|
+
const outputView = new DataView(output);
|
|
361
|
+
[h0, h1, h2, h3, h4, h5, h6, h7].forEach((word, index) => {
|
|
362
|
+
outputView.setUint32(index * 4, word);
|
|
363
|
+
});
|
|
364
|
+
return output;
|
|
365
|
+
}
|
|
222
366
|
async function generateChallenge(verifier) {
|
|
223
367
|
const data = new TextEncoder().encode(verifier);
|
|
224
|
-
const digest = await crypto.subtle.digest("SHA-256", data);
|
|
368
|
+
const digest = globalThis.crypto?.subtle?.digest ? await globalThis.crypto.subtle.digest("SHA-256", data) : sha256Fallback(data);
|
|
225
369
|
return base64urlEncode(digest);
|
|
226
370
|
}
|
|
227
371
|
function generateState(length = 43) {
|
|
@@ -231,6 +375,13 @@ function generateState(length = 43) {
|
|
|
231
375
|
// src/popup.ts
|
|
232
376
|
var DEFAULT_HIOFU_ORIGIN = "https://hiofu.com";
|
|
233
377
|
var DEFAULT_AUTHORIZE_TIMEOUT_MS = 5 * 6e4;
|
|
378
|
+
var HiofuPopupError = class extends Error {
|
|
379
|
+
constructor(reason, message) {
|
|
380
|
+
super(message);
|
|
381
|
+
this.name = "HiofuPopupError";
|
|
382
|
+
this.reason = reason;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
234
385
|
function resolveRedirectUri(config, hiofuOrigin) {
|
|
235
386
|
if (config.redirectUri) return config.redirectUri;
|
|
236
387
|
const hiofuBaseOrigin = new URL(hiofuOrigin).origin;
|
|
@@ -254,6 +405,8 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
254
405
|
url.searchParams.set("state", state);
|
|
255
406
|
url.searchParams.set("code_challenge", challenge);
|
|
256
407
|
url.searchParams.set("code_challenge_method", "S256");
|
|
408
|
+
url.searchParams.set("popup", "1");
|
|
409
|
+
url.searchParams.set("sdk", "apply");
|
|
257
410
|
if (context?.jobId) url.searchParams.set("job_id", context.jobId);
|
|
258
411
|
if (context?.jobTitle) url.searchParams.set("job_title", context.jobTitle);
|
|
259
412
|
if (context?.employerId)
|
|
@@ -281,11 +434,15 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
281
434
|
let focusTimer = null;
|
|
282
435
|
let overallTimeout = null;
|
|
283
436
|
let channel = null;
|
|
437
|
+
let openerLostAttention = false;
|
|
438
|
+
let openerRegainedAttention = false;
|
|
284
439
|
const cleanup = () => {
|
|
285
440
|
settled = true;
|
|
286
441
|
window.removeEventListener("message", onMessage);
|
|
287
442
|
window.removeEventListener("storage", onStorage);
|
|
443
|
+
window.removeEventListener("blur", onBlur);
|
|
288
444
|
window.removeEventListener("focus", onFocus);
|
|
445
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
289
446
|
window.clearInterval(poll);
|
|
290
447
|
if (focusTimer) clearTimeout(focusTimer);
|
|
291
448
|
if (overallTimeout) clearTimeout(overallTimeout);
|
|
@@ -356,6 +513,14 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
356
513
|
} catch {
|
|
357
514
|
}
|
|
358
515
|
};
|
|
516
|
+
const onBlur = () => {
|
|
517
|
+
openerLostAttention = true;
|
|
518
|
+
};
|
|
519
|
+
const onVisibilityChange = () => {
|
|
520
|
+
if (document.visibilityState === "hidden") {
|
|
521
|
+
openerLostAttention = true;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
359
524
|
if (typeof BroadcastChannel !== "undefined") {
|
|
360
525
|
try {
|
|
361
526
|
channel = new BroadcastChannel("hiofu_oauth");
|
|
@@ -369,6 +534,9 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
369
534
|
}
|
|
370
535
|
const onFocus = () => {
|
|
371
536
|
if (settled) return;
|
|
537
|
+
if (openerLostAttention) {
|
|
538
|
+
openerRegainedAttention = true;
|
|
539
|
+
}
|
|
372
540
|
if (focusTimer) clearTimeout(focusTimer);
|
|
373
541
|
focusTimer = setTimeout(() => {
|
|
374
542
|
try {
|
|
@@ -383,7 +551,9 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
383
551
|
};
|
|
384
552
|
window.addEventListener("message", onMessage);
|
|
385
553
|
window.addEventListener("storage", onStorage);
|
|
554
|
+
window.addEventListener("blur", onBlur);
|
|
386
555
|
window.addEventListener("focus", onFocus);
|
|
556
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
387
557
|
const poll = window.setInterval(() => {
|
|
388
558
|
if (settled) return;
|
|
389
559
|
try {
|
|
@@ -415,10 +585,14 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
415
585
|
}
|
|
416
586
|
} catch {
|
|
417
587
|
}
|
|
418
|
-
if (popup.closed) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
588
|
+
if (popup.closed && openerRegainedAttention) {
|
|
589
|
+
try {
|
|
590
|
+
const raw = localStorage.getItem("hiofu_oauth_result");
|
|
591
|
+
if (raw) {
|
|
592
|
+
handleResult(JSON.parse(raw), "close_check");
|
|
593
|
+
}
|
|
594
|
+
} catch {
|
|
595
|
+
}
|
|
422
596
|
}
|
|
423
597
|
}, 500);
|
|
424
598
|
overallTimeout = window.setTimeout(() => {
|
|
@@ -429,7 +603,12 @@ async function authorize(config, scopes, context, callbacks) {
|
|
|
429
603
|
} catch {
|
|
430
604
|
}
|
|
431
605
|
callbacks?.onPopupClosed?.("timed_out");
|
|
432
|
-
reject(
|
|
606
|
+
reject(
|
|
607
|
+
new HiofuPopupError(
|
|
608
|
+
"timed_out",
|
|
609
|
+
"Authorization timed out. Please try again."
|
|
610
|
+
)
|
|
611
|
+
);
|
|
433
612
|
}, authorizeTimeoutMs);
|
|
434
613
|
});
|
|
435
614
|
}
|
|
@@ -790,9 +969,9 @@ function autoBind(client) {
|
|
|
790
969
|
const variationId = target.getAttribute("data-hiofu-variation-id") ?? void 0;
|
|
791
970
|
const idempotencyKey = target.getAttribute("data-hiofu-idempotency-key") ?? void 0;
|
|
792
971
|
const scopes = parseScopes(target.getAttribute("data-hiofu-scopes"));
|
|
793
|
-
if (!jobId || !jobTitle
|
|
972
|
+
if (!jobId || !jobTitle) {
|
|
794
973
|
const err = new Error(
|
|
795
|
-
"data-job-id
|
|
974
|
+
"data-job-id and data-job-title are required"
|
|
796
975
|
);
|
|
797
976
|
target.dispatchEvent(
|
|
798
977
|
new CustomEvent("hiofu:apply:error", {
|
|
@@ -806,17 +985,17 @@ function autoBind(client) {
|
|
|
806
985
|
try {
|
|
807
986
|
const applyOptions = {
|
|
808
987
|
jobId,
|
|
809
|
-
jobTitle
|
|
810
|
-
employerId,
|
|
811
|
-
employerName
|
|
988
|
+
jobTitle
|
|
812
989
|
};
|
|
990
|
+
if (employerId) applyOptions.employerId = employerId;
|
|
991
|
+
if (employerName) applyOptions.employerName = employerName;
|
|
813
992
|
if (variationId) applyOptions.variationId = variationId;
|
|
814
993
|
if (idempotencyKey) applyOptions.idempotencyKey = idempotencyKey;
|
|
815
994
|
if (scopes) applyOptions.scopes = scopes;
|
|
816
995
|
if (externalRoleId || externalEmployerId) {
|
|
817
996
|
applyOptions.role = {
|
|
818
997
|
externalRoleId: externalRoleId ?? jobId,
|
|
819
|
-
externalEmployerId: externalEmployerId ?? employerId,
|
|
998
|
+
externalEmployerId: externalEmployerId ?? employerId ?? void 0,
|
|
820
999
|
title: target.getAttribute("data-role-title") ?? jobTitle,
|
|
821
1000
|
description: target.getAttribute("data-role-description") ?? void 0,
|
|
822
1001
|
department: target.getAttribute("data-role-department") ?? void 0,
|
|
@@ -932,17 +1111,14 @@ function assertPublicKey(environment, publicKey) {
|
|
|
932
1111
|
}
|
|
933
1112
|
function toApplyOptions(payload) {
|
|
934
1113
|
const locations = payload.role.locations ?? (payload.role.location ? [payload.role.location] : void 0);
|
|
935
|
-
|
|
1114
|
+
const options = {
|
|
936
1115
|
jobId: payload.externalJobId,
|
|
937
1116
|
jobTitle: payload.jobTitle ?? payload.role.title,
|
|
938
|
-
employerId: payload.externalEmployerId,
|
|
939
|
-
employerName: payload.employerName ?? payload.externalEmployerId,
|
|
940
1117
|
scopes: payload.scopes,
|
|
941
1118
|
variationId: payload.variationId,
|
|
942
1119
|
idempotencyKey: payload.idempotencyKey,
|
|
943
1120
|
role: {
|
|
944
1121
|
externalRoleId: payload.externalJobId,
|
|
945
|
-
externalEmployerId: payload.externalEmployerId,
|
|
946
1122
|
title: payload.role.title,
|
|
947
1123
|
description: payload.role.description,
|
|
948
1124
|
locations,
|
|
@@ -956,6 +1132,14 @@ function toApplyOptions(payload) {
|
|
|
956
1132
|
}
|
|
957
1133
|
}
|
|
958
1134
|
};
|
|
1135
|
+
if (payload.externalEmployerId) {
|
|
1136
|
+
options.employerId = payload.externalEmployerId;
|
|
1137
|
+
options.role.externalEmployerId = payload.externalEmployerId;
|
|
1138
|
+
}
|
|
1139
|
+
if (payload.employerName) {
|
|
1140
|
+
options.employerName = payload.employerName;
|
|
1141
|
+
}
|
|
1142
|
+
return options;
|
|
959
1143
|
}
|
|
960
1144
|
function toNormalizedResult(result, environment, partnerApplicationId) {
|
|
961
1145
|
const submittedAt = result.application.submittedAt instanceof Date ? result.application.submittedAt.toISOString() : result.application.submittedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -976,12 +1160,26 @@ function toApplyError(error, correlationId) {
|
|
|
976
1160
|
let retryable = false;
|
|
977
1161
|
if (error instanceof HiofuConfigurationError) {
|
|
978
1162
|
code = error.code === "hiofu.environment_mismatch" ? "environment_mismatch" : "configuration_error";
|
|
1163
|
+
} else if (error instanceof HiofuPopupError) {
|
|
1164
|
+
if (error.reason === "timed_out") {
|
|
1165
|
+
code = "timeout";
|
|
1166
|
+
} else {
|
|
1167
|
+
code = "popup_closed";
|
|
1168
|
+
}
|
|
1169
|
+
retryable = true;
|
|
979
1170
|
} else if (/popup blocked/i.test(message)) {
|
|
980
1171
|
code = "popup_blocked";
|
|
981
1172
|
retryable = true;
|
|
1173
|
+
} else if (/authorization popup closed|popup closed/i.test(message)) {
|
|
1174
|
+
code = "popup_closed";
|
|
1175
|
+
retryable = true;
|
|
982
1176
|
} else if (/timed out/i.test(message)) {
|
|
983
1177
|
code = "timeout";
|
|
984
1178
|
retryable = true;
|
|
1179
|
+
} 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(
|
|
1180
|
+
message
|
|
1181
|
+
)) {
|
|
1182
|
+
code = "configuration_error";
|
|
985
1183
|
} else if (/access_denied|consent/i.test(message)) {
|
|
986
1184
|
code = "consent_required";
|
|
987
1185
|
} else if (error instanceof HiofuApiError) {
|
|
@@ -1044,10 +1242,10 @@ function createApplyClient(config) {
|
|
|
1044
1242
|
const applyError = toApplyError(err, correlationId);
|
|
1045
1243
|
if (applyError.code === "consent_required") {
|
|
1046
1244
|
config.onCancel?.({ reason: "user_cancelled", correlationId });
|
|
1245
|
+
} else if (applyError.code === "popup_closed") {
|
|
1246
|
+
config.onCancel?.({ reason: "popup_closed", correlationId });
|
|
1047
1247
|
} else if (applyError.code === "timeout") {
|
|
1048
1248
|
config.onCancel?.({ reason: "timeout", correlationId });
|
|
1049
|
-
} else if (/popup closed/i.test(applyError.message)) {
|
|
1050
|
-
config.onCancel?.({ reason: "popup_closed", correlationId });
|
|
1051
1249
|
}
|
|
1052
1250
|
config.onError?.(applyError);
|
|
1053
1251
|
throw applyError;
|
|
@@ -1056,6 +1254,149 @@ function createApplyClient(config) {
|
|
|
1056
1254
|
};
|
|
1057
1255
|
}
|
|
1058
1256
|
|
|
1257
|
+
// src/management.ts
|
|
1258
|
+
function buildQuery(params) {
|
|
1259
|
+
if (!params) {
|
|
1260
|
+
return "";
|
|
1261
|
+
}
|
|
1262
|
+
const search = new URLSearchParams();
|
|
1263
|
+
if (typeof params.page === "number") {
|
|
1264
|
+
search.set("page", String(params.page));
|
|
1265
|
+
}
|
|
1266
|
+
if (typeof params.limit === "number") {
|
|
1267
|
+
search.set("limit", String(params.limit));
|
|
1268
|
+
}
|
|
1269
|
+
if (params.status) {
|
|
1270
|
+
search.set("status", params.status);
|
|
1271
|
+
}
|
|
1272
|
+
if (params.search?.trim()) {
|
|
1273
|
+
search.set("search", params.search.trim());
|
|
1274
|
+
}
|
|
1275
|
+
const query = search.toString();
|
|
1276
|
+
return query ? `?${query}` : "";
|
|
1277
|
+
}
|
|
1278
|
+
var HiofuManagementClient = class {
|
|
1279
|
+
constructor(config = {}) {
|
|
1280
|
+
this.config = config;
|
|
1281
|
+
}
|
|
1282
|
+
async request(path, init = {}) {
|
|
1283
|
+
const apiBase = this.config.apiBase ?? DEFAULT_API_BASE;
|
|
1284
|
+
const headers = new Headers(this.config.headers);
|
|
1285
|
+
if (init.headers) {
|
|
1286
|
+
new Headers(init.headers).forEach((value, key) => {
|
|
1287
|
+
headers.set(key, value);
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
return jsonFetch(`${apiBase}${path}`, {
|
|
1291
|
+
...init,
|
|
1292
|
+
headers,
|
|
1293
|
+
token: this.config.accessToken,
|
|
1294
|
+
credentials: this.config.credentials ?? (this.config.accessToken ? void 0 : "include")
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
async listRoles(params) {
|
|
1298
|
+
return this.request(
|
|
1299
|
+
`/employer-roles${buildQuery(params)}`
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
async getRole(roleId) {
|
|
1303
|
+
const response = await this.request(
|
|
1304
|
+
`/employer-roles/${roleId}`
|
|
1305
|
+
);
|
|
1306
|
+
return response.data;
|
|
1307
|
+
}
|
|
1308
|
+
async createRole(input) {
|
|
1309
|
+
const response = await this.request(
|
|
1310
|
+
"/employer-roles",
|
|
1311
|
+
{
|
|
1312
|
+
method: "POST",
|
|
1313
|
+
body: JSON.stringify(input)
|
|
1314
|
+
}
|
|
1315
|
+
);
|
|
1316
|
+
return response.data;
|
|
1317
|
+
}
|
|
1318
|
+
async updateRole(roleId, input) {
|
|
1319
|
+
const response = await this.request(
|
|
1320
|
+
`/employer-roles/${roleId}`,
|
|
1321
|
+
{
|
|
1322
|
+
method: "PATCH",
|
|
1323
|
+
body: JSON.stringify(input)
|
|
1324
|
+
}
|
|
1325
|
+
);
|
|
1326
|
+
return response.data;
|
|
1327
|
+
}
|
|
1328
|
+
async updateRoleStatus(roleId, status) {
|
|
1329
|
+
const response = await this.request(
|
|
1330
|
+
`/employer-roles/${roleId}/status`,
|
|
1331
|
+
{
|
|
1332
|
+
method: "PATCH",
|
|
1333
|
+
body: JSON.stringify({ status })
|
|
1334
|
+
}
|
|
1335
|
+
);
|
|
1336
|
+
return response.data;
|
|
1337
|
+
}
|
|
1338
|
+
async getDeveloperSettings() {
|
|
1339
|
+
const response = await this.request(
|
|
1340
|
+
"/employers/developer/apply-sdk"
|
|
1341
|
+
);
|
|
1342
|
+
return response.data;
|
|
1343
|
+
}
|
|
1344
|
+
async issuePublishableKey() {
|
|
1345
|
+
const response = await this.request(
|
|
1346
|
+
"/employers/developer/apply-sdk",
|
|
1347
|
+
{
|
|
1348
|
+
method: "POST"
|
|
1349
|
+
}
|
|
1350
|
+
);
|
|
1351
|
+
return response.data;
|
|
1352
|
+
}
|
|
1353
|
+
async saveRoleMapping(input) {
|
|
1354
|
+
let resolvedRole = null;
|
|
1355
|
+
if (!input.title || !input.description || !input.locations) {
|
|
1356
|
+
resolvedRole = await this.getRole(input.employerRoleId);
|
|
1357
|
+
}
|
|
1358
|
+
const response = await this.request(
|
|
1359
|
+
"/employers/developer/apply-sdk/role-mappings",
|
|
1360
|
+
{
|
|
1361
|
+
method: "POST",
|
|
1362
|
+
body: JSON.stringify({
|
|
1363
|
+
mode: input.mode,
|
|
1364
|
+
externalRoleId: input.externalRoleId,
|
|
1365
|
+
externalEmployerId: input.externalEmployerId,
|
|
1366
|
+
employerRoleId: input.employerRoleId,
|
|
1367
|
+
title: input.title ?? resolvedRole?.title,
|
|
1368
|
+
description: input.description ?? resolvedRole?.description ?? void 0,
|
|
1369
|
+
locations: input.locations ?? resolvedRole?.locations ?? void 0,
|
|
1370
|
+
metadata: input.metadata
|
|
1371
|
+
})
|
|
1372
|
+
}
|
|
1373
|
+
);
|
|
1374
|
+
return response.data;
|
|
1375
|
+
}
|
|
1376
|
+
async addRedirectUri(input) {
|
|
1377
|
+
const response = await this.request(
|
|
1378
|
+
"/employers/developer/apply-sdk/redirect-uris",
|
|
1379
|
+
{
|
|
1380
|
+
method: "POST",
|
|
1381
|
+
body: JSON.stringify(input)
|
|
1382
|
+
}
|
|
1383
|
+
);
|
|
1384
|
+
return response.data;
|
|
1385
|
+
}
|
|
1386
|
+
async removeRedirectUri(uriId) {
|
|
1387
|
+
const response = await this.request(
|
|
1388
|
+
`/employers/developer/apply-sdk/redirect-uris/${uriId}`,
|
|
1389
|
+
{
|
|
1390
|
+
method: "DELETE"
|
|
1391
|
+
}
|
|
1392
|
+
);
|
|
1393
|
+
return response.data;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
function createManagementClient(config = {}) {
|
|
1397
|
+
return new HiofuManagementClient(config);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1059
1400
|
// src/index.ts
|
|
1060
1401
|
var _instance = null;
|
|
1061
1402
|
var Hiofu = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HiofuClient, a as HiofuScope, b as HiofuApplyResult, c as HiofuConfig, d as HiofuEvent, e as
|
|
2
|
-
export { D as DEFAULT_APPLY_SCOPES,
|
|
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.cjs';
|
|
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.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Scan the document for `[data-hiofu-apply]` buttons and wire them up to call
|
|
@@ -33,7 +33,7 @@ declare class HiofuApiError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
type HiofuEnvironment = "sandbox" | "production";
|
|
36
|
-
type HiofuApplyErrorCode = "configuration_error" | "environment_mismatch" | "popup_blocked" | "auth_failed" | "consent_required" | "role_mapping_failed" | "submit_failed" | "timeout";
|
|
36
|
+
type HiofuApplyErrorCode = "configuration_error" | "environment_mismatch" | "popup_blocked" | "popup_closed" | "auth_failed" | "consent_required" | "role_mapping_failed" | "submit_failed" | "timeout";
|
|
37
37
|
declare class HiofuApplyError extends Error {
|
|
38
38
|
readonly code: HiofuApplyErrorCode;
|
|
39
39
|
readonly correlationId: string;
|
|
@@ -68,7 +68,7 @@ interface HiofuCreateApplyClientConfig {
|
|
|
68
68
|
apiBase?: string;
|
|
69
69
|
}
|
|
70
70
|
interface HiofuApplyPayload {
|
|
71
|
-
externalEmployerId
|
|
71
|
+
externalEmployerId?: string;
|
|
72
72
|
externalJobId: string;
|
|
73
73
|
role: {
|
|
74
74
|
title: string;
|
|
@@ -117,6 +117,29 @@ declare class HiofuConfigurationError extends Error {
|
|
|
117
117
|
constructor(code: HiofuConfigurationErrorCode, message: string, details?: Record<string, unknown>);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
declare class HiofuManagementClient {
|
|
121
|
+
private readonly config;
|
|
122
|
+
constructor(config?: HiofuManagementConfig);
|
|
123
|
+
private request;
|
|
124
|
+
listRoles(params?: HiofuManagementListRolesParams): Promise<HiofuManagementPaginatedResult<HiofuManagementRoleListItem>>;
|
|
125
|
+
getRole(roleId: string): Promise<HiofuManagementRole>;
|
|
126
|
+
createRole(input: HiofuManagementCreateRoleInput): Promise<HiofuManagementRole>;
|
|
127
|
+
updateRole(roleId: string, input: HiofuManagementUpdateRoleInput): Promise<HiofuManagementRole>;
|
|
128
|
+
updateRoleStatus(roleId: string, status: HiofuManagementRoleStatus): Promise<HiofuManagementRole>;
|
|
129
|
+
getDeveloperSettings(): Promise<HiofuManagementDeveloperSettings>;
|
|
130
|
+
issuePublishableKey(): Promise<HiofuManagementDeveloperSettings>;
|
|
131
|
+
saveRoleMapping(input: HiofuManagementSaveRoleMappingInput): Promise<HiofuManagementDeveloperSettings>;
|
|
132
|
+
addRedirectUri(input: HiofuManagementAddRedirectUriInput): Promise<HiofuManagementDeveloperSettings>;
|
|
133
|
+
removeRedirectUri(uriId: string): Promise<HiofuManagementDeveloperSettings>;
|
|
134
|
+
}
|
|
135
|
+
declare function createManagementClient(config?: HiofuManagementConfig): HiofuManagementClient;
|
|
136
|
+
|
|
137
|
+
type HiofuPopupErrorReason = "user_closed" | "timed_out";
|
|
138
|
+
declare class HiofuPopupError extends Error {
|
|
139
|
+
readonly reason: HiofuPopupErrorReason;
|
|
140
|
+
constructor(reason: HiofuPopupErrorReason, message: string);
|
|
141
|
+
}
|
|
142
|
+
|
|
120
143
|
/**
|
|
121
144
|
* @fileoverview Hiofu brand assets exposed for partners that want their
|
|
122
145
|
* "Apply with Hiofu" button to match the canonical look. All values here are
|
|
@@ -155,4 +178,4 @@ declare const Hiofu: {
|
|
|
155
178
|
logout(): Promise<void>;
|
|
156
179
|
};
|
|
157
180
|
|
|
158
|
-
export { HIOFU_BRAND_COLOR, HIOFU_BRAND_SOFT, HIOFU_BUTTON_LABEL, HIOFU_FONT_FAMILY, HIOFU_FONT_URL, HIOFU_TAGLINE, HIOFU_WORDMARK, Hiofu, HiofuApiError, type HiofuApplyClient, HiofuApplyError, type HiofuApplyErrorCode, HiofuApplyOptions, type HiofuApplyPayload, HiofuApplyResult, type HiofuCancelContext, HiofuClient, HiofuConfig, HiofuConfigurationError, type HiofuCreateApplyClientConfig, type HiofuEnvironment, HiofuEvent, type HiofuNormalizedApplyResult, HiofuScope, HiofuTokenSet, autoBind, bootstrapFromScriptTag, createApplyClient, hiofuLogoSvg, isAutoBound };
|
|
181
|
+
export { HIOFU_BRAND_COLOR, HIOFU_BRAND_SOFT, HIOFU_BUTTON_LABEL, HIOFU_FONT_FAMILY, HIOFU_FONT_URL, HIOFU_TAGLINE, HIOFU_WORDMARK, Hiofu, HiofuApiError, type HiofuApplyClient, HiofuApplyError, type HiofuApplyErrorCode, HiofuApplyOptions, type HiofuApplyPayload, HiofuApplyResult, type HiofuCancelContext, HiofuClient, HiofuConfig, HiofuConfigurationError, type HiofuCreateApplyClientConfig, type HiofuEnvironment, HiofuEvent, HiofuManagementAddRedirectUriInput, HiofuManagementClient, HiofuManagementConfig, HiofuManagementCreateRoleInput, HiofuManagementDeveloperSettings, HiofuManagementListRolesParams, HiofuManagementPaginatedResult, HiofuManagementRole, HiofuManagementRoleListItem, HiofuManagementRoleStatus, HiofuManagementSaveRoleMappingInput, HiofuManagementUpdateRoleInput, type HiofuNormalizedApplyResult, HiofuPopupError, HiofuScope, HiofuTokenSet, autoBind, bootstrapFromScriptTag, createApplyClient, createManagementClient, hiofuLogoSvg, isAutoBound };
|
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
|
|
2
|
-
export { D as DEFAULT_APPLY_SCOPES,
|
|
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';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Scan the document for `[data-hiofu-apply]` buttons and wire them up to call
|
|
@@ -33,7 +33,7 @@ declare class HiofuApiError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
type HiofuEnvironment = "sandbox" | "production";
|
|
36
|
-
type HiofuApplyErrorCode = "configuration_error" | "environment_mismatch" | "popup_blocked" | "auth_failed" | "consent_required" | "role_mapping_failed" | "submit_failed" | "timeout";
|
|
36
|
+
type HiofuApplyErrorCode = "configuration_error" | "environment_mismatch" | "popup_blocked" | "popup_closed" | "auth_failed" | "consent_required" | "role_mapping_failed" | "submit_failed" | "timeout";
|
|
37
37
|
declare class HiofuApplyError extends Error {
|
|
38
38
|
readonly code: HiofuApplyErrorCode;
|
|
39
39
|
readonly correlationId: string;
|
|
@@ -68,7 +68,7 @@ interface HiofuCreateApplyClientConfig {
|
|
|
68
68
|
apiBase?: string;
|
|
69
69
|
}
|
|
70
70
|
interface HiofuApplyPayload {
|
|
71
|
-
externalEmployerId
|
|
71
|
+
externalEmployerId?: string;
|
|
72
72
|
externalJobId: string;
|
|
73
73
|
role: {
|
|
74
74
|
title: string;
|
|
@@ -117,6 +117,29 @@ declare class HiofuConfigurationError extends Error {
|
|
|
117
117
|
constructor(code: HiofuConfigurationErrorCode, message: string, details?: Record<string, unknown>);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
declare class HiofuManagementClient {
|
|
121
|
+
private readonly config;
|
|
122
|
+
constructor(config?: HiofuManagementConfig);
|
|
123
|
+
private request;
|
|
124
|
+
listRoles(params?: HiofuManagementListRolesParams): Promise<HiofuManagementPaginatedResult<HiofuManagementRoleListItem>>;
|
|
125
|
+
getRole(roleId: string): Promise<HiofuManagementRole>;
|
|
126
|
+
createRole(input: HiofuManagementCreateRoleInput): Promise<HiofuManagementRole>;
|
|
127
|
+
updateRole(roleId: string, input: HiofuManagementUpdateRoleInput): Promise<HiofuManagementRole>;
|
|
128
|
+
updateRoleStatus(roleId: string, status: HiofuManagementRoleStatus): Promise<HiofuManagementRole>;
|
|
129
|
+
getDeveloperSettings(): Promise<HiofuManagementDeveloperSettings>;
|
|
130
|
+
issuePublishableKey(): Promise<HiofuManagementDeveloperSettings>;
|
|
131
|
+
saveRoleMapping(input: HiofuManagementSaveRoleMappingInput): Promise<HiofuManagementDeveloperSettings>;
|
|
132
|
+
addRedirectUri(input: HiofuManagementAddRedirectUriInput): Promise<HiofuManagementDeveloperSettings>;
|
|
133
|
+
removeRedirectUri(uriId: string): Promise<HiofuManagementDeveloperSettings>;
|
|
134
|
+
}
|
|
135
|
+
declare function createManagementClient(config?: HiofuManagementConfig): HiofuManagementClient;
|
|
136
|
+
|
|
137
|
+
type HiofuPopupErrorReason = "user_closed" | "timed_out";
|
|
138
|
+
declare class HiofuPopupError extends Error {
|
|
139
|
+
readonly reason: HiofuPopupErrorReason;
|
|
140
|
+
constructor(reason: HiofuPopupErrorReason, message: string);
|
|
141
|
+
}
|
|
142
|
+
|
|
120
143
|
/**
|
|
121
144
|
* @fileoverview Hiofu brand assets exposed for partners that want their
|
|
122
145
|
* "Apply with Hiofu" button to match the canonical look. All values here are
|
|
@@ -155,4 +178,4 @@ declare const Hiofu: {
|
|
|
155
178
|
logout(): Promise<void>;
|
|
156
179
|
};
|
|
157
180
|
|
|
158
|
-
export { HIOFU_BRAND_COLOR, HIOFU_BRAND_SOFT, HIOFU_BUTTON_LABEL, HIOFU_FONT_FAMILY, HIOFU_FONT_URL, HIOFU_TAGLINE, HIOFU_WORDMARK, Hiofu, HiofuApiError, type HiofuApplyClient, HiofuApplyError, type HiofuApplyErrorCode, HiofuApplyOptions, type HiofuApplyPayload, HiofuApplyResult, type HiofuCancelContext, HiofuClient, HiofuConfig, HiofuConfigurationError, type HiofuCreateApplyClientConfig, type HiofuEnvironment, HiofuEvent, type HiofuNormalizedApplyResult, HiofuScope, HiofuTokenSet, autoBind, bootstrapFromScriptTag, createApplyClient, hiofuLogoSvg, isAutoBound };
|
|
181
|
+
export { HIOFU_BRAND_COLOR, HIOFU_BRAND_SOFT, HIOFU_BUTTON_LABEL, HIOFU_FONT_FAMILY, HIOFU_FONT_URL, HIOFU_TAGLINE, HIOFU_WORDMARK, Hiofu, HiofuApiError, type HiofuApplyClient, HiofuApplyError, type HiofuApplyErrorCode, HiofuApplyOptions, type HiofuApplyPayload, HiofuApplyResult, type HiofuCancelContext, HiofuClient, HiofuConfig, HiofuConfigurationError, type HiofuCreateApplyClientConfig, type HiofuEnvironment, HiofuEvent, HiofuManagementAddRedirectUriInput, HiofuManagementClient, HiofuManagementConfig, HiofuManagementCreateRoleInput, HiofuManagementDeveloperSettings, HiofuManagementListRolesParams, HiofuManagementPaginatedResult, HiofuManagementRole, HiofuManagementRoleListItem, HiofuManagementRoleStatus, HiofuManagementSaveRoleMappingInput, HiofuManagementUpdateRoleInput, type HiofuNormalizedApplyResult, HiofuPopupError, HiofuScope, HiofuTokenSet, autoBind, bootstrapFromScriptTag, createApplyClient, createManagementClient, hiofuLogoSvg, isAutoBound };
|