{"success":true,"name":"tazmall-prod-write","description":"Use for any TazMall production DB read/write (hide/mask a vendor or product, check catalogue, audit public listing). Direct Mongo access exists on [PRIVATE_HOST] — no owner escalation needed for routine reversible changes.","category":"unitary","path":"unitary/tazmall-prod-write/SKILL.md","file":"SKILL.md","content":"---\nname: tazmall-prod-write\ndescription: Use for any TazMall production DB read/write (hide/mask a vendor or product, check catalogue, audit public listing). Direct Mongo access exists on [PRIVATE_HOST] — no owner escalation needed for routine reversible changes.\n---\n\nAll commands run on [PRIVATE_HOST]: `ssh [PRIVATE_HOST] 'cd ~/unitary && <command>'`. The TazMall repo (`[PATH] MultiVendor`) holds `.env.prod` with the Mongo URI — this is the LIVE production database, not a staging copy.\n\n## The write tool: agents/tazmall-manager/tools/db.mjs\n\nThis is the standing, already-working path to prod — do not escalate to the owner for a routine reversible catalogue change; just use it.\n\n```\nnode agents/tazmall-manager/tools/db.mjs <ABSOLUTE-path-to-script.mjs>\n```\n\nThe script must `export default async (db, env) => {...}`. **The path argument must be absolute** — `db.mjs` does `import(process.argv[2])` from its own working context, so a relative path throws `ERR_MODULE_NOT_FOUND: Cannot find package 'agents'`. Write your script locally, `scp` it to an `agents/tazmall-manager/tools/<name>.mjs` path on [PRIVATE_HOST], then invoke with that full `[PATH]` path.\n\n**Never `import('mongodb')` or `import('bson')` yourself inside the script** to build an `ObjectId` for an `$in` query — the repo has multiple bson versions across node_modules and a mismatched one throws `BSONVersionError: Unsupported BSON version, bson types must be from bson 7.x.x`. Instead do the whole scan client-side with the `db` connection already given to you: `const all = await db.collection('products').find({}).toArray()`, then filter in JS with `String(doc._id) === targetId` or `targetIdSet.has(String(doc._id))`. Slower on huge collections but always correct, and it's what every precedent script in this folder does.\n\n`db.mjs` already refuses any `products.insertOne/insertMany` with `stock <= 0` (owner rule: never list a product sold out) — do not try to work around this, get the real stock count instead.\n\n## Data model facts (don't re-derive each time)\n\n- Vendors are `users` documents with `role: 'vendor'` — the separate `vendors` collection is empty, never query it.\n- Dropshipped catalogue products (e.g. Tunisianet, Mytek) are **not separate vendor accounts**. They are all products under the single vendor `TazMall Sélection` (`_id 6ab5abe4727af6ff4fdd474d`), distinguished by the product field `sourceSite` (`'tunisianet'`, `'mytek'`, etc.). To act on \"all X products\", filter `products` by `vendor === <Sélection id> && sourceSite === 'x'` — searching vendor names for \"tunisianet\"/\"mytek\" finds nothing.\n- Other known standing vendor ids worth keeping handy: Karffa `69bb068467143bdf1d08e5f5`, Brinis/owner `69bfb0c4951fb98f50ba6a3b`.\n\n## Procedure for any mask/hide/unhide (product, vendor, or source)\n\n1. Read first: query the exact scope (vendor id + any extra filter like `sourceSite`) and print a count before touching anything.\n2. Write a scoped script, same shape as the precedent scripts in `tools/hide-vendors-*.mjs`:\n   - A comment line stating who ordered it and the exact scope.\n   - Collect the target docs, write them to `agents/tazmall-manager/data/backups/<name>-<timestamp>.json` BEFORE any update (bulk-change rule: always back up first, never skip it even under time pressure).\n   - `updateMany(... , { $set: { isActive: false, updatedAt: new Date() } })` — never delete a vendor/product/order, only deactivate. Same pattern in reverse (`isActive: true`) to undo.\n   - Append one line to `agents/tazmall-manager/data/db-writes.jsonl`: `{at, by, op, collection, ids, what, why, backup}`.\n3. Verify the change is actually live, not just written to the DB: hit the public API directly, e.g. `curl https://tazmall.shop/api/products?limit=300` and confirm the hidden items/sourceSite no longer appear (cache or a stale frontend build can lag behind a DB write). When verifying scoped to one category, `/api/products?categoryId=<id>` and `/api/products?categorySlug=<slug>` return DIFFERENT result sets (categoryId matched far fewer products than the real public listing in one check) — use `categorySlug` for a true count, or better, pull the id list the actual page query uses and cross-check those specific ids against the DB rather than trusting either endpoint's total alone.\n4. For dropship sources (Tunisianet/Mytek) specifically, a hide is NOT durable by itself: `systemctl --user list-timers | grep tazmall` on [PRIVATE_HOST] to see what's running, in particular `brimind-tazmall-verify.service` (hourly, `scripts/seed-dropship.js verify --apply`, `--source tunisianet,mytek` by default). It re-checks stock on the source site and sets `isActive: true` again on any product whose `sourceCheck.hiddenByCheck` was already true and is now back in stock — silently undoing a manual `isActive:false` hide within the hour, with no error or log you'd notice unless you re-check. To hide a source permanently: edit `~/.config/systemd/user/brimind-tazmall-verify.service`'s `ExecStart` to add `--source <kept-source-only>` (e.g. `--source mytek` to stop it ever touching tunisianet again), back up the unit file first (`cp x x.bak-<date>`), then `systemctl --user daemon-reload`. Re-run your hide script afterward to re-catch anything the timer already reactivated, and re-verify the public API a second time — the first verification right after the hide can look correct and still drift within the hour.\n\n## Coupon profit ceiling\n\n- Enforce the owner's current **3% maximum coupon**, superseding the older 15% engagement/rank policy. Never let rank bonuses or stale stored percentages exceed it. This is a maximum, not a guarantee of retained profit: a 3% discount can consume the full 3% margin.\n- Change all enforcement layers together: store `src/lib/coupon-rule.js` MAX_PERCENT (used by checkout AND orders), `src/models/Coupon.ts` max, Unitary `agents/tazmall-manager/tools/coupons.mjs` MAX_PERCENT, engagement `lib/score.mjs` hard cap, and `engage/rules.json` maxPercent. Floor the monetary discount to the millime so rounding cannot exceed the ceiling.\n- Repair unused coupon documents above the ceiling with backup + history + db-writes log; preserve active/disabled status, use counters and redemption history. Also cap cached `data/fb-engagement/codes.json` and `undeliverable.json` percentages, preserving deliveredPercent as communication history, or delivery can still advertise old discounts. Update the manager AGENT.md policy without overwriting existing edits. Never run `deliver` just to verify a code fix.\n- Test rail files with `TMPDIR=[PATH] node --test agents/tazmall-manager/engage/test/*.test.mjs` (Node 22 does not accept this directory alone). In-memory createCode mocks must throw before logging an insert; otherwise the real db-writes ledger receives fictitious test records.\n- Verify via POST `/api/checkout/coupon` with a real active Selection product and a live existing coupon (no order is created), plus public 200 and the new build's `_next/static/<BUILD_ID>/_buildManifest.js`. A transient public 404 immediately after the listener restart requires a retry before concluding failure.\n- If git push is rejected because origin advanced, fetch and inspect divergence, cherry-pick only your coupon commit into a detached worktree based on origin/Tazmall, and push HEAD:Tazmall normally; do not force-push or reset the dirty live worktree.\n\n## Homepage asset releases on the [PRIVATE_HOST] → [PRIVATE_HOST] production rail\n\n- Confirm the public Next build ID matches [PRIVATE_HOST]'s [PRIVATE_HOST] tunnel (`[PRIVATE_HOST]`) and the current artifact before choosing a host; [PRIVATE_HOST]'s `:3024` can serve a different build. For the December 3, 2026 homepage release, public traffic matched `brimind-proj-tazmall.service` on [PRIVATE_HOST], mirrored by `brimind-proj-sync-tazmall.service` on [PRIVATE_HOST]. The checkout branch name/HEAD alone did not identify the exact deployed source.\n- Read only `appDir` out of `.next-list/required-server-files.json` (do not dump the manifest or environment). Its archived stage can identify the actual source snapshot. Verify its relevant source, build configuration and environment against the service without printing credentials. Clone the archived stage, apply only the allowlisted patch, build in isolation, compare route manifests, then test an isolated Next server before swapping artifacts. Do not build the dirty service checkout or overwrite existing production environment or rollback data.\n- `siteassets` can contain multiple documents. Match the complete ordered set of `_id`s from the public `/api/assets`; use a compare-and-set on the current slide array with a private backup and exact readback. For new per-slide CTA links, release the supporting homepage and schema before setting the links. Verify public `/api/assets`, homepage HTML, each rendered carousel slide and each category URL. Production Next ISR can temporarily serve old homepage/API data after the DB write; allow the configured revalidation window before deciding rollout failed.\n- Preserve the prior `.next-list` plus source patch and the DB backup; target just `.next-list` when syncing the staged artifact to the [PRIVATE_HOST] mirror. Restore only touched fields and source paths during rollback, and verify the prior public release. On December 3 the homepage release went from `kt1rMaGFBv0i1UZMQ3c9_` to `D-_I4mYbEuR7Qp8l2DxMi`; rollback script and prior artifact were retained outside the [PRIVATE_HOST] checkout at `/mnt/ssdext-home/GitHub/.tazmall-home-20261203`.\n\n## When to actually escalate to the owner\n\nOnly for things outside this tool's safe, reversible scope: hard deletes, schema/field changes, payment/account changes, or anything the dry-run count check would refuse. Routine \"hide/show this vendor or product line\" is NOT one of these — do it directly with the procedure above.\n","linked_files":[],"origin":"brimind","owner_id":null,"source":"router"}