-
Notifications
You must be signed in to change notification settings - Fork 2
feat(data-access): add feedback review constants + verdict/signal helpers (SITES-43974) #1696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
721a01e
feat(data-access): add feedback review constants + verdict/signal hel…
tathagat2241 63de6fb
address PR comments.
tathagat2241 5ce9f1c
Merge branch 'main' into SITES-43974-feedback-event-pipeline
tathagat2241 f7318b0
bump mysticat-data-service version.
tathagat2241 cd138a8
Merge branch 'SITES-43974-feedback-event-pipeline' of https://github.…
tathagat2241 44d0613
test(data-access): pin IT image to v5.51.0 (v5.24.1 pruned; v5.52.0 d…
tathagat2241 0710a50
Merge branch 'main' into SITES-43974-feedback-event-pipeline
tathagat2241 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
packages/spacecat-shared-data-access/src/models/feedback-event/feedback-event.constants.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview Shared constants + helpers for the human-review feedback loop | ||
| * (SITES-43974). The `feedback_event` table has a client-supplied `event_id` | ||
| * primary key and is append-only, so it is NOT modelled as a data-access entity | ||
| * (the entity framework forces an auto-generated `id` PK). Producers and | ||
| * consumers — `spacecat-api-service` (capture + ?include=reviews composition) | ||
| * and `spacecat-jobs-dispatcher` (the daily JSONL exporter) — talk to the table | ||
| * via the raw `postgrestClient`. These constants + the verdict<->signal | ||
| * translation live here so the enum values and the JSONL contract never drift | ||
| * across those repos. | ||
| */ | ||
|
|
||
| /** | ||
| * Capture surface. Derived server-side from the API route (never trusted from | ||
| * the request body — FR-10). Only `backoffice` is wired up for v1; `aso_ui` and | ||
| * `aemy_pr` are reserved. | ||
| */ | ||
| export const REVIEW_SOURCES = Object.freeze({ | ||
| BACKOFFICE: 'backoffice', | ||
| ASO_UI: 'aso_ui', | ||
| AEMY_PR: 'aemy_pr', | ||
| }); | ||
|
|
||
| /** | ||
| * App-layer verdict — what the reviewer expresses in the UI / request body. | ||
| */ | ||
| export const REVIEW_VERDICTS = Object.freeze({ | ||
| UP: 'up', | ||
| DOWN: 'down', | ||
| }); | ||
|
|
||
| /** | ||
| * Persisted training label on `feedback_event.signal`. Translated once from the | ||
| * verdict at capture time (see {@link verdictToSignal}). | ||
| */ | ||
| export const REVIEW_SIGNALS = Object.freeze({ | ||
| POSITIVE: 'positive', | ||
| NEGATIVE: 'negative', | ||
| }); | ||
|
|
||
| /** | ||
| * Optional ESE category on a reject. `product_bug` rows are filtered OUT of the | ||
| * Learning Agent export (routed to Jira); `bad_recommendation` / `other` / NULL | ||
| * are exported. | ||
| */ | ||
| export const REJECTION_CATEGORIES = Object.freeze({ | ||
| PRODUCT_BUG: 'product_bug', | ||
| BAD_RECOMMENDATION: 'bad_recommendation', | ||
| OTHER: 'other', | ||
| }); | ||
|
|
||
| /** | ||
| * Commerce tier of the reviewed site at review time. | ||
| */ | ||
| export const FEEDBACK_TIERS = Object.freeze({ | ||
| PAID: 'paid', | ||
| FREE: 'free', | ||
| }); | ||
|
|
||
| /** | ||
| * Rejection categories whose rows must NOT be exported to the Learning Agent | ||
| * training corpus (they describe product/detection bugs the LA cannot learn | ||
| * from). The exporter filters these out; NULL-category rows are still exported. | ||
| */ | ||
| export const EXPORT_EXCLUDED_REJECTION_CATEGORIES = Object.freeze([ | ||
| REJECTION_CATEGORIES.PRODUCT_BUG, | ||
| ]); | ||
|
|
||
| /** | ||
| * Customer-derived fields stripped from the JSONL export for organizations with | ||
| * `training_opt_in = false`. Verdict / signal / category / identity metadata | ||
| * still ship. | ||
| */ | ||
| export const OPT_OUT_STRIPPED_FIELDS = Object.freeze([ | ||
| 'previousFix', | ||
| 'editedFix', | ||
| 'detailMarkdown', | ||
| ]); | ||
|
|
||
| /** | ||
| * Translate the app-layer verdict to the persisted training signal. Single | ||
| * source of truth shared by the capture handler and any consumer. | ||
| * | ||
| * @param {string} verdict - one of {@link REVIEW_VERDICTS}. | ||
| * @returns {string} the corresponding {@link REVIEW_SIGNALS} value. | ||
| * @throws {Error} if the verdict is not a recognised value. | ||
| */ | ||
| export function verdictToSignal(verdict) { | ||
| if (verdict === REVIEW_VERDICTS.UP) { | ||
| return REVIEW_SIGNALS.POSITIVE; | ||
| } | ||
| if (verdict === REVIEW_VERDICTS.DOWN) { | ||
| return REVIEW_SIGNALS.NEGATIVE; | ||
| } | ||
| throw new Error(`Invalid review verdict: ${verdict}`); | ||
| } | ||
|
|
||
| /** | ||
| * Inverse of {@link verdictToSignal} — translate a persisted signal back to the | ||
| * app-layer verdict (used when composing reviews into an API response). | ||
| * | ||
| * @param {string} signal - one of {@link REVIEW_SIGNALS}. | ||
| * @returns {string} the corresponding {@link REVIEW_VERDICTS} value. | ||
| * @throws {Error} if the signal is not a recognised value. | ||
| */ | ||
| export function signalToVerdict(signal) { | ||
| if (signal === REVIEW_SIGNALS.POSITIVE) { | ||
| return REVIEW_VERDICTS.UP; | ||
| } | ||
| if (signal === REVIEW_SIGNALS.NEGATIVE) { | ||
| return REVIEW_VERDICTS.DOWN; | ||
| } | ||
| throw new Error(`Invalid review signal: ${signal}`); | ||
| } | ||
|
|
||
| /** | ||
| * Map a raw `feedback_event` row (snake_case, as returned by PostgREST) to the | ||
| * API review view (camelCase, verdict-flavoured). The heavy patch fields | ||
| * (`previous_fix` / `edited_fix`) are omitted unless `includePatches` is set — | ||
| * they exist for training export, not for the default read response. | ||
| * | ||
| * @param {object} row - a raw feedback_event row from PostgREST. | ||
| * @param {object} [options] | ||
| * @param {boolean} [options.includePatches=false] - include previous/edited fix. | ||
| * @returns {object} the review view object. | ||
| */ | ||
| export function toReviewView(row, { includePatches = false } = {}) { | ||
| const view = { | ||
| eventId: row.event_id, | ||
| eventTime: row.event_time, | ||
| source: row.source, | ||
| verdict: signalToVerdict(row.signal), | ||
| signal: row.signal, | ||
| reviewerId: row.reviewer_id ?? null, | ||
| detailMarkdown: row.detail_markdown ?? null, | ||
| rejectionCategory: row.rejection_category ?? null, | ||
| stateTransition: row.state_transition ?? null, | ||
| tier: row.tier, | ||
| }; | ||
|
|
||
| if (includePatches) { | ||
| view.previousFix = row.previous_fix ?? null; | ||
| view.editedFix = row.edited_fix ?? null; | ||
| } | ||
|
|
||
| return view; | ||
| } | ||
60 changes: 60 additions & 0 deletions
60
packages/spacecat-shared-data-access/src/models/feedback-event/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| export const REVIEW_SOURCES: Readonly<{ | ||
| BACKOFFICE: 'backoffice'; | ||
| ASO_UI: 'aso_ui'; | ||
| AEMY_PR: 'aemy_pr'; | ||
| }>; | ||
|
|
||
| export const REVIEW_VERDICTS: Readonly<{ UP: 'up'; DOWN: 'down' }>; | ||
|
|
||
| export const REVIEW_SIGNALS: Readonly<{ POSITIVE: 'positive'; NEGATIVE: 'negative' }>; | ||
|
|
||
| export const REJECTION_CATEGORIES: Readonly<{ | ||
| PRODUCT_BUG: 'product_bug'; | ||
| BAD_RECOMMENDATION: 'bad_recommendation'; | ||
| OTHER: 'other'; | ||
| }>; | ||
|
|
||
| export const FEEDBACK_TIERS: Readonly<{ PAID: 'paid'; FREE: 'free' }>; | ||
|
|
||
| export const EXPORT_EXCLUDED_REJECTION_CATEGORIES: ReadonlyArray<string>; | ||
|
|
||
| export const OPT_OUT_STRIPPED_FIELDS: ReadonlyArray<string>; | ||
|
|
||
| /** Translate the app-layer verdict (`up`/`down`) to the persisted signal. */ | ||
| export function verdictToSignal(verdict: string): 'positive' | 'negative'; | ||
|
|
||
| /** Translate a persisted signal (`positive`/`negative`) back to the verdict. */ | ||
| export function signalToVerdict(signal: string): 'up' | 'down'; | ||
|
|
||
| export interface ReviewView { | ||
| eventId: string; | ||
| eventTime: string; | ||
| source: string; | ||
| verdict: 'up' | 'down'; | ||
| signal: 'positive' | 'negative'; | ||
| reviewerId: string | null; | ||
| detailMarkdown: string | null; | ||
| rejectionCategory: string | null; | ||
| stateTransition: string | null; | ||
| tier: string; | ||
| previousFix?: unknown; | ||
| editedFix?: unknown; | ||
| } | ||
|
|
||
| /** Map a raw PostgREST `feedback_event` row to the API review view. */ | ||
| export function toReviewView( | ||
| row: Record<string, unknown>, | ||
| options?: { includePatches?: boolean }, | ||
| ): ReviewView; |
28 changes: 28 additions & 0 deletions
28
packages/spacecat-shared-data-access/src/models/feedback-event/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| // feedback_event has a client-supplied PK and is append-only, so it is NOT a | ||
| // data-access entity (no model/collection/schema/registry). This barrel only | ||
| // re-exports the shared constants + verdict<->signal helpers consumed by | ||
| // spacecat-api-service and spacecat-jobs-dispatcher. | ||
| export { | ||
| REVIEW_SOURCES, | ||
| REVIEW_VERDICTS, | ||
| REVIEW_SIGNALS, | ||
| REJECTION_CATEGORIES, | ||
| FEEDBACK_TIERS, | ||
| EXPORT_EXCLUDED_REJECTION_CATEGORIES, | ||
| OPT_OUT_STRIPPED_FIELDS, | ||
| verdictToSignal, | ||
| signalToVerdict, | ||
| toReviewView, | ||
| } from './feedback-event.constants.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.