create-brainerce-store 1.83.0 → 1.84.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.
@@ -0,0 +1,49 @@
1
+ import type { PaymentClientSdk } from 'brainerce';
2
+
3
+ /**
4
+ * Render-mode negotiation: predict which mode a payment intent will come back
5
+ * with, so the checkout can pass the matching return URL BEFORE the intent
6
+ * exists. An iframe provider returns the shopper inside the frame, to a
7
+ * same-origin transition page (`/payment-complete`) that posts to the parent;
8
+ * a redirect provider returns them straight to `/order-confirmation`.
9
+ *
10
+ * This is the platform's own rule, verbatim:
11
+ * 1. no preference -> the provider's default (`renderType`)
12
+ * 2. preference listed in displayModes -> the preference
13
+ * 3. preference not listed -> the provider's default
14
+ * 4. displayModes absent (legacy) -> treated as `[renderType]`
15
+ *
16
+ * The SDK exports the same function as `resolveRenderType` from 'brainerce'.
17
+ * This local copy exists because scaffolded stores pin an exact SDK version
18
+ * that must be at least seven days old on npm (see cli-shared/versions.ts),
19
+ * and the version carrying the export is younger than that. Replace this
20
+ * file's body with `export { resolveRenderType } from 'brainerce'` once the
21
+ * pin reaches it.
22
+ */
23
+
24
+ export type PreferredRenderType = 'redirect' | 'iframe';
25
+
26
+ /**
27
+ * The mode this storefront asks the platform for, or `undefined` to take each
28
+ * provider's default. Set to `'iframe'` only if the payment step has a frame
29
+ * to render into AND the provider's iframe has been verified on a real
30
+ * checkout; set to `'redirect'` to keep every provider on a full-page
31
+ * redirect. The platform only honours a mode the provider declares, and the
32
+ * checkout always branches on the `renderType` that comes BACK, so a wrong
33
+ * preference degrades to the provider default rather than breaking payment.
34
+ */
35
+ export const PREFERRED_RENDER_MODE: PreferredRenderType | undefined = undefined;
36
+
37
+ type ProviderSdk = Pick<PaymentClientSdk, 'renderType'> & {
38
+ /** Every mode the provider can serve. Sent by the platform; older SDK types omit it. */
39
+ displayModes?: PaymentClientSdk['renderType'][];
40
+ };
41
+
42
+ export function resolveRenderType(
43
+ sdk: ProviderSdk | null | undefined,
44
+ preferred?: PreferredRenderType
45
+ ): PaymentClientSdk['renderType'] {
46
+ if (!sdk) return 'redirect';
47
+ const declared = sdk.displayModes?.length ? sdk.displayModes : [sdk.renderType];
48
+ return preferred && declared.includes(preferred) ? preferred : sdk.renderType;
49
+ }