Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to loopkit are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [0.6.5] - 2026-12-02

### Changed

- Stamps earned from qkit orders are now Free. The dashboard qkit setting no longer asks for Pro, `saveQkitEarnConfigAction` no longer checks the plan, and migration `0072` drops the `is_pro` check from `qkit_earn_resolve_program`, so a free vendor's stamp program shows on every qkit order by default too. The program-count limit and other Pro features are unchanged. Migration `0072` must be applied to hosted staging and prod by hand.

## [0.6.4] - 2026-12-01

### Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ flips it from a switch there (`src/app/dashboard/customer-notify-settings.tsx`,
under RLS (`for all` own-row policy, not service-role-only). See
`docs/superpowers/specs/2026-08-16-customer-notify-vendor-toggle-design.md`.

Separately, every Pro vendor with a stamp program shows it on qkit orders by default and can switch it off
(migration `0071`; a vendor with no `qkit_earn_config` row offers its oldest active stamp program)
Separately, every vendor with a stamp program (Free or Pro) shows it on qkit orders by default and can switch it off
(migrations `0071`, `0072`; a vendor with no `qkit_earn_config` row offers its oldest active stamp program)
so customers can earn a stamp from a completed
qkit order (`src/app/dashboard/qkit-earn-settings.tsx`) — this is a pull-model
claim link, not push automation: qkit shows a stamp card on the
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loopkit",
"version": "0.6.4",
"version": "0.6.5",
"private": true,
"packageManager": "pnpm@11.10.0",
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions src/app/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo
- `stamp-actions.ts` — server actions that change a card: `stampAction` (`add_stamp`, `rewardReady` via `getProgress` so every type's engine decides), `adjustStampAction` (manual `±` correction with a required reason via `loopkit.adjust_stamp`, free-tier), `recordVisitAction` (engine play path for Lucky Tap/Sprout with a server-side roll and `record_visit_checked`), `redeemPlantAction` and `regenerateCardAction` (credential rotation that keeps progress)
- `lookup-actions.ts` — read-only server actions: `resolveTokenAction` (scanned token to a `kind: "card" | "voucher"` result, falling back to `voucher_by_token` on a card miss) and `lookupAction` (a card's per-type progress by phone, no visit recorded)
- `redeem-actions.ts` — server actions that redeem: `redeemAction` (resets a full card, then alerts the vendor on Telegram and the customer when `vendor_notify_settings` allows it; a missing row means on and notify failures never change the result), `redeemVoucherAction` (catalog-mode Points Club voucher via `redeem_voucher_by_token`, mapping `already_redeemed`/`expired` to friendly copy) and `applyPointsOffsetAction` (offset-mode points deduction returning the dollar figure)
- `settings-actions.ts` — vendor settings actions: `saveQkitEarnConfigAction` (Pro-gated qkit-order earn program) and `saveCustomerNotifySettingsAction` (customer redemption-notify toggle, not Pro-gated), both upserting on `vendor_id`
- `settings-actions.ts` — vendor settings actions: `saveQkitEarnConfigAction` (qkit-order earn program, Free for every vendor) and `saveCustomerNotifySettingsAction` (customer redemption-notify toggle, not Pro-gated), both upserting on `vendor_id`
- `activity/`
- `card-link.tsx` — client `CardLinkActions`: copy-link (`@merqo/ui`'s `CopyButton`, keeping the sonner toasts) and print-QR buttons for the shop QR block
- `card.ts` — exports the shared `StampCard` type `{ id, phone, stamp_count }` used across actions and form components
Expand Down Expand Up @@ -44,8 +44,8 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo
- `referrals/`
- `points-offset-form.dom.test.tsx` — jsdom tests for `PointsOffsetForm`: input defaults to the card's full balance and Apply calls through, Apply disables once the entered amount exceeds the card's balance
- `points-offset-form.tsx` — client `PointsOffsetForm`: a small inline apply-points form (not an AlertDialog like `redeem-button.tsx`/`redeem-voucher/`'s confirm screen, since there's a number to pick here) — calls `applyPointsOffsetAction` and reports the updated card plus the dollar figure back to the caller for the vendor to apply manually at their own register
- `qkit-earn-settings.dom.test.tsx` — jsdom tests for `QkitEarnSettings`: the not-Pro note, the on-by-default switch and its every-qkit-order copy (never claiming the stamp is awarded automatically), the no-stamp-program note, and picking a program and toggling the switch
- `qkit-earn-settings.tsx` — client `QkitEarnSettings` form: switch + program picker that calls `saveQkitEarnConfigAction`, with a not-available note for non-Pro vendors. The stamp card shows on every qkit order by default (migration `0071`), and turning the switch off saves `enabled = false`. With no stamp program it shows a note to create one. Wrapped in `@merqo/ui`'s `ElevatedCard`
- `qkit-earn-settings.dom.test.tsx` — jsdom tests for `QkitEarnSettings`: the on-by-default switch and its every-qkit-order copy (never claiming the stamp is awarded automatically), the no-stamp-program note, and any vendor picking a program and toggling the switch
- `qkit-earn-settings.tsx` — client `QkitEarnSettings` form: switch + program picker that calls `saveQkitEarnConfigAction`. Free for every vendor. The stamp card shows on every qkit order by default (migration `0071`), and turning the switch off saves `enabled = false`. With no stamp program it shows a note to create one. Wrapped in `@merqo/ui`'s `ElevatedCard`
- `redeem-button.dom.test.tsx` — jsdom test asserting `RedeemButton`'s confirm dialog shows the exact stamp count and carryover wording
- `redeem-button.tsx` — client `RedeemButton`: ConfirmDialog-confirmed redeem control that calls `redeemAction` and reports the reset card back to the caller
- `redeem-voucher/`
Expand Down Expand Up @@ -86,7 +86,7 @@ Each page exports its own `metadata.title`, shown through the root `loopkit | %s

card-link test pins the clipboard-failure copy.

`qkit-earn-settings.tsx` stays Pro-gated: the qkit stamp card is on for every Pro vendor with a stamp program until they switch it off.
`qkit-earn-settings.tsx` is Free: the qkit stamp card is on for every vendor with a stamp program until they switch it off.

Dates and times on these pages render through `@merqo/ui`'s `formatDate`/`formatDateTime` (Singapore time).

Expand Down
2 changes: 2 additions & 0 deletions src/app/dashboard/profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ profile-form.errors test pins the "Could not save" and "do not match" copy.
This folder now imports its shared page and dialog components from `@merqo/ui` (v0.42.1) instead of local copies.

- `loading.tsx` uses `ListSkeleton` from `@merqo/ui`.

The qkit stamp setting is free for every vendor and defaults to the oldest active stamp program; the page no longer reads the plan.
12 changes: 5 additions & 7 deletions src/app/dashboard/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getVendorProfile } from "@/lib/vendor";
import { createServerClient } from "@/lib/supabase/server";
import { getOrCreateVendorProfile } from "@/lib/merqo-vendor-profile";
import { ProfileForm } from "@/app/dashboard/profile/profile-form";
import { listPrograms, isPro } from "@/lib/program";
import { listPrograms } from "@/lib/program";
import { QkitEarnSettings } from "@/app/dashboard/qkit-earn-settings";
import { CustomerNotifySettings } from "@/app/dashboard/customer-notify-settings";
import type { SocialLinks } from "@/lib/types";
Expand All @@ -18,10 +18,9 @@ export default async function ProfilePage() {
const profile = await getVendorProfile();

const supabase = await createServerClient();
const [programs, pro, qkitEarnConfigResult, notifySettingsResult] =
const [programs, qkitEarnConfigResult, notifySettingsResult] =
await Promise.all([
listPrograms(),
isPro(),
supabase
.from("qkit_earn_config")
.select("program_id, enabled")
Expand All @@ -37,9 +36,9 @@ export default async function ProfilePage() {
const qkitPrograms = programs.filter(
(prog) => prog.type === "stamp" && prog.active,
);
// Mirrors qkit_earn_resolve_program: with no saved row a Pro vendor's oldest
// active stamp program is already on.
const defaultProgram = pro ? qkitPrograms[0] : undefined;
// Mirrors qkit_earn_resolve_program: with no saved row the oldest active
// stamp program is already on.
const defaultProgram = qkitPrograms[0];
let qkitCurrent: { programId: string; enabled: boolean } | null = null;
if (qkitEarnConfig) {
qkitCurrent = {
Expand Down Expand Up @@ -99,7 +98,6 @@ export default async function ProfilePage() {
name: prog.name,
}))}
current={qkitCurrent}
isPro={pro}
/>
</div>
<div>
Expand Down
14 changes: 0 additions & 14 deletions src/app/dashboard/profile/profile-page.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ vi.mock("@/lib/program", () => ({
{ id: "p1", name: "Coffee Stamps", type: "stamp", active: true },
{ id: "p2", name: "Lucky Wheel", type: "wheel" },
]),
isPro: vi.fn(async () => true),
}));
const qkitMaybeSingle = vi.fn(
async (): Promise<{
Expand Down Expand Up @@ -49,14 +48,12 @@ vi.mock("@/app/dashboard/qkit-earn-settings", () => ({
QkitEarnSettings: (props: {
programs: { id: string; name: string }[];
current: { programId: string; enabled: boolean } | null;
isPro: boolean;
}) => (
<div data-testid="qkit-earn-settings">
{props.programs.map((p) => p.name).join(",")} / current:
{props.current
? `${props.current.programId}:${String(props.current.enabled)}`
: "none"}{" "}
/ pro:{String(props.isPro)}
</div>
),
}));
Expand Down Expand Up @@ -132,17 +129,6 @@ describe("ProfilePage", () => {
);
});

it("does not default the qkit stamp on for a non-Pro vendor", async () => {
const { isPro } = await import("@/lib/program");
vi.mocked(isPro).mockResolvedValueOnce(false);

render(await ProfilePage());

expect(screen.getByTestId("qkit-earn-settings")).toHaveTextContent(
"current:none / pro:false",
);
});

it("keeps the qkit stamp card off when the saved row says so", async () => {
qkitMaybeSingle.mockResolvedValueOnce({
data: { program_id: "p1", enabled: false },
Expand Down
21 changes: 3 additions & 18 deletions src/app/dashboard/qkit-earn-settings.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,29 @@ vi.mock("./settings-actions", () => ({
}));

describe("QkitEarnSettings", () => {
it("shows a not-available note instead of the form when not Pro", () => {
render(
<QkitEarnSettings
programs={[{ id: "p1", name: "Coffee Stamps" }]}
current={null}
isPro={false}
/>,
);
expect(screen.getByText(/not available yet/i)).toBeInTheDocument();
expect(screen.queryByRole("link")).not.toBeInTheDocument();
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
});

it("says a stamp card shows on every qkit order and is not automatic", () => {
render(
<QkitEarnSettings
programs={[{ id: "p1", name: "Coffee Stamps" }]}
current={{ programId: "p1", enabled: true }}
isPro
/>,
);
expect(screen.getByText(/shows on every qkit order/i)).toBeInTheDocument();
expect(screen.getByRole("switch")).toBeChecked();
expect(screen.queryByText(/automatically/i)).not.toBeInTheDocument();
});

it("asks a Pro vendor for a stamp program when there is none", () => {
render(<QkitEarnSettings programs={[]} current={null} isPro />);
it("asks a vendor for a stamp program when there is none", () => {
render(<QkitEarnSettings programs={[]} current={null} />);
expect(screen.getByText(/create a stamp program/i)).toBeInTheDocument();
expect(screen.queryByRole("switch")).not.toBeInTheDocument();
});

it("lets a Pro vendor pick a program and enable it", () => {
it("lets any vendor pick a program and enable it", () => {
render(
<QkitEarnSettings
programs={[{ id: "p1", name: "Coffee Stamps" }]}
current={null}
isPro
/>,
);
expect(screen.getByRole("combobox")).toBeInTheDocument();
Expand Down
14 changes: 0 additions & 14 deletions src/app/dashboard/qkit-earn-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,12 @@ type Program = { id: string; name: string };
export function QkitEarnSettings({
programs,
current,
isPro,
}: {
programs: Program[];
current: { programId: string; enabled: boolean } | null;
isPro: boolean;
}) {
const { pending, save } = useSaveSettings(saveQkitEarnConfigAction);

if (!isPro) {
return (
<ElevatedCard className="space-y-3 p-4 text-sm text-muted-foreground">
<p>
Let customers claim a stamp after completing a qkit order, they get a
link on their order page and enter their phone number to collect it.
</p>
<p className="font-medium">Qkit stamp earning is not available yet.</p>
</ElevatedCard>
);
}

if (programs.length === 0) {
return (
<ElevatedCard className="p-4 text-sm text-muted-foreground">
Expand Down
11 changes: 1 addition & 10 deletions src/app/dashboard/settings-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { revalidatePath } from "next/cache";
import { requireVendor } from "@/features/auth";
import { isPro } from "@/lib/program";
import { createServerClient } from "@/lib/supabase/server";
import type { ActionResult } from "@merqo/ui/kit-api";

Expand All @@ -12,19 +11,11 @@ export type QkitEarnConfigResult = ActionResult<{
}>;

// Vendor-owned setting: which stamp program (if any) earns a stamp when a
// customer completes a qkit order. Pro-gated, same tier check as the
// program-count limit (isPro from @/lib/program).
// customer completes a qkit order. Free for every vendor.
export async function saveQkitEarnConfigAction(
formData: FormData,
): Promise<QkitEarnConfigResult> {
const { user } = await requireVendor();
const pro = await isPro();
if (!pro) {
return {
success: false,
error: "Qkit stamp earning is not available yet.",
};
}

const enabled = formData.get("enabled") === "on";
const programId = String(formData.get("program_id") ?? "");
Expand Down
1 change: 0 additions & 1 deletion src/app/dashboard/settings-lifecycle.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe.each(["notify", "earn"] as const)(
<QkitEarnSettings
programs={[{ id: "p1", name: "Coffee" }]}
current={{ programId: "p1", enabled: true }}
isPro
/>,
);
}
Expand Down
26 changes: 26 additions & 0 deletions supabase/migrations/0072_qkit_earn_free.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- With no config row, the oldest active stamp program is offered on any plan.
create or replace function loopkit.qkit_earn_resolve_program(p_vendor uuid)
returns uuid
language sql
stable
security definer
set search_path = ''
as $$
select case
when exists (select 1 from loopkit.qkit_earn_config c where c.vendor_id = p_vendor) then (
select p.id
from loopkit.qkit_earn_config c
join loopkit.programs p on p.id = c.program_id and p.vendor_id = c.vendor_id
where c.vendor_id = p_vendor and c.enabled and p.active and p.type = 'stamp'
)
else (
select p.id
from loopkit.programs p
where p.vendor_id = p_vendor and p.active and p.type = 'stamp'
order by p.created_at, p.id
limit 1
)
end;
$$;

revoke all on function loopkit.qkit_earn_resolve_program(uuid) from public, anon, authenticated, service_role;
3 changes: 2 additions & 1 deletion supabase/migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ exception.
- `0068_drop_vendor_pro.sql`: drops `loopkit.vendor_pro`. Apply `0066` to `0068` together.
- `0069_drop_pricing.sql`: drops `loopkit.pricing`; merqo owns plans and pricing.
- `0070_drop_upgrade_requests.sql`: drops `loopkit.upgrade_requests`; the upgrade inbox is gone.
- `0071_qkit_earn_default_stamp.sql`: `loopkit.qkit_earn_resolve_program(uuid)` picks the program a qkit order stamps: the `qkit_earn_config` program while enabled, active and a stamp program, or with no row, for a Pro vendor (`loopkit.is_pro`), the vendor's oldest active stamp program. `qkit_earn_offer`, `qkit_earn_lookup` and `qkit_earn_commit` use it, so the stamp shows on every qkit order by default and `enabled = false` still turns it off. The offer adds `reward_label`, `stamps_goal` and `stamps_per_order` (always 1) and returns only `{enabled: false}` for vendors with no stamp program.
- `0071_qkit_earn_default_stamp.sql`: `loopkit.qkit_earn_resolve_program(uuid)` picks the program a qkit order stamps: the `qkit_earn_config` program while enabled, active and a stamp program, or with no row, the vendor's oldest active stamp program. `qkit_earn_offer`, `qkit_earn_lookup` and `qkit_earn_commit` use it, so the stamp shows on every qkit order by default and `enabled = false` still turns it off. The offer adds `reward_label`, `stamps_goal` and `stamps_per_order` (always 1) and returns only `{enabled: false}` for vendors with no stamp program.
- `0072_qkit_earn_free.sql`: qkit-order stamps are Free. `qkit_earn_resolve_program` drops the `loopkit.is_pro` check from 0071, so a vendor with no `qkit_earn_config` row defaults to its oldest active stamp program on any plan.

Prepared audit migrations require database validation and rollout review before deployment.
2 changes: 1 addition & 1 deletion supabase/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fixtures have not yet been executed in this checkout.
- `customer-capability.test.sql` and `earn-customer-capability.test.sql` exercise
customer and earn proofs; `retired-rpc-permissions.test.sql` checks retired RPC
grants.
- `qkit-earn-offer.test.sql` checks that only the service role can call `qkit_earn_offer`, that it answers enabled, disabled and unknown vendors with the reward, goal and stamps-per-order keys, that a Pro vendor with no config row defaults to its oldest active stamp program while a non-Pro vendor offers nothing and cannot claim, that an explicit off stays off, that a claim with no config row works once per order, and that it exposes no customer data.
- `qkit-earn-offer.test.sql` checks that only the service role can call `qkit_earn_offer`, that it answers enabled, disabled and unknown vendors with the reward, goal and stamps-per-order keys, that a vendor with no config row, Pro or free, defaults to its oldest active stamp program and can claim, that an explicit off stays off, that a claim with no config row works once per order, and that it exposes no customer data.
- `reward-rpc.test.sql`, `plant-redemption.test.sql` and
`plant-redemption-parity.test.sql` exercise reward state and redemption contracts.
- `anon-abuse-limits.test.sql` covers the `0064` limiter (grants, RLS, window counting) and the 5-per-day referral credit cap, including retry of a reserved guest, the cap resetting, a past window not carrying its count and out-of-range parameters being rejected.
Expand Down
19 changes: 9 additions & 10 deletions supabase/tests/qkit-earn-offer.test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ select is(
select is(
loopkit.qkit_earn_offer('00620000-0000-0000-0000-000000000003'),
'{"enabled": true, "program_name": "Oldest Club", "reward_label": "Free kopi", "stamps_goal": 6, "stamps_per_order": 1}'::jsonb,
'a Pro vendor with no config row defaults on with the oldest active stamp program'
'a vendor with no config row defaults on with the oldest active stamp program'
);
select is(
loopkit.qkit_earn_offer('00620000-0000-0000-0000-000000000005'),
'{"enabled": false}'::jsonb,
'a non-Pro vendor with no config row offers nothing'
'{"enabled": true, "program_name": "Free Club", "reward_label": "Snack", "stamps_goal": 10, "stamps_per_order": 1}'::jsonb,
'a free vendor with no config row defaults on with its stamp program'
);
select is(
loopkit.qkit_earn_offer('00620000-0000-0000-0000-000000000004'),
Expand Down Expand Up @@ -104,11 +104,10 @@ select throws_ok(
'not configured',
'a vendor who turned earning off cannot be claimed against'
);
select throws_ok(
$$select loopkit.customer_qkit_earn_claim('00620000-0000-0000-0000-000000000103', '+6591110064', 'Guest', null)$$,
'P0001',
'not configured',
'a non-Pro vendor with no config row cannot be claimed against'
select is(
(loopkit.customer_qkit_earn_claim('00620000-0000-0000-0000-000000000103', '+6591110064', 'Guest', null)->>'stamp_count')::int,
1,
'a free vendor with no config row can be claimed against'
);
reset role;
select is(
Expand All @@ -118,8 +117,8 @@ select is(
);
select is(
(select count(*) from loopkit.qkit_earn_events),
1::bigint,
'reading offers writes nothing and the order is claimed once'
2::bigint,
'reading offers writes nothing and each order is claimed once'
);

select * from finish();
Expand Down
Loading
Loading