@stackonward/cli 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +16 -12
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
package checkoutbff
|
|
2
|
+
|
|
3
|
+
import "time"
|
|
4
|
+
|
|
5
|
+
const (
|
|
6
|
+
TargetTypeCatalogPrice = "catalog_price"
|
|
7
|
+
TargetTypeBenefitUpgradeQuote = "benefit_upgrade_quote"
|
|
8
|
+
TargetTypeCreditTopUpQuote = "credit_top_up_quote"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// DelegatedActor 是产品 BFF 从当前已认证会话提取的委托主体。
|
|
12
|
+
type DelegatedActor struct {
|
|
13
|
+
SubjectToken string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// SessionTargetRequest 指定 Checkout owner 可以解析的公开业务目标。
|
|
17
|
+
type SessionTargetRequest struct {
|
|
18
|
+
Type string `json:"type"`
|
|
19
|
+
Reference string `json:"reference"`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// BillingJurisdiction 是创建会话时冻结的计税国家事实。
|
|
23
|
+
type BillingJurisdiction struct {
|
|
24
|
+
CountryCode string `json:"country_code"`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// CreateSessionRequest 是产品 façade 提交给 Platform Checkout owner 的受信任命令。
|
|
28
|
+
type CreateSessionRequest struct {
|
|
29
|
+
Target SessionTargetRequest `json:"target"`
|
|
30
|
+
Currency string `json:"currency"`
|
|
31
|
+
Quantity int `json:"quantity"`
|
|
32
|
+
CouponCode *string `json:"coupon_code,omitempty"`
|
|
33
|
+
SurfaceCode string `json:"surface_code"`
|
|
34
|
+
BillingJurisdiction BillingJurisdiction `json:"billing_jurisdiction"`
|
|
35
|
+
CustomerEmail string `json:"customer_email"`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// RequestContext 承载跨服务调用允许透传的非秘密请求上下文。
|
|
39
|
+
type RequestContext struct {
|
|
40
|
+
// AppVersion 是产品应用版本。
|
|
41
|
+
AppVersion string
|
|
42
|
+
// ClientPlatform 是客户端运行平台。
|
|
43
|
+
ClientPlatform string
|
|
44
|
+
// ClientType 是客户端形态。
|
|
45
|
+
ClientType string
|
|
46
|
+
// ClientVersion 是客户端实现版本。
|
|
47
|
+
ClientVersion string
|
|
48
|
+
// ClientLocale 是客户端显式选择的语言区域。
|
|
49
|
+
ClientLocale string
|
|
50
|
+
// AcceptLanguage 是入口请求的语言偏好。
|
|
51
|
+
AcceptLanguage string
|
|
52
|
+
// DeviceID 是产品边界提供的设备引用。
|
|
53
|
+
DeviceID string
|
|
54
|
+
// ClientIP 是受信任入口解析的客户端网络地址。
|
|
55
|
+
ClientIP string
|
|
56
|
+
// GeoCountryCode 是受信任入口解析的国家代码。
|
|
57
|
+
GeoCountryCode string
|
|
58
|
+
// GeoCity 是受信任入口解析的城市。
|
|
59
|
+
GeoCity string
|
|
60
|
+
// SessionID 是产品会话的稳定引用。
|
|
61
|
+
SessionID string
|
|
62
|
+
// TouchID 是营销触点的稳定引用。
|
|
63
|
+
TouchID string
|
|
64
|
+
// CampaignID 是营销活动的稳定引用。
|
|
65
|
+
CampaignID string
|
|
66
|
+
// AttributionSource 是归因来源编码。
|
|
67
|
+
AttributionSource string
|
|
68
|
+
// RequestID 是入口请求的追踪引用。
|
|
69
|
+
RequestID string
|
|
70
|
+
// Traceparent 是 W3C Trace Context 父级标识。
|
|
71
|
+
Traceparent string
|
|
72
|
+
// Tracestate 是 W3C Trace Context 供应商状态。
|
|
73
|
+
Tracestate string
|
|
74
|
+
// Baggage 是 W3C 追踪上下文附加信息。
|
|
75
|
+
Baggage string
|
|
76
|
+
// UserAgent 是入口请求的客户端代理标识。
|
|
77
|
+
UserAgent string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// SessionResponse 是创建会话后返回的稳定 Checkout 能力。
|
|
81
|
+
type SessionResponse struct {
|
|
82
|
+
CheckoutSessionNo string `json:"checkout_session_no"`
|
|
83
|
+
ExpiresAt time.Time `json:"expires_at"`
|
|
84
|
+
CheckoutURL string `json:"checkout_url"`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ReissueAuthorizationResponse 是重新签发会话入口后的稳定 Checkout 能力。
|
|
88
|
+
type ReissueAuthorizationResponse struct {
|
|
89
|
+
CheckoutSessionNo string `json:"checkout_session_no"`
|
|
90
|
+
ExpiresAt time.Time `json:"expires_at"`
|
|
91
|
+
CheckoutURL string `json:"checkout_url"`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// CheckoutResultTarget 是结账结果关联的 canonical 业务目标。
|
|
95
|
+
type CheckoutResultTarget struct {
|
|
96
|
+
Type string `json:"type"`
|
|
97
|
+
Reference string `json:"reference"`
|
|
98
|
+
Name string `json:"name"`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// CheckoutResult 是商业、资金与履约 owner 汇总出的终态事实。
|
|
102
|
+
type CheckoutResult struct {
|
|
103
|
+
SettlementKind *string `json:"settlement_kind"`
|
|
104
|
+
OrderNo *string `json:"order_no"`
|
|
105
|
+
Amount *string `json:"amount"`
|
|
106
|
+
Currency *string `json:"currency"`
|
|
107
|
+
Quantity *int `json:"quantity"`
|
|
108
|
+
WinningExecutionNo *string `json:"winning_execution_no"`
|
|
109
|
+
AuthorizationGrantNo *string `json:"authorization_grant_no"`
|
|
110
|
+
CommercialStatus *string `json:"commercial_status"`
|
|
111
|
+
FinancialStatus *string `json:"financial_status"`
|
|
112
|
+
FulfillmentStatus *string `json:"fulfillment_status"`
|
|
113
|
+
CompensationReason *string `json:"compensation_reason"`
|
|
114
|
+
CompensationStatus *string `json:"compensation_status"`
|
|
115
|
+
SuccessReturnURL string `json:"success_return_url"`
|
|
116
|
+
CancelReturnURL string `json:"cancel_return_url"`
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// CheckoutResultResponse 是当前会话的服务端权威终态结果。
|
|
120
|
+
type CheckoutResultResponse struct {
|
|
121
|
+
CheckoutSessionNo string `json:"checkout_session_no"`
|
|
122
|
+
Status string `json:"status"`
|
|
123
|
+
Target CheckoutResultTarget `json:"target"`
|
|
124
|
+
Result CheckoutResult `json:"result"`
|
|
125
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
package checkoutbff
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"net/http"
|
|
6
|
+
"net/url"
|
|
7
|
+
"strings"
|
|
8
|
+
"time"
|
|
9
|
+
|
|
10
|
+
"{{module}}/internal/common/internalservice"
|
|
11
|
+
"{{module}}/internal/common/types"
|
|
12
|
+
"{{module}}/internal/core/config"
|
|
13
|
+
"{{module}}/internal/core/httpclient"
|
|
14
|
+
"{{module}}/pkg/apierror"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const platformOutboundIdentityName = "platform"
|
|
18
|
+
|
|
19
|
+
type delegatedAccessTokenExchanger interface {
|
|
20
|
+
Exchange(context.Context, string, string) (string, error)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// PlatformClient 适配 Platform Checkout 的 IAM 内部合同。
|
|
24
|
+
type PlatformClient struct {
|
|
25
|
+
client *httpclient.Client
|
|
26
|
+
baseURL string
|
|
27
|
+
delegations delegatedAccessTokenExchanger
|
|
28
|
+
productCode string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// NewPlatformClient 创建由产品 BFF 固定发送身份访问的 Checkout 客户端。
|
|
32
|
+
func NewPlatformClient(
|
|
33
|
+
client *httpclient.Client,
|
|
34
|
+
cfg *config.Config,
|
|
35
|
+
delegations *internalservice.DelegatedAccessTokenExchanger,
|
|
36
|
+
) (*PlatformClient, error) {
|
|
37
|
+
if delegations == nil {
|
|
38
|
+
return nil, apierror.Internal("Checkout platform client dependencies are not configured")
|
|
39
|
+
}
|
|
40
|
+
return newPlatformClient(client, cfg, delegations)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func newPlatformClient(
|
|
44
|
+
client *httpclient.Client,
|
|
45
|
+
cfg *config.Config,
|
|
46
|
+
delegations delegatedAccessTokenExchanger,
|
|
47
|
+
) (*PlatformClient, error) {
|
|
48
|
+
if client == nil || cfg == nil || delegations == nil {
|
|
49
|
+
return nil, apierror.Internal("Checkout platform client dependencies are not configured")
|
|
50
|
+
}
|
|
51
|
+
baseURL := strings.TrimRight(strings.TrimSpace(cfg.InternalService.PlatformBaseURL), "/")
|
|
52
|
+
parsed, err := url.Parse(baseURL)
|
|
53
|
+
if err != nil || parsed.Scheme == "" || parsed.Host == "" || parsed.Path != "/internal/v1" {
|
|
54
|
+
return nil, apierror.Internal("Checkout platform base URL is invalid")
|
|
55
|
+
}
|
|
56
|
+
identity, ok := cfg.InternalService.OutboundIdentities[platformOutboundIdentityName]
|
|
57
|
+
if !ok || len(identity.AllowedProductCodes) != 1 {
|
|
58
|
+
return nil, apierror.Internal("Checkout platform identity is invalid")
|
|
59
|
+
}
|
|
60
|
+
productCode := strings.TrimSpace(identity.AllowedProductCodes[0])
|
|
61
|
+
if productCode == "" || strings.TrimSpace(identity.ExpectedServiceAccountCode) == "" {
|
|
62
|
+
return nil, apierror.Internal("Checkout platform identity is invalid")
|
|
63
|
+
}
|
|
64
|
+
retry := httpclient.RetryConfig{
|
|
65
|
+
MaxRetries: 2, RetryDelay: 100 * time.Millisecond, UseExponentialBackoff: true, MaxDelay: time.Second,
|
|
66
|
+
RetryableStatusCodes: []int{http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout},
|
|
67
|
+
RetryOnNetworkError: true,
|
|
68
|
+
}
|
|
69
|
+
return &PlatformClient{
|
|
70
|
+
client: client.WithOptions(httpclient.Options{
|
|
71
|
+
Timeout: cfg.InternalService.RequestTimeout,
|
|
72
|
+
Retry: &retry,
|
|
73
|
+
RedirectPolicy: httpclient.PreserveRedirectResponsePolicy(),
|
|
74
|
+
}),
|
|
75
|
+
baseURL: baseURL, delegations: delegations, productCode: productCode,
|
|
76
|
+
}, nil
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// CreateSession 创建 canonical Checkout Session。
|
|
80
|
+
func (client *PlatformClient) CreateSession(
|
|
81
|
+
ctx context.Context,
|
|
82
|
+
actor DelegatedActor,
|
|
83
|
+
req CreateSessionRequest,
|
|
84
|
+
idempotencyKey string,
|
|
85
|
+
requestContext RequestContext,
|
|
86
|
+
) (SessionResponse, error) {
|
|
87
|
+
var result SessionResponse
|
|
88
|
+
if err := client.call(
|
|
89
|
+
ctx, actor, http.MethodPost, "/checkout-sessions", http.StatusCreated,
|
|
90
|
+
req, &result, idempotencyKey, requestContext,
|
|
91
|
+
); err != nil {
|
|
92
|
+
return SessionResponse{}, err
|
|
93
|
+
}
|
|
94
|
+
if strings.TrimSpace(result.CheckoutSessionNo) == "" || strings.TrimSpace(result.CheckoutURL) == "" || result.ExpiresAt.IsZero() {
|
|
95
|
+
return SessionResponse{}, invalidPlatformContract()
|
|
96
|
+
}
|
|
97
|
+
return result, nil
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// QueryResult 按当前委托主体读取 canonical Checkout 终态结果。
|
|
101
|
+
func (client *PlatformClient) QueryResult(
|
|
102
|
+
ctx context.Context,
|
|
103
|
+
checkoutSessionNo string,
|
|
104
|
+
actor DelegatedActor,
|
|
105
|
+
requestContext RequestContext,
|
|
106
|
+
) (CheckoutResultResponse, error) {
|
|
107
|
+
var result CheckoutResultResponse
|
|
108
|
+
err := client.call(
|
|
109
|
+
ctx, actor, http.MethodGet, "/checkout-results/"+url.PathEscape(checkoutSessionNo),
|
|
110
|
+
http.StatusOK, nil, &result, "", requestContext,
|
|
111
|
+
)
|
|
112
|
+
if err != nil {
|
|
113
|
+
return CheckoutResultResponse{}, err
|
|
114
|
+
}
|
|
115
|
+
if result.CheckoutSessionNo != checkoutSessionNo || strings.TrimSpace(result.Status) == "" ||
|
|
116
|
+
strings.TrimSpace(result.Target.Type) == "" || strings.TrimSpace(result.Target.Reference) == "" {
|
|
117
|
+
return CheckoutResultResponse{}, invalidPlatformContract()
|
|
118
|
+
}
|
|
119
|
+
return result, nil
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ReissueAuthorization 为当前委托主体重新签发 canonical Checkout 入口。
|
|
123
|
+
func (client *PlatformClient) ReissueAuthorization(
|
|
124
|
+
ctx context.Context,
|
|
125
|
+
checkoutSessionNo string,
|
|
126
|
+
actor DelegatedActor,
|
|
127
|
+
idempotencyKey string,
|
|
128
|
+
requestContext RequestContext,
|
|
129
|
+
) (ReissueAuthorizationResponse, error) {
|
|
130
|
+
var result ReissueAuthorizationResponse
|
|
131
|
+
err := client.call(
|
|
132
|
+
ctx, actor, http.MethodPost,
|
|
133
|
+
"/checkout-sessions/"+url.PathEscape(checkoutSessionNo)+"/authorizations/reissue",
|
|
134
|
+
http.StatusOK, nil, &result, idempotencyKey, requestContext,
|
|
135
|
+
)
|
|
136
|
+
if err != nil {
|
|
137
|
+
return ReissueAuthorizationResponse{}, err
|
|
138
|
+
}
|
|
139
|
+
if result.CheckoutSessionNo != checkoutSessionNo || strings.TrimSpace(result.CheckoutURL) == "" || result.ExpiresAt.IsZero() {
|
|
140
|
+
return ReissueAuthorizationResponse{}, invalidPlatformContract()
|
|
141
|
+
}
|
|
142
|
+
return result, nil
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func (client *PlatformClient) call(
|
|
146
|
+
ctx context.Context,
|
|
147
|
+
actor DelegatedActor,
|
|
148
|
+
method string,
|
|
149
|
+
path string,
|
|
150
|
+
expectedStatus int,
|
|
151
|
+
body any,
|
|
152
|
+
result any,
|
|
153
|
+
idempotencyKey string,
|
|
154
|
+
requestContext RequestContext,
|
|
155
|
+
) error {
|
|
156
|
+
delegation, err := client.delegations.Exchange(ctx, actor.SubjectToken, client.productCode)
|
|
157
|
+
if err != nil {
|
|
158
|
+
return platformUnavailable()
|
|
159
|
+
}
|
|
160
|
+
headers := map[string]string{"Authorization": "Bearer " + delegation}
|
|
161
|
+
headers[types.HeaderProductCode] = client.productCode
|
|
162
|
+
headers["Accept"] = "application/json"
|
|
163
|
+
copyRequestContextHeaders(headers, requestContext)
|
|
164
|
+
if value := strings.TrimSpace(idempotencyKey); value != "" {
|
|
165
|
+
headers[types.HeaderIdempotencyKey] = value
|
|
166
|
+
}
|
|
167
|
+
var response *httpclient.Response
|
|
168
|
+
if strings.TrimSpace(idempotencyKey) != "" {
|
|
169
|
+
response, err = client.client.DoWithHeaders(ctx, method, client.baseURL+path, body, result, headers)
|
|
170
|
+
} else {
|
|
171
|
+
response, err = client.client.DoOnceWithHeaders(ctx, method, client.baseURL+path, body, result, headers)
|
|
172
|
+
}
|
|
173
|
+
if err != nil {
|
|
174
|
+
return platformUnavailable()
|
|
175
|
+
}
|
|
176
|
+
if response.StatusCode != expectedStatus {
|
|
177
|
+
return apierror.DecodeHTTPResponse(
|
|
178
|
+
response.StatusCode,
|
|
179
|
+
response.Headers,
|
|
180
|
+
response.Body,
|
|
181
|
+
apierror.New(http.StatusBadGateway, apierror.TypeAPI, "checkout_platform_contract_invalid", "Checkout platform returned an invalid error contract"),
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
return nil
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
func copyRequestContextHeaders(headers map[string]string, requestContext RequestContext) {
|
|
188
|
+
values := map[string]string{
|
|
189
|
+
types.HeaderAppVersion: requestContext.AppVersion, types.HeaderClientPlatform: requestContext.ClientPlatform,
|
|
190
|
+
types.HeaderClientType: requestContext.ClientType, types.HeaderClientVersion: requestContext.ClientVersion,
|
|
191
|
+
types.HeaderClientLocale: requestContext.ClientLocale, "Accept-Language": requestContext.AcceptLanguage,
|
|
192
|
+
types.HeaderDeviceID: requestContext.DeviceID, types.HeaderXRealIP: requestContext.ClientIP,
|
|
193
|
+
types.HeaderGeoIPCountryCode: requestContext.GeoCountryCode, types.HeaderGeoIPCity: requestContext.GeoCity,
|
|
194
|
+
types.HeaderSessionID: requestContext.SessionID, types.HeaderAttributionTouchID: requestContext.TouchID,
|
|
195
|
+
types.HeaderAttributionCampaignID: requestContext.CampaignID, types.HeaderAttributionSource: requestContext.AttributionSource,
|
|
196
|
+
types.HeaderRequestID: requestContext.RequestID, "traceparent": requestContext.Traceparent,
|
|
197
|
+
"tracestate": requestContext.Tracestate, "baggage": requestContext.Baggage, "User-Agent": requestContext.UserAgent,
|
|
198
|
+
}
|
|
199
|
+
for key, value := range values {
|
|
200
|
+
if value = strings.TrimSpace(value); value != "" {
|
|
201
|
+
headers[key] = value
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
func platformUnavailable() *apierror.APIError {
|
|
207
|
+
return apierror.New(http.StatusServiceUnavailable, apierror.TypeAPI, apierror.CodeServiceUnavailable, "Checkout platform is unavailable")
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
func invalidPlatformContract() *apierror.APIError {
|
|
211
|
+
return apierror.New(http.StatusBadGateway, apierror.TypeAPI, "checkout_platform_contract_invalid", "Checkout platform returned an invalid success contract")
|
|
212
|
+
}
|
package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client_test.go
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
package checkoutbff
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"errors"
|
|
7
|
+
"io"
|
|
8
|
+
"net/http"
|
|
9
|
+
"net/http/httptest"
|
|
10
|
+
"sync/atomic"
|
|
11
|
+
"testing"
|
|
12
|
+
"time"
|
|
13
|
+
|
|
14
|
+
"go.uber.org/zap"
|
|
15
|
+
|
|
16
|
+
"{{module}}/internal/common/types"
|
|
17
|
+
"{{module}}/internal/core/config"
|
|
18
|
+
"{{module}}/internal/core/httpclient"
|
|
19
|
+
"{{module}}/pkg/apierror"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
func TestPlatformClientCreatesSessionWithDelegatedAccessToken(t *testing.T) {
|
|
23
|
+
var body map[string]any
|
|
24
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
25
|
+
if r.Method != http.MethodPost || r.URL.Path != "/internal/v1/checkout-sessions" {
|
|
26
|
+
t.Errorf("request = %s %s", r.Method, r.URL.Path)
|
|
27
|
+
http.Error(w, "unexpected request", http.StatusBadRequest)
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
if r.Header.Get("Authorization") != "Bearer delegated-token" || r.Header.Get("X-Product-Code") != "product_alpha" ||
|
|
31
|
+
r.Header.Get(types.HeaderIdempotencyKey) != "checkout-session-001" || r.Header.Get("X-Request-ID") != "request-001" ||
|
|
32
|
+
r.Header.Get(types.HeaderAttributionTouchID) != "touch-001" ||
|
|
33
|
+
r.Header.Get(types.HeaderAttributionCampaignID) != "campaign-001" ||
|
|
34
|
+
r.Header.Get(types.HeaderSessionID) != "701" || r.Header.Get(types.HeaderDeviceID) != "device-001" {
|
|
35
|
+
t.Errorf("headers = %#v", r.Header)
|
|
36
|
+
http.Error(w, "unexpected headers", http.StatusBadRequest)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
40
|
+
t.Errorf("decode request: %v", err)
|
|
41
|
+
http.Error(w, "invalid request", http.StatusBadRequest)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
w.Header().Set("Content-Type", "application/json")
|
|
45
|
+
w.WriteHeader(http.StatusCreated)
|
|
46
|
+
_, _ = w.Write([]byte(`{"checkout_session_no":"chs_001","checkout_url":"https://paykit.test/checkout?authorization_code=cha_001","expires_at":"2026-07-18T12:00:00Z"}`))
|
|
47
|
+
}))
|
|
48
|
+
defer server.Close()
|
|
49
|
+
|
|
50
|
+
var subjectToken, productCode string
|
|
51
|
+
exchanger := &delegatedAccessTokenExchangerStub{exchange: func(_ context.Context, subject, product string) (string, error) {
|
|
52
|
+
subjectToken = subject
|
|
53
|
+
productCode = product
|
|
54
|
+
return "delegated-token", nil
|
|
55
|
+
}}
|
|
56
|
+
client := newPlatformClientForTest(t, server.URL, exchanger)
|
|
57
|
+
coupon := "WELCOME10"
|
|
58
|
+
result, err := client.CreateSession(context.Background(), DelegatedActor{SubjectToken: "subject-token"}, CreateSessionRequest{
|
|
59
|
+
Target: SessionTargetRequest{Type: TargetTypeCatalogPrice, Reference: "1"},
|
|
60
|
+
Currency: "USD", Quantity: 1, CouponCode: &coupon, SurfaceCode: "marketing_modal",
|
|
61
|
+
BillingJurisdiction: BillingJurisdiction{CountryCode: "US"}, CustomerEmail: "owner@example.com",
|
|
62
|
+
}, "checkout-session-001", RequestContext{
|
|
63
|
+
RequestID: "request-001", Traceparent: "00-test", UserAgent: "checkout-test",
|
|
64
|
+
TouchID: "touch-001", CampaignID: "campaign-001", SessionID: "701", DeviceID: "device-001",
|
|
65
|
+
})
|
|
66
|
+
if err != nil {
|
|
67
|
+
t.Fatalf("CreateSession() error = %v", err)
|
|
68
|
+
}
|
|
69
|
+
if result.CheckoutSessionNo != "chs_001" || result.CheckoutURL == "" {
|
|
70
|
+
t.Fatalf("result = %#v", result)
|
|
71
|
+
}
|
|
72
|
+
if subjectToken != "subject-token" || productCode != "product_alpha" {
|
|
73
|
+
t.Fatalf("token exchange input = subject %q, product %q", subjectToken, productCode)
|
|
74
|
+
}
|
|
75
|
+
expectedKeys := map[string]struct{}{
|
|
76
|
+
"target": {}, "currency": {}, "quantity": {}, "coupon_code": {}, "surface_code": {},
|
|
77
|
+
"billing_jurisdiction": {}, "customer_email": {},
|
|
78
|
+
}
|
|
79
|
+
if len(body) != len(expectedKeys) {
|
|
80
|
+
t.Fatalf("body fields = %#v", body)
|
|
81
|
+
}
|
|
82
|
+
for key := range body {
|
|
83
|
+
if _, ok := expectedKeys[key]; !ok {
|
|
84
|
+
t.Fatalf("request contains non-canonical field %q: %#v", key, body)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
target, ok := body["target"].(map[string]any)
|
|
88
|
+
if !ok || target["type"] != TargetTypeCatalogPrice || target["reference"] != "1" {
|
|
89
|
+
t.Fatalf("target = %#v", body["target"])
|
|
90
|
+
}
|
|
91
|
+
jurisdiction, ok := body["billing_jurisdiction"].(map[string]any)
|
|
92
|
+
if !ok || jurisdiction["country_code"] != "US" {
|
|
93
|
+
t.Fatalf("billing_jurisdiction = %#v", body["billing_jurisdiction"])
|
|
94
|
+
}
|
|
95
|
+
for _, forbidden := range []string{
|
|
96
|
+
"locale", "country_code", "user_id", "identity_id", "principal_type", "purchase_option_id", "order_type", "redeem_challenge",
|
|
97
|
+
} {
|
|
98
|
+
if _, exists := body[forbidden]; exists {
|
|
99
|
+
t.Fatalf("request contains forbidden %s: %#v", forbidden, body)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
func TestPlatformClientUsesCanonicalResultAndReissueRoutes(t *testing.T) {
|
|
105
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
106
|
+
if r.Header.Get("Authorization") != "Bearer delegated-token" {
|
|
107
|
+
http.Error(w, "delegated authority missing", http.StatusUnauthorized)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
w.Header().Set("Content-Type", "application/json")
|
|
111
|
+
switch {
|
|
112
|
+
case r.Method == http.MethodGet && r.URL.Path == "/internal/v1/checkout-results/chs_001":
|
|
113
|
+
body, err := io.ReadAll(r.Body)
|
|
114
|
+
if err != nil || len(body) != 0 {
|
|
115
|
+
t.Errorf("result request body = %q, err = %v", body, err)
|
|
116
|
+
}
|
|
117
|
+
_, _ = w.Write([]byte(`{
|
|
118
|
+
"checkout_session_no":"chs_001","status":"completed",
|
|
119
|
+
"target":{"type":"catalog_price","reference":"1","name":"ProductA Pro"},
|
|
120
|
+
"result":{"settlement_kind":"paid","order_no":"ord_001","amount":"9.99","currency":"USD","quantity":1,
|
|
121
|
+
"winning_execution_no":"che_001","authorization_grant_no":null,"commercial_status":"confirmed",
|
|
122
|
+
"financial_status":"paid","fulfillment_status":"fulfilled","compensation_reason":null,
|
|
123
|
+
"compensation_status":null,"success_return_url":"https://example.test/success?checkout_session_no=chs_001",
|
|
124
|
+
"cancel_return_url":"https://example.test/cancel?checkout_session_no=chs_001"}
|
|
125
|
+
}`))
|
|
126
|
+
case r.Method == http.MethodPost && r.URL.Path == "/internal/v1/checkout-sessions/chs_001/authorizations/reissue":
|
|
127
|
+
if r.Header.Get(types.HeaderIdempotencyKey) != "reissue-001" {
|
|
128
|
+
t.Errorf("idempotency header = %q", r.Header.Get(types.HeaderIdempotencyKey))
|
|
129
|
+
}
|
|
130
|
+
body, err := io.ReadAll(r.Body)
|
|
131
|
+
if err != nil || len(body) != 0 {
|
|
132
|
+
t.Errorf("reissue request body = %q, err = %v", body, err)
|
|
133
|
+
}
|
|
134
|
+
_, _ = w.Write([]byte(`{"checkout_session_no":"chs_001","checkout_url":"https://paykit.test/checkout?authorization_code=cha_002","expires_at":"2026-07-18T12:05:00Z"}`))
|
|
135
|
+
default:
|
|
136
|
+
http.Error(w, "unexpected request", http.StatusBadRequest)
|
|
137
|
+
}
|
|
138
|
+
}))
|
|
139
|
+
defer server.Close()
|
|
140
|
+
|
|
141
|
+
client := newPlatformClientForTest(t, server.URL, &delegatedAccessTokenExchangerStub{})
|
|
142
|
+
actor := DelegatedActor{SubjectToken: "subject-token"}
|
|
143
|
+
result, err := client.QueryResult(context.Background(), "chs_001", actor, RequestContext{})
|
|
144
|
+
if err != nil {
|
|
145
|
+
t.Fatalf("QueryResult() error = %v", err)
|
|
146
|
+
}
|
|
147
|
+
if result.CheckoutSessionNo != "chs_001" || result.Status != "completed" || result.Target.Reference != "1" ||
|
|
148
|
+
result.Result.OrderNo == nil || *result.Result.OrderNo != "ord_001" {
|
|
149
|
+
t.Fatalf("result = %#v", result)
|
|
150
|
+
}
|
|
151
|
+
reissued, err := client.ReissueAuthorization(context.Background(), "chs_001", actor, "reissue-001", RequestContext{})
|
|
152
|
+
if err != nil {
|
|
153
|
+
t.Fatalf("ReissueAuthorization() error = %v", err)
|
|
154
|
+
}
|
|
155
|
+
if reissued.CheckoutSessionNo != "chs_001" || reissued.CheckoutURL == "" {
|
|
156
|
+
t.Fatalf("reissued = %#v", reissued)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
func TestPlatformClientRetriesOnlyIdempotentMutation(t *testing.T) {
|
|
161
|
+
var calls atomic.Int32
|
|
162
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
163
|
+
if calls.Add(1) == 1 {
|
|
164
|
+
w.WriteHeader(http.StatusServiceUnavailable)
|
|
165
|
+
_, _ = w.Write([]byte(`{"error":{"type":"api_error","code":"service_unavailable","message":"unavailable"}}`))
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
w.Header().Set("Content-Type", "application/json")
|
|
169
|
+
w.WriteHeader(http.StatusCreated)
|
|
170
|
+
_, _ = w.Write([]byte(`{"checkout_session_no":"chs_002","checkout_url":"https://paykit.test/checkout?authorization_code=cha_002","expires_at":"2026-07-18T12:00:00Z"}`))
|
|
171
|
+
}))
|
|
172
|
+
defer server.Close()
|
|
173
|
+
|
|
174
|
+
client := newPlatformClientForTest(t, server.URL, &delegatedAccessTokenExchangerStub{})
|
|
175
|
+
_, err := client.CreateSession(context.Background(), DelegatedActor{SubjectToken: "subject-token"}, CreateSessionRequest{}, "checkout-session-002", RequestContext{})
|
|
176
|
+
if err != nil {
|
|
177
|
+
t.Fatalf("CreateSession() error = %v", err)
|
|
178
|
+
}
|
|
179
|
+
if calls.Load() != 2 {
|
|
180
|
+
t.Fatalf("idempotent mutation calls = %d", calls.Load())
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
func TestPlatformClientDoesNotRetryResultQuery(t *testing.T) {
|
|
185
|
+
var calls atomic.Int32
|
|
186
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
187
|
+
calls.Add(1)
|
|
188
|
+
w.WriteHeader(http.StatusServiceUnavailable)
|
|
189
|
+
_, _ = w.Write([]byte(`{"error":{"type":"api_error","code":"service_unavailable","message":"unavailable"}}`))
|
|
190
|
+
}))
|
|
191
|
+
defer server.Close()
|
|
192
|
+
|
|
193
|
+
client := newPlatformClientForTest(t, server.URL, &delegatedAccessTokenExchangerStub{})
|
|
194
|
+
if _, err := client.QueryResult(context.Background(), "chs_003", DelegatedActor{SubjectToken: "subject-token"}, RequestContext{}); err == nil {
|
|
195
|
+
t.Fatal("QueryResult() accepted unavailable response")
|
|
196
|
+
}
|
|
197
|
+
if calls.Load() != 1 {
|
|
198
|
+
t.Fatalf("result query calls = %d", calls.Load())
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
func TestPlatformClientRejectsInvalidSuccessContract(t *testing.T) {
|
|
203
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
204
|
+
w.Header().Set("Content-Type", "application/json")
|
|
205
|
+
w.WriteHeader(http.StatusCreated)
|
|
206
|
+
_, _ = w.Write([]byte(`{"checkout_session_no":"","checkout_url":"","expires_at":"0001-01-01T00:00:00Z"}`))
|
|
207
|
+
}))
|
|
208
|
+
defer server.Close()
|
|
209
|
+
|
|
210
|
+
client := newPlatformClientForTest(t, server.URL, &delegatedAccessTokenExchangerStub{})
|
|
211
|
+
if _, err := client.CreateSession(context.Background(), DelegatedActor{SubjectToken: "subject-token"}, CreateSessionRequest{}, "checkout-session-004", RequestContext{}); err == nil {
|
|
212
|
+
t.Fatal("CreateSession() accepted invalid success contract")
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
func TestPlatformClientPreservesCanonicalErrorEnvelope(t *testing.T) {
|
|
217
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
218
|
+
w.Header().Set("Content-Type", "application/json")
|
|
219
|
+
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
220
|
+
_, _ = w.Write([]byte(`{"error":{"type":"api_error","code":"checkout_surface_unavailable","message":"Checkout surface is unavailable"}}`))
|
|
221
|
+
}))
|
|
222
|
+
defer server.Close()
|
|
223
|
+
|
|
224
|
+
client := newPlatformClientForTest(t, server.URL, &delegatedAccessTokenExchangerStub{})
|
|
225
|
+
_, err := client.CreateSession(context.Background(), DelegatedActor{SubjectToken: "subject-token"}, CreateSessionRequest{}, "checkout-session-005", RequestContext{})
|
|
226
|
+
var apiErr *apierror.APIError
|
|
227
|
+
if !errors.As(err, &apiErr) {
|
|
228
|
+
t.Fatalf("CreateSession() error = %v", err)
|
|
229
|
+
}
|
|
230
|
+
if apiErr.Status != http.StatusUnprocessableEntity || apiErr.Detail.Code != "checkout_surface_unavailable" {
|
|
231
|
+
t.Fatalf("CreateSession() error = %#v", apiErr)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
func TestPlatformClientRejectsRedirectAsInvalidContract(t *testing.T) {
|
|
236
|
+
var targetCalls atomic.Int32
|
|
237
|
+
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
238
|
+
targetCalls.Add(1)
|
|
239
|
+
w.WriteHeader(http.StatusCreated)
|
|
240
|
+
}))
|
|
241
|
+
defer target.Close()
|
|
242
|
+
|
|
243
|
+
redirect := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
244
|
+
w.Header().Set("Location", target.URL)
|
|
245
|
+
w.WriteHeader(http.StatusFound)
|
|
246
|
+
}))
|
|
247
|
+
defer redirect.Close()
|
|
248
|
+
|
|
249
|
+
client := newPlatformClientForTest(t, redirect.URL, &delegatedAccessTokenExchangerStub{})
|
|
250
|
+
_, err := client.CreateSession(
|
|
251
|
+
context.Background(), DelegatedActor{SubjectToken: "subject-token"}, CreateSessionRequest{}, "checkout-session-redirect", RequestContext{},
|
|
252
|
+
)
|
|
253
|
+
var apiErr *apierror.APIError
|
|
254
|
+
if !errors.As(err, &apiErr) {
|
|
255
|
+
t.Fatalf("CreateSession() error = %v", err)
|
|
256
|
+
}
|
|
257
|
+
if apiErr.Status != http.StatusBadGateway || apiErr.Detail.Code != "checkout_platform_contract_invalid" {
|
|
258
|
+
t.Fatalf("CreateSession() error = %#v", apiErr)
|
|
259
|
+
}
|
|
260
|
+
if targetCalls.Load() != 0 {
|
|
261
|
+
t.Fatalf("redirect target calls = %d, want 0", targetCalls.Load())
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
func TestPlatformClientFailsClosedWhenDelegationCannotBeIssued(t *testing.T) {
|
|
266
|
+
var calls atomic.Int32
|
|
267
|
+
server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
|
|
268
|
+
calls.Add(1)
|
|
269
|
+
}))
|
|
270
|
+
defer server.Close()
|
|
271
|
+
|
|
272
|
+
exchanger := &delegatedAccessTokenExchangerStub{exchange: func(context.Context, string, string) (string, error) {
|
|
273
|
+
return "", errors.New("authority unavailable")
|
|
274
|
+
}}
|
|
275
|
+
client := newPlatformClientForTest(t, server.URL, exchanger)
|
|
276
|
+
_, err := client.CreateSession(context.Background(), DelegatedActor{SubjectToken: "subject-token"}, CreateSessionRequest{}, "checkout-session-006", RequestContext{})
|
|
277
|
+
var apiErr *apierror.APIError
|
|
278
|
+
if !errors.As(err, &apiErr) || apiErr.Status != http.StatusServiceUnavailable {
|
|
279
|
+
t.Fatalf("CreateSession() error = %#v", err)
|
|
280
|
+
}
|
|
281
|
+
if calls.Load() != 0 {
|
|
282
|
+
t.Fatalf("platform calls = %d, want 0", calls.Load())
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
func newPlatformClientForTest(
|
|
287
|
+
t *testing.T,
|
|
288
|
+
baseURL string,
|
|
289
|
+
exchanger delegatedAccessTokenExchanger,
|
|
290
|
+
) *PlatformClient {
|
|
291
|
+
t.Helper()
|
|
292
|
+
client, err := newPlatformClient(httpclient.New(zap.NewNop()), &config.Config{InternalService: config.InternalServiceConfig{
|
|
293
|
+
PlatformBaseURL: baseURL + "/internal/v1", RequestTimeout: 2 * time.Second,
|
|
294
|
+
OutboundIdentities: map[string]config.InternalServiceIdentityConfig{
|
|
295
|
+
platformOutboundIdentityName: {
|
|
296
|
+
AllowedProductCodes: []string{"product_alpha"}, ExpectedServiceAccountCode: "svc_product_alpha_bff_prod",
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
}}, exchanger)
|
|
300
|
+
if err != nil {
|
|
301
|
+
t.Fatalf("newPlatformClient() error = %v", err)
|
|
302
|
+
}
|
|
303
|
+
return client
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
type delegatedAccessTokenExchangerStub struct {
|
|
307
|
+
exchange func(context.Context, string, string) (string, error)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
func (stub *delegatedAccessTokenExchangerStub) Exchange(
|
|
311
|
+
ctx context.Context,
|
|
312
|
+
subjectToken string,
|
|
313
|
+
productCode string,
|
|
314
|
+
) (string, error) {
|
|
315
|
+
if stub.exchange != nil {
|
|
316
|
+
return stub.exchange(ctx, subjectToken, productCode)
|
|
317
|
+
}
|
|
318
|
+
return "delegated-token", nil
|
|
319
|
+
}
|