@miso.ai/server-sdk 0.6.6-beta.13 → 0.6.6-beta.14

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/cli/index.js CHANGED
@@ -47,29 +47,12 @@ const users = {
47
47
  .command(status('users')),
48
48
  };
49
49
 
50
- const experiments = {
51
- command: 'experiments',
52
- aliases: ['experiment'],
53
- description: 'Experiment commands',
54
- builder: yargs => buildForApi(yargs)
55
- .option('experiment-id', {
56
- alias: ['exp-id'],
57
- describe: 'Experiment ID for experiment API',
58
- })
59
- .command({
60
- command: 'events',
61
- builder: yargs => yargs
62
- .command(upload('experiment-events')),
63
- }),
64
- };
65
-
66
50
  yargs.build(yargs => {
67
51
  yargs
68
52
  .env('MISO')
69
53
  .command(interactions)
70
54
  .command(products)
71
55
  .command(users)
72
- .command(experiments)
73
56
  .command(transform)
74
57
  .command(mergeLocal)
75
58
  .command(search)
package/cli/utils.js CHANGED
@@ -17,7 +17,7 @@ export function buildForApi(yargs) {
17
17
  .option('param', {
18
18
  alias: ['v', 'var'],
19
19
  describe: 'Extra URL parameters',
20
- type: 'array',
20
+ type: 'string',
21
21
  coerce: _yargs.coerceToArray,
22
22
  })
23
23
  .option('debug', {
package/package.json CHANGED
@@ -16,12 +16,12 @@
16
16
  "simonpai <simon.pai@askmiso.com>"
17
17
  ],
18
18
  "dependencies": {
19
- "@miso.ai/server-commons": "0.6.6-beta.13",
19
+ "@miso.ai/server-commons": "0.6.6-beta.14",
20
20
  "axios": "^1.6.2",
21
21
  "axios-retry": "^4.5.0",
22
22
  "dotenv": "^16.0.1",
23
23
  "split2": "^4.1.0",
24
24
  "yargs": "^17.5.1"
25
25
  },
26
- "version": "0.6.6-beta.13"
26
+ "version": "0.6.6-beta.14"
27
27
  }
@@ -14,12 +14,15 @@ export async function upload(client, type, records, options = {}) {
14
14
  }
15
15
 
16
16
  async function recoverValidRecords(client, type, records, options, response) {
17
- if (!response || response.status !== 422 || !options.recoverValidRecordsOn422) {
17
+ if (!response || response.status !== 422) {
18
18
  return;
19
19
  }
20
20
  records = extractRecordsFromUploadPayload(records);
21
21
  // try to collect valid records and resend them, which should pass the validation
22
- const { groups = [], unrecognized = [] } = process422ResponseBody(records, response.data); // it takes records too
22
+ const { groups = [], unrecognized = [] } = response.issues = process422ResponseBody(records, response.data); // it takes records too
23
+ if (!options.recoverValidRecordsOn422) {
24
+ return; // still write issues to response
25
+ }
23
26
  if (groups.length === 0 || groups.length === records.length || unrecognized.length > 0) {
24
27
  // if there are unrecognized messages, it's hard to tell which records are valid
25
28
  return;
package/src/api/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import Products from './products.js';
2
2
  import Users from './users.js';
3
3
  import Interactions from './interactions.js';
4
- import Experiments from './experiments.js';
5
4
  import Ask from './ask.js';
6
5
  import Search from './search.js';
7
6
  import Recommendation from './recommendation.js';
@@ -12,7 +11,6 @@ export default class Api {
12
11
  this.products = new Products(client);
13
12
  this.users = new Users(client);
14
13
  this.interactions = new Interactions(client);
15
- this.experiments = new Experiments(client);
16
14
  this.ask = new Ask(client);
17
15
  this.search = new Search(client);
18
16
  this.recommendation = new Recommendation(client);
@@ -62,6 +62,9 @@ export default class ApiSink extends sink.BpsSink {
62
62
  if (error.response.recovered) {
63
63
  data.recovered = error.response.recovered;
64
64
  }
65
+ if (error.response.issues) {
66
+ data.issues = error.response.issues;
67
+ }
65
68
  }
66
69
 
67
70
  // keep track of service stats on successful calls
@@ -28,28 +28,12 @@ class UploadSink extends ApiSink {
28
28
 
29
29
  }
30
30
 
31
- class ExperimentEventUploadSink extends UploadSink {
32
-
33
- constructor(client, options) {
34
- super(client, { ...options, type: 'experiment-events' });
35
- }
36
-
37
- async _execute(payload) {
38
- const { experimentId } = this._options;
39
- const { data } = await this._client.api.experiments.uploadEvent(experimentId, payload);
40
- return data;
41
- }
42
-
43
- }
44
-
45
31
  export default function create(client, type, options) {
46
32
  switch (type) {
47
33
  case 'users':
48
34
  case 'products':
49
35
  case 'interactions':
50
36
  return new UploadSink(client, { ...options, type });
51
- case 'experiment-events':
52
- return new ExperimentEventUploadSink(client, options);
53
37
  default:
54
38
  throw new Error(`Unrecognized type: ${type}`);
55
39
  }
@@ -2,7 +2,6 @@ import { stream } from '@miso.ai/server-commons';
2
2
  import version from '../version.js';
3
3
  import createSink from './upload-sink.js';
4
4
  import createBuffer from './upload-buffer.js';
5
- import { process422ResponseBody } from '../api/helpers.js';
6
5
 
7
6
  export default class UploadStream extends stream.BufferedWriteStream {
8
7
 
@@ -67,13 +66,12 @@ export default class UploadStream extends stream.BufferedWriteStream {
67
66
 
68
67
  // if upload fails, emit extracted payload at response event
69
68
  if (message.event === 'response') {
70
- // TODO: we can do these near recoverValidRecords()
71
69
  const { response, payload } = args;
72
70
  if (payload) {
73
71
  output.payload = JSON.parse(payload);
74
- if (response && response.status === 422) {
75
- output.issues = process422ResponseBody(payload, response);
76
- }
72
+ }
73
+ if (response && response.issues) {
74
+ output.issues = response.issues;
77
75
  }
78
76
  }
79
77
 
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.6.6-beta.13';
1
+ export default '0.6.6-beta.14';
@@ -1,19 +0,0 @@
1
- import { buildUrl } from './helpers.js';
2
-
3
- export default class Experiments {
4
-
5
- constructor(client) {
6
- this._client = client;
7
- }
8
-
9
- async uploadEvent(experimentId, record) {
10
- // TODO: support non-string record
11
- const url = buildUrl(this._client, `experiments/${experimentId}/events`);
12
- // TODO: make content type header global
13
- const headers = { 'Content-Type': 'application/json' };
14
- const response = await this._client._axios.post(url, record, { headers });
15
- // 200 response body does not have .data layer
16
- return response.data ? response : { data: response };
17
- }
18
-
19
- }