@leancodepl/kratos
Version:
Headless React components library for building Ory Kratos authentication flows
1,302 lines (1,292 loc) • 751 kB
JavaScript
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import { useContext, createContext, useMemo, useState, useEffect, useCallback } from 'react';
import * as Slot from '@radix-ui/react-slot';
import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query';
import { useForm } from '@tanstack/react-form';
import { toUpperFirst } from '@leancodepl/utils';
var GetFlowError;
(function(GetFlowError) {
GetFlowError[GetFlowError["NoFlowId"] = 0] = "NoFlowId";
GetFlowError[GetFlowError["FlowRestartRequired"] = 1] = "FlowRestartRequired";
})(GetFlowError || (GetFlowError = {}));
var kratosSessionContext = /*#__PURE__*/ createContext(undefined);
function useKratosSessionContext() {
var context = useContext(kratosSessionContext);
if (context === undefined) {
throw new Error("useKratosSessionContext must be used within a KratosSessionContextProvider");
}
return context;
}
function KratosSessionProvider(param) {
var children = param.children, sessionManager = param.sessionManager;
var kratosSessionContextData = useMemo(function() {
return {
sessionManager: sessionManager
};
}, [
sessionManager
]);
return /*#__PURE__*/ jsx(kratosSessionContext.Provider, {
value: kratosSessionContextData,
children: children
});
}
function _array_like_to_array$b(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes$7(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit$7(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest$7() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array$7(arr, i) {
return _array_with_holes$7(arr) || _iterable_to_array_limit$7(arr, i) || _unsupported_iterable_to_array$b(arr, i) || _non_iterable_rest$7();
}
function _unsupported_iterable_to_array$b(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array$b(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$b(o, minLen);
}
var useFlowManager = function(param) {
var initialFlowId = param.initialFlowId, currentFlowId = param.currentFlowId, error = param.error, onFlowRestart = param.onFlowRestart, createFlow = param.createFlow, setFlowId = param.setFlowId, waitForSession = param.waitForSession;
var _useState = _sliced_to_array$7(useState(false), 2), initialFlowIdUsed = _useState[0], setInitialFlowIdUsed = _useState[1];
var _useState1 = _sliced_to_array$7(useState(initialFlowId), 2), prevInitialFlowId = _useState1[0], setPrevInitialFlowId = _useState1[1];
var sessionManager = useKratosSessionContext().sessionManager;
var isLoading = sessionManager.useSession().isLoading;
if (prevInitialFlowId !== initialFlowId) {
setInitialFlowIdUsed(false);
setPrevInitialFlowId(initialFlowId);
}
var shouldWait = !!waitForSession && isLoading;
useEffect(function() {
if (currentFlowId || shouldWait) {
return;
}
if (initialFlowId && !initialFlowIdUsed) {
setFlowId(initialFlowId);
setInitialFlowIdUsed(true);
} else {
createFlow();
}
}, [
createFlow,
currentFlowId,
initialFlowId,
initialFlowIdUsed,
setFlowId,
shouldWait
]);
useEffect(function() {
if (error && error.cause === GetFlowError.FlowRestartRequired) {
createFlow();
onFlowRestart === null || onFlowRestart === void 0 ? void 0 : onFlowRestart();
}
}, [
createFlow,
error,
onFlowRestart
]);
};
var traitPrefix = "traits.";
function _array_like_to_array$a(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_without_holes$3(arr) {
if (Array.isArray(arr)) return _array_like_to_array$a(arr);
}
function _iterable_to_array$3(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread$3() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _to_consumable_array$3(arr) {
return _array_without_holes$3(arr) || _iterable_to_array$3(arr) || _unsupported_iterable_to_array$a(arr) || _non_iterable_spread$3();
}
function _unsupported_iterable_to_array$a(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array$a(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$a(o, minLen);
}
function base64urlDecode(value) {
return Uint8Array.from(atob(value.replaceAll("-", "+").replaceAll("_", "/")), function(c) {
return c.charCodeAt(0);
});
}
function base64urlEncode(value) {
var _String;
return btoa((_String = String).fromCharCode.apply(_String, _to_consumable_array$3(new Uint8Array(value)))).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
}
function asyncGeneratorStep$B(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator$B(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep$B(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep$B(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _instanceof$5(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _ts_generator$B(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
function trySafeStringifyNewCredential(credential) {
if (!credential) return undefined;
if (!_instanceof$5(credential, PublicKeyCredential)) return undefined;
if (!_instanceof$5(credential.response, AuthenticatorAttestationResponse)) return undefined;
return JSON.stringify({
id: credential.id,
rawId: base64urlEncode(credential.rawId),
type: credential.type,
response: {
attestationObject: base64urlEncode(credential.response.attestationObject),
clientDataJSON: base64urlEncode(credential.response.clientDataJSON)
}
});
}
function createCredential(_) {
return _createCredential.apply(this, arguments);
}
function _createCredential() {
_createCredential = _async_to_generator$B(function(param) {
var credentialOptions, signal, userName, userDisplayName;
return _ts_generator$B(this, function(_state) {
switch(_state.label){
case 0:
credentialOptions = param.credentialOptions, signal = param.signal, userName = param.userName, userDisplayName = param.userDisplayName;
return [
4,
navigator.credentials.create({
signal: signal,
publicKey: {
challenge: base64urlDecode(credentialOptions.publicKey.challenge),
timeout: credentialOptions.publicKey.timeout,
rp: {
id: credentialOptions.publicKey.rp.id,
name: credentialOptions.publicKey.rp.name
},
user: {
id: base64urlDecode(credentialOptions.publicKey.user.id),
name: userName,
displayName: userDisplayName
},
pubKeyCredParams: credentialOptions.publicKey.pubKeyCredParams
}
})
];
case 1:
return [
2,
_state.sent()
];
}
});
});
return _createCredential.apply(this, arguments);
}
function trySafeStringifyExistingCredential(credential) {
if (!credential) return undefined;
if (!_instanceof$5(credential, PublicKeyCredential)) return undefined;
if (!_instanceof$5(credential.response, AuthenticatorAssertionResponse)) return undefined;
return JSON.stringify({
id: credential.id,
rawId: base64urlEncode(credential.rawId),
type: credential.type,
response: {
authenticatorData: base64urlEncode(credential.response.authenticatorData),
clientDataJSON: base64urlEncode(credential.response.clientDataJSON),
signature: base64urlEncode(credential.response.signature),
userHandle: credential.response.userHandle ? base64urlEncode(credential.response.userHandle) : undefined
}
});
}
function getCredential(_) {
return _getCredential.apply(this, arguments);
}
function _getCredential() {
_getCredential = _async_to_generator$B(function(param) {
var challengeOptions, signal;
return _ts_generator$B(this, function(_state) {
switch(_state.label){
case 0:
challengeOptions = param.challengeOptions, signal = param.signal;
return [
4,
navigator.credentials.get({
signal: signal,
publicKey: {
challenge: base64urlDecode(challengeOptions.publicKey.challenge),
timeout: challengeOptions.publicKey.timeout,
rpId: challengeOptions.publicKey.rpId,
userVerification: challengeOptions.publicKey.userVerification
}
})
];
case 1:
return [
2,
_state.sent()
];
}
});
});
return _getCredential.apply(this, arguments);
}
function asyncGeneratorStep$A(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator$A(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep$A(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep$A(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _instanceof$4(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _ts_generator$A(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
function isPasskeySupported() {
return !!window.PublicKeyCredential;
}
function passkeyLoginInit(passkeyChallengeString, signal) {
return _passkeyLoginInit.apply(this, arguments);
}
function _passkeyLoginInit() {
_passkeyLoginInit = _async_to_generator$A(function(passkeyChallengeString, signal) {
var passkeyChallenge, credential;
return _ts_generator$A(this, function(_state) {
switch(_state.label){
case 0:
passkeyChallenge = JSON.parse(passkeyChallengeString);
if (!isPasskeySupported()) return [
2,
undefined
];
if (!window.PublicKeyCredential.isConditionalMediationAvailable) return [
2,
undefined
];
return [
4,
window.PublicKeyCredential.isConditionalMediationAvailable()
];
case 1:
if (!_state.sent()) return [
2,
undefined
];
_state.label = 2;
case 2:
_state.trys.push([
2,
4,
,
5
]);
return [
4,
navigator.credentials.get({
mediation: "conditional",
signal: signal,
publicKey: {
challenge: base64urlDecode(passkeyChallenge.publicKey.challenge),
timeout: passkeyChallenge.publicKey.timeout,
rpId: passkeyChallenge.publicKey.rpId,
userVerification: passkeyChallenge.publicKey.userVerification
}
})
];
case 3:
credential = _state.sent();
if (!credential) return [
2,
undefined
];
if (!_instanceof$4(credential, PublicKeyCredential)) return [
2,
undefined
];
if (!_instanceof$4(credential.response, AuthenticatorAssertionResponse)) return [
2,
undefined
];
return [
2,
JSON.stringify({
id: credential.id,
rawId: base64urlEncode(credential.rawId),
type: credential.type,
response: {
authenticatorData: base64urlEncode(credential.response.authenticatorData),
clientDataJSON: base64urlEncode(credential.response.clientDataJSON),
signature: base64urlEncode(credential.response.signature),
userHandle: credential.response.userHandle ? base64urlEncode(credential.response.userHandle) : undefined
}
})
];
case 4:
_state.sent();
return [
2,
undefined
];
case 5:
return [
2
];
}
});
});
return _passkeyLoginInit.apply(this, arguments);
}
function passkeyLogin(passkeyChallengeString, signal) {
return _passkeyLogin.apply(this, arguments);
}
function _passkeyLogin() {
_passkeyLogin = _async_to_generator$A(function(passkeyChallengeString, signal) {
var challengeOptions;
return _ts_generator$A(this, function(_state) {
switch(_state.label){
case 0:
challengeOptions = JSON.parse(passkeyChallengeString);
_state.label = 1;
case 1:
_state.trys.push([
1,
3,
,
4
]);
return [
4,
getCredential({
challengeOptions: challengeOptions,
signal: signal
})
];
case 2:
return [
2,
trySafeStringifyExistingCredential.apply(void 0, [
_state.sent()
])
];
case 3:
_state.sent();
return [
2,
undefined
];
case 4:
return [
2
];
}
});
});
return _passkeyLogin.apply(this, arguments);
}
function passkeyRegister(passkeyChallengeString, signal, traits) {
return _passkeyRegister.apply(this, arguments);
}
function _passkeyRegister() {
_passkeyRegister = _async_to_generator$A(function(passkeyChallengeString, signal, traits) {
var _JSON_parse, credentialOptions, displayNameFieldName, displayNameTraitName, displayName;
return _ts_generator$A(this, function(_state) {
switch(_state.label){
case 0:
_JSON_parse = JSON.parse(passkeyChallengeString), credentialOptions = _JSON_parse.credentialOptions, displayNameFieldName = _JSON_parse.displayNameFieldName;
displayNameTraitName = displayNameFieldName.startsWith(traitPrefix) ? displayNameFieldName.slice(traitPrefix.length) : displayNameFieldName;
displayName = typeof (traits === null || traits === void 0 ? void 0 : traits[displayNameTraitName]) === "string" ? traits[displayNameTraitName] : "";
_state.label = 1;
case 1:
_state.trys.push([
1,
3,
,
4
]);
return [
4,
createCredential({
credentialOptions: credentialOptions,
signal: signal,
userName: displayName,
userDisplayName: displayName
})
];
case 2:
return [
2,
trySafeStringifyNewCredential.apply(void 0, [
_state.sent()
])
];
case 3:
_state.sent();
return [
2,
undefined
];
case 4:
return [
2
];
}
});
});
return _passkeyRegister.apply(this, arguments);
}
function passkeySettingsRegister(passkeyChallengeString, signal) {
return _passkeySettingsRegister.apply(this, arguments);
}
function _passkeySettingsRegister() {
_passkeySettingsRegister = _async_to_generator$A(function(passkeyChallengeString, signal) {
var credentialOptions;
return _ts_generator$A(this, function(_state) {
switch(_state.label){
case 0:
credentialOptions = JSON.parse(passkeyChallengeString);
_state.label = 1;
case 1:
_state.trys.push([
1,
3,
,
4
]);
return [
4,
createCredential({
credentialOptions: credentialOptions,
signal: signal,
userName: credentialOptions.publicKey.user.name,
userDisplayName: credentialOptions.publicKey.user.displayName
})
];
case 2:
return [
2,
trySafeStringifyNewCredential.apply(void 0, [
_state.sent()
])
];
case 3:
_state.sent();
return [
2,
undefined
];
case 4:
return [
2
];
}
});
});
return _passkeySettingsRegister.apply(this, arguments);
}
function _type_of$2(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
var hasProperetyOfType = function(obj, propertyName, propertyType) {
return obj !== undefined && propertyName in obj && _type_of$2(obj[propertyName]) === propertyType;
};
/* tslint:disable */ /* eslint-disable */ /**
* Ory APIs
* # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers. ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages: | Language | Download SDK | Documentation | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart | [pub.dev](https://pub.dev/packages/ory_client) | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md) | | .NET | [nuget.org](https://www.nuget.org/packages/Ory.Client/) | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md) | | Elixir | [hex.pm](https://hex.pm/packages/ory_client) | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md) | | Go | [github.com](https://github.com/ory/client-go) | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md) | | Java | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md) | | JavaScript | [npmjs.com](https://www.npmjs.com/package/@ory/client) | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch) | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) | | PHP | [packagist.org](https://packagist.org/packages/ory/client) | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md) | | Python | [pypi.org](https://pypi.org/project/ory-client/) | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md) | | Ruby | [rubygems.org](https://rubygems.org/gems/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md) | | Rust | [crates.io](https://crates.io/crates/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md) |
*
* The version of the OpenAPI document: v1.20.10
* Contact: support@ory.sh
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/ function _array_like_to_array$9(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_without_holes$2(arr) {
if (Array.isArray(arr)) return _array_like_to_array$9(arr);
}
function _assert_this_initialized$1(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function asyncGeneratorStep$z(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator$z(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep$z(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep$z(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _class_call_check$2(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _construct(Parent, args, Class) {
if (_is_native_reflect_construct$1()) {
_construct = Reflect.construct;
} else {
_construct = function construct(Parent, args, Class) {
var a = [
null
];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _set_prototype_of$1(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _defineProperties$1(target, props) {
for(var i = 0; i < props.length; i++){
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class$1(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
return Constructor;
}
function _define_property$z(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _get_prototype_of$1(o) {
_get_prototype_of$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _get_prototype_of$1(o);
}
function _inherits$1(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _set_prototype_of$1(subClass, superClass);
}
function _instanceof$3(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _is_native_function(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _iterable_to_array$2(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread$2() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread$p(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property$z(target, key, source[key]);
});
}
return target;
}
function ownKeys$i(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props$i(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys$i(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _possible_constructor_return$1(self, call) {
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
return call;
}
return _assert_this_initialized$1(self);
}
function _set_prototype_of$1(o, p) {
_set_prototype_of$1 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _set_prototype_of$1(o, p);
}
function _to_consumable_array$2(arr) {
return _array_without_holes$2(arr) || _iterable_to_array$2(arr) || _unsupported_iterable_to_array$9(arr) || _non_iterable_spread$2();
}
function _type_of$1(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array$9(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array$9(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$9(o, minLen);
}
function _wrap_native_super(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrap_native_super = function wrapNativeSuper(Class) {
if (Class === null || !_is_native_function(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _get_prototype_of$1(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _set_prototype_of$1(Wrapper, Class);
};
return _wrap_native_super(Class);
}
function _is_native_reflect_construct$1() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
return true;
} catch (e) {
return false;
}
}
function _create_super$1(Derived) {
var hasNativeReflectConstruct = _is_native_reflect_construct$1();
return function _createSuperInternal() {
var Super = _get_prototype_of$1(Derived), result;
if (hasNativeReflectConstruct) {
var NewTarget = _get_prototype_of$1(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possible_constructor_return$1(this, result);
};
}
function _ts_generator$z(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
var BASE_PATH = "https://playground.projects.oryapis.com".replace(/\/+$/, "");
var Configuration = /*#__PURE__*/ function() {
function Configuration() {
var configuration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
_class_call_check$2(this, Configuration);
_define_property$z(this, "configuration", void 0);
this.configuration = configuration;
}
_create_class$1(Configuration, [
{
key: "config",
set: function set(configuration) {
this.configuration = configuration;
}
},
{
key: "basePath",
get: function get() {
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
}
},
{
key: "fetchApi",
get: function get() {
return this.configuration.fetchApi;
}
},
{
key: "middleware",
get: function get() {
return this.configuration.middleware || [];
}
},
{
key: "queryParamsStringify",
get: function get() {
return this.configuration.queryParamsStringify || querystring;
}
},
{
key: "username",
get: function get() {
return this.configuration.username;
}
},
{
key: "password",
get: function get() {
return this.configuration.password;
}
},
{
key: "apiKey",
get: function get() {
var apiKey = this.configuration.apiKey;
if (apiKey) {
return typeof apiKey === 'function' ? apiKey : function() {
return apiKey;
};
}
return undefined;
}
},
{
key: "accessToken",
get: function get() {
var accessToken = this.configuration.accessToken;
if (accessToken) {
return typeof accessToken === 'function' ? accessToken : /*#__PURE__*/ _async_to_generator$z(function() {
return _ts_generator$z(this, function(_state) {
return [
2,
accessToken
];
});
});
}
return undefined;
}
},
{
key: "headers",
get: function get() {
return this.configuration.headers;
}
},
{
key: "credentials",
get: function get() {
return this.configuration.credentials;
}
}
]);
return Configuration;
}();
var DefaultConfig = new Configuration();
/**
* This is the base class for all generated API classes.
*/ var BaseAPI = /*#__PURE__*/ function() {
function BaseAPI() {
var configuration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : DefaultConfig;
_class_call_check$2(this, BaseAPI);
_define_property$z(this, "configuration", void 0);
_define_property$z(this, "middleware", void 0);
_define_property$z(this, "fetchApi", void 0);
this.configuration = configuration;
var _this = this;
this.fetchApi = function() {
var _ref = _async_to_generator$z(function(url, init) {
var fetchParams, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, middleware, err, response, e, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, middleware1, err, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, middleware2, err;
return _ts_generator$z(this, function(_state) {
switch(_state.label){
case 0:
fetchParams = {
url: url,
init: init
};
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
_state.label = 1;
case 1:
_state.trys.push([
1,
6,
7,
8
]);
_iterator = _this.middleware[Symbol.iterator]();
_state.label = 2;
case 2:
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3,
5
];
middleware = _step.value;
if (!middleware.pre) return [
3,
4
];
return [
4,
middleware.pre(_object_spread$p({
fetch: _this.fetchApi
}, fetchParams))
];
case 3:
fetchParams = _state.sent() || fetchParams;
_state.label = 4;
case 4:
_iteratorNormalCompletion = true;
return [
3,
2
];
case 5:
return [
3,
8
];
case 6:
err = _state.sent();
_didIteratorError = true;
_iteratorError = err;
return [
3,
8
];
case 7:
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
return [
7
];
case 8:
response = undefined;
_state.label = 9;
case 9: