airalo-sdk-type 0.0.1
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 +59 -0
- package/dist/auth.d.ts +13 -0
- package/dist/auth.js +99 -0
- package/dist/balance.d.ts +29 -0
- package/dist/balance.js +48 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +59 -0
- package/dist/order.d.ts +26 -0
- package/dist/order.js +64 -0
- package/dist/package.d.ts +14 -0
- package/dist/package.js +48 -0
- package/dist/types/order.d.ts +38 -0
- package/dist/types/order.js +2 -0
- package/dist/types/package.d.ts +84 -0
- package/dist/types/package.js +2 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# CloudHub
|
|
2
|
+
|
|
3
|
+
CloudHub is an API wrapper for managing authentication, products, and orders seamlessly. It is built with TypeScript and designed for flexibility and scalability.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package using npm or yarn:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install cloudhub.mn
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Import CloudHub and configure it for your application:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import CloudHub from "cloudhub";
|
|
19
|
+
|
|
20
|
+
// Set host and logger
|
|
21
|
+
await CloudHub.setHost("https://api.example.com");
|
|
22
|
+
await CloudHub.setLogger(true);
|
|
23
|
+
|
|
24
|
+
// Authenticate
|
|
25
|
+
const authResult = await CloudHub.auth.LOGIN({
|
|
26
|
+
email: "user@example.com",
|
|
27
|
+
password: "password123",
|
|
28
|
+
});
|
|
29
|
+
console.log(authResult);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Authentication**: Login and manage tokens.
|
|
35
|
+
- **Item Management**: Retrieve and manage items.
|
|
36
|
+
- **Product Management**: Retrieve products and details.
|
|
37
|
+
- **Order Verification**: Verify orders by ID.
|
|
38
|
+
|
|
39
|
+
## API
|
|
40
|
+
|
|
41
|
+
### `CloudHub.setHost(url: string)`
|
|
42
|
+
|
|
43
|
+
Set the API host URL.
|
|
44
|
+
|
|
45
|
+
### `CloudHub.setLogger(status: boolean)`
|
|
46
|
+
|
|
47
|
+
Enable or disable logging.
|
|
48
|
+
|
|
49
|
+
### `CloudHub.auth.LOGIN(body: { email: string; password: string })`
|
|
50
|
+
|
|
51
|
+
Authenticate a user and retrieve an access token.
|
|
52
|
+
|
|
53
|
+
### `CloudHub.auth.getToken()`
|
|
54
|
+
|
|
55
|
+
Retrieve a new authentication token using stored credentials.
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT License
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type AuthType = {
|
|
2
|
+
client_id: string;
|
|
3
|
+
client_secret: string;
|
|
4
|
+
};
|
|
5
|
+
type TokenResponse = {
|
|
6
|
+
success: boolean;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const getToken: () => Promise<string>;
|
|
10
|
+
declare const _default: {
|
|
11
|
+
TOKEN: (auth: AuthType) => Promise<TokenResponse>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getToken = void 0;
|
|
7
|
+
const _1 = require("./");
|
|
8
|
+
const axios_master_1 = require("axios-master");
|
|
9
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
10
|
+
const TOKEN = async (auth) => {
|
|
11
|
+
try {
|
|
12
|
+
let data = new form_data_1.default();
|
|
13
|
+
data.append("client_id", auth.client_id);
|
|
14
|
+
data.append("client_secret", auth.client_secret);
|
|
15
|
+
data.append("grant_type", "client_credentials");
|
|
16
|
+
const response = await (0, axios_master_1.axiosMasterLogger)({
|
|
17
|
+
method: "POST",
|
|
18
|
+
url: `${_1.config.host}/v2/token`,
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: "application/json",
|
|
21
|
+
...data.getHeaders(),
|
|
22
|
+
},
|
|
23
|
+
data: data,
|
|
24
|
+
}, {
|
|
25
|
+
name: "Token",
|
|
26
|
+
timeout: 20000,
|
|
27
|
+
logger: (data) => {
|
|
28
|
+
if (_1.config.logger)
|
|
29
|
+
console.log(data);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (response?.data?.access_token) {
|
|
33
|
+
_1.config.token = response?.data?.access_token;
|
|
34
|
+
_1.config.auth = auth;
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
message: "Token retrieved successfully.",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
message: "Failed to retrieve token.",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const axiosError = error;
|
|
47
|
+
if (axiosError?.response) {
|
|
48
|
+
console.log(axiosError.response);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.error("Token Request Failed:", axiosError);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
message: axiosError?.response?.data?.meta?.message || "An error occurred.",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const getToken = async () => {
|
|
60
|
+
try {
|
|
61
|
+
const data = new form_data_1.default();
|
|
62
|
+
data.append("client_id", _1.config.auth.client_id);
|
|
63
|
+
data.append("client_secret", _1.config.auth.client_secret);
|
|
64
|
+
data.append("grant_type", "client_credentials");
|
|
65
|
+
const response = await (0, axios_master_1.axiosMasterLogger)({
|
|
66
|
+
method: "POST",
|
|
67
|
+
url: `${_1.config.host}/v2/token`,
|
|
68
|
+
headers: {
|
|
69
|
+
Accept: "application/json",
|
|
70
|
+
...data.getHeaders(),
|
|
71
|
+
},
|
|
72
|
+
data: data,
|
|
73
|
+
}, {
|
|
74
|
+
name: "Token",
|
|
75
|
+
timeout: 20000,
|
|
76
|
+
logger: (data) => {
|
|
77
|
+
if (_1.config.logger)
|
|
78
|
+
console.log(data);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
if (response?.data?.access_token) {
|
|
82
|
+
_1.config.token = response?.data?.access_token;
|
|
83
|
+
return response?.data?.access_token;
|
|
84
|
+
}
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const axiosError = error;
|
|
89
|
+
if (axiosError?.response) {
|
|
90
|
+
console.log(axiosError.response);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.error("Token Request Failed:", axiosError);
|
|
94
|
+
}
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.getToken = getToken;
|
|
99
|
+
exports.default = { TOKEN };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const Balance: () => Promise<{
|
|
2
|
+
success: boolean;
|
|
3
|
+
data: {
|
|
4
|
+
balances: {
|
|
5
|
+
name: "balance";
|
|
6
|
+
availableBalance: {
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
} | null;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
declare const _default: {
|
|
15
|
+
Balance: () => Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
data: {
|
|
18
|
+
balances: {
|
|
19
|
+
name: "balance";
|
|
20
|
+
availableBalance: {
|
|
21
|
+
amount: number;
|
|
22
|
+
currency: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
} | null;
|
|
26
|
+
message: string;
|
|
27
|
+
}>;
|
|
28
|
+
};
|
|
29
|
+
export default _default;
|
package/dist/balance.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Balance = void 0;
|
|
4
|
+
const _1 = require("./");
|
|
5
|
+
const axios_master_1 = require("axios-master");
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
const Balance = async () => {
|
|
8
|
+
try {
|
|
9
|
+
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
10
|
+
method: "GET",
|
|
11
|
+
maxBodyLength: Infinity,
|
|
12
|
+
url: `${_1.config.host}/v2/balance`,
|
|
13
|
+
headers: {
|
|
14
|
+
Accept: "application/json",
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
Authorization: `Bearer ${_1.config.token}`,
|
|
17
|
+
},
|
|
18
|
+
}, {
|
|
19
|
+
name: "Balance",
|
|
20
|
+
timeout: 20000,
|
|
21
|
+
retryFunction: auth_1.getToken,
|
|
22
|
+
shouldRetry: true,
|
|
23
|
+
shouldRetryStatus: [401],
|
|
24
|
+
logger: (data) => _1.config.logger && console.log("Balance:", data.json),
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
success: true,
|
|
28
|
+
data: result?.data || null,
|
|
29
|
+
message: "Successfully",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const axiosError = error;
|
|
34
|
+
if (axiosError?.response) {
|
|
35
|
+
console.log(axiosError.response);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error("Balance Request Failed:", axiosError);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
message: axiosError?.response?.data?.meta?.message || "An error occurred.",
|
|
43
|
+
data: null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.Balance = Balance;
|
|
48
|
+
exports.default = { Balance: exports.Balance };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const jsonToQueryString: (params: {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}) => string;
|
|
4
|
+
export declare const config: {
|
|
5
|
+
token: string;
|
|
6
|
+
env: "PROD" | "STAGING";
|
|
7
|
+
host: string;
|
|
8
|
+
auth: {
|
|
9
|
+
client_id: string;
|
|
10
|
+
client_secret: string;
|
|
11
|
+
};
|
|
12
|
+
logger: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const setHost: (url: string) => void;
|
|
15
|
+
export declare const setLogger: (status: boolean) => void;
|
|
16
|
+
declare const _default: {
|
|
17
|
+
auth: {
|
|
18
|
+
TOKEN: (auth: {
|
|
19
|
+
client_id: string;
|
|
20
|
+
client_secret: string;
|
|
21
|
+
}) => Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
message: string;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
config: {
|
|
27
|
+
token: string;
|
|
28
|
+
env: "PROD" | "STAGING";
|
|
29
|
+
host: string;
|
|
30
|
+
auth: {
|
|
31
|
+
client_id: string;
|
|
32
|
+
client_secret: string;
|
|
33
|
+
};
|
|
34
|
+
logger: boolean;
|
|
35
|
+
};
|
|
36
|
+
ObjectId: () => string;
|
|
37
|
+
setHost: (url: string) => void;
|
|
38
|
+
setLogger: (status: boolean) => void;
|
|
39
|
+
};
|
|
40
|
+
export default _default;
|
|
41
|
+
export { default as Package } from "./package";
|
|
42
|
+
export { default as Order } from "./order";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Order = exports.Package = exports.setLogger = exports.setHost = exports.config = exports.jsonToQueryString = void 0;
|
|
7
|
+
const auth_1 = __importDefault(require("./auth"));
|
|
8
|
+
const jsonToQueryString = (params) => {
|
|
9
|
+
const query = Object.keys(params)
|
|
10
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
|
11
|
+
.join("&");
|
|
12
|
+
return query ? `?${query}` : "";
|
|
13
|
+
};
|
|
14
|
+
exports.jsonToQueryString = jsonToQueryString;
|
|
15
|
+
const ObjectId = function () {
|
|
16
|
+
var timestamp = ((new Date().getTime() / 1000) | 0).toString(16);
|
|
17
|
+
return (timestamp +
|
|
18
|
+
"xxxxxxxxxxxxxxxx"
|
|
19
|
+
.replace(/[x]/g, function () {
|
|
20
|
+
return ((Math.random() * 16) | 0).toString(16);
|
|
21
|
+
})
|
|
22
|
+
.toLowerCase());
|
|
23
|
+
};
|
|
24
|
+
exports.config = {
|
|
25
|
+
token: "",
|
|
26
|
+
env: "STAGING",
|
|
27
|
+
host: "https://sandbox-partners-api.airalo.com", // https://sandbox-partners-api.airalo.com, https://partners-api.airalo.com
|
|
28
|
+
auth: {
|
|
29
|
+
client_id: "",
|
|
30
|
+
client_secret: "",
|
|
31
|
+
},
|
|
32
|
+
logger: false,
|
|
33
|
+
};
|
|
34
|
+
// Function to set the host URL for API requests
|
|
35
|
+
const setHost = (url) => {
|
|
36
|
+
exports.config.host = url;
|
|
37
|
+
if (url == "https://partners-api.airalo.com") {
|
|
38
|
+
exports.config.env = "PROD";
|
|
39
|
+
}
|
|
40
|
+
console.log("Host set to:", url);
|
|
41
|
+
};
|
|
42
|
+
exports.setHost = setHost;
|
|
43
|
+
// Function to enable or disable logging
|
|
44
|
+
const setLogger = (status) => {
|
|
45
|
+
exports.config.logger = status;
|
|
46
|
+
console.log("Logger status set to:", status);
|
|
47
|
+
};
|
|
48
|
+
exports.setLogger = setLogger;
|
|
49
|
+
exports.default = {
|
|
50
|
+
auth: auth_1.default,
|
|
51
|
+
config: exports.config,
|
|
52
|
+
ObjectId,
|
|
53
|
+
setHost: exports.setHost,
|
|
54
|
+
setLogger: exports.setLogger,
|
|
55
|
+
};
|
|
56
|
+
var package_1 = require("./package");
|
|
57
|
+
Object.defineProperty(exports, "Package", { enumerable: true, get: function () { return __importDefault(package_1).default; } });
|
|
58
|
+
var order_1 = require("./order");
|
|
59
|
+
Object.defineProperty(exports, "Order", { enumerable: true, get: function () { return __importDefault(order_1).default; } });
|
package/dist/order.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Order } from "./types/order";
|
|
2
|
+
export declare const SubmitOrder: (body: {
|
|
3
|
+
quantity: string;
|
|
4
|
+
package_id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
brand_settings_name?: string;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
success: boolean;
|
|
10
|
+
data: Order;
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
13
|
+
declare const _default: {
|
|
14
|
+
SubmitOrder: (body: {
|
|
15
|
+
quantity: string;
|
|
16
|
+
package_id: string;
|
|
17
|
+
type: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
brand_settings_name?: string;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
success: boolean;
|
|
22
|
+
data: Order;
|
|
23
|
+
message: string;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
package/dist/order.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SubmitOrder = void 0;
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const axios_master_1 = require("axios-master");
|
|
9
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
10
|
+
const auth_1 = require("./auth");
|
|
11
|
+
const SubmitOrder = async (body) => {
|
|
12
|
+
try {
|
|
13
|
+
const data = new form_data_1.default();
|
|
14
|
+
data.append("client_id", _1.config.auth.client_id);
|
|
15
|
+
data.append("quantity", body.quantity);
|
|
16
|
+
data.append("package_id", body.package_id);
|
|
17
|
+
data.append("type", body.type);
|
|
18
|
+
if (body.description) {
|
|
19
|
+
data.append("description", body.description);
|
|
20
|
+
}
|
|
21
|
+
if (body.brand_settings_name) {
|
|
22
|
+
data.append("brand_settings_name", body.brand_settings_name);
|
|
23
|
+
}
|
|
24
|
+
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
25
|
+
method: "POST",
|
|
26
|
+
maxBodyLength: Infinity,
|
|
27
|
+
url: `${_1.config.host}/v2/orders`,
|
|
28
|
+
headers: {
|
|
29
|
+
Accept: "application/json",
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
Authorization: `Bearer ${_1.config.token}`,
|
|
32
|
+
},
|
|
33
|
+
data: data,
|
|
34
|
+
}, {
|
|
35
|
+
name: "SubmitOrder",
|
|
36
|
+
timeout: 20000,
|
|
37
|
+
retryFunction: auth_1.getToken,
|
|
38
|
+
shouldRetry: true,
|
|
39
|
+
shouldRetryStatus: [401],
|
|
40
|
+
logger: (data) => _1.config.logger && console.log("SubmitOrder:", data.json),
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
data: result.data || null,
|
|
45
|
+
message: "Successfully",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const axiosError = error;
|
|
50
|
+
if (axiosError?.response) {
|
|
51
|
+
console.log(axiosError.response);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error("Packages Request Failed:", axiosError);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
message: axiosError?.response?.data?.meta?.message || "An error occurred.",
|
|
59
|
+
data: null,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.SubmitOrder = SubmitOrder;
|
|
64
|
+
exports.default = { SubmitOrder: exports.SubmitOrder };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CountryData } from "./types/package";
|
|
2
|
+
export declare const Packages: () => Promise<{
|
|
3
|
+
success: boolean;
|
|
4
|
+
data: CountryData[];
|
|
5
|
+
message: string;
|
|
6
|
+
}>;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
Packages: () => Promise<{
|
|
9
|
+
success: boolean;
|
|
10
|
+
data: CountryData[];
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
package/dist/package.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Packages = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const axios_master_1 = require("axios-master");
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
const Packages = async () => {
|
|
8
|
+
try {
|
|
9
|
+
const result = await (0, axios_master_1.axiosMasterLogger)({
|
|
10
|
+
method: "GET",
|
|
11
|
+
maxBodyLength: Infinity,
|
|
12
|
+
url: `${_1.config.host}/v2/packages`,
|
|
13
|
+
headers: {
|
|
14
|
+
Accept: "application/json",
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
Authorization: `Bearer ${_1.config.token}`,
|
|
17
|
+
},
|
|
18
|
+
}, {
|
|
19
|
+
name: "Packages",
|
|
20
|
+
timeout: 20000,
|
|
21
|
+
retryFunction: auth_1.getToken,
|
|
22
|
+
shouldRetry: true,
|
|
23
|
+
shouldRetryStatus: [401],
|
|
24
|
+
logger: (data) => _1.config.logger && console.log("Packages:", data.json),
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
success: true,
|
|
28
|
+
data: result.data || null,
|
|
29
|
+
message: "Successfully",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const axiosError = error;
|
|
34
|
+
if (axiosError?.response) {
|
|
35
|
+
console.log(axiosError.response);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error("Packages Request Failed:", axiosError);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
message: axiosError?.response?.data?.meta?.message || "An error occurred.",
|
|
43
|
+
data: null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.Packages = Packages;
|
|
48
|
+
exports.default = { Packages: exports.Packages };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type Order = {
|
|
2
|
+
package_id: string;
|
|
3
|
+
quantity: string;
|
|
4
|
+
type: string;
|
|
5
|
+
description: string;
|
|
6
|
+
esim_type: string;
|
|
7
|
+
validity: number;
|
|
8
|
+
package: string;
|
|
9
|
+
data: string;
|
|
10
|
+
price: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
id: number;
|
|
13
|
+
code: string;
|
|
14
|
+
currency: string;
|
|
15
|
+
manual_installation: string;
|
|
16
|
+
qrcode_installation: string;
|
|
17
|
+
installation_guides: {
|
|
18
|
+
[langCode: string]: string;
|
|
19
|
+
};
|
|
20
|
+
brand_settings_name: string;
|
|
21
|
+
sims: Sim[];
|
|
22
|
+
};
|
|
23
|
+
export type Sim = {
|
|
24
|
+
id: number;
|
|
25
|
+
created_at: string;
|
|
26
|
+
iccid: string;
|
|
27
|
+
lpa: string;
|
|
28
|
+
imsis: string | null;
|
|
29
|
+
matching_id: string;
|
|
30
|
+
qrcode: string;
|
|
31
|
+
qrcode_url: string;
|
|
32
|
+
direct_apple_installation_url: string;
|
|
33
|
+
airalo_code: string | null;
|
|
34
|
+
apn_type: string;
|
|
35
|
+
apn_value: string | null;
|
|
36
|
+
is_roaming: boolean;
|
|
37
|
+
confirmation_code: string | null;
|
|
38
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type CountryData = {
|
|
2
|
+
slug: string;
|
|
3
|
+
country_code: string;
|
|
4
|
+
title: string;
|
|
5
|
+
image: Image;
|
|
6
|
+
operators: Operator[];
|
|
7
|
+
};
|
|
8
|
+
type Image = {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
url: string;
|
|
12
|
+
};
|
|
13
|
+
type Operator = {
|
|
14
|
+
id: number;
|
|
15
|
+
style: string;
|
|
16
|
+
gradient_start: string;
|
|
17
|
+
gradient_end: string;
|
|
18
|
+
type: string;
|
|
19
|
+
is_prepaid: boolean;
|
|
20
|
+
title: string;
|
|
21
|
+
esim_type: string;
|
|
22
|
+
warning: string | null;
|
|
23
|
+
apn_type: string;
|
|
24
|
+
apn_value: string | null;
|
|
25
|
+
is_roaming: boolean;
|
|
26
|
+
info: string[];
|
|
27
|
+
image: Image;
|
|
28
|
+
plan_type: string;
|
|
29
|
+
activation_policy: string;
|
|
30
|
+
is_kyc_verify: boolean;
|
|
31
|
+
rechargeability: boolean;
|
|
32
|
+
other_info: string | null;
|
|
33
|
+
coverages: Coverage[];
|
|
34
|
+
install_window_days: number | null;
|
|
35
|
+
topup_grace_window_days: number | null;
|
|
36
|
+
apn: {
|
|
37
|
+
ios: APN;
|
|
38
|
+
android: APN;
|
|
39
|
+
};
|
|
40
|
+
packages: Package[];
|
|
41
|
+
countries: {
|
|
42
|
+
country_code: string;
|
|
43
|
+
title: string;
|
|
44
|
+
image: Image;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
type Coverage = {
|
|
48
|
+
name: string;
|
|
49
|
+
code: string;
|
|
50
|
+
networks: {
|
|
51
|
+
name: string;
|
|
52
|
+
types: string[];
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
type APN = {
|
|
56
|
+
apn_type: string;
|
|
57
|
+
apn_value: string | null;
|
|
58
|
+
};
|
|
59
|
+
type Package = {
|
|
60
|
+
id: string;
|
|
61
|
+
type: string;
|
|
62
|
+
price: number;
|
|
63
|
+
amount: number;
|
|
64
|
+
day: number;
|
|
65
|
+
is_unlimited: boolean;
|
|
66
|
+
title: string;
|
|
67
|
+
short_info: string | null;
|
|
68
|
+
qr_installation: string;
|
|
69
|
+
manual_installation: string;
|
|
70
|
+
is_fair_usage_policy: boolean;
|
|
71
|
+
fair_usage_policy: string | null;
|
|
72
|
+
data: string;
|
|
73
|
+
voice: string | null;
|
|
74
|
+
text: string | null;
|
|
75
|
+
net_price: number;
|
|
76
|
+
prices: {
|
|
77
|
+
net_price: CurrencyPrice;
|
|
78
|
+
recommended_retail_price: CurrencyPrice;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
type CurrencyPrice = {
|
|
82
|
+
[currency: string]: number;
|
|
83
|
+
};
|
|
84
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "airalo-sdk-type",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "UNOFFICIAL AIRALO API INTEGRATION FOR JAVASCRIPT/TYPESCRIPT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"build-ts": "npx tsc",
|
|
13
|
+
"build": "npx tsc",
|
|
14
|
+
"debug": "npm run build && npm run watch-debug",
|
|
15
|
+
"lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/togtokh-dev/airalo.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"benefits",
|
|
23
|
+
"axios",
|
|
24
|
+
"api",
|
|
25
|
+
"toki"
|
|
26
|
+
],
|
|
27
|
+
"author": "Buyantogtokh",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/togtokh-dev/airalo/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/togtokh-dev/airalo/#readme",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"axios": "^1.6.2",
|
|
35
|
+
"axios-master": "^2.0.4",
|
|
36
|
+
"https": "^1.0.0",
|
|
37
|
+
"node": "^23.4.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/jest": "^29.5.14",
|
|
41
|
+
"@types/node": "^18.19.68",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
43
|
+
"@typescript-eslint/parser": "^6.4.0",
|
|
44
|
+
"eslint": "^8.47.0",
|
|
45
|
+
"jest": "^29.5.0",
|
|
46
|
+
"ts-jest": "^29.1.0",
|
|
47
|
+
"ts-node": "^10.9.2",
|
|
48
|
+
"tslib": "^2.6.3",
|
|
49
|
+
"typescript": "^5.5.4"
|
|
50
|
+
}
|
|
51
|
+
}
|