Skip to content

chore: Move common logic to shared package - #325

Merged
hhvrc merged 10 commits into
developfrom
feature/consume-internal-packages
Aug 14, 2026
Merged

chore: Move common logic to shared package#325
hhvrc merged 10 commits into
developfrom
feature/consume-internal-packages

Conversation

@hhvrc

@hhvrc hhvrc commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

hhvrc and others added 2 commits June 22, 2026 17:24
…mon code

Replace the duplicated shared utility/validation/crypto/geo/dynamic-LINQ/
ASP.NET code in Common/ with references to the published packages
OpenShock.Internal.Common, OpenShock.Internal.AspNet and
OpenShock.Internal.DynamicLinq (pinned at 0.0.1).

- Delete 38 now-redundant files (exact duplicates + the PasswordHashingAlgorithm
  enum + the Cloudflare IP generation, now owned by the package).
- Re-point ~150 consumers to the OpenShock.Internal.* namespaces.
- OpenShockControllerBase now inherits the package base, keeping API-specific
  session/cookie/legacy-response helpers.
- Split HardLimits: shared limits come from the package, API-specific extras
  move to a new local ApiHardLimits.
- Split IQueryableExtensions: ApplyFilter/ApplyOrderBy from the package,
  WhereUserIdMatches/WhereIsUserOrPrivileged stay local.
- Adapt to package surface changes: CryptoUtils.RandomString rename,
  OpenShockProblem.WriteAsJsonAsync / OpenShockExceptionHandler now take
  JsonSerializerOptions (registered JsonOptions.Default in DI), ApplyOrderBy
  is now static.
- Bump BCrypt.Net-Next 4.2.0 -> 4.2.1 (required by OpenShock.Internal.Common).
- Drop the 6 Common.Tests files now covered by the packages' own test projects.
@hhvrc hhvrc self-assigned this Jun 28, 2026
@ghost

ghost commented Jun 28, 2026

Copy link
Copy Markdown

hhvrc added 2 commits June 28, 2026 23:34
Add a Paired value to DeviceUpdateType and emit it to the device owner
after a pair code is consumed, so clients are notified when a device pairs.
hhvrc and others added 4 commits July 3, 2026 12:05
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
feat: emit DeviceUpdateType.Paired when a device consumes a pair code
Reconciles develop's email-outbox, user-audit-log, health-check and
pg-enum work with this branch's move onto the OpenShock.Internal.*
packages.

Conflict resolutions:
- Directory.Packages.props: kept develop's health-check packages and the
  newer BCrypt 4.2.1; dropped the BCrypt reference entirely since
  HashingUtils now ships in OpenShock.Internal.Common.
- AccountService: took develop's lazy token minting (the outbox delivery
  job mints the real token at send time), dropping the eager
  CryptoUtils calls this branch had only renamed.
- OpenShockServiceHelper: OpenShock.Internal.Common.ExceptionHandling
  alongside develop's new HealthChecks.
- HardLimits/HashingUtils/HashingUtilsTests: stay deleted (provided by
  OpenShock.Internal.Common). develop's new constants
  (EmailOutbox{LastError,CoalesceKey}MaxLength, AuditReasonMaxLength)
  moved into ApiHardLimits, and the API-specific references repointed.

Follow-up fixes so develop's new code builds against the packages:
- EmailOutboxList: OpenShock.Common.Query -> OpenShock.Internal.DynamicLinq.
- EmailOutboxDispatcher / Cron.IntegrationTests: CryptoUtils and
  HashingUtils from OpenShock.Internal.Common,
  RandomAlphaNumericString -> RandomString.
- Cron.IntegrationTests.csproj: GitHashAttribute from the package.

Also pins SSH.NET 2026.0.0 (transitive via Testcontainers) to clear
GHSA-q939-rpr3-3284, which was failing restore under NuGetAudit.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 206 files, which is 106 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c48a1d88-c403-45b5-a8da-1f26985c8ddc

📥 Commits

Reviewing files that changed from the base of the PR and between 9b7279d and 26ad580.

📒 Files selected for processing (206)
  • API.IntegrationTests/API.IntegrationTests.csproj
  • API.IntegrationTests/Docker/InMemoryDatabase.cs
  • API.IntegrationTests/Helpers/TestHelper.cs
  • API.IntegrationTests/Tests/AdminUsersViewTests.cs
  • API.IntegrationTests/Tests/LcgAssignmentTests.cs
  • API/API.csproj
  • API/Controller/Account/Activate.cs
  • API/Controller/Account/Authenticated/ChangeEmail.cs
  • API/Controller/Account/Authenticated/ChangePassword.cs
  • API/Controller/Account/Authenticated/ChangeUsername.cs
  • API/Controller/Account/Authenticated/Deactivate.cs
  • API/Controller/Account/Login.cs
  • API/Controller/Account/LoginV2.cs
  • API/Controller/Account/PasswordResetCheckValid.cs
  • API/Controller/Account/PasswordResetComplete.cs
  • API/Controller/Account/PasswordResetInitiateV2.cs
  • API/Controller/Account/Signup.cs
  • API/Controller/Account/SignupV2.cs
  • API/Controller/Account/VerifyEmail.cs
  • API/Controller/Account/_Turnstile.cs
  • API/Controller/Admin/Configuration.cs
  • API/Controller/Admin/DeactivateUser.cs
  • API/Controller/Admin/DeleteUser.cs
  • API/Controller/Admin/EmailOutboxList.cs
  • API/Controller/Admin/GetUsers.cs
  • API/Controller/Admin/ReactivateUser.cs
  • API/Controller/Device/AssignLCG.cs
  • API/Controller/Device/AssignLCGV2.cs
  • API/Controller/Device/Pair.cs
  • API/Controller/Device/_ApiController.cs
  • API/Controller/Devices/DeviceOtaController.cs
  • API/Controller/Devices/DevicesController.cs
  • API/Controller/Devices/GetShockers.cs
  • API/Controller/Public/PublicShareController.cs
  • API/Controller/Sessions/DeleteSessions.cs
  • API/Controller/Shares/DeleteShareCode.cs
  • API/Controller/Shares/LinkShareCode.cs
  • API/Controller/Shares/Links/AddShocker.cs
  • API/Controller/Shares/Links/DeletePublicShare.cs
  • API/Controller/Shares/Links/EditShocker.cs
  • API/Controller/Shares/Links/PauseShocker.cs
  • API/Controller/Shares/Links/RemoveShocker.cs
  • API/Controller/Shares/UserShares/CreateShareInvite.cs
  • API/Controller/Shares/UserShares/Invites.cs
  • API/Controller/Shares/UserShares/UpdateShockerShares.cs
  • API/Controller/Shockers/EditShocker.cs
  • API/Controller/Shockers/GetShockerById.cs
  • API/Controller/Shockers/GetShockerLogs.cs
  • API/Controller/Shockers/PauseShocker.cs
  • API/Controller/Shockers/RegisterShocker.cs
  • API/Controller/Shockers/RemoveShocker.cs
  • API/Controller/Shockers/SendControl.cs
  • API/Controller/Shockers/ShockerShares.cs
  • API/Controller/Tokens/DeleteToken.cs
  • API/Controller/Tokens/ReportTokens.cs
  • API/Controller/Tokens/Tokens.cs
  • API/Controller/Users/LookupByName.cs
  • API/Controller/Version/_ApiController.cs
  • API/Errors/TurnstileError.cs
  • API/Models/Requests/CreateShareRequest.cs
  • API/Models/Requests/EditTokenRequest.cs
  • API/Models/Requests/EditTokenRequestV2.cs
  • API/Models/Requests/HubCreateRequest.cs
  • API/Models/Requests/HubEditRequest.cs
  • API/Models/Requests/LoginV2.cs
  • API/Models/Requests/NewShocker.cs
  • API/Models/Requests/PasswordResetRequestV2.cs
  • API/Models/Requests/PublicShareCreate.cs
  • API/Models/Requests/PublicShareEditShocker.cs
  • API/Models/Requests/ReportTokensRequest.cs
  • API/Models/Requests/SignupV2.cs
  • API/Models/Response/ShockerLimits.cs
  • API/Models/ShockerControlSettings.cs
  • API/OAuth/OAuthError.cs
  • API/Realtime/RedisSubscriberService.cs
  • API/Services/Account/AccountService.cs
  • API/Services/LCGNodeProvisioner/ILCGNodeProvisioner.cs
  • API/Services/LCGNodeProvisioner/LCGNodeProvisioner.cs
  • API/Services/Token/ApiTokenService.cs
  • Common.Tests/Geo/Alpha2CountryCodeTests.cs
  • Common.Tests/Geo/DistanceLookupTests.cs
  • Common.Tests/Query/ExpressionBuilderTests.cs
  • Common.Tests/Query/QueryStringTokenizerTests.cs
  • Common.Tests/Utils/CryptoUtilsTests.cs
  • Common.Tests/Utils/GravatarUtilsTests.cs
  • Common.Tests/Utils/LatencyEmulatorTests.cs
  • Common.Tests/Utils/MathUtilsTests.cs
  • Common.Tests/Validation/CharsetMatchersTests.cs
  • Common.Tests/Validation/UsernameValidatorTests.cs
  • Common/Authentication/Attributes/TokenPermissionAttribute.cs
  • Common/Authentication/AuthenticationHandlers/ApiTokenAuthentication.cs
  • Common/Authentication/AuthenticationHandlers/HubAuthentication.cs
  • Common/Authentication/AuthenticationHandlers/UserSessionAuthentication.cs
  • Common/Authentication/OpenShockAuthorizationMiddlewareResultHandler.cs
  • Common/CloudflareIPs.targets
  • Common/Common.csproj
  • Common/Constants/ApiHardLimits.cs
  • Common/Constants/Distance.cs
  • Common/Constants/HardLimits.cs
  • Common/DataAnnotations/EmailAddressAttribute.cs
  • Common/DataAnnotations/PasswordAttribute.cs
  • Common/DataAnnotations/StringCollectionItemMaxLengthAttribute.cs
  • Common/Errors/AccountActivationError.cs
  • Common/Errors/AccountError.cs
  • Common/Errors/AdminError.cs
  • Common/Errors/ApiTokenError.cs
  • Common/Errors/AssignLcgError.cs
  • Common/Errors/AuthResultError.cs
  • Common/Errors/AuthorizationError.cs
  • Common/Errors/ConfigurationError.cs
  • Common/Errors/ExceptionError.cs
  • Common/Errors/ExpressionError.cs
  • Common/Errors/GoneError.cs
  • Common/Errors/HubError.cs
  • Common/Errors/LoginError.cs
  • Common/Errors/PairError.cs
  • Common/Errors/PasswordResetError.cs
  • Common/Errors/PublicShareError.cs
  • Common/Errors/SessionError.cs
  • Common/Errors/ShareCodeError.cs
  • Common/Errors/ShareError.cs
  • Common/Errors/ShockerError.cs
  • Common/Errors/SignupError.cs
  • Common/Errors/UserError.cs
  • Common/Errors/WebsocketError.cs
  • Common/ExceptionHandle/OpenShockExceptionHandler.cs
  • Common/ExceptionHandle/RequestInfo.cs
  • Common/Extensions/ConfigurationExtensions.cs
  • Common/Extensions/DictionaryExtensions.cs
  • Common/Extensions/IQueryableExtensions.cs
  • Common/Extensions/SemaphoreSlimExtensions.cs
  • Common/Geo/Alpha2CountryCode.cs
  • Common/Geo/Alpha2CountryCodeAttribute.cs
  • Common/Geo/CountryInfo.cs
  • Common/Geo/DistanceLookup.cs
  • Common/Hubs/PublicShareHub.cs
  • Common/JsonSerialization/FlagGuardedJsonStringEnumConverter.cs
  • Common/JsonSerialization/JsonOptions.cs
  • Common/JsonSerialization/UnixMillisecondsDateTimeOffsetConverter.cs
  • Common/Models/ApiTokenControlLimits.cs
  • Common/Models/DeviceUpdateType.cs
  • Common/Models/WebSocket/User/Control.cs
  • Common/Models/WebSocket/User/ControlLog.cs
  • Common/OpenShockControllerBase.cs
  • Common/OpenShockDb/Models/ApiToken.cs
  • Common/OpenShockDb/OpenShockContext.cs
  • Common/OpenShockMiddlewareHelper.cs
  • Common/OpenShockServiceHelper.cs
  • Common/Problems/CustomProblems/PolicyNotMetProblem.cs
  • Common/Problems/CustomProblems/ShockerControlProblem.cs
  • Common/Problems/CustomProblems/ShockersNotFoundProblem.cs
  • Common/Problems/CustomProblems/TokenPermissionProblem.cs
  • Common/Problems/ExceptionProblem.cs
  • Common/Problems/OpenShockProblem.cs
  • Common/Problems/ValidationProblem.cs
  • Common/Query/DBExpressionBuilder.cs
  • Common/Query/DBExpressionBuilderUtils.cs
  • Common/Query/OrderByQueryBuilder.cs
  • Common/Query/QueryStringTokenizer.cs
  • Common/Redis/LoginSessions.cs
  • Common/Redis/QueueHelper.cs
  • Common/Services/BatchUpdate/BatchUpdateService.cs
  • Common/Services/ControlSender.cs
  • Common/Services/Session/SessionService.cs
  • Common/Utils/CloudflareNetworks.g.cs
  • Common/Utils/ConnectionDetailsFetcher.cs
  • Common/Utils/CryptoUtils.cs
  • Common/Utils/GitHashAttribute.cs
  • Common/Utils/GravatarUtils.cs
  • Common/Utils/HashingUtils.cs
  • Common/Utils/LatencyEmulator.cs
  • Common/Utils/MathUtils.cs
  • Common/Utils/OsTask.cs
  • Common/Utils/PBKDF2PasswordHasher.cs
  • Common/Utils/TrustedProxiesFetcher.cs
  • Common/Validation/ChatsetMatchers.cs
  • Common/Validation/UsernameValidator.cs
  • Common/Websocket/WebsockBaseController.cs
  • Cron.IntegrationTests/Cron.IntegrationTests.csproj
  • Cron.IntegrationTests/Docker/InMemoryDatabase.cs
  • Cron.IntegrationTests/Tests/ControlLogRetentionTests.cs
  • Cron.IntegrationTests/Tests/EmailOutboxDeliveryTests.cs
  • Cron/Cron.csproj
  • Cron/Jobs/ClearOldShockerControlLogs.cs
  • Cron/Services/Email/Outbox/EmailOutboxDispatcher.cs
  • Cron/Services/Email/Outbox/EmailOutboxStateMachine.cs
  • Directory.Packages.props
  • LiveControlGateway/Controllers/HubControllerBase.cs
  • LiveControlGateway/Controllers/InstanceDetailsController.cs
  • LiveControlGateway/Controllers/LiveControlController.cs
  • LiveControlGateway/LcgKeepAlive.cs
  • LiveControlGateway/LifetimeManager/HubLifetime.cs
  • LiveControlGateway/LifetimeManager/HubLifetimeManager.cs
  • LiveControlGateway/LifetimeManager/ShockerState.cs
  • LiveControlGateway/LiveControlGateway.csproj
  • LiveControlGateway/Options/LcgOptions.cs
  • LiveControlGateway/PubSub/ApiTokenUpdateSubscriber.cs
  • SeedE2E/Seeders/ApiTokenSeeder.cs
  • SeedE2E/Seeders/DeviceSeeder.cs
  • SeedE2E/Seeders/PublicShareSeeder.cs
  • SeedE2E/Seeders/ShockerSeeder.cs
  • SeedE2E/Seeders/UserActivationRequestSeeder.cs
  • SeedE2E/Seeders/UserEmailChangeSeeder.cs
  • SeedE2E/Seeders/UserNameChangeSeeder.cs
  • SeedE2E/Seeders/UserPasswordResetSeeder.cs
  • SeedE2E/Seeders/UserSeeder.cs

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ocal

0.1.1 removed HashingUtils and PasswordHashingAlgorithm from
OpenShock.Internal.Common, and no other OpenShock.Internal.* package picked
them up. Everything else in the 0.0.1 -> 0.1.1 range is unchanged: AspNet and
DynamicLinq are API-identical, and Common's only delta is those removals.

So the ~38 HashingUtils call sites across API, Common, Cron, SeedE2E and both
integration test projects (HashPassword/VerifyPassword/HashToken/VerifyToken/
HashSha256) move back onto a local copy, restored from develop along with its
tests. BCrypt.Net-Next comes back with it; LatencyEmulator and
PBKDF2PasswordHasher stay in the package, which still ships them.

PasswordHashingAlgorithm likewise returns to OpenShock.Common.OpenShockDb,
where it keeps the [PgEnum]/[PgName] labels the package copy never had.
AdminUsersView drops the now-nonexistent OpenShock.Internal.Common.Enums
import and resolves the enum from its own namespace. No EF model change.

Adds AdminUsersViewTests: admin_users_view.password_hash_type is text derived
from the "bcrypt:"/"pbkdf2:" prefix on users.password_hash, not the legacy
password_encryption_type enum, so EF converts it by matching enum member names
case-insensitively. That coupling had no coverage.
@hhvrc
hhvrc marked this pull request as ready for review August 14, 2026 08:43
CryptoUtilsTests, LatencyEmulatorTests and MathUtilsTests only exercise
OpenShock.Internal.Common.Utils types; they stayed behind when the utilities
moved into the package. They now live in OpenShock/Internal.NET
(Internal.Common.Tests/Utils), next to the code they cover.

The rest of Common.Tests/Utils stays: GravatarUtils, DomainUtils, StringUtils
and HashingUtils are all local types, as is UsernameValidator.

177 -> 147 tests here, 47 -> 77 there.
@hhvrc
hhvrc merged commit 09451b0 into develop Aug 14, 2026
10 checks passed
@hhvrc
hhvrc deleted the feature/consume-internal-packages branch August 14, 2026 08:57
hhvrc added a commit that referenced this pull request Aug 14, 2026
Brings in the Internal.Net package extraction (#325) plus the develop
changes since the last sync (healthcheck endpoint, PeriodicTimer rework,
share/publicshare token permissions, dependabot/action pins).

Conflict resolutions:

* Directory.Packages.props: keep the .NET 11 preview pins
  (Npgsql.EntityFrameworkCore.PostgreSQL, Microsoft.AspNetCore.Mvc.Testing),
  take develop's NRedisStack bump and the new OpenShock.Internal.*
  references. OneOf is dropped -- nothing references it since the union
  refactor.
* Common/Results/Unions.cs: OpenShockProblem now lives in
  OpenShock.Internal.Common.Problems.
* Common/Websocket/WebsockBaseController.cs: keep the union pattern match
  over develop's .AsT1.Value, with develop's new JsonOptions argument on
  WriteAsJsonAsync.
* API/Controller/Account/_Turnstile.cs: drop the now-dead Common.Problems
  and Common.Results usings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants