@tapcart/mobile-components 0.18.0 → 0.18.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"swr-retry.d.ts","sourceRoot":"","sources":["../../../components/hooks/swr-retry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAE3C,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAOtC,eAAO,MAAM,YAAY,QAAS,OAAO,KAAG,OAG3C,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,OAAO,KAAG,OAA6B,CAAA;AAiC/E,KAAK,YAAY,GAAG,WAAW,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAA;AACjE,KAAK,SAAS,GAAG,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;IAC1D,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAO,cAkCpC,CAAA"}
1
+ {"version":3,"file":"swr-retry.d.ts","sourceRoot":"","sources":["../../../components/hooks/swr-retry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAE3C,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAOtC,eAAO,MAAM,YAAY,QAAS,OAAO,KAAG,OAG3C,CAAA;AAmDD,eAAO,MAAM,kBAAkB,QAAS,OAAO,KAAG,OACE,CAAA;AAiCpD,KAAK,YAAY,GAAG,WAAW,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAA;AACjE,KAAK,SAAS,GAAG,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;IAC1D,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAO,cAkCpC,CAAA"}
@@ -8,7 +8,53 @@ export const isAbortError = (err) => {
8
8
  return false;
9
9
  return err.name === "AbortError";
10
10
  };
11
- export const shouldRetryOnError = (err) => !isAbortError(err);
11
+ /**
12
+ * The 4xx statuses that mean "later", not "never" — the request may well succeed
13
+ * unchanged, so retrying is not wasted.
14
+ *
15
+ * 425 Too Early is deliberately absent: it only arises from TLS 1.3 early data,
16
+ * which we never send, so treating it as retryable would describe a state this
17
+ * client cannot reach.
18
+ */
19
+ const RETRYABLE_CLIENT_STATUSES = new Set([
20
+ // The server gave up waiting for the request, rather than refusing what it
21
+ // received. Nothing about the request is wrong, so a retry is the correct
22
+ // response — note `getRetryAfterMs` still only honors `Retry-After` on 429,
23
+ // so a 408 takes the normal backoff.
24
+ 408,
25
+ 429,
26
+ ]);
27
+ /**
28
+ * A 4xx outside RETRYABLE_CLIENT_STATUSES is deterministic: the request itself
29
+ * is what the upstream refused, so every retry earns the identical rejection.
30
+ *
31
+ * WHY THIS MATTERS: retrying spends the upstream's quota for no chance of
32
+ * success. Google Retail calls are billed and quota'd against the *merchant's*
33
+ * GCP project, and on 2026-08-14 one store's filter — referencing a catalog
34
+ * attribute that was never marked indexable — was retried 4x per page view
35
+ * until it exhausted that quota. Google then 429'd every search for that store,
36
+ * including the ones that would have succeeded. A permanent rejection has to
37
+ * cost one call, not four.
38
+ *
39
+ * This predicate is shared across consumers (the cluster feed included), which
40
+ * is why the retryable set is defined by HTTP semantics rather than by what any
41
+ * one upstream happens to emit. The google-retail proxy collapses every upstream
42
+ * 4xx to 400 or 429 (see tapcart-microservices integrations/app/googleRetail/
43
+ * errors.js), so 408 reaches this predicate only from the other consumers.
44
+ *
45
+ * Errors carrying no `status` keep the previous behaviour (retry unless
46
+ * aborted), so integrations that do not populate it are unaffected.
47
+ */
48
+ const isPermanentClientError = (err) => {
49
+ if (!err || typeof err !== "object")
50
+ return false;
51
+ const { status } = err;
52
+ return (typeof status === "number" &&
53
+ status >= 400 &&
54
+ status < 500 &&
55
+ !RETRYABLE_CLIENT_STATUSES.has(status));
56
+ };
57
+ export const shouldRetryOnError = (err) => !isAbortError(err) && !isPermanentClientError(err);
12
58
  const parseRetryAfter = (value) => {
13
59
  if (value === null || value === undefined)
14
60
  return null;
@@ -31,6 +31,85 @@ describe("swr-retry helpers", () => {
31
31
  expect(shouldRetryOnError(new Error("boom"))).toBe(true);
32
32
  expect(shouldRetryOnError({ status: 500 })).toBe(true);
33
33
  });
34
+ // A 4xx is deterministic — retrying it burns the upstream's quota for no
35
+ // chance of success. This is the guard that stopped one bad Google Retail
36
+ // filter costing 4 API calls per page view.
37
+ it("returns false for a 4xx, which cannot succeed on retry", () => {
38
+ expect(shouldRetryOnError({ status: 400 })).toBe(false);
39
+ expect(shouldRetryOnError({ status: 403 })).toBe(false);
40
+ expect(shouldRetryOnError({ status: 404 })).toBe(false);
41
+ expect(shouldRetryOnError({ status: 499 })).toBe(false);
42
+ });
43
+ // 429 is the 4xx that means "later", not "never".
44
+ it("returns true for 429 so Retry-After is honored", () => {
45
+ expect(shouldRetryOnError({ status: 429 })).toBe(true);
46
+ });
47
+ /**
48
+ * 408 is the other one: the server gave up waiting for the request rather
49
+ * than refusing what it received, so the same request may well succeed. The
50
+ * google-retail proxy collapses upstream 408s to 400 before they get here,
51
+ * so this matters for the cluster feed and any future consumer — which is
52
+ * the reason the retryable set is defined by HTTP semantics and not by what
53
+ * one upstream emits.
54
+ */
55
+ it("returns true for 408, which is transient rather than deterministic", () => {
56
+ expect(shouldRetryOnError({ status: 408 })).toBe(true);
57
+ const clusterFeed408 = Object.assign(new Error("Cluster feed HTTP 408"), {
58
+ reason: "cluster-feed-http",
59
+ status: 408,
60
+ retryAfter: null,
61
+ });
62
+ expect(shouldRetryOnError(clusterFeed408)).toBe(true);
63
+ });
64
+ // 425 Too Early is retryable in the abstract but unreachable here — we send
65
+ // no TLS early data — so it stays in the permanent set deliberately.
66
+ it("returns false for 425, which this client cannot receive", () => {
67
+ expect(shouldRetryOnError({ status: 425 })).toBe(false);
68
+ });
69
+ it("returns true for 5xx and for statuses below 400", () => {
70
+ expect(shouldRetryOnError({ status: 500 })).toBe(true);
71
+ expect(shouldRetryOnError({ status: 503 })).toBe(true);
72
+ expect(shouldRetryOnError({ status: 399 })).toBe(true);
73
+ });
74
+ // Integrations that never set `status` must behave exactly as before.
75
+ it("retries when status is absent or not a number", () => {
76
+ expect(shouldRetryOnError(new Error("network down"))).toBe(true);
77
+ expect(shouldRetryOnError({ status: undefined })).toBe(true);
78
+ expect(shouldRetryOnError({ status: "400" })).toBe(true);
79
+ expect(shouldRetryOnError({})).toBe(true);
80
+ });
81
+ // An abort still wins even if a status rode along.
82
+ it("returns false for an AbortError carrying a retryable status", () => {
83
+ const err = Object.assign(new Error("aborted"), {
84
+ name: "AbortError",
85
+ status: 500,
86
+ });
87
+ expect(shouldRetryOnError(err)).toBe(false);
88
+ });
89
+ it("does not throw on null / undefined / primitives", () => {
90
+ expect(shouldRetryOnError(null)).toBe(true);
91
+ expect(shouldRetryOnError(undefined)).toBe(true);
92
+ expect(shouldRetryOnError(404)).toBe(true);
93
+ });
94
+ /**
95
+ * This hook is shared. Both known callers — use-infinite-scroll (the
96
+ * search-client path) and usePersonalizedClusterFeed — throw errors that
97
+ * carry `status`, so both stop retrying 4xx. That is deliberate: a 4xx is
98
+ * deterministic whichever API produced it, and the cluster feed already
99
+ * attached `status`/`retryAfter` (see use-personalized-cluster-feed-core.ts
100
+ * :258) purely so this layer could act on them.
101
+ */
102
+ it("applies to the cluster-feed error shape too, not just search", () => {
103
+ const clusterFeed4xx = Object.assign(new Error("Cluster feed HTTP 404"), {
104
+ reason: "cluster-feed-http",
105
+ status: 404,
106
+ retryAfter: null,
107
+ });
108
+ expect(shouldRetryOnError(clusterFeed4xx)).toBe(false);
109
+ // A network failure there has no status, so it still retries.
110
+ const clusterFeedNetwork = Object.assign(new Error("Cluster feed request failed"), { reason: "cluster-feed-network" });
111
+ expect(shouldRetryOnError(clusterFeedNetwork)).toBe(true);
112
+ });
34
113
  });
35
114
  });
36
115
  describe("useSwrRetryConfig", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",