@novacraft-engineering/pulsar-code-push 1.5.2 → 1.5.4

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
@@ -4,6 +4,7 @@ import requestFetchAdapter from "./request-fetch-adapter";
4
4
  import { AppState, Platform } from "react-native";
5
5
  import log from "./logging";
6
6
  import hoistStatics from 'hoist-non-react-statics';
7
+ import { setTargetingInfo, getTargetingInfo } from "./targeting";
7
8
 
8
9
  let NativeCodePush = require("react-native").NativeModules.CodePush;
9
10
  const PackageMixins = require("./package-mixins")(NativeCodePush);
@@ -19,6 +20,11 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
19
20
  * different from the CodePush update they have already installed.
20
21
  */
21
22
  const nativeConfig = await getConfiguration();
23
+ // The native module reports the hardware model; use it for Pulsar device-model targeting unless
24
+ // the host app already supplied one explicitly (e.g. via react-native-device-info).
25
+ if (nativeConfig && nativeConfig.deviceModel && !getTargetingInfo().deviceModel) {
26
+ setTargetingInfo({ deviceModel: nativeConfig.deviceModel });
27
+ }
22
28
  /*
23
29
  * If a deployment key was explicitly provided,
24
30
  * then let's override the one we retrieved
@@ -618,6 +624,7 @@ if (NativeCodePush) {
618
624
  notifyAppReady: notifyApplicationReady,
619
625
  notifyApplicationReady,
620
626
  restartApp,
627
+ setTargetingInfo,
621
628
  setUpTestDependencies,
622
629
  sync,
623
630
  disallowRestart: NativeCodePush.disallow,
@@ -501,6 +501,7 @@ public class CodePushNativeModule extends BaseJavaModule {
501
501
  configMap.putString("clientUniqueId", mClientUniqueId);
502
502
  configMap.putString("deploymentKey", mCodePush.getDeploymentKey());
503
503
  configMap.putString("serverUrl", mCodePush.getServerUrl());
504
+ configMap.putString("deviceModel", android.os.Build.MODEL);
504
505
 
505
506
  // The binary hash may be null in debug builds
506
507
  if (mBinaryContentsHash != null) {
@@ -16,6 +16,14 @@
16
16
  #endif
17
17
 
18
18
  #import "CodePush.h"
19
+ #import <sys/utsname.h>
20
+
21
+ // Hardware model identifier (e.g. "iPhone15,3"), used for Pulsar device-model targeting.
22
+ static NSString *CPDeviceModel(void) {
23
+ struct utsname systemInfo;
24
+ uname(&systemInfo);
25
+ return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
26
+ }
19
27
 
20
28
  @interface CodePush () <RCTBridgeModule, RCTFrameUpdateObserver>
21
29
  @end
@@ -806,7 +814,8 @@ RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
806
814
  RCT_EXPORT_METHOD(getConfiguration:(RCTPromiseResolveBlock)resolve
807
815
  rejecter:(RCTPromiseRejectBlock)reject)
808
816
  {
809
- NSDictionary *configuration = [[CodePushConfig current] configuration];
817
+ NSMutableDictionary *configuration = [[[CodePushConfig current] configuration] mutableCopy];
818
+ configuration[@"deviceModel"] = CPDeviceModel();
810
819
  NSError *error;
811
820
  if (isRunningBinaryVersion) {
812
821
  // isRunningBinaryVersion will not get set to "YES" if running against the packager.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novacraft-engineering/pulsar-code-push",
3
- "version": "1.5.2",
4
- "description": "Pulsar OTA client for React Native \u2014 over-the-air JavaScript updates. A CodePush-compatible client (RevoPush lineage) pointed at Pulsar.",
3
+ "version": "1.5.4",
4
+ "description": "Pulsar OTA client for React Native — over-the-air JavaScript updates. A CodePush-compatible client (RevoPush lineage) pointed at Pulsar.",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
7
7
  "homepage": "https://pulsar.novacraft.africa",
@@ -26,6 +26,7 @@
26
26
  "files": [
27
27
  "CodePush.js",
28
28
  "AlertAdapter.js",
29
+ "targeting.js",
29
30
  "logging.js",
30
31
  "package-mixins.js",
31
32
  "request-fetch-adapter.js",
@@ -61,4 +62,4 @@
61
62
  ]
62
63
  }
63
64
  }
64
- }
65
+ }
@@ -1,4 +1,5 @@
1
1
  const packageJson = require("./package.json");
2
+ const { getTargetingInfo } = require("./targeting");
2
3
 
3
4
  module.exports = {
4
5
  async request(verb, url, requestBody, callback) {
@@ -7,6 +8,16 @@ module.exports = {
7
8
  requestBody = null;
8
9
  }
9
10
 
11
+ // Scope the update-check to a specific device model / user id when the host app has set them.
12
+ // Only the GET update_check request is augmented; report_status is untouched.
13
+ if (verb === 0 && url.indexOf("update_check") !== -1) {
14
+ const { userId, deviceModel } = getTargetingInfo();
15
+ const extra = [];
16
+ if (deviceModel) extra.push("device_model=" + encodeURIComponent(deviceModel));
17
+ if (userId) extra.push("user_id=" + encodeURIComponent(userId));
18
+ if (extra.length) url += (url.indexOf("?") === -1 ? "?" : "&") + extra.join("&");
19
+ }
20
+
10
21
  const headers = {
11
22
  "Accept": "application/json",
12
23
  "Content-Type": "application/json",
package/targeting.js ADDED
@@ -0,0 +1,17 @@
1
+ // Optional targeting identifiers the host app can set (e.g. at login). They are appended to the
2
+ // update-check request so the server can scope a release to specific device models / user ids.
3
+ // Shared singleton: the fetch adapter reads it, CodePush.setTargetingInfo writes it.
4
+ let info = { userId: null, deviceModel: null };
5
+
6
+ function setTargetingInfo(next) {
7
+ if (!next) return info;
8
+ if (next.userId !== undefined) info.userId = next.userId == null ? null : String(next.userId);
9
+ if (next.deviceModel !== undefined) info.deviceModel = next.deviceModel == null ? null : String(next.deviceModel);
10
+ return info;
11
+ }
12
+
13
+ function getTargetingInfo() {
14
+ return info;
15
+ }
16
+
17
+ module.exports = { setTargetingInfo, getTargetingInfo };