@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 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
- ## Installation
8
- Install @payhos/api via npm by running the following command:
9
- > `npm install @payhos/api --save`
7
+ # PayHos API SDK
10
8
 
11
- ## Usage
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
- ```typescript
15
- import { PayHos } from '@payhos/api';
11
+ ## Install
16
12
 
17
- // or
18
- const { PayHos } = require('@payhos/api');
13
+ ```bash
14
+ npm install @payhos/api --save
15
+ ```
19
16
 
20
- const payhos = new PayHos('<YOUR API TOKEN>');
17
+ ## SMS
21
18
 
22
- // You can access each of PayHos' API features as follows:
23
- const sms = payhos.sms;
24
- const email = payhos.email;
25
- ```
19
+ Use the `sms` helper to send messages.
26
20
 
27
- ## SMS
28
- Visit [Send SMS with PayHos](https://docs.payhos.com/components/sms) for more information on SMS dodumentations.
29
- ```javascript
30
- const sms = payhos.sms;
31
- const data = {
32
- message: 'Hello there, this is a test message from PayHos SDK',
33
- recipients: ['+2348166666666', '+2348055555555'],
34
- senderId: 'PayHos',
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
- For detailed documentations on sending emails with PayHos API and other supported SDKs, visit [Sending Emails](https://docs.payhos.com/components/email) with PayHos
48
- ```javascript
49
- const email = payhos.email;
50
- const data = {
51
- subject: 'Test Email',
52
- content: `Hey <strong>Alice</strong>, this is a test email message from <a href="https://payhos.com">PayHos API Hub</a>`,
53
- customData: {},
54
- recipients: [
55
- {email: 'example@example.com'},
56
- { name: 'Alice', email: 'alice@example.com' }
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
@@ -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.headers());
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,+CAA2C;AAG3C,MAAa,KAAK;IAGhB,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAEO,OAAO;QACb,OAAO;YACL,aAAa,EAAE,UAAU,IAAI,CAAC,OAAO,EAAE;YACvC,cAAc,EAAE,kBAAkB;SACnC,CAAC;IACJ,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,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;CACF;AArBD,sBAqBC"}
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
@@ -1,8 +1,10 @@
1
1
  import { Email } from './email';
2
+ import { PreRender } from './prerender';
2
3
  import { SMS } from './sms';
3
4
  export * from './model';
4
5
  export declare class PayHos {
5
6
  sms: SMS;
6
7
  email: Email;
8
+ prerender: PreRender;
7
9
  constructor(key: string);
8
10
  }
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;IAIjB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF;AARD,wBAQC"}
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
@@ -25,3 +25,7 @@ export interface SMSOpts {
25
25
  message: string;
26
26
  senderId: string;
27
27
  }
28
+ export interface PreRenderOpts {
29
+ url: string;
30
+ cacheMs?: number;
31
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@payhos/api",
3
3
  "description": "An API package for payhos's API built for JavaScript and Typescript developers",
4
- "version": "2.1.0",
4
+ "version": "2.3.1",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
package/prerender.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { PreRenderOpts } from './model';
2
+ export declare class PreRender {
3
+ private _apiKey;
4
+ constructor(key: string);
5
+ page(opts: PreRenderOpts): Promise<import("./model").ApiResponse<string>>;
6
+ }
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
@@ -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
@@ -2,6 +2,5 @@ import { SMSOpts } from './model';
2
2
  export declare class SMS {
3
3
  private _apiKey;
4
4
  constructor(key: string);
5
- private headers;
6
5
  sendSMS<T>(opts: SMSOpts[]): Promise<import("./model").ApiResponse<T>>;
7
6
  }
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.headers());
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,+CAA2C;AAG3C,MAAa,GAAG;IAGd,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAEO,OAAO;QACb,OAAO;YACL,aAAa,EAAE,UAAU,IAAI,CAAC,OAAO,EAAE;YACvC,cAAc,EAAE,kBAAkB;SACnC,CAAC;IACJ,CAAC;IAEM,OAAO,CAAI,IAAe;QAC/B,OAAO,wBAAU,CAAC,IAAI,CAAI,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAjBD,kBAiBC"}
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"}