@revenexx/cover 0.21.1 → 0.21.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -47,19 +47,39 @@ function clientAdding(client: SdkClient, extra: Record<string, unknown>): SdkCli
47
47
  });
48
48
  }
49
49
 
50
+ /**
51
+ * Keys of a placement the typed SDK does not map and silently drops, sent on
52
+ * the wire as they are given. `discounts` is what the promotions app decided
53
+ * and reserved for this cart: without it the order is stored at the full
54
+ * price while the redemption is committed against it.
55
+ */
56
+ const UNMAPPED_KEYS = ["discounts"] as const;
57
+
58
+ function unmappedOf(submission: unknown): Record<string, unknown> {
59
+ const body = (submission ?? {}) as Record<string, unknown>;
60
+ return Object.fromEntries(UNMAPPED_KEYS
61
+ .filter(key => Array.isArray(body[key]) ? (body[key] as unknown[]).length > 0 : body[key] !== undefined)
62
+ .map(key => [key, body[key]]));
63
+ }
64
+
50
65
  export async function placeOrderWithAttribution<T>(submission: unknown, attribution: Attribution | null): Promise<T> {
51
66
  const sdk = useRevenexxSdk();
67
+ const unmapped = unmappedOf(submission);
68
+ const place = async (extra: Record<string, unknown>): Promise<T> => (Object.keys(extra).length
69
+ ? await new Orders(clientAdding(sdk.client, extra) as never).ordersPlace(submission as never)
70
+ : await sdk.orders.ordersPlace(submission as never)) as unknown as T;
71
+
52
72
  if (!attribution) {
53
- return await sdk.orders.ordersPlace(submission as never) as unknown as T;
73
+ return await place(unmapped);
54
74
  }
55
75
  try {
56
- return await new Orders(clientAdding(sdk.client, { attribution }) as never).ordersPlace(submission as never) as unknown as T;
76
+ return await place({ ...unmapped, attribution });
57
77
  }
58
78
  catch (err) {
59
79
  if (!isAttributionRefusal(err)) {
60
80
  throw err;
61
81
  }
62
82
  getLogService().warn("order attribution refused, placed without it", apiErrorContext(err));
63
- return await sdk.orders.ordersPlace(submission as never) as unknown as T;
83
+ return await place(unmapped);
64
84
  }
65
85
  }