fontdue-js 3.15.0-beta.0 → 3.15.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 3.15.0
2
+
3
+ - Added a `locale` option, such as `"de"`, to `FontdueProvider`, `createFontdueFetch` and the server config in `fontdue-js/server`, and to `runWithFontdue` (plus a new `runWithLocale`) in `fontdue-js/server/middleware`. Components then load the foundry’s content in that language and show their own text in it – English and German so far – and without a `locale` nothing changes. In Next.js, set it per page as well as on the layout’s provider, since a soft navigation re-renders the page without the layout.
4
+ - Added `returnUrl` and `returnLabel` to the `storeModal` config. The order page buyers land on after paying links back to that URL instead of the foundry’s site, as long as it’s on one of the store’s allowed origins.
5
+ - Added `collapse` and `loadMoreLabel` to `CharacterViewer`. `collapse` shows only the first character group, or the grid cut to a given height, with a *Load more* button underneath.
6
+ - `StoreModal`, the font families list and `TypeTester`’s select button leave out styles set to *Unlisted*. A type tester still shows an unlisted style, without a select button.
7
+ - Fixed removing the last item a coupon applies to, or emptying a cart with a coupon on it, doing nothing in the `StoreModal` cart. The coupon now comes off with the item and the cart shows a notice saying so.
8
+ - Fixed `CharacterViewer` and the `StoreModal` breaking on a superfamily whose families are all hidden.
9
+
1
10
  ## 3.14.0
2
11
 
3
12
  - `StoreModal` puts two bundles on one row when the second directly follows the first and repeats its name plus a suffix, such as *Thin* and *Thin Italic*.
@@ -1,10 +1,13 @@
1
1
  /**
2
- * @generated SignedSource<<9e2fb92d3b6dbb2988837d16a6e95d8e>>
2
+ * @generated SignedSource<<1366f7e8c1c4f057f72ce4366915ef52>>
3
3
  * @lightSyntaxTransform
4
4
  * @nogrep
5
5
  */
6
6
  import { ConcreteRequest } from 'relay-runtime';
7
- export type StripeProviderCreateCheckoutSessionMutation$variables = Record<PropertyKey, never>;
7
+ export type StripeProviderCreateCheckoutSessionMutation$variables = {
8
+ returnLabel?: string | null;
9
+ returnUrl?: string | null;
10
+ };
8
11
  export type StripeProviderCreateCheckoutSessionMutation$data = {
9
12
  readonly createOrderCheckoutSession: {
10
13
  readonly order: {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @generated SignedSource<<9e2fb92d3b6dbb2988837d16a6e95d8e>>
2
+ * @generated SignedSource<<1366f7e8c1c4f057f72ce4366915ef52>>
3
3
  * @lightSyntaxTransform
4
4
  * @nogrep
5
5
  */
@@ -10,30 +10,49 @@
10
10
 
11
11
  const node = function () {
12
12
  var v0 = {
13
- "alias": null,
14
- "args": null,
15
- "concreteType": "StripeCheckoutSession",
16
- "kind": "LinkedField",
17
- "name": "stripeCheckoutSession",
18
- "plural": false,
19
- "selections": [{
13
+ "defaultValue": null,
14
+ "kind": "LocalArgument",
15
+ "name": "returnLabel"
16
+ },
17
+ v1 = {
18
+ "defaultValue": null,
19
+ "kind": "LocalArgument",
20
+ "name": "returnUrl"
21
+ },
22
+ v2 = [{
23
+ "kind": "Variable",
24
+ "name": "returnLabel",
25
+ "variableName": "returnLabel"
26
+ }, {
27
+ "kind": "Variable",
28
+ "name": "returnUrl",
29
+ "variableName": "returnUrl"
30
+ }],
31
+ v3 = {
20
32
  "alias": null,
21
33
  "args": null,
22
- "kind": "ScalarField",
23
- "name": "clientSecret",
34
+ "concreteType": "StripeCheckoutSession",
35
+ "kind": "LinkedField",
36
+ "name": "stripeCheckoutSession",
37
+ "plural": false,
38
+ "selections": [{
39
+ "alias": null,
40
+ "args": null,
41
+ "kind": "ScalarField",
42
+ "name": "clientSecret",
43
+ "storageKey": null
44
+ }],
24
45
  "storageKey": null
25
- }],
26
- "storageKey": null
27
- };
46
+ };
28
47
  return {
29
48
  "fragment": {
30
- "argumentDefinitions": [],
49
+ "argumentDefinitions": [v0 /*: any*/, v1 /*: any*/],
31
50
  "kind": "Fragment",
32
51
  "metadata": null,
33
52
  "name": "StripeProviderCreateCheckoutSessionMutation",
34
53
  "selections": [{
35
54
  "alias": null,
36
- "args": null,
55
+ "args": v2 /*: any*/,
37
56
  "concreteType": "CreateOrderCheckoutSessionPayload",
38
57
  "kind": "LinkedField",
39
58
  "name": "createOrderCheckoutSession",
@@ -45,7 +64,7 @@ const node = function () {
45
64
  "kind": "LinkedField",
46
65
  "name": "order",
47
66
  "plural": false,
48
- "selections": [v0 /*: any*/],
67
+ "selections": [v3 /*: any*/],
49
68
  "storageKey": null
50
69
  }],
51
70
  "storageKey": null
@@ -55,12 +74,12 @@ const node = function () {
55
74
  },
56
75
  "kind": "Request",
57
76
  "operation": {
58
- "argumentDefinitions": [],
77
+ "argumentDefinitions": [v1 /*: any*/, v0 /*: any*/],
59
78
  "kind": "Operation",
60
79
  "name": "StripeProviderCreateCheckoutSessionMutation",
61
80
  "selections": [{
62
81
  "alias": null,
63
- "args": null,
82
+ "args": v2 /*: any*/,
64
83
  "concreteType": "CreateOrderCheckoutSessionPayload",
65
84
  "kind": "LinkedField",
66
85
  "name": "createOrderCheckoutSession",
@@ -72,7 +91,7 @@ const node = function () {
72
91
  "kind": "LinkedField",
73
92
  "name": "order",
74
93
  "plural": false,
75
- "selections": [v0 /*: any*/, {
94
+ "selections": [v3 /*: any*/, {
76
95
  "alias": null,
77
96
  "args": null,
78
97
  "kind": "ScalarField",
@@ -85,14 +104,14 @@ const node = function () {
85
104
  }]
86
105
  },
87
106
  "params": {
88
- "cacheID": "0ece78edfb78a66584361cee7d83e6a2",
107
+ "cacheID": "694e81728d2fe3f137af118dc09961ca",
89
108
  "id": null,
90
109
  "metadata": {},
91
110
  "name": "StripeProviderCreateCheckoutSessionMutation",
92
111
  "operationKind": "mutation",
93
- "text": "mutation StripeProviderCreateCheckoutSessionMutation {\n createOrderCheckoutSession {\n order {\n stripeCheckoutSession {\n clientSecret\n }\n id\n }\n }\n}\n"
112
+ "text": "mutation StripeProviderCreateCheckoutSessionMutation(\n $returnUrl: String\n $returnLabel: String\n) {\n createOrderCheckoutSession(returnUrl: $returnUrl, returnLabel: $returnLabel) {\n order {\n stripeCheckoutSession {\n clientSecret\n }\n id\n }\n }\n}\n"
94
113
  }
95
114
  };
96
115
  }();
97
- node.hash = "2ca9a7fcfed1292117e3cd6d0d95cca6";
116
+ node.hash = "182092b555f884405afb61050ed98b79";
98
117
  export default node;
@@ -0,0 +1,66 @@
1
+ // `storeModal.returnUrl` as checkout hands it to the order page that payment
2
+ // returns to, for that page's link back.
3
+
4
+ import { describe, expect, it } from 'vitest';
5
+ import { checkoutReturnParams, withCheckoutReturn } from '../components/Cart/checkoutReturn.js';
6
+ const page = 'https://ornaments.example.com/draw?tool=box';
7
+ const completeUrl = 'https://store.example.com/orders/1';
8
+ describe('checkoutReturnParams', () => {
9
+ it('is null when the site sets no return URL', () => {
10
+ expect(checkoutReturnParams(undefined, page)).toEqual({
11
+ returnUrl: null,
12
+ returnLabel: null
13
+ });
14
+ expect(checkoutReturnParams({
15
+ returnLabel: 'Back'
16
+ }, page)).toEqual({
17
+ returnUrl: null,
18
+ returnLabel: null
19
+ });
20
+ });
21
+ it('keeps an absolute URL as given, with its label', () => {
22
+ expect(checkoutReturnParams({
23
+ returnUrl: 'https://ornaments.example.com/',
24
+ returnLabel: 'Back to Ornaments'
25
+ }, page)).toEqual({
26
+ returnUrl: 'https://ornaments.example.com/',
27
+ returnLabel: 'Back to Ornaments'
28
+ });
29
+ });
30
+ it('resolves a relative URL against the page the store modal is on', () => {
31
+ expect(checkoutReturnParams({
32
+ returnUrl: '/'
33
+ }, page)).toEqual({
34
+ returnUrl: 'https://ornaments.example.com/',
35
+ returnLabel: null
36
+ });
37
+ expect(checkoutReturnParams({
38
+ returnUrl: '?from=checkout'
39
+ }, page).returnUrl).toBe('https://ornaments.example.com/draw?from=checkout');
40
+ });
41
+ it('is null rather than throwing for a value that is no URL', () => {
42
+ expect(checkoutReturnParams({
43
+ returnUrl: 'http://[bad'
44
+ }, page).returnUrl).toBeNull();
45
+ });
46
+ });
47
+ describe('withCheckoutReturn', () => {
48
+ it('leaves the order page URL alone when the site sets no return URL', () => {
49
+ expect(withCheckoutReturn(completeUrl, undefined, page)).toBe(completeUrl);
50
+ });
51
+ it('carries the return URL and label as query parameters', () => {
52
+ const url = new URL(withCheckoutReturn(completeUrl, {
53
+ returnUrl: '/?purchased=1',
54
+ returnLabel: 'Back to Ornaments'
55
+ }, page));
56
+ expect(url.origin + url.pathname).toBe(completeUrl);
57
+ expect(url.searchParams.get('return_url')).toBe('https://ornaments.example.com/?purchased=1');
58
+ expect(url.searchParams.get('return_label')).toBe('Back to Ornaments');
59
+ });
60
+ it('omits the label when the site sets none', () => {
61
+ const url = new URL(withCheckoutReturn(completeUrl, {
62
+ returnUrl: '/'
63
+ }, page));
64
+ expect(url.searchParams.has('return_label')).toBe(false);
65
+ });
66
+ });
@@ -0,0 +1,17 @@
1
+ import { StoreModalConfig } from '../StoreModal/types.js';
2
+ type ReturnConfig = Pick<StoreModalConfig, 'returnUrl' | 'returnLabel'> | undefined;
3
+ /**
4
+ * `storeModal.returnUrl` as the server takes it: absolute, resolved against
5
+ * the page the store modal is on, or null when the site sets none.
6
+ */
7
+ export declare function checkoutReturnParams(config: ReturnConfig, pageUrl: string): {
8
+ returnUrl: string | null;
9
+ returnLabel: string | null;
10
+ };
11
+ /**
12
+ * The order page URL payment returns to, carrying where that page's link back
13
+ * should go (`return_url`, `return_label`). The server ignores a URL that
14
+ * isn't on the store's allowed origins and links to the foundry's site.
15
+ */
16
+ export declare function withCheckoutReturn(completeUrl: string, config: ReturnConfig, pageUrl: string): string;
17
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `storeModal.returnUrl` as the server takes it: absolute, resolved against
3
+ * the page the store modal is on, or null when the site sets none.
4
+ */
5
+ export function checkoutReturnParams(config, pageUrl) {
6
+ if (!(config !== null && config !== void 0 && config.returnUrl)) return {
7
+ returnUrl: null,
8
+ returnLabel: null
9
+ };
10
+ try {
11
+ return {
12
+ returnUrl: new URL(config.returnUrl, pageUrl).href,
13
+ returnLabel: config.returnLabel ?? null
14
+ };
15
+ } catch {
16
+ return {
17
+ returnUrl: null,
18
+ returnLabel: null
19
+ };
20
+ }
21
+ }
22
+
23
+ /**
24
+ * The order page URL payment returns to, carrying where that page's link back
25
+ * should go (`return_url`, `return_label`). The server ignores a URL that
26
+ * isn't on the store's allowed origins and links to the foundry's site.
27
+ */
28
+ export function withCheckoutReturn(completeUrl, config, pageUrl) {
29
+ const {
30
+ returnUrl,
31
+ returnLabel
32
+ } = checkoutReturnParams(config, pageUrl);
33
+ if (!returnUrl) return completeUrl;
34
+ const url = new URL(completeUrl);
35
+ url.searchParams.set('return_url', returnUrl);
36
+ if (returnLabel) url.searchParams.set('return_label', returnLabel);
37
+ return url.href;
38
+ }
@@ -110,6 +110,8 @@ export declare const makeConfig: (config?: Config) => {
110
110
  indexExcludeTags: string[] | undefined;
111
111
  productLicensesPosition: "bottom" | "top";
112
112
  hideAllCollections: boolean;
113
+ returnUrl: string | undefined;
114
+ returnLabel: string | undefined;
113
115
  };
114
116
  stripe: {
115
117
  appearance: Appearance | null;
@@ -192,6 +194,8 @@ declare const _default: React.Context<{
192
194
  indexExcludeTags: string[] | undefined;
193
195
  productLicensesPosition: "bottom" | "top";
194
196
  hideAllCollections: boolean;
197
+ returnUrl: string | undefined;
198
+ returnLabel: string | undefined;
195
199
  };
196
200
  stripe: {
197
201
  appearance: Appearance | null;
@@ -91,7 +91,7 @@ export const mergeConfig = (base, override) => {
91
91
  return deepMerge(base, override);
92
92
  };
93
93
  export const makeConfig = config => {
94
- var _config$form, _config$testFonts, _config$testFonts2, _config$storeModal, _config$storeModal2, _config$storeModal3, _config$storeModal4, _config$stripe, _config$tracking, _config$tracking2, _config$tracking3, _config$tracking4, _config$preview, _config$preview2, _config$preview3;
94
+ var _config$form, _config$testFonts, _config$testFonts2, _config$storeModal, _config$storeModal2, _config$storeModal3, _config$storeModal4, _config$storeModal5, _config$storeModal6, _config$stripe, _config$tracking, _config$tracking2, _config$tracking3, _config$tracking4, _config$preview, _config$preview2, _config$preview3;
95
95
  return {
96
96
  typeTester: makeTypeTesterConfig(config === null || config === void 0 ? void 0 : config.typeTester),
97
97
  form: {
@@ -108,7 +108,9 @@ export const makeConfig = config => {
108
108
  indexLayout: (config === null || config === void 0 ? void 0 : (_config$storeModal = config.storeModal) === null || _config$storeModal === void 0 ? void 0 : _config$storeModal.indexLayout) ?? 'styled-aa',
109
109
  indexExcludeTags: config === null || config === void 0 ? void 0 : (_config$storeModal2 = config.storeModal) === null || _config$storeModal2 === void 0 ? void 0 : _config$storeModal2.indexExcludeTags,
110
110
  productLicensesPosition: (config === null || config === void 0 ? void 0 : (_config$storeModal3 = config.storeModal) === null || _config$storeModal3 === void 0 ? void 0 : _config$storeModal3.productLicensesPosition) ?? 'top',
111
- hideAllCollections: (config === null || config === void 0 ? void 0 : (_config$storeModal4 = config.storeModal) === null || _config$storeModal4 === void 0 ? void 0 : _config$storeModal4.hideAllCollections) ?? false
111
+ hideAllCollections: (config === null || config === void 0 ? void 0 : (_config$storeModal4 = config.storeModal) === null || _config$storeModal4 === void 0 ? void 0 : _config$storeModal4.hideAllCollections) ?? false,
112
+ returnUrl: config === null || config === void 0 ? void 0 : (_config$storeModal5 = config.storeModal) === null || _config$storeModal5 === void 0 ? void 0 : _config$storeModal5.returnUrl,
113
+ returnLabel: config === null || config === void 0 ? void 0 : (_config$storeModal6 = config.storeModal) === null || _config$storeModal6 === void 0 ? void 0 : _config$storeModal6.returnLabel
112
114
  },
113
115
  stripe: {
114
116
  appearance: (config === null || config === void 0 ? void 0 : (_config$stripe = config.stripe) === null || _config$stripe === void 0 ? void 0 : _config$stripe.appearance) ?? null
@@ -3,4 +3,13 @@ export interface StoreModalConfig {
3
3
  indexExcludeTags?: string[] | undefined;
4
4
  productLicensesPosition?: 'bottom' | 'top';
5
5
  hideAllCollections?: boolean;
6
+ /**
7
+ * Where the order page's link back goes once the buyer has paid, instead of
8
+ * the foundry's site – the page this store modal is embedded in, say.
9
+ * Relative URLs resolve against the current page. Must be on one of the
10
+ * store's allowed origins; anything else is refused.
11
+ */
12
+ returnUrl?: string;
13
+ /** The text of that link. Defaults to "Back to <host>". */
14
+ returnLabel?: string;
6
15
  }
@@ -6,6 +6,7 @@ import { Elements, EmbeddedCheckoutProvider } from '@stripe/react-stripe-js';
6
6
  import { loadStripe } from '@stripe/stripe-js';
7
7
  import { parseCustomProperties } from '../../utils.js';
8
8
  import ConfigContext from '../ConfigContext.js';
9
+ import { checkoutReturnParams } from '../Cart/checkoutReturn.js';
9
10
  import { useLocale } from '../LocaleContext.js';
10
11
  import { stripeElementsLocale } from '../../locale.js';
11
12
  import StoreModalPageContainer from '../elements/StoreModalPageContainer/index.js';
@@ -28,7 +29,8 @@ const StripeProvider = _ref => {
28
29
  // All hooks must be called before any conditional returns (React rules of hooks)
29
30
  const environment = useRelayEnvironment();
30
31
  const {
31
- stripe: config
32
+ stripe: config,
33
+ storeModal: storeModalConfig
32
34
  } = useContext(ConfigContext);
33
35
  const stripeLocale = stripeElementsLocale(useLocale());
34
36
  const [checkoutError, setCheckoutError] = useState(null);
@@ -54,8 +56,10 @@ const StripeProvider = _ref => {
54
56
  const fetchClientSecret = useCallback(() => {
55
57
  return new Promise((resolve, reject) => {
56
58
  commitMutation(environment, {
57
- mutation: (_StripeProviderCreateCheckoutSessionMutation.hash && _StripeProviderCreateCheckoutSessionMutation.hash !== "2ca9a7fcfed1292117e3cd6d0d95cca6" && console.error("The definition of 'StripeProviderCreateCheckoutSessionMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _StripeProviderCreateCheckoutSessionMutation),
58
- variables: {},
59
+ mutation: (_StripeProviderCreateCheckoutSessionMutation.hash && _StripeProviderCreateCheckoutSessionMutation.hash !== "182092b555f884405afb61050ed98b79" && console.error("The definition of 'StripeProviderCreateCheckoutSessionMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _StripeProviderCreateCheckoutSessionMutation),
60
+ // Stripe returns to the order page; this names where that page's link
61
+ // back goes (`storeModal.returnUrl`).
62
+ variables: checkoutReturnParams(storeModalConfig, window.location.href),
59
63
  onCompleted: (response, errors) => {
60
64
  var _response$createOrder, _response$createOrder2, _response$createOrder3;
61
65
  const clientSecret = (_response$createOrder = response.createOrderCheckoutSession) === null || _response$createOrder === void 0 ? void 0 : (_response$createOrder2 = _response$createOrder.order) === null || _response$createOrder2 === void 0 ? void 0 : (_response$createOrder3 = _response$createOrder2.stripeCheckoutSession) === null || _response$createOrder3 === void 0 ? void 0 : _response$createOrder3.clientSecret;
@@ -76,7 +80,7 @@ const StripeProvider = _ref => {
76
80
  }
77
81
  });
78
82
  });
79
- }, [environment]);
83
+ }, [environment, storeModalConfig === null || storeModalConfig === void 0 ? void 0 : storeModalConfig.returnUrl, storeModalConfig === null || storeModalConfig === void 0 ? void 0 : storeModalConfig.returnLabel]);
80
84
  const options = {
81
85
  appearance: config.appearance ?? {
82
86
  theme: 'flat',
@@ -80,6 +80,7 @@ import { Check, X } from '../Icons/index.js';
80
80
  import ConfigContext from '../ConfigContext.js';
81
81
  import { Price } from '../Price/index.js';
82
82
  import { sendOrderTracking } from '../Cart/orderTracking.js';
83
+ import { withCheckoutReturn } from '../Cart/checkoutReturn.js';
83
84
  import { trackPaymentInfoEntered } from '../Cart/storefrontEvents.js';
84
85
  import { validateAddressElements, validateElements } from '../../stripeElements.js';
85
86
  import { useRecaptchaTimeout, isRecaptchaScriptLoaded } from '../../hooks/useRecaptchaTimeout.js';
@@ -285,6 +286,9 @@ export default function StoreModalUnifiedCheckout(_ref2) {
285
286
  }));
286
287
  }, [setLicenseeIdentity]);
287
288
  const environment = useRelayEnvironment();
289
+ const {
290
+ storeModal: storeModalConfig
291
+ } = useContext(ConfigContext);
288
292
 
289
293
  // Capture analytics consent + attribution on the order for the purchase
290
294
  // event the server emits on completion (from a Stripe webhook, where no
@@ -623,6 +627,9 @@ export default function StoreModalUnifiedCheckout(_ref2) {
623
627
  }
624
628
  setCompleting(true);
625
629
  setError(null);
630
+
631
+ // The order page, told where its link back goes (`storeModal.returnUrl`).
632
+ const completeUrl = withCheckoutReturn(order.completeUrl, storeModalConfig, window.location.href);
626
633
  const processPayment = () => {
627
634
  var _billingIdentity$stre, _billingIdentity$stre2;
628
635
  if (order.canCompleteWithCoupon) {
@@ -635,7 +642,7 @@ export default function StoreModalUnifiedCheckout(_ref2) {
635
642
  setError(errors[0].message);
636
643
  return;
637
644
  }
638
- window.location.href = order.completeUrl;
645
+ window.location.href = completeUrl;
639
646
  }
640
647
  });
641
648
  return;
@@ -644,7 +651,7 @@ export default function StoreModalUnifiedCheckout(_ref2) {
644
651
  stripe === null || stripe === void 0 ? void 0 : stripe.confirmPayment({
645
652
  elements,
646
653
  confirmParams: {
647
- return_url: order.completeUrl,
654
+ return_url: completeUrl,
648
655
  payment_method_data: {
649
656
  billing_details: {
650
657
  email: billingIdentity.email,
package/dist/version.js CHANGED
@@ -8,4 +8,4 @@
8
8
  // (Fontage.ClientVersions) to spot sites that need to upgrade before a
9
9
  // feature that depends on a newer client can work for them.
10
10
  export const CLIENT_VERSION_HEADER = 'fontdue-client-version';
11
- export const version = "3.15.0-beta.0";
11
+ export const version = "3.15.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fontdue-js",
3
- "version": "3.15.0-beta.0",
3
+ "version": "3.15.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npm run relay && run-p build-js build-css build-ts",