rubik-pact 1.0.6 → 1.0.8

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.
@@ -2,6 +2,6 @@ module.exports = [
2
2
  { kubikName: 'companies.channels.conversations', apiName: 'companies/{{companyId}}/channels/{{channelId}}/conversations' },
3
3
  { kubikName: 'companies.conversations.messages', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}/messages' },
4
4
  { kubikName: 'companies.conversations.messages.attachments', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}/messages/attachments' },
5
- { kubikName: 'companies.conversationsGet', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}' }
5
+ { kubikName: 'companies.conversationsGet', apiName: 'companies/{{companyId}}/conversations/{{conversationId}}' },
6
6
  { kubikName: 'companies.companyId', apiName: 'companies/{{companyId}}' }
7
7
  ];
package/classes/Pact.js CHANGED
@@ -72,25 +72,30 @@ class Pact extends Kubik {
72
72
  if (!token) token = this.token;
73
73
  const headers = { 'X-Private-Api-Token': token };
74
74
 
75
- method = method || 'POST';
75
+ if (!method) {
76
+ if (body) method = 'POST';
77
+ else method = 'GET';
78
+ }
79
+
76
80
  if (body instanceof FormData) {
77
81
  Object.assign(headers, body.getHeaders());
78
82
  } else if (isObject(body)) {
79
83
  body = JSON.stringify(body);
80
84
  headers['Content-Type'] = 'application/json';
81
- } else {
82
- method = 'GET';
83
85
  }
84
86
 
85
- const request = await fetch(url, { method, body, headers });
86
- // console.log(await request.text());
87
- const result = await request.json();
87
+ const res = await fetch(url, { method, body, headers });
88
+ if (res.status !== 200) {
89
+ throw new Error(`Invalid status ${res.status}`);
90
+ };
91
+
92
+ const resBody = await res.json();
88
93
 
89
- if (result.status === 'errored') {
90
- throw new PactError(`${get(result, 'errors.0.code')} ${get(result, 'errors.0.description')}`);
94
+ if (resBody.status === 'errored') {
95
+ throw new PactError(`${get(resBody, 'errors.0.code')} ${get(resBody, 'errors.0.description')}`);
91
96
  }
92
97
 
93
- return result;
98
+ return resBody;
94
99
  }
95
100
 
96
101
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubik-pact",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Pact Bot Api kubik for the Rubik application system",
5
5
  "main": "classes/Pact.js",
6
6
  "author": "ns@indotech.ru",