@stackonward/cli 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4588 -205
- package/dist/index.js.map +1 -1
- package/dist/resources/apple/.claude/docs/architecture-template.md +54 -0
- package/dist/resources/apple/.claude/docs/architecture.md +52 -0
- package/dist/resources/apple/.claude/docs/index.md +13 -0
- package/dist/resources/apple/.claude/docs/security-lifecycle.md +57 -0
- package/dist/resources/apple/.claude/docs/stack.md +93 -0
- package/dist/resources/apple/.claude/docs/verification.md +63 -0
- package/dist/resources/apple/AGENTS.md +397 -0
- package/dist/resources/apple/CLAUDE.md +397 -0
- package/dist/resources/apple/Gemfile +2 -0
- package/dist/resources/apple/Gemfile.lock +365 -0
- package/dist/resources/apple/_gitignore +14 -0
- package/dist/resources/apple/fastlane/Fastfile +123 -0
- package/dist/resources/components/nuxt/site-source/app/app.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/assets/css/site-shell.css +1035 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/brand/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/common/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationHeader.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationShell.vue +56 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationSidebar.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/BackToTop.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentArticlePage.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentListPage.vue +30 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/CookieConsent.vue +18 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingFooter.vue +52 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingHeader.vue +106 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingShell.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/SiteBrand.vue +10 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/StaticPage.vue +21 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ToastViewport.vue +25 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseButton.vue +86 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseGradientBorder.vue +59 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseModal.vue +131 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BasePopover.vue +150 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseText.vue +138 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutStatus.vue +112 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutSummary.vue +172 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/GoogleSignInButton.vue +113 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/InfiniteScroll.vue +123 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/YoutubeEmbed.vue +126 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useAnalytics.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useCheckout.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useConsent.ts +31 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useGoogleIdentity.ts +163 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useNavigation.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSeo.ts +33 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSiteShell.ts +58 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useToasts.ts +48 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/app.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/default.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/analytics.client.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/google-identity.client.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/theme/accordion.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/breadcrumb.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/button.ts +92 -0
- package/dist/resources/components/nuxt/site-source/app/theme/carousel.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/theme/checkbox.ts +12 -0
- package/dist/resources/components/nuxt/site-source/app/theme/index.ts +30 -0
- package/dist/resources/components/nuxt/site-source/app/theme/input.ts +47 -0
- package/dist/resources/components/nuxt/site-source/app/theme/modal.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/pagination.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/theme/select.ts +23 -0
- package/dist/resources/components/nuxt/site-source/app/theme/stepper.ts +10 -0
- package/dist/resources/components/nuxt/site-source/app/theme/toast.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/tooltip.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/types/site-shell.ts +85 -0
- package/dist/resources/components/react/ui/Button.tsx +73 -0
- package/dist/resources/components/react/ui/Input.tsx +44 -0
- package/dist/resources/components/registry.json +355 -0
- package/dist/resources/components/vue/feedback/Toast.vue +120 -0
- package/dist/resources/components/vue/feedback/useToast.ts +70 -0
- package/dist/resources/components/vue/media/FileUpload.vue +229 -0
- package/dist/resources/components/vue/media/VideoPlayer.vue +157 -0
- package/dist/resources/components/vue/ui/AppImage.vue +147 -0
- package/dist/resources/components/vue/ui/BottomSheet.vue +217 -0
- package/dist/resources/components/vue/ui/Button.vue +154 -0
- package/dist/resources/components/vue/ui/Card.vue +111 -0
- package/dist/resources/components/vue/ui/Input.vue +113 -0
- package/dist/resources/components/vue/ui/Modal.vue +193 -0
- package/dist/resources/components/vue/ui/ScrollArea.vue +163 -0
- package/dist/resources/components/vue/ui/Tooltip.vue +115 -0
- package/dist/resources/registry.json +158 -0
- package/dist/resources/snippets/node/cache.ts +116 -0
- package/dist/resources/snippets/node/date.ts +126 -0
- package/dist/resources/snippets/node/logger.ts +104 -0
- package/dist/resources/snippets/node/validation.ts +132 -0
- package/dist/resources/snippets/react/useDebounce.ts +90 -0
- package/dist/resources/snippets/registry.json +65 -0
- package/dist/resources/snippets/vue/useAsync.ts +96 -0
- package/dist/resources/snippets/vue/usePagination.ts +102 -0
- package/dist/resources/templates/base/.claude/docs/architecture-template.md +459 -0
- package/dist/resources/templates/base/.claude/docs/architecture.md +137 -0
- package/dist/resources/templates/base/.claude/docs/index.md +42 -0
- package/dist/resources/templates/base/.claude/docs/security-lifecycle.md +129 -0
- package/dist/resources/templates/base/.claude/docs/verification.md +121 -0
- package/dist/resources/templates/base/AGENTS.md +415 -0
- package/dist/resources/templates/base/CLAUDE.md +415 -0
- package/dist/resources/templates/go-backend/.claude/docs/api-design.md +486 -0
- package/dist/resources/templates/go-backend/.claude/docs/architecture-template.md +449 -0
- package/dist/resources/templates/go-backend/.claude/docs/check-list.md +155 -0
- package/dist/resources/templates/go-backend/.claude/docs/database.md +369 -0
- package/dist/resources/templates/go-backend/.claude/docs/e2e-standards.md +161 -0
- package/dist/resources/templates/go-backend/.claude/docs/error-handling.md +558 -0
- package/dist/resources/templates/go-backend/.claude/docs/event-runtime-boundary.md +124 -0
- package/dist/resources/templates/go-backend/.claude/docs/identifier-contract.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/index.md +22 -0
- package/dist/resources/templates/go-backend/.claude/docs/logging.md +314 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-onboarding-sop.md +917 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-quick-reference.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/module-standards.md +309 -0
- package/dist/resources/templates/go-backend/.claude/docs/openapi-contract.md +141 -0
- package/dist/resources/templates/go-backend/.claude/docs/payment-gateway-onboarding.md +283 -0
- package/dist/resources/templates/go-backend/.claude/docs/platform-boundary.md +191 -0
- package/dist/resources/templates/go-backend/.claude/docs/quality-gates.md +112 -0
- package/dist/resources/templates/go-backend/.dockerignore +6 -0
- package/dist/resources/templates/go-backend/.env.example +13 -0
- package/dist/resources/templates/go-backend/.gitattributes +2 -0
- package/dist/resources/templates/go-backend/AGENTS.md +1139 -0
- package/dist/resources/templates/go-backend/CLAUDE.md +1139 -0
- package/dist/resources/templates/go-backend/Dockerfile +14 -0
- package/dist/resources/templates/go-backend/Makefile +71 -0
- package/dist/resources/templates/go-backend/README.md +66 -0
- package/dist/resources/templates/go-backend/_gitignore +10 -0
- package/dist/resources/templates/go-backend/api/openapi/README.md +29 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/artifact-manifest.json +19 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/conformance-matrix.json +276 -0
- package/dist/resources/templates/go-backend/api/openapi/document.go +30 -0
- package/dist/resources/templates/go-backend/api/openapi/package.json +28 -0
- package/dist/resources/templates/go-backend/api/openapi/pnpm-lock.yaml +3052 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly-source.yaml +18 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly.yaml +8 -0
- package/dist/resources/templates/go-backend/api/openapi/sdk-generators.json +16 -0
- package/dist/resources/templates/go-backend/api/openapi/service-registry.json +39 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/breaking.mjs +416 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/build.mjs +103 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/conformance_coverage.mjs +111 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_compiler.mjs +62 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_policy.mjs +208 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/delegated_contract.mjs +302 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/deterministic_archive.mjs +69 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_example_privacy.mjs +93 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_projection.mjs +498 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_quality.mjs +346 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/git_artifact_history.mjs +188 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/manifest.mjs +170 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/overlay.mjs +98 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/project.mjs +549 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/route_contract.mjs +156 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/runtime_conformance.mjs +193 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/scalar_asset_localization.mjs +164 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/sdk_generator.mjs +229 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/semantic_version.mjs +64 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/service_contract_inputs.mjs +16 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/breaking.test.mjs +365 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/build.test.mjs +42 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/conformance_coverage.test.mjs +88 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/contract_policy.test.mjs +257 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/delegated_contract.test.mjs +205 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_example_privacy.test.mjs +51 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_projection.test.mjs +368 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_quality.test.mjs +151 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/git_artifact_history.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/head_policy.test.mjs +8 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/overlay.test.mjs +44 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/projection.test.mjs +270 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/redocly_documentation_rules.test.mjs +146 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/release_manifest.test.mjs +76 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/route_contract.test.mjs +119 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/runtime_conformance.test.mjs +75 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/scalar_asset_localization.test.mjs +50 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/sdk_generator.test.mjs +31 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/semantic_version.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/service_contract_inputs.test.mjs +27 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/resources.go +125 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime.go +102 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime_test.go +70 -0
- package/dist/resources/templates/go-backend/cmd/product-api/lifecycle_test.go +58 -0
- package/dist/resources/templates/go-backend/cmd/product-api/main.go +32 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire.go +13 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire_gen.go +94 -0
- package/dist/resources/templates/go-backend/cmd/worker/main.go +47 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire.go +14 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire_gen.go +111 -0
- package/dist/resources/templates/go-backend/configs/config.yaml +37 -0
- package/dist/resources/templates/go-backend/deployments/compose.yaml +71 -0
- package/dist/resources/templates/go-backend/docs/openapi-provenance.json +489 -0
- package/dist/resources/templates/go-backend/docs/runtime-provenance.json +175 -0
- package/dist/resources/templates/go-backend/docs/source-provenance.json +3568 -0
- package/dist/resources/templates/go-backend/docs/standards-provenance.json +1624 -0
- package/dist/resources/templates/go-backend/go.mod +256 -0
- package/dist/resources/templates/go-backend/go.sum +805 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical.go +370 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical_test.go +223 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/contracts.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/contentaccess/contentaccess.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/contracts/contact.go +85 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/identity.go +20 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/product.go +53 -0
- package/dist/resources/templates/go-backend/internal/common/enumdomain/payment.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/dto_admin.go +9 -0
- package/dist/resources/templates/go-backend/internal/common/enums/enum.go +1247 -0
- package/dist/resources/templates/go-backend/internal/common/enums/handler_admin.go +66 -0
- package/dist/resources/templates/go-backend/internal/common/enums/module.go +46 -0
- package/dist/resources/templates/go-backend/internal/common/enums/provider.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_audit.go +274 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_command_replay.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_config.go +27 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_locale.go +37 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_ops.go +14 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_outbox.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_rule_expression.go +63 -0
- package/dist/resources/templates/go-backend/internal/common/enums/registry.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin_test.go +38 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext_test.go +29 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_binding.go +26 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter.go +173 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter_test.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/authorization_details.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies.go +660 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/audience_token_source.go +166 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bootstrap_token_exchanger.go +183 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bound_service_token_signer.go +52 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger.go +189 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/product_scoped_service_token_signer.go +92 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/provider.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/request_signer.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver.go +69 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver_test.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope.go +95 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope_test.go +78 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/service_identity_test.go +387 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler_test.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale.go +145 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale_test.go +75 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref.go +54 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_auth.go +320 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_throttle.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth_test.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/client_context.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/cors.go +68 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/event_context.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/gateway_identity.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/helpers.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_route_permission.go +171 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth.go +151 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_identity.go +138 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_token_auth.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent.go +273 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent_test.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission_test.go +186 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/logging.go +191 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/metrics.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/middleware_test.go +1516 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context.go +160 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context_test.go +355 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/product_context.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/recovery.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/referral_attribution.go +178 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/requestid.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission.go +790 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission_test.go +440 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/service_credential_auth.go +67 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/tenant.go +148 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/throttle.go +310 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/money/currency.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/money/errors.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/money/format.go +123 -0
- package/dist/resources/templates/go-backend/internal/common/money/format_test.go +204 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway.go +144 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway_test.go +165 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/principal/context.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/principal/principal.go +49 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema.go +577 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema_test.go +47 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request.go +246 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/common/response/pagination.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/response/response.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/response/response_test.go +463 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast.go +141 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical.go +184 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder.go +555 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder_test.go +260 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/errors.go +55 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator.go +96 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator_test.go +220 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/fuzz_test.go +116 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/limits.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema.go +412 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema_test.go +164 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input.go +627 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input_test.go +245 -0
- package/dist/resources/templates/go-backend/internal/common/semver/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver_test.go +205 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier.go +33 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier_test.go +32 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator_test.go +396 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/prefix.go +247 -0
- package/dist/resources/templates/go-backend/internal/common/types/asset_url.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing.go +89 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/types/country.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/types/country_test.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/currency.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/types/identifiers.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/types/operator.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/types/tier.go +72 -0
- package/dist/resources/templates/go-backend/internal/common/types/types.go +411 -0
- package/dist/resources/templates/go-backend/internal/common/types/types_test.go +295 -0
- package/dist/resources/templates/go-backend/internal/common/utils/constants.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto_test.go +345 -0
- package/dist/resources/templates/go-backend/internal/common/utils/duration.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/utils/helpers.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json_test.go +76 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination_test.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer.go +107 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer_test.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/utils/slice.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake_test.go +316 -0
- package/dist/resources/templates/go-backend/internal/common/utils/string.go +16 -0
- package/dist/resources/templates/go-backend/internal/common/utils/timefmt.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator.go +136 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator_test.go +240 -0
- package/dist/resources/templates/go-backend/internal/common/youtubeapi/client.go +224 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator.go +78 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator_test.go +108 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.js +2385 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.metadata.json +10 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route.go +107 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route_test.go +200 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar.go +117 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy.go +91 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/audit/actor_resolver.go +36 -0
- package/dist/resources/templates/go-backend/internal/core/audit/constants.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context.go +119 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context_test.go +310 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto.go +468 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto_admin.go +172 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum.go +460 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum_test.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/audit/errors.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/handler.go +568 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener.go +319 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware.go +669 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware_test.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/audit/model.go +306 -0
- package/dist/resources/templates/go-backend/internal/core/audit/partition_job.go +316 -0
- package/dist/resources/templates/go-backend/internal/core/audit/ports.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/provider.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository.go +1007 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository_test.go +934 -0
- package/dist/resources/templates/go-backend/internal/core/audit/router.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service.go +770 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/core/audit/vo_admin.go +475 -0
- package/dist/resources/templates/go-backend/internal/core/cache/config.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key.go +41 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key_test.go +62 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1.go +153 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1_test.go +212 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager.go +278 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager_provider.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/cache/metrics.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace_test.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options.go +39 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options_test.go +96 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis.go +311 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer.go +31 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer_test.go +139 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight_test.go +211 -0
- package/dist/resources/templates/go-backend/internal/core/cache/warming.go +86 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock.go +66 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock_test.go +26 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock.go +283 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model_test.go +79 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/namespace.go +7 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence_test.go +185 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/provider.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/repository.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service.go +853 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_persistence_test.go +432 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_test.go +891 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/types.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/config/config.go +2069 -0
- package/dist/resources/templates/go-backend/internal/core/config/config_test.go +1122 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/contract_test.go +388 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/docs.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/verify.go +424 -0
- package/dist/resources/templates/go-backend/internal/core/config/enum.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata.go +717 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata_test.go +228 -0
- package/dist/resources/templates/go-backend/internal/core/config/product_admin_config_test.go +210 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm.go +111 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm_test.go +364 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/encryptor.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor.go +134 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor_test.go +118 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem_test.go +44 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider.go +130 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider_test.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/database/base_model.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/database/clickhouse.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/database/database.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/database/database_logger_test.go +95 -0
- package/dist/resources/templates/go-backend/internal/core/database/errors.go +25 -0
- package/dist/resources/templates/go-backend/internal/core/database/metrics_plugin.go +105 -0
- package/dist/resources/templates/go-backend/internal/core/database/pool_collector.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/database/read_replica.go +520 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction_test.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock.go +353 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock_test.go +106 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler.go +189 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler_test.go +515 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus.go +667 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus_test.go +792 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/noop.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/provider.go +20 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/publisher.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/redis.go +109 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing_test.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/model.go +19 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/service.go +88 -0
- package/dist/resources/templates/go-backend/internal/core/health/health.go +333 -0
- package/dist/resources/templates/go-backend/internal/core/health/health_test.go +27 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client.go +772 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client_test.go +287 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download.go +578 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download_test.go +374 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/jwk.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring.go +144 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring_test.go +128 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/registry.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger_test.go +194 -0
- package/dist/resources/templates/go-backend/internal/core/observability/metrics.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry.go +445 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry_privacy_test.go +175 -0
- package/dist/resources/templates/go-backend/internal/core/observability/tracing.go +187 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/persistence.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/provider.go +23 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay.go +1138 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_postgres_test.go +257 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_test.go +690 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler.go +164 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler_test.go +209 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer.go +249 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_postgres_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_test.go +123 -0
- package/dist/resources/templates/go-backend/internal/core/provider.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware_test.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue.go +288 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead.go +514 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead_test.go +984 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker_test.go +788 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry.go +318 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry_test.go +735 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/recorder.go +305 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context.go +124 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context_test.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler.go +1589 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler_control_test.go +808 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider.go +398 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider_test.go +89 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path.go +110 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path_test.go +301 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider.go +489 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/storage/storage.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation.go +225 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation_test.go +495 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/logger.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider_test.go +67 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/config.go +58 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/handler.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/hub.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/message.go +273 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/notifier.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/provider.go +33 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action.go +77 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action_test.go +238 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/condition.go +107 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/decision.go +256 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/enum.go +643 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/errors.go +102 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/principal_record.go +21 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/product_context.go +486 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource.go +215 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource_test.go +242 -0
- package/dist/resources/templates/go-backend/internal/products/README.md +5 -0
- package/dist/resources/templates/go-backend/internal/sharedevents/README.md +5 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.down.sql +13 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.up.sql +886 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error.go +327 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_code.go +65 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_test.go +41 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_type.go +14 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response.go +216 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response_test.go +216 -0
- package/dist/resources/templates/go-backend/scripts/check-openapi-clean-deletion.sh +54 -0
- package/dist/resources/templates/go-backend/scripts/test-migrations.sh +32 -0
- package/dist/resources/templates/go-backend/tests/infrastructure.sql +69 -0
- package/dist/resources/templates/mcp-server/.claude/docs/stack.md +338 -0
- package/dist/resources/templates/mcp-server/.editorconfig +13 -0
- package/dist/resources/templates/mcp-server/.env.example +8 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/bug_report.yml +104 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/feature_request.yml +54 -0
- package/dist/resources/templates/mcp-server/.github/PULL_REQUEST_TEMPLATE.md +36 -0
- package/dist/resources/templates/mcp-server/.github/workflows/ci.yml +78 -0
- package/dist/resources/templates/mcp-server/.husky/commit-msg +1 -0
- package/dist/resources/templates/mcp-server/.husky/pre-commit +1 -0
- package/dist/resources/templates/mcp-server/.lintstagedrc.json +4 -0
- package/dist/resources/templates/mcp-server/.nvmrc +1 -0
- package/dist/resources/templates/mcp-server/.prettierrc +8 -0
- package/dist/resources/templates/mcp-server/CONTRIBUTING.md +184 -0
- package/dist/resources/templates/mcp-server/Dockerfile +23 -0
- package/dist/resources/templates/mcp-server/LICENSE +21 -0
- package/dist/resources/templates/mcp-server/README.md +123 -0
- package/dist/resources/templates/mcp-server/_gitignore +26 -0
- package/dist/resources/templates/mcp-server/commitlint.config.js +24 -0
- package/dist/resources/templates/mcp-server/eslint.config.js +30 -0
- package/dist/resources/templates/mcp-server/package.json +72 -0
- package/dist/resources/templates/mcp-server/src/index.ts +27 -0
- package/dist/resources/templates/mcp-server/src/resources.ts +33 -0
- package/dist/resources/templates/mcp-server/src/services/.gitkeep +0 -0
- package/dist/resources/templates/mcp-server/src/tools.ts +43 -0
- package/dist/resources/templates/mcp-server/src/types/index.ts +19 -0
- package/dist/resources/templates/mcp-server/src/utils/index.ts +31 -0
- package/dist/resources/templates/mcp-server/tsconfig.json +22 -0
- package/dist/resources/templates/mcp-server/tsup.config.ts +14 -0
- package/dist/resources/templates/mcp-server/vitest.config.ts +15 -0
- package/dist/resources/templates/nuxt/.claude/docs/stack.md +666 -0
- package/dist/resources/templates/nuxt/.editorconfig +15 -0
- package/dist/resources/templates/nuxt/.env.example +22 -0
- package/dist/resources/templates/nuxt/.github/workflows/ci.yml +34 -0
- package/dist/resources/templates/nuxt/.husky/commit-msg +1 -0
- package/dist/resources/templates/nuxt/.husky/pre-commit +1 -0
- package/dist/resources/templates/nuxt/.nvmrc +1 -0
- package/dist/resources/templates/nuxt/.prettierignore +9 -0
- package/dist/resources/templates/nuxt/.prettierrc +1 -0
- package/dist/resources/templates/nuxt/README.md +23 -0
- package/dist/resources/templates/nuxt/_gitignore +7 -0
- package/dist/resources/templates/nuxt/app/app.config.ts +105 -0
- package/dist/resources/templates/nuxt/app/i18n/locales/en.json +5 -0
- package/dist/resources/templates/nuxt/app/pages/app/index.vue +224 -0
- package/dist/resources/templates/nuxt/app/pages/authors/[slug].vue +37 -0
- package/dist/resources/templates/nuxt/app/pages/blog/[slug].vue +55 -0
- package/dist/resources/templates/nuxt/app/pages/blog/category/[category].vue +38 -0
- package/dist/resources/templates/nuxt/app/pages/blog/index.vue +46 -0
- package/dist/resources/templates/nuxt/app/pages/index.vue +626 -0
- package/dist/resources/templates/nuxt/app/pages/legal/privacy.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/legal/terms.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/ui/index.vue +397 -0
- package/dist/resources/templates/nuxt/commitlint.config.mjs +1 -0
- package/dist/resources/templates/nuxt/eslint.config.mjs +4 -0
- package/dist/resources/templates/nuxt/lint-staged.config.mjs +8 -0
- package/dist/resources/templates/nuxt/nuxt.config.ts +71 -0
- package/dist/resources/templates/nuxt/package.json +67 -0
- package/dist/resources/templates/nuxt/public/apple-touch-icon.png +0 -0
- package/dist/resources/templates/nuxt/public/favicon.ico +0 -0
- package/dist/resources/templates/nuxt/public/favicon.svg +5 -0
- package/dist/resources/templates/nuxt/public/icon-16x16.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-192x192.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-32x32.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-512x512.png +0 -0
- package/dist/resources/templates/nuxt/public/logo.svg +6 -0
- package/dist/resources/templates/nuxt/public/media/hero-product-gallery.png +0 -0
- package/dist/resources/templates/nuxt/server/api/content/sitemap-urls.get.ts +12 -0
- package/dist/resources/templates/nuxt/server/api/preview.get.ts +9 -0
- package/dist/resources/templates/nuxt/stylelint.config.mjs +3 -0
- package/dist/resources/templates/nuxt/test/e2e/rendering.test.ts +13 -0
- package/dist/resources/templates/nuxt/tsconfig.json +3 -0
- package/dist/resources/templates/nuxt/vitest.config.ts +8 -0
- package/package.json +8 -5
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
package commandreplay
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"bytes"
|
|
5
|
+
"context"
|
|
6
|
+
"crypto/rand"
|
|
7
|
+
"crypto/sha256"
|
|
8
|
+
"crypto/subtle"
|
|
9
|
+
"encoding/base64"
|
|
10
|
+
"encoding/hex"
|
|
11
|
+
"encoding/json"
|
|
12
|
+
"errors"
|
|
13
|
+
"strings"
|
|
14
|
+
"time"
|
|
15
|
+
"unicode/utf8"
|
|
16
|
+
|
|
17
|
+
"{{module}}/internal/common/canonicaljson"
|
|
18
|
+
"{{module}}/internal/core/database"
|
|
19
|
+
"{{module}}/pkg/apierror"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
const (
|
|
23
|
+
defaultCommandReplayTTL = 24 * time.Hour
|
|
24
|
+
|
|
25
|
+
maxNamespaceLength = 200
|
|
26
|
+
maxCommandScopeLength = 128
|
|
27
|
+
maxIdempotencyKeyLength = 191
|
|
28
|
+
maxPrincipalTypeLength = 32
|
|
29
|
+
maxPrincipalRefLength = 64
|
|
30
|
+
maxErrorCodeLength = 120
|
|
31
|
+
maxExternalReferenceTypeLength = 64
|
|
32
|
+
maxExternalReferenceNoLength = 191
|
|
33
|
+
|
|
34
|
+
errCodeCommandReplayConflict = "command_replay_conflict"
|
|
35
|
+
errCodeCommandReplayInProgress = "command_replay_in_progress"
|
|
36
|
+
errCodeCommandReplayExpired = "command_replay_expired"
|
|
37
|
+
commandReplayExecutionTokenSize = 32
|
|
38
|
+
maxExternalLeaseTTL = 15 * time.Minute
|
|
39
|
+
maxExternalRecoveryBatchSize = 500
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
// CommandReplayService 提供跨领域命令共享的幂等回放契约。
|
|
43
|
+
type CommandReplayService struct {
|
|
44
|
+
repo CommandReplayRepository
|
|
45
|
+
txManager *database.TransactionManager
|
|
46
|
+
now func() time.Time
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// NewCommandReplayService 创建命令幂等回放服务。
|
|
50
|
+
func NewCommandReplayService(repo CommandReplayRepository, txManager *database.TransactionManager) *CommandReplayService {
|
|
51
|
+
return &CommandReplayService{
|
|
52
|
+
repo: repo,
|
|
53
|
+
txManager: txManager,
|
|
54
|
+
now: func() time.Time { return time.Now().UTC() },
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Execute 在同一命令事务内完成幂等注册、业务执行和终态持久化。
|
|
59
|
+
func (s *CommandReplayService) Execute(ctx context.Context, req CommandReplayBeginRequest, fn CommandReplayExecuteFunc) (*CommandReplayExecuteResult, error) {
|
|
60
|
+
var result *CommandReplayExecuteResult
|
|
61
|
+
var terminalBusinessErr error
|
|
62
|
+
|
|
63
|
+
err := s.withTransaction(ctx, func(txCtx context.Context) error {
|
|
64
|
+
normalized, normalizeErr := normalizeCommandReplayBeginRequest(req)
|
|
65
|
+
if normalizeErr != nil {
|
|
66
|
+
return normalizeErr
|
|
67
|
+
}
|
|
68
|
+
if fn == nil {
|
|
69
|
+
return apierror.Internal("Command replay execute function is required")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
now := s.now().UTC()
|
|
73
|
+
expiresAt := now.Add(normalized.ttl)
|
|
74
|
+
acquired, lockErr := s.repo.TryAcquireScopeLock(
|
|
75
|
+
txCtx,
|
|
76
|
+
normalized.namespace,
|
|
77
|
+
normalized.commandScope,
|
|
78
|
+
normalized.idempotencyKey,
|
|
79
|
+
)
|
|
80
|
+
if lockErr != nil {
|
|
81
|
+
return apierror.Internal("Failed to acquire command replay scope lock")
|
|
82
|
+
}
|
|
83
|
+
if !acquired {
|
|
84
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "Command replay is already in progress")
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
existing, findErr := s.repo.FindByScope(
|
|
88
|
+
txCtx,
|
|
89
|
+
normalized.namespace,
|
|
90
|
+
normalized.commandScope,
|
|
91
|
+
normalized.idempotencyKey,
|
|
92
|
+
)
|
|
93
|
+
if findErr != nil {
|
|
94
|
+
return apierror.Internal("Failed to load command replay record")
|
|
95
|
+
}
|
|
96
|
+
if existing != nil {
|
|
97
|
+
classified, classifyErr := classifyCommandReplayRecord(existing, normalized.requestHash, now)
|
|
98
|
+
if classifyErr != nil {
|
|
99
|
+
return classifyErr
|
|
100
|
+
}
|
|
101
|
+
result = classified
|
|
102
|
+
if replayErr, replayErrBuildErr := commandReplayBusinessErrorFromRecord(existing); replayErrBuildErr != nil {
|
|
103
|
+
return replayErrBuildErr
|
|
104
|
+
} else if replayErr != nil {
|
|
105
|
+
terminalBusinessErr = replayErr
|
|
106
|
+
}
|
|
107
|
+
return nil
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
record := &CommandReplayRecord{
|
|
111
|
+
Namespace: normalized.namespace,
|
|
112
|
+
CommandScope: normalized.commandScope,
|
|
113
|
+
IdempotencyKey: normalized.idempotencyKey,
|
|
114
|
+
RequestHash: normalized.requestHash,
|
|
115
|
+
PrincipalType: cloneStringPtr(normalized.principalType),
|
|
116
|
+
PrincipalRef: cloneStringPtr(normalized.principalRef),
|
|
117
|
+
Status: CommandReplayStatusStarted,
|
|
118
|
+
ResponsePayload: json.RawMessage(`{}`),
|
|
119
|
+
ExpiresAt: expiresAt,
|
|
120
|
+
Metadata: normalized.metadata,
|
|
121
|
+
}
|
|
122
|
+
if createErr := s.repo.Create(txCtx, record); createErr != nil {
|
|
123
|
+
if !isCommandReplayDuplicateCreateError(createErr) {
|
|
124
|
+
return apierror.Internal("Failed to create command replay record")
|
|
125
|
+
}
|
|
126
|
+
duplicate, reloadErr := s.repo.FindByScope(
|
|
127
|
+
txCtx,
|
|
128
|
+
normalized.namespace,
|
|
129
|
+
normalized.commandScope,
|
|
130
|
+
normalized.idempotencyKey,
|
|
131
|
+
)
|
|
132
|
+
if reloadErr != nil {
|
|
133
|
+
return apierror.Internal("Failed to load command replay record")
|
|
134
|
+
}
|
|
135
|
+
if duplicate == nil {
|
|
136
|
+
return apierror.Internal("Command replay record was not found after duplicate insert")
|
|
137
|
+
}
|
|
138
|
+
classified, classifyErr := classifyCommandReplayRecord(duplicate, normalized.requestHash, now)
|
|
139
|
+
if classifyErr != nil {
|
|
140
|
+
return classifyErr
|
|
141
|
+
}
|
|
142
|
+
result = classified
|
|
143
|
+
if replayErr, replayErrBuildErr := commandReplayBusinessErrorFromRecord(duplicate); replayErrBuildErr != nil {
|
|
144
|
+
return replayErrBuildErr
|
|
145
|
+
} else if replayErr != nil {
|
|
146
|
+
terminalBusinessErr = replayErr
|
|
147
|
+
}
|
|
148
|
+
return nil
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
commandResult, executeErr := fn(txCtx, record)
|
|
152
|
+
if executeErr != nil {
|
|
153
|
+
return executeErr
|
|
154
|
+
}
|
|
155
|
+
normalizedResult, resultErr := normalizeCommandReplayCommandResult(commandResult)
|
|
156
|
+
if resultErr != nil {
|
|
157
|
+
return resultErr
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
completedAt := s.now().UTC()
|
|
161
|
+
switch normalizedResult.status {
|
|
162
|
+
case CommandReplayStatusSucceeded:
|
|
163
|
+
if markErr := s.markSucceeded(txCtx, record.ID, normalizedResult.responsePayload, completedAt); markErr != nil {
|
|
164
|
+
return markErr
|
|
165
|
+
}
|
|
166
|
+
case CommandReplayStatusFailed:
|
|
167
|
+
if markErr := s.markFailed(txCtx, record.ID, normalizedResult.errorCode, normalizedResult.errorStatus, normalizedResult.responsePayload, completedAt); markErr != nil {
|
|
168
|
+
return markErr
|
|
169
|
+
}
|
|
170
|
+
terminalBusinessErr = normalizedResult.returnError
|
|
171
|
+
default:
|
|
172
|
+
return apierror.Internal("Command replay result has invalid status")
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
record.Status = normalizedResult.status
|
|
176
|
+
record.ResponsePayload = append(json.RawMessage(nil), normalizedResult.responsePayload...)
|
|
177
|
+
record.CompletedAt = cloneTimePtr(&completedAt)
|
|
178
|
+
if normalizedResult.status == CommandReplayStatusFailed {
|
|
179
|
+
record.ErrorCode = cloneStringPtr(&normalizedResult.errorCode)
|
|
180
|
+
record.ErrorStatus = cloneIntPtr(&normalizedResult.errorStatus)
|
|
181
|
+
}
|
|
182
|
+
result = &CommandReplayExecuteResult{
|
|
183
|
+
Record: record,
|
|
184
|
+
Replayed: false,
|
|
185
|
+
ResponsePayload: normalizedResult.responsePayload,
|
|
186
|
+
ErrorCode: cloneStringPtr(record.ErrorCode),
|
|
187
|
+
ErrorStatus: cloneIntPtr(record.ErrorStatus),
|
|
188
|
+
Status: normalizedResult.status,
|
|
189
|
+
}
|
|
190
|
+
return nil
|
|
191
|
+
})
|
|
192
|
+
if err != nil {
|
|
193
|
+
return nil, err
|
|
194
|
+
}
|
|
195
|
+
if terminalBusinessErr != nil {
|
|
196
|
+
return result, terminalBusinessErr
|
|
197
|
+
}
|
|
198
|
+
return result, nil
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// BeginExternal 原子创建回放记录、业务预留和首次执行租约。
|
|
202
|
+
func (s *CommandReplayService) BeginExternal(
|
|
203
|
+
ctx context.Context,
|
|
204
|
+
req CommandReplayBeginRequest,
|
|
205
|
+
leaseTTL time.Duration,
|
|
206
|
+
reserve CommandReplayExternalBeginFunc,
|
|
207
|
+
) (*CommandReplayExternalLease, error) {
|
|
208
|
+
normalized, err := normalizeCommandReplayBeginRequest(req)
|
|
209
|
+
if err != nil {
|
|
210
|
+
return nil, err
|
|
211
|
+
}
|
|
212
|
+
if err := validateExternalLeaseTTL(leaseTTL); err != nil {
|
|
213
|
+
return nil, err
|
|
214
|
+
}
|
|
215
|
+
if reserve == nil {
|
|
216
|
+
return nil, apierror.Internal("External command reservation function is required")
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var lease *CommandReplayExternalLease
|
|
220
|
+
err = s.withTransaction(ctx, func(txCtx context.Context) error {
|
|
221
|
+
now := s.now().UTC()
|
|
222
|
+
acquired, lockErr := s.repo.TryAcquireScopeLock(txCtx, normalized.namespace, normalized.commandScope, normalized.idempotencyKey)
|
|
223
|
+
if lockErr != nil {
|
|
224
|
+
return apierror.Internal("Failed to acquire command replay scope lock")
|
|
225
|
+
}
|
|
226
|
+
if !acquired {
|
|
227
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "Command replay is already in progress")
|
|
228
|
+
}
|
|
229
|
+
existing, findErr := s.repo.FindByScope(txCtx, normalized.namespace, normalized.commandScope, normalized.idempotencyKey)
|
|
230
|
+
if findErr != nil {
|
|
231
|
+
return apierror.Internal("Failed to load command replay record")
|
|
232
|
+
}
|
|
233
|
+
if existing != nil {
|
|
234
|
+
if !existing.MatchesRequestHash(normalized.requestHash) {
|
|
235
|
+
return apierror.Conflict(errCodeCommandReplayConflict, "Idempotency key was reused with a different request payload")
|
|
236
|
+
}
|
|
237
|
+
if existing.Status.IsTerminal() {
|
|
238
|
+
replayed, classifyErr := classifyCommandReplayRecord(existing, normalized.requestHash, now)
|
|
239
|
+
if classifyErr != nil {
|
|
240
|
+
return classifyErr
|
|
241
|
+
}
|
|
242
|
+
lease = &CommandReplayExternalLease{RecordID: existing.ID, Replayed: replayed}
|
|
243
|
+
return nil
|
|
244
|
+
}
|
|
245
|
+
if existing.Status != CommandReplayStatusStarted || !existing.HasExternalReservation() || existing.ExternalNextRecoveryAt == nil {
|
|
246
|
+
return apierror.Internal("External command replay record is incomplete")
|
|
247
|
+
}
|
|
248
|
+
if existing.HasActiveExternalLease(now) || now.Before(*existing.ExternalNextRecoveryAt) {
|
|
249
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "Command replay is already in progress")
|
|
250
|
+
}
|
|
251
|
+
executionToken, tokenHash, tokenErr := newCommandReplayExecutionToken()
|
|
252
|
+
if tokenErr != nil {
|
|
253
|
+
return apierror.Internal("Failed to create external command execution lease")
|
|
254
|
+
}
|
|
255
|
+
leaseExpiresAt := now.Add(leaseTTL)
|
|
256
|
+
if claimErr := s.repo.ClaimExternalRecovery(txCtx, existing.ID, *existing.ExternalNextRecoveryAt, tokenHash, leaseExpiresAt); claimErr != nil {
|
|
257
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "External command recovery lease is unavailable")
|
|
258
|
+
}
|
|
259
|
+
lease = externalLeaseFromRecord(existing, executionToken, existing.ExternalAttemptCount+1)
|
|
260
|
+
return nil
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
record := newCommandReplayRecord(normalized, now)
|
|
264
|
+
if createErr := s.repo.Create(txCtx, record); createErr != nil {
|
|
265
|
+
return apierror.Internal("Failed to create command replay record")
|
|
266
|
+
}
|
|
267
|
+
reservation, reserveErr := reserve(txCtx, record)
|
|
268
|
+
if reserveErr != nil {
|
|
269
|
+
return reserveErr
|
|
270
|
+
}
|
|
271
|
+
reservation, reservationErr := normalizeExternalReservation(reservation)
|
|
272
|
+
if reservationErr != nil {
|
|
273
|
+
return reservationErr
|
|
274
|
+
}
|
|
275
|
+
executionToken, tokenHash, tokenErr := newCommandReplayExecutionToken()
|
|
276
|
+
if tokenErr != nil {
|
|
277
|
+
return apierror.Internal("Failed to create external command execution lease")
|
|
278
|
+
}
|
|
279
|
+
leaseExpiresAt := now.Add(leaseTTL)
|
|
280
|
+
if startErr := s.repo.StartExternalExecution(
|
|
281
|
+
txCtx,
|
|
282
|
+
record.ID,
|
|
283
|
+
reservation.ReferenceType,
|
|
284
|
+
reservation.ReferenceNo,
|
|
285
|
+
tokenHash,
|
|
286
|
+
reservation.PreparedResponsePayload,
|
|
287
|
+
leaseExpiresAt,
|
|
288
|
+
); startErr != nil {
|
|
289
|
+
return apierror.Internal("Failed to persist external command execution lease")
|
|
290
|
+
}
|
|
291
|
+
record.ResponsePayload = append(json.RawMessage(nil), reservation.PreparedResponsePayload...)
|
|
292
|
+
lease = &CommandReplayExternalLease{
|
|
293
|
+
RecordID: record.ID, ExecutionToken: executionToken, Reservation: reservation, AttemptCount: 1,
|
|
294
|
+
}
|
|
295
|
+
return nil
|
|
296
|
+
})
|
|
297
|
+
if err != nil {
|
|
298
|
+
return nil, err
|
|
299
|
+
}
|
|
300
|
+
return lease, nil
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ClaimExternalRecovery 领取已到期外部执行记录的新租约。
|
|
304
|
+
func (s *CommandReplayService) ClaimExternalRecovery(
|
|
305
|
+
ctx context.Context,
|
|
306
|
+
recordID int64,
|
|
307
|
+
leaseTTL time.Duration,
|
|
308
|
+
) (*CommandReplayExternalLease, error) {
|
|
309
|
+
if recordID <= 0 {
|
|
310
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "recordID must be positive")
|
|
311
|
+
}
|
|
312
|
+
if err := validateExternalLeaseTTL(leaseTTL); err != nil {
|
|
313
|
+
return nil, err
|
|
314
|
+
}
|
|
315
|
+
var lease *CommandReplayExternalLease
|
|
316
|
+
err := s.withTransaction(ctx, func(txCtx context.Context) error {
|
|
317
|
+
now := s.now().UTC()
|
|
318
|
+
record, findErr := s.repo.FindByIDForUpdate(txCtx, recordID)
|
|
319
|
+
if findErr != nil {
|
|
320
|
+
return apierror.Internal("Failed to load external command replay record")
|
|
321
|
+
}
|
|
322
|
+
if record == nil || record.Status != CommandReplayStatusStarted || !record.HasExternalReservation() || record.ExternalNextRecoveryAt == nil {
|
|
323
|
+
return apierror.NotFound("External command recovery was not found")
|
|
324
|
+
}
|
|
325
|
+
if record.HasActiveExternalLease(now) || now.Before(*record.ExternalNextRecoveryAt) {
|
|
326
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "External command recovery lease is unavailable")
|
|
327
|
+
}
|
|
328
|
+
executionToken, tokenHash, tokenErr := newCommandReplayExecutionToken()
|
|
329
|
+
if tokenErr != nil {
|
|
330
|
+
return apierror.Internal("Failed to create external command recovery lease")
|
|
331
|
+
}
|
|
332
|
+
if claimErr := s.repo.ClaimExternalRecovery(txCtx, record.ID, *record.ExternalNextRecoveryAt, tokenHash, now.Add(leaseTTL)); claimErr != nil {
|
|
333
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "External command recovery lease is unavailable")
|
|
334
|
+
}
|
|
335
|
+
lease = externalLeaseFromRecord(record, executionToken, record.ExternalAttemptCount+1)
|
|
336
|
+
return nil
|
|
337
|
+
})
|
|
338
|
+
if err != nil {
|
|
339
|
+
return nil, err
|
|
340
|
+
}
|
|
341
|
+
return lease, nil
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// CompleteExternal 使用当前租约提交非敏感回放结果。
|
|
345
|
+
func (s *CommandReplayService) CompleteExternal(
|
|
346
|
+
ctx context.Context,
|
|
347
|
+
recordID int64,
|
|
348
|
+
executionToken string,
|
|
349
|
+
complete CommandReplayExternalCompleteFunc,
|
|
350
|
+
) (*CommandReplayExecuteResult, error) {
|
|
351
|
+
if recordID <= 0 || complete == nil {
|
|
352
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "external completion input is invalid")
|
|
353
|
+
}
|
|
354
|
+
tokenHash, err := commandReplayExecutionTokenHash(executionToken)
|
|
355
|
+
if err != nil {
|
|
356
|
+
return nil, err
|
|
357
|
+
}
|
|
358
|
+
var result *CommandReplayExecuteResult
|
|
359
|
+
var terminalBusinessErr error
|
|
360
|
+
err = s.withTransaction(ctx, func(txCtx context.Context) error {
|
|
361
|
+
now := s.now().UTC()
|
|
362
|
+
record, findErr := s.repo.FindByIDForUpdate(txCtx, recordID)
|
|
363
|
+
if findErr != nil {
|
|
364
|
+
return apierror.Internal("Failed to load external command replay record")
|
|
365
|
+
}
|
|
366
|
+
if !hasCurrentExternalLease(record, tokenHash, now) {
|
|
367
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "External command execution lease is invalid or expired")
|
|
368
|
+
}
|
|
369
|
+
commandResult, completeErr := complete(txCtx, record)
|
|
370
|
+
if completeErr != nil {
|
|
371
|
+
return completeErr
|
|
372
|
+
}
|
|
373
|
+
normalizedResult, normalizeErr := normalizeCommandReplayCommandResult(commandResult)
|
|
374
|
+
if normalizeErr != nil {
|
|
375
|
+
return normalizeErr
|
|
376
|
+
}
|
|
377
|
+
if clearErr := s.repo.ClearExternalExecution(txCtx, record.ID, tokenHash); clearErr != nil {
|
|
378
|
+
return apierror.Internal("Failed to clear external command execution lease")
|
|
379
|
+
}
|
|
380
|
+
completedAt := s.now().UTC()
|
|
381
|
+
switch normalizedResult.status {
|
|
382
|
+
case CommandReplayStatusSucceeded:
|
|
383
|
+
if markErr := s.markSucceeded(txCtx, record.ID, normalizedResult.responsePayload, completedAt); markErr != nil {
|
|
384
|
+
return markErr
|
|
385
|
+
}
|
|
386
|
+
case CommandReplayStatusFailed:
|
|
387
|
+
if markErr := s.markFailed(txCtx, record.ID, normalizedResult.errorCode, normalizedResult.errorStatus, normalizedResult.responsePayload, completedAt); markErr != nil {
|
|
388
|
+
return markErr
|
|
389
|
+
}
|
|
390
|
+
terminalBusinessErr = normalizedResult.returnError
|
|
391
|
+
default:
|
|
392
|
+
return apierror.Internal("External command completion has invalid status")
|
|
393
|
+
}
|
|
394
|
+
record.Status = normalizedResult.status
|
|
395
|
+
record.ResponsePayload = append(json.RawMessage(nil), normalizedResult.responsePayload...)
|
|
396
|
+
record.CompletedAt = cloneTimePtr(&completedAt)
|
|
397
|
+
record.ExternalReferenceType = nil
|
|
398
|
+
record.ExternalReferenceNo = nil
|
|
399
|
+
record.ExecutionTokenHash = nil
|
|
400
|
+
record.LeaseExpiresAt = nil
|
|
401
|
+
record.ExternalNextRecoveryAt = nil
|
|
402
|
+
record.ExternalAttemptCount = 0
|
|
403
|
+
record.ExternalLastErrorCode = nil
|
|
404
|
+
if normalizedResult.status == CommandReplayStatusFailed {
|
|
405
|
+
record.ErrorCode = cloneStringPtr(&normalizedResult.errorCode)
|
|
406
|
+
record.ErrorStatus = cloneIntPtr(&normalizedResult.errorStatus)
|
|
407
|
+
}
|
|
408
|
+
result = &CommandReplayExecuteResult{
|
|
409
|
+
Record: record, ResponsePayload: normalizedResult.responsePayload, ErrorCode: cloneStringPtr(record.ErrorCode),
|
|
410
|
+
ErrorStatus: cloneIntPtr(record.ErrorStatus), Status: normalizedResult.status,
|
|
411
|
+
}
|
|
412
|
+
return nil
|
|
413
|
+
})
|
|
414
|
+
if err != nil {
|
|
415
|
+
return nil, err
|
|
416
|
+
}
|
|
417
|
+
if terminalBusinessErr != nil {
|
|
418
|
+
return result, terminalBusinessErr
|
|
419
|
+
}
|
|
420
|
+
return result, nil
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// DeferExternal 记录可重试分类并安排下一次查询。
|
|
424
|
+
func (s *CommandReplayService) DeferExternal(
|
|
425
|
+
ctx context.Context,
|
|
426
|
+
recordID int64,
|
|
427
|
+
executionToken string,
|
|
428
|
+
errorCode string,
|
|
429
|
+
nextRecoveryAt time.Time,
|
|
430
|
+
) error {
|
|
431
|
+
return s.deferExternal(ctx, recordID, executionToken, errorCode, nextRecoveryAt, nil)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// DeferExternalWith 在同一事务内校验租约、提交业务恢复状态并安排下一次查询。
|
|
435
|
+
func (s *CommandReplayService) DeferExternalWith(
|
|
436
|
+
ctx context.Context,
|
|
437
|
+
recordID int64,
|
|
438
|
+
executionToken string,
|
|
439
|
+
errorCode string,
|
|
440
|
+
nextRecoveryAt time.Time,
|
|
441
|
+
deferFn CommandReplayExternalDeferFunc,
|
|
442
|
+
) error {
|
|
443
|
+
if deferFn == nil {
|
|
444
|
+
return apierror.Internal("External command defer callback is required")
|
|
445
|
+
}
|
|
446
|
+
return s.deferExternal(ctx, recordID, executionToken, errorCode, nextRecoveryAt, deferFn)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
func (s *CommandReplayService) deferExternal(
|
|
450
|
+
ctx context.Context,
|
|
451
|
+
recordID int64,
|
|
452
|
+
executionToken string,
|
|
453
|
+
errorCode string,
|
|
454
|
+
nextRecoveryAt time.Time,
|
|
455
|
+
deferFn CommandReplayExternalDeferFunc,
|
|
456
|
+
) error {
|
|
457
|
+
if recordID <= 0 {
|
|
458
|
+
return apierror.BadRequest(apierror.CodeValidationFailed, "recordID must be positive")
|
|
459
|
+
}
|
|
460
|
+
normalizedErrorCode, err := normalizeRequiredString("errorCode", errorCode, maxErrorCodeLength)
|
|
461
|
+
if err != nil {
|
|
462
|
+
return err
|
|
463
|
+
}
|
|
464
|
+
tokenHash, err := commandReplayExecutionTokenHash(executionToken)
|
|
465
|
+
if err != nil {
|
|
466
|
+
return err
|
|
467
|
+
}
|
|
468
|
+
return s.withTransaction(ctx, func(txCtx context.Context) error {
|
|
469
|
+
now := s.now().UTC()
|
|
470
|
+
if !nextRecoveryAt.After(now) {
|
|
471
|
+
return apierror.BadRequest(apierror.CodeValidationFailed, "nextRecoveryAt must be in the future")
|
|
472
|
+
}
|
|
473
|
+
record, findErr := s.repo.FindByIDForUpdate(txCtx, recordID)
|
|
474
|
+
if findErr != nil {
|
|
475
|
+
return apierror.Internal("Failed to load external command replay record")
|
|
476
|
+
}
|
|
477
|
+
if !hasCurrentExternalLease(record, tokenHash, now) {
|
|
478
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "External command execution lease is invalid or expired")
|
|
479
|
+
}
|
|
480
|
+
if deferFn != nil {
|
|
481
|
+
if deferErr := deferFn(txCtx, record); deferErr != nil {
|
|
482
|
+
return deferErr
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if deferErr := s.repo.DeferExternalExecution(txCtx, recordID, tokenHash, normalizedErrorCode, nextRecoveryAt.UTC()); deferErr != nil {
|
|
486
|
+
return apierror.Conflict(errCodeCommandReplayInProgress, "External command execution lease is invalid or expired")
|
|
487
|
+
}
|
|
488
|
+
return nil
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// ListDueExternalRecoveries 有界列出已到期且无有效租约的记录。
|
|
493
|
+
func (s *CommandReplayService) ListDueExternalRecoveries(
|
|
494
|
+
ctx context.Context,
|
|
495
|
+
referenceType string,
|
|
496
|
+
at time.Time,
|
|
497
|
+
limit int,
|
|
498
|
+
) ([]CommandReplayRecord, error) {
|
|
499
|
+
normalizedReferenceType, err := normalizeRequiredString("referenceType", referenceType, maxExternalReferenceTypeLength)
|
|
500
|
+
if err != nil {
|
|
501
|
+
return nil, err
|
|
502
|
+
}
|
|
503
|
+
if limit < 1 || limit > maxExternalRecoveryBatchSize {
|
|
504
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "limit must be between 1 and 500")
|
|
505
|
+
}
|
|
506
|
+
records, err := s.repo.ListDueExternalRecoveries(ctx, normalizedReferenceType, at.UTC(), limit)
|
|
507
|
+
if err != nil {
|
|
508
|
+
return nil, apierror.Internal("Failed to list due external command recoveries")
|
|
509
|
+
}
|
|
510
|
+
return records, nil
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
func newCommandReplayRecord(normalized *normalizedCommandReplayBeginRequest, now time.Time) *CommandReplayRecord {
|
|
514
|
+
return &CommandReplayRecord{
|
|
515
|
+
Namespace: normalized.namespace, CommandScope: normalized.commandScope,
|
|
516
|
+
IdempotencyKey: normalized.idempotencyKey, RequestHash: normalized.requestHash,
|
|
517
|
+
PrincipalType: cloneStringPtr(normalized.principalType), PrincipalRef: cloneStringPtr(normalized.principalRef),
|
|
518
|
+
Status: CommandReplayStatusStarted, ResponsePayload: json.RawMessage(`{}`),
|
|
519
|
+
ExpiresAt: now.Add(normalized.ttl), Metadata: normalized.metadata,
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
func normalizeExternalReservation(reservation CommandReplayExternalReservation) (CommandReplayExternalReservation, error) {
|
|
524
|
+
referenceType, err := normalizeRequiredString("referenceType", reservation.ReferenceType, maxExternalReferenceTypeLength)
|
|
525
|
+
if err != nil {
|
|
526
|
+
return CommandReplayExternalReservation{}, err
|
|
527
|
+
}
|
|
528
|
+
referenceNo, err := normalizeRequiredString("referenceNo", reservation.ReferenceNo, maxExternalReferenceNoLength)
|
|
529
|
+
if err != nil {
|
|
530
|
+
return CommandReplayExternalReservation{}, err
|
|
531
|
+
}
|
|
532
|
+
preparedResponsePayload, err := canonicalRawJSONObject(reservation.PreparedResponsePayload, true)
|
|
533
|
+
if err != nil {
|
|
534
|
+
return CommandReplayExternalReservation{}, err
|
|
535
|
+
}
|
|
536
|
+
return CommandReplayExternalReservation{
|
|
537
|
+
ReferenceType: referenceType,
|
|
538
|
+
ReferenceNo: referenceNo,
|
|
539
|
+
PreparedResponsePayload: preparedResponsePayload,
|
|
540
|
+
}, nil
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
func validateExternalLeaseTTL(leaseTTL time.Duration) error {
|
|
544
|
+
if leaseTTL < time.Second || leaseTTL > maxExternalLeaseTTL {
|
|
545
|
+
return apierror.BadRequest(apierror.CodeValidationFailed, "leaseTTL must be between 1s and 15m")
|
|
546
|
+
}
|
|
547
|
+
return nil
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
func newCommandReplayExecutionToken() (string, string, error) {
|
|
551
|
+
raw := make([]byte, commandReplayExecutionTokenSize)
|
|
552
|
+
if _, err := rand.Read(raw); err != nil {
|
|
553
|
+
return "", "", err
|
|
554
|
+
}
|
|
555
|
+
token := base64.RawURLEncoding.EncodeToString(raw)
|
|
556
|
+
hash := sha256.Sum256(raw)
|
|
557
|
+
return token, hex.EncodeToString(hash[:]), nil
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
func commandReplayExecutionTokenHash(token string) (string, error) {
|
|
561
|
+
raw, err := base64.RawURLEncoding.DecodeString(token)
|
|
562
|
+
if err != nil || len(raw) != commandReplayExecutionTokenSize {
|
|
563
|
+
return "", apierror.Conflict(errCodeCommandReplayInProgress, "External command execution lease is invalid or expired")
|
|
564
|
+
}
|
|
565
|
+
hash := sha256.Sum256(raw)
|
|
566
|
+
return hex.EncodeToString(hash[:]), nil
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
func hasCurrentExternalLease(record *CommandReplayRecord, tokenHash string, at time.Time) bool {
|
|
570
|
+
return record != nil && record.Status == CommandReplayStatusStarted && record.ExecutionTokenHash != nil &&
|
|
571
|
+
record.LeaseExpiresAt != nil && at.Before(*record.LeaseExpiresAt) &&
|
|
572
|
+
subtle.ConstantTimeCompare([]byte(*record.ExecutionTokenHash), []byte(tokenHash)) == 1
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
func externalLeaseFromRecord(record *CommandReplayRecord, executionToken string, attemptCount int) *CommandReplayExternalLease {
|
|
576
|
+
return &CommandReplayExternalLease{
|
|
577
|
+
RecordID: record.ID, ExecutionToken: executionToken,
|
|
578
|
+
Reservation: CommandReplayExternalReservation{
|
|
579
|
+
ReferenceType: *record.ExternalReferenceType,
|
|
580
|
+
ReferenceNo: *record.ExternalReferenceNo,
|
|
581
|
+
PreparedResponsePayload: append(json.RawMessage(nil), record.ResponsePayload...),
|
|
582
|
+
},
|
|
583
|
+
AttemptCount: attemptCount,
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
func normalizeCommandReplayBeginRequest(req CommandReplayBeginRequest) (*normalizedCommandReplayBeginRequest, error) {
|
|
588
|
+
namespace, err := normalizeCommandReplayNamespace(req.Namespace)
|
|
589
|
+
if err != nil {
|
|
590
|
+
return nil, err
|
|
591
|
+
}
|
|
592
|
+
commandScope, err := normalizeRequiredString("commandScope", req.CommandScope, maxCommandScopeLength)
|
|
593
|
+
if err != nil {
|
|
594
|
+
return nil, err
|
|
595
|
+
}
|
|
596
|
+
idempotencyKey, err := normalizeRequiredString("idempotencyKey", req.IdempotencyKey, maxIdempotencyKeyLength)
|
|
597
|
+
if err != nil {
|
|
598
|
+
return nil, err
|
|
599
|
+
}
|
|
600
|
+
requestPayload, err := canonicalRawJSONObject(req.RequestPayload, false)
|
|
601
|
+
if err != nil {
|
|
602
|
+
return nil, err
|
|
603
|
+
}
|
|
604
|
+
requestHash, err := canonicaljson.Hash(requestPayload)
|
|
605
|
+
if err != nil {
|
|
606
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "payload must be a JSON object")
|
|
607
|
+
}
|
|
608
|
+
metadata, err := canonicalRawJSONObject(req.Metadata, true)
|
|
609
|
+
if err != nil {
|
|
610
|
+
return nil, err
|
|
611
|
+
}
|
|
612
|
+
principalType, err := normalizeOptionalString("principalType", req.PrincipalType, maxPrincipalTypeLength)
|
|
613
|
+
if err != nil {
|
|
614
|
+
return nil, err
|
|
615
|
+
}
|
|
616
|
+
principalRef, err := normalizeOptionalString("principalRef", req.PrincipalRef, maxPrincipalRefLength)
|
|
617
|
+
if err != nil {
|
|
618
|
+
return nil, err
|
|
619
|
+
}
|
|
620
|
+
if (principalType == nil) != (principalRef == nil) {
|
|
621
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "principalType and principalRef must be provided together")
|
|
622
|
+
}
|
|
623
|
+
ttl := req.TTL
|
|
624
|
+
if ttl <= 0 {
|
|
625
|
+
ttl = defaultCommandReplayTTL
|
|
626
|
+
}
|
|
627
|
+
return &normalizedCommandReplayBeginRequest{
|
|
628
|
+
namespace: namespace,
|
|
629
|
+
commandScope: commandScope,
|
|
630
|
+
idempotencyKey: idempotencyKey,
|
|
631
|
+
requestHash: requestHash,
|
|
632
|
+
principalType: principalType,
|
|
633
|
+
principalRef: principalRef,
|
|
634
|
+
metadata: metadata,
|
|
635
|
+
ttl: ttl,
|
|
636
|
+
}, nil
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
func normalizeCommandReplayNamespace(value string) (string, error) {
|
|
640
|
+
namespace := strings.TrimSpace(value)
|
|
641
|
+
if utf8.RuneCountInString(namespace) > maxNamespaceLength || !commandReplayNamespacePattern.MatchString(namespace) {
|
|
642
|
+
return "", apierror.BadRequest(apierror.CodeValidationFailed, "namespace must be a valid dotted command namespace")
|
|
643
|
+
}
|
|
644
|
+
return namespace, nil
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
func normalizeCommandReplayCommandResult(result *CommandReplayCommandResult) (*normalizedCommandReplayCommandResult, error) {
|
|
648
|
+
if result == nil {
|
|
649
|
+
return nil, apierror.Internal("Command replay result is required")
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
switch result.Status {
|
|
653
|
+
case CommandReplayStatusSucceeded:
|
|
654
|
+
responsePayload, err := canonicalRawJSONObject(result.ResponsePayload, false)
|
|
655
|
+
if err != nil {
|
|
656
|
+
return nil, err
|
|
657
|
+
}
|
|
658
|
+
if strings.TrimSpace(result.ErrorCode) != "" {
|
|
659
|
+
return nil, apierror.Internal("Successful command replay result cannot include errorCode")
|
|
660
|
+
}
|
|
661
|
+
if result.ReturnError != nil {
|
|
662
|
+
return nil, apierror.Internal("Successful command replay result cannot include returnError")
|
|
663
|
+
}
|
|
664
|
+
return &normalizedCommandReplayCommandResult{
|
|
665
|
+
status: result.Status,
|
|
666
|
+
responsePayload: responsePayload,
|
|
667
|
+
}, nil
|
|
668
|
+
case CommandReplayStatusFailed:
|
|
669
|
+
var apiErr *apierror.APIError
|
|
670
|
+
if !errors.As(result.ReturnError, &apiErr) || apiErr == nil {
|
|
671
|
+
return nil, apierror.Internal("Failed command replay result requires APIError returnError")
|
|
672
|
+
}
|
|
673
|
+
errorCode, codeErr := normalizeRequiredString("errorCode", apiErr.Detail.Code, maxErrorCodeLength)
|
|
674
|
+
if codeErr != nil {
|
|
675
|
+
return nil, codeErr
|
|
676
|
+
}
|
|
677
|
+
if providedErrorCode := strings.TrimSpace(result.ErrorCode); providedErrorCode != "" && providedErrorCode != errorCode {
|
|
678
|
+
return nil, apierror.Internal("Failed command replay result errorCode must match returnError")
|
|
679
|
+
}
|
|
680
|
+
if apiErr.Status < 400 || apiErr.Status > 599 {
|
|
681
|
+
return nil, apierror.Internal("Failed command replay result has invalid error status")
|
|
682
|
+
}
|
|
683
|
+
responsePayload, payloadErr := canonicalAPIErrorPayload(apiErr)
|
|
684
|
+
if payloadErr != nil {
|
|
685
|
+
return nil, payloadErr
|
|
686
|
+
}
|
|
687
|
+
return &normalizedCommandReplayCommandResult{
|
|
688
|
+
status: result.Status,
|
|
689
|
+
responsePayload: responsePayload,
|
|
690
|
+
errorCode: errorCode,
|
|
691
|
+
errorStatus: apiErr.Status,
|
|
692
|
+
returnError: apiErr,
|
|
693
|
+
}, nil
|
|
694
|
+
default:
|
|
695
|
+
return nil, apierror.Internal("Command replay result has invalid status")
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
func classifyCommandReplayRecord(record *CommandReplayRecord, requestHash string, now time.Time) (*CommandReplayExecuteResult, error) {
|
|
700
|
+
if !record.MatchesRequestHash(requestHash) {
|
|
701
|
+
return nil, apierror.Conflict(errCodeCommandReplayConflict, "Idempotency key was reused with a different request payload")
|
|
702
|
+
}
|
|
703
|
+
if record.IsExpiredAt(now) {
|
|
704
|
+
return nil, apierror.Conflict(errCodeCommandReplayExpired, "Idempotency key has expired")
|
|
705
|
+
}
|
|
706
|
+
if record.Status.IsTerminal() {
|
|
707
|
+
return &CommandReplayExecuteResult{
|
|
708
|
+
Record: record,
|
|
709
|
+
Replayed: true,
|
|
710
|
+
ResponsePayload: defaultRawJSONObject(record.ResponsePayload),
|
|
711
|
+
ErrorCode: cloneStringPtr(record.ErrorCode),
|
|
712
|
+
ErrorStatus: cloneIntPtr(record.ErrorStatus),
|
|
713
|
+
Status: record.Status,
|
|
714
|
+
}, nil
|
|
715
|
+
}
|
|
716
|
+
if record.Status == CommandReplayStatusStarted {
|
|
717
|
+
return nil, apierror.Conflict(errCodeCommandReplayInProgress, "Command replay is already in progress")
|
|
718
|
+
}
|
|
719
|
+
return nil, apierror.Internal("Command replay record has invalid status")
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
func canonicalRawJSONObject(raw json.RawMessage, allowEmpty bool) (json.RawMessage, error) {
|
|
723
|
+
trimmed := bytes.TrimSpace(raw)
|
|
724
|
+
if len(trimmed) == 0 {
|
|
725
|
+
if allowEmpty {
|
|
726
|
+
return json.RawMessage(`{}`), nil
|
|
727
|
+
}
|
|
728
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "payload must be a JSON object")
|
|
729
|
+
}
|
|
730
|
+
if trimmed[0] != '{' {
|
|
731
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "payload must be a JSON object")
|
|
732
|
+
}
|
|
733
|
+
canonical, err := canonicaljson.Canonicalize(trimmed)
|
|
734
|
+
if err != nil {
|
|
735
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, "payload must be a JSON object")
|
|
736
|
+
}
|
|
737
|
+
return canonical, nil
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
func defaultRawJSONObject(raw json.RawMessage) json.RawMessage {
|
|
741
|
+
if len(bytes.TrimSpace(raw)) == 0 {
|
|
742
|
+
return json.RawMessage(`{}`)
|
|
743
|
+
}
|
|
744
|
+
return append(json.RawMessage(nil), raw...)
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
func canonicalAPIErrorPayload(apiErr *apierror.APIError) (json.RawMessage, error) {
|
|
748
|
+
raw, err := json.Marshal(apiErr.ToResponse())
|
|
749
|
+
if err != nil {
|
|
750
|
+
return nil, apierror.Internal("Failed to marshal command replay error response")
|
|
751
|
+
}
|
|
752
|
+
return canonicalRawJSONObject(raw, false)
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
func commandReplayBusinessErrorFromRecord(record *CommandReplayRecord) (*apierror.APIError, error) {
|
|
756
|
+
if record == nil || record.Status != CommandReplayStatusFailed {
|
|
757
|
+
return nil, nil
|
|
758
|
+
}
|
|
759
|
+
if record.ErrorCode == nil || strings.TrimSpace(*record.ErrorCode) == "" || record.ErrorStatus == nil {
|
|
760
|
+
return nil, apierror.Internal("Failed command replay record is missing error fields")
|
|
761
|
+
}
|
|
762
|
+
if *record.ErrorStatus < 400 || *record.ErrorStatus > 599 {
|
|
763
|
+
return nil, apierror.Internal("Failed command replay record has invalid error status")
|
|
764
|
+
}
|
|
765
|
+
var response apierror.ErrorResponse
|
|
766
|
+
if err := json.Unmarshal(defaultRawJSONObject(record.ResponsePayload), &response); err != nil {
|
|
767
|
+
return nil, apierror.Internal("Failed command replay record has invalid error response")
|
|
768
|
+
}
|
|
769
|
+
if response.Error.Code != strings.TrimSpace(*record.ErrorCode) {
|
|
770
|
+
return nil, apierror.Internal("Failed command replay record error response does not match errorCode")
|
|
771
|
+
}
|
|
772
|
+
if response.Error.Type == "" || response.Error.Message == "" {
|
|
773
|
+
return nil, apierror.Internal("Failed command replay record error response is incomplete")
|
|
774
|
+
}
|
|
775
|
+
return &apierror.APIError{
|
|
776
|
+
Status: *record.ErrorStatus,
|
|
777
|
+
Detail: response.Error,
|
|
778
|
+
}, nil
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
func normalizeRequiredString(fieldName, value string, maxLength int) (string, error) {
|
|
782
|
+
normalized := strings.TrimSpace(value)
|
|
783
|
+
if normalized == "" {
|
|
784
|
+
return "", apierror.BadRequest(apierror.CodeValidationFailed, fieldName+" is required")
|
|
785
|
+
}
|
|
786
|
+
if utf8.RuneCountInString(normalized) > maxLength {
|
|
787
|
+
return "", apierror.BadRequest(apierror.CodeValidationFailed, fieldName+" is too long")
|
|
788
|
+
}
|
|
789
|
+
return normalized, nil
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
func normalizeOptionalString(fieldName string, value *string, maxLength int) (*string, error) {
|
|
793
|
+
if value == nil {
|
|
794
|
+
return nil, nil
|
|
795
|
+
}
|
|
796
|
+
normalized := strings.TrimSpace(*value)
|
|
797
|
+
if normalized == "" {
|
|
798
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, fieldName+" must not be blank")
|
|
799
|
+
}
|
|
800
|
+
if utf8.RuneCountInString(normalized) > maxLength {
|
|
801
|
+
return nil, apierror.BadRequest(apierror.CodeValidationFailed, fieldName+" is too long")
|
|
802
|
+
}
|
|
803
|
+
return &normalized, nil
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
func (s *CommandReplayService) markSucceeded(ctx context.Context, recordID int64, responsePayload json.RawMessage, completedAt time.Time) error {
|
|
807
|
+
if markErr := s.repo.MarkSucceeded(ctx, recordID, responsePayload, completedAt); markErr != nil {
|
|
808
|
+
return apierror.Internal("Failed to mark command replay record as succeeded")
|
|
809
|
+
}
|
|
810
|
+
return nil
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
func (s *CommandReplayService) markFailed(ctx context.Context, recordID int64, errorCode string, errorStatus int, responsePayload json.RawMessage, completedAt time.Time) error {
|
|
814
|
+
if markErr := s.repo.MarkFailed(ctx, recordID, errorCode, errorStatus, responsePayload, completedAt); markErr != nil {
|
|
815
|
+
return apierror.Internal("Failed to mark command replay record as failed")
|
|
816
|
+
}
|
|
817
|
+
return nil
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
func isCommandReplayDuplicateCreateError(err error) bool {
|
|
821
|
+
return errors.Is(err, ErrCommandReplayRecordExists) || database.IsDuplicateKeyError(err)
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
func (s *CommandReplayService) withTransaction(ctx context.Context, fn func(context.Context) error) error {
|
|
825
|
+
if s.txManager == nil {
|
|
826
|
+
return apierror.Internal("Transaction manager is required")
|
|
827
|
+
}
|
|
828
|
+
return s.txManager.WithTransaction(ctx, fn)
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
func cloneStringPtr(value *string) *string {
|
|
832
|
+
if value == nil {
|
|
833
|
+
return nil
|
|
834
|
+
}
|
|
835
|
+
cloned := *value
|
|
836
|
+
return &cloned
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
func cloneTimePtr(value *time.Time) *time.Time {
|
|
840
|
+
if value == nil {
|
|
841
|
+
return nil
|
|
842
|
+
}
|
|
843
|
+
cloned := *value
|
|
844
|
+
return &cloned
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
func cloneIntPtr(value *int) *int {
|
|
848
|
+
if value == nil {
|
|
849
|
+
return nil
|
|
850
|
+
}
|
|
851
|
+
cloned := *value
|
|
852
|
+
return &cloned
|
|
853
|
+
}
|