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

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 } from "./targeting";
7
8
 
8
9
  let NativeCodePush = require("react-native").NativeModules.CodePush;
9
10
  const PackageMixins = require("./package-mixins")(NativeCodePush);
@@ -618,6 +619,7 @@ if (NativeCodePush) {
618
619
  notifyAppReady: notifyApplicationReady,
619
620
  notifyApplicationReady,
620
621
  restartApp,
622
+ setTargetingInfo,
621
623
  setUpTestDependencies,
622
624
  sync,
623
625
  disallowRestart: NativeCodePush.disallow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novacraft-engineering/pulsar-code-push",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Pulsar OTA client for React Native \u2014 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",
@@ -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",
@@ -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 };