tharos-web-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,307 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ Tharos: () => Tharos
23
+ });
24
+ module.exports = __toCommonJS(index_exports);
25
+
26
+ // src/tharos.ts
27
+ var BasicTharosContext = class {
28
+ ctx;
29
+ constructor(tharosCtx) {
30
+ this.ctx = tharosCtx;
31
+ }
32
+ };
33
+
34
+ // src/auth/client-inputs/client-input.ts
35
+ var JourneyStepType = class extends BasicTharosContext {
36
+ clientInput;
37
+ static stepsMap = /* @__PURE__ */ new Map();
38
+ constructor(clientInput, ctx) {
39
+ super(ctx);
40
+ this.clientInput = clientInput;
41
+ }
42
+ getID() {
43
+ return this.clientInput.id;
44
+ }
45
+ getStepType() {
46
+ return this.clientInput.step_type;
47
+ }
48
+ getType() {
49
+ return this.clientInput.type;
50
+ }
51
+ setInput(data) {
52
+ this.clientInput.input = data;
53
+ }
54
+ getOutput() {
55
+ return this.clientInput.output;
56
+ }
57
+ getPayload() {
58
+ return this.clientInput;
59
+ }
60
+ };
61
+
62
+ // src/auth/journey.ts
63
+ var JourneyResponse = class extends BasicTharosContext {
64
+ journeyResponsePayload;
65
+ clientInputs;
66
+ constructor(journeyResponsePayload, ctx) {
67
+ super(ctx);
68
+ this.journeyResponsePayload = journeyResponsePayload;
69
+ this.clientInputs = this.journeyResponsePayload.client_inputs.map(
70
+ (el) => new (JourneyStepType.stepsMap.get(el.step_type.toString()))(el, ctx)
71
+ );
72
+ }
73
+ getJourneyToken() {
74
+ return this.journeyResponsePayload.journey_token;
75
+ }
76
+ getClientInputs(stepType) {
77
+ return this.clientInputs.filter((el) => el.getStepType() == stepType);
78
+ }
79
+ getAllClientInputs() {
80
+ return this.clientInputs;
81
+ }
82
+ };
83
+ var JourneyRequestProcess = class extends BasicTharosContext {
84
+ async start(payload, executor, options) {
85
+ let journeyResponse = await this.ctx.api.post(
86
+ `/realms/${this.ctx.config.realm}/journeys/auth`,
87
+ payload,
88
+ {
89
+ headers: options == null ? void 0 : options.headers
90
+ }
91
+ );
92
+ while (journeyResponse.hasOwnProperty("journey_token")) {
93
+ journeyResponse = journeyResponse;
94
+ let process = new JourneyResponse(journeyResponse, this.ctx);
95
+ await executor.onNewStep(process);
96
+ journeyResponse = await this.ctx.api.post(
97
+ `/realms/${this.ctx.config.realm}/journeys/auth`,
98
+ {
99
+ journey_token: journeyResponse.journey_token,
100
+ client_inputs: process.getAllClientInputs().map((el) => el.getPayload())
101
+ }
102
+ );
103
+ }
104
+ if (journeyResponse.hasOwnProperty("session_id")) {
105
+ await this.ctx.setAuthenticatedUser();
106
+ executor.onSuccess(journeyResponse);
107
+ } else {
108
+ executor.onFailure(journeyResponse);
109
+ }
110
+ }
111
+ };
112
+
113
+ // src/auth/user.ts
114
+ var User = class extends BasicTharosContext {
115
+ tokens = null;
116
+ getUserTokens() {
117
+ return this.tokens;
118
+ }
119
+ async sessionInfo() {
120
+ return await this.ctx.api.post(`/realms/${this.ctx.config.realm}/session/info`);
121
+ }
122
+ async validateSession(refresh = false) {
123
+ return await this.ctx.api.post(
124
+ `/realms/${this.ctx.config.realm}/session/validate?refresh=${refresh}`
125
+ );
126
+ }
127
+ };
128
+
129
+ // src/http.ts
130
+ var HttpError = class extends Error {
131
+ code;
132
+ details;
133
+ constructor({ code, message, details }) {
134
+ super(message);
135
+ this.code = code;
136
+ this.details = details;
137
+ }
138
+ };
139
+ var ApiClient = class _ApiClient {
140
+ baseUrl;
141
+ defaultHeaders;
142
+ requestInterceptors;
143
+ responseInterceptors;
144
+ constructor(baseUrl, defaultHeaders = {}) {
145
+ this.baseUrl = baseUrl;
146
+ this.defaultHeaders = { ...defaultHeaders };
147
+ this.requestInterceptors = [];
148
+ this.responseInterceptors = [];
149
+ }
150
+ withPath(subPath) {
151
+ const child = new _ApiClient(this.baseUrl + subPath, this.defaultHeaders);
152
+ child.requestInterceptors = [...this.requestInterceptors];
153
+ child.responseInterceptors = [...this.responseInterceptors];
154
+ return child;
155
+ }
156
+ setDefaultHeader(key, value) {
157
+ this.defaultHeaders[key] = value;
158
+ }
159
+ addRequestInterceptor(interceptor) {
160
+ this.requestInterceptors.push(interceptor);
161
+ }
162
+ addResponseInterceptor(interceptor) {
163
+ this.responseInterceptors.push(interceptor);
164
+ }
165
+ async fetch(path, options = {}) {
166
+ var _a;
167
+ if (path == "/") {
168
+ path = "";
169
+ }
170
+ let url = options.overrideUrl ? path : `${this.baseUrl}${path}`;
171
+ let init = {
172
+ headers: { ...this.defaultHeaders, ...options.headers || {} },
173
+ ...options,
174
+ credentials: "include"
175
+ };
176
+ for (const interceptor of this.requestInterceptors) {
177
+ [url, init] = await interceptor(url, init);
178
+ }
179
+ let response = await fetch(url, init);
180
+ for (const interceptor of this.responseInterceptors) {
181
+ response = await interceptor(response);
182
+ }
183
+ if (!response.ok) {
184
+ if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
185
+ throw new HttpError(await response.json());
186
+ } else {
187
+ throw new Error(`Error ${response.status}: ${response.statusText}`);
188
+ }
189
+ }
190
+ return response.json();
191
+ }
192
+ get(path, options) {
193
+ return this.fetch(path, { ...options, method: "GET" });
194
+ }
195
+ post(path, body, options) {
196
+ return this.fetch(path, {
197
+ ...options,
198
+ method: "POST",
199
+ body: JSON.stringify(body)
200
+ });
201
+ }
202
+ put(path, body, options) {
203
+ return this.fetch(path, {
204
+ ...options,
205
+ method: "PUT",
206
+ body: JSON.stringify(body)
207
+ });
208
+ }
209
+ delete(path, options) {
210
+ return this.fetch(path, { ...options, method: "DELETE" });
211
+ }
212
+ };
213
+
214
+ // src/config.ts
215
+ var TharosConfig = class _TharosConfig {
216
+ tharosAuthUrl;
217
+ realm;
218
+ oidc;
219
+ oauth;
220
+ constructor({ tharosAuthUrl, realm, oidc, oauth }) {
221
+ this.tharosAuthUrl = tharosAuthUrl;
222
+ this.realm = realm;
223
+ this.oidc = oidc;
224
+ this.oauth = oauth;
225
+ }
226
+ static async newInstance(config) {
227
+ const api = new ApiClient("");
228
+ const oidc = null;
229
+ return new _TharosConfig({ ...config, oidc });
230
+ }
231
+ };
232
+
233
+ // src/auth/client-inputs/user-name.ts
234
+ var UserNameInput = class extends JourneyStepType {
235
+ setInput(userName) {
236
+ super.setInput(userName);
237
+ }
238
+ };
239
+ JourneyStepType.stepsMap.set("UserName" /* USER_NAME */, UserNameInput);
240
+
241
+ // src/auth/client-inputs/metadata.ts
242
+ var MeatadataInput = class extends JourneyStepType {
243
+ setInput() {
244
+ }
245
+ };
246
+ JourneyStepType.stepsMap.set("Metadata" /* METADATA */, MeatadataInput);
247
+
248
+ // src/index.ts
249
+ var Tharos = class _Tharos {
250
+ config;
251
+ api;
252
+ journey;
253
+ defaultJourneyExecutor;
254
+ user = null;
255
+ constructor({ config, defaultJourneyExecutor }) {
256
+ var _a;
257
+ this.config = config;
258
+ this.api = new ApiClient(this.config.tharosAuthUrl);
259
+ this.journey = new JourneyRequestProcess(this);
260
+ this.defaultJourneyExecutor = defaultJourneyExecutor;
261
+ const currentURL = new URL(window.location.href).origin + new URL(window.location.href).pathname;
262
+ if (currentURL === ((_a = this.config.oauth) == null ? void 0 : _a.redirectUri)) {
263
+ }
264
+ }
265
+ getDefaultJourneyExecutor() {
266
+ return this.defaultJourneyExecutor;
267
+ }
268
+ getCurrentUser() {
269
+ return this.user;
270
+ }
271
+ async setAuthenticatedUser() {
272
+ const user = new User(this);
273
+ await user.sessionInfo();
274
+ this.user = user;
275
+ }
276
+ getAuthorizeUrl(config) {
277
+ if (!config) {
278
+ if (!this.config.oauth) {
279
+ throw new Error("oauth not configured");
280
+ }
281
+ config = this.config.oauth;
282
+ }
283
+ return `${this.config.tharosAuthUrl}/realms/${this.config.realm}/oauth2/auth?client_id=${config.clientId}&scope=${config.scope}&response_type=code&redirect_uri=${config.redirectUri}&acr_values=all1`;
284
+ }
285
+ async exchangeTokens() {
286
+ var _a, _b;
287
+ const url = new URL(window.location.href);
288
+ this.api.post(
289
+ `/realms/${this.config.realm}/oauth2/token`,
290
+ {
291
+ grant_type: "authorization_code",
292
+ code: url.searchParams.get("code"),
293
+ client_id: (_a = this.config.oauth) == null ? void 0 : _a.clientId,
294
+ scope: (_b = this.config.oauth) == null ? void 0 : _b.scope
295
+ },
296
+ { headers: { "Content-Type": "application/x-www-form-urlencoded" } }
297
+ );
298
+ }
299
+ static async newInstance(baseConfig) {
300
+ return new _Tharos({ config: await TharosConfig.newInstance(baseConfig) });
301
+ }
302
+ };
303
+ // Annotate the CommonJS export names for ESM import in node:
304
+ 0 && (module.exports = {
305
+ Tharos
306
+ });
307
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/tharos.ts","../src/auth/client-inputs/client-input.ts","../src/auth/journey.ts","../src/auth/user.ts","../src/http.ts","../src/config.ts","../src/auth/client-inputs/user-name.ts","../src/auth/client-inputs/metadata.ts"],"sourcesContent":["import { JourneyRequestProcess, type JourneyExecutor } from './auth/journey.js';\nimport { User } from './auth/user.js';\nimport { TharosConfig } from './config.js';\nimport { ApiClient } from './http.js';\nimport type { Config, OAuth } from './types/config.js';\nimport './auth/client-inputs/index.js';\n\nexport class Tharos {\n public readonly config: TharosConfig;\n public readonly api: ApiClient;\n public readonly journey: JourneyRequestProcess;\n private defaultJourneyExecutor: JourneyExecutor | undefined;\n private user: User | null = null;\n\n constructor({ config, defaultJourneyExecutor }: { config: TharosConfig; defaultJourneyExecutor?: JourneyExecutor }) {\n this.config = config;\n this.api = new ApiClient(this.config.tharosAuthUrl);\n this.journey = new JourneyRequestProcess(this);\n this.defaultJourneyExecutor = defaultJourneyExecutor;\n\n const currentURL = new URL(window.location.href).origin + new URL(window.location.href).pathname;\n\n if (currentURL === this.config.oauth?.redirectUri) {\n }\n }\n\n public getDefaultJourneyExecutor() {\n return this.defaultJourneyExecutor;\n }\n\n public getCurrentUser() {\n return this.user;\n }\n\n public async setAuthenticatedUser() {\n const user = new User(this);\n\n await user.sessionInfo();\n this.user = user;\n }\n\n public getAuthorizeUrl(config?: OAuth): string {\n if (!config) {\n if (!this.config.oauth) {\n throw new Error('oauth not configured');\n }\n\n config = this.config.oauth;\n }\n\n return `${this.config.tharosAuthUrl}/realms/${this.config.realm}/oauth2/auth?client_id=${config.clientId}&scope=${config.scope}&response_type=code&redirect_uri=${config.redirectUri}&acr_values=all1`;\n }\n\n public async exchangeTokens() {\n const url = new URL(window.location.href);\n this.api.post(\n `/realms/${this.config.realm}/oauth2/token`,\n {\n grant_type: 'authorization_code',\n code: url.searchParams.get('code'),\n client_id: this.config.oauth?.clientId,\n scope: this.config.oauth?.scope,\n },\n { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }\n );\n }\n\n public static async newInstance(baseConfig: Config) {\n return new Tharos({ config: await TharosConfig.newInstance(baseConfig) });\n }\n}\n","import type { JourneyRequestProcess } from './auth/journey.js';\nimport type { User } from './auth/user.js';\nimport type { TharosConfig } from './config.js';\nimport type { ApiClient } from './http.js';\n\nexport interface TharosImpl {\n config: TharosConfig;\n api: ApiClient;\n journey: JourneyRequestProcess;\n getCurrentUser(): User | null;\n setAuthenticatedUser(): Promise<void>;\n}\n\nexport class BasicTharosContext {\n protected ctx: TharosImpl;\n\n constructor(tharosCtx: TharosImpl) {\n this.ctx = tharosCtx;\n }\n}\n","import { BasicTharosContext, type TharosImpl } from '../../tharos.js';\nimport type { ClientInput } from '../../types/journey.js';\n\nexport class JourneyStepType extends BasicTharosContext {\n private clientInput: ClientInput;\n public static readonly stepsMap: Map<string, typeof JourneyStepType> = new Map();\n\n constructor(clientInput: ClientInput, ctx: TharosImpl) {\n super(ctx);\n\n this.clientInput = clientInput;\n }\n\n public getID() {\n return this.clientInput.id;\n }\n\n public getStepType() {\n return this.clientInput.step_type;\n }\n\n public getType() {\n return this.clientInput.type;\n }\n\n public setInput(data: any) {\n this.clientInput.input = data;\n }\n\n public getOutput() {\n return this.clientInput.output;\n }\n\n public getPayload() {\n return this.clientInput;\n }\n}\n","import { BasicTharosContext, type TharosImpl } from '../tharos.js';\nimport type {\n ClientInput,\n JourneyFailure,\n JourneyRequest,\n JourneyResponsePayload,\n JourneySuccess,\n StepType,\n} from '../types/journey.js';\nimport { JourneyStepType } from './client-inputs/client-input.js';\n\nexport class JourneyResponse extends BasicTharosContext {\n private journeyResponsePayload: JourneyResponsePayload;\n private clientInputs: JourneyStepType[];\n\n constructor(journeyResponsePayload: JourneyResponsePayload, ctx: TharosImpl) {\n super(ctx);\n\n this.journeyResponsePayload = journeyResponsePayload;\n this.clientInputs = this.journeyResponsePayload.client_inputs.map(\n (el) => new (JourneyStepType.stepsMap.get(el.step_type.toString())!)(el, ctx)\n );\n }\n\n public getJourneyToken() {\n return this.journeyResponsePayload.journey_token;\n }\n\n public getClientInputs<T extends JourneyStepType>(stepType: StepType): T[] {\n return this.clientInputs.filter((el) => el.getStepType() == stepType) as T[];\n }\n\n public getAllClientInputs() {\n return this.clientInputs;\n }\n}\n\nexport class JourneyRequestProcess extends BasicTharosContext {\n public async start(\n payload: { journey_id: string } | { resume_id: string },\n executor: JourneyExecutor,\n options?: { headers: Map<string, string> }\n ) {\n let journeyResponse = await this.ctx.api.post<JourneyResponsePayload | JourneyFailure | JourneySuccess>(\n `/realms/${this.ctx.config.realm}/journeys/auth`,\n payload,\n {\n headers: options?.headers as any,\n }\n );\n\n while (journeyResponse.hasOwnProperty('journey_token')) {\n journeyResponse = journeyResponse as JourneyResponsePayload;\n let process = new JourneyResponse(journeyResponse, this.ctx);\n await executor.onNewStep(process);\n\n journeyResponse = await this.ctx.api.post<JourneyResponsePayload | JourneyFailure | JourneySuccess>(\n `/realms/${this.ctx.config.realm}/journeys/auth`,\n {\n journey_token: journeyResponse.journey_token,\n client_inputs: process.getAllClientInputs().map((el) => el.getPayload()),\n }\n );\n }\n\n if (journeyResponse.hasOwnProperty('session_id')) {\n await this.ctx.setAuthenticatedUser();\n executor.onSuccess(journeyResponse as JourneySuccess);\n } else {\n executor.onFailure(journeyResponse as JourneyFailure);\n }\n }\n}\n\nexport interface JourneyExecutor {\n onSuccess: (journeySuccess: JourneySuccess) => Promise<void>;\n onFailure: (journeyFailure: JourneyFailure) => Promise<void>;\n onNewStep: (journeyResponse: JourneyResponse) => Promise<void>;\n}\n","import { BasicTharosContext } from '../tharos.js';\nimport type { UserTokens } from './tokens.js';\n\nexport class User extends BasicTharosContext {\n private tokens: UserTokens | null = null;\n\n public getUserTokens() {\n return this.tokens;\n }\n\n public async sessionInfo() {\n return await this.ctx.api.post<Record<string, string>>(`/realms/${this.ctx.config.realm}/session/info`);\n }\n\n public async validateSession(refresh: boolean = false) {\n return await this.ctx.api.post<Record<string, string>>(\n `/realms/${this.ctx.config.realm}/session/validate?refresh=${refresh}`\n );\n }\n}\n","type RequestInterceptor = (url: string, request: RequestInit) => Promise<[string, RequestInit]> | [string, RequestInit];\n\ntype ResponseInterceptor = (response: Response) => Promise<Response> | Response;\n\nexport class HttpError extends Error {\n code: number;\n details: any;\n\n constructor({ code, message, details }: { code: number; message: string; details: any }) {\n super(message);\n\n this.code = code;\n this.details = details;\n }\n}\n\nexport class ApiClient {\n private baseUrl: string;\n private defaultHeaders: Record<string, string>;\n private requestInterceptors: RequestInterceptor[];\n private responseInterceptors: ResponseInterceptor[];\n\n constructor(baseUrl: string, defaultHeaders: Record<string, string> = {}) {\n this.baseUrl = baseUrl;\n this.defaultHeaders = { ...defaultHeaders };\n this.requestInterceptors = [];\n this.responseInterceptors = [];\n }\n\n withPath(subPath: string): ApiClient {\n const child = new ApiClient(this.baseUrl + subPath, this.defaultHeaders);\n\n child.requestInterceptors = [...this.requestInterceptors];\n child.responseInterceptors = [...this.responseInterceptors];\n\n return child;\n }\n\n setDefaultHeader(key: string, value: string) {\n this.defaultHeaders[key] = value;\n }\n\n addRequestInterceptor(interceptor: RequestInterceptor) {\n this.requestInterceptors.push(interceptor);\n }\n\n addResponseInterceptor(interceptor: ResponseInterceptor) {\n this.responseInterceptors.push(interceptor);\n }\n\n async fetch<T>(path: string, options: RequestInit & { overrideUrl?: boolean } = {}): Promise<T> {\n if (path == '/') {\n path = '';\n }\n\n let url = options.overrideUrl ? path : `${this.baseUrl}${path}`;\n let init: RequestInit = {\n headers: { ...this.defaultHeaders, ...(options.headers || {}) },\n ...options,\n credentials: 'include',\n };\n\n // Interceptores de request\n for (const interceptor of this.requestInterceptors) {\n [url, init] = await interceptor(url, init);\n }\n\n // Ejecutar fetch\n let response = await fetch(url, init);\n\n // Interceptores de response\n for (const interceptor of this.responseInterceptors) {\n response = await interceptor(response);\n }\n\n if (!response.ok) {\n if (response.headers.get('content-type')?.includes('application/json')) {\n throw new HttpError(await response.json());\n } else {\n throw new Error(`Error ${response.status}: ${response.statusText}`);\n }\n }\n\n return response.json() as Promise<T>;\n }\n\n get<T>(path: string, options?: RequestInit & { overrideUrl?: boolean }) {\n return this.fetch<T>(path, { ...options, method: 'GET' });\n }\n post<T>(path: string, body?: any, options?: RequestInit) {\n return this.fetch<T>(path, {\n ...options,\n method: 'POST',\n body: JSON.stringify(body),\n });\n }\n put<T>(path: string, body?: any, options?: RequestInit) {\n return this.fetch<T>(path, {\n ...options,\n method: 'PUT',\n body: JSON.stringify(body),\n });\n }\n delete<T>(path: string, options?: RequestInit) {\n return this.fetch<T>(path, { ...options, method: 'DELETE' });\n }\n}\n","import { ApiClient } from './http.js';\nimport type { Config, OAuth } from './types/config.js';\n\nexport interface OpenIdConfiguration {\n issuer: string;\n\n authorization_endpoint: string;\n token_endpoint: string;\n userinfo_endpoint: string;\n jwks_uri: string;\n registration_endpoint?: string;\n revocation_endpoint?: string;\n introspection_endpoint?: string;\n device_authorization_endpoint?: string;\n pushed_authorization_request_endpoint?: string;\n\n scopes_supported?: string[];\n response_types_supported: string[];\n response_modes_supported?: string[];\n grant_types_supported?: string[];\n\n subject_types_supported: ('public' | 'pairwise')[];\n id_token_signing_alg_values_supported: string[];\n id_token_encryption_alg_values_supported?: string[];\n id_token_encryption_enc_values_supported?: string[];\n\n userinfo_signing_alg_values_supported?: string[];\n userinfo_encryption_alg_values_supported?: string[];\n userinfo_encryption_enc_values_supported?: string[];\n\n request_object_signing_alg_values_supported?: string[];\n request_object_encryption_alg_values_supported?: string[];\n request_object_encryption_enc_values_supported?: string[];\n\n token_endpoint_auth_methods_supported?: string[];\n token_endpoint_auth_signing_alg_values_supported?: string[];\n\n introspection_endpoint_auth_methods_supported?: string[];\n introspection_endpoint_auth_signing_alg_values_supported?: string[];\n\n revocation_endpoint_auth_methods_supported?: string[];\n revocation_endpoint_auth_signing_alg_values_supported?: string[];\n\n claims_supported?: string[];\n claims_locales_supported?: string[];\n ui_locales_supported?: string[];\n\n claims_parameter_supported?: boolean;\n request_parameter_supported?: boolean;\n request_uri_parameter_supported?: boolean;\n require_request_uri_registration?: boolean;\n\n frontchannel_logout_supported?: boolean;\n frontchannel_logout_session_supported?: boolean;\n backchannel_logout_supported?: boolean;\n backchannel_logout_session_supported?: boolean;\n\n code_challenge_methods_supported?: ('plain' | 'S256')[];\n\n tls_client_certificate_bound_access_tokens?: boolean;\n authorization_response_iss_parameter_supported?: boolean;\n\n [key: string]: unknown;\n}\n\nexport class TharosConfig {\n public readonly tharosAuthUrl: string;\n public readonly realm: string;\n public readonly oidc: OpenIdConfiguration;\n public readonly oauth: OAuth | undefined;\n\n constructor({ tharosAuthUrl, realm, oidc, oauth }: Config & { oidc: OpenIdConfiguration }) {\n this.tharosAuthUrl = tharosAuthUrl;\n this.realm = realm;\n this.oidc = oidc;\n this.oauth = oauth;\n }\n\n public static async newInstance(config: Config) {\n const api = new ApiClient('');\n\n const oidc = null as any;\n\n return new TharosConfig({ ...config, oidc });\n }\n}\n","import { StepType } from '../../types/journey.js';\nimport { JourneyStepType } from './client-input.js';\n\nexport class UserNameInput extends JourneyStepType {\n public setInput(userName: string) {\n super.setInput(userName);\n }\n}\n\nJourneyStepType.stepsMap.set(StepType.USER_NAME, UserNameInput);\n","import { StepType } from '../../types/journey.js';\nimport { JourneyStepType } from './client-input.js';\n\nexport class MeatadataInput extends JourneyStepType {\n public setInput() {}\n}\n\nJourneyStepType.stepsMap.set(StepType.METADATA, MeatadataInput);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,IAAM,qBAAN,MAAyB;AAAA,EACpB;AAAA,EAEV,YAAY,WAAuB;AACjC,SAAK,MAAM;AAAA,EACb;AACF;;;AChBO,IAAM,kBAAN,cAA8B,mBAAmB;AAAA,EAC9C;AAAA,EACR,OAAuB,WAAgD,oBAAI,IAAI;AAAA,EAE/E,YAAY,aAA0B,KAAiB;AACrD,UAAM,GAAG;AAET,SAAK,cAAc;AAAA,EACrB;AAAA,EAEO,QAAQ;AACb,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,UAAU;AACf,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,SAAS,MAAW;AACzB,SAAK,YAAY,QAAQ;AAAA,EAC3B;AAAA,EAEO,YAAY;AACjB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;
4
+ access_token?: string;
5
+ id_token?: string;
6
+ refresh_token?: string;
7
+ }
8
+
9
+ declare class UserTokens extends BasicTharosContext {
10
+ private tokens;
11
+ constructor(tokens: Tokens, tharosCtx: TharosImpl);
12
+ getSessionID(): string;
13
+ userInfo(): Promise<Map<string, any>>;
14
+ getAccessToken(): string;
15
+ /**
16
+ * Get claims for the current access token, if its a JWT extracts claims from encoded payload, otherwhise makes a call to /userinfo endpoint.
17
+ */
18
+ getAccessTokenClaims(): Promise<Map<string, any>>;
19
+ private getClaimsFromJWT;
20
+ getIDToken(): string;
21
+ getRefreshToken(): string;
22
+ refreshTokens(): Promise<boolean>;
23
+ }
24
+
25
+ declare class User extends BasicTharosContext {
26
+ private tokens;
27
+ getUserTokens(): UserTokens;
28
+ sessionInfo(): Promise<Record<string, string>>;
29
+ validateSession(refresh?: boolean): Promise<Record<string, string>>;
30
+ }
31
+
32
+ interface OAuth {
33
+ clientId: string;
34
+ scope: string;
35
+ redirectUri?: string;
36
+ }
37
+ interface Config {
38
+ tharosAuthUrl: string;
39
+ realm: string;
40
+ oauth: OAuth;
41
+ }
42
+
43
+ interface OpenIdConfiguration {
44
+ issuer: string;
45
+ authorization_endpoint: string;
46
+ token_endpoint: string;
47
+ userinfo_endpoint: string;
48
+ jwks_uri: string;
49
+ registration_endpoint?: string;
50
+ revocation_endpoint?: string;
51
+ introspection_endpoint?: string;
52
+ device_authorization_endpoint?: string;
53
+ pushed_authorization_request_endpoint?: string;
54
+ scopes_supported?: string[];
55
+ response_types_supported: string[];
56
+ response_modes_supported?: string[];
57
+ grant_types_supported?: string[];
58
+ subject_types_supported: ('public' | 'pairwise')[];
59
+ id_token_signing_alg_values_supported: string[];
60
+ id_token_encryption_alg_values_supported?: string[];
61
+ id_token_encryption_enc_values_supported?: string[];
62
+ userinfo_signing_alg_values_supported?: string[];
63
+ userinfo_encryption_alg_values_supported?: string[];
64
+ userinfo_encryption_enc_values_supported?: string[];
65
+ request_object_signing_alg_values_supported?: string[];
66
+ request_object_encryption_alg_values_supported?: string[];
67
+ request_object_encryption_enc_values_supported?: string[];
68
+ token_endpoint_auth_methods_supported?: string[];
69
+ token_endpoint_auth_signing_alg_values_supported?: string[];
70
+ introspection_endpoint_auth_methods_supported?: string[];
71
+ introspection_endpoint_auth_signing_alg_values_supported?: string[];
72
+ revocation_endpoint_auth_methods_supported?: string[];
73
+ revocation_endpoint_auth_signing_alg_values_supported?: string[];
74
+ claims_supported?: string[];
75
+ claims_locales_supported?: string[];
76
+ ui_locales_supported?: string[];
77
+ claims_parameter_supported?: boolean;
78
+ request_parameter_supported?: boolean;
79
+ request_uri_parameter_supported?: boolean;
80
+ require_request_uri_registration?: boolean;
81
+ frontchannel_logout_supported?: boolean;
82
+ frontchannel_logout_session_supported?: boolean;
83
+ backchannel_logout_supported?: boolean;
84
+ backchannel_logout_session_supported?: boolean;
85
+ code_challenge_methods_supported?: ('plain' | 'S256')[];
86
+ tls_client_certificate_bound_access_tokens?: boolean;
87
+ authorization_response_iss_parameter_supported?: boolean;
88
+ [key: string]: unknown;
89
+ }
90
+ declare class TharosConfig {
91
+ readonly tharosAuthUrl: string;
92
+ readonly realm: string;
93
+ readonly oidc: OpenIdConfiguration;
94
+ readonly oauth: OAuth | undefined;
95
+ constructor({ tharosAuthUrl, realm, oidc, oauth }: Config & {
96
+ oidc: OpenIdConfiguration;
97
+ });
98
+ static newInstance(config: Config): Promise<TharosConfig>;
99
+ }
100
+
101
+ type RequestInterceptor = (url: string, request: RequestInit) => Promise<[string, RequestInit]> | [string, RequestInit];
102
+ type ResponseInterceptor = (response: Response) => Promise<Response> | Response;
103
+ declare class ApiClient {
104
+ private baseUrl;
105
+ private defaultHeaders;
106
+ private requestInterceptors;
107
+ private responseInterceptors;
108
+ constructor(baseUrl: string, defaultHeaders?: Record<string, string>);
109
+ withPath(subPath: string): ApiClient;
110
+ setDefaultHeader(key: string, value: string): void;
111
+ addRequestInterceptor(interceptor: RequestInterceptor): void;
112
+ addResponseInterceptor(interceptor: ResponseInterceptor): void;
113
+ fetch<T>(path: string, options?: RequestInit & {
114
+ overrideUrl?: boolean;
115
+ }): Promise<T>;
116
+ get<T>(path: string, options?: RequestInit & {
117
+ overrideUrl?: boolean;
118
+ }): Promise<T>;
119
+ post<T>(path: string, body?: any, options?: RequestInit): Promise<T>;
120
+ put<T>(path: string, body?: any, options?: RequestInit): Promise<T>;
121
+ delete<T>(path: string, options?: RequestInit): Promise<T>;
122
+ }
123
+
124
+ interface TharosImpl {
125
+ config: TharosConfig;
126
+ api: ApiClient;
127
+ journey: JourneyRequestProcess;
128
+ getCurrentUser(): User | null;
129
+ setAuthenticatedUser(): Promise<void>;
130
+ }
131
+ declare class BasicTharosContext {
132
+ protected ctx: TharosImpl;
133
+ constructor(tharosCtx: TharosImpl);
134
+ }
135
+
136
+ declare enum StepType {
137
+ USER_NAME = "UserName",
138
+ PASSWORD = "Password",
139
+ METADATA = "Metadata"
140
+ }
141
+ interface ClientInput {
142
+ id: string;
143
+ step_type: StepType;
144
+ type: string;
145
+ send_back: boolean;
146
+ output: Map<string, any>;
147
+ input: any;
148
+ }
149
+ interface JourneyResponsePayload {
150
+ journey_token: string;
151
+ client_inputs: ClientInput[];
152
+ client_error?: {
153
+ error: string;
154
+ details?: Map<string, any>;
155
+ };
156
+ }
157
+ interface JourneySuccess {
158
+ session_id?: string;
159
+ success_url?: string;
160
+ }
161
+ interface JourneyFailure {
162
+ error: string;
163
+ failure_url?: string;
164
+ }
165
+
166
+ declare class JourneyStepType extends BasicTharosContext {
167
+ private clientInput;
168
+ static readonly stepsMap: Map<string, typeof JourneyStepType>;
169
+ constructor(clientInput: ClientInput, ctx: TharosImpl);
170
+ getID(): string;
171
+ getStepType(): StepType;
172
+ getType(): string;
173
+ setInput(data: any): void;
174
+ getOutput(): Map<string, any>;
175
+ getPayload(): ClientInput;
176
+ }
177
+
178
+ declare class JourneyResponse extends BasicTharosContext {
179
+ private journeyResponsePayload;
180
+ private clientInputs;
181
+ constructor(journeyResponsePayload: JourneyResponsePayload, ctx: TharosImpl);
182
+ getJourneyToken(): string;
183
+ getClientInputs<T extends JourneyStepType>(stepType: StepType): T[];
184
+ getAllClientInputs(): JourneyStepType[];
185
+ }
186
+ declare class JourneyRequestProcess extends BasicTharosContext {
187
+ start(payload: {
188
+ journey_id: string;
189
+ } | {
190
+ resume_id: string;
191
+ }, executor: JourneyExecutor, options?: {
192
+ headers: Map<string, string>;
193
+ }): Promise<void>;
194
+ }
195
+ interface JourneyExecutor {
196
+ onSuccess: (journeySuccess: JourneySuccess) => Promise<void>;
197
+ onFailure: (journeyFailure: JourneyFailure) => Promise<void>;
198
+ onNewStep: (journeyResponse: JourneyResponse) => Promise<void>;
199
+ }
200
+
201
+ declare class Tharos {
202
+ readonly config: TharosConfig;
203
+ readonly api: ApiClient;
204
+ readonly journey: JourneyRequestProcess;
205
+ private defaultJourneyExecutor;
206
+ private user;
207
+ constructor({ config, defaultJourneyExecutor }: {
208
+ config: TharosConfig;
209
+ defaultJourneyExecutor?: JourneyExecutor;
210
+ });
211
+ getDefaultJourneyExecutor(): JourneyExecutor;
212
+ getCurrentUser(): User;
213
+ setAuthenticatedUser(): Promise<void>;
214
+ getAuthorizeUrl(config?: OAuth): string;
215
+ exchangeTokens(): Promise<void>;
216
+ static newInstance(baseConfig: Config): Promise<Tharos>;
217
+ }
218
+
219
+ export { Tharos };
@@ -0,0 +1,219 @@
1
+ interface Tokens {
2
+ iss?: string;
3
+ session_id?: string;
4
+ access_token?: string;
5
+ id_token?: string;
6
+ refresh_token?: string;
7
+ }
8
+
9
+ declare class UserTokens extends BasicTharosContext {
10
+ private tokens;
11
+ constructor(tokens: Tokens, tharosCtx: TharosImpl);
12
+ getSessionID(): string;
13
+ userInfo(): Promise<Map<string, any>>;
14
+ getAccessToken(): string;
15
+ /**
16
+ * Get claims for the current access token, if its a JWT extracts claims from encoded payload, otherwhise makes a call to /userinfo endpoint.
17
+ */
18
+ getAccessTokenClaims(): Promise<Map<string, any>>;
19
+ private getClaimsFromJWT;
20
+ getIDToken(): string;
21
+ getRefreshToken(): string;
22
+ refreshTokens(): Promise<boolean>;
23
+ }
24
+
25
+ declare class User extends BasicTharosContext {
26
+ private tokens;
27
+ getUserTokens(): UserTokens;
28
+ sessionInfo(): Promise<Record<string, string>>;
29
+ validateSession(refresh?: boolean): Promise<Record<string, string>>;
30
+ }
31
+
32
+ interface OAuth {
33
+ clientId: string;
34
+ scope: string;
35
+ redirectUri?: string;
36
+ }
37
+ interface Config {
38
+ tharosAuthUrl: string;
39
+ realm: string;
40
+ oauth: OAuth;
41
+ }
42
+
43
+ interface OpenIdConfiguration {
44
+ issuer: string;
45
+ authorization_endpoint: string;
46
+ token_endpoint: string;
47
+ userinfo_endpoint: string;
48
+ jwks_uri: string;
49
+ registration_endpoint?: string;
50
+ revocation_endpoint?: string;
51
+ introspection_endpoint?: string;
52
+ device_authorization_endpoint?: string;
53
+ pushed_authorization_request_endpoint?: string;
54
+ scopes_supported?: string[];
55
+ response_types_supported: string[];
56
+ response_modes_supported?: string[];
57
+ grant_types_supported?: string[];
58
+ subject_types_supported: ('public' | 'pairwise')[];
59
+ id_token_signing_alg_values_supported: string[];
60
+ id_token_encryption_alg_values_supported?: string[];
61
+ id_token_encryption_enc_values_supported?: string[];
62
+ userinfo_signing_alg_values_supported?: string[];
63
+ userinfo_encryption_alg_values_supported?: string[];
64
+ userinfo_encryption_enc_values_supported?: string[];
65
+ request_object_signing_alg_values_supported?: string[];
66
+ request_object_encryption_alg_values_supported?: string[];
67
+ request_object_encryption_enc_values_supported?: string[];
68
+ token_endpoint_auth_methods_supported?: string[];
69
+ token_endpoint_auth_signing_alg_values_supported?: string[];
70
+ introspection_endpoint_auth_methods_supported?: string[];
71
+ introspection_endpoint_auth_signing_alg_values_supported?: string[];
72
+ revocation_endpoint_auth_methods_supported?: string[];
73
+ revocation_endpoint_auth_signing_alg_values_supported?: string[];
74
+ claims_supported?: string[];
75
+ claims_locales_supported?: string[];
76
+ ui_locales_supported?: string[];
77
+ claims_parameter_supported?: boolean;
78
+ request_parameter_supported?: boolean;
79
+ request_uri_parameter_supported?: boolean;
80
+ require_request_uri_registration?: boolean;
81
+ frontchannel_logout_supported?: boolean;
82
+ frontchannel_logout_session_supported?: boolean;
83
+ backchannel_logout_supported?: boolean;
84
+ backchannel_logout_session_supported?: boolean;
85
+ code_challenge_methods_supported?: ('plain' | 'S256')[];
86
+ tls_client_certificate_bound_access_tokens?: boolean;
87
+ authorization_response_iss_parameter_supported?: boolean;
88
+ [key: string]: unknown;
89
+ }
90
+ declare class TharosConfig {
91
+ readonly tharosAuthUrl: string;
92
+ readonly realm: string;
93
+ readonly oidc: OpenIdConfiguration;
94
+ readonly oauth: OAuth | undefined;
95
+ constructor({ tharosAuthUrl, realm, oidc, oauth }: Config & {
96
+ oidc: OpenIdConfiguration;
97
+ });
98
+ static newInstance(config: Config): Promise<TharosConfig>;
99
+ }
100
+
101
+ type RequestInterceptor = (url: string, request: RequestInit) => Promise<[string, RequestInit]> | [string, RequestInit];
102
+ type ResponseInterceptor = (response: Response) => Promise<Response> | Response;
103
+ declare class ApiClient {
104
+ private baseUrl;
105
+ private defaultHeaders;
106
+ private requestInterceptors;
107
+ private responseInterceptors;
108
+ constructor(baseUrl: string, defaultHeaders?: Record<string, string>);
109
+ withPath(subPath: string): ApiClient;
110
+ setDefaultHeader(key: string, value: string): void;
111
+ addRequestInterceptor(interceptor: RequestInterceptor): void;
112
+ addResponseInterceptor(interceptor: ResponseInterceptor): void;
113
+ fetch<T>(path: string, options?: RequestInit & {
114
+ overrideUrl?: boolean;
115
+ }): Promise<T>;
116
+ get<T>(path: string, options?: RequestInit & {
117
+ overrideUrl?: boolean;
118
+ }): Promise<T>;
119
+ post<T>(path: string, body?: any, options?: RequestInit): Promise<T>;
120
+ put<T>(path: string, body?: any, options?: RequestInit): Promise<T>;
121
+ delete<T>(path: string, options?: RequestInit): Promise<T>;
122
+ }
123
+
124
+ interface TharosImpl {
125
+ config: TharosConfig;
126
+ api: ApiClient;
127
+ journey: JourneyRequestProcess;
128
+ getCurrentUser(): User | null;
129
+ setAuthenticatedUser(): Promise<void>;
130
+ }
131
+ declare class BasicTharosContext {
132
+ protected ctx: TharosImpl;
133
+ constructor(tharosCtx: TharosImpl);
134
+ }
135
+
136
+ declare enum StepType {
137
+ USER_NAME = "UserName",
138
+ PASSWORD = "Password",
139
+ METADATA = "Metadata"
140
+ }
141
+ interface ClientInput {
142
+ id: string;
143
+ step_type: StepType;
144
+ type: string;
145
+ send_back: boolean;
146
+ output: Map<string, any>;
147
+ input: any;
148
+ }
149
+ interface JourneyResponsePayload {
150
+ journey_token: string;
151
+ client_inputs: ClientInput[];
152
+ client_error?: {
153
+ error: string;
154
+ details?: Map<string, any>;
155
+ };
156
+ }
157
+ interface JourneySuccess {
158
+ session_id?: string;
159
+ success_url?: string;
160
+ }
161
+ interface JourneyFailure {
162
+ error: string;
163
+ failure_url?: string;
164
+ }
165
+
166
+ declare class JourneyStepType extends BasicTharosContext {
167
+ private clientInput;
168
+ static readonly stepsMap: Map<string, typeof JourneyStepType>;
169
+ constructor(clientInput: ClientInput, ctx: TharosImpl);
170
+ getID(): string;
171
+ getStepType(): StepType;
172
+ getType(): string;
173
+ setInput(data: any): void;
174
+ getOutput(): Map<string, any>;
175
+ getPayload(): ClientInput;
176
+ }
177
+
178
+ declare class JourneyResponse extends BasicTharosContext {
179
+ private journeyResponsePayload;
180
+ private clientInputs;
181
+ constructor(journeyResponsePayload: JourneyResponsePayload, ctx: TharosImpl);
182
+ getJourneyToken(): string;
183
+ getClientInputs<T extends JourneyStepType>(stepType: StepType): T[];
184
+ getAllClientInputs(): JourneyStepType[];
185
+ }
186
+ declare class JourneyRequestProcess extends BasicTharosContext {
187
+ start(payload: {
188
+ journey_id: string;
189
+ } | {
190
+ resume_id: string;
191
+ }, executor: JourneyExecutor, options?: {
192
+ headers: Map<string, string>;
193
+ }): Promise<void>;
194
+ }
195
+ interface JourneyExecutor {
196
+ onSuccess: (journeySuccess: JourneySuccess) => Promise<void>;
197
+ onFailure: (journeyFailure: JourneyFailure) => Promise<void>;
198
+ onNewStep: (journeyResponse: JourneyResponse) => Promise<void>;
199
+ }
200
+
201
+ declare class Tharos {
202
+ readonly config: TharosConfig;
203
+ readonly api: ApiClient;
204
+ readonly journey: JourneyRequestProcess;
205
+ private defaultJourneyExecutor;
206
+ private user;
207
+ constructor({ config, defaultJourneyExecutor }: {
208
+ config: TharosConfig;
209
+ defaultJourneyExecutor?: JourneyExecutor;
210
+ });
211
+ getDefaultJourneyExecutor(): JourneyExecutor;
212
+ getCurrentUser(): User;
213
+ setAuthenticatedUser(): Promise<void>;
214
+ getAuthorizeUrl(config?: OAuth): string;
215
+ exchangeTokens(): Promise<void>;
216
+ static newInstance(baseConfig: Config): Promise<Tharos>;
217
+ }
218
+
219
+ export { Tharos };
package/dist/index.js ADDED
@@ -0,0 +1,281 @@
1
+ // src/tharos.ts
2
+ var BasicTharosContext = class {
3
+ ctx;
4
+ constructor(tharosCtx) {
5
+ this.ctx = tharosCtx;
6
+ }
7
+ };
8
+
9
+ // src/auth/client-inputs/client-input.ts
10
+ var JourneyStepType = class extends BasicTharosContext {
11
+ clientInput;
12
+ static stepsMap = /* @__PURE__ */ new Map();
13
+ constructor(clientInput, ctx) {
14
+ super(ctx);
15
+ this.clientInput = clientInput;
16
+ }
17
+ getID() {
18
+ return this.clientInput.id;
19
+ }
20
+ getStepType() {
21
+ return this.clientInput.step_type;
22
+ }
23
+ getType() {
24
+ return this.clientInput.type;
25
+ }
26
+ setInput(data) {
27
+ this.clientInput.input = data;
28
+ }
29
+ getOutput() {
30
+ return this.clientInput.output;
31
+ }
32
+ getPayload() {
33
+ return this.clientInput;
34
+ }
35
+ };
36
+
37
+ // src/auth/journey.ts
38
+ var JourneyResponse = class extends BasicTharosContext {
39
+ journeyResponsePayload;
40
+ clientInputs;
41
+ constructor(journeyResponsePayload, ctx) {
42
+ super(ctx);
43
+ this.journeyResponsePayload = journeyResponsePayload;
44
+ this.clientInputs = this.journeyResponsePayload.client_inputs.map(
45
+ (el) => new (JourneyStepType.stepsMap.get(el.step_type.toString()))(el, ctx)
46
+ );
47
+ }
48
+ getJourneyToken() {
49
+ return this.journeyResponsePayload.journey_token;
50
+ }
51
+ getClientInputs(stepType) {
52
+ return this.clientInputs.filter((el) => el.getStepType() == stepType);
53
+ }
54
+ getAllClientInputs() {
55
+ return this.clientInputs;
56
+ }
57
+ };
58
+ var JourneyRequestProcess = class extends BasicTharosContext {
59
+ async start(payload, executor, options) {
60
+ let journeyResponse = await this.ctx.api.post(
61
+ `/realms/${this.ctx.config.realm}/journeys/auth`,
62
+ payload,
63
+ {
64
+ headers: options == null ? void 0 : options.headers
65
+ }
66
+ );
67
+ while (journeyResponse.hasOwnProperty("journey_token")) {
68
+ journeyResponse = journeyResponse;
69
+ let process = new JourneyResponse(journeyResponse, this.ctx);
70
+ await executor.onNewStep(process);
71
+ journeyResponse = await this.ctx.api.post(
72
+ `/realms/${this.ctx.config.realm}/journeys/auth`,
73
+ {
74
+ journey_token: journeyResponse.journey_token,
75
+ client_inputs: process.getAllClientInputs().map((el) => el.getPayload())
76
+ }
77
+ );
78
+ }
79
+ if (journeyResponse.hasOwnProperty("session_id")) {
80
+ await this.ctx.setAuthenticatedUser();
81
+ executor.onSuccess(journeyResponse);
82
+ } else {
83
+ executor.onFailure(journeyResponse);
84
+ }
85
+ }
86
+ };
87
+
88
+ // src/auth/user.ts
89
+ var User = class extends BasicTharosContext {
90
+ tokens = null;
91
+ getUserTokens() {
92
+ return this.tokens;
93
+ }
94
+ async sessionInfo() {
95
+ return await this.ctx.api.post(`/realms/${this.ctx.config.realm}/session/info`);
96
+ }
97
+ async validateSession(refresh = false) {
98
+ return await this.ctx.api.post(
99
+ `/realms/${this.ctx.config.realm}/session/validate?refresh=${refresh}`
100
+ );
101
+ }
102
+ };
103
+
104
+ // src/http.ts
105
+ var HttpError = class extends Error {
106
+ code;
107
+ details;
108
+ constructor({ code, message, details }) {
109
+ super(message);
110
+ this.code = code;
111
+ this.details = details;
112
+ }
113
+ };
114
+ var ApiClient = class _ApiClient {
115
+ baseUrl;
116
+ defaultHeaders;
117
+ requestInterceptors;
118
+ responseInterceptors;
119
+ constructor(baseUrl, defaultHeaders = {}) {
120
+ this.baseUrl = baseUrl;
121
+ this.defaultHeaders = { ...defaultHeaders };
122
+ this.requestInterceptors = [];
123
+ this.responseInterceptors = [];
124
+ }
125
+ withPath(subPath) {
126
+ const child = new _ApiClient(this.baseUrl + subPath, this.defaultHeaders);
127
+ child.requestInterceptors = [...this.requestInterceptors];
128
+ child.responseInterceptors = [...this.responseInterceptors];
129
+ return child;
130
+ }
131
+ setDefaultHeader(key, value) {
132
+ this.defaultHeaders[key] = value;
133
+ }
134
+ addRequestInterceptor(interceptor) {
135
+ this.requestInterceptors.push(interceptor);
136
+ }
137
+ addResponseInterceptor(interceptor) {
138
+ this.responseInterceptors.push(interceptor);
139
+ }
140
+ async fetch(path, options = {}) {
141
+ var _a;
142
+ if (path == "/") {
143
+ path = "";
144
+ }
145
+ let url = options.overrideUrl ? path : `${this.baseUrl}${path}`;
146
+ let init = {
147
+ headers: { ...this.defaultHeaders, ...options.headers || {} },
148
+ ...options,
149
+ credentials: "include"
150
+ };
151
+ for (const interceptor of this.requestInterceptors) {
152
+ [url, init] = await interceptor(url, init);
153
+ }
154
+ let response = await fetch(url, init);
155
+ for (const interceptor of this.responseInterceptors) {
156
+ response = await interceptor(response);
157
+ }
158
+ if (!response.ok) {
159
+ if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
160
+ throw new HttpError(await response.json());
161
+ } else {
162
+ throw new Error(`Error ${response.status}: ${response.statusText}`);
163
+ }
164
+ }
165
+ return response.json();
166
+ }
167
+ get(path, options) {
168
+ return this.fetch(path, { ...options, method: "GET" });
169
+ }
170
+ post(path, body, options) {
171
+ return this.fetch(path, {
172
+ ...options,
173
+ method: "POST",
174
+ body: JSON.stringify(body)
175
+ });
176
+ }
177
+ put(path, body, options) {
178
+ return this.fetch(path, {
179
+ ...options,
180
+ method: "PUT",
181
+ body: JSON.stringify(body)
182
+ });
183
+ }
184
+ delete(path, options) {
185
+ return this.fetch(path, { ...options, method: "DELETE" });
186
+ }
187
+ };
188
+
189
+ // src/config.ts
190
+ var TharosConfig = class _TharosConfig {
191
+ tharosAuthUrl;
192
+ realm;
193
+ oidc;
194
+ oauth;
195
+ constructor({ tharosAuthUrl, realm, oidc, oauth }) {
196
+ this.tharosAuthUrl = tharosAuthUrl;
197
+ this.realm = realm;
198
+ this.oidc = oidc;
199
+ this.oauth = oauth;
200
+ }
201
+ static async newInstance(config) {
202
+ const api = new ApiClient("");
203
+ const oidc = null;
204
+ return new _TharosConfig({ ...config, oidc });
205
+ }
206
+ };
207
+
208
+ // src/auth/client-inputs/user-name.ts
209
+ var UserNameInput = class extends JourneyStepType {
210
+ setInput(userName) {
211
+ super.setInput(userName);
212
+ }
213
+ };
214
+ JourneyStepType.stepsMap.set("UserName" /* USER_NAME */, UserNameInput);
215
+
216
+ // src/auth/client-inputs/metadata.ts
217
+ var MeatadataInput = class extends JourneyStepType {
218
+ setInput() {
219
+ }
220
+ };
221
+ JourneyStepType.stepsMap.set("Metadata" /* METADATA */, MeatadataInput);
222
+
223
+ // src/index.ts
224
+ var Tharos = class _Tharos {
225
+ config;
226
+ api;
227
+ journey;
228
+ defaultJourneyExecutor;
229
+ user = null;
230
+ constructor({ config, defaultJourneyExecutor }) {
231
+ var _a;
232
+ this.config = config;
233
+ this.api = new ApiClient(this.config.tharosAuthUrl);
234
+ this.journey = new JourneyRequestProcess(this);
235
+ this.defaultJourneyExecutor = defaultJourneyExecutor;
236
+ const currentURL = new URL(window.location.href).origin + new URL(window.location.href).pathname;
237
+ if (currentURL === ((_a = this.config.oauth) == null ? void 0 : _a.redirectUri)) {
238
+ }
239
+ }
240
+ getDefaultJourneyExecutor() {
241
+ return this.defaultJourneyExecutor;
242
+ }
243
+ getCurrentUser() {
244
+ return this.user;
245
+ }
246
+ async setAuthenticatedUser() {
247
+ const user = new User(this);
248
+ await user.sessionInfo();
249
+ this.user = user;
250
+ }
251
+ getAuthorizeUrl(config) {
252
+ if (!config) {
253
+ if (!this.config.oauth) {
254
+ throw new Error("oauth not configured");
255
+ }
256
+ config = this.config.oauth;
257
+ }
258
+ return `${this.config.tharosAuthUrl}/realms/${this.config.realm}/oauth2/auth?client_id=${config.clientId}&scope=${config.scope}&response_type=code&redirect_uri=${config.redirectUri}&acr_values=all1`;
259
+ }
260
+ async exchangeTokens() {
261
+ var _a, _b;
262
+ const url = new URL(window.location.href);
263
+ this.api.post(
264
+ `/realms/${this.config.realm}/oauth2/token`,
265
+ {
266
+ grant_type: "authorization_code",
267
+ code: url.searchParams.get("code"),
268
+ client_id: (_a = this.config.oauth) == null ? void 0 : _a.clientId,
269
+ scope: (_b = this.config.oauth) == null ? void 0 : _b.scope
270
+ },
271
+ { headers: { "Content-Type": "application/x-www-form-urlencoded" } }
272
+ );
273
+ }
274
+ static async newInstance(baseConfig) {
275
+ return new _Tharos({ config: await TharosConfig.newInstance(baseConfig) });
276
+ }
277
+ };
278
+ export {
279
+ Tharos
280
+ };
281
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tharos.ts","../src/auth/client-inputs/client-input.ts","../src/auth/journey.ts","../src/auth/user.ts","../src/http.ts","../src/config.ts","../src/auth/client-inputs/user-name.ts","../src/auth/client-inputs/metadata.ts","../src/index.ts"],"sourcesContent":["import type { JourneyRequestProcess } from './auth/journey.js';\nimport type { User } from './auth/user.js';\nimport type { TharosConfig } from './config.js';\nimport type { ApiClient } from './http.js';\n\nexport interface TharosImpl {\n config: TharosConfig;\n api: ApiClient;\n journey: JourneyRequestProcess;\n getCurrentUser(): User | null;\n setAuthenticatedUser(): Promise<void>;\n}\n\nexport class BasicTharosContext {\n protected ctx: TharosImpl;\n\n constructor(tharosCtx: TharosImpl) {\n this.ctx = tharosCtx;\n }\n}\n","import { BasicTharosContext, type TharosImpl } from '../../tharos.js';\nimport type { ClientInput } from '../../types/journey.js';\n\nexport class JourneyStepType extends BasicTharosContext {\n private clientInput: ClientInput;\n public static readonly stepsMap: Map<string, typeof JourneyStepType> = new Map();\n\n constructor(clientInput: ClientInput, ctx: TharosImpl) {\n super(ctx);\n\n this.clientInput = clientInput;\n }\n\n public getID() {\n return this.clientInput.id;\n }\n\n public getStepType() {\n return this.clientInput.step_type;\n }\n\n public getType() {\n return this.clientInput.type;\n }\n\n public setInput(data: any) {\n this.clientInput.input = data;\n }\n\n public getOutput() {\n return this.clientInput.output;\n }\n\n public getPayload() {\n return this.clientInput;\n }\n}\n","import { BasicTharosContext, type TharosImpl } from '../tharos.js';\nimport type {\n ClientInput,\n JourneyFailure,\n JourneyRequest,\n JourneyResponsePayload,\n JourneySuccess,\n StepType,\n} from '../types/journey.js';\nimport { JourneyStepType } from './client-inputs/client-input.js';\n\nexport class JourneyResponse extends BasicTharosContext {\n private journeyResponsePayload: JourneyResponsePayload;\n private clientInputs: JourneyStepType[];\n\n constructor(journeyResponsePayload: JourneyResponsePayload, ctx: TharosImpl) {\n super(ctx);\n\n this.journeyResponsePayload = journeyResponsePayload;\n this.clientInputs = this.journeyResponsePayload.client_inputs.map(\n (el) => new (JourneyStepType.stepsMap.get(el.step_type.toString())!)(el, ctx)\n );\n }\n\n public getJourneyToken() {\n return this.journeyResponsePayload.journey_token;\n }\n\n public getClientInputs<T extends JourneyStepType>(stepType: StepType): T[] {\n return this.clientInputs.filter((el) => el.getStepType() == stepType) as T[];\n }\n\n public getAllClientInputs() {\n return this.clientInputs;\n }\n}\n\nexport class JourneyRequestProcess extends BasicTharosContext {\n public async start(\n payload: { journey_id: string } | { resume_id: string },\n executor: JourneyExecutor,\n options?: { headers: Map<string, string> }\n ) {\n let journeyResponse = await this.ctx.api.post<JourneyResponsePayload | JourneyFailure | JourneySuccess>(\n `/realms/${this.ctx.config.realm}/journeys/auth`,\n payload,\n {\n headers: options?.headers as any,\n }\n );\n\n while (journeyResponse.hasOwnProperty('journey_token')) {\n journeyResponse = journeyResponse as JourneyResponsePayload;\n let process = new JourneyResponse(journeyResponse, this.ctx);\n await executor.onNewStep(process);\n\n journeyResponse = await this.ctx.api.post<JourneyResponsePayload | JourneyFailure | JourneySuccess>(\n `/realms/${this.ctx.config.realm}/journeys/auth`,\n {\n journey_token: journeyResponse.journey_token,\n client_inputs: process.getAllClientInputs().map((el) => el.getPayload()),\n }\n );\n }\n\n if (journeyResponse.hasOwnProperty('session_id')) {\n await this.ctx.setAuthenticatedUser();\n executor.onSuccess(journeyResponse as JourneySuccess);\n } else {\n executor.onFailure(journeyResponse as JourneyFailure);\n }\n }\n}\n\nexport interface JourneyExecutor {\n onSuccess: (journeySuccess: JourneySuccess) => Promise<void>;\n onFailure: (journeyFailure: JourneyFailure) => Promise<void>;\n onNewStep: (journeyResponse: JourneyResponse) => Promise<void>;\n}\n","import { BasicTharosContext } from '../tharos.js';\nimport type { UserTokens } from './tokens.js';\n\nexport class User extends BasicTharosContext {\n private tokens: UserTokens | null = null;\n\n public getUserTokens() {\n return this.tokens;\n }\n\n public async sessionInfo() {\n return await this.ctx.api.post<Record<string, string>>(`/realms/${this.ctx.config.realm}/session/info`);\n }\n\n public async validateSession(refresh: boolean = false) {\n return await this.ctx.api.post<Record<string, string>>(\n `/realms/${this.ctx.config.realm}/session/validate?refresh=${refresh}`\n );\n }\n}\n","type RequestInterceptor = (url: string, request: RequestInit) => Promise<[string, RequestInit]> | [string, RequestInit];\n\ntype ResponseInterceptor = (response: Response) => Promise<Response> | Response;\n\nexport class HttpError extends Error {\n code: number;\n details: any;\n\n constructor({ code, message, details }: { code: number; message: string; details: any }) {\n super(message);\n\n this.code = code;\n this.details = details;\n }\n}\n\nexport class ApiClient {\n private baseUrl: string;\n private defaultHeaders: Record<string, string>;\n private requestInterceptors: RequestInterceptor[];\n private responseInterceptors: ResponseInterceptor[];\n\n constructor(baseUrl: string, defaultHeaders: Record<string, string> = {}) {\n this.baseUrl = baseUrl;\n this.defaultHeaders = { ...defaultHeaders };\n this.requestInterceptors = [];\n this.responseInterceptors = [];\n }\n\n withPath(subPath: string): ApiClient {\n const child = new ApiClient(this.baseUrl + subPath, this.defaultHeaders);\n\n child.requestInterceptors = [...this.requestInterceptors];\n child.responseInterceptors = [...this.responseInterceptors];\n\n return child;\n }\n\n setDefaultHeader(key: string, value: string) {\n this.defaultHeaders[key] = value;\n }\n\n addRequestInterceptor(interceptor: RequestInterceptor) {\n this.requestInterceptors.push(interceptor);\n }\n\n addResponseInterceptor(interceptor: ResponseInterceptor) {\n this.responseInterceptors.push(interceptor);\n }\n\n async fetch<T>(path: string, options: RequestInit & { overrideUrl?: boolean } = {}): Promise<T> {\n if (path == '/') {\n path = '';\n }\n\n let url = options.overrideUrl ? path : `${this.baseUrl}${path}`;\n let init: RequestInit = {\n headers: { ...this.defaultHeaders, ...(options.headers || {}) },\n ...options,\n credentials: 'include',\n };\n\n // Interceptores de request\n for (const interceptor of this.requestInterceptors) {\n [url, init] = await interceptor(url, init);\n }\n\n // Ejecutar fetch\n let response = await fetch(url, init);\n\n // Interceptores de response\n for (const interceptor of this.responseInterceptors) {\n response = await interceptor(response);\n }\n\n if (!response.ok) {\n if (response.headers.get('content-type')?.includes('application/json')) {\n throw new HttpError(await response.json());\n } else {\n throw new Error(`Error ${response.status}: ${response.statusText}`);\n }\n }\n\n return response.json() as Promise<T>;\n }\n\n get<T>(path: string, options?: RequestInit & { overrideUrl?: boolean }) {\n return this.fetch<T>(path, { ...options, method: 'GET' });\n }\n post<T>(path: string, body?: any, options?: RequestInit) {\n return this.fetch<T>(path, {\n ...options,\n method: 'POST',\n body: JSON.stringify(body),\n });\n }\n put<T>(path: string, body?: any, options?: RequestInit) {\n return this.fetch<T>(path, {\n ...options,\n method: 'PUT',\n body: JSON.stringify(body),\n });\n }\n delete<T>(path: string, options?: RequestInit) {\n return this.fetch<T>(path, { ...options, method: 'DELETE' });\n }\n}\n","import { ApiClient } from './http.js';\nimport type { Config, OAuth } from './types/config.js';\n\nexport interface OpenIdConfiguration {\n issuer: string;\n\n authorization_endpoint: string;\n token_endpoint: string;\n userinfo_endpoint: string;\n jwks_uri: string;\n registration_endpoint?: string;\n revocation_endpoint?: string;\n introspection_endpoint?: string;\n device_authorization_endpoint?: string;\n pushed_authorization_request_endpoint?: string;\n\n scopes_supported?: string[];\n response_types_supported: string[];\n response_modes_supported?: string[];\n grant_types_supported?: string[];\n\n subject_types_supported: ('public' | 'pairwise')[];\n id_token_signing_alg_values_supported: string[];\n id_token_encryption_alg_values_supported?: string[];\n id_token_encryption_enc_values_supported?: string[];\n\n userinfo_signing_alg_values_supported?: string[];\n userinfo_encryption_alg_values_supported?: string[];\n userinfo_encryption_enc_values_supported?: string[];\n\n request_object_signing_alg_values_supported?: string[];\n request_object_encryption_alg_values_supported?: string[];\n request_object_encryption_enc_values_supported?: string[];\n\n token_endpoint_auth_methods_supported?: string[];\n token_endpoint_auth_signing_alg_values_supported?: string[];\n\n introspection_endpoint_auth_methods_supported?: string[];\n introspection_endpoint_auth_signing_alg_values_supported?: string[];\n\n revocation_endpoint_auth_methods_supported?: string[];\n revocation_endpoint_auth_signing_alg_values_supported?: string[];\n\n claims_supported?: string[];\n claims_locales_supported?: string[];\n ui_locales_supported?: string[];\n\n claims_parameter_supported?: boolean;\n request_parameter_supported?: boolean;\n request_uri_parameter_supported?: boolean;\n require_request_uri_registration?: boolean;\n\n frontchannel_logout_supported?: boolean;\n frontchannel_logout_session_supported?: boolean;\n backchannel_logout_supported?: boolean;\n backchannel_logout_session_supported?: boolean;\n\n code_challenge_methods_supported?: ('plain' | 'S256')[];\n\n tls_client_certificate_bound_access_tokens?: boolean;\n authorization_response_iss_parameter_supported?: boolean;\n\n [key: string]: unknown;\n}\n\nexport class TharosConfig {\n public readonly tharosAuthUrl: string;\n public readonly realm: string;\n public readonly oidc: OpenIdConfiguration;\n public readonly oauth: OAuth | undefined;\n\n constructor({ tharosAuthUrl, realm, oidc, oauth }: Config & { oidc: OpenIdConfiguration }) {\n this.tharosAuthUrl = tharosAuthUrl;\n this.realm = realm;\n this.oidc = oidc;\n this.oauth = oauth;\n }\n\n public static async newInstance(config: Config) {\n const api = new ApiClient('');\n\n const oidc = null as any;\n\n return new TharosConfig({ ...config, oidc });\n }\n}\n","import { StepType } from '../../types/journey.js';\nimport { JourneyStepType } from './client-input.js';\n\nexport class UserNameInput extends JourneyStepType {\n public setInput(userName: string) {\n super.setInput(userName);\n }\n}\n\nJourneyStepType.stepsMap.set(StepType.USER_NAME, UserNameInput);\n","import { StepType } from '../../types/journey.js';\nimport { JourneyStepType } from './client-input.js';\n\nexport class MeatadataInput extends JourneyStepType {\n public setInput() {}\n}\n\nJourneyStepType.stepsMap.set(StepType.METADATA, MeatadataInput);\n","import { JourneyRequestProcess, type JourneyExecutor } from './auth/journey.js';\nimport { User } from './auth/user.js';\nimport { TharosConfig } from './config.js';\nimport { ApiClient } from './http.js';\nimport type { Config, OAuth } from './types/config.js';\nimport './auth/client-inputs/index.js';\n\nexport class Tharos {\n public readonly config: TharosConfig;\n public readonly api: ApiClient;\n public readonly journey: JourneyRequestProcess;\n private defaultJourneyExecutor: JourneyExecutor | undefined;\n private user: User | null = null;\n\n constructor({ config, defaultJourneyExecutor }: { config: TharosConfig; defaultJourneyExecutor?: JourneyExecutor }) {\n this.config = config;\n this.api = new ApiClient(this.config.tharosAuthUrl);\n this.journey = new JourneyRequestProcess(this);\n this.defaultJourneyExecutor = defaultJourneyExecutor;\n\n const currentURL = new URL(window.location.href).origin + new URL(window.location.href).pathname;\n\n if (currentURL === this.config.oauth?.redirectUri) {\n }\n }\n\n public getDefaultJourneyExecutor() {\n return this.defaultJourneyExecutor;\n }\n\n public getCurrentUser() {\n return this.user;\n }\n\n public async setAuthenticatedUser() {\n const user = new User(this);\n\n await user.sessionInfo();\n this.user = user;\n }\n\n public getAuthorizeUrl(config?: OAuth): string {\n if (!config) {\n if (!this.config.oauth) {\n throw new Error('oauth not configured');\n }\n\n config = this.config.oauth;\n }\n\n return `${this.config.tharosAuthUrl}/realms/${this.config.realm}/oauth2/auth?client_id=${config.clientId}&scope=${config.scope}&response_type=code&redirect_uri=${config.redirectUri}&acr_values=all1`;\n }\n\n public async exchangeTokens() {\n const url = new URL(window.location.href);\n this.api.post(\n `/realms/${this.config.realm}/oauth2/token`,\n {\n grant_type: 'authorization_code',\n code: url.searchParams.get('code'),\n client_id: this.config.oauth?.clientId,\n scope: this.config.oauth?.scope,\n },\n { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }\n );\n }\n\n public static async newInstance(baseConfig: Config) {\n return new Tharos({ config: await TharosConfig.newInstance(baseConfig) });\n }\n}\n"],"mappings":";AAaO,IAAM,qBAAN,MAAyB;AAAA,EACpB;AAAA,EAEV,YAAY,WAAuB;AACjC,SAAK,MAAM;AAAA,EACb;AACF;;;AChBO,IAAM,kBAAN,cAA8B,mBAAmB;AAAA,EAC9C;AAAA,EACR,OAAuB,WAAgD,oBAAI,IAAI;AAAA,EAE/E,YAAY,aAA0B,KAAiB;AACrD,UAAM,GAAG;AAET,SAAK,cAAc;AAAA,EACrB;AAAA,EAEO,QAAQ;AACb,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,UAAU;AACf,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,SAAS,MAAW;AACzB,SAAK,YAAY,QAAQ;AAAA,EAC3B;AAAA,EAEO,YAAY;AACjB,WAAO,KAAK,YAAY;AAAA,EAC1B;AAAA,EAEO,aAAa;AAClB,WAAO,KAAK;AAAA,EACd;AACF;;;ACzBO,IAAM,kBAAN,cAA8B,mBAAmB;AAAA,EAC9C;AAAA,EACA;AAAA,EAER,YAAY,wBAAgD,KAAiB;AAC3E,UAAM,GAAG;AAET,SAAK,yBAAyB;AAC9B,SAAK,eAAe,KAAK,uBAAuB,cAAc;AAAA,MAC5D,CAAC,OA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AAI,KAAK,IAAI;AAE1B,UAAM,KAAK,YAAY;AACvB,SAAK,OAAO;AAAA,EACd;AAAA,EAEO,gBAAgB,QAAwB;AAC7C,QAAI,CAAC,QAAQ;AACX,UAAI,CAAC,KAAK,OAAO,OAAO;AACtB,cAAM,IAAI,MAAM,sBAAsB;AAAA,MACxC;AAEA,eAAS,KAAK,OAAO;AAAA,IACvB;AAEA,WAAO,GAAG,KAAK,OAAO,aAAa,WAAW,KAAK,OAAO,KAAK,0BAA0B,OAAO,QAAQ,UAAU,OAAO,KAAK,oCAAoC,OAAO,WAAW;AAAA,EACtL;AAAA,EAEA,MAAa,iBAAiB;AArDhC;AAsDI,UAAM,MAAM,IAAI,IAAI,OAAO,SAAS,IAAI;AACxC,SAAK,IAAI;AAAA,MACP,WAAW,KAAK,OAAO,KAAK;AAAA,MAC5B;AAAA,QACE,YAAY;AAAA,QACZ,MAAM,IAAI,aAAa,IAAI,MAAM;AAAA,QACjC,YAAW,UAAK,OAAO,UAAZ,mBAAmB;AAAA,QAC9B,QAAO,UAAK,OAAO,UAAZ,mBAAmB;AAAA,MAC5B;AAAA,MACA,EAAE,SAAS,EAAE,gBAAgB,oCAAoC,EAAE;AAAA,IACrE;AAAA,EACF;AAAA,EAEA,aAAoB,YAAY,YAAoB;AAClD,WAAO,IAAI,QAAO,EAAE,QAAQ,MAAM,aAAa,YAAY,UAAU,EAAE,CAAC;AAAA,EAC1E;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "tharos-web-sdk",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "dev": "tsup --watch",
21
+ "clean": "rm -rf dist"
22
+ },
23
+ "devDependencies": {
24
+ "tsup": "^8.0.0",
25
+ "typescript": "^5.0.0"
26
+ }
27
+ }