@h-ai/api-client 0.1.0-alpha.71 → 0.1.0-alpha.73
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.en.md +14 -0
- package/README.ja.md +14 -0
- package/README.md +14 -0
- package/dist/index.d.ts +436 -3
- package/dist/index.js +49 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -286,8 +286,12 @@ var apiClientM = core.i18n.createMessageGetter({
|
|
|
286
286
|
"en-US": en_US_default,
|
|
287
287
|
"ja-JP": ja_JP_default
|
|
288
288
|
});
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
var pageExitBindings = /* @__PURE__ */ new WeakMap();
|
|
290
|
+
function clearIamPageExitBindings(auth) {
|
|
291
|
+
for (const stop of pageExitBindings.get(auth) ?? [])
|
|
292
|
+
stop();
|
|
293
|
+
pageExitBindings.delete(auth);
|
|
294
|
+
}
|
|
291
295
|
function createIamAuthActions(client) {
|
|
292
296
|
async function save(result) {
|
|
293
297
|
if (result.success)
|
|
@@ -295,15 +299,45 @@ function createIamAuthActions(client) {
|
|
|
295
299
|
return result;
|
|
296
300
|
}
|
|
297
301
|
return {
|
|
302
|
+
bindPageExit(options = {}) {
|
|
303
|
+
if (!options.enabled || typeof window === "undefined")
|
|
304
|
+
return () => {
|
|
305
|
+
};
|
|
306
|
+
const target = window;
|
|
307
|
+
let sent = false;
|
|
308
|
+
const onPageHide = (event) => {
|
|
309
|
+
if (event.persisted || sent)
|
|
310
|
+
return;
|
|
311
|
+
sent = true;
|
|
312
|
+
void client.iam.auth.closeSession({}, { context: { keepalive: true, autoRefresh: false } }).then((result) => {
|
|
313
|
+
if (!result.success)
|
|
314
|
+
core.logger.warn("Page exit session revocation failed", { errorCode: result.error.code });
|
|
315
|
+
}).catch(() => core.logger.warn("Page exit session request did not complete"));
|
|
316
|
+
};
|
|
317
|
+
target.addEventListener("pagehide", onPageHide);
|
|
318
|
+
const bindings = pageExitBindings.get(client.auth) ?? /* @__PURE__ */ new Set();
|
|
319
|
+
const stop = () => {
|
|
320
|
+
target.removeEventListener("pagehide", onPageHide);
|
|
321
|
+
bindings.delete(stop);
|
|
322
|
+
if (!bindings.size)
|
|
323
|
+
pageExitBindings.delete(client.auth);
|
|
324
|
+
};
|
|
325
|
+
bindings.add(stop);
|
|
326
|
+
pageExitBindings.set(client.auth, bindings);
|
|
327
|
+
return stop;
|
|
328
|
+
},
|
|
298
329
|
publicConfig: () => client.iam.auth.publicConfig(),
|
|
330
|
+
createCaptcha: (input) => client.iam.auth.createCaptcha(input),
|
|
299
331
|
login: async (input) => {
|
|
300
|
-
const result = input.method === "ldap" ? await client.iam.auth.loginWithLdap({ username: input.identifier, password: input.password }) : input.method === "email" || input.method === "sms" ? await client.iam.auth.loginWithOtp({ identifier: input.identifier, code: input.code ?? "" }) : await client.iam.auth.login({ identifier: input.identifier, password: input.password });
|
|
332
|
+
const result = input.method === "ldap" ? await client.iam.auth.loginWithLdap({ username: input.identifier, password: input.password, captcha: input.captcha }) : input.method === "email" || input.method === "sms" ? await client.iam.auth.loginWithOtp({ identifier: input.identifier, code: input.code ?? "", captcha: input.captcha }) : await client.iam.auth.login({ identifier: input.identifier, password: input.password, captcha: input.captcha });
|
|
301
333
|
return save(result);
|
|
302
334
|
},
|
|
303
335
|
register: async (input) => save(await client.iam.auth.register(input)),
|
|
304
|
-
sendOtp: (identifier) => client.iam.auth.sendOtp({ identifier }),
|
|
305
|
-
requestPasswordReset: (identifier) => client.iam.auth.requestPasswordReset({ identifier }),
|
|
306
|
-
confirmPasswordReset: (token, newPassword) => client.iam.auth.confirmPasswordReset({ token, newPassword })
|
|
336
|
+
sendOtp: (identifier, options) => client.iam.auth.sendOtp({ identifier, ...options }),
|
|
337
|
+
requestPasswordReset: (identifier, options) => client.iam.auth.requestPasswordReset({ identifier, ...options }),
|
|
338
|
+
confirmPasswordReset: (token, newPassword) => client.iam.auth.confirmPasswordReset({ token, newPassword }),
|
|
339
|
+
renewPassword: (input) => client.iam.auth.renewPassword(input),
|
|
340
|
+
reauthenticate: (password, operation) => client.iam.auth.reauthenticate({ password, operation })
|
|
307
341
|
};
|
|
308
342
|
}
|
|
309
343
|
var ApiClientErrorInfo = {
|
|
@@ -404,6 +438,7 @@ function createApiClient(contract) {
|
|
|
404
438
|
}
|
|
405
439
|
},
|
|
406
440
|
async close() {
|
|
441
|
+
clearIamPageExitBindings(auth);
|
|
407
442
|
state.observers.clear();
|
|
408
443
|
state.transport?.destroy();
|
|
409
444
|
state.config = null;
|
|
@@ -559,7 +594,12 @@ function buildTransportSession(config) {
|
|
|
559
594
|
function buildRawClient(contract, config, tokenManager, transport) {
|
|
560
595
|
const link = new OpenAPILink(contract, {
|
|
561
596
|
url: config.baseUrl,
|
|
562
|
-
headers: async (options) =>
|
|
597
|
+
headers: async (options) => {
|
|
598
|
+
const headers = await buildHeaders(config, tokenManager, getObservation(options.context)?.requestId);
|
|
599
|
+
if (typeof options.context.reauthentication === "string")
|
|
600
|
+
headers["x-hai-reauthentication"] = options.context.reauthentication;
|
|
601
|
+
return headers;
|
|
602
|
+
},
|
|
563
603
|
fetch: async (request, init, options) => {
|
|
564
604
|
const record = getObservation(options.context);
|
|
565
605
|
if (record) {
|
|
@@ -569,7 +609,8 @@ function buildRawClient(contract, config, tokenManager, transport) {
|
|
|
569
609
|
url.hash = "";
|
|
570
610
|
record.url = core.sanitize.sanitizeUrl(url.toString());
|
|
571
611
|
}
|
|
572
|
-
const
|
|
612
|
+
const requestInit = options.context.keepalive === true ? { ...init, keepalive: true } : init;
|
|
613
|
+
const response = await fetchWithRefresh(request, requestInit, config, options.context.autoRefresh === false ? void 0 : tokenManager, transport, record);
|
|
573
614
|
if (record) {
|
|
574
615
|
record.status = response.status;
|
|
575
616
|
const traceId = response.headers.get("x-trace-id") ?? response.headers.get("x-request-id");
|