@axiumine/koa-utils 7.2.0 → 8.1.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 +40 -13
- package/dist/dataSources/MariaDB.mjs +3 -3
- package/dist/dataSources/MongoDB.mjs +2 -2
- package/dist/dataSources/PostgreSQL.mjs +3 -3
- package/dist/dataSources/Redis.mjs +3 -3
- package/dist/email/ISocketLabsClient.d.mts +8 -0
- package/dist/email/ISocketLabsClient.mjs +2 -0
- package/dist/email/ISocketLabsMessage.d.mts +20 -0
- package/dist/email/ISocketLabsMessage.mjs +4 -0
- package/dist/email/ISocketLabsSendResult.d.mts +12 -0
- package/dist/email/ISocketLabsSendResult.mjs +2 -0
- package/dist/email/ISocketLabsSenderOptions.d.mts +30 -0
- package/dist/email/ISocketLabsSenderOptions.mjs +3 -0
- package/dist/email/SocketLabsLib.d.mts +1 -0
- package/dist/email/SocketLabsLib.mjs +30 -21
- package/dist/email/createSocketLabsSender.d.mts +20 -0
- package/dist/email/createSocketLabsSender.mjs +66 -0
- package/dist/files/scanVirus.mjs +1 -1
- package/dist/files/storeUploadAsTemp.mjs +2 -2
- package/dist/graphQL/schema/mutations/login4Ever.mjs +1 -1
- package/dist/graphQL/schema/mutations/loginAdmin.mjs +1 -1
- package/dist/graphQL/schema/mutations/loginRememberme.mjs +1 -1
- package/dist/graphQL/schema/mutations/logout.mjs +3 -3
- package/dist/graphQL/schema/mutations/refresh.mjs +3 -3
- package/dist/graphQL/schema/mutations/resetPwd.mjs +1 -1
- package/dist/graphQL/schema/mutations/updatePassword.mjs +1 -1
- package/dist/koa/IKoaErrorHandlerContext.d.mts +11 -0
- package/dist/koa/IKoaErrorHandlerContext.mjs +2 -0
- package/dist/koa/IKoaErrorHandlerOptions.d.mts +28 -0
- package/dist/koa/IKoaErrorHandlerOptions.mjs +3 -0
- package/dist/koa/createKoaErrorHandler.d.mts +11 -0
- package/dist/koa/createKoaErrorHandler.mjs +37 -0
- package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs +2 -2
- package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs +2 -2
- package/dist/koa/middleware/authenticatedResourceHandler/index.mjs +2 -2
- package/dist/koa/tdwKoaErrorHandler.mjs +15 -23
- package/dist/lib/Constants.d.mts +0 -2
- package/dist/lib/Constants.mjs +0 -2
- package/dist/lib/MongoDB/throwMongoErrors.mjs +1 -1
- package/dist/lib/OBJECTID_0_OBJ.d.mts +6 -0
- package/dist/lib/OBJECTID_0_OBJ.mjs +8 -0
- package/dist/lib/PostgreSQL/clock/CLOCK_SQL.d.mts +7 -0
- package/dist/lib/PostgreSQL/clock/CLOCK_SQL.mjs +8 -0
- package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.d.mts +5 -0
- package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.mjs +6 -0
- package/dist/lib/PostgreSQL/clock/IClock.d.mts +4 -0
- package/dist/lib/PostgreSQL/clock/IClock.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/IDbClock.d.mts +11 -0
- package/dist/lib/PostgreSQL/clock/IDbClock.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/IDbClockOptions.d.mts +11 -0
- package/dist/lib/PostgreSQL/clock/IDbClockOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/IDbClockSeam.d.mts +10 -0
- package/dist/lib/PostgreSQL/clock/IDbClockSeam.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/createDbClock.d.mts +23 -0
- package/dist/lib/PostgreSQL/clock/createDbClock.mjs +54 -0
- package/dist/lib/PostgreSQL/clock/lockTaken.d.mts +11 -0
- package/dist/lib/PostgreSQL/clock/lockTaken.mjs +17 -0
- package/dist/lib/PostgreSQL/counter/IDbCounter.d.mts +9 -0
- package/dist/lib/PostgreSQL/counter/IDbCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.d.mts +12 -0
- package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.mjs +20 -0
- package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.mjs +12 -0
- package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.d.mts +23 -0
- package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.mjs +35 -0
- package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.d.mts +13 -0
- package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.mjs +14 -0
- package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.mjs +8 -0
- package/dist/lib/PostgreSQL/error/DB_TX_REASONS.d.mts +9 -0
- package/dist/lib/PostgreSQL/error/DB_TX_REASONS.mjs +10 -0
- package/dist/lib/PostgreSQL/error/DbClockError.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/DbClockError.mjs +27 -0
- package/dist/lib/PostgreSQL/error/DbConnectError.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/DbConnectError.mjs +18 -0
- package/dist/lib/PostgreSQL/error/DbParseError.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/DbParseError.mjs +16 -0
- package/dist/lib/PostgreSQL/error/DbStateError.d.mts +10 -0
- package/dist/lib/PostgreSQL/error/DbStateError.mjs +14 -0
- package/dist/lib/PostgreSQL/error/DbTxError.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/DbTxError.mjs +10 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntry.d.mts +17 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntry.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.d.mts +20 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IConstraintTable.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/IConstraintTable.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbClockReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbClockReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbConnectReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbConnectReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounter.d.mts +4 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounterName.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounterName.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbErrorFactory.d.mts +16 -0
- package/dist/lib/PostgreSQL/error/IDbErrorFactory.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbInternalReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbInternalReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbParseReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbParseReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbStateReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbStateReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbTxReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbTxReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/ILockOrderReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/ILockOrderReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.d.mts +22 -0
- package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.d.mts +12 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.mjs +2 -0
- package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.mjs +12 -0
- package/dist/lib/PostgreSQL/error/LockOrderError.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/LockOrderError.mjs +10 -0
- package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.d.mts +21 -0
- package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.mjs +35 -0
- package/dist/lib/PostgreSQL/error/RoleAssertionError.d.mts +19 -0
- package/dist/lib/PostgreSQL/error/RoleAssertionError.mjs +58 -0
- package/dist/lib/PostgreSQL/error/buildConstraintEntry.d.mts +15 -0
- package/dist/lib/PostgreSQL/error/buildConstraintEntry.mjs +16 -0
- package/dist/lib/PostgreSQL/error/constraintNameOf.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/constraintNameOf.mjs +17 -0
- package/dist/lib/PostgreSQL/error/errorNameOf.d.mts +5 -0
- package/dist/lib/PostgreSQL/error/errorNameOf.mjs +12 -0
- package/dist/lib/PostgreSQL/error/lookupConstraint.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/lookupConstraint.mjs +8 -0
- package/dist/lib/PostgreSQL/error/mapDbError.d.mts +28 -0
- package/dist/lib/PostgreSQL/error/mapDbError.mjs +52 -0
- package/dist/lib/PostgreSQL/error/sqlstateField.d.mts +4 -0
- package/dist/lib/PostgreSQL/error/sqlstateField.mjs +5 -0
- package/dist/lib/PostgreSQL/error/sqlstateOf.d.mts +5 -0
- package/dist/lib/PostgreSQL/error/sqlstateOf.mjs +12 -0
- package/dist/lib/PostgreSQL/guard/IAffectedResult.d.mts +4 -0
- package/dist/lib/PostgreSQL/guard/IAffectedResult.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IGuardCounter.d.mts +3 -0
- package/dist/lib/PostgreSQL/guard/IGuardCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardCode.d.mts +5 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardCode.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardField.d.mts +3 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardField.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardInput.d.mts +29 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardInput.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.d.mts +2 -0
- package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.mjs +3 -0
- package/dist/lib/PostgreSQL/guard/assertAffected.d.mts +10 -0
- package/dist/lib/PostgreSQL/guard/assertAffected.mjs +17 -0
- package/dist/lib/PostgreSQL/guard/guardVersion.d.mts +21 -0
- package/dist/lib/PostgreSQL/guard/guardVersion.mjs +47 -0
- package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.d.mts +2 -0
- package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.mjs +3 -0
- package/dist/lib/PostgreSQL/lock/IClaimRegistry.d.mts +6 -0
- package/dist/lib/PostgreSQL/lock/IClaimRegistry.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/IClaimRequest.d.mts +7 -0
- package/dist/lib/PostgreSQL/lock/IClaimRequest.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockAdmission.d.mts +4 -0
- package/dist/lib/PostgreSQL/lock/ILockAdmission.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderSpec.d.mts +19 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderSpec.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderTracker.d.mts +41 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderTracker.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.d.mts +5 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.d.mts +7 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/IRowLockMode.d.mts +3 -0
- package/dist/lib/PostgreSQL/lock/IRowLockMode.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.d.mts +2 -0
- package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.mjs +3 -0
- package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.d.mts +16 -0
- package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.mjs +32 -0
- package/dist/lib/PostgreSQL/lock/createLockOrderTracker.d.mts +14 -0
- package/dist/lib/PostgreSQL/lock/createLockOrderTracker.mjs +60 -0
- package/dist/lib/PostgreSQL/lock/lockedRow.d.mts +7 -0
- package/dist/lib/PostgreSQL/lock/lockedRow.mjs +12 -0
- package/dist/lib/PostgreSQL/lock/lockedRows.d.mts +3 -0
- package/dist/lib/PostgreSQL/lock/lockedRows.mjs +8 -0
- package/dist/lib/PostgreSQL/lock/rowLockModeOf.d.mts +3 -0
- package/dist/lib/PostgreSQL/lock/rowLockModeOf.mjs +9 -0
- package/dist/lib/PostgreSQL/lock/uuidOf.d.mts +2 -0
- package/dist/lib/PostgreSQL/lock/uuidOf.mjs +10 -0
- package/dist/lib/PostgreSQL/lock/uuidsOf.d.mts +5 -0
- package/dist/lib/PostgreSQL/lock/uuidsOf.mjs +13 -0
- package/dist/lib/PostgreSQL/parse/IArrayParser.d.mts +2 -0
- package/dist/lib/PostgreSQL/parse/IArrayParser.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/IDriverTypes.d.mts +4 -0
- package/dist/lib/PostgreSQL/parse/IDriverTypes.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/IStringParser.d.mts +2 -0
- package/dist/lib/PostgreSQL/parse/IStringParser.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/ITypeParserEntry.d.mts +9 -0
- package/dist/lib/PostgreSQL/parse/ITypeParserEntry.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.d.mts +12 -0
- package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.mjs +38 -0
- package/dist/lib/PostgreSQL/parse/arrayOf.d.mts +7 -0
- package/dist/lib/PostgreSQL/parse/arrayOf.mjs +50 -0
- package/dist/lib/PostgreSQL/parse/createTypeRegistry.d.mts +13 -0
- package/dist/lib/PostgreSQL/parse/createTypeRegistry.mjs +26 -0
- package/dist/lib/PostgreSQL/parse/parseDate.d.mts +7 -0
- package/dist/lib/PostgreSQL/parse/parseDate.mjs +19 -0
- package/dist/lib/PostgreSQL/parse/parseInt8.d.mts +6 -0
- package/dist/lib/PostgreSQL/parse/parseInt8.mjs +17 -0
- package/dist/lib/PostgreSQL/parse/parseTime.d.mts +7 -0
- package/dist/lib/PostgreSQL/parse/parseTime.mjs +24 -0
- package/dist/lib/PostgreSQL/parse/parseTimestamptz.d.mts +17 -0
- package/dist/lib/PostgreSQL/parse/parseTimestamptz.mjs +79 -0
- package/dist/lib/PostgreSQL/parse/parseUuid.d.mts +3 -0
- package/dist/lib/PostgreSQL/parse/parseUuid.mjs +9 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.d.mts +28 -0
- package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IDbDriver.d.mts +12 -0
- package/dist/lib/PostgreSQL/pool/IDbDriver.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounter.d.mts +4 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounterName.d.mts +7 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounterName.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolEvents.d.mts +4 -0
- package/dist/lib/PostgreSQL/pool/IPoolEvents.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolLogger.d.mts +8 -0
- package/dist/lib/PostgreSQL/pool/IPoolLogger.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.d.mts +2 -0
- package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.mjs +3 -0
- package/dist/lib/PostgreSQL/pool/createPool.d.mts +31 -0
- package/dist/lib/PostgreSQL/pool/createPool.mjs +67 -0
- package/dist/lib/PostgreSQL/role/IAssertRoleOptions.d.mts +10 -0
- package/dist/lib/PostgreSQL/role/IAssertRoleOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/role/IRoleAssertion.d.mts +6 -0
- package/dist/lib/PostgreSQL/role/IRoleAssertion.mjs +2 -0
- package/dist/lib/PostgreSQL/role/IRoleGrant.d.mts +19 -0
- package/dist/lib/PostgreSQL/role/IRoleGrant.mjs +2 -0
- package/dist/lib/PostgreSQL/role/IRolePool.d.mts +6 -0
- package/dist/lib/PostgreSQL/role/IRolePool.mjs +2 -0
- package/dist/lib/PostgreSQL/role/assertRole.d.mts +36 -0
- package/dist/lib/PostgreSQL/role/assertRole.mjs +54 -0
- package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/IRetryDelay.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/IRetryDelay.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITx.d.mts +9 -0
- package/dist/lib/PostgreSQL/tx/ITx.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxClient.d.mts +12 -0
- package/dist/lib/PostgreSQL/tx/ITxClient.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxCounter.d.mts +4 -0
- package/dist/lib/PostgreSQL/tx/ITxCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxCounterName.d.mts +10 -0
- package/dist/lib/PostgreSQL/tx/ITxCounterName.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxFailureReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/tx/ITxFailureReason.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxIsolation.d.mts +3 -0
- package/dist/lib/PostgreSQL/tx/ITxIsolation.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxOptions.d.mts +27 -0
- package/dist/lib/PostgreSQL/tx/ITxOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxPool.d.mts +5 -0
- package/dist/lib/PostgreSQL/tx/ITxPool.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxResult.d.mts +6 -0
- package/dist/lib/PostgreSQL/tx/ITxResult.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.d.mts +7 -0
- package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.mjs +8 -0
- package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/defaultRetryDelay.d.mts +3 -0
- package/dist/lib/PostgreSQL/tx/defaultRetryDelay.mjs +4 -0
- package/dist/lib/PostgreSQL/tx/jitteredDelay.d.mts +7 -0
- package/dist/lib/PostgreSQL/tx/jitteredDelay.mjs +16 -0
- package/dist/lib/PostgreSQL/tx/withTx.d.mts +39 -0
- package/dist/lib/PostgreSQL/tx/withTx.mjs +41 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.d.mts +10 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.d.mts +14 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.mjs +2 -0
- package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.d.mts +2 -0
- package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.mjs +3 -0
- package/dist/lib/PostgreSQL/url/databaseUrlReason.d.mts +20 -0
- package/dist/lib/PostgreSQL/url/databaseUrlReason.mjs +99 -0
- package/dist/lib/PostgreSQL/url/isAbsolutePath.d.mts +2 -0
- package/dist/lib/PostgreSQL/url/isAbsolutePath.mjs +14 -0
- package/dist/lib/PostgreSQL/url/isValidHost.d.mts +6 -0
- package/dist/lib/PostgreSQL/url/isValidHost.mjs +20 -0
- package/dist/lib/tokenOptions.mjs +2 -2
- package/dist/lib/tokens.mjs +3 -2
- package/dist/lib/tryCatchRethrow.mjs +1 -1
- package/dist/private/email/orFalse.mjs +1 -1
- package/dist/private/files/reEncode.mjs +1 -1
- package/dist/private/graphQL/schema/mutations/setLastLoginSQL.mjs +1 -1
- package/dist/private/graphQL/schema/mutations/setRedisLoginSession.mjs +3 -3
- package/dist/private/lib/ISentryClient.d.mts +10 -0
- package/dist/private/lib/ISentryClient.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ICivilDate.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/ICivilDate.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IClientConstructor.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/IClientConstructor.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IClientShape.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/IClientShape.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IClockSlot.d.mts +11 -0
- package/dist/private/lib/PostgreSQL/IClockSlot.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IConnectCallback.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/IConnectCallback.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IConnectSettings.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/IConnectSettings.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IHelperRank.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/IHelperRank.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IInternalSink.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/IInternalSink.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ILockOrderPlan.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/ILockOrderPlan.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IModeOrder.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/IModeOrder.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IPostgresState.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/IPostgresState.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleCheck.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/IRoleCheck.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleColumnCheck.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/IRoleColumnCheck.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleObjectCheck.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/IRoleObjectCheck.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRolePlan.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/IRolePlan.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleRow.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/IRoleRow.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ITrackerState.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/ITrackerState.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ITxHandleState.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/ITxHandleState.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ITxSettings.d.mts +14 -0
- package/dist/private/lib/PostgreSQL/ITxSettings.mjs +2 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.mjs +6 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.mjs +7 -0
- package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.mjs +9 -0
- package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.d.mts +26 -0
- package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.mjs +84 -0
- package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.mjs +7 -0
- package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.mjs +11 -0
- package/dist/private/lib/PostgreSQL/admitLock.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/admitLock.mjs +33 -0
- package/dist/private/lib/PostgreSQL/assertPoolOptions.d.mts +12 -0
- package/dist/private/lib/PostgreSQL/assertPoolOptions.mjs +19 -0
- package/dist/private/lib/PostgreSQL/assertVersionGuardInput.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/assertVersionGuardInput.mjs +14 -0
- package/dist/private/lib/PostgreSQL/catalogFlag.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/catalogFlag.mjs +7 -0
- package/dist/private/lib/PostgreSQL/catalogRow.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/catalogRow.mjs +11 -0
- package/dist/private/lib/PostgreSQL/catalogRows.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/catalogRows.mjs +12 -0
- package/dist/private/lib/PostgreSQL/catalogText.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/catalogText.mjs +7 -0
- package/dist/private/lib/PostgreSQL/checkRoleOnClient.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/checkRoleOnClient.mjs +31 -0
- package/dist/private/lib/PostgreSQL/checkedClient.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/checkedClient.mjs +22 -0
- package/dist/private/lib/PostgreSQL/civilCalendar.d.mts +13 -0
- package/dist/private/lib/PostgreSQL/civilCalendar.mjs +48 -0
- package/dist/private/lib/PostgreSQL/clockInstant.d.mts +11 -0
- package/dist/private/lib/PostgreSQL/clockInstant.mjs +18 -0
- package/dist/private/lib/PostgreSQL/clockSlot.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/clockSlot.mjs +11 -0
- package/dist/private/lib/PostgreSQL/clockStatement.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/clockStatement.mjs +22 -0
- package/dist/private/lib/PostgreSQL/connectAndCheck.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/connectAndCheck.mjs +47 -0
- package/dist/private/lib/PostgreSQL/constraintDetails.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/constraintDetails.mjs +21 -0
- package/dist/private/lib/PostgreSQL/constraintField.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/constraintField.mjs +5 -0
- package/dist/private/lib/PostgreSQL/errorCodeOf.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/errorCodeOf.mjs +7 -0
- package/dist/private/lib/PostgreSQL/internalFailure.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/internalFailure.mjs +10 -0
- package/dist/private/lib/PostgreSQL/isNameList.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isNameList.mjs +6 -0
- package/dist/private/lib/PostgreSQL/isOneOf.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isOneOf.mjs +5 -0
- package/dist/private/lib/PostgreSQL/isQualifiedName.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isQualifiedName.mjs +7 -0
- package/dist/private/lib/PostgreSQL/isRoleName.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isRoleName.mjs +7 -0
- package/dist/private/lib/PostgreSQL/lockOrderPlan.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/lockOrderPlan.mjs +66 -0
- package/dist/private/lib/PostgreSQL/mapTypedError.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/mapTypedError.mjs +28 -0
- package/dist/private/lib/PostgreSQL/mapViolation.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/mapViolation.mjs +32 -0
- package/dist/private/lib/PostgreSQL/membershipOutsider.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/membershipOutsider.mjs +17 -0
- package/dist/private/lib/PostgreSQL/missingColumn.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/missingColumn.mjs +15 -0
- package/dist/private/lib/PostgreSQL/missingGrant.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/missingGrant.mjs +7 -0
- package/dist/private/lib/PostgreSQL/missingObject.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/missingObject.mjs +14 -0
- package/dist/private/lib/PostgreSQL/poolUrlSecrets.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/poolUrlSecrets.mjs +41 -0
- package/dist/private/lib/PostgreSQL/postgresState.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/postgresState.mjs +32 -0
- package/dist/private/lib/PostgreSQL/rankCheckOption.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/rankCheckOption.mjs +7 -0
- package/dist/private/lib/PostgreSQL/readField.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/readField.mjs +10 -0
- package/dist/private/lib/PostgreSQL/roleCheckOf.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/roleCheckOf.mjs +39 -0
- package/dist/private/lib/PostgreSQL/roleFailureSubject.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/roleFailureSubject.mjs +12 -0
- package/dist/private/lib/PostgreSQL/rolePlan.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/rolePlan.mjs +26 -0
- package/dist/private/lib/PostgreSQL/runRoleChecks.d.mts +17 -0
- package/dist/private/lib/PostgreSQL/runRoleChecks.mjs +48 -0
- package/dist/private/lib/PostgreSQL/runTxAttempt.d.mts +12 -0
- package/dist/private/lib/PostgreSQL/runTxAttempt.mjs +50 -0
- package/dist/private/lib/PostgreSQL/runTxBody.d.mts +11 -0
- package/dist/private/lib/PostgreSQL/runTxBody.mjs +19 -0
- package/dist/private/lib/PostgreSQL/runTxWithRetries.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/runTxWithRetries.mjs +31 -0
- package/dist/private/lib/PostgreSQL/scrubSecrets.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/scrubSecrets.mjs +6 -0
- package/dist/private/lib/PostgreSQL/txFailure.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/txFailure.mjs +7 -0
- package/dist/private/lib/PostgreSQL/txHandle.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/txHandle.mjs +26 -0
- package/dist/private/lib/PostgreSQL/txSettings.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/txSettings.mjs +48 -0
- package/dist/private/lib/PostgreSQL/versionText.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/versionText.mjs +12 -0
- package/dist/private/lib/access/assertResetAllowed.mjs +1 -1
- package/dist/private/lib/access/db/deleteUserByEmail.mjs +1 -1
- package/dist/private/lib/access/db/enableEmailAccess.mjs +1 -1
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs +1 -1
- package/dist/private/lib/access/handleBadDB.mjs +1 -1
- package/dist/private/lib/createSentryClient.d.mts +7 -0
- package/dist/private/lib/createSentryClient.mjs +20 -0
- package/dist/private/lib/importOptional.d.mts +7 -0
- package/dist/private/lib/importOptional.mjs +27 -0
- package/dist/private/lib/loadEnv.d.mts +12 -0
- package/dist/private/lib/loadEnv.mjs +14 -0
- package/dist/private/lib/sentry.d.mts +3 -0
- package/dist/private/lib/sentry.mjs +12 -0
- package/package.json +563 -7
package/README.md
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
TypeScript utility library for Koa + GraphQL backends. Ships authentication middleware, GraphQL error helpers, data-source connectors (MongoDB, MariaDB, PostgreSQL, Redis), file upload pipeline (ClamAV + sharp re-encode), and transactional email via SocketLabs.
|
|
7
7
|
|
|
8
8
|
- **Module format:** ESM only (`.mjs` + `.d.mts`)
|
|
9
|
-
- **Node:** `^24.14.0`
|
|
9
|
+
- **Node:** `^24.14.0 || ^26.13.0` (24 and 26 are the LTS lines; the suite runs on both)
|
|
10
10
|
- **TypeScript:** `6.0`
|
|
11
11
|
- **License:** GPL-3.0-or-later
|
|
12
|
-
- **
|
|
12
|
+
- **Maintainers:** [Giovanni Manzoni](https://www.giovannimanzoni.com) and [Vincenzo Favara](https://github.com/vivi7)
|
|
13
13
|
- **Project:** [Contributing](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) · [Governance](https://github.com/Axiumine/koa-utils/blob/main/GOVERNANCE.md) · [Roadmap](https://github.com/Axiumine/koa-utils/blob/main/ROADMAP.md) · [Security policy](https://github.com/Axiumine/koa-utils/blob/main/SECURITY.md) · [Code of Conduct](https://github.com/Axiumine/koa-utils/blob/main/CODE_OF_CONDUCT.md) · [Changelog](https://github.com/Axiumine/koa-utils/blob/main/CHANGELOG.md)
|
|
14
14
|
|
|
15
15
|
## Install
|
|
@@ -22,17 +22,19 @@ npm install @axiumine/koa-utils
|
|
|
22
22
|
|
|
23
23
|
All runtime dependencies are declared as **peer dependencies** — the package ships zero `dependencies`, so the consuming project owns every installed version.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
**Every peer is optional** (`peerDependenciesMeta`, since 8.0.0). npm 7+ and Yarn no longer install any of them for you, and they do not warn about a missing one. There is no barrel export: each peer is reachable only through the subpaths that need it, so install the rows for the subpaths you import. A subpath whose peer is missing fails at import with `ERR_MODULE_NOT_FOUND`, except `@sentry/node` and `dotenv` (see below). The auth core (sign-up, the login variants, refresh, logout, the middleware, the models and the error helpers) reaches `@node-rs/bcrypt`, `graphql`, `mongoose` and `redis`:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
yarn add @node-rs/bcrypt
|
|
28
|
+
yarn add @node-rs/bcrypt graphql mongoose redis
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| Optional peer | Required by |
|
|
31
|
+
| Peer | Needed by (fails at import with `ERR_MODULE_NOT_FOUND` if missing) |
|
|
34
32
|
|---|---|
|
|
35
|
-
| `@
|
|
33
|
+
| `@node-rs/bcrypt` | the password flows: `lib/encryptPassword`, `lib/hash`, `lib/db/registerNewUser`, `lib/access/createResetPwdFlow`, and the `signUp` / `login*` / `updatePassword` mutations |
|
|
34
|
+
| `graphql` | `graphQL/throw/*`, `graphQL/schema/types/*`, `graphQL/schema/GraphQLInput/*`, the mutations, and every subpath that raises a `GraphQLError` through a `throw*` helper: `lib/checkEmailLen`, `lib/checkPwdLen`, `lib/tryCatchRethrow`, `lib/MongoDB/*`, `lib/MariaDB/throwSqlErrors`, `lib/throwIfNotValidEnumValue`, `lib/access/create*Flow`, `lib/access/*Mailer`, `koa/customFormatErrorFn`, `koa/tdwKoaErrorHandler`, the `koa/middleware/*` handlers, `koa/router/verifyEmail`, `email/SocketLabsLib`, `files/uploadTempImage` and `files/reEncodeTo*` |
|
|
35
|
+
| `mongoose` | `dataSources/MongoDB`, the models (`graphQL/models/MongoDB/*`), the mutations other than `logout` and `refresh`, `lib/db/*`, `lib/OBJECTID_0_OBJ`, `lib/access/create*Flow`, `koa/router/verifyEmail`, `koa/middleware/authenticatedAuthorizationHandler`, `koa/middleware/authenticatedResourceHandler` (its types are also named by a few `.d.mts` files) |
|
|
36
|
+
| `redis` | `dataSources/Redis`, the `login*` / `logout` / `refresh` mutations, `koa/middleware/authenticatedAuthorizationHandler`, `koa/middleware/authenticatedLogoutHandler`, `koa/middleware/authenticatedResourceHandler` |
|
|
37
|
+
| `@socketlabs/email` | `email/SocketLabsLib`, `email/createSocketLabsSender`, `lib/access/createResetPwdFlow`, `lib/access/createVerifyEmailFlow`, `lib/access/resetPwdMailer`, `lib/access/verifyEmailMailer`, `koa/router/verifyEmail`, and the `signUp` / `login*` / `resetPwd` / `updatePassword` / `emailChangeHashVerify` mutations |
|
|
36
38
|
| `clamscan` | `files/scanVirus`, `files/uploadTempImage`, `files/uploadTempPdf` |
|
|
37
39
|
| `file-type` | `files/validateMimeType`, `files/validateMimeTypeImages`, `files/validateJpgPngMimeType`, `files/uploadTempImage`, `files/uploadTempPdf` — loaded lazily, at first call |
|
|
38
40
|
| `fs-extra` | the `files/move*` and `files/validate*` helpers, `files/uploadTempImage`, `files/uploadTempPdf` |
|
|
@@ -45,14 +47,29 @@ The remaining twelve are declared **optional** in `peerDependenciesMeta`. There
|
|
|
45
47
|
| `sequelize-typescript` | `dataSources/MariaDB` |
|
|
46
48
|
| `sharp` | `files/reEncodeToJpeg`, `files/reEncodeToPng`, `files/reEncodeToWebp`, `files/uploadTempImage` |
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
A subpath that reaches no peer needs nothing installed, not even `koa` (it appears there only as a type you pass in): `koa/createKoaErrorHandler`, a Koa error middleware you configure with `statusOf`, `bodyOf`, `report` and `noBodyStatuses`, and its two type files `koa/IKoaErrorHandlerOptions` and `koa/IKoaErrorHandlerContext`. `koa/tdwKoaErrorHandler` is the same middleware preconfigured for GraphQL errors, Sentry and dotenv, which is why it needs the peers above.
|
|
51
|
+
|
|
52
|
+
`email/createSocketLabsSender` needs only `@socketlabs/email`: it builds a function that sends one mail you composed, with your own `serverId` and `apiKey`, and returns `{ ok: true }` or `{ ok: false, code }` instead of throwing on a rejected send. It reads no environment variable and loads no Sentry, no dotenv and no `graphql`; its four type files (`email/ISocketLabsSenderOptions`, `ISocketLabsMessage`, `ISocketLabsSendResult`, `ISocketLabsClient`) need nothing installed. `email/SocketLabsLib` sends through it and adds the copy, the HTML template, the environment variables and the Sentry report.
|
|
53
|
+
|
|
54
|
+
The PostgreSQL kit under `lib/PostgreSQL/{error,parse,pool,url,counter,tx,guard,role,clock,lock}/` reaches no peer either, `pg` included: `lib/PostgreSQL/pool/createPool` takes the `pg` module you imported as its `driver` argument and talks to it through structural types, so you install `pg` yourself for your own code and the kit never imports it. It holds the pool factory (URL allow-list, `SHOW timezone` must answer `UTC`, one connect deadline, a listener for idle-client errors), `lib/PostgreSQL/tx/withTx` (one transaction wrapper: closed `BEGIN`, `SET LOCAL lock_timeout`, a bounded retry on deadlocks and serialisation failures, and an error factory you pass in), string parsers for `date`, `time`, `timestamptz`, `int8`, `uuid` and arrays of them that never build a `Date`, closed-reason `DbParseError`, `DbConnectError` and `DbTxError`, SQLSTATE readers, `lib/PostgreSQL/error/mapDbError` (turns any driver failure into an error of your own family through a constraint table you pass in, and logs a closed reason, never the driver text), `lib/PostgreSQL/guard/assertAffected` and `guardVersion` (say why an update matched no row), `lib/PostgreSQL/role/assertRole` (a boot check that the connected database role has no dangerous attribute, owns nothing, has no unlisted membership and holds the grants you list, with a closed-reason `RoleAssertionError`), `lib/PostgreSQL/clock/createDbClock` (the server time read once per transaction, which a write transaction may read only after a lock), `lib/PostgreSQL/lock/createLockOrderTracker` (the order of the locks of a transaction from a spec you give, checked before each statement) with the small parts for writing your own lock helpers (the kit exports no lock clause), and `databaseUrlReason`, a strict check for a database URL. See [docs/code/lib-postgres.md](https://github.com/Axiumine/koa-utils/blob/main/docs/code/lib-postgres.md).
|
|
55
|
+
|
|
56
|
+
Two peers do not make a subpath fail when they are missing, because the package loads them only if they are installed:
|
|
57
|
+
|
|
58
|
+
| Peer | Used by | Without it |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `@sentry/node` | every subpath that reports a caught error: the auth mutations and middleware, `dataSources/MariaDB`, `dataSources/PostgreSQL`, `dataSources/Redis`, `email/SocketLabsLib`, `files/scanVirus`, `files/reEncodeTo*`, `files/uploadTemp*`, `lib/tryCatchRethrow`, `lib/MongoDB/throwMongoErrors`, `koa/router/verifyEmail`, `koa/tdwKoaErrorHandler`, the `lib/access/*` flows | nothing is reported; the call is skipped and the code after it runs as before |
|
|
61
|
+
| `dotenv` | every subpath that reads the environment file at import: the data sources, `email/SocketLabsLib`, `lib/tokenOptions`, `lib/setLoginCookies`, the `lib/access/*` flows, the auth mutations and middleware, `koa/router/verifyEmail`, `koa/tdwKoaErrorHandler` | no environment file is read; `process.env` must already hold your settings |
|
|
62
|
+
|
|
63
|
+
Before 8.0.0 both were installed for you and their absence was an import error. `test/__snapshots__/peer-reach.json` is the exact, machine-checked version of these tables (which subpath loads which peer at import, lazily, or only in its types).
|
|
64
|
+
|
|
65
|
+
Optionality is a promise about the load path, not a way to silence the warning: it holds only while the dependency stays behind a subpath the consumer opts into. Adding a root `"."` barrel, or importing one of these from a module that every subpath reaches, breaks it for every consumer at once. `@sentry/node` and `dotenv` are the exception by design: they are reached by many subpaths, so they load through two internal facades that skip them when they are not installed.
|
|
49
66
|
|
|
50
67
|
## Quick start
|
|
51
68
|
|
|
52
69
|
A Koa app that refuses every request without a valid access token and answers with the caller's id. It needs a MongoDB and a Redis server you can reach.
|
|
53
70
|
|
|
54
71
|
```bash
|
|
55
|
-
yarn add @axiumine/koa-utils @node-rs/bcrypt
|
|
72
|
+
yarn add @axiumine/koa-utils @node-rs/bcrypt dotenv graphql mongoose redis koa
|
|
56
73
|
printf 'MONGODB_URI=mongodb://localhost:27017/app\nREDIS_URL=redis://localhost:6379\nREDIS_KEY=app:\n' > .env
|
|
57
74
|
```
|
|
58
75
|
|
|
@@ -78,7 +95,7 @@ app.use(async (ctx) => {
|
|
|
78
95
|
app.listen(3000)
|
|
79
96
|
```
|
|
80
97
|
|
|
81
|
-
Run it with `node server.mts` (an ES module project, `"type": "module"`, Node
|
|
98
|
+
Run it with `node server.mts` (an ES module project, `"type": "module"`, Node 24 or 26, which strips the types itself). `curl -i localhost:3000` answers `412 Precondition Failed` ("No authorization header."): a request needs `Authorization: Bearer access:<uuid>` with a token that exists in Redis. To obtain one, add the `signUp` and `loginRememberme` mutations from [Usage](#usage) to your GraphQL schema and follow the [Auth flow](#auth-flow).
|
|
82
99
|
|
|
83
100
|
## Usage
|
|
84
101
|
|
|
@@ -247,7 +264,7 @@ import { StringLib } from '@axiumine/koa-utils/lib/StringLib'
|
|
|
247
264
|
| `STATIC_FOLDER` | Destination for `moveFileStaticDomain` |
|
|
248
265
|
| `NODE_ENV` | `development` enables extra Sentry capture in the error handler. Also gates the introspection bypass: `development` and `test` are the only values that let `x-introspectioncode` skip authentication |
|
|
249
266
|
|
|
250
|
-
Each module calls `
|
|
267
|
+
Each module that reads these variables calls the internal `loadEnv()` at import time: it runs `dotenv.config()` when `dotenv` is installed and does nothing when it is not (then `process.env` must already hold the values).
|
|
251
268
|
|
|
252
269
|
### Introspection bypass and `NODE_ENV` (6.0.0)
|
|
253
270
|
|
|
@@ -318,7 +335,17 @@ There is no barrel and no `main` / `module` field.
|
|
|
318
335
|
|
|
319
336
|
`yarn.lock` always resolves against `https://registry.npmjs.org/`, so a plain clone installs with no extra setup.
|
|
320
337
|
|
|
321
|
-
|
|
338
|
+
If you install through a private npm mirror, do not commit its host. Yarn 1 downloads tarballs from the absolute `resolved` URL in the lockfile and ignores the configured registry for them, so a lockfile written through a mirror breaks every clone that cannot reach it. Nothing is rewritten unless you ask for it:
|
|
339
|
+
|
|
340
|
+
```sh
|
|
341
|
+
export REGISTRY_MIRROR=http://host:4873
|
|
342
|
+
yarn registry:mirror # public registry -> mirror, before install
|
|
343
|
+
yarn install
|
|
344
|
+
yarn registry:canonical # mirror -> public registry, before commit
|
|
345
|
+
yarn registry:check # exit 1 if yarn.lock names any other host
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
`registry:check` needs no `REGISTRY_MIRROR`. A pre-commit check also rejects any staged lockfile that names a non-public host.
|
|
322
349
|
|
|
323
350
|
## Feedback, contributing and security
|
|
324
351
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
1
|
+
import { loadEnv } from "../private/lib/loadEnv.mjs";
|
|
2
|
+
import * as Sentry from "../private/lib/sentry.mjs";
|
|
3
3
|
import { Sequelize } from 'sequelize-typescript';
|
|
4
|
-
|
|
4
|
+
loadEnv();
|
|
5
5
|
export const sequelize = new Sequelize(`${process.env['MARIADB_DBNAME']}`, `${process.env['MARIADB_USER']}`, `${process.env['MARIADB_PWD']}`, {
|
|
6
6
|
host: `${process.env['MARIADB_IP']}`,
|
|
7
7
|
dialect: 'mariadb',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { loadEnv } from "../private/lib/loadEnv.mjs";
|
|
2
2
|
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
3
|
+
loadEnv();
|
|
4
4
|
// DeprecationWarning: collection.ensureIndex is deprecated.Use createIndexes instead.
|
|
5
5
|
// mongoose.set('useCreateIndex', true);
|
|
6
6
|
export async function MongoDBConnect() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
1
|
+
import { loadEnv } from "../private/lib/loadEnv.mjs";
|
|
2
|
+
import * as Sentry from "../private/lib/sentry.mjs";
|
|
3
3
|
import pg from 'pg';
|
|
4
4
|
const { Client, Pool } = pg;
|
|
5
|
-
|
|
5
|
+
loadEnv();
|
|
6
6
|
export const pgClient = new Client({
|
|
7
7
|
user: `${process.env['POSTGRESQL_USER']}`,
|
|
8
8
|
password: `${process.env['POSTGRESQL_PWD']}`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isRedisTlsRequired } from "../private/dataSources/isRedisTlsRequired.mjs";
|
|
2
2
|
import { redisNodeUrl } from "../private/dataSources/redisNodeUrl.mjs";
|
|
3
3
|
import { resolveRedisUrl } from "../private/dataSources/resolveRedisUrl.mjs";
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
4
|
+
import { loadEnv } from "../private/lib/loadEnv.mjs";
|
|
5
|
+
import * as Sentry from "../private/lib/sentry.mjs";
|
|
6
6
|
import { createClient, createCluster } from 'redis';
|
|
7
|
-
|
|
7
|
+
loadEnv();
|
|
8
8
|
export const redisClient = process.env['REDIS_IS_CLUSTER'] === '1'
|
|
9
9
|
? /* c8 ignore start -- cluster branch: requires REDIS_IS_CLUSTER=1 + 3 redis nodes, not in unit env */
|
|
10
10
|
createCluster({
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of a SocketLabs client that {@link createSocketLabsSender} calls. `SocketLabsClient` fits it, and so does a
|
|
3
|
+
* test double such as `{ send: async () => ({}) }`. It is declared here because the SocketLabs SDK ships no types
|
|
4
|
+
* and this package never imports a type from it, so `.d.mts` files that name this interface need no peer.
|
|
5
|
+
*/
|
|
6
|
+
export interface ISocketLabsClient {
|
|
7
|
+
send(message: unknown): Promise<unknown>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One mail handed to the function that {@link createSocketLabsSender} returns. A single recipient, no attachments,
|
|
3
|
+
* no copies. `text` and `html` are both optional here, but the SDK rejects a message with neither (`MessageValidationEmptyMessage`).
|
|
4
|
+
*/
|
|
5
|
+
export interface ISocketLabsMessage {
|
|
6
|
+
/** Sender address. */
|
|
7
|
+
from: string;
|
|
8
|
+
/** Display name shown next to `from`. Omitted: the address alone. */
|
|
9
|
+
fromName?: string | undefined;
|
|
10
|
+
/** Recipient address. */
|
|
11
|
+
to: string;
|
|
12
|
+
/** Subject line, raw text. */
|
|
13
|
+
subject: string;
|
|
14
|
+
/** Plain-text body. */
|
|
15
|
+
text?: string | undefined;
|
|
16
|
+
/** HTML body, sent as given: no header, footer or escaping is added. */
|
|
17
|
+
html?: string | undefined;
|
|
18
|
+
/** Your own message id, sent as the SocketLabs `MessageId`. Omitted: none is sent. */
|
|
19
|
+
messageId?: string | undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable sonarjs/no-redundant-optional -- under exactOptionalPropertyTypes `?: T` rejects an explicit `undefined`, so `| undefined` is what lets a caller pass `{ text: maybeText }` */
|
|
2
|
+
export {};
|
|
3
|
+
/* eslint-enable sonarjs/no-redundant-optional -- end of the exactOptionalPropertyTypes block above */
|
|
4
|
+
//# sourceMappingURL=ISocketLabsMessage.mjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the function from {@link createSocketLabsSender} resolves to. A failed send does not reject: it resolves to
|
|
3
|
+
* `{ ok: false, code }`, where `code` is the `name` of the SDK's result enum (`'Timeout'`, `'InvalidAuthentication'`,
|
|
4
|
+
* `'Warning'`, ...) or `'UnknownError'` when the rejection carries none. The code is all that is exposed: never the
|
|
5
|
+
* SDK's response message, the per-recipient results or the raw rejection, which can hold recipients and a receipt.
|
|
6
|
+
*/
|
|
7
|
+
export type ISocketLabsSendResult = {
|
|
8
|
+
ok: true;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
code: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ISocketLabsClient } from './ISocketLabsClient.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Options of {@link createSocketLabsSender}. Nothing is read from the environment: you pass the credentials.
|
|
4
|
+
* There is no `endpointUrl` and no proxy option on purpose, so the sender can only talk to the SDK's default endpoint.
|
|
5
|
+
*/
|
|
6
|
+
export interface ISocketLabsSenderOptions {
|
|
7
|
+
/** SocketLabs server id. Not validated here. Ignored when `client` is given. */
|
|
8
|
+
serverId: number;
|
|
9
|
+
/** SocketLabs injection API key. Not validated here, never put in an error text. Ignored when `client` is given. */
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/**
|
|
12
|
+
* Timeout of one HTTP request, in seconds. Default 120. Must be finite and above 0, else `RangeError` when the
|
|
13
|
+
* sender is created. Unused when `client` is given.
|
|
14
|
+
*/
|
|
15
|
+
requestTimeout?: number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* How many times the SDK retries a failed request. Default 3. Must be an integer from 0 to 5, else `RangeError` when
|
|
18
|
+
* the sender is created. Unused when `client` is given. Retries add to the time one send can take
|
|
19
|
+
* (up to `requestTimeout` x (1 + `numberOfRetries`) plus the SDK's back-off), and a retry after a timeout can deliver the mail twice.
|
|
20
|
+
*/
|
|
21
|
+
numberOfRetries?: number | undefined;
|
|
22
|
+
/** Use this client instead of building a `SocketLabsClient`. For tests and for a client you configure yourself. */
|
|
23
|
+
client?: ISocketLabsClient | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Called with the raw rejection of a failed send, before the sender resolves to `{ ok: false, code }`. Default: nothing.
|
|
26
|
+
* The value is whatever the client rejected with (a `SendResponse`, an `Error`, a `TypeError`, a string, `null`) and can
|
|
27
|
+
* hold recipients and a transaction receipt: do not log or serialise it as is. A throw from here rejects the sender's promise.
|
|
28
|
+
*/
|
|
29
|
+
onError?: ((rejection: unknown) => void) | undefined;
|
|
30
|
+
}
|
|
@@ -10,6 +10,7 @@ export declare class SocketLabsLib {
|
|
|
10
10
|
private readonly linkBase;
|
|
11
11
|
private readonly emailFrom;
|
|
12
12
|
private client;
|
|
13
|
+
private readonly credentials;
|
|
13
14
|
private readonly emailHtmlHeader1;
|
|
14
15
|
private readonly emailHtmlHeader2;
|
|
15
16
|
private readonly emailHtmlFooter;
|
|
@@ -5,23 +5,28 @@ import { confirmationLink, httpLinkBase } from "../private/email/messageParts.mj
|
|
|
5
5
|
import * as notice from "../private/email/noticeMessages.mjs";
|
|
6
6
|
import { orFalse } from "../private/email/orFalse.mjs";
|
|
7
7
|
import * as reset from "../private/email/resetMessages.mjs";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
8
|
+
import { loadEnv } from "../private/lib/loadEnv.mjs";
|
|
9
|
+
import * as Sentry from "../private/lib/sentry.mjs";
|
|
10
|
+
import { SocketLabsClient } from '@socketlabs/email';
|
|
11
|
+
import { createSocketLabsSender } from './createSocketLabsSender.mjs';
|
|
12
|
+
loadEnv();
|
|
12
13
|
export class SocketLabsLib {
|
|
13
14
|
platformName;
|
|
14
15
|
linkBase;
|
|
15
16
|
emailFrom;
|
|
16
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- @socketlabs/email ships no types (untyped module in src/types/socketlabs-email.d.ts), so the client is untyped
|
|
17
18
|
client;
|
|
19
|
+
// Only so a send can hand the sender its required options; the sender ignores them because `client` is injected
|
|
20
|
+
credentials;
|
|
18
21
|
emailHtmlHeader1;
|
|
19
22
|
emailHtmlHeader2;
|
|
20
23
|
emailHtmlFooter;
|
|
21
24
|
constructor(htmlHeader1 = '', htmlHeader2 = '', htmlFooter = '') {
|
|
22
|
-
this.client = new SocketLabsClient(
|
|
23
25
|
/* c8 ignore next -- env fallback '0' covered only when SOCKETLABS_SERVER_ID is unset */
|
|
24
|
-
parseInt(process.env['SOCKETLABS_SERVER_ID'] || '0')
|
|
26
|
+
const serverId = parseInt(process.env['SOCKETLABS_SERVER_ID'] || '0');
|
|
27
|
+
const apiKey = `${process.env['SOCKETLABS_SERVER_APIKEY']}`;
|
|
28
|
+
this.client = new SocketLabsClient(serverId, apiKey, { requestTimeout: 120, numberOfRetries: 3 });
|
|
29
|
+
this.credentials = { serverId, apiKey };
|
|
25
30
|
this.platformName = `${process.env['PLATFORM_NAME']}`;
|
|
26
31
|
this.linkBase = `${process.env['APP_DOMAIN']}`;
|
|
27
32
|
this.emailFrom = `${process.env['EMAIL_FROM']}`;
|
|
@@ -239,22 +244,26 @@ SendResponse {
|
|
|
239
244
|
}
|
|
240
245
|
async sendTemplate(emailTo, content) {
|
|
241
246
|
const { subject, textBody, htmlBody } = content;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return true;
|
|
252
|
-
}, (e) => {
|
|
253
|
-
Sentry.captureException(e, {
|
|
254
|
-
extra: { detail: 'Error in sending the email' }
|
|
255
|
-
});
|
|
256
|
-
return false;
|
|
247
|
+
// Built per send, not once: the client is read from `this.client` each time, so a replaced client is honoured
|
|
248
|
+
const send = createSocketLabsSender({
|
|
249
|
+
...this.credentials,
|
|
250
|
+
client: this.client,
|
|
251
|
+
onError: (rejection) => {
|
|
252
|
+
Sentry.captureException(rejection, {
|
|
253
|
+
extra: { detail: 'Error in sending the email' }
|
|
254
|
+
});
|
|
255
|
+
}
|
|
257
256
|
});
|
|
257
|
+
const result = await send({
|
|
258
|
+
from: this.emailFrom,
|
|
259
|
+
fromName: this.platformName,
|
|
260
|
+
to: emailTo,
|
|
261
|
+
subject,
|
|
262
|
+
text: textBody,
|
|
263
|
+
// The subject is plain text for the subject line and the text part, so only its copy placed in the HTML is escaped.
|
|
264
|
+
html: this.emailHtmlHeader1 + escapeHtml(subject) + this.emailHtmlHeader2 + htmlBody + this.emailHtmlFooter
|
|
265
|
+
});
|
|
266
|
+
return result.ok;
|
|
258
267
|
}
|
|
259
268
|
}
|
|
260
269
|
//# sourceMappingURL=SocketLabsLib.mjs.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ISocketLabsMessage } from './ISocketLabsMessage.mjs';
|
|
2
|
+
import type { ISocketLabsSenderOptions } from './ISocketLabsSenderOptions.mjs';
|
|
3
|
+
import type { ISocketLabsSendResult } from './ISocketLabsSendResult.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Builds a function that sends one mail through SocketLabs and reports the outcome as a value.
|
|
6
|
+
*
|
|
7
|
+
* The returned function builds a `BasicMessage` (setters in the order `setFromAddress`, `setSubject`, `setTextBody`,
|
|
8
|
+
* `setHtmlBody`, `setTo`, `setMessageId`) and passes it to the client. On success it resolves to `{ ok: true }`. When the
|
|
9
|
+
* client rejects it calls `onError` with the raw rejection and resolves to `{ ok: false, code }`, where `code` is
|
|
10
|
+
* `rejection.result.name` if that is a string and `'UnknownError'` otherwise.
|
|
11
|
+
*
|
|
12
|
+
* There is no `try`/`catch`: a throw from a setter or from `client.send` itself, and a throw from `onError`, reject the
|
|
13
|
+
* returned promise, and when a setter throws `client.send` is never called.
|
|
14
|
+
*
|
|
15
|
+
* It reads no environment variable and checks nothing about `serverId` and `apiKey`: the SDK rejects bad credentials
|
|
16
|
+
* at send time. Importing it loads the SocketLabs SDK (the optional peer of this subpath) and nothing else: no Sentry, no dotenv.
|
|
17
|
+
*
|
|
18
|
+
* @throws RangeError `requestTimeout` is not a finite number above 0, or `numberOfRetries` is not an integer from 0 to 5. The text never holds the API key.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createSocketLabsSender(options: ISocketLabsSenderOptions): (message: ISocketLabsMessage) => Promise<ISocketLabsSendResult>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BasicMessage, SocketLabsClient } from '@socketlabs/email';
|
|
2
|
+
/** Seconds, what `SocketLabsLib` has always passed. */
|
|
3
|
+
const DEFAULT_REQUEST_TIMEOUT = 120;
|
|
4
|
+
/** What `SocketLabsLib` has always passed. */
|
|
5
|
+
const DEFAULT_NUMBER_OF_RETRIES = 3;
|
|
6
|
+
/** Upper bound of `numberOfRetries`: every retry can run a full timeout, so a larger value outlives any sane job lease. */
|
|
7
|
+
const MAX_NUMBER_OF_RETRIES = 5;
|
|
8
|
+
/** The SDK's own name for a rejection it cannot classify (`sendResultEnum.UnknownError`). */
|
|
9
|
+
const UNKNOWN_ERROR = 'UnknownError';
|
|
10
|
+
// The import is `any` (src/types/socketlabs-email.d.ts): one assertion each gives the two classes the shapes above
|
|
11
|
+
const Message = BasicMessage;
|
|
12
|
+
const Client = SocketLabsClient;
|
|
13
|
+
// Messages name the constraint, never the value: the options object also holds the API key
|
|
14
|
+
function assertRequestTimeout(requestTimeout) {
|
|
15
|
+
if (!Number.isFinite(requestTimeout) || requestTimeout <= 0) {
|
|
16
|
+
throw new RangeError('requestTimeout must be a finite number of seconds above 0');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function assertNumberOfRetries(numberOfRetries) {
|
|
20
|
+
if (!Number.isInteger(numberOfRetries) || numberOfRetries < 0 || numberOfRetries > MAX_NUMBER_OF_RETRIES) {
|
|
21
|
+
throw new RangeError(`numberOfRetries must be an integer from 0 to ${MAX_NUMBER_OF_RETRIES}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** `rejection.result.name` when it is a string, else `'UnknownError'`. The SDK rejects with a `SendResponse` whose `result` is one of its enum values. */
|
|
25
|
+
const codeOf = (rejection) => {
|
|
26
|
+
const name = rejection?.result?.name;
|
|
27
|
+
return typeof name === 'string' ? name : UNKNOWN_ERROR;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Builds a function that sends one mail through SocketLabs and reports the outcome as a value.
|
|
31
|
+
*
|
|
32
|
+
* The returned function builds a `BasicMessage` (setters in the order `setFromAddress`, `setSubject`, `setTextBody`,
|
|
33
|
+
* `setHtmlBody`, `setTo`, `setMessageId`) and passes it to the client. On success it resolves to `{ ok: true }`. When the
|
|
34
|
+
* client rejects it calls `onError` with the raw rejection and resolves to `{ ok: false, code }`, where `code` is
|
|
35
|
+
* `rejection.result.name` if that is a string and `'UnknownError'` otherwise.
|
|
36
|
+
*
|
|
37
|
+
* There is no `try`/`catch`: a throw from a setter or from `client.send` itself, and a throw from `onError`, reject the
|
|
38
|
+
* returned promise, and when a setter throws `client.send` is never called.
|
|
39
|
+
*
|
|
40
|
+
* It reads no environment variable and checks nothing about `serverId` and `apiKey`: the SDK rejects bad credentials
|
|
41
|
+
* at send time. Importing it loads the SocketLabs SDK (the optional peer of this subpath) and nothing else: no Sentry, no dotenv.
|
|
42
|
+
*
|
|
43
|
+
* @throws RangeError `requestTimeout` is not a finite number above 0, or `numberOfRetries` is not an integer from 0 to 5. The text never holds the API key.
|
|
44
|
+
*/
|
|
45
|
+
export function createSocketLabsSender(options) {
|
|
46
|
+
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
47
|
+
const numberOfRetries = options.numberOfRetries ?? DEFAULT_NUMBER_OF_RETRIES;
|
|
48
|
+
assertRequestTimeout(requestTimeout);
|
|
49
|
+
assertNumberOfRetries(numberOfRetries);
|
|
50
|
+
const client = options.client ?? new Client(options.serverId, options.apiKey, { requestTimeout, numberOfRetries });
|
|
51
|
+
const { onError } = options;
|
|
52
|
+
return async function sendSocketLabsMessage(message) {
|
|
53
|
+
const basicMessage = new Message();
|
|
54
|
+
basicMessage.setFromAddress(message.from, message.fromName);
|
|
55
|
+
basicMessage.setSubject(message.subject);
|
|
56
|
+
basicMessage.setTextBody(message.text);
|
|
57
|
+
basicMessage.setHtmlBody(message.html);
|
|
58
|
+
basicMessage.setTo(message.to);
|
|
59
|
+
basicMessage.setMessageId(message.messageId);
|
|
60
|
+
return client.send(basicMessage).then(() => ({ ok: true }), (rejection) => {
|
|
61
|
+
onError?.(rejection);
|
|
62
|
+
return { ok: false, code: codeOf(rejection) };
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=createSocketLabsSender.mjs.map
|
package/dist/files/scanVirus.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { createWriteStream, unlink } from 'node:fs';
|
|
2
3
|
import path from 'path';
|
|
3
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
import { UPLOAD_TEMP_DIRECTORY_URL } from './fileConst.mjs';
|
|
5
5
|
// Simulating __dirname using process.cwd()
|
|
6
6
|
// const __dirname = process.cwd()
|
|
@@ -8,7 +8,7 @@ const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB size limit
|
|
|
8
8
|
export async function storeUploadAsTemp(upload, maxFileSize = MAX_FILE_SIZE) {
|
|
9
9
|
const { createReadStream, filename } = await upload;
|
|
10
10
|
const stream = createReadStream();
|
|
11
|
-
const storedFileName =
|
|
11
|
+
const storedFileName = randomUUID() + path.extname(filename).toLowerCase();
|
|
12
12
|
const storedFileUrl = `${UPLOAD_TEMP_DIRECTORY_URL}/${storedFileName}`;
|
|
13
13
|
let fileSize = 0; // Variable to track file size
|
|
14
14
|
let sizeExceeded = false; // Set once the limit is passed; read by the 'close' handler
|
|
@@ -6,7 +6,7 @@ import { tryCatchRethrow } from "../../../lib/tryCatchRethrow.mjs";
|
|
|
6
6
|
import { checkUserLoginAuthorization } from "../../../private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs";
|
|
7
7
|
import { setRedisLoginSession } from "../../../private/graphQL/schema/mutations/setRedisLoginSession.mjs";
|
|
8
8
|
import { updateLoginStats4ever } from "../../../private/graphQL/schema/mutations/updateLoginStats4ever.mjs";
|
|
9
|
-
import * as Sentry from
|
|
9
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
10
10
|
import { LoginType } from "../types/LoginType.mjs";
|
|
11
11
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
|
12
12
|
import mongoose from 'mongoose';
|
|
@@ -6,7 +6,7 @@ import { tryCatchRethrow } from "../../../lib/tryCatchRethrow.mjs";
|
|
|
6
6
|
import { checkUserAdminLoginAuthorization } from "../../../private/graphQL/schema/mutations/checkUserAdminLoginAuthorization.mjs";
|
|
7
7
|
import { setRedisLoginSession } from "../../../private/graphQL/schema/mutations/setRedisLoginSession.mjs";
|
|
8
8
|
import { updateAdminLoginStats } from "../../../private/graphQL/schema/mutations/updateAdminLoginStats.mjs";
|
|
9
|
-
import * as Sentry from
|
|
9
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
10
10
|
import { LoginType } from "../types/LoginType.mjs";
|
|
11
11
|
import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
12
12
|
import mongoose from 'mongoose';
|
|
@@ -6,7 +6,7 @@ import { tryCatchRethrow } from "../../../lib/tryCatchRethrow.mjs";
|
|
|
6
6
|
import { checkUserLoginAuthorization } from "../../../private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs";
|
|
7
7
|
import { setRedisLoginSession } from "../../../private/graphQL/schema/mutations/setRedisLoginSession.mjs";
|
|
8
8
|
import { updateLoginStatsRememberme } from "../../../private/graphQL/schema/mutations/updateLoginStatsRememberme.mjs";
|
|
9
|
-
import * as Sentry from
|
|
9
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
10
10
|
import { LoginType } from "../types/LoginType.mjs";
|
|
11
11
|
import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
12
12
|
import mongoose from 'mongoose';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { redisClient } from "../../../dataSources/Redis.mjs";
|
|
2
2
|
import { buildPrefixedRedisKey } from "../../../lib/Redis/buildPrefixedRedisKey.mjs";
|
|
3
3
|
import { refreshTokenOptions } from "../../../lib/tokenOptions.mjs";
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
4
|
+
import { loadEnv } from "../../../private/lib/loadEnv.mjs";
|
|
5
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
6
6
|
import { GraphQLBoolean, GraphQLNonNull } from 'graphql';
|
|
7
|
-
|
|
7
|
+
loadEnv();
|
|
8
8
|
export const logout = {
|
|
9
9
|
description: 'logout',
|
|
10
10
|
type: new GraphQLNonNull(GraphQLBoolean),
|
|
@@ -2,11 +2,11 @@ import { redisClient } from "../../../dataSources/Redis.mjs";
|
|
|
2
2
|
import { setLoginCookies } from "../../../lib/setLoginCookies.mjs";
|
|
3
3
|
import { accessTokenExpiry, generateAccessToken, generateRefreshToken, REFRESH_TOKEN_EXPIRY } from "../../../lib/tokens.mjs";
|
|
4
4
|
import { tryCatchRethrow } from "../../../lib/tryCatchRethrow.mjs";
|
|
5
|
-
import
|
|
5
|
+
import { loadEnv } from "../../../private/lib/loadEnv.mjs";
|
|
6
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
6
7
|
import { RefreshType } from "../types/RefreshType.mjs";
|
|
7
|
-
import * as dotenv from 'dotenv';
|
|
8
8
|
import { GraphQLNonNull } from 'graphql';
|
|
9
|
-
|
|
9
|
+
loadEnv();
|
|
10
10
|
export const refresh = {
|
|
11
11
|
description: 'refresh token',
|
|
12
12
|
type: new GraphQLNonNull(RefreshType),
|
|
@@ -6,7 +6,7 @@ import { StringLib } from "../../../lib/StringLib.mjs";
|
|
|
6
6
|
import { tryCatchRethrow } from "../../../lib/tryCatchRethrow.mjs";
|
|
7
7
|
import { getResetPwd } from "../../../private/lib/access/db/getResetPwd.mjs";
|
|
8
8
|
import { saveResetReq } from "../../../private/lib/access/db/saveResetReq.mjs";
|
|
9
|
-
import * as Sentry from
|
|
9
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
10
10
|
import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
11
11
|
import mongoose from 'mongoose';
|
|
12
12
|
/**
|
|
@@ -6,7 +6,7 @@ import { applyPasswordReset } from "../../../private/lib/access/applyPasswordRes
|
|
|
6
6
|
import { getResetPwd } from "../../../private/lib/access/db/getResetPwd.mjs";
|
|
7
7
|
import removeResetReq from "../../../private/lib/access/db/removeResetReq.mjs";
|
|
8
8
|
import updatePasswordDb from "../../../private/lib/access/db/updatePasswordDb.mjs";
|
|
9
|
-
import * as Sentry from
|
|
9
|
+
import * as Sentry from "../../../private/lib/sentry.mjs";
|
|
10
10
|
import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
11
11
|
import mongoose from 'mongoose';
|
|
12
12
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of a Koa context that {@link createKoaErrorHandler} reads and writes. Koa's `ParameterizedContext` and
|
|
3
|
+
* `IContextKoaErrorHandler` both fit it, so the factory needs no `koa` types and no peer at all.
|
|
4
|
+
*/
|
|
5
|
+
export interface IKoaErrorHandlerContext {
|
|
6
|
+
status: number;
|
|
7
|
+
body: unknown;
|
|
8
|
+
app: {
|
|
9
|
+
emit(event: string, err: unknown, ctx: unknown): unknown;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IKoaErrorHandlerContext } from './IKoaErrorHandlerContext.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Options of {@link createKoaErrorHandler}. Every field is optional; omitted, the handler behaves like
|
|
4
|
+
* `tdwKoaErrorHandler` without GraphQL, Sentry or dotenv. `undefined` is accepted for each field
|
|
5
|
+
* (`exactOptionalPropertyTypes`), so `{ report: maybeReport }` needs no conditional spread.
|
|
6
|
+
*/
|
|
7
|
+
export interface IKoaErrorHandlerOptions<TCtx extends IKoaErrorHandlerContext = IKoaErrorHandlerContext> {
|
|
8
|
+
/**
|
|
9
|
+
* HTTP status for a caught value. Default `err?.status || 500`: a missing, `0` or `NaN` status gives 500.
|
|
10
|
+
* A truthy status outside 100-999 makes Koa's own `ctx.status` setter assert.
|
|
11
|
+
*/
|
|
12
|
+
statusOf?: ((err: unknown, ctx: TCtx) => number) | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Response body for a caught value, called after `ctx.status` is set and only when that status may carry a body.
|
|
15
|
+
* Default `{ message: err?.message }`. Returning `undefined` leaves `ctx.body` as it was; `null`, `''` and `0` are assigned.
|
|
16
|
+
*/
|
|
17
|
+
bodyOf?: ((err: unknown, ctx: TCtx) => unknown) | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Side effect for a caught value (logging, Sentry), called after status and body and before `'error'` is emitted.
|
|
20
|
+
* No default. Not wrapped in `try`/`catch`: a throwing `report` rejects the middleware and skips the `emit`.
|
|
21
|
+
*/
|
|
22
|
+
report?: ((err: unknown, ctx: TCtx) => void) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Statuses that get no body (`bodyOf` is not called). Default `[100, 101, 102, 204, 205, 304]`. Copied into a `Set`
|
|
25
|
+
* when the handler is created, so changing the array afterwards has no effect. `[]` allows a body for every status.
|
|
26
|
+
*/
|
|
27
|
+
noBodyStatuses?: readonly number[] | undefined;
|
|
28
|
+
}
|