react-native-update 10.45.0 → 10.47.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,83 @@
1
+ import type { UpdateErrorCode } from './error';
2
+ import type { EventType } from './type';
3
+
4
+ // Server-side lifecycle event intake (POST {endpoint}/report/{appKey}); the
5
+ // enum must stay in sync with the server's client_event_type. Only these five
6
+ // aggregate types exist server-side — everything else stays local-only.
7
+ export type ServerEventType =
8
+ | 'download_success'
9
+ | 'download_fail'
10
+ | 'patch_fail'
11
+ | 'rollback'
12
+ | 'mark_success';
13
+
14
+ // Failure detail is stored server-side in a VARCHAR(512); stay under it.
15
+ export const MAX_DETAIL_LENGTH = 500;
16
+
17
+ export interface ServerReportPayload {
18
+ type: ServerEventType;
19
+ hash: string;
20
+ packageVersion?: string;
21
+ cInfo?: {
22
+ rnu?: string;
23
+ rn?: string;
24
+ os?: string;
25
+ uuid?: string;
26
+ };
27
+ detail?: string;
28
+ }
29
+
30
+ /**
31
+ * Maps a local report event to the server-side aggregate type, or undefined
32
+ * for events the server does not collect. A DOWNLOAD_FAILED whose underlying
33
+ * native code was PATCH_FAILED counts as patch_fail (the download itself
34
+ * worked; applying it did not), same for switch-version failures.
35
+ */
36
+ export const resolveServerEventType = (
37
+ type: EventType,
38
+ code?: UpdateErrorCode,
39
+ ): ServerEventType | undefined => {
40
+ switch (type) {
41
+ case 'downloadSuccess':
42
+ return 'download_success';
43
+ case 'errorUpdate':
44
+ return code === 'PATCH_FAILED' ? 'patch_fail' : 'download_fail';
45
+ case 'errorSwitchVersion':
46
+ return 'patch_fail';
47
+ case 'markSuccess':
48
+ return 'mark_success';
49
+ case 'rollback':
50
+ return 'rollback';
51
+ default:
52
+ return undefined;
53
+ }
54
+ };
55
+
56
+ /**
57
+ * The version hash a server event is about. Server-side rows key on it, so an
58
+ * event without one is not reportable (returns '').
59
+ */
60
+ export const resolveServerEventHash = ({
61
+ serverType,
62
+ data,
63
+ currentVersion,
64
+ }: {
65
+ serverType: ServerEventType;
66
+ data: Record<string, string | number>;
67
+ currentVersion: string;
68
+ }): string => {
69
+ if (serverType === 'rollback') {
70
+ return String(data.rolledBackVersion || '');
71
+ }
72
+ if (serverType === 'mark_success') {
73
+ return String(data.newVersion || currentVersion || '');
74
+ }
75
+ return String(data.newVersion || '');
76
+ };
77
+
78
+ export const truncateDetail = (detail?: string) => {
79
+ if (!detail) {
80
+ return undefined;
81
+ }
82
+ return detail.slice(0, MAX_DETAIL_LENGTH);
83
+ };
package/src/type.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { UpdateErrorCode } from './error';
2
+
1
3
  export interface VersionInfo {
2
4
  name: string;
3
5
  hash: string;
@@ -52,6 +54,8 @@ export type EventType =
52
54
  | 'downloadSuccess'
53
55
  | 'errorUpdate'
54
56
  | 'markSuccess'
57
+ | 'errorMarkSuccess'
58
+ | 'errorSwitchVersion'
55
59
  | 'downloadingApk'
56
60
  | 'rejectStoragePermission'
57
61
  | 'errorStoragePermission'
@@ -59,6 +63,8 @@ export type EventType =
59
63
  | 'errorInstallApk';
60
64
 
61
65
  export interface EventData {
66
+ /** Stable machine-readable error code; present on error events */
67
+ code?: UpdateErrorCode;
62
68
  currentVersion: string;
63
69
  cInfo: {
64
70
  rnu: string;
@@ -123,6 +129,12 @@ export interface ClientOptions {
123
129
  overridePackageVersion?: string;
124
130
  /** Maximum number of retry attempts for failed downloads (default: 3) */
125
131
  maxRetries?: number;
132
+ /**
133
+ * Disable reporting update lifecycle events (download/patch failures,
134
+ * rollback, mark success) to the update server. These aggregate stats power
135
+ * the version health view in the console. Default: false (enabled).
136
+ */
137
+ disableTelemetry?: boolean;
126
138
  }
127
139
 
128
140
  export interface UpdateTestPayload {