swiftyper-node 1.0.6 → 1.0.7
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/README.md +73 -73
- package/lib/Error.js +77 -77
- package/lib/SwiftyperMethod.js +21 -21
- package/lib/SwiftyperResource.js +338 -338
- package/lib/makeRequest.js +103 -103
- package/lib/resources/Business.js +23 -23
- package/lib/resources/EmailUtil.js +13 -0
- package/lib/resources/Fbt.js +13 -13
- package/lib/resources/Phrase.js +23 -23
- package/lib/resources/Places.js +58 -58
- package/lib/resources/Translation.js +38 -38
- package/lib/resources.js +10 -9
- package/lib/swiftyper.js +159 -159
- package/lib/utils.js +272 -272
- package/package.json +36 -36
package/README.md
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
# Swiftyper Node.js Library
|
|
2
|
-
|
|
3
|
-
## Dokumentácia
|
|
4
|
-
|
|
5
|
-
[`swiftyper-node` API dokumentácia](https://developers.swiftyper.sk/docs/api/node) pre Node.js.
|
|
6
|
-
|
|
7
|
-
## Požiadavky
|
|
8
|
-
|
|
9
|
-
Node 8, 10+.
|
|
10
|
-
|
|
11
|
-
## Inštalácia
|
|
12
|
-
|
|
13
|
-
```sh
|
|
14
|
-
npm install swiftyper-node --save
|
|
15
|
-
# alebo
|
|
16
|
-
yarn add swiftyper-node
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Použitie
|
|
20
|
-
|
|
21
|
-
Pred začatím používania je nutné nastaviť API kľúč ktorý môžete spravovať cez Váš [používateľský účet](https://manage.swiftyper.sk/dashboard).
|
|
22
|
-
|
|
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
|
-
```js
|
|
25
|
-
const swiftyper = require('swiftyper-node')('VÁŠ_API_KĽÚČ_SLUŽBY_BUSINESS');
|
|
26
|
-
|
|
27
|
-
swiftyper.business.query({query: 'Google Slovakia', country: 'SK'})
|
|
28
|
-
.then(business => console.log(business))
|
|
29
|
-
.catch(error => console.error(error));
|
|
30
|
-
|
|
31
|
-
// alebo bez použitia then/catch
|
|
32
|
-
|
|
33
|
-
swiftyper.business.detail('sk_WbilvhDEDokFTWk0FbNjeQ', function(err, result) {
|
|
34
|
-
console.error(err);
|
|
35
|
-
console.log(result);
|
|
36
|
-
})
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Alebo s použitím `async`/`await`:
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
import Swiftyper from 'swiftyper-node';
|
|
43
|
-
const swiftyper = new Swiftyper('VÁŠ_API_KĽÚČ_SLUŽBY_PLACES');
|
|
44
|
-
|
|
45
|
-
(async () => {
|
|
46
|
-
const address = await swiftyper.places.detail('sk_m16ZZTrfCm2Rfnm6oN7oeA');
|
|
47
|
-
|
|
48
|
-
console.log(address);
|
|
49
|
-
})();
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Konfigurácia
|
|
53
|
-
|
|
54
|
-
### Inicializácia pomocou konfiguračného objektu
|
|
55
|
-
|
|
56
|
-
```js
|
|
57
|
-
const swiftyper = Swiftyper('VÁŠ_API_KĽÚČ', {
|
|
58
|
-
maxNetworkRetries: 1,
|
|
59
|
-
timeout: 1000,
|
|
60
|
-
host: 'api.mojafirma.sk',
|
|
61
|
-
port: 443,
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
| Nastavenie | Predvolené | Popis |
|
|
66
|
-
| ------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
67
|
-
| `maxNetworkRetries` | 0 | Počet opakovaní v prípade zlyhania požiadavky. |
|
|
68
|
-
| `timeout` | 8000 | Maximálny čas na spracovanie požiadavky uvádzaný v ms. |
|
|
69
|
-
| `host` | `'api.swiftyper.sk'` | Hostiteľ, na ktorého sa odosielajú požiadavky. |
|
|
70
|
-
| `port` | 443 | Port, na ktorý sa odosielajú požiadavky. |
|
|
71
|
-
| `protocol` | `'https'` | `'https'` alebo `'http'`. Požiadavky na naše servery musia byť smerované prostredníctvom protokolu `https`. |
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
# Swiftyper Node.js Library
|
|
2
|
+
|
|
3
|
+
## Dokumentácia
|
|
4
|
+
|
|
5
|
+
[`swiftyper-node` API dokumentácia](https://developers.swiftyper.sk/docs/api/node) pre Node.js.
|
|
6
|
+
|
|
7
|
+
## Požiadavky
|
|
8
|
+
|
|
9
|
+
Node 8, 10+.
|
|
10
|
+
|
|
11
|
+
## Inštalácia
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install swiftyper-node --save
|
|
15
|
+
# alebo
|
|
16
|
+
yarn add swiftyper-node
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Použitie
|
|
20
|
+
|
|
21
|
+
Pred začatím používania je nutné nastaviť API kľúč ktorý môžete spravovať cez Váš [používateľský účet](https://manage.swiftyper.sk/dashboard).
|
|
22
|
+
|
|
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
|
+
```js
|
|
25
|
+
const swiftyper = require('swiftyper-node')('VÁŠ_API_KĽÚČ_SLUŽBY_BUSINESS');
|
|
26
|
+
|
|
27
|
+
swiftyper.business.query({query: 'Google Slovakia', country: 'SK'})
|
|
28
|
+
.then(business => console.log(business))
|
|
29
|
+
.catch(error => console.error(error));
|
|
30
|
+
|
|
31
|
+
// alebo bez použitia then/catch
|
|
32
|
+
|
|
33
|
+
swiftyper.business.detail('sk_WbilvhDEDokFTWk0FbNjeQ', function(err, result) {
|
|
34
|
+
console.error(err);
|
|
35
|
+
console.log(result);
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Alebo s použitím `async`/`await`:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import Swiftyper from 'swiftyper-node';
|
|
43
|
+
const swiftyper = new Swiftyper('VÁŠ_API_KĽÚČ_SLUŽBY_PLACES');
|
|
44
|
+
|
|
45
|
+
(async () => {
|
|
46
|
+
const address = await swiftyper.places.detail('sk_m16ZZTrfCm2Rfnm6oN7oeA');
|
|
47
|
+
|
|
48
|
+
console.log(address);
|
|
49
|
+
})();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Konfigurácia
|
|
53
|
+
|
|
54
|
+
### Inicializácia pomocou konfiguračného objektu
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const swiftyper = Swiftyper('VÁŠ_API_KĽÚČ', {
|
|
58
|
+
maxNetworkRetries: 1,
|
|
59
|
+
timeout: 1000,
|
|
60
|
+
host: 'api.mojafirma.sk',
|
|
61
|
+
port: 443,
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Nastavenie | Predvolené | Popis |
|
|
66
|
+
| ------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `maxNetworkRetries` | 0 | Počet opakovaní v prípade zlyhania požiadavky. |
|
|
68
|
+
| `timeout` | 8000 | Maximálny čas na spracovanie požiadavky uvádzaný v ms. |
|
|
69
|
+
| `host` | `'api.swiftyper.sk'` | Hostiteľ, na ktorého sa odosielajú požiadavky. |
|
|
70
|
+
| `port` | 443 | Port, na ktorý sa odosielajú požiadavky. |
|
|
71
|
+
| `protocol` | `'https'` | `'https'` alebo `'http'`. Požiadavky na naše servery musia byť smerované prostredníctvom protokolu `https`. |
|
|
72
|
+
|
|
73
|
+
|
package/lib/Error.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class SwiftyperError extends Error {
|
|
4
|
-
constructor(raw = {}) {
|
|
5
|
-
super(raw.message);
|
|
6
|
-
this.type = this.constructor.name;
|
|
7
|
-
|
|
8
|
-
this.raw = raw;
|
|
9
|
-
this.rawType = raw.type;
|
|
10
|
-
this.code = raw.code;
|
|
11
|
-
this.param = raw.param;
|
|
12
|
-
this.headers = raw.headers;
|
|
13
|
-
this.statusCode = raw.statusCode;
|
|
14
|
-
this.message = raw.message;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static generate(rawSwiftyperError) {
|
|
18
|
-
switch (rawSwiftyperError.type) {
|
|
19
|
-
case 'over_query_limit':
|
|
20
|
-
return new SwiftyperQuotaError(rawSwiftyperError);
|
|
21
|
-
case 'missing':
|
|
22
|
-
return new SwiftyperMissingError(rawSwiftyperError);
|
|
23
|
-
case 'restricted':
|
|
24
|
-
return new SwiftyperRestrictedError(rawSwiftyperError);
|
|
25
|
-
case 'unexpected_parameter':
|
|
26
|
-
return new SwiftyperUnexpectedParameterError(rawSwiftyperError);
|
|
27
|
-
case 'invalid_request':
|
|
28
|
-
return new SwiftyperInvalidRequestError(rawSwiftyperError);
|
|
29
|
-
case 'invalid_parameter':
|
|
30
|
-
return new SwiftyperInvalidParameterError(rawSwiftyperError);
|
|
31
|
-
case 'missing_parameter':
|
|
32
|
-
return new SwiftyperMissingParameterError(rawSwiftyperError);
|
|
33
|
-
case 'invalid_api_key':
|
|
34
|
-
return new SwiftyperInvalidApiKeyError(rawSwiftyperError);
|
|
35
|
-
case 'rate_limit':
|
|
36
|
-
return new SwiftyperRateLimitError(rawSwiftyperError);
|
|
37
|
-
default:
|
|
38
|
-
return new GenericError({message: 'Unknown Error'});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class GenericError extends SwiftyperError {}
|
|
44
|
-
|
|
45
|
-
class SwiftyperUnexpectedParameterError extends SwiftyperError {}
|
|
46
|
-
|
|
47
|
-
class SwiftyperRateLimitError extends SwiftyperError {}
|
|
48
|
-
|
|
49
|
-
class SwiftyperInvalidRequestError extends SwiftyperError {}
|
|
50
|
-
|
|
51
|
-
class SwiftyperInvalidParameterError extends SwiftyperError {}
|
|
52
|
-
|
|
53
|
-
class SwiftyperMissingParameterError extends SwiftyperError {}
|
|
54
|
-
|
|
55
|
-
class SwiftyperInvalidApiKeyError extends SwiftyperError {}
|
|
56
|
-
|
|
57
|
-
class SwiftyperAPIError extends SwiftyperError {}
|
|
58
|
-
|
|
59
|
-
class SwiftyperQuotaError extends SwiftyperError {}
|
|
60
|
-
|
|
61
|
-
class SwiftyperMissingError extends SwiftyperError {}
|
|
62
|
-
|
|
63
|
-
class SwiftyperRestrictedError extends SwiftyperError {}
|
|
64
|
-
|
|
65
|
-
class SwiftyperConnectionError extends SwiftyperError {}
|
|
66
|
-
|
|
67
|
-
module.exports.generate = SwiftyperError.generate;
|
|
68
|
-
module.exports.SwiftyperError = SwiftyperError;
|
|
69
|
-
module.exports.SwiftyperUnexpectedParameterError =
|
|
70
|
-
SwiftyperUnexpectedParameterError;
|
|
71
|
-
module.exports.SwiftypeRateLimitError = SwiftyperRateLimitError;
|
|
72
|
-
module.exports.SwiftyperInvalidApiKeyError = SwiftyperInvalidApiKeyError;
|
|
73
|
-
module.exports.SwiftyperInvalidParameterError = SwiftyperInvalidParameterError;
|
|
74
|
-
module.exports.SwiftyperAPIError = SwiftyperAPIError;
|
|
75
|
-
module.exports.SwiftyperMissingError = SwiftyperMissingError;
|
|
76
|
-
module.exports.SwiftyperRestrictedError = SwiftyperRestrictedError;
|
|
77
|
-
module.exports.SwiftyperConnectionError = SwiftyperConnectionError;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class SwiftyperError extends Error {
|
|
4
|
+
constructor(raw = {}) {
|
|
5
|
+
super(raw.message);
|
|
6
|
+
this.type = this.constructor.name;
|
|
7
|
+
|
|
8
|
+
this.raw = raw;
|
|
9
|
+
this.rawType = raw.type;
|
|
10
|
+
this.code = raw.code;
|
|
11
|
+
this.param = raw.param;
|
|
12
|
+
this.headers = raw.headers;
|
|
13
|
+
this.statusCode = raw.statusCode;
|
|
14
|
+
this.message = raw.message;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static generate(rawSwiftyperError) {
|
|
18
|
+
switch (rawSwiftyperError.type) {
|
|
19
|
+
case 'over_query_limit':
|
|
20
|
+
return new SwiftyperQuotaError(rawSwiftyperError);
|
|
21
|
+
case 'missing':
|
|
22
|
+
return new SwiftyperMissingError(rawSwiftyperError);
|
|
23
|
+
case 'restricted':
|
|
24
|
+
return new SwiftyperRestrictedError(rawSwiftyperError);
|
|
25
|
+
case 'unexpected_parameter':
|
|
26
|
+
return new SwiftyperUnexpectedParameterError(rawSwiftyperError);
|
|
27
|
+
case 'invalid_request':
|
|
28
|
+
return new SwiftyperInvalidRequestError(rawSwiftyperError);
|
|
29
|
+
case 'invalid_parameter':
|
|
30
|
+
return new SwiftyperInvalidParameterError(rawSwiftyperError);
|
|
31
|
+
case 'missing_parameter':
|
|
32
|
+
return new SwiftyperMissingParameterError(rawSwiftyperError);
|
|
33
|
+
case 'invalid_api_key':
|
|
34
|
+
return new SwiftyperInvalidApiKeyError(rawSwiftyperError);
|
|
35
|
+
case 'rate_limit':
|
|
36
|
+
return new SwiftyperRateLimitError(rawSwiftyperError);
|
|
37
|
+
default:
|
|
38
|
+
return new GenericError({message: 'Unknown Error'});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class GenericError extends SwiftyperError {}
|
|
44
|
+
|
|
45
|
+
class SwiftyperUnexpectedParameterError extends SwiftyperError {}
|
|
46
|
+
|
|
47
|
+
class SwiftyperRateLimitError extends SwiftyperError {}
|
|
48
|
+
|
|
49
|
+
class SwiftyperInvalidRequestError extends SwiftyperError {}
|
|
50
|
+
|
|
51
|
+
class SwiftyperInvalidParameterError extends SwiftyperError {}
|
|
52
|
+
|
|
53
|
+
class SwiftyperMissingParameterError extends SwiftyperError {}
|
|
54
|
+
|
|
55
|
+
class SwiftyperInvalidApiKeyError extends SwiftyperError {}
|
|
56
|
+
|
|
57
|
+
class SwiftyperAPIError extends SwiftyperError {}
|
|
58
|
+
|
|
59
|
+
class SwiftyperQuotaError extends SwiftyperError {}
|
|
60
|
+
|
|
61
|
+
class SwiftyperMissingError extends SwiftyperError {}
|
|
62
|
+
|
|
63
|
+
class SwiftyperRestrictedError extends SwiftyperError {}
|
|
64
|
+
|
|
65
|
+
class SwiftyperConnectionError extends SwiftyperError {}
|
|
66
|
+
|
|
67
|
+
module.exports.generate = SwiftyperError.generate;
|
|
68
|
+
module.exports.SwiftyperError = SwiftyperError;
|
|
69
|
+
module.exports.SwiftyperUnexpectedParameterError =
|
|
70
|
+
SwiftyperUnexpectedParameterError;
|
|
71
|
+
module.exports.SwiftypeRateLimitError = SwiftyperRateLimitError;
|
|
72
|
+
module.exports.SwiftyperInvalidApiKeyError = SwiftyperInvalidApiKeyError;
|
|
73
|
+
module.exports.SwiftyperInvalidParameterError = SwiftyperInvalidParameterError;
|
|
74
|
+
module.exports.SwiftyperAPIError = SwiftyperAPIError;
|
|
75
|
+
module.exports.SwiftyperMissingError = SwiftyperMissingError;
|
|
76
|
+
module.exports.SwiftyperRestrictedError = SwiftyperRestrictedError;
|
|
77
|
+
module.exports.SwiftyperConnectionError = SwiftyperConnectionError;
|
package/lib/SwiftyperMethod.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const utils = require('./utils');
|
|
4
|
-
const makeRequest = require('./makeRequest');
|
|
5
|
-
|
|
6
|
-
function swiftyperMethod(spec) {
|
|
7
|
-
return function (...args) {
|
|
8
|
-
const callback = typeof args[args.length - 1] == 'function' && args.pop();
|
|
9
|
-
|
|
10
|
-
spec.urlParams = utils.extractUrlParams(
|
|
11
|
-
this.createResourcePathWithSymbols(spec.path || '')
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
return utils.callbackifyPromiseWithTimeout(
|
|
15
|
-
makeRequest(this, args, spec, {}),
|
|
16
|
-
callback
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = swiftyperMethod;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const utils = require('./utils');
|
|
4
|
+
const makeRequest = require('./makeRequest');
|
|
5
|
+
|
|
6
|
+
function swiftyperMethod(spec) {
|
|
7
|
+
return function (...args) {
|
|
8
|
+
const callback = typeof args[args.length - 1] == 'function' && args.pop();
|
|
9
|
+
|
|
10
|
+
spec.urlParams = utils.extractUrlParams(
|
|
11
|
+
this.createResourcePathWithSymbols(spec.path || '')
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return utils.callbackifyPromiseWithTimeout(
|
|
15
|
+
makeRequest(this, args, spec, {}),
|
|
16
|
+
callback
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = swiftyperMethod;
|