@payhos/api 2.1.0 → 2.3.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 +45 -53
- package/api.service.d.ts +5 -0
- package/api.service.js +13 -1
- package/api.service.js.map +1 -1
- package/email.d.ts +0 -1
- package/email.js +1 -7
- package/email.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/model.d.ts +4 -0
- package/package.json +1 -1
- package/prerender.d.ts +6 -0
- package/prerender.js +15 -0
- package/prerender.js.map +1 -0
- package/sms.d.ts +0 -1
- package/sms.js +1 -7
- package/sms.js.map +1 -1
package/README.md
CHANGED
|
@@ -4,68 +4,60 @@
|
|
|
4
4
|
|
|
5
5
|
This API SDK is intended to assist web applications of any kind to interact with the PayHos API server by utilizing its simple schematics. For a more modular usage, this library is designed such that bundlers with tree-shaking is enhanced.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
Install @payhos/api via npm by running the following command:
|
|
9
|
-
> `npm install @payhos/api --save`
|
|
7
|
+
# PayHos API SDK
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
Create an instance and call available methods from the instance created.
|
|
9
|
+
PayHos provides a small client SDK to interact with the PayHos API for sending email, SMS and requesting prerendered HTML pages.
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
import { PayHos } from '@payhos/api';
|
|
11
|
+
## Install
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npm install @payhos/api --save
|
|
15
|
+
```
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
## SMS
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
const sms = payhos.sms;
|
|
24
|
-
const email = payhos.email;
|
|
25
|
-
```
|
|
19
|
+
Use the `sms` helper to send messages.
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
message:
|
|
33
|
-
recipients: [
|
|
34
|
-
senderId:
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// to send SMS
|
|
38
|
-
sms.send(data).then(response => {
|
|
39
|
-
// message(s) sent successfully
|
|
40
|
-
console.log(response);
|
|
41
|
-
}).catch(err => {
|
|
42
|
-
console.log(err);
|
|
21
|
+
```ts
|
|
22
|
+
import { PayHos } from "@payhos/api";
|
|
23
|
+
const payhos = new PayHos("<YOUR_API_TOKEN>");
|
|
24
|
+
|
|
25
|
+
await payhos.sms.send({
|
|
26
|
+
message: "Hello from PayHos",
|
|
27
|
+
recipients: ["+1234567890"],
|
|
28
|
+
senderId: "PayHos",
|
|
43
29
|
});
|
|
44
30
|
```
|
|
45
31
|
|
|
46
32
|
## Email
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
],
|
|
58
|
-
from: {
|
|
59
|
-
name: 'PayHos',
|
|
60
|
-
email: 'test@yourdomain.com'
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// to send email
|
|
65
|
-
email.send(data).then(response => {
|
|
66
|
-
// message(s) sent successfully
|
|
67
|
-
console.log(response);
|
|
68
|
-
}).catch(err => {
|
|
69
|
-
console.log(err);
|
|
33
|
+
|
|
34
|
+
Use the `email` helper to send emails.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { PayHos } from "@payhos/api";
|
|
38
|
+
const payhos = new PayHos("<YOUR_API_TOKEN>");
|
|
39
|
+
|
|
40
|
+
await payhos.email.send({
|
|
41
|
+
subject: "Hi",
|
|
42
|
+
content: "<p>Hello</p>",
|
|
43
|
+
recipients: [{ email: "user@example.com" }],
|
|
44
|
+
from: { name: "PayHos", email: "noreply@payhos.com" },
|
|
70
45
|
});
|
|
71
46
|
```
|
|
47
|
+
|
|
48
|
+
## Prerender
|
|
49
|
+
|
|
50
|
+
Use the `prerender` helper to request a pre-rendered HTML snapshot of a URL.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { PayHos } from "@payhos/api";
|
|
54
|
+
const payhos = new PayHos("<YOUR_API_TOKEN>");
|
|
55
|
+
|
|
56
|
+
const resp = await payhos.prerender.page({
|
|
57
|
+
url: "https://example.com",
|
|
58
|
+
cacheMs: 86400000,
|
|
59
|
+
});
|
|
60
|
+
console.log(resp.result);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For full API details, see https://docs.payhos.com.
|
package/api.service.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { ApiResponse, Map } from './model';
|
|
2
2
|
export declare const apiHandler: {
|
|
3
3
|
post: <T>(path: string, body: Map<any>, headers: Map<any>) => Promise<ApiResponse<T>>;
|
|
4
|
+
get: <T_1>(path: string, headers: Map<any>) => Promise<ApiResponse<T_1>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const apiHeaders: (apiKey: string) => {
|
|
7
|
+
Authorization: string;
|
|
8
|
+
'Content-Type': string;
|
|
4
9
|
};
|
package/api.service.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.apiHandler = void 0;
|
|
3
|
+
exports.apiHeaders = exports.apiHandler = void 0;
|
|
4
4
|
const axios_1 = require("axios");
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
exports.apiHandler = {
|
|
@@ -8,6 +8,18 @@ exports.apiHandler = {
|
|
|
8
8
|
const url = `${config_1.baseUrl}/v1/api/${path}`;
|
|
9
9
|
const res = await axios_1.default.post(url, body, { headers });
|
|
10
10
|
return res.data;
|
|
11
|
+
},
|
|
12
|
+
get: async (path, headers) => {
|
|
13
|
+
const url = `${config_1.baseUrl}/v1/api/${path}`;
|
|
14
|
+
const res = await axios_1.default.get(url, { headers });
|
|
15
|
+
return res.data;
|
|
11
16
|
}
|
|
12
17
|
};
|
|
18
|
+
const apiHeaders = (apiKey) => {
|
|
19
|
+
return {
|
|
20
|
+
Authorization: `Bearer ${apiKey}`,
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.apiHeaders = apiHeaders;
|
|
13
25
|
//# sourceMappingURL=api.service.js.map
|
package/api.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.service.js","sourceRoot":"","sources":["../src/api.service.ts"],"names":[],"mappings":";;;AAAA,iCAA0B;AAE1B,qCAAmC;AAEtB,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,KAAK,EAAK,IAAY,EAAE,IAAc,EAAE,OAAiB,EAAE,EAAE;QACjE,MAAM,GAAG,GAAG,GAAG,gBAAO,WAAW,IAAI,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,OAAO,GAAG,CAAC,IAAsB,CAAC;IACpC,CAAC;CACF,CAAA"}
|
|
1
|
+
{"version":3,"file":"api.service.js","sourceRoot":"","sources":["../src/api.service.ts"],"names":[],"mappings":";;;AAAA,iCAA0B;AAE1B,qCAAmC;AAEtB,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,KAAK,EAAK,IAAY,EAAE,IAAc,EAAE,OAAiB,EAAE,EAAE;QACjE,MAAM,GAAG,GAAG,GAAG,gBAAO,WAAW,IAAI,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,OAAO,GAAG,CAAC,IAAsB,CAAC;IACpC,CAAC;IACD,GAAG,EAAE,KAAK,EAAK,IAAY,EAAE,OAAiB,EAAE,EAAE;QAChD,MAAM,GAAG,GAAG,GAAG,gBAAO,WAAW,IAAI,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC,IAAsB,CAAC;IACpC,CAAC;CACF,CAAA;AAEM,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,EAAE;IAC3C,OAAO;QACL,aAAa,EAAE,UAAU,MAAM,EAAE;QACjC,cAAc,EAAE,kBAAkB;KACnC,CAAC;AACJ,CAAC,CAAA;AALY,QAAA,UAAU,cAKtB"}
|
package/email.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { EmailOpts } from './model';
|
|
|
2
2
|
export declare class Email {
|
|
3
3
|
private _apiKey;
|
|
4
4
|
constructor(key: string);
|
|
5
|
-
private headers;
|
|
6
5
|
sendEmail(opts: EmailOpts): Promise<import("./model").ApiResponse<any>>;
|
|
7
6
|
sendEmails(opts: EmailOpts[]): Promise<import("./model").ApiResponse<any>>;
|
|
8
7
|
}
|
package/email.js
CHANGED
|
@@ -6,17 +6,11 @@ class Email {
|
|
|
6
6
|
constructor(key) {
|
|
7
7
|
this._apiKey = key;
|
|
8
8
|
}
|
|
9
|
-
headers() {
|
|
10
|
-
return {
|
|
11
|
-
Authorization: `Bearer ${this._apiKey}`,
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
9
|
sendEmail(opts) {
|
|
16
10
|
return this.sendEmails([opts]);
|
|
17
11
|
}
|
|
18
12
|
sendEmails(opts) {
|
|
19
|
-
return api_service_1.apiHandler.post('emails/send', opts, this.
|
|
13
|
+
return api_service_1.apiHandler.post('emails/send', opts, (0, api_service_1.apiHeaders)(this._apiKey));
|
|
20
14
|
}
|
|
21
15
|
}
|
|
22
16
|
exports.Email = Email;
|
package/email.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.js","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"email.js","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAGvD,MAAa,KAAK;IAGhB,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAEM,SAAS,CAAC,IAAe;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IAEM,UAAU,CAAC,IAAiB;QACjC,OAAO,wBAAU,CAAC,IAAI,CAAM,aAAa,EAAE,IAAI,EAAE,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;CACF;AAdD,sBAcC"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PayHos = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const email_1 = require("./email");
|
|
6
|
+
const prerender_1 = require("./prerender");
|
|
6
7
|
const sms_1 = require("./sms");
|
|
7
8
|
tslib_1.__exportStar(require("./model"), exports);
|
|
8
9
|
class PayHos {
|
|
9
10
|
constructor(key) {
|
|
10
11
|
this.sms = new sms_1.SMS(key);
|
|
11
12
|
this.email = new email_1.Email(key);
|
|
13
|
+
this.prerender = new prerender_1.PreRender(key);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
exports.PayHos = PayHos;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAAgC;AAChC,+BAA4B;AAE5B,kDAAwB;AAExB,MAAa,MAAM;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAAgC;AAChC,2CAAwC;AACxC,+BAA4B;AAE5B,kDAAwB;AAExB,MAAa,MAAM;IAKjB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF;AAVD,wBAUC"}
|
package/model.d.ts
CHANGED
package/package.json
CHANGED
package/prerender.d.ts
ADDED
package/prerender.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreRender = void 0;
|
|
4
|
+
const api_service_1 = require("./api.service");
|
|
5
|
+
class PreRender {
|
|
6
|
+
constructor(key) {
|
|
7
|
+
this._apiKey = key;
|
|
8
|
+
}
|
|
9
|
+
page(opts) {
|
|
10
|
+
const path = `prerender?url=${encodeURIComponent(opts.url)}&cacheMs=${opts.cacheMs || 86400000}`;
|
|
11
|
+
return api_service_1.apiHandler.get(path, (0, api_service_1.apiHeaders)(this._apiKey));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PreRender = PreRender;
|
|
15
|
+
//# sourceMappingURL=prerender.js.map
|
package/prerender.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prerender.js","sourceRoot":"","sources":["../src/prerender.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAGvD,MAAa,SAAS;IAGpB,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAEM,IAAI,CAAC,IAAmB;QAC7B,MAAM,IAAI,GAAG,iBAAiB,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,CAAC;QACjG,OAAO,wBAAU,CAAC,GAAG,CAAS,IAAI,EAAE,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAChE,CAAC;CACF;AAXD,8BAWC"}
|
package/sms.d.ts
CHANGED
package/sms.js
CHANGED
|
@@ -6,14 +6,8 @@ class SMS {
|
|
|
6
6
|
constructor(key) {
|
|
7
7
|
this._apiKey = key;
|
|
8
8
|
}
|
|
9
|
-
headers() {
|
|
10
|
-
return {
|
|
11
|
-
Authorization: `Bearer ${this._apiKey}`,
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
9
|
sendSMS(opts) {
|
|
16
|
-
return api_service_1.apiHandler.post('sms/send', opts, this.
|
|
10
|
+
return api_service_1.apiHandler.post('sms/send', opts, (0, api_service_1.apiHeaders)(this._apiKey));
|
|
17
11
|
}
|
|
18
12
|
}
|
|
19
13
|
exports.SMS = SMS;
|
package/sms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sms.js","sourceRoot":"","sources":["../src/sms.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"sms.js","sourceRoot":"","sources":["../src/sms.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAGvD,MAAa,GAAG;IAGd,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAEM,OAAO,CAAI,IAAe;QAC/B,OAAO,wBAAU,CAAC,IAAI,CAAI,UAAU,EAAE,IAAI,EAAE,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAVD,kBAUC"}
|