@xeno-js/shared 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +675 -678
- package/dist/axios.cjs +2230 -0
- package/dist/axios.cjs.map +1 -0
- package/dist/axios.d.cts +19 -0
- package/dist/axios.d.ts +19 -0
- package/dist/axios.js +2203 -0
- package/dist/axios.js.map +1 -0
- package/dist/common.types-DT8JtZ0E.d.cts +214 -0
- package/dist/common.types-DT8JtZ0E.d.ts +214 -0
- package/dist/iauth-service.contracts-DotziBbm.d.ts +230 -0
- package/dist/iauth-service.contracts-DyFYvLdb.d.cts +230 -0
- package/dist/ihttp-client.contracts-DX2hDTW6.d.ts +299 -0
- package/dist/ihttp-client.contracts-KMkYuIHH.d.cts +299 -0
- package/dist/index.cjs +2 -347
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +973 -2295
- package/dist/index.d.ts +973 -2295
- package/dist/index.js +1 -340
- package/dist/index.js.map +1 -1
- package/dist/ivalidator-service.contracts-DGMounqU.d.cts +102 -0
- package/dist/ivalidator-service.contracts-ulue7FGh.d.ts +102 -0
- package/dist/result.types-BNTzjCgR.d.cts +381 -0
- package/dist/result.types-DRyxvpQs.d.ts +381 -0
- package/dist/supabase.cjs +2431 -0
- package/dist/supabase.cjs.map +1 -0
- package/dist/supabase.d.cts +53 -0
- package/dist/supabase.d.ts +53 -0
- package/dist/supabase.js +2402 -0
- package/dist/supabase.js.map +1 -0
- package/dist/zod.cjs +2372 -0
- package/dist/zod.cjs.map +1 -0
- package/dist/zod.d.cts +63 -0
- package/dist/zod.d.ts +63 -0
- package/dist/zod.js +2344 -0
- package/dist/zod.js.map +1 -0
- package/package.json +17 -2
package/dist/index.js
CHANGED
|
@@ -2533,90 +2533,6 @@ var StorageHelper = Object.freeze({
|
|
|
2533
2533
|
}
|
|
2534
2534
|
});
|
|
2535
2535
|
|
|
2536
|
-
// src/infrastructure/auth/supabase-auth.service.ts
|
|
2537
|
-
var SupabaseAuthService = class {
|
|
2538
|
-
constructor(_supabase, _mapper, _sessionMapper, _opts) {
|
|
2539
|
-
this._supabase = _supabase;
|
|
2540
|
-
this._mapper = _mapper;
|
|
2541
|
-
this._sessionMapper = _sessionMapper;
|
|
2542
|
-
this._opts = _opts;
|
|
2543
|
-
}
|
|
2544
|
-
_supabase;
|
|
2545
|
-
_mapper;
|
|
2546
|
-
_sessionMapper;
|
|
2547
|
-
_opts;
|
|
2548
|
-
async authenticate(token) {
|
|
2549
|
-
const { data, error } = await this._supabase.auth.getUser(token);
|
|
2550
|
-
if (Guards.isDefined(error) || !Guards.isDefined(data.user)) {
|
|
2551
|
-
return Result.fail(
|
|
2552
|
-
AppError.authFailed("SupabaseAuthenticationService", error?.message ?? "Unknown error")
|
|
2553
|
-
);
|
|
2554
|
-
}
|
|
2555
|
-
const user = data.user;
|
|
2556
|
-
const claims = this._mapper.map(user);
|
|
2557
|
-
return Result.ok(claims);
|
|
2558
|
-
}
|
|
2559
|
-
async isAuthenticated() {
|
|
2560
|
-
const session = await this._supabase.auth.getSession();
|
|
2561
|
-
return Guards.isDefined(session.data.session);
|
|
2562
|
-
}
|
|
2563
|
-
async exchangeCodeForSession(code) {
|
|
2564
|
-
const { data, error } = await this._supabase.auth.exchangeCodeForSession(code);
|
|
2565
|
-
if (Guards.isDefined(error) || !Guards.isDefined(data.session))
|
|
2566
|
-
return Result.fail(
|
|
2567
|
-
AppError.authFailed("SupabaseAuthenticationService", error?.message ?? "Unknown error")
|
|
2568
|
-
);
|
|
2569
|
-
const session = data.session;
|
|
2570
|
-
if (Guards.isDefined(session)) return Result.ok(this._sessionMapper.map(session));
|
|
2571
|
-
return Result.ok();
|
|
2572
|
-
}
|
|
2573
|
-
async signInWithProvider(provider) {
|
|
2574
|
-
const { data, error } = await this._supabase.auth.signInWithOAuth({
|
|
2575
|
-
provider,
|
|
2576
|
-
options: { redirectTo: this._opts.redirectTo }
|
|
2577
|
-
});
|
|
2578
|
-
if (Guards.isDefined(error) || Guards.isNullOrEmpty(data.url)) {
|
|
2579
|
-
return Result.fail(
|
|
2580
|
-
AppError.authFailed("SupabaseFrontendAuthService", error?.message ?? "Unexpected error")
|
|
2581
|
-
);
|
|
2582
|
-
}
|
|
2583
|
-
return Result.ok({ url: data.url });
|
|
2584
|
-
}
|
|
2585
|
-
async getSession() {
|
|
2586
|
-
const { data, error } = await this._supabase.auth.getSession();
|
|
2587
|
-
if (Guards.isDefined(error)) {
|
|
2588
|
-
return Result.fail(AppError.authFailed("SupabaseFrontendAuthService", error.message));
|
|
2589
|
-
}
|
|
2590
|
-
const session = data.session;
|
|
2591
|
-
if (Guards.isDefined(session)) return Result.ok(this._sessionMapper.map(data.session));
|
|
2592
|
-
return Result.ok();
|
|
2593
|
-
}
|
|
2594
|
-
async getUser() {
|
|
2595
|
-
const { data, error } = await this._supabase.auth.getUser();
|
|
2596
|
-
if (Guards.isDefined(error)) {
|
|
2597
|
-
return Result.fail(AppError.authFailed("SupabaseFrontendAuthService", error.message));
|
|
2598
|
-
}
|
|
2599
|
-
const user = data.user;
|
|
2600
|
-
if (Guards.isDefined(user)) return Result.ok(this._mapper.map(user));
|
|
2601
|
-
return Result.ok();
|
|
2602
|
-
}
|
|
2603
|
-
async signOut() {
|
|
2604
|
-
const { error } = await this._supabase.auth.signOut();
|
|
2605
|
-
if (Guards.isDefined(error)) {
|
|
2606
|
-
return Result.fail(AppError.authFailed("SupabaseFrontendAuthService", error.message));
|
|
2607
|
-
}
|
|
2608
|
-
return Result.ok();
|
|
2609
|
-
}
|
|
2610
|
-
async getSessionToken() {
|
|
2611
|
-
const sessionResult = await this.getSession();
|
|
2612
|
-
if (!sessionResult.isOk()) {
|
|
2613
|
-
return Result.fail(sessionResult.getErrorOrThrow());
|
|
2614
|
-
}
|
|
2615
|
-
const session = sessionResult.getValueOrThrow();
|
|
2616
|
-
return Result.ok(session?.accessToken);
|
|
2617
|
-
}
|
|
2618
|
-
};
|
|
2619
|
-
|
|
2620
2536
|
// src/infrastructure/cache/in-memory.cache.ts
|
|
2621
2537
|
var InMemoryCache = class {
|
|
2622
2538
|
/**
|
|
@@ -2704,259 +2620,9 @@ var CacheKeyBuilder = class {
|
|
|
2704
2620
|
return this.buildContextualKey(key);
|
|
2705
2621
|
}
|
|
2706
2622
|
};
|
|
2707
|
-
|
|
2708
|
-
// src/infrastructure/http/axios.http.ts
|
|
2709
|
-
import { AxiosError } from "axios";
|
|
2710
|
-
var AxiosHttpClient = class {
|
|
2711
|
-
constructor(_client) {
|
|
2712
|
-
this._client = _client;
|
|
2713
|
-
}
|
|
2714
|
-
_client;
|
|
2715
|
-
async executInAsync(callback, opts) {
|
|
2716
|
-
AppError.throwIfAborted(opts.signal, opts.name);
|
|
2717
|
-
try {
|
|
2718
|
-
return await callback();
|
|
2719
|
-
} catch (error) {
|
|
2720
|
-
this.handleError(error, "AxiosHttpClient.get");
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
async get(url, options) {
|
|
2724
|
-
return await this.executInAsync(
|
|
2725
|
-
async () => {
|
|
2726
|
-
const response = await this._client.get(url, this.buildConfig(options));
|
|
2727
|
-
return this.handleResponse(response);
|
|
2728
|
-
},
|
|
2729
|
-
{ signal: options?.signal, name: "AxiosHttpClient.get" }
|
|
2730
|
-
);
|
|
2731
|
-
}
|
|
2732
|
-
async post(url, body, options) {
|
|
2733
|
-
return await this.executInAsync(
|
|
2734
|
-
async () => {
|
|
2735
|
-
const response = await this._client.post(url, body, this.buildConfig(options));
|
|
2736
|
-
return this.handleResponse(response);
|
|
2737
|
-
},
|
|
2738
|
-
{ signal: options?.signal, name: "AxiosHttpClient.post" }
|
|
2739
|
-
);
|
|
2740
|
-
}
|
|
2741
|
-
async put(url, body, options) {
|
|
2742
|
-
return await this.executInAsync(
|
|
2743
|
-
async () => {
|
|
2744
|
-
const response = await this._client.put(url, body, this.buildConfig(options));
|
|
2745
|
-
return this.handleResponse(response);
|
|
2746
|
-
},
|
|
2747
|
-
{ signal: options?.signal, name: "AxiosHttpClient.put" }
|
|
2748
|
-
);
|
|
2749
|
-
}
|
|
2750
|
-
async patch(url, body, options) {
|
|
2751
|
-
return await this.executInAsync(
|
|
2752
|
-
async () => {
|
|
2753
|
-
const response = await this._client.patch(url, body, this.buildConfig(options));
|
|
2754
|
-
return this.handleResponse(response);
|
|
2755
|
-
},
|
|
2756
|
-
{ signal: options?.signal, name: "AxiosHttpClient.patch" }
|
|
2757
|
-
);
|
|
2758
|
-
}
|
|
2759
|
-
async delete(url, options) {
|
|
2760
|
-
return await this.executInAsync(
|
|
2761
|
-
async () => {
|
|
2762
|
-
const response = await this._client.delete(url, this.buildConfig(options));
|
|
2763
|
-
return this.handleResponse(response);
|
|
2764
|
-
},
|
|
2765
|
-
{ signal: options?.signal, name: "AxiosHttpClient.delete" }
|
|
2766
|
-
);
|
|
2767
|
-
}
|
|
2768
|
-
buildConfig(options) {
|
|
2769
|
-
return {
|
|
2770
|
-
headers: options?.headers,
|
|
2771
|
-
params: options?.query,
|
|
2772
|
-
signal: options?.signal,
|
|
2773
|
-
timeout: options?.timeoutMs,
|
|
2774
|
-
validateStatus: () => true
|
|
2775
|
-
};
|
|
2776
|
-
}
|
|
2777
|
-
handleResponse(response) {
|
|
2778
|
-
if (!Guards.isDefined(response.status) || response.status >= 400) {
|
|
2779
|
-
AppError.throw({
|
|
2780
|
-
code: ERROR_CODES.EXTERNAL_SERVICE_ERROR,
|
|
2781
|
-
message: ERROR_CODE_MESSAGES[ERROR_CODES.EXTERNAL_SERVICE_ERROR],
|
|
2782
|
-
status: response.status,
|
|
2783
|
-
name: "AxiosHttpClientException",
|
|
2784
|
-
cause: new AxiosError(
|
|
2785
|
-
`Request failed with status code ${response.status}`,
|
|
2786
|
-
void 0,
|
|
2787
|
-
response.config,
|
|
2788
|
-
response.request,
|
|
2789
|
-
response
|
|
2790
|
-
)
|
|
2791
|
-
});
|
|
2792
|
-
}
|
|
2793
|
-
return {
|
|
2794
|
-
status: response.status,
|
|
2795
|
-
ok: response.status >= 200 && response.status < 300,
|
|
2796
|
-
headers: HttpHelper.normalizeHeaders(response.headers),
|
|
2797
|
-
data: response.data
|
|
2798
|
-
};
|
|
2799
|
-
}
|
|
2800
|
-
handleError(error, name) {
|
|
2801
|
-
if (error instanceof AppError) throw error;
|
|
2802
|
-
const status = error instanceof AxiosError && Guards.isDefined(error.response) ? error.response.status : STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
2803
|
-
AppError.throw({
|
|
2804
|
-
code: ERROR_CODES.EXTERNAL_SERVICE_ERROR,
|
|
2805
|
-
message: ERROR_CODE_MESSAGES[ERROR_CODES.EXTERNAL_SERVICE_ERROR],
|
|
2806
|
-
status,
|
|
2807
|
-
name,
|
|
2808
|
-
cause: error
|
|
2809
|
-
});
|
|
2810
|
-
}
|
|
2811
|
-
};
|
|
2812
|
-
|
|
2813
|
-
// src/infrastructure/mappers/supabase-claims.mapper.ts
|
|
2814
|
-
var SupabaseClaimsMapper = class {
|
|
2815
|
-
map(user) {
|
|
2816
|
-
const appMetadata = user.app_metadata ?? {};
|
|
2817
|
-
return {
|
|
2818
|
-
sub: user.id,
|
|
2819
|
-
email: user.email,
|
|
2820
|
-
name: Guards.isString(user.user_metadata?.["name"]) ? user.user_metadata?.["name"] : void 0,
|
|
2821
|
-
tenantId: Guards.isString(appMetadata?.["tenant_id"]) ? appMetadata?.["tenant_id"] : void 0,
|
|
2822
|
-
roles: Guards.isArray(appMetadata["roles"]) ? appMetadata["roles"] : void 0,
|
|
2823
|
-
permissions: Guards.isArray(appMetadata["permissions"]) ? appMetadata["permissions"] : void 0
|
|
2824
|
-
};
|
|
2825
|
-
}
|
|
2826
|
-
};
|
|
2827
|
-
|
|
2828
|
-
// src/infrastructure/mappers/supabase-session.mapper.ts
|
|
2829
|
-
var SupabaseSessionMapper = class {
|
|
2830
|
-
constructor(_claimsMapper) {
|
|
2831
|
-
this._claimsMapper = _claimsMapper;
|
|
2832
|
-
}
|
|
2833
|
-
_claimsMapper;
|
|
2834
|
-
map(source) {
|
|
2835
|
-
const claims = this._claimsMapper.map(source.user);
|
|
2836
|
-
return {
|
|
2837
|
-
accessToken: source.access_token,
|
|
2838
|
-
refreshToken: source.refresh_token,
|
|
2839
|
-
expiresAt: source.expires_at,
|
|
2840
|
-
user: claims
|
|
2841
|
-
};
|
|
2842
|
-
}
|
|
2843
|
-
};
|
|
2844
|
-
|
|
2845
|
-
// src/infrastructure/validators/base-schema.constant.ts
|
|
2846
|
-
import { z } from "zod";
|
|
2847
|
-
var baseZodSchema = {
|
|
2848
|
-
get(intent, type) {
|
|
2849
|
-
return z.object({
|
|
2850
|
-
intent: z.literal(intent),
|
|
2851
|
-
type: z.literal(type)
|
|
2852
|
-
});
|
|
2853
|
-
}
|
|
2854
|
-
};
|
|
2855
|
-
var cacheableOptionsZodSchema = {
|
|
2856
|
-
get() {
|
|
2857
|
-
return z.object({
|
|
2858
|
-
cacheKey: z.string().min(1, "Cache key is required"),
|
|
2859
|
-
ttl: z.number().int().positive().optional(),
|
|
2860
|
-
bypassCache: z.boolean().optional(),
|
|
2861
|
-
consistentRead: z.boolean().optional()
|
|
2862
|
-
});
|
|
2863
|
-
}
|
|
2864
|
-
};
|
|
2865
|
-
var baseCommandZodSchema = {
|
|
2866
|
-
/**
|
|
2867
|
-
* @description Gets the base schema for a command with the given intent.
|
|
2868
|
-
* @param intent The intent of the command.
|
|
2869
|
-
* @returns The base schema for the command.
|
|
2870
|
-
*/
|
|
2871
|
-
get(intent) {
|
|
2872
|
-
return baseZodSchema.get(intent, REQUEST_TYPE.COMMAND);
|
|
2873
|
-
}
|
|
2874
|
-
};
|
|
2875
|
-
var baseQueryZodSchema = {
|
|
2876
|
-
/**
|
|
2877
|
-
* @description Gets the base schema for a query with the given intent and chache key.
|
|
2878
|
-
* @param intent The intent of the query.
|
|
2879
|
-
* @returns The base schema for the query.
|
|
2880
|
-
*/
|
|
2881
|
-
get(intent) {
|
|
2882
|
-
const baseSchema = baseZodSchema.get(intent, REQUEST_TYPE.QUERY);
|
|
2883
|
-
return baseSchema.extend({
|
|
2884
|
-
cacheOptions: cacheableOptionsZodSchema.get()
|
|
2885
|
-
});
|
|
2886
|
-
}
|
|
2887
|
-
};
|
|
2888
|
-
|
|
2889
|
-
// src/infrastructure/validators/schema-zod.utils.ts
|
|
2890
|
-
var ZodUtils = Object.freeze({
|
|
2891
|
-
/**
|
|
2892
|
-
* @description Creates a Zod schema for a command by extending the base command schema with additional properties.
|
|
2893
|
-
* @param intent - The intent of the command.
|
|
2894
|
-
* @param additionalSchema - An object representing additional properties to be added to the command schema.
|
|
2895
|
-
* @returns A Zod schema for the command.
|
|
2896
|
-
*/
|
|
2897
|
-
createCommandSchema: (intent, additionalSchema) => {
|
|
2898
|
-
return baseCommandZodSchema.get(intent).extend(additionalSchema).strict();
|
|
2899
|
-
},
|
|
2900
|
-
/**
|
|
2901
|
-
* @description Creates a Zod schema for a query by extending the base query schema with additional properties.
|
|
2902
|
-
* @param intent - The intent of the query.
|
|
2903
|
-
* @param additionalSchema - An object representing additional properties to be added to the query schema.
|
|
2904
|
-
* @returns A Zod schema for the query.
|
|
2905
|
-
*/
|
|
2906
|
-
createQuerySchema: (intent, additionalSchema) => {
|
|
2907
|
-
return baseQueryZodSchema.get(intent).extend(additionalSchema).strict();
|
|
2908
|
-
}
|
|
2909
|
-
});
|
|
2910
|
-
|
|
2911
|
-
// src/infrastructure/validators/zod.validator.ts
|
|
2912
|
-
var ZodValidatorService = class _ZodValidatorService {
|
|
2913
|
-
/**
|
|
2914
|
-
* @description Constructs a new instance of the ZodValidatorService class, which takes an ICache instance as a parameter. This cache is used to store and manage the validation schemas that will be applied to incoming data. The constructor initializes the service with the provided cache, allowing it to perform validation checks based on the cached schemas when the validate method is called.
|
|
2915
|
-
*
|
|
2916
|
-
* @param _cache An instance of ICache used to store and retrieve Zod schemas. This cache is essential for the operation of the validator service, as it allows it to look up and apply the correct schema for validating incoming data.
|
|
2917
|
-
* @param _logger An instance of ILogger used to log warning when schema was not found.
|
|
2918
|
-
*
|
|
2919
|
-
* @author Xeno
|
|
2920
|
-
* @version 1.0.0
|
|
2921
|
-
* @since 2025-09-30
|
|
2922
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2923
|
-
*/
|
|
2924
|
-
constructor(_cache = /* @__PURE__ */ new Map(), _logger) {
|
|
2925
|
-
this._cache = _cache;
|
|
2926
|
-
this._logger = _logger;
|
|
2927
|
-
}
|
|
2928
|
-
_cache;
|
|
2929
|
-
_logger;
|
|
2930
|
-
static formatIssue(issue) {
|
|
2931
|
-
const issuePath = !Guards.isNullOrEmpty(issue.path) ? issue.path.map(String).join(".") : "root";
|
|
2932
|
-
return `[${issuePath}] ${issue.message}`;
|
|
2933
|
-
}
|
|
2934
|
-
addSchema(key, schema) {
|
|
2935
|
-
this._cache.set(key, schema);
|
|
2936
|
-
}
|
|
2937
|
-
async validate(key, data) {
|
|
2938
|
-
const schema = this._cache.get(key);
|
|
2939
|
-
if (!Guards.isDefined(schema)) {
|
|
2940
|
-
this._logger.warn(`Schema for intent: ${key} was not found`);
|
|
2941
|
-
return Result.ok();
|
|
2942
|
-
}
|
|
2943
|
-
const zodResult = schema.safeParse(data);
|
|
2944
|
-
if (!zodResult.success) {
|
|
2945
|
-
const errorMessage = zodResult.error.issues.map((issue) => _ZodValidatorService.formatIssue(issue)).join(", ");
|
|
2946
|
-
return Result.fail(
|
|
2947
|
-
AppError.validationError(
|
|
2948
|
-
"ZodValidatorService",
|
|
2949
|
-
`Validation failed for schema: ${errorMessage}`
|
|
2950
|
-
)
|
|
2951
|
-
);
|
|
2952
|
-
}
|
|
2953
|
-
return Result.ok(true);
|
|
2954
|
-
}
|
|
2955
|
-
};
|
|
2956
2623
|
export {
|
|
2957
2624
|
AbortSignalHelper,
|
|
2958
2625
|
AppError,
|
|
2959
|
-
AxiosHttpClient,
|
|
2960
2626
|
BaseLogger,
|
|
2961
2627
|
CacheKeyBuilder,
|
|
2962
2628
|
Command,
|
|
@@ -2989,13 +2655,8 @@ export {
|
|
|
2989
2655
|
SanitizeHelper,
|
|
2990
2656
|
StorageHelper,
|
|
2991
2657
|
StringHelper,
|
|
2992
|
-
SupabaseAuthService,
|
|
2993
|
-
SupabaseClaimsMapper,
|
|
2994
|
-
SupabaseSessionMapper,
|
|
2995
2658
|
TOKENS,
|
|
2996
2659
|
UniqueId,
|
|
2997
|
-
ValueObject
|
|
2998
|
-
ZodUtils,
|
|
2999
|
-
ZodValidatorService
|
|
2660
|
+
ValueObject
|
|
3000
2661
|
};
|
|
3001
2662
|
//# sourceMappingURL=index.js.map
|