@mohasinac/appkit 4.60.0 → 4.61.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.
Files changed (122) hide show
  1. package/dist/.build-stamp.json +3 -3
  2. package/dist/_internal/server/features/auctions/actions.d.ts +1 -1
  3. package/dist/_internal/server/features/auctions/actions.js +12 -1
  4. package/dist/_internal/server/features/blog/actions.d.ts +1 -1
  5. package/dist/_internal/server/features/blog/actions.js +12 -1
  6. package/dist/_internal/server/features/brands/actions.d.ts +1 -1
  7. package/dist/_internal/server/features/brands/actions.js +12 -1
  8. package/dist/_internal/server/features/cart/actions.d.ts +1 -1
  9. package/dist/_internal/server/features/cart/actions.js +12 -1
  10. package/dist/_internal/server/features/checkout/actions.js +0 -1
  11. package/dist/_internal/server/features/events/actions.d.ts +1 -1
  12. package/dist/_internal/server/features/events/actions.js +12 -1
  13. package/dist/_internal/server/features/gateway-events/redact.js +14 -2
  14. package/dist/_internal/server/features/history/actions.d.ts +1 -1
  15. package/dist/_internal/server/features/history/actions.js +12 -1
  16. package/dist/_internal/server/features/lottery/actions.d.ts +1 -1
  17. package/dist/_internal/server/features/lottery/actions.js +12 -1
  18. package/dist/_internal/server/features/orders/actions.d.ts +1 -1
  19. package/dist/_internal/server/features/orders/actions.js +12 -1
  20. package/dist/_internal/server/features/orders/adapters.d.ts +20 -2
  21. package/dist/_internal/server/features/orders/adapters.js +18 -0
  22. package/dist/_internal/server/features/orders/cancellation-refund.js +0 -1
  23. package/dist/_internal/server/features/orders/service.js +31 -1
  24. package/dist/_internal/server/features/payouts/actions.d.ts +1 -1
  25. package/dist/_internal/server/features/payouts/actions.js +12 -1
  26. package/dist/_internal/server/features/points/award.js +9 -1
  27. package/dist/_internal/server/features/pre-orders/actions.d.ts +1 -1
  28. package/dist/_internal/server/features/pre-orders/actions.js +12 -1
  29. package/dist/_internal/server/features/prize-draws/actions.d.ts +1 -1
  30. package/dist/_internal/server/features/prize-draws/actions.js +12 -1
  31. package/dist/_internal/server/features/products/actions.d.ts +1 -1
  32. package/dist/_internal/server/features/products/actions.js +12 -1
  33. package/dist/_internal/server/features/promotions/actions.d.ts +1 -1
  34. package/dist/_internal/server/features/promotions/actions.js +12 -1
  35. package/dist/_internal/server/features/protection-claims/actions.d.ts +2 -2
  36. package/dist/_internal/server/features/protection-claims/actions.js +21 -12
  37. package/dist/_internal/server/features/raffle/actions.d.ts +1 -1
  38. package/dist/_internal/server/features/raffle/actions.js +12 -1
  39. package/dist/_internal/server/features/refunds/actions.d.ts +1 -3
  40. package/dist/_internal/server/features/refunds/actions.js +14 -2
  41. package/dist/_internal/server/features/reviews/actions.d.ts +1 -1
  42. package/dist/_internal/server/features/reviews/actions.js +12 -1
  43. package/dist/_internal/server/features/wishlist/actions.d.ts +1 -1
  44. package/dist/_internal/server/features/wishlist/actions.js +12 -1
  45. package/dist/_internal/server/jobs/core/obligationSweep.js +0 -1
  46. package/dist/_internal/server/jobs/core/paymentReconcile.js +84 -57
  47. package/dist/_internal/server/jobs/core/testDataCleanup.d.ts +1 -1
  48. package/dist/_internal/server/jobs/core/testDataCleanup.js +22 -1
  49. package/dist/_internal/server/jobs/handlers/onShipmentAllocationSync.js +16 -4
  50. package/dist/_internal/shared/features/promotions/schema.d.ts +66 -0
  51. package/dist/_internal/shared/features/promotions/schema.js +7 -0
  52. package/dist/_internal/shared/obligations/deadlines.js +11 -1
  53. package/dist/_internal/shared/tester/window.d.ts +25 -0
  54. package/dist/_internal/shared/tester/window.js +66 -0
  55. package/dist/client.d.ts +1 -0
  56. package/dist/client.js +3 -0
  57. package/dist/core/unit-of-work.js +15 -1
  58. package/dist/errors/firestore-codes.d.ts +37 -0
  59. package/dist/errors/firestore-codes.js +52 -0
  60. package/dist/errors/index.d.ts +0 -1
  61. package/dist/errors/index.js +12 -2
  62. package/dist/features/admin/components/AdminCouponEditorView.js +8 -0
  63. package/dist/features/admin/components/AdminGatewayEventsView.js +2 -2
  64. package/dist/features/admin/components/DataListingView.js +2 -0
  65. package/dist/features/admin/components/analytics/AdminStatCard.js +4 -1
  66. package/dist/features/admin/repository/site-settings.repository.d.ts +2 -1
  67. package/dist/features/admin/repository/site-settings.repository.js +7 -0
  68. package/dist/features/auctions/components/MarketplaceAuctionCard.js +1 -1
  69. package/dist/features/catalogue/actions/approve-catalogue-listing.d.ts +1 -1
  70. package/dist/features/catalogue/actions/approve-catalogue-listing.js +12 -1
  71. package/dist/features/catalogue/actions/list-from-catalogue.d.ts +1 -1
  72. package/dist/features/catalogue/actions/list-from-catalogue.js +12 -1
  73. package/dist/features/catalogue/actions/submit-for-approval.d.ts +1 -1
  74. package/dist/features/catalogue/actions/submit-for-approval.js +12 -1
  75. package/dist/features/categories/repository/price-observation.repository.d.ts +19 -0
  76. package/dist/features/categories/repository/price-observation.repository.js +21 -2
  77. package/dist/features/events/actions/event-actions.js +4 -1
  78. package/dist/features/events/components/AdminEventEditorView.js +72 -45
  79. package/dist/features/events/components/EventsListPageView.js +2 -1
  80. package/dist/features/events/schemas/firestore.d.ts +17 -0
  81. package/dist/features/events/schemas/firestore.js +1 -0
  82. package/dist/features/events/utils/sort-pinned.d.ts +33 -0
  83. package/dist/features/events/utils/sort-pinned.js +46 -0
  84. package/dist/features/gateway-events/repository/gateway-events.repository.js +3 -40
  85. package/dist/features/gateway-events/schemas/index.d.ts +2 -2
  86. package/dist/features/inventory/components/AdminStorageBoxesView.js +55 -39
  87. package/dist/features/inventory/components/ReceiveStationView.js +61 -17
  88. package/dist/features/inventory/repository/storage-boxes.repository.d.ts +3 -1
  89. package/dist/features/inventory/repository/storage-boxes.repository.js +36 -3
  90. package/dist/features/obligations/repository/obligations.repository.js +10 -1
  91. package/dist/features/orders/schemas/firestore.d.ts +19 -0
  92. package/dist/features/orders/schemas/firestore.js +19 -0
  93. package/dist/features/payment-cases/repository/payment-cases.repository.d.ts +1 -0
  94. package/dist/features/payment-cases/repository/payment-cases.repository.js +3 -14
  95. package/dist/features/pre-orders/components/MarketplacePreorderCard.js +1 -1
  96. package/dist/features/products/components/MarketplaceBundleCard.js +1 -1
  97. package/dist/features/products/components/MarketplacePrizeDrawCard.js +1 -1
  98. package/dist/features/products/components/ProductForm.js +2 -2
  99. package/dist/features/products/components/ProductGrid.js +1 -1
  100. package/dist/features/promotions/repository/claimed-coupons.repository.js +31 -1
  101. package/dist/features/promotions/schemas/firestore.d.ts +22 -0
  102. package/dist/features/promotions/schemas/firestore.js +22 -0
  103. package/dist/features/promotions/schemas/index.d.ts +479 -6
  104. package/dist/features/promotions/schemas/index.js +153 -0
  105. package/dist/features/protection-claims/repository/protection-claims.repository.js +22 -15
  106. package/dist/features/seller/schemas/coupon-form.d.ts +5 -0
  107. package/dist/features/seller/schemas/coupon-form.js +18 -0
  108. package/dist/features/shell/SectionForm.js +31 -9
  109. package/dist/features/sticker-trace/server.d.ts +2 -0
  110. package/dist/http/api-handler.js +4 -1
  111. package/dist/index.d.ts +3 -3
  112. package/dist/index.js +3 -3
  113. package/dist/next/routing/route-map.d.ts +0 -2
  114. package/dist/next/routing/route-map.js +10 -1
  115. package/dist/schemas/registry.d.ts +11 -6
  116. package/dist/server.js +7 -0
  117. package/dist/styles.css +51 -0
  118. package/dist/ui/components/PaginatedSelect.js +0 -0
  119. package/package.json +1 -1
  120. package/scripts/seed-cli.mjs +1822 -1812
  121. package/dist/features/tester/utils/phases.d.ts +0 -48
  122. package/dist/features/tester/utils/phases.js +0 -139
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "stampVersion": 1,
3
- "version": "4.60.0",
4
- "head": "75dbddb0be908315382e2df74f6f9540c469a77d",
3
+ "version": "4.61.0",
4
+ "head": "7fd2f6fe0a6d6314241671329d51d11d008fca95",
5
5
  "branch": "main",
6
6
  "dirty": false,
7
- "builtAt": "2026-10-21T23:51:33.351Z"
7
+ "builtAt": "2026-10-22T08:29:07.009Z"
8
8
  }
@@ -1,2 +1,2 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function placeBidAction(input: unknown): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { safeRead } from "../../../../errors/safe-read.js";
4
15
  import { bidRepository, productRepository, userRepository, siteSettingsRepository } from "../../../../repositories/index.js";
5
16
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function createBlogPostAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  export declare function updateBlogPostAction(postId: string, input: unknown): Promise<ActionResult<unknown>>;
4
4
  export declare function deleteBlogPostAction(postId: string): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { blogRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { blogPostInputSchema, blogPostUpdateSchema } from "../../../shared/features/blog/schema.js";
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function createBrandAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  export declare function updateBrandAction(brandId: string, input: unknown): Promise<ActionResult<unknown>>;
4
4
  export declare function deleteBrandAction(brandId: string): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { categoriesRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { brandInputSchema, brandUpdateSchema } from "../../../shared/features/brands/schema.js";
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function addToCartAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  export declare function removeFromCartAction(input: unknown): Promise<ActionResult<unknown>>;
4
4
  export declare function clearCartAction(): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { cartRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { addToCartSchema, removeFromCartSchema, mergeGuestCartSchema } from "../../../shared/features/cart/schema.js";
@@ -1833,7 +1833,6 @@ async function refundDroppedItemsForPhonePeCheckout(input) {
1833
1833
  : droppedValue;
1834
1834
  const refundResult = await processRefundAction({
1835
1835
  orderId: primaryOrderId,
1836
- type: "partial",
1837
1836
  amount: refundAmount,
1838
1837
  /*
1839
1838
  * A SYSTEM refund, not a buyer claim: items the buyer paid for turned
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function createEventAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  export declare function updateEventAction(eventId: string, input: unknown): Promise<ActionResult<unknown>>;
4
4
  export declare function registerForEventAction(input: unknown): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { eventRepository, eventEntryRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { eventInputSchema, eventUpdateSchema, registerForEventSchema } from "../../../shared/features/events/schema.js";
@@ -37,6 +37,7 @@
37
37
  * `card` key without anyone having written that path down.
38
38
  */
39
39
  import { GATEWAY_EVENT_PAYLOAD_MAX_BYTES } from "../../../../features/gateway-events/schemas/firestore.js";
40
+ import { normalizeError } from "../../../../errors/normalize.js";
40
41
  /**
41
42
  * Keys dropped wherever they appear, at any depth.
42
43
  *
@@ -130,13 +131,24 @@ export function redactGatewayPayload(body) {
130
131
  try {
131
132
  serialisedLength = JSON.stringify(redacted)?.length ?? 0;
132
133
  }
133
- catch {
134
+ catch (err) {
134
135
  /*
135
136
  * A circular structure cannot come from `JSON.parse`, which is the only
136
137
  * producer here — but this function is exported and a future caller could
137
138
  * hand it something else. Failing to a marker keeps the row writable.
139
+ *
140
+ * 🛑 The reason is CARRIED, not discarded. This was a bare `catch {}`, so
141
+ * the one case the comment above exists to anticipate — a future caller
142
+ * handing it something `JSON.stringify` cannot take — produced a row
143
+ * saying only `redactionFailed: true`, with nothing anywhere to say why.
144
+ * The row is a debugging record; a marker that cannot explain itself is
145
+ * the silent-degrade shape this codebase keeps paying for.
138
146
  */
139
- return { payload: { redactionFailed: true }, truncated: true };
147
+ const n = normalizeError(err);
148
+ return {
149
+ payload: { redactionFailed: true, reason: n.message },
150
+ truncated: true,
151
+ };
140
152
  }
141
153
  if (serialisedLength > GATEWAY_EVENT_PAYLOAD_MAX_BYTES) {
142
154
  return {
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  import { type UserHistoryItem, type HistoryProductType } from "../../../../repositories";
3
3
  export declare function trackProductViewAction(productId: string, productType: HistoryProductType, productSnapshot?: UserHistoryItem["productSnapshot"]): Promise<ActionResult<unknown>>;
4
4
  export declare function mergeGuestHistoryAction(guestItems: Array<{
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
4
15
  import { historyRepository, } from "../../../../repositories/index.js";
5
16
  export async function trackProductViewAction(productId, productType, productSnapshot) {
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  import type { LotteryConfig } from "../../../../features/lottery/types";
3
3
  import type { LotteryEntryDocument } from "../../../../features/lottery/schemas/firestore";
4
4
  /**
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { getAdminDb } from "../../../../providers/db-firebase/index.js";
4
15
  import { eventRepository, productRepository, orderRepository } from "../../../../repositories/index.js";
5
16
  import { serverLogger } from "../../../../monitoring/index.js";
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function createOrderAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  /**
4
4
  * Cancel an order, and give the money back if any was taken (D14).
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { adminNotificationsRepository, orderRepository, storeRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { createOrderSchema, updateOrderStatusSchema, cancelOrderSchema, returnRequestSchema, } from "../../../shared/features/orders/schema.js";
@@ -1,3 +1,21 @@
1
1
  import type { Order } from "../../../../features/orders/types";
2
- import type { OrderDocument } from "../../../../features/orders/schemas/firestore";
3
- export declare function orderDocumentToOrder(doc: OrderDocument): Order;
2
+ import type { OrderPlain } from "../../../../features/orders/schemas/firestore";
3
+ /**
4
+ * 🛑 `OrderPlain`, not `OrderDocument` — this builds the BUYER-FACING shape.
5
+ *
6
+ * `orderRepository.findById` is ciphertext-by-default, so a signature taking
7
+ * the raw document would invite a caller to hand over `enc:v1:` strings and
8
+ * have them copied straight into an API response. The one caller
9
+ * (`GET /api/user/orders/[id]`) already holds a revealed order; this makes the
10
+ * signature say so.
11
+ *
12
+ * It does not currently read any of `ORDER_PII_FIELDS` (`userName`,
13
+ * `userEmail`, `sellerEmail`), so nothing is leaking today — the point is that
14
+ * adding one of them later is correct by default rather than a new leak.
15
+ *
16
+ * Accepted residue, stated rather than hidden: `Encrypted<string>` is
17
+ * assignable to `string`, so a raw document still satisfies this structurally.
18
+ * The brand forces the choice at the REPOSITORY boundary, which is where it
19
+ * can actually be enforced; this parameter documents the expectation.
20
+ */
21
+ export declare function orderDocumentToOrder(doc: OrderPlain): Order;
@@ -37,6 +37,24 @@ function toIsoOrUndefined(value) {
37
37
  }
38
38
  return undefined;
39
39
  }
40
+ /**
41
+ * 🛑 `OrderPlain`, not `OrderDocument` — this builds the BUYER-FACING shape.
42
+ *
43
+ * `orderRepository.findById` is ciphertext-by-default, so a signature taking
44
+ * the raw document would invite a caller to hand over `enc:v1:` strings and
45
+ * have them copied straight into an API response. The one caller
46
+ * (`GET /api/user/orders/[id]`) already holds a revealed order; this makes the
47
+ * signature say so.
48
+ *
49
+ * It does not currently read any of `ORDER_PII_FIELDS` (`userName`,
50
+ * `userEmail`, `sellerEmail`), so nothing is leaking today — the point is that
51
+ * adding one of them later is correct by default rather than a new leak.
52
+ *
53
+ * Accepted residue, stated rather than hidden: `Encrypted<string>` is
54
+ * assignable to `string`, so a raw document still satisfies this structurally.
55
+ * The brand forces the choice at the REPOSITORY boundary, which is where it
56
+ * can actually be enforced; this parameter documents the expectation.
57
+ */
40
58
  export function orderDocumentToOrder(doc) {
41
59
  const items = doc.items?.length
42
60
  ? doc.items.map((item) => ({
@@ -391,7 +391,6 @@ export async function cancelOrderWithRefund(order, opts) {
391
391
  */
392
392
  const result = await processRefundAction({
393
393
  orderId: order.id,
394
- type: "full",
395
394
  amount,
396
395
  /*
397
396
  * `changed_mind` is the honest default: a cancellation before dispatch is a
@@ -1,6 +1,30 @@
1
1
  import { orderRepository } from "../../../../repositories/index.js";
2
2
  import { OrderNotFoundError, OrderCancelError, OrderOwnershipError, OrderReturnWindowError, } from "../../../shared/features/orders/errors.js";
3
3
  import { ORDER_CANCELLABLE_STATUSES, ORDER_RETURN_WINDOW_MS, } from "../../../shared/features/orders/config.js";
4
+ /**
5
+ * The three shapes `updatedAt` really arrives in, resolved to a `Date`.
6
+ *
7
+ * A Firestore `Timestamp` is duck-typed on `toDate` rather than imported, so
8
+ * this file stays free of a firebase-admin import — the same trade
9
+ * `orders/adapters.ts` makes and for the same reason.
10
+ *
11
+ * Falls back to NOW rather than to an invalid date: the caller measures a
12
+ * return window against it, and `new Date(undefined)` is `NaN`, which makes
13
+ * every comparison false and would silently hold the window open forever.
14
+ */
15
+ function toDateOrNow(value) {
16
+ if (value instanceof Date)
17
+ return Number.isNaN(value.getTime()) ? new Date() : value;
18
+ if (typeof value === "object" && value !== null && typeof value.toDate === "function") {
19
+ const d = value.toDate();
20
+ return d instanceof Date && !Number.isNaN(d.getTime()) ? d : new Date();
21
+ }
22
+ if (typeof value === "string") {
23
+ const d = new Date(value);
24
+ return Number.isNaN(d.getTime()) ? new Date() : d;
25
+ }
26
+ return new Date();
27
+ }
4
28
  export async function assertOrderOwnership(orderId, userId) {
5
29
  const order = await orderRepository.findById(orderId);
6
30
  if (!order)
@@ -97,7 +121,13 @@ export async function assertReturnWindowOpen(orderId, userId) {
97
121
  */
98
122
  const deliveredAt = order.deliveryDate instanceof Date
99
123
  ? order.deliveryDate
100
- : new Date(order.updatedAt ?? Date.now());
124
+ /*
125
+ * Typed, and the `as never` is gone with it. That cast existed only to
126
+ * feed an `unknown` into `new Date()` — it suppressed the one check that
127
+ * would have caught a wrong shape. A Firestore Timestamp is duck-typed on
128
+ * `toDate` rather than imported, the same way `toIsoOrUndefined` does it.
129
+ */
130
+ : toDateOrNow(order.updatedAt);
101
131
  if (Date.now() - deliveredAt.getTime() > ORDER_RETURN_WINDOW_MS)
102
132
  throw new OrderReturnWindowError();
103
133
  return order;
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export type ApplyRefundDeductionInput = {
3
3
  storeId: string;
4
4
  orderId: string;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  /**
4
15
  * applyRefundDeductionAction — deduct a refund from a seller's pending payout.
5
16
  *
@@ -91,7 +91,15 @@ export async function awardPurchasePoints(order) {
91
91
  return { awarded: 0, skipped: "no-buyer" };
92
92
  }
93
93
  const goods = orderTaxableValue(order);
94
- const amount = roundPoints((goods * POINTS_EARN_PERCENT) / 100);
94
+ /*
95
+ * `goods * (PERCENT / 100)`, not `(goods * PERCENT) / 100` — the same value,
96
+ * written the way every fee in `fees/calculator.ts` is
97
+ * (`subtotal * (commissions.platformFeePercent / 100)`). The division
98
+ * belongs to the PERCENT, and grouping it that way is what distinguishes a
99
+ * percentage from the subunit-conversion `/100` that `audit-money-units`
100
+ * exists to catch — which read the old grouping as exactly that.
101
+ */
102
+ const amount = roundPoints(goods * (POINTS_EARN_PERCENT / 100));
95
103
  if (amount <= 0) {
96
104
  /*
97
105
  * A fully-cancelled or zero-value order. Marked as awarded anyway below so
@@ -1,2 +1,2 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function reservePreOrderAction(input: unknown): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { productRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { reservePreOrderSchema } from "../../../shared/features/pre-orders/schema.js";
@@ -1,2 +1,2 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function enterPrizeDrawAction(input: unknown): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { productRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { assertPrizeDrawOpen } from "./service.js";
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function createProductAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  export declare function createAuctionAction(input: unknown): Promise<ActionResult<unknown>>;
4
4
  export declare function createPreOrderAction(input: unknown): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { productRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { isAdminUser } from "../../../../features/auth/role-predicates.js";
@@ -1,4 +1,4 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
2
2
  export declare function applyCouponAction(input: unknown): Promise<ActionResult<unknown>>;
3
3
  export declare function createCouponAction(input: unknown): Promise<ActionResult<unknown>>;
4
4
  export declare function updateCouponAction(couponId: string, input: unknown): Promise<ActionResult<unknown>>;
@@ -1,5 +1,16 @@
1
1
  "use server";
2
- import { wrapAction } from "@mohasinac/appkit/server";
2
+ /*
3
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
4
+ *
5
+ * appkit importing its own public server barrel is a self-reference that drags
6
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
7
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
8
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
9
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
10
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
11
+ * .wasm files, naming none of the responsible files. Root Cause #18.
12
+ */
13
+ import { wrapAction } from "../../../shared/types/action-result.js";
3
14
  import { couponsRepository } from "../../../../repositories/index.js";
4
15
  import { requireRoleUser } from "../../../../providers/auth-firebase/helpers.js";
5
16
  import { applyCouponSchema, createCouponSchema, updateCouponSchema, } from "../../../shared/features/promotions/schema.js";
@@ -66,7 +66,7 @@ export declare function adjudicateProtectionClaimAction(claimId: string, finding
66
66
  /** A buyer's own claims, for their order detail page. */
67
67
  export declare function getMyProtectionClaimsAction(): Promise<ActionResult<ProtectionClaimDocument[]>>;
68
68
  /** Whether this order can be claimed against right now, for rendering the CTA. */
69
- export declare function canClaimProtection(order: Parameters<typeof deadlinesFor>[0], kind: "shipping" | "sale"): Promise<{
69
+ export declare function canClaimProtection(order: Parameters<typeof deadlinesFor>[0], kind: "shipping" | "sale"): Promise<ActionResult<{
70
70
  can: boolean;
71
71
  reason?: string;
72
- }>;
72
+ }>>;
@@ -213,16 +213,25 @@ export async function getMyProtectionClaimsAction() {
213
213
  }
214
214
  /** Whether this order can be claimed against right now, for rendering the CTA. */
215
215
  export async function canClaimProtection(order, kind) {
216
- const feePaid = kind === "shipping" ? order.shipmentProtectionFee : order.saleProtectionFee;
217
- if (!feePaid || feePaid <= 0)
218
- return { can: false, reason: "not-covered" };
219
- const existing = await protectionClaimsRepository().findById(createProtectionClaimId(order.id, kind));
220
- if (existing)
221
- return { can: false, reason: "already-claimed" };
222
- const obligationKind = kind === "shipping" ? "claim-shipping" : "claim-sale";
223
- const window = deadlinesFor(order).find((d) => d.kind === obligationKind);
224
- if (order.deliveryDate && window && window.dueAt.getTime() <= Date.now()) {
225
- return { can: false, reason: "window-closed" };
226
- }
227
- return { can: true };
216
+ /*
217
+ * 🛑 Wrapped, because this file is `"use server"` — which makes EVERY export
218
+ * in it a client-callable RPC endpoint, read-only predicate included. So it
219
+ * owes the same uniform envelope as its sibling mutations: a caller cannot
220
+ * tell a thrown repository error from a `{can:false}` verdict otherwise, and
221
+ * "the claim window is closed" and "the lookup failed" are opposite answers.
222
+ */
223
+ return wrapAction(async () => {
224
+ const feePaid = kind === "shipping" ? order.shipmentProtectionFee : order.saleProtectionFee;
225
+ if (!feePaid || feePaid <= 0)
226
+ return { can: false, reason: "not-covered" };
227
+ const existing = await protectionClaimsRepository().findById(createProtectionClaimId(order.id, kind));
228
+ if (existing)
229
+ return { can: false, reason: "already-claimed" };
230
+ const obligationKind = kind === "shipping" ? "claim-shipping" : "claim-sale";
231
+ const window = deadlinesFor(order).find((d) => d.kind === obligationKind);
232
+ if (order.deliveryDate && window && window.dueAt.getTime() <= Date.now()) {
233
+ return { can: false, reason: "window-closed" };
234
+ }
235
+ return { can: true };
236
+ });
228
237
  }
@@ -5,7 +5,7 @@
5
5
  * handlers also work in a Vercel lambda (10s cap honoured by raffle pool
6
6
  * size).
7
7
  */
8
- import { type ActionResult } from "@mohasinac/appkit/server";
8
+ import { type ActionResult } from "../../../shared/types/action-result";
9
9
  import { type TriggerEventRaffleInput, type TriggerEventRaffleResult } from "../../jobs/core/triggerEventRaffle";
10
10
  import { type AssignSpinPrizeInput, type AssignSpinPrizeResult } from "../../jobs/core/assignSpinPrize";
11
11
  export declare function triggerEventRaffleAction(input: TriggerEventRaffleInput): Promise<ActionResult<TriggerEventRaffleResult>>;
@@ -6,7 +6,18 @@
6
6
  * handlers also work in a Vercel lambda (10s cap honoured by raffle pool
7
7
  * size).
8
8
  */
9
- import { wrapAction } from "@mohasinac/appkit/server";
9
+ /*
10
+ * 🛑 From the DEFINING module, never "@mohasinac/appkit/server".
11
+ *
12
+ * appkit importing its own public server barrel is a self-reference that drags
13
+ * the whole server surface in behind it — `dist/server.js` reaches next/og,
14
+ * next/navigation, next/headers and driver.js. Twenty `actions.ts` files did
15
+ * this for two symbols, and because `obligationSweep` reaches one of them, the
16
+ * Firebase Functions tsup bundle (noExternal: appkit) had to resolve Next:
17
+ * it failed on two `react-server-dom-webpack/*` requires and two @vercel/og
18
+ * .wasm files, naming none of the responsible files. Root Cause #18.
19
+ */
20
+ import { wrapAction } from "../../../shared/types/action-result.js";
10
21
  import { getAdminDb } from "../../../../providers/db-firebase/admin.js";
11
22
  import { runTriggerEventRaffle, } from "../../jobs/core/triggerEventRaffle.js";
12
23
  import { runAssignSpinPrize, } from "../../jobs/core/assignSpinPrize.js";
@@ -1,9 +1,7 @@
1
- import { type ActionResult } from "@mohasinac/appkit/server";
2
- import type { RefundType } from "../../../../features/orders/schemas";
1
+ import { type ActionResult } from "../../../shared/types/action-result";
3
2
  import { type ReturnReason } from "../../../shared/features/orders/return-reasons";
4
3
  export type ProcessRefundInput = {
5
4
  orderId: string;
6
- type: RefundType;
7
5
  /** Decimal rupees. Must be > 0 and ≤ remaining refundable amount on the order. */
8
6
  amount: number;
9
7
  /**