@autobusal/providers 1.29.3 → 1.30.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,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.30.0
4
+
5
+ ### Added
6
+
7
+ - **`BootstrapError` tells a transient failure from a real one and recovers
8
+ by itself.** A rate limit or a dropped connection is not a system error,
9
+ and "something broke on our side" is wrong twice for either: it blames the
10
+ wrong thing, and it hands the visitor a reload button for a situation where
11
+ reloading immediately makes it worse. 429/503/504 and a request with no
12
+ response at all now get their own wording and an automatic retry that backs
13
+ off 5s, 10s, 20s, 30s.
14
+
15
+ ## 1.29.4
16
+
17
+ ### Added
18
+
19
+ - **`OrderData.addons`** (`OrderAddonData[]`) - the extra services bought at
20
+ checkout. There is no `data` field by design: the API withholds it because
21
+ the Telegram add-on's copy holds a bind token.
22
+ - **`OrderData.fare_display`** - the fare WITHOUT add-ons. Optional, because
23
+ only the single-order endpoint opts into it; `amount_display` remains fare +
24
+ add-ons.
25
+
3
26
  ## 1.29.3
4
27
 
5
28
  ### Fixed
@@ -35,11 +35,63 @@ interface Props {
35
35
  * *into*. A full reload is the honest recovery, and it is what a visitor
36
36
  * would do anyway.
37
37
  */
38
- class BootstrapError extends React.Component<Props, { failed: boolean }> {
39
- state = { failed: false };
38
+ /**
39
+ * Is this a failure that fixes itself?
40
+ *
41
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
42
+ *
43
+ * A rate limit and a dropped connection are not system errors, and telling
44
+ * somebody "something broke on our side" for either is wrong twice over: it
45
+ * blames the wrong thing, and it hands them a reload button for a situation
46
+ * where reloading immediately is the one move that makes it worse.
47
+ *
48
+ * Read off the axios error rather than the message text, which is not
49
+ * stable. A 429 carries a status; a network failure carries none at all,
50
+ * which is what distinguishes it from a server that answered with a fault.
51
+ */
52
+ const transient = (error: any): 'busy' | 'offline' | null => {
53
+ const status = error?.response?.status ?? error?.status;
54
+
55
+ if (status === 429) {
56
+ return 'busy';
57
+ }
58
+
59
+ if (status === 503 || status === 504) {
60
+ return 'busy';
61
+ }
62
+
63
+ // No response at all - DNS, offline, connection refused, CORS preflight
64
+ // that never landed. Distinct from a server that replied with a 500.
65
+ if (error?.isAxiosError && !error?.response) {
66
+ return 'offline';
67
+ }
68
+
69
+ return null;
70
+ };
71
+
72
+ /**
73
+ * How long to wait before trying again.
74
+ *
75
+ * The rate limiter's window is a minute, so a few seconds is usually enough
76
+ * and a full minute feels broken. Backs off on each successive failure so a
77
+ * genuinely overloaded server is not hammered by every open tab at once.
78
+ */
79
+ const DELAYS = [ 5, 10, 20, 30 ];
80
+
81
+ interface State {
82
+ failed: boolean
83
+ kind: 'busy' | 'offline' | null
84
+ attempt: number
85
+ countdown: number
86
+ }
40
87
 
41
- static getDerivedStateFromError() {
42
- return { failed: true };
88
+ class BootstrapError extends React.Component<Props, State> {
89
+ state: State = { failed: false, kind: null, attempt: 0, countdown: 0 };
90
+
91
+ private timer?: ReturnType<typeof setInterval>;
92
+
93
+ static getDerivedStateFromError(error: Error) {
94
+ return { failed: true, kind: transient(error) };
43
95
  }
44
96
 
45
97
  componentDidCatch(error: Error, info: React.ErrorInfo): void {
@@ -47,6 +99,45 @@ class BootstrapError extends React.Component<Props, { failed: boolean }> {
47
99
  // knows the app failed to start, and a white page with a `log` entry is
48
100
  // easy to miss when somebody finally does open the console.
49
101
  console.error('[bootstrap] the application could not start', error, info);
102
+
103
+ /*
104
+ * A transient failure retries itself. The visitor did nothing wrong and
105
+ * has nothing useful to do, so asking them to press a button is asking
106
+ * them to do our waiting for us - and the thing they would press it for
107
+ * is a rate limit that clears on its own.
108
+ */
109
+ if (transient(error)) {
110
+ this.countdownTo(this.state.attempt);
111
+ }
112
+ }
113
+
114
+ componentWillUnmount(): void {
115
+ if (this.timer) {
116
+ clearInterval(this.timer);
117
+ }
118
+ }
119
+
120
+ private countdownTo(attempt: number): void {
121
+ const seconds = DELAYS[Math.min(attempt, DELAYS.length - 1)];
122
+
123
+ this.setState({ countdown: seconds });
124
+
125
+ this.timer = setInterval(() => {
126
+ this.setState(state => {
127
+ if (state.countdown > 1) {
128
+ return { ...state, countdown: state.countdown - 1 };
129
+ }
130
+
131
+ clearInterval(this.timer);
132
+
133
+ // A full reload rather than resetting this boundary: whatever
134
+ // suspended did so during bootstrap, so there is no reliable state
135
+ // to retry INTO - the same reasoning as the button below.
136
+ window.location.reload();
137
+
138
+ return { ...state, countdown: 0 };
139
+ });
140
+ }, 1000);
50
141
  }
51
142
 
52
143
  render() {
@@ -59,6 +150,26 @@ class BootstrapError extends React.Component<Props, { failed: boolean }> {
59
150
  const language = getLanguage('en');
60
151
  const copy = errors[language as keyof typeof errors] ?? errors.en;
61
152
 
153
+ /*
154
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
155
+ * A transient failure gets its own words and its own countdown. The
156
+ * generic system error keeps the reload button, because for a real
157
+ * fault there is nothing to wait for.
158
+ */
159
+ const { kind, countdown } = this.state;
160
+
161
+ const title = kind === 'busy' ? (copy as any).busy ?? copy.system : copy.system;
162
+
163
+ const detail = kind === 'busy'
164
+ ? ((copy as any).busy_detail ?? copy.system_detail)
165
+ : kind === 'offline'
166
+ ? ((copy as any).offline_detail ?? copy.system_detail)
167
+ : copy.system_detail;
168
+
169
+ const message = kind
170
+ ? String(detail).replace('{n}', String(countdown))
171
+ : detail;
172
+
62
173
  return (
63
174
  <div
64
175
  role="alert"
@@ -75,11 +186,11 @@ class BootstrapError extends React.Component<Props, { failed: boolean }> {
75
186
  >
76
187
  <div style={ { maxWidth: '460px', textAlign: 'center' } }>
77
188
  <h1 style={ { fontSize: '20px', lineHeight: 1.4, margin: '0 0 12px' } }>
78
- { copy.system }
189
+ { title }
79
190
  </h1>
80
191
 
81
192
  <p style={ { fontSize: '15px', lineHeight: 1.6, margin: '0 0 24px', opacity: 0.8 } }>
82
- { copy.system_detail }
193
+ { message }
83
194
  </p>
84
195
 
85
196
  <button
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/providers",
3
- "version": "1.29.3",
3
+ "version": "1.30.0",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"
package/stores/user.ts CHANGED
@@ -20,7 +20,19 @@ export interface UserStore {
20
20
  // login/activate/refresh); it's just never written to disk. A bootstrap
21
21
  // fetch (see Setup/useUserBootstrap.ts) re-hydrates the full in-memory
22
22
  // object shortly after app load using this same reduced signal.
23
- type PersistedUser = Pick<UserData, 'id' | 'name' | 'name_display' | 'type' | 'status'>;
23
+ // Edited: Ferjolt Ozuni - Date: 2026-08-07
24
+ // `verified` joins the subset because `status` cannot be READ without it.
25
+ // Status 0 means "activation pending" for a self-registered account and
26
+ // "switched off by staff" for one an admin created - and the two get
27
+ // different screens (see @autobusal/auth's Secure). Persisting the status
28
+ // but not the field that disambiguates it meant the first paint after a
29
+ // reload had to guess, and guessed activation: a deactivated employee was
30
+ // shown "enter the 5-digit code we emailed you" for a code that does not
31
+ // exist.
32
+ //
33
+ // It is a verification timestamp, not personal data - it says nothing about
34
+ // who the person is, which is what the rest of this redaction is for.
35
+ type PersistedUser = Pick<UserData, 'id' | 'name' | 'name_display' | 'type' | 'status' | 'verified'>;
24
36
 
25
37
  const STORAGE_KEY = 'user';
26
38
 
@@ -29,7 +41,8 @@ const redact = (user: UserData): PersistedUser => ({
29
41
  name: user.name,
30
42
  name_display: user.name_display,
31
43
  type: user.type,
32
- status: user.status
44
+ status: user.status,
45
+ verified: user.verified
33
46
  });
34
47
 
35
48
  const stored = localStorage.getItem(STORAGE_KEY);
package/types/orders.ts CHANGED
@@ -33,6 +33,12 @@ export interface OrderData {
33
33
  passengers: TicketData[]
34
34
  tickets: number
35
35
  amount_display: string
36
+ /*
37
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
38
+ * The fare WITHOUT add-ons. Optional: only the single-order endpoint opts
39
+ * into it (it costs a sum query), so the listing does not carry it.
40
+ */
41
+ fare_display?: string
36
42
  note_cancel: string
37
43
  actions: string[]
38
44
  created_at: string
@@ -42,6 +48,29 @@ export interface OrderData {
42
48
  reference?: OrderData
43
49
  updated_at: string
44
50
  account?: any
51
+
52
+ /*
53
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
54
+ * The extra services bought at checkout. Optional: only the single-order
55
+ * endpoint loads them, and the listing does not.
56
+ *
57
+ * There is no `data` field by design - the API withholds it because the
58
+ * Telegram add-on's copy holds a bind token. See Libraries\Orders\View.
59
+ */
60
+ addons?: OrderAddonData[]
61
+ }
62
+
63
+ export interface OrderAddonData {
64
+ id: number
65
+ // 'flex' | 'whatsapp' | 'telegram' | 'sms' - open, since the registry is
66
+ // a table and a brand can be given a key this build has never heard of.
67
+ key: string
68
+ price: string
69
+ // The same value with the brand's currency on it. The currency is a label
70
+ // setting the client is never sent, so this has to be formatted server
71
+ // side - see Orders\OrderAddon.
72
+ price_display: string
73
+ created_at: string
45
74
  }
46
75
 
47
76
  export interface ContactData {