@oxy.so/services 12.6.0 → 12.8.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/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/client.js +20 -0
- package/lib/commonjs/ui/client.js.map +1 -1
- package/lib/commonjs/ui/components/FollowButton.js +8 -12
- package/lib/commonjs/ui/components/FollowButton.js.map +1 -1
- package/lib/commonjs/ui/components/FollowTargetButton.js +1 -2
- package/lib/commonjs/ui/components/FollowTargetButton.js.map +1 -1
- package/lib/commonjs/ui/components/followLabels.js +34 -0
- package/lib/commonjs/ui/components/followLabels.js.map +1 -1
- package/lib/commonjs/ui/hooks/useAccountColor.js +56 -0
- package/lib/commonjs/ui/hooks/useAccountColor.js.map +1 -0
- package/lib/commonjs/ui/hooks/useFollow.js +5 -4
- package/lib/commonjs/ui/hooks/useFollow.js.map +1 -1
- package/lib/commonjs/ui/hooks/useFollowTarget.js +8 -8
- package/lib/commonjs/ui/hooks/useFollowTarget.js.map +1 -1
- package/lib/commonjs/ui/stores/followStore.js +10 -9
- package/lib/commonjs/ui/stores/followStore.js.map +1 -1
- package/lib/commonjs/ui/stores/followTargetStore.js.map +1 -1
- package/lib/commonjs/ui/utils/followErrors.js +45 -0
- package/lib/commonjs/ui/utils/followErrors.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/client.js +2 -0
- package/lib/module/ui/client.js.map +1 -1
- package/lib/module/ui/components/FollowButton.js +9 -13
- package/lib/module/ui/components/FollowButton.js.map +1 -1
- package/lib/module/ui/components/FollowTargetButton.js +2 -3
- package/lib/module/ui/components/FollowTargetButton.js.map +1 -1
- package/lib/module/ui/components/followLabels.js +33 -1
- package/lib/module/ui/components/followLabels.js.map +1 -1
- package/lib/module/ui/hooks/useAccountColor.js +51 -0
- package/lib/module/ui/hooks/useAccountColor.js.map +1 -0
- package/lib/module/ui/hooks/useFollow.js +5 -4
- package/lib/module/ui/hooks/useFollow.js.map +1 -1
- package/lib/module/ui/hooks/useFollowTarget.js +8 -8
- package/lib/module/ui/hooks/useFollowTarget.js.map +1 -1
- package/lib/module/ui/stores/followStore.js +10 -9
- package/lib/module/ui/stores/followStore.js.map +1 -1
- package/lib/module/ui/stores/followTargetStore.js.map +1 -1
- package/lib/module/ui/utils/followErrors.js +41 -0
- package/lib/module/ui/utils/followErrors.js.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/client.d.ts +3 -0
- package/lib/typescript/commonjs/ui/client.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/FollowButton.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/FollowTargetButton.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/followLabels.d.ts +13 -0
- package/lib/typescript/commonjs/ui/components/followLabels.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useAccountColor.d.ts +25 -0
- package/lib/typescript/commonjs/ui/hooks/useAccountColor.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/useFollow.d.ts +5 -4
- package/lib/typescript/commonjs/ui/hooks/useFollow.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useFollow.types.d.ts +3 -2
- package/lib/typescript/commonjs/ui/hooks/useFollow.types.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useFollowTarget.d.ts +4 -2
- package/lib/typescript/commonjs/ui/hooks/useFollowTarget.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/stores/followStore.d.ts +3 -1
- package/lib/typescript/commonjs/ui/stores/followStore.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/stores/followTargetStore.d.ts +4 -2
- package/lib/typescript/commonjs/ui/stores/followTargetStore.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/followErrors.d.ts +42 -0
- package/lib/typescript/commonjs/ui/utils/followErrors.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/client.d.ts +3 -0
- package/lib/typescript/module/ui/client.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/FollowButton.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/FollowTargetButton.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/followLabels.d.ts +13 -0
- package/lib/typescript/module/ui/components/followLabels.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useAccountColor.d.ts +25 -0
- package/lib/typescript/module/ui/hooks/useAccountColor.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/useFollow.d.ts +5 -4
- package/lib/typescript/module/ui/hooks/useFollow.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useFollow.types.d.ts +3 -2
- package/lib/typescript/module/ui/hooks/useFollow.types.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useFollowTarget.d.ts +4 -2
- package/lib/typescript/module/ui/hooks/useFollowTarget.d.ts.map +1 -1
- package/lib/typescript/module/ui/stores/followStore.d.ts +3 -1
- package/lib/typescript/module/ui/stores/followStore.d.ts.map +1 -1
- package/lib/typescript/module/ui/stores/followTargetStore.d.ts +4 -2
- package/lib/typescript/module/ui/stores/followTargetStore.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/followErrors.d.ts +42 -0
- package/lib/typescript/module/ui/utils/followErrors.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +2 -0
- package/src/ui/client.ts +3 -0
- package/src/ui/components/FollowButton.tsx +14 -12
- package/src/ui/components/FollowTargetButton.tsx +7 -3
- package/src/ui/components/followLabels.ts +36 -2
- package/src/ui/hooks/useAccountColor.ts +52 -0
- package/src/ui/hooks/useFollow.ts +22 -10
- package/src/ui/hooks/useFollow.types.ts +6 -2
- package/src/ui/hooks/useFollowTarget.ts +15 -10
- package/src/ui/stores/__tests__/followStore.test.ts +1 -1
- package/src/ui/stores/followStore.ts +12 -14
- package/src/ui/stores/followTargetStore.ts +4 -2
- package/src/ui/utils/followErrors.ts +56 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a failed follow read or write leaves behind: a stable CODE, never text.
|
|
3
|
+
*
|
|
4
|
+
* The follow stores and hooks have no translator and must not pretend to — an
|
|
5
|
+
* English sentence written into a store reaches every locale's toast verbatim,
|
|
6
|
+
* and so does a server's `message`. They keep one of these codes instead, and
|
|
7
|
+
* the UI turns it into words in the user's language (`describeFollowError` in
|
|
8
|
+
* `components/followLabels.ts`).
|
|
9
|
+
*
|
|
10
|
+
* A code says either what the caller was doing (`read_failed`, `update_failed`,
|
|
11
|
+
* `mode_failed`) or — when the failure says more than that — why it failed,
|
|
12
|
+
* taken from the API's machine code and HTTP status rather than its message.
|
|
13
|
+
*/
|
|
14
|
+
export type FollowErrorCode =
|
|
15
|
+
/** The status could not be read. */
|
|
16
|
+
| 'read_failed'
|
|
17
|
+
/** A follow or unfollow was refused. */
|
|
18
|
+
| 'update_failed'
|
|
19
|
+
/** Switching a follow off or back on in this application was refused. */
|
|
20
|
+
| 'mode_failed'
|
|
21
|
+
/** No response arrived: the device is offline, or the request timed out. */
|
|
22
|
+
| 'offline'
|
|
23
|
+
/** The session is gone; signing in again is the only fix. */
|
|
24
|
+
| 'signed_out'
|
|
25
|
+
/** This application lacks the permission the write needs. */
|
|
26
|
+
| 'forbidden'
|
|
27
|
+
/** The target or the relationship no longer exists. */
|
|
28
|
+
| 'not_found'
|
|
29
|
+
/** Too many writes in a short window. */
|
|
30
|
+
| 'rate_limited';
|
|
31
|
+
|
|
32
|
+
/** The codes that name the caller's action rather than a cause. */
|
|
33
|
+
export type FollowActionErrorCode = 'read_failed' | 'update_failed' | 'mode_failed';
|
|
34
|
+
|
|
35
|
+
const OFFLINE_CODES = new Set(['NETWORK_ERROR', 'CONNECTION_FAILED', 'TIMEOUT']);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The code for whatever a follow request rejected with.
|
|
39
|
+
*
|
|
40
|
+
* Read structurally — every `OxyServices` call rejects with an `OxyApiError`
|
|
41
|
+
* (or an `OxyAuthenticationError`), and both carry `status` and `code` — so a
|
|
42
|
+
* second copy of `@oxy.so/core` in an app cannot defeat an `instanceof`.
|
|
43
|
+
* Anything the cause does not explain falls back to the caller's `action`.
|
|
44
|
+
*/
|
|
45
|
+
export function toFollowErrorCode(error: unknown, action: FollowActionErrorCode): FollowErrorCode {
|
|
46
|
+
const { status, code } = (error && typeof error === 'object' ? error : {}) as {
|
|
47
|
+
status?: unknown;
|
|
48
|
+
code?: unknown;
|
|
49
|
+
};
|
|
50
|
+
if (typeof code === 'string' && OFFLINE_CODES.has(code)) return 'offline';
|
|
51
|
+
if (status === 401) return 'signed_out';
|
|
52
|
+
if (status === 403) return 'forbidden';
|
|
53
|
+
if (status === 404) return 'not_found';
|
|
54
|
+
if (status === 429) return 'rate_limited';
|
|
55
|
+
return action;
|
|
56
|
+
}
|