greip.js 2.4.7 → 2.4.9

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.
Files changed (3) hide show
  1. package/README.md +167 -205
  2. package/lib/util.js +3 -3
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -26,33 +26,37 @@ The official Javascript package of Greip API
26
26
 
27
27
  ## Installation
28
28
 
29
- ### 1. For React.js, React Native, etc:
29
+ You can install the Greip JavaScript package using npm, yarn, or via CDN.
30
30
 
31
- ```
32
- npm i greip.js --save
31
+ ### Using npm
32
+
33
+ ```bash
34
+ npm install greip.js --save
33
35
  ```
34
36
 
35
- or
37
+ ### Using yarn
36
38
 
37
- ```
39
+ ```bash
38
40
  yarn add greip.js
39
41
  ```
40
42
 
41
- ### 2. For CDN Integration
43
+ ### CDN Integration
44
+
45
+ Add the following script tag to your HTML file:
42
46
 
43
47
  ```html
44
48
  <script src="https://cdn.jsdelivr.net/gh/Greipio/javascript/greip.bundle.js" type="text/javascript"></script>
45
49
  ```
46
50
 
47
- ### 3. For Node.js
51
+ > **Note:** For Node.js environments, please use our [Node.js library](https://github.com/Greipio/node).
48
52
 
49
- Please use our [Node.js library](https://github.com/Greipio/node) instead.
53
+ ---
50
54
 
51
- ## Initializing the Greip object
55
+ ## Getting Started
52
56
 
53
- There're two different ways to initialize the Greip object, let's dive into this:
57
+ ### Importing Greip Methods
54
58
 
55
- ### 1. For React.js, React Native, etc:
59
+ #### For React.js, React Native, etc.
56
60
 
57
61
  ```javascript
58
62
  import {
@@ -70,165 +74,178 @@ import {
70
74
  } from 'greip.js';
71
75
  ```
72
76
 
73
- ### 2. CDN Integration
74
-
75
- In CDN integration, you already have `Greip` as a global variable initialized automatically when the page loads.
77
+ #### For CDN Integration
76
78
 
77
- You can start using it directly as follows:
79
+ The `Greip` object is available globally. You can use its methods directly:
78
80
 
79
81
  ```javascript
80
82
  Greip.GeoIP({
81
83
  key: 'your-api-key',
82
- // other options here
84
+ // other options
83
85
  }).then((response) => {
84
86
  console.log(response);
85
87
  });
86
88
  ```
87
89
 
88
- ## Usage
90
+ ---
91
+
92
+ ## Usage Examples
93
+
94
+ Below are examples for each available method. All methods return Promises.
89
95
 
90
- Here's how you use the API Methods:
96
+ ### 1. IP Geolocation
91
97
 
92
- ### 1. IP Geolocation Method
98
+ **Options:**
93
99
 
94
- Use this method to retrieve the IP address of the visitor/user with its full information.
100
+ | Option | Type | Required | Description |
101
+ | ------ | -------- | -------- | ----------------------------------------------------------------- |
102
+ | key | string | Yes | Your API key |
103
+ | params | string[] | No | Modules: `location`, `security`, `timezone`, `currency`, `device` |
104
+ | format | string | No | Response format: `JSON`, `XML`, `CSV`, `Newline` |
105
+ | lang | string | No | Language: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH`, `RU` |
106
+ | mode | string | No | `live` (default) or `test` |
95
107
 
96
108
  ```javascript
97
- await GeoIP({
98
- key: 'your-api-key',
99
- })
100
- .then((res: any) => {
101
- console.log(res.data); // Log Response
102
- })
103
- .catch((error: any) => {
104
- console.log(error);
105
- });
109
+ await GeoIP({ key: 'your-api-key' })
110
+ .then((res) => console.log(res.data))
111
+ .catch((error) => console.error(error));
106
112
  ```
107
113
 
108
- ### 2. IP Threats Method
114
+ ### 2. IP Threats
109
115
 
110
- Use this method to retrieve threat intelligence information associated with a given IP address.
116
+ **Options:**
117
+
118
+ | Option | Type | Required | Description |
119
+ | ------ | ------ | -------- | ------------------------------------------------ |
120
+ | key | string | Yes | Your API key |
121
+ | ip | string | Yes | IP address to check |
122
+ | format | string | No | Response format: `JSON`, `XML`, `CSV`, `Newline` |
123
+ | mode | string | No | `live` (default) or `test` |
111
124
 
112
125
  ```javascript
113
- await Threats({
114
- key: 'your-api-key',
115
- ip: '1.1.1.1',
116
- })
117
- .then((res: any) => {
118
- console.log(res.data); // Log Response
119
- })
120
- .catch((error: any) => {
121
- console.log(error);
122
- });
126
+ await Threats({ key: 'your-api-key', ip: '1.1.1.1' })
127
+ .then((res) => console.log(res.data))
128
+ .catch((error) => console.error(error));
123
129
  ```
124
130
 
125
- ### 3. IP Lookup Method
131
+ ### 3. IP Lookup
126
132
 
127
- Use this method to retrieve the information of a given IP address.
133
+ **Options:**
134
+
135
+ | Option | Type | Required | Description |
136
+ | ------ | -------- | -------- | ----------------------------------------------------------------- |
137
+ | key | string | Yes | Your API key |
138
+ | ip | string | Yes | IP address to lookup |
139
+ | params | string[] | No | Modules: `location`, `security`, `timezone`, `currency`, `device` |
140
+ | format | string | No | Response format: `JSON`, `XML`, `CSV`, `Newline` |
141
+ | lang | string | No | Language: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH`, `RU` |
142
+ | mode | string | No | `live` (default) or `test` |
128
143
 
129
144
  ```javascript
130
- await Lookup({
131
- key: 'your-api-key',
132
- ip: '1.1.1.1',
133
- })
134
- .then((res: any) => {
135
- console.log(res.data); // Log Response
136
- })
137
- .catch((error: any) => {
138
- console.log(error);
139
- });
145
+ await Lookup({ key: 'your-api-key', ip: '1.1.1.1' })
146
+ .then((res) => console.log(res.data))
147
+ .catch((error) => console.error(error));
140
148
  ```
141
149
 
142
- ### 4. Bulk IP Lookup Method
150
+ ### 4. Bulk IP Lookup
151
+
152
+ **Options:**
143
153
 
144
- You can use this method to retrieve the information of multiple IP addresses (no need to use the `Lookup` method inside a loop).
154
+ | Option | Type | Required | Description |
155
+ | ------ | -------- | -------- | ----------------------------------------------------------------- |
156
+ | key | string | Yes | Your API key |
157
+ | ips | string[] | Yes | Array of IP addresses |
158
+ | params | string[] | No | Modules: `location`, `security`, `timezone`, `currency`, `device` |
159
+ | format | string | No | Response format: `JSON`, `XML`, `CSV`, `Newline` |
160
+ | lang | string | No | Language: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH`, `RU` |
161
+ | mode | string | No | `live` (default) or `test` |
145
162
 
146
163
  ```javascript
147
- await BulkLookup({
148
- key: 'your-api-key',
149
- ips: ['1.1.1.1', '2.2.2.2'],
150
- })
151
- .then((res: any) => {
152
- console.log(res.data); // Log Response
153
- })
154
- .catch((error: any) => {
155
- console.log(error);
156
- });
164
+ await BulkLookup({ key: 'your-api-key', ips: ['1.1.1.1', '2.2.2.2'] })
165
+ .then((res) => console.log(res.data))
166
+ .catch((error) => console.error(error));
157
167
  ```
158
168
 
159
- ### 5. ASN Lookup Method
169
+ ### 5. ASN Lookup
170
+
171
+ **Options:**
160
172
 
161
- In this method, Greip will help you lookup any given AS Number and returning all data related to it, like: name, org (the organization name), country, domain, email, phone, totalIPs, list of all routes (v4 & v6) related the given AS Number, etc.
173
+ | Option | Type | Required | Description |
174
+ | ------ | ------ | -------- | -------------------------- |
175
+ | key | string | Yes | Your API key |
176
+ | asn | string | Yes | ASN to lookup |
177
+ | mode | string | No | `live` (default) or `test` |
162
178
 
163
179
  ```javascript
164
- await ASN({
165
- key: 'your-api-key',
166
- asn: 'AS01',
167
- })
168
- .then((res: any) => {
169
- console.log(res.data); // Log Response
170
- })
171
- .catch((error: any) => {
172
- console.log(error);
173
- });
180
+ await ASN({ key: 'your-api-key', asn: 'AS01' })
181
+ .then((res) => console.log(res.data))
182
+ .catch((error) => console.error(error));
174
183
  ```
175
184
 
176
- ### 6. Profanity Detection Method
185
+ ### 6. Profanity Detection
186
+
187
+ **Options:**
177
188
 
178
- This method can be used to detect abuse of your website/app. It’s a great way to know more about your user inputs and whether they contain profanity (bad words) or not before releasing them to the public.
189
+ | Option | Type | Required | Description |
190
+ | ------ | -------- | -------- | -------------------------------------------------------- |
191
+ | key | string | Yes | Your API key |
192
+ | text | string | Yes | Text to check |
193
+ | params | string[] | No | Additional params (see docs) |
194
+ | format | string | No | Response format: `JSON`, `XML`, `CSV` |
195
+ | lang | string | No | Language: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH`, `RU` |
196
+ | mode | string | No | `live` (default) or `test` |
179
197
 
180
198
  ```javascript
181
- await BadWord({
182
- key: 'your-api-key',
183
- text: 'This is just normal sample text.',
184
- })
185
- .then((res: any) => {
186
- console.log(res.data); // Log Response
187
- })
188
- .catch((error: any) => {
189
- console.log(error);
190
- });
199
+ await BadWord({ key: 'your-api-key', text: 'Sample text.' })
200
+ .then((res) => console.log(res.data))
201
+ .catch((error) => console.error(error));
191
202
  ```
192
203
 
193
- ### 7. Country Lookup Method
204
+ ### 7. Country Lookup
205
+
206
+ **Options:**
194
207
 
195
- This method can help you retrieve information of the given country.
208
+ | Option | Type | Required | Description |
209
+ | ----------- | -------- | -------- | -------------------------------------------------------- |
210
+ | key | string | Yes | Your API key |
211
+ | countryCode | string | Yes | ISO 3166-1 alpha-2 country code |
212
+ | params | string[] | No | Modules: `language`, `flag`, `currency`, `timezone` |
213
+ | format | string | No | Response format: `JSON`, `XML`, `CSV`, `Newline` |
214
+ | lang | string | No | Language: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH`, `RU` |
215
+ | mode | string | No | `live` (default) or `test` |
196
216
 
197
217
  ```javascript
198
- await Country({
199
- key: 'your-api-key',
200
- countryCode: 'SA',
201
- })
202
- .then((res: any) => {
203
- console.log(res.data); // Log Response
204
- })
205
- .catch((error: any) => {
206
- console.log(error);
207
- });
218
+ await Country({ key: 'your-api-key', countryCode: 'SA' })
219
+ .then((res) => console.log(res.data))
220
+ .catch((error) => console.error(error));
208
221
  ```
209
222
 
210
- ### 8. Email Validation Method
223
+ ### 8. Email Validation
211
224
 
212
- This method provides an additional layer of validation for your system. While validating email syntax is important, it is not sufficient.
225
+ **Options:**
213
226
 
214
- This method goes beyond syntax validation by checking the domain’s validity, the availability of the Mail Service, detecting Disposable Email (Temporary Emails), etc. By utilising this method, you can ensure a more thorough validation process for email addresses.
227
+ | Option | Type | Required | Description |
228
+ | ------ | ------ | -------- | -------------------------- |
229
+ | key | string | Yes | Your API key |
230
+ | email | string | Yes | Email to validate |
231
+ | mode | string | No | `live` (default) or `test` |
215
232
 
216
233
  ```javascript
217
- await EmailValidation({
218
- key: 'your-api-key',
219
- email: 'name@domain.com',
220
- })
221
- .then((res: any) => {
222
- console.log(res.data); // Log Response
223
- })
224
- .catch((error: any) => {
225
- console.log(error);
226
- });
234
+ await EmailValidation({ key: 'your-api-key', email: 'name@domain.com' })
235
+ .then((res) => console.log(res.data))
236
+ .catch((error) => console.error(error));
227
237
  ```
228
238
 
229
- ### 9. Phone Validation Method
239
+ ### 9. Phone Validation
240
+
241
+ **Options:**
230
242
 
231
- This method can be used as an extra-layer of your system for validating phone numbers. It validates phone number syntax and valid-possibility.
243
+ | Option | Type | Required | Description |
244
+ | ----------- | ------ | -------- | -------------------------- |
245
+ | key | string | Yes | Your API key |
246
+ | phone | string | Yes | Phone number |
247
+ | countryCode | string | Yes | Country code (ISO) |
248
+ | mode | string | No | `live` (default) or `test` |
232
249
 
233
250
  ```javascript
234
251
  await PhoneValidation({
@@ -236,117 +253,62 @@ await PhoneValidation({
236
253
  phone: '123123123',
237
254
  countryCode: 'US',
238
255
  })
239
- .then((res: any) => {
240
- console.log(res.data); // Log Response
241
- })
242
- .catch((error: any) => {
243
- console.log(error);
244
- });
256
+ .then((res) => console.log(res.data))
257
+ .catch((error) => console.error(error));
245
258
  ```
246
259
 
247
- ### 10. Payment Fraud Prevention Method
260
+ ### 10. Payment Fraud Prevention
248
261
 
249
- Prevent financial losses by deploying AI-Powered modules.
262
+ **Options:**
263
+
264
+ | Option | Type | Required | Description |
265
+ | ------ | ------ | -------- | ----------------------------------------------------------------------------------------------------------------- |
266
+ | key | string | Yes | Your API key |
267
+ | data | object | Yes | Transaction data ([see all fields](https://docs.greip.io/api-reference/endpoint/scoring/payment#body-parameters)) |
268
+ | mode | string | No | `live` (default) or `test` |
250
269
 
251
270
  ```javascript
252
271
  await PaymentFraud({
253
272
  key: 'your-api-key',
254
273
  data: {
255
- action: 'purchase',
256
- website_domain: '',
257
- website_name: '',
258
- merchant_id: 21,
259
- shipment_id: 1,
260
- transaction_id: 100,
261
- transaction_amount: 1000000,
262
- transaction_currency: 'GBP',
263
- cart_items: {
264
- item_id: 1,
265
- item_name: 'Product name',
266
- item_quantity: 1,
267
- item_price: '1100.55',
268
- item_category_id: 1,
269
- },
270
- isDigitalProducts: true,
271
- coupon: 'ASDF',
272
- customer_id: 1,
273
- customer_firstname: 'First',
274
- customer_lastname: 'Last',
275
- customer_pob: 'London',
276
- customer_ip: '1.1.1.1',
277
- customer_country: 'GB',
278
- customer_region: 'London',
279
- customer_city: 'London',
280
- customer_zip: 'NW10 7PQ',
281
- customer_street: '7 Coronation Road',
282
- customer_street2: '',
283
- customer_latitude: 0.123,
284
- customer_longitude: 0.123,
285
- customer_device_id: 'UNIQUE_DEVICE_ID',
286
- customer_phone: '000000000',
287
- customer_registration_date: 1677554670,
288
- customer_balance: '1000.00',
289
- customer_dob: '1997-19-05',
290
- customer_email: 'name@domain.com',
291
- customer_2fa: true,
292
- customer_useragent: 'Mozill almaden sdfwer',
293
- shipping_country: 'GB',
294
- shipping_region: 'London',
295
- shipping_city: 'London',
296
- shipping_zip: 'NW10 7PQ',
297
- shipping_street: '7 Coronation Road',
298
- shipping_street2: '',
299
- shipping_latitude: 0.123,
300
- shipping_longitude: 0.123,
301
- billing_country: 'GB',
302
- billing_region: 'London',
303
- billing_city: 'London',
304
- billing_zip: 'NW10 7PQ',
305
- billing_street: '7 Coronation Road',
306
- billing_street2: '',
307
- billing_latitude: 0.123,
308
- billing_longitude: 0.123,
309
- payment_type: 'applepay',
310
- card_name: 'First Last',
311
- card_number: '1234XXXXXXXX1234',
312
- card_expiry: '29/05',
313
- cvv_result: true,
274
+ // ...transaction and customer details...
314
275
  },
315
276
  })
316
- .then((res: any) => {
317
- console.log(res.data); // Log Response
318
- })
319
- .catch((error: any) => {
320
- console.log(error);
321
- });
277
+ .then((res) => console.log(res.data))
278
+ .catch((error) => console.error(error));
322
279
  ```
323
280
 
324
- ### 11. IBAN Validation Method
281
+ ### 11. IBAN Validation
282
+
283
+ **Options:**
325
284
 
326
- This method allows you to validate International Bank Account Numbers (IBANs) and retrieve additional information about the country associated with the IBAN.
285
+ | Option | Type | Required | Description |
286
+ | ------ | ------ | -------- | -------------------------- |
287
+ | key | string | Yes | Your API key |
288
+ | iban | string | Yes | IBAN to validate |
289
+ | mode | string | No | `live` (default) or `test` |
327
290
 
328
291
  ```javascript
329
- await IBANValidation({
330
- key: 'your-api-key',
331
- iban: 'BY86AKBB10100000002966000000',
332
- })
333
- .then((res: any) => {
334
- console.log(res); // Log Response
335
- })
336
- .catch((error: any) => {
337
- console.log(error);
338
- });
292
+ await IBANValidation({ key: 'your-api-key', iban: 'BY86AKBB10100000002966000000' })
293
+ .then((res) => console.log(res))
294
+ .catch((error) => console.error(error));
339
295
  ```
340
296
 
341
- ## Options, Methods and More
297
+ ---
298
+
299
+ ## Documentation
300
+
301
+ For detailed documentation, options, and advanced usage, please visit our [official documentation](https://docs.greip.io/).
342
302
 
343
- You can find the full guide of this package by visiting our [documentation page](https://docs.greip.io/).
303
+ ---
344
304
 
345
305
  ## Credits
346
306
 
347
307
  - [Greip Developers](https://greip.io)
348
308
  - [All Contributors](https://github.com/Greipio/javascript/graphs/contributors)
349
309
 
350
- ## Repo Activity
310
+ ---
311
+
312
+ ## Repository Activity
351
313
 
352
- ![Alt](https://repobeats.axiom.co/api/embed/db51cf11f87d8fdca78afb81e7711761affa247f.svg "Repobeats analytics image")
314
+ ![Alt](https://repobeats.axiom.co/api/embed/db51cf11f87d8fdca78afb81e7711761affa247f.svg 'Repobeats analytics image')
package/lib/util.js CHANGED
@@ -18,10 +18,10 @@ var serialize = function (obj) {
18
18
  exports.serialize = serialize;
19
19
  var makeHttpRquest = function (endpoint, options, callback, headers) {
20
20
  options.source = 'JS-Package';
21
+ // Only include headers if provided and not empty, to avoid triggering CORS preflight (OPTIONS) requests
22
+ var axiosConfig = headers && Object.keys(headers).length > 0 ? { headers: headers } : undefined;
21
23
  axios_1.default
22
- .get(exports.baseURL + endpoint + '?' + (0, exports.serialize)(options), {
23
- headers: headers,
24
- })
24
+ .get(exports.baseURL + endpoint + '?' + (0, exports.serialize)(options), axiosConfig)
25
25
  .then(function (response) {
26
26
  if (response.status === 200) {
27
27
  callback(response.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greip.js",
3
- "version": "2.4.7",
3
+ "version": "2.4.9",
4
4
  "description": "The official Javascript library of Greip.",
5
5
  "author": {
6
6
  "name": "Greip",
@@ -49,7 +49,7 @@
49
49
  "url": "https://github.com/Greipio/javascript.git"
50
50
  },
51
51
  "dependencies": {
52
- "axios": "^1.6.7"
52
+ "axios": "^1.9.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/jest": "^29.2.4",