Skip to content

Add controlled TokMetric activation console#219

Open
support371 wants to merge 23 commits into
mainfrom
feat/tokmetric-activation-command-center
Open

Add controlled TokMetric activation console#219
support371 wants to merge 23 commits into
mainfrom
feat/tokmetric-activation-command-center

Conversation

@support371

@support371 support371 commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Adds the protected TokMetric activation console and routes its internal workflow through the existing administrator gateway.

Included:

  • live workspace status and blockers
  • internal drafts and immutable versions
  • compliance review
  • exact-version approvals with separation of duties
  • controlled publishing preflight
  • connector and posting-scope checks
  • session-revocation enforcement
  • regression coverage

External TikTok publishing, advertising, and Shop writes remain disabled.

Release status: mergeable, but not ready to merge. Vercel verification is rate-limited and the updated administrator gateway has not been activated in Supabase.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a governed TokMetric command gateway and a protected activation console that operates on real workspace data but keeps all TikTok publishing actions internal and fail-closed, wired through a Next.js API route and a shared gateway client, with tests ensuring the gateway is included in production and constrained to GEM admin sessions.

Sequence diagram for TokMetric create_draft command flow

sequenceDiagram
  actor Admin
  participant TokMetricActivationPanel
  participant TokMetricCommandRoute as api_tokmetric_command_route
  participant GatewayClient as invokeTokMetricCommandGateway
  participant SupabaseFunction as gem_tokmetric_command_gateway
  participant Database

  Admin->>TokMetricActivationPanel: click Create draft
  TokMetricActivationPanel->>TokMetricCommandRoute: POST /api/tokmetric/command
  TokMetricCommandRoute->>TokMetricCommandRoute: getGatewaySessionToken
  TokMetricCommandRoute->>GatewayClient: invokeTokMetricCommandGateway(token, create_draft, payload)
  GatewayClient->>SupabaseFunction: POST gem-tokmetric-command-gateway
  SupabaseFunction->>SupabaseFunction: requireOperator(token)
  SupabaseFunction->>SupabaseFunction: dispatch(create_draft)
  SupabaseFunction->>Database: insert tokmetric_contents, tokmetric_content_versions
  Database-->>SupabaseFunction: OK
  SupabaseFunction-->>GatewayClient: { ok: true, externalActionTaken: false }
  GatewayClient-->>TokMetricCommandRoute: result
  TokMetricCommandRoute-->>TokMetricActivationPanel: JSON 201
  TokMetricActivationPanel-->>Admin: show success notice
Loading

File-Level Changes

Change Details Files
Wire a protected activation panel into the TokMetric command center UI to drive internal drafts, reviews, approvals, and preflight from real workspace data.
  • Import and render the new activation panel component in the existing TokMetric command center page and mark the command-center workflow as READY in the control state.
  • Implement a client-side React activation panel that loads a workspace snapshot, surfaces connectors and content, and issues commands for the controlled activation sequence via a single API endpoint.
  • Provide operator controls for TikTok OAuth start, draft creation, compliance review, approval requests/decisions, and publishing preflight while clearly indicating that no external actions are taken.
src/app/app/command-center/tokmetric/page.tsx
src/components/tokmetric/TokMetricActivationPanel.tsx
Introduce a Supabase Edge function as the governed TokMetric command gateway enforcing GEM admin sessions and a controlled activation sequence, with fail-closed publishing behavior.
  • Set up a strict edge runtime with Supabase client and CORS for the command gateway, including workspace identification and admin-role-only access.
  • Implement helpers for session validation, input validation, canonical hashing, workspace lookup, audit logging, and domain events.
  • Add operations for snapshot, draft creation, content versioning, compliance review, approval request/decision, and publishing preflight, all returning externalActionTaken=false and blocking when live gates or approvals are missing.
  • Route GET/POST requests through the dispatcher with structured error handling and environment-derived activation flags, and configure Deno compiler options for strict typing.
supabase/functions/gem-tokmetric-command-gateway/index.ts
supabase/functions/gem-tokmetric-command-gateway/deno.json
Add a Next.js API route and shared gateway client to proxy TokMetric commands through the HttpOnly GEM session token with timeouts and constrained operations.
  • Implement a gateway client that posts commands to the Supabase function with a bearer token, fixed timeout, and normalized error handling via GatewayRequestError.
  • Expose a /api/tokmetric/command route that validates JSON, restricts allowed operations, injects the GEM gateway session token, and forwards commands to the edge gateway with appropriate status codes and headers.
  • Ensure the API route does not access service-role secrets directly and enforces authentication via GEM_SESSION_REQUIRED errors.
src/app/api/tokmetric/command/route.ts
src/lib/tokmetric/command-gateway.ts
Ensure deployment and behavior constraints via tests and build configuration for the TokMetric command gateway.
  • Update .vercelignore to keep the TokMetric Supabase edge function included in production builds via negative rules.
  • Add Vitest tests that assert the gateway is retained, requires versioned GEM admin sessions, keeps activation internal and fail-closed, supports all operations, proxies through GEM session-only API, and exposes the operator controls in the UI.
  • Verify that no direct external TikTok publish calls or privileged environment variables are referenced in the route or gateway code.
.vercelignore
src/__tests__/tokmetric-activation-command-center.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
support371-gem-enterprise Error Error Jul 17, 2026 10:21am
8 Skipped Deployments
Project Deployment Actions Updated (UTC)
gem-enterprise Ignored Ignored Preview Jul 17, 2026 10:21am
gem-enterprise-in Ignored Ignored Preview Jul 17, 2026 10:21am
gem-enterprise-jx Ignored Ignored Preview Jul 17, 2026 10:21am
v0-continue-conversation Ignored Ignored Preview Jul 17, 2026 10:21am
v0-continue-conversation-3875 Ignored Ignored Preview Jul 17, 2026 10:21am
v0-deployment-alignment-task Ignored Ignored Preview Jul 17, 2026 10:21am
v0-image-analysis Ignored Ignored Preview Jul 17, 2026 10:21am
v0-v0-geraldhoeven-4141-ff89f7f-5 Ignored Ignored Preview Jul 17, 2026 10:21am

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The workspace ID is hard-coded in both the Supabase function and the React panel; consider centralizing this into a shared configuration/constant to avoid drift and make future workspace changes safer.
  • Operation names are duplicated across the edge gateway dispatch logic, the Next.js API route OPERATIONS set, and the TokMetricCommandOperation union; aligning these via a single shared definition or enum would reduce the risk of mismatches when adding or renaming operations.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The workspace ID is hard-coded in both the Supabase function and the React panel; consider centralizing this into a shared configuration/constant to avoid drift and make future workspace changes safer.
- Operation names are duplicated across the edge gateway dispatch logic, the Next.js API route `OPERATIONS` set, and the `TokMetricCommandOperation` union; aligning these via a single shared definition or enum would reduce the risk of mismatches when adding or renaming operations.

## Individual Comments

### Comment 1
<location path="src/app/api/tokmetric/command/route.ts" line_range="99-102" />
<code_context>
+    );
+  }
+  const payload = body as Record<string, unknown>;
+  const operation =
+    typeof payload.operation === "string"
+      ? (payload.operation as TokMetricCommandOperation)
+      : "snapshot";
+  if (!OPERATIONS.has(operation)) {
+    return json(
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Defaulting to `snapshot` when `operation` is omitted may hide client-side bugs.

This silent fallback makes it easy for clients to ship code that omits or misnames `operation` without noticing, including cases where a write was intended but the payload was malformed. Consider treating a missing `operation` as a 4xx error and requiring explicit operations, with `GET` remaining the way to request snapshots.

Suggested implementation:

```typescript
  const payload = body as Record<string, unknown>;

  if (typeof payload.operation !== "string") {
    return json(
      {
        error: "TokMetric command operation is required.",
        code: "INVALID_OPERATION",
      },
      400,
    );
  }

  const operation = payload.operation as TokMetricCommandOperation;

  if (!OPERATIONS.has(operation)) {
    return json(
      {
        error: "TokMetric command operation is invalid.",
        code: "INVALID_OPERATION",
      },
      400,
    );

```

1. Any client code issuing POST requests to this `/tokmetric/command` route must now always include a valid `operation` field; missing or malformed values will receive a 400 response.
2. Ensure the snapshot behavior via `GET` is documented and, if implemented in a separate handler/file, confirm it remains the sanctioned way to request snapshots without an explicit `operation` field.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/app/api/tokmetric/command/route.ts Outdated
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 17, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
gem-enterprise 8e700f8 Jul 17 2026, 10:30 AM

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/admin-25521151s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/geraldhoeven-4141s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/carolinasuarez8419-9338s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/alliancetrustrealtyearner-cells-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/carolinasuarez8419-9338s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/dpj58sq6xc-2324s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/geraldhoeven-4141s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/legal-9831s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/garciamirandaramirez-2606s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/jamesaugustine199726-2076s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/gilbertmichael561-5155s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/support-8685s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/victoriaeleanor544-2270s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/gemassists-projects-3feb3fa9?upgradeToPro=build-rate-limit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant