varsnap 1.6.7 → 1.7.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,35 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 1.7.0 (2022-01-03)
5
+ ------------------
6
+
7
+ - Send git branch when generating trial groups
8
+ - Update dependencies
9
+ - Refactors
10
+
11
+
12
+ 1.6.10 (2022-01-01)
13
+ -------------------
14
+
15
+ - Update dependencies
16
+ - Simplify testing
17
+
18
+
19
+ 1.6.9 (2021-09-11)
20
+ ------------------
21
+
22
+ - Update dependencies
23
+
24
+
25
+ 1.6.8 (2021-07-25)
26
+ ------------------
27
+
28
+ - Remove "v" prefix from versions
29
+ - Optimize dependency installation during CI
30
+ - Update dependencies
31
+
32
+
4
33
  1.6.7 (2021-05-22)
5
34
  ------------------
6
35
 
package/README.md CHANGED
@@ -122,6 +122,5 @@ Client Development
122
122
  3. Update package.json version and run `npm install`
123
123
  4. Update `.uglify.json` and `.uglify.min.json`
124
124
  5. Run `npm run package`
125
- 6. Git commit and tag
126
- 7. `npm publish`
125
+ 6. Git commit, tag, and push
127
126
  8. Upload `dist/*` to https://github.com/albertyw/varsnap.js/releases
@@ -1,16 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  import querystring = require('querystring');
3
- export declare const version = "v1.6.7";
3
+ export declare const version = "1.7.0";
4
4
  export declare const clientName: string;
5
5
  export interface Config {
6
6
  varsnap: boolean;
7
7
  env: string;
8
+ branch: string;
8
9
  producerToken?: string;
9
10
  consumerToken?: string;
10
11
  logger?: Logger;
11
12
  }
12
13
  declare type ConfigKeys = keyof Config;
13
- declare type rawJSONObject = ConsumeSnapResponse | ProduceTrialResponse | TrialGroupResponse | querystring.ParsedUrlQueryInput;
14
+ declare type rawJSONObject = ConsumeSnapResponse | ProduceTrialResponse | TrialGroupRequest | TrialGroupResponse | querystring.ParsedUrlQueryInput;
14
15
  export interface Logger {
15
16
  debug(s: string): void;
16
17
  log(s: string): void;
@@ -29,6 +30,8 @@ export declare class Util {
29
30
  static getProducers(): Producer[];
30
31
  static getConsumers(): Consumer[];
31
32
  static limitString(x: TargetFunctionInput[] | TargetFunctionOutput): string;
33
+ static isNode(): boolean;
34
+ static getBranch(config: Config): Promise<string>;
32
35
  }
33
36
  export declare class Producer {
34
37
  targetFunc: TargetFunction;
@@ -84,6 +87,11 @@ export declare namespace varsnap {
84
87
  var version: string;
85
88
  var runTests: typeof import("./core").runTests;
86
89
  }
90
+ interface TrialGroupRequest {
91
+ branch: string;
92
+ consumer_token: string;
93
+ client: string;
94
+ }
87
95
  interface TrialGroupResponse {
88
96
  status: string;
89
97
  project_id: string;
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runTests = exports.varsnap = exports.Consumer = exports.Producer = exports.Util = exports.clientName = exports.version = void 0;
4
4
  const axios_1 = require("axios");
5
5
  const querystring = require("querystring");
6
+ const child_process_1 = require("child_process");
6
7
  const produceURL = 'https://www.varsnap.com/api/snap/produce/';
7
8
  const consumeURL = 'https://www.varsnap.com/api/snap/consume/';
8
9
  const produceTrialURL = 'https://www.varsnap.com/api/trial/produce/';
9
10
  const trialGroupURL = 'https://www.varsnap.com/api/trial_group/';
10
- exports.version = 'v1.6.7';
11
+ exports.version = '1.7.0';
11
12
  exports.clientName = 'javascript.' + exports.version;
12
13
  const defaultConfig = {
13
14
  varsnap: true,
14
15
  env: 'development',
16
+ branch: '',
15
17
  producerToken: '',
16
18
  consumerToken: '',
17
19
  logger: console, // eslint-disable-line no-console
@@ -37,7 +39,7 @@ class Util {
37
39
  }
38
40
  config[configKey] = configValue;
39
41
  }
40
- if (configKey === 'env' || configKey === 'producerToken' || configKey === 'consumerToken') {
42
+ if (configKey === 'env' || configKey === 'producerToken' || configKey === 'consumerToken' || configKey === 'branch') {
41
43
  config[configKey] = configValue;
42
44
  }
43
45
  if (configKey === 'logger') {
@@ -70,10 +72,10 @@ class Util {
70
72
  data: querystring.stringify(requestData),
71
73
  responseType: 'json',
72
74
  };
73
- if (typeof process === 'object' && typeof window === 'undefined') {
75
+ if (Util.isNode() && options.headers) {
74
76
  options.headers['User-Agent'] = 'varsnap.js';
75
77
  }
76
- const ajaxPromise = axios_1.default(options).then((response) => {
78
+ const ajaxPromise = (0, axios_1.default)(options).then((response) => {
77
79
  return response.data;
78
80
  });
79
81
  return ajaxPromise;
@@ -114,6 +116,36 @@ class Util {
114
116
  }
115
117
  return limitedString.substring(0, 30 - ellipsis.length) + ellipsis;
116
118
  }
119
+ static isNode() {
120
+ if (typeof process !== 'object') {
121
+ return false;
122
+ }
123
+ if (typeof window !== 'undefined') {
124
+ return false;
125
+ }
126
+ return true;
127
+ }
128
+ static getBranch(config) {
129
+ const configBranch = Util.getConfig(config, 'branch');
130
+ if (configBranch) {
131
+ const configPromise = new Promise((resolve) => {
132
+ return resolve(configBranch);
133
+ });
134
+ return configPromise;
135
+ }
136
+ if (!Util.isNode()) {
137
+ const defaultPromise = new Promise((resolve) => {
138
+ return resolve('');
139
+ });
140
+ return defaultPromise;
141
+ }
142
+ const command = 'git rev-parse --abbrev-ref HEAD';
143
+ return new Promise((resolve) => {
144
+ (0, child_process_1.exec)(command, (err, stdout, stderr) => {
145
+ return resolve(stdout);
146
+ });
147
+ });
148
+ }
117
149
  }
118
150
  exports.Util = Util;
119
151
  class Producer {
@@ -346,11 +378,19 @@ varsnap.reset = function reset() {
346
378
  };
347
379
  varsnap.version = exports.version;
348
380
  function getTrialGroup(consumerConfig) {
349
- const data = {
350
- 'consumer_token': Util.getConfig(consumerConfig, 'consumerToken'),
351
- 'client': exports.clientName,
352
- };
353
- const ajax = Util.ajax(trialGroupURL, data);
381
+ const getBranch = Util.getBranch(consumerConfig);
382
+ const getRequestConfig = getBranch.then((branch) => {
383
+ const data = {
384
+ 'branch': branch,
385
+ 'consumer_token': Util.getConfig(consumerConfig, 'consumerToken'),
386
+ 'client': exports.clientName,
387
+ };
388
+ return data;
389
+ });
390
+ const ajax = getRequestConfig.then((data) => {
391
+ const raw = data;
392
+ return Util.ajax(trialGroupURL, raw);
393
+ });
354
394
  const trialGroup = ajax.then((rawResponse) => {
355
395
  const response = rawResponse;
356
396
  return response;