react-native-update-cli 2.6.0 → 2.7.1

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/api.js CHANGED
@@ -21,6 +21,9 @@ _export(exports, {
21
21
  getAllPackages: function() {
22
22
  return getAllPackages;
23
23
  },
24
+ getApiToken: function() {
25
+ return getApiToken;
26
+ },
24
27
  getSession: function() {
25
28
  return getSession;
26
29
  },
@@ -39,6 +42,9 @@ _export(exports, {
39
42
  saveSession: function() {
40
43
  return saveSession;
41
44
  },
45
+ setApiToken: function() {
46
+ return setApiToken;
47
+ },
42
48
  uploadFile: function() {
43
49
  return uploadFile;
44
50
  }
@@ -63,12 +69,25 @@ function _interop_require_default(obj) {
63
69
  const tcpPing = _util.default.promisify(_tcpping.default.ping);
64
70
  let session;
65
71
  let savedSession;
72
+ let apiToken;
66
73
  const userAgent = `react-native-update-cli/${_packagejson.default.version}`;
67
74
  const getSession = ()=>session;
75
+ const getApiToken = ()=>apiToken;
76
+ const setApiToken = (token)=>{
77
+ apiToken = token;
78
+ };
79
+ const loadApiTokenFromEnv = ()=>{
80
+ // Use CRESC_API_TOKEN for cresc, PUSHY_API_TOKEN for pushy
81
+ const envToken = _constants.IS_CRESC ? process.env.CRESC_API_TOKEN : process.env.PUSHY_API_TOKEN;
82
+ if (envToken) {
83
+ apiToken = envToken;
84
+ }
85
+ };
68
86
  const replaceSession = (newSession)=>{
69
87
  session = newSession;
70
88
  };
71
89
  const loadSession = async ()=>{
90
+ loadApiTokenFromEnv();
72
91
  if (_fs.default.existsSync(_constants.credentialFile)) {
73
92
  try {
74
93
  replaceSession(JSON.parse(_fs.default.readFileSync(_constants.credentialFile, 'utf8')));
@@ -114,24 +133,38 @@ async function query(url, options) {
114
133
  return json;
115
134
  }
116
135
  function queryWithoutBody(method) {
117
- return (api)=>query(api, {
136
+ return (api)=>{
137
+ const headers = {
138
+ 'User-Agent': userAgent
139
+ };
140
+ if (apiToken) {
141
+ headers['x-api-token'] = apiToken;
142
+ } else if (session == null ? void 0 : session.token) {
143
+ headers['X-AccessToken'] = session.token;
144
+ }
145
+ return query(api, {
118
146
  method,
119
- headers: {
120
- 'User-Agent': userAgent,
121
- 'X-AccessToken': session ? session.token : ''
122
- }
147
+ headers
123
148
  });
149
+ };
124
150
  }
125
151
  function queryWithBody(method) {
126
- return (api, body)=>query(api, {
152
+ return (api, body)=>{
153
+ const headers = {
154
+ 'User-Agent': userAgent,
155
+ 'Content-Type': 'application/json'
156
+ };
157
+ if (apiToken) {
158
+ headers['x-api-token'] = apiToken;
159
+ } else if (session == null ? void 0 : session.token) {
160
+ headers['X-AccessToken'] = session.token;
161
+ }
162
+ return query(api, {
127
163
  method,
128
- headers: {
129
- 'User-Agent': userAgent,
130
- 'Content-Type': 'application/json',
131
- 'X-AccessToken': session ? session.token : ''
132
- },
164
+ headers,
133
165
  body: JSON.stringify(body)
134
166
  });
167
+ };
135
168
  }
136
169
  const get = queryWithoutBody('GET');
137
170
  const post = queryWithBody('POST');
@@ -185,6 +218,9 @@ async function uploadFile(fn, key) {
185
218
  form.append('key', key);
186
219
  }
187
220
  form.append('file', fileStream);
221
+ // form.append('file', fileStream, {
222
+ // contentType: 'application/octet-stream',
223
+ // });
188
224
  const res = await (0, _nodefetch.default)(realUrl, {
189
225
  method: 'POST',
190
226
  body: form
package/lib/package.js CHANGED
@@ -233,7 +233,7 @@ const packageCommands = {
233
233
  const { id } = await (0, _api.post)(`/app/${appId}/package/create`, {
234
234
  name: versionName,
235
235
  hash,
236
- buildTime,
236
+ buildTime: String(buildTime),
237
237
  deps: _depversions.depVersions,
238
238
  commit: await (0, _git.getCommitInfo)()
239
239
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.6.0",
3
+ "version": "2.7.1",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/api.ts CHANGED
@@ -9,23 +9,41 @@ import tcpp from 'tcp-ping';
9
9
  import { getBaseUrl } from 'utils/http-helper';
10
10
  import packageJson from '../package.json';
11
11
  import type { Package, Session } from './types';
12
- import { credentialFile, pricingPageUrl } from './utils/constants';
12
+ import { credentialFile, pricingPageUrl, IS_CRESC } from './utils/constants';
13
13
  import { t } from './utils/i18n';
14
14
 
15
15
  const tcpPing = util.promisify(tcpp.ping);
16
16
 
17
17
  let session: Session | undefined;
18
18
  let savedSession: Session | undefined;
19
+ let apiToken: string | undefined;
19
20
 
20
21
  const userAgent = `react-native-update-cli/${packageJson.version}`;
21
22
 
22
23
  export const getSession = () => session;
23
24
 
25
+ export const getApiToken = () => apiToken;
26
+
27
+ export const setApiToken = (token: string) => {
28
+ apiToken = token;
29
+ };
30
+
31
+ const loadApiTokenFromEnv = () => {
32
+ // Use CRESC_API_TOKEN for cresc, PUSHY_API_TOKEN for pushy
33
+ const envToken = IS_CRESC
34
+ ? process.env.CRESC_API_TOKEN
35
+ : process.env.PUSHY_API_TOKEN;
36
+ if (envToken) {
37
+ apiToken = envToken;
38
+ }
39
+ };
40
+
24
41
  export const replaceSession = (newSession: { token: string }) => {
25
42
  session = newSession;
26
43
  };
27
44
 
28
45
  export const loadSession = async () => {
46
+ loadApiTokenFromEnv();
29
47
  if (fs.existsSync(credentialFile)) {
30
48
  try {
31
49
  replaceSession(JSON.parse(fs.readFileSync(credentialFile, 'utf8')));
@@ -78,27 +96,39 @@ async function query(url: string, options: fetch.RequestInit) {
78
96
  }
79
97
 
80
98
  function queryWithoutBody(method: string) {
81
- return (api: string) =>
82
- query(api, {
99
+ return (api: string) => {
100
+ const headers: Record<string, string> = {
101
+ 'User-Agent': userAgent,
102
+ };
103
+ if (apiToken) {
104
+ headers['x-api-token'] = apiToken;
105
+ } else if (session?.token) {
106
+ headers['X-AccessToken'] = session.token;
107
+ }
108
+ return query(api, {
83
109
  method,
84
- headers: {
85
- 'User-Agent': userAgent,
86
- 'X-AccessToken': session ? session.token : '',
87
- },
110
+ headers,
88
111
  });
112
+ };
89
113
  }
90
114
 
91
115
  function queryWithBody(method: string) {
92
- return (api: string, body?: Record<string, any>) =>
93
- query(api, {
116
+ return (api: string, body?: Record<string, any>) => {
117
+ const headers: Record<string, string> = {
118
+ 'User-Agent': userAgent,
119
+ 'Content-Type': 'application/json',
120
+ };
121
+ if (apiToken) {
122
+ headers['x-api-token'] = apiToken;
123
+ } else if (session?.token) {
124
+ headers['X-AccessToken'] = session.token;
125
+ }
126
+ return query(api, {
94
127
  method,
95
- headers: {
96
- 'User-Agent': userAgent,
97
- 'Content-Type': 'application/json',
98
- 'X-AccessToken': session ? session.token : '',
99
- },
128
+ headers,
100
129
  body: JSON.stringify(body),
101
130
  });
131
+ };
102
132
  }
103
133
 
104
134
  export const get = queryWithoutBody('GET');
@@ -161,6 +191,9 @@ export async function uploadFile(fn: string, key?: string) {
161
191
  form.append('key', key);
162
192
  }
163
193
  form.append('file', fileStream);
194
+ // form.append('file', fileStream, {
195
+ // contentType: 'application/octet-stream',
196
+ // });
164
197
 
165
198
  const res = await fetch(realUrl, {
166
199
  method: 'POST',
package/src/package.ts CHANGED
@@ -229,7 +229,7 @@ export const packageCommands = {
229
229
  const { id } = await post(`/app/${appId}/package/create`, {
230
230
  name: versionName,
231
231
  hash,
232
- buildTime,
232
+ buildTime: String(buildTime),
233
233
  deps: depVersions,
234
234
  commit: await getCommitInfo(),
235
235
  });