swiftyper-node 1.0.1 → 1.0.4

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/LICENSE CHANGED
@@ -1,19 +1,19 @@
1
- Copyright (C) 2021 Swiftyper (https://swiftyper.sk)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
1
+ Copyright (C) 2021 Swiftyper (https://swiftyper.sk)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md CHANGED
@@ -22,7 +22,7 @@ Pred začatím používania je nutné nastaviť API kľúč ktorý môžete spra
22
22
 
23
23
  **API kľúče sú predvolene neobmedzené.** Neobmedzené kľúče nie sú bezpečné, pretože ich môže používať ktokoľvek a odkiaľkoľvek. Pre produkčné aplikácie odporúčame nastaviť obmedzenia API kľúča nakoľko pomáhajú zabrániť neoprávnenému použitiu a vyčerpávaniu kvót. Obmedzenia určujú, ktoré webové stránky alebo IP adresy môžu používať API kľúč.
24
24
  ```js
25
- const swiftyper = require('swiftyper')('VÁŠ_API_KĽÚČ_SLUŽBY_BUSINESS');
25
+ const swiftyper = require('swiftyper-node')('VÁŠ_API_KĽÚČ_SLUŽBY_BUSINESS');
26
26
 
27
27
  swiftyper.business.query({query: 'Google Slovakia', country: 'SK'})
28
28
  .then(business => console.log(business))
@@ -39,7 +39,7 @@ swiftyper.business.detail('sk_WbilvhDEDokFTWk0FbNjeQ', function(err, result) {
39
39
  Alebo s použitím `async`/`await`:
40
40
 
41
41
  ```js
42
- import Swiftyper from 'swiftyper';
42
+ import Swiftyper from 'swiftyper-node';
43
43
  const swiftyper = new Swiftyper('VÁŠ_API_KĽÚČ_SLUŽBY_PLACES');
44
44
 
45
45
  (async () => {
package/lib/Error.js CHANGED
@@ -16,11 +16,11 @@ class SwiftyperError extends Error {
16
16
 
17
17
  static generate(rawSwiftyperError) {
18
18
  switch (rawSwiftyperError.code) {
19
- case "over_query_limit":
19
+ case 'over_query_limit':
20
20
  return new SwiftyperQuotaError(rawSwiftyperError);
21
- case "missing":
21
+ case 'missing':
22
22
  return new SwiftyperMissingError(rawSwiftyperError);
23
- case "restricted":
23
+ case 'restricted':
24
24
  return new SwiftyperRestrictedError(rawSwiftyperError);
25
25
  case 'unexpected_parameter':
26
26
  return new SwiftyperUnexpectedParameterError(rawSwiftyperError);
@@ -33,7 +33,7 @@ class SwiftyperError extends Error {
33
33
  case 'invalid_api_key':
34
34
  return new SwiftyperInvalidApiKeyError(rawSwiftyperError);
35
35
  case 'rate_limit':
36
- return new SwiftypeRateLimitError(rawSwiftyperError);
36
+ return new SwiftyperRateLimitError(rawSwiftyperError);
37
37
  default:
38
38
  return new GenericError({message: 'Unknown Error'});
39
39
  }
@@ -44,7 +44,7 @@ class GenericError extends SwiftyperError {}
44
44
 
45
45
  class SwiftyperUnexpectedParameterError extends SwiftyperError {}
46
46
 
47
- class SwiftypeRateLimitError extends SwiftyperError {}
47
+ class SwiftyperRateLimitError extends SwiftyperError {}
48
48
 
49
49
  class SwiftyperInvalidRequestError extends SwiftyperError {}
50
50
 
@@ -66,8 +66,9 @@ class SwiftyperConnectionError extends SwiftyperError {}
66
66
 
67
67
  module.exports.generate = SwiftyperError.generate;
68
68
  module.exports.SwiftyperError = SwiftyperError;
69
- module.exports.SwiftyperUnexpectedParameterError = SwiftyperUnexpectedParameterError;
70
- module.exports.SwiftypeRateLimitError = SwiftypeRateLimitError;
69
+ module.exports.SwiftyperUnexpectedParameterError =
70
+ SwiftyperUnexpectedParameterError;
71
+ module.exports.SwiftypeRateLimitError = SwiftyperRateLimitError;
71
72
  module.exports.SwiftyperInvalidApiKeyError = SwiftyperInvalidApiKeyError;
72
73
  module.exports.SwiftyperInvalidParameterError = SwiftyperInvalidParameterError;
73
74
  module.exports.SwiftyperAPIError = SwiftyperAPIError;
@@ -4,7 +4,7 @@ const utils = require('./utils');
4
4
  const makeRequest = require('./makeRequest');
5
5
 
6
6
  function swiftyperMethod(spec) {
7
- return function(...args) {
7
+ return function (...args) {
8
8
  const callback = typeof args[args.length - 1] == 'function' && args.pop();
9
9
 
10
10
  spec.urlParams = utils.extractUrlParams(
@@ -165,7 +165,8 @@ SwiftyperResource.prototype = {
165
165
  },
166
166
 
167
167
  _getSleepTimeInMS(numRetries, retryAfter = null) {
168
- const initialNetworkRetryDelay = this._swiftyper.getInitialNetworkRetryDelay();
168
+ const initialNetworkRetryDelay =
169
+ this._swiftyper.getInitialNetworkRetryDelay();
169
170
  const maxNetworkRetryDelay = this._swiftyper.getMaxNetworkRetryDelay();
170
171
 
171
172
  let sleepSeconds = Math.min(
@@ -186,16 +187,12 @@ SwiftyperResource.prototype = {
186
187
 
187
188
  _getMaxNetworkRetries(settings = {}) {
188
189
  return settings.maxNetworkRetries &&
189
- Number.isInteger(settings.maxNetworkRetries)
190
+ Number.isInteger(settings.maxNetworkRetries)
190
191
  ? settings.maxNetworkRetries
191
192
  : this._swiftyper.getMaxNetworkRetries();
192
193
  },
193
194
 
194
- _makeHeaders(
195
- contentLength,
196
- method,
197
- userSuppliedHeaders,
198
- ) {
195
+ _makeHeaders(contentLength, method, userSuppliedHeaders) {
199
196
  const defaultHeaders = {
200
197
  Accept: 'application/json',
201
198
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -214,12 +211,7 @@ SwiftyperResource.prototype = {
214
211
  data.__req = requests++;
215
212
  data.api_key = auth ? auth : this._swiftyper.getApiField('auth');
216
213
 
217
- const retryRequest = (
218
- requestFn,
219
- headers,
220
- requestRetries,
221
- retryAfter
222
- ) => {
214
+ const retryRequest = (requestFn, headers, requestRetries, retryAfter) => {
223
215
  return setTimeout(
224
216
  requestFn,
225
217
  this._getSleepTimeInMS(requestRetries, retryAfter),
@@ -230,17 +222,19 @@ SwiftyperResource.prototype = {
230
222
 
231
223
  const makeRequest = (headers, numRetries) => {
232
224
  const protocol = this._swiftyper.getApiField('protocol');
233
- const timeout = options.settings && Number.isInteger(options.settings.timeout) &&
234
- options.settings.timeout >= 0
235
- ? options.settings.timeout
236
- : this._swiftyper.getApiField('timeout');
225
+ const timeout =
226
+ options.settings &&
227
+ Number.isInteger(options.settings.timeout) &&
228
+ options.settings.timeout >= 0
229
+ ? options.settings.timeout
230
+ : this._swiftyper.getApiField('timeout');
237
231
  const isInsecureConnection = protocol === 'http';
238
- let agent = isInsecureConnection ? defaultHttpAgent : defaultHttpsAgent;
232
+ const agent = isInsecureConnection ? defaultHttpAgent : defaultHttpsAgent;
239
233
 
240
234
  const req = (isInsecureConnection ? http : https).request({
241
235
  host: host || this._swiftyper.getApiField('host'),
242
236
  port: this._swiftyper.getApiField('port'),
243
- protocol: protocol + `:`,
237
+ protocol: protocol + ':',
244
238
  path,
245
239
  method,
246
240
  agent,
@@ -285,12 +279,7 @@ SwiftyperResource.prototype = {
285
279
 
286
280
  req.on('error', (error) => {
287
281
  if (this._shouldRetry(null, requestRetries, maxRetries)) {
288
- return retryRequest(
289
- makeRequest,
290
- headers,
291
- requestRetries,
292
- null
293
- );
282
+ return retryRequest(makeRequest, headers, requestRetries, null);
294
283
  } else {
295
284
  if (error.code === 'ETIMEDOUT') {
296
285
  return callback.call(
@@ -46,6 +46,11 @@ module.exports = SwiftyperResource.extend({
46
46
  path: '/counties',
47
47
  }),
48
48
 
49
+ municipalities: swiftyperMethod({
50
+ method: 'POST',
51
+ path: '/municipalities',
52
+ }),
53
+
49
54
  detail: swiftyperMethod({
50
55
  method: 'POST',
51
56
  path: '/{place_id}',
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const SwiftyperResource = require('../SwiftyperResource');
4
+ const swiftyperMethod = SwiftyperResource.method;
5
+
6
+ module.exports = SwiftyperResource.extend({
7
+ path: 'intl/translations',
8
+
9
+ query: swiftyperMethod({
10
+ method: 'POST',
11
+ path: '/query',
12
+ }),
13
+
14
+ translate: swiftyperMethod({
15
+ method: 'POST',
16
+ path: '/submit',
17
+ }),
18
+
19
+ upload: swiftyperMethod({
20
+ method: 'POST',
21
+ path: '/upload',
22
+ }),
23
+
24
+ vote: swiftyperMethod({
25
+ method: 'POST',
26
+ path: '/vote',
27
+ }),
28
+
29
+ raw: swiftyperMethod({
30
+ method: 'GET',
31
+ path: '/raw',
32
+ }),
33
+
34
+ variationGrid: swiftyperMethod({
35
+ method: 'POST',
36
+ path: '/variationGrid',
37
+ }),
38
+ });
package/lib/resources.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = {
4
+ Translations: require('./resources/Translation'),
4
5
  Business: require('./resources/Business'),
5
6
  Places: require('./resources/Places'),
6
7
  };
package/lib/utils.js CHANGED
@@ -4,10 +4,7 @@ const qs = require('qs');
4
4
 
5
5
  const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
6
6
 
7
- const OPTIONS_KEYS = [
8
- 'maxNetworkRetries',
9
- 'timeout',
10
- ];
7
+ const OPTIONS_KEYS = ['maxNetworkRetries', 'timeout'];
11
8
 
12
9
  const DEPRECATED_OPTIONS = {};
13
10
 
@@ -28,14 +25,12 @@ const utils = (module.exports = {
28
25
  * (forming the conventional key 'parent[child]=value')
29
26
  */
30
27
  stringifyRequestData: (data) => {
31
- return (
32
- qs
33
- .stringify(data, {
34
- serializeDate: (d) => Math.floor(d.getTime() / 1000),
35
- })
36
- .replace(/%5B/g, '[')
37
- .replace(/%5D/g, ']')
38
- );
28
+ return qs
29
+ .stringify(data, {
30
+ serializeDate: (d) => Math.floor(d.getTime() / 1000),
31
+ })
32
+ .replace(/%5B/g, '[')
33
+ .replace(/%5D/g, ']');
39
34
  },
40
35
 
41
36
  /**
@@ -167,7 +162,7 @@ const utils = (module.exports = {
167
162
  const Super = this;
168
163
  const Constructor = hasOwn(sub, 'constructor')
169
164
  ? sub.constructor
170
- : function(...args) {
165
+ : function (...args) {
171
166
  Super.apply(this, args);
172
167
  };
173
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swiftyper-node",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "Swiftyper API",
5
5
  "keywords": [
6
6
  "swiftyper",