@bravemobile/react-native-code-push 10.0.0-beta.0 → 10.0.0-beta.2

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/CodePush.js CHANGED
@@ -253,9 +253,11 @@ async function tryReportStatus(statusReport, retryOnAppResume) {
253
253
  const label = statusReport.package.label;
254
254
  if (statusReport.status === "DeploymentSucceeded") {
255
255
  log(`Reporting CodePush update success (${label})`);
256
+ sharedCodePushOptions?.onUpdateSuccess(label);
256
257
  } else {
257
258
  log(`Reporting CodePush update rollback (${label})`);
258
259
  await NativeCodePush.setLatestRollbackInfo(statusReport.package.packageHash);
260
+ sharedCodePushOptions?.onUpdateRollback(label);
259
261
  }
260
262
  }
261
263
 
@@ -464,16 +466,22 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
464
466
  }
465
467
  };
466
468
 
469
+ let remotePackageLabel;
467
470
  try {
468
471
  await CodePush.notifyApplicationReady();
469
472
 
470
473
  syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE);
471
474
  const remotePackage = await checkForUpdate(handleBinaryVersionMismatchCallback);
475
+ remotePackageLabel = remotePackage.label;
472
476
 
473
477
  const doDownloadAndInstall = async () => {
474
478
  syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE);
479
+ sharedCodePushOptions.onDownloadStart?.(remotePackageLabel);
480
+
475
481
  const localPackage = await remotePackage.download(downloadProgressCallback);
476
482
 
483
+ sharedCodePushOptions.onDownloadSuccess?.(remotePackageLabel);
484
+
477
485
  // Determine the correct install mode based on whether the update is mandatory or not.
478
486
  resolvedInstallMode = localPackage.isMandatory ? syncOptions.mandatoryInstallMode : syncOptions.installMode;
479
487
 
@@ -556,6 +564,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
556
564
  }
557
565
  } catch (error) {
558
566
  syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR);
567
+ sharedCodePushOptions?.onSyncError(remotePackageLabel ?? 'unknown', error);
559
568
  log(error.message);
560
569
  throw error;
561
570
  }
@@ -582,8 +591,24 @@ let CodePush;
582
591
  * @type {{
583
592
  * releaseHistoryFetcher: releaseHistoryFetcher | undefined,
584
593
  * setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
594
+ *
585
595
  * updateChecker: updateChecker | undefined,
586
596
  * setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
597
+ *
598
+ * onUpdateSuccess: (label: string) => void | undefined,
599
+ * setOnUpdateSuccess(onUpdateSuccessFunction: (label: string) => void | undefined): void,
600
+ *
601
+ * onUpdateRollback: (label: string) => void | undefined,
602
+ * setOnUpdateRollback(onUpdateRollbackFunction: (label: string) => void | undefined): void,
603
+ *
604
+ * onDownloadStart: (label: string) => void | undefined,
605
+ * setOnDownloadStart(onDownloadStartFunction: (label: string) => void | undefined): void,
606
+ *
607
+ * onDownloadSuccess: (label: string) => void | undefined,
608
+ * setOnDownloadSuccess(onDownloadSuccessFunction: (label: string) => void | undefined): void,
609
+ *
610
+ * onSyncError: (label: string, error: Error) => void | undefined,
611
+ * setOnSyncError(onSyncErrorFunction: (label: string, error: Error) => void | undefined): void,
587
612
  * }}
588
613
  */
589
614
  const sharedCodePushOptions = {
@@ -598,6 +623,36 @@ const sharedCodePushOptions = {
598
623
  if (typeof updateCheckerFunction !== 'function') throw new Error('Please pass a function to updateChecker');
599
624
  this.updateChecker = updateCheckerFunction;
600
625
  },
626
+ onUpdateSuccess: undefined,
627
+ setOnUpdateSuccess(onUpdateSuccessFunction) {
628
+ if (!onUpdateSuccessFunction) return;
629
+ if (typeof onUpdateSuccessFunction !== 'function') throw new Error('Please pass a function to onUpdateSuccess');
630
+ this.onUpdateSuccess = onUpdateSuccessFunction;
631
+ },
632
+ onUpdateRollback: undefined,
633
+ setOnUpdateRollback(onUpdateRollbackFunction) {
634
+ if (!onUpdateRollbackFunction) return;
635
+ if (typeof onUpdateRollbackFunction !== 'function') throw new Error('Please pass a function to onUpdateRollback');
636
+ this.onUpdateRollback = onUpdateRollbackFunction;
637
+ },
638
+ onDownloadStart: undefined,
639
+ setOnDownloadStart(onDownloadStartFunction) {
640
+ if (!onDownloadStartFunction) return;
641
+ if (typeof onDownloadStartFunction !== 'function') throw new Error('Please pass a function to onDownloadStart');
642
+ this.onDownloadStart = onDownloadStartFunction;
643
+ },
644
+ onDownloadSuccess: undefined,
645
+ setOnDownloadSuccess(onDownloadSuccessFunction) {
646
+ if (!onDownloadSuccessFunction) return;
647
+ if (typeof onDownloadSuccessFunction !== 'function') throw new Error('Please pass a function to onDownloadSuccess');
648
+ this.onDownloadSuccess = onDownloadSuccessFunction;
649
+ },
650
+ onSyncError: undefined,
651
+ setOnSyncError(onSyncErrorFunction) {
652
+ if (!onSyncErrorFunction) return;
653
+ if (typeof onSyncErrorFunction !== 'function') throw new Error('Please pass a function to onSyncError');
654
+ this.onSyncError = onSyncErrorFunction;
655
+ },
601
656
  }
602
657
 
603
658
  function codePushify(options = {}) {
@@ -627,6 +682,13 @@ function codePushify(options = {}) {
627
682
  sharedCodePushOptions.setReleaseHistoryFetcher(options.releaseHistoryFetcher);
628
683
  sharedCodePushOptions.setUpdateChecker(options.updateChecker);
629
684
 
685
+ // set telemetry callbacks
686
+ sharedCodePushOptions.setOnUpdateSuccess(options.onUpdateSuccess);
687
+ sharedCodePushOptions.setOnUpdateRollback(options.onUpdateRollback);
688
+ sharedCodePushOptions.setOnDownloadStart(options.onDownloadStart);
689
+ sharedCodePushOptions.setOnDownloadSuccess(options.onDownloadSuccess);
690
+ sharedCodePushOptions.setOnSyncError(options.onSyncError);
691
+
630
692
  const decorator = (RootComponent) => {
631
693
  class CodePushComponent extends React.Component {
632
694
  constructor(props) {
package/README.md CHANGED
@@ -217,6 +217,16 @@ export default CodePush({
217
217
  > The URL for fetching the release history should point to the resource location generated by the CLI tool.
218
218
 
219
219
 
220
+ #### 4-1. Telemetry Callbacks
221
+
222
+ Please refer to the [CodePushOptions](https://github.com/Soomgo-Mobile/react-native-code-push/blob/f0d26f7614af41c6dd4daecd9f7146e2383b2b0d/typings/react-native-code-push.d.ts#L76-L95) type for more details.
223
+ - **onUpdateSuccess:** Triggered when the update bundle is executed successfully.
224
+ - **onUpdateRollback:** Triggered when there is an issue executing the update bundle, leading to a rollback.
225
+ - **onDownloadStart:** Triggered when the bundle download begins.
226
+ - **onDownloadSuccess:** Triggered when the bundle download completes successfully.
227
+ - **onSyncError:** Triggered when an unknown error occurs during the update process. (`CodePush.SyncStatus.UNKNOWN_ERROR` status)
228
+
229
+
220
230
  ### 5. Configure the CLI Tool
221
231
 
222
232
  > [!TIP]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bravemobile/react-native-code-push",
3
- "version": "10.0.0-beta.0",
3
+ "version": "10.0.0-beta.2",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
@@ -73,6 +73,26 @@ export interface CodePushOptions extends SyncOptions {
73
73
  * @deprecated It will be removed in the next major version. Please migrate to `releaseHistoryFetcher`.
74
74
  */
75
75
  updateChecker?: (updateRequest: UpdateCheckRequest) => Promise<{ update_info: UpdateCheckResponse }>;
76
+ /**
77
+ * Callback function that is called when the update installation succeeds.
78
+ */
79
+ onUpdateSuccess?: (label: string) => void;
80
+ /**
81
+ * Callback function that is called when the update rolled back.
82
+ */
83
+ onUpdateRollback?: (label: string) => void;
84
+ /**
85
+ * Callback function that is called when download starts.
86
+ */
87
+ onDownloadStart?: (label: string) => void;
88
+ /**
89
+ * Callback function that is called when download finished successfully.
90
+ */
91
+ onDownloadSuccess?: (label: string) => void;
92
+ /**
93
+ * Callback function that is called when sync process failed.
94
+ */
95
+ onSyncError?: (label: string, error: Error) => void;
76
96
  }
77
97
 
78
98
  export interface DownloadProgress {