@dragonmastery/dragoncore-api 0.0.1 → 0.0.2
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.d.mts +229 -229
- package/dist/index.mjs +73 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/dist/session_validation-DYUZWJFy.mjs +0 -3
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,6 @@ import { hashPassword, verifyPassword } from "worker-password-auth";
|
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import * as jose from "jose";
|
|
11
11
|
import { HTTPException } from "hono/http-exception";
|
|
12
|
-
import { archiveConditions as archiveConditions$1, createBackendRegistry as createBackendRegistry$1, createFilterBuilder as createFilterBuilder$1, deriveColumnMap as deriveColumnMap$1, searchOrCondition as searchOrCondition$1 } from "@dragonmastery/dragoncore-api";
|
|
13
12
|
import { RpcTarget } from "capnweb";
|
|
14
13
|
|
|
15
14
|
//#region src/di_tokens.ts
|
|
@@ -2426,6 +2425,63 @@ async function verifyToken(token, secret) {
|
|
|
2426
2425
|
}
|
|
2427
2426
|
}
|
|
2428
2427
|
|
|
2428
|
+
//#endregion
|
|
2429
|
+
//#region src/middleware/session_validation.ts
|
|
2430
|
+
/**
|
|
2431
|
+
* Validates session from JWT token in Authorization header
|
|
2432
|
+
* Returns the appropriate SessionState based on token validation
|
|
2433
|
+
*
|
|
2434
|
+
* @param authHeader - Authorization header value (e.g., "Bearer <token>")
|
|
2435
|
+
* @param config - Configuration for session validation
|
|
2436
|
+
* @returns Promise resolving to SessionState
|
|
2437
|
+
*/
|
|
2438
|
+
async function validateSessionFromJWT(authHeader, config) {
|
|
2439
|
+
if (!authHeader?.startsWith("Bearer ")) return config.createUnauthenticatedState();
|
|
2440
|
+
try {
|
|
2441
|
+
const accessToken = authHeader.replace("Bearer ", "");
|
|
2442
|
+
const payload = await config.verifyToken(accessToken, config.env.ACCESS_JWT_SECRET);
|
|
2443
|
+
if (payload.exp < Math.floor(Date.now() / 1e3)) return config.createExpiredState();
|
|
2444
|
+
if (payload.type === "access" && payload.exp > Math.floor(Date.now() / 1e3)) {
|
|
2445
|
+
const globalRevokeTimestamp = config.getGlobalRevokeTimestamp?.(config.env);
|
|
2446
|
+
if (config.shouldRevokeTokens?.(config.env) && globalRevokeTimestamp && payload.iat < parseInt(globalRevokeTimestamp)) {
|
|
2447
|
+
config.logger?.warn("Token revoked by global timestamp", {
|
|
2448
|
+
issued_at: payload.iat,
|
|
2449
|
+
revoke_threshold: globalRevokeTimestamp
|
|
2450
|
+
});
|
|
2451
|
+
return config.createRevokedState();
|
|
2452
|
+
}
|
|
2453
|
+
const headers = config.getRequestHeaders?.() || {};
|
|
2454
|
+
const minimalSession = {
|
|
2455
|
+
id: payload.jti,
|
|
2456
|
+
created_at: (/* @__PURE__ */ new Date(payload.iat * 1e3)).toISOString(),
|
|
2457
|
+
expires_at: (/* @__PURE__ */ new Date(payload.exp * 1e3)).toISOString(),
|
|
2458
|
+
status: "active",
|
|
2459
|
+
user_agent: headers.userAgent || null,
|
|
2460
|
+
ip_address: headers.ipAddress || null,
|
|
2461
|
+
user: {
|
|
2462
|
+
userId: payload.sub,
|
|
2463
|
+
username: payload.username,
|
|
2464
|
+
email: payload.email,
|
|
2465
|
+
email_verified: payload.email_verified,
|
|
2466
|
+
user_type: payload.user_type,
|
|
2467
|
+
first_name: null,
|
|
2468
|
+
last_name: null,
|
|
2469
|
+
avatar_url: null,
|
|
2470
|
+
subscriptions: []
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
return config.createAuthenticatedState(minimalSession);
|
|
2474
|
+
}
|
|
2475
|
+
return config.createUnauthenticatedState();
|
|
2476
|
+
} catch (error) {
|
|
2477
|
+
config.logger?.error("Error validating session", {
|
|
2478
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2479
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
2480
|
+
});
|
|
2481
|
+
return config.createUnauthenticatedState();
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2429
2485
|
//#endregion
|
|
2430
2486
|
//#region src/middleware/container_setup_helpers.ts
|
|
2431
2487
|
/**
|
|
@@ -2521,9 +2577,7 @@ function createDefaultContainerSetupConfig(config) {
|
|
|
2521
2577
|
return {
|
|
2522
2578
|
createRequestContainer: config.createRequestContainer,
|
|
2523
2579
|
validateSession: async (authHeader) => {
|
|
2524
|
-
|
|
2525
|
-
const { validateSessionFromJWT: validateSessionFromJWT$1 } = await import("./session_validation-DYUZWJFy.mjs");
|
|
2526
|
-
return validateSessionFromJWT$1(authHeader, sessionConfig);
|
|
2580
|
+
return validateSessionFromJWT(authHeader, createDefaultSessionValidationConfig(config.env, config.ctx, getLogger, perfLog, config.sessionValidationOptions));
|
|
2527
2581
|
},
|
|
2528
2582
|
buildFactories: () => {
|
|
2529
2583
|
return buildContainerFactories({
|
|
@@ -2672,63 +2726,6 @@ function createIsAuthenticatedMiddleware(options) {
|
|
|
2672
2726
|
};
|
|
2673
2727
|
}
|
|
2674
2728
|
|
|
2675
|
-
//#endregion
|
|
2676
|
-
//#region src/middleware/session_validation.ts
|
|
2677
|
-
/**
|
|
2678
|
-
* Validates session from JWT token in Authorization header
|
|
2679
|
-
* Returns the appropriate SessionState based on token validation
|
|
2680
|
-
*
|
|
2681
|
-
* @param authHeader - Authorization header value (e.g., "Bearer <token>")
|
|
2682
|
-
* @param config - Configuration for session validation
|
|
2683
|
-
* @returns Promise resolving to SessionState
|
|
2684
|
-
*/
|
|
2685
|
-
async function validateSessionFromJWT(authHeader, config) {
|
|
2686
|
-
if (!authHeader?.startsWith("Bearer ")) return config.createUnauthenticatedState();
|
|
2687
|
-
try {
|
|
2688
|
-
const accessToken = authHeader.replace("Bearer ", "");
|
|
2689
|
-
const payload = await config.verifyToken(accessToken, config.env.ACCESS_JWT_SECRET);
|
|
2690
|
-
if (payload.exp < Math.floor(Date.now() / 1e3)) return config.createExpiredState();
|
|
2691
|
-
if (payload.type === "access" && payload.exp > Math.floor(Date.now() / 1e3)) {
|
|
2692
|
-
const globalRevokeTimestamp = config.getGlobalRevokeTimestamp?.(config.env);
|
|
2693
|
-
if (config.shouldRevokeTokens?.(config.env) && globalRevokeTimestamp && payload.iat < parseInt(globalRevokeTimestamp)) {
|
|
2694
|
-
config.logger?.warn("Token revoked by global timestamp", {
|
|
2695
|
-
issued_at: payload.iat,
|
|
2696
|
-
revoke_threshold: globalRevokeTimestamp
|
|
2697
|
-
});
|
|
2698
|
-
return config.createRevokedState();
|
|
2699
|
-
}
|
|
2700
|
-
const headers = config.getRequestHeaders?.() || {};
|
|
2701
|
-
const minimalSession = {
|
|
2702
|
-
id: payload.jti,
|
|
2703
|
-
created_at: (/* @__PURE__ */ new Date(payload.iat * 1e3)).toISOString(),
|
|
2704
|
-
expires_at: (/* @__PURE__ */ new Date(payload.exp * 1e3)).toISOString(),
|
|
2705
|
-
status: "active",
|
|
2706
|
-
user_agent: headers.userAgent || null,
|
|
2707
|
-
ip_address: headers.ipAddress || null,
|
|
2708
|
-
user: {
|
|
2709
|
-
userId: payload.sub,
|
|
2710
|
-
username: payload.username,
|
|
2711
|
-
email: payload.email,
|
|
2712
|
-
email_verified: payload.email_verified,
|
|
2713
|
-
user_type: payload.user_type,
|
|
2714
|
-
first_name: null,
|
|
2715
|
-
last_name: null,
|
|
2716
|
-
avatar_url: null,
|
|
2717
|
-
subscriptions: []
|
|
2718
|
-
}
|
|
2719
|
-
};
|
|
2720
|
-
return config.createAuthenticatedState(minimalSession);
|
|
2721
|
-
}
|
|
2722
|
-
return config.createUnauthenticatedState();
|
|
2723
|
-
} catch (error) {
|
|
2724
|
-
config.logger?.error("Error validating session", {
|
|
2725
|
-
error: error instanceof Error ? error.message : String(error),
|
|
2726
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
2727
|
-
});
|
|
2728
|
-
return config.createUnauthenticatedState();
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
2729
|
//#endregion
|
|
2733
2730
|
//#region src/db/schemas/app_setting/app_settings_table.ts
|
|
2734
2731
|
/**
|
|
@@ -3269,7 +3266,7 @@ const credit_transaction_table = sqliteTable("credit_transaction", {
|
|
|
3269
3266
|
|
|
3270
3267
|
//#endregion
|
|
3271
3268
|
//#region src/slices/customer/db/credit_transaction_query_config.ts
|
|
3272
|
-
const creditTransactionFields = createBackendRegistry
|
|
3269
|
+
const creditTransactionFields = createBackendRegistry({
|
|
3273
3270
|
type: {
|
|
3274
3271
|
type: "string",
|
|
3275
3272
|
filterable: true,
|
|
@@ -3314,8 +3311,8 @@ const creditTransactionFields = createBackendRegistry$1({
|
|
|
3314
3311
|
created_at: credit_transaction_table.created_at,
|
|
3315
3312
|
created_by: credit_transaction_table.created_by
|
|
3316
3313
|
});
|
|
3317
|
-
const creditTransactionColumnMap = deriveColumnMap
|
|
3318
|
-
const buildFieldFilters$3 = createFilterBuilder
|
|
3314
|
+
const creditTransactionColumnMap = deriveColumnMap(creditTransactionFields);
|
|
3315
|
+
const buildFieldFilters$3 = createFilterBuilder({
|
|
3319
3316
|
fieldRegistry: creditTransactionFields,
|
|
3320
3317
|
processedSeparately: []
|
|
3321
3318
|
});
|
|
@@ -3324,7 +3321,7 @@ const buildFieldFilters$3 = createFilterBuilder$1({
|
|
|
3324
3321
|
*/
|
|
3325
3322
|
function buildCreditTransactionQuery(filters) {
|
|
3326
3323
|
const fields = buildFieldFilters$3(filters).conditions;
|
|
3327
|
-
const search = searchOrCondition
|
|
3324
|
+
const search = searchOrCondition(filters?.search?.query, creditTransactionFields, filters?.search?.searchableFields);
|
|
3328
3325
|
return {
|
|
3329
3326
|
conditions: [...fields, ...search ? [search] : []],
|
|
3330
3327
|
skipQuery: false
|
|
@@ -3867,8 +3864,8 @@ const noteFields = {
|
|
|
3867
3864
|
sortable: false
|
|
3868
3865
|
}
|
|
3869
3866
|
};
|
|
3870
|
-
const noteColumnMap = deriveColumnMap
|
|
3871
|
-
const buildFieldFilters$2 = createFilterBuilder
|
|
3867
|
+
const noteColumnMap = deriveColumnMap(noteFields);
|
|
3868
|
+
const buildFieldFilters$2 = createFilterBuilder({
|
|
3872
3869
|
fieldRegistry: noteFields,
|
|
3873
3870
|
processedSeparately: ["archived_at"]
|
|
3874
3871
|
});
|
|
@@ -3877,9 +3874,9 @@ const buildFieldFilters$2 = createFilterBuilder$1({
|
|
|
3877
3874
|
*/
|
|
3878
3875
|
function buildNoteQuery(filters) {
|
|
3879
3876
|
const softDelete = isNull(note_table.deleted_at);
|
|
3880
|
-
const archive = archiveConditions
|
|
3877
|
+
const archive = archiveConditions(filters, note_table.archived_at);
|
|
3881
3878
|
const fields = buildFieldFilters$2(filters).conditions;
|
|
3882
|
-
const search = searchOrCondition
|
|
3879
|
+
const search = searchOrCondition(filters?.search?.query, noteFields, filters?.search?.searchableFields);
|
|
3883
3880
|
return {
|
|
3884
3881
|
conditions: [
|
|
3885
3882
|
softDelete,
|
|
@@ -4990,8 +4987,8 @@ const supportTicketFields = {
|
|
|
4990
4987
|
sortable: false
|
|
4991
4988
|
}
|
|
4992
4989
|
};
|
|
4993
|
-
const supportTicketColumnMap = deriveColumnMap
|
|
4994
|
-
const buildFieldFilters$1 = createFilterBuilder
|
|
4990
|
+
const supportTicketColumnMap = deriveColumnMap(supportTicketFields);
|
|
4991
|
+
const buildFieldFilters$1 = createFilterBuilder({
|
|
4995
4992
|
fieldRegistry: supportTicketFields,
|
|
4996
4993
|
processedSeparately: [
|
|
4997
4994
|
"archived_at",
|
|
@@ -5031,9 +5028,9 @@ function mapSupportTicketStatusToApprovalStatus(statuses) {
|
|
|
5031
5028
|
*/
|
|
5032
5029
|
function buildSupportTicketQuery(filters) {
|
|
5033
5030
|
const softDelete = isNull(support_ticket_table.deleted_at);
|
|
5034
|
-
const archive = archiveConditions
|
|
5031
|
+
const archive = archiveConditions(filters, support_ticket_table.archived_at);
|
|
5035
5032
|
const fields = buildFieldFilters$1(filters).conditions;
|
|
5036
|
-
const search = searchOrCondition
|
|
5033
|
+
const search = searchOrCondition(filters?.search?.query, supportTicketFields, filters?.search?.searchableFields);
|
|
5037
5034
|
const conditions = [
|
|
5038
5035
|
softDelete,
|
|
5039
5036
|
...archive,
|
|
@@ -6928,15 +6925,15 @@ const teamMemberFields = {
|
|
|
6928
6925
|
sortable: true
|
|
6929
6926
|
}
|
|
6930
6927
|
};
|
|
6931
|
-
const teamMemberColumnMap = deriveColumnMap
|
|
6932
|
-
const buildFieldFilters = createFilterBuilder
|
|
6928
|
+
const teamMemberColumnMap = deriveColumnMap(teamMemberFields);
|
|
6929
|
+
const buildFieldFilters = createFilterBuilder({ fieldRegistry: teamMemberFields });
|
|
6933
6930
|
/**
|
|
6934
6931
|
* Build team member query conditions from filters
|
|
6935
6932
|
*/
|
|
6936
6933
|
function buildTeamMemberQuery(filters) {
|
|
6937
6934
|
const softDelete = isNull(team_member_table.deleted_at);
|
|
6938
6935
|
const fields = buildFieldFilters(filters).conditions;
|
|
6939
|
-
const search = searchOrCondition
|
|
6936
|
+
const search = searchOrCondition(filters?.search?.query, teamMemberFields, filters?.search?.searchableFields);
|
|
6940
6937
|
return {
|
|
6941
6938
|
conditions: [
|
|
6942
6939
|
softDelete,
|