@payhos/api 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 ADDED
@@ -0,0 +1,30 @@
1
+ # PayHos API SDK
2
+
3
+ [PayHos](https://payhos.com) is an easy go-to solution to many day-to-day fintech problems by providing an easily accessible opportunities to all and sundry with minimal bar of entry. It is provided by [EmbyBest Concept Nig. Ltd](https://embyconcept.com)
4
+
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
+
7
+ ## Installation
8
+ Install @payhos/api via npm by running the following command:
9
+ > `npm install @payhos/api --save`
10
+
11
+ ## Usage
12
+ Create an instance and call available methods from the instance created.
13
+
14
+ ```typescript
15
+ import { } from '@payhos/api';
16
+
17
+ const payHos = new PayHos();
18
+ ```
19
+
20
+ ## SMS
21
+ ```typescript
22
+ // comment
23
+ const doc = {};
24
+ ```
25
+
26
+ ### Further Reading
27
+ Have a look at other packages:
28
+ - [pincode](https://www.npmjs.com/package/pincode)
29
+ - [timestamp-date](https://www.npmjs.com/package/timestamp-date)
30
+ - [ng-sub](https://www.npmjs.com/package/ng-sub)
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { PayHosAirtime } from './modules/airtime';
2
+ import { PayHosSMS } from './modules/sms';
3
+ export declare class PayHos {
4
+ sms: PayHosSMS;
5
+ airtime: PayHosAirtime;
6
+ constructor(tkn: string);
7
+ }
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PayHos = void 0;
4
+ const airtime_1 = require("./modules/airtime");
5
+ const sms_1 = require("./modules/sms");
6
+ const api_service_1 = require("./services/api.service");
7
+ class PayHos {
8
+ constructor(tkn) {
9
+ const client = new api_service_1.PayHosApiClient(tkn);
10
+ this.sms = new sms_1.PayHosSMS(client);
11
+ this.airtime = new airtime_1.PayHosAirtime(client);
12
+ }
13
+ }
14
+ exports.PayHos = PayHos;
15
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAClD,uCAA0C;AAC1C,wDAAyD;AAEzD,MAAa,MAAM;IAIjB,YAAY,GAAW;QACrB,MAAM,MAAM,GAAG,IAAI,6BAAe,CAAC,GAAG,CAAC,CAAC;QAExC,IAAI,CAAC,GAAG,GAAG,IAAI,eAAS,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF;AAVD,wBAUC"}
@@ -0,0 +1,9 @@
1
+ export interface Map<T> {
2
+ [key: string]: T;
3
+ }
4
+ export interface ApiResponse<T> {
5
+ success: boolean;
6
+ data?: T;
7
+ message?: string;
8
+ stackTrace?: any;
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { PayHosApiClient } from '../../services/api.service';
2
+ export declare class PayHosAirtime {
3
+ private client;
4
+ constructor(c: PayHosApiClient);
5
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PayHosAirtime = void 0;
4
+ class PayHosAirtime {
5
+ constructor(c) {
6
+ this.client = c;
7
+ console.log(this.client);
8
+ }
9
+ }
10
+ exports.PayHosAirtime = PayHosAirtime;
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/airtime/index.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IAGxB,YAAY,CAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAEhB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;CACF;AARD,sCAQC"}
@@ -0,0 +1,6 @@
1
+ import { PayHosApiClient } from '../../services/api.service';
2
+ export declare class PayHosSMS {
3
+ private client;
4
+ constructor(c: PayHosApiClient);
5
+ send(msg: string, recipients: string[], flash?: boolean): Promise<{}>;
6
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PayHosSMS = void 0;
4
+ const utilities_service_1 = require("../../services/utilities.service");
5
+ class PayHosSMS {
6
+ constructor(c) {
7
+ this.client = c;
8
+ }
9
+ send(msg, recipients, flash) {
10
+ const body = {
11
+ message: msg,
12
+ recipients: recipients.map(r => (0, utilities_service_1.formatPhoneNumber)(r)),
13
+ flash,
14
+ };
15
+ return this.client.postApi('/sms/send', body);
16
+ }
17
+ }
18
+ exports.PayHosSMS = PayHosSMS;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/sms/index.ts"],"names":[],"mappings":";;;AAAA,wEAAqE;AAGrE,MAAa,SAAS;IAGpB,YAAY,CAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAEM,IAAI,CAAC,GAAW,EAAE,UAAoB,EAAE,KAAe;QAC5D,MAAM,IAAI,GAAG;YACX,OAAO,EAAE,GAAG;YACZ,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,qCAAiB,EAAC,CAAC,CAAC,CAAC;YACrD,KAAK;SACN,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;CACF;AAhBD,8BAgBC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@payhos/api",
3
+ "description": "An API SDK to communicate with the PayHos API",
4
+ "version": "0.0.1",
5
+ "main": "index.js",
6
+ "typings": "index.d.ts",
7
+ "scripts": {
8
+ "test": "mocha --require ts-node/register test/**/*.ts",
9
+ "deploy": "tsc && node copy && cd dist && npm publish --access=public",
10
+ "unpublish": "npm unpublish @payhos/api@0.0.1"
11
+ },
12
+ "dependencies": {
13
+ "axios": "^0.26.1"
14
+ },
15
+ "author": {
16
+ "name": "Moses Godson",
17
+ "email": "mosesgodson27@gmail.com"
18
+ },
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/Moses270/@payhos/api/issues"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/Moses270/@payhos/api"
26
+ },
27
+ "homepage": "https://payhos.com",
28
+ "keywords": [
29
+ "PayHos",
30
+ "API",
31
+ "SMS",
32
+ "Airtime",
33
+ "Data subscription",
34
+ "Electricity bills"
35
+ ],
36
+ "devDependencies": {
37
+ "fs-extra": "^9.0.0",
38
+ "tslib": "^2.3.1"
39
+ }
40
+ }
@@ -0,0 +1,13 @@
1
+ import { Map } from '../models';
2
+ export declare class PayHosApiClient {
3
+ private token;
4
+ private baseUrl;
5
+ constructor(tkn: string);
6
+ private config;
7
+ private toUrl;
8
+ private handleApiResponse;
9
+ getApi<T>(url: string, params?: Map<string>): Promise<T>;
10
+ postApi<T>(url: string, body: Map<any>, params?: Map<string>): Promise<T>;
11
+ putApi<T>(url: string, body: Map<any>, params?: Map<string>): Promise<T>;
12
+ deleteApi<T>(url: string, params?: Map<string>): Promise<T>;
13
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PayHosApiClient = void 0;
4
+ const axios_1 = require("axios");
5
+ class PayHosApiClient {
6
+ constructor(tkn) {
7
+ this.baseUrl = 'https://us-central1-pay-hos.cloudfunctions.net/apiHttp/api/v1';
8
+ this.token = tkn;
9
+ }
10
+ config() {
11
+ if (!this.token) {
12
+ throw Error('API token must be provided');
13
+ }
14
+ const config = {
15
+ headers: {
16
+ 'Authorization': 'Bearer ' + this.token,
17
+ },
18
+ };
19
+ return config;
20
+ }
21
+ toUrl(url, params) {
22
+ let result = this.baseUrl + '/' + url.substring(url.startsWith('/') ? 1 : 0) + '?';
23
+ const pms = params || {};
24
+ pms._phos_now = Date.now().toString();
25
+ const keys = Object.keys(pms);
26
+ for (const k of keys) {
27
+ result += `${k}=${params[k]}&`;
28
+ }
29
+ return result.substring(0, result.length - 1);
30
+ }
31
+ handleApiResponse(promise) {
32
+ return new Promise((resolve, reject) => {
33
+ promise.then(res => {
34
+ if (res.success) {
35
+ resolve(res.data);
36
+ }
37
+ else {
38
+ reject(res.message || res.stackTrace || 'Error encountered!');
39
+ }
40
+ }).catch(e => {
41
+ reject(e);
42
+ });
43
+ });
44
+ }
45
+ getApi(url, params) {
46
+ return this.handleApiResponse(axios_1.default.get(this.toUrl(url, params), this.config()));
47
+ }
48
+ async postApi(url, body, params) {
49
+ return this.handleApiResponse(axios_1.default.post(this.toUrl(url, params), body, this.config()));
50
+ }
51
+ async putApi(url, body, params) {
52
+ return this.handleApiResponse(axios_1.default.put(this.toUrl(url, params), body, this.config()));
53
+ }
54
+ async deleteApi(url, params) {
55
+ return this.handleApiResponse(axios_1.default.delete(this.toUrl(url, params), this.config()));
56
+ }
57
+ }
58
+ exports.PayHosApiClient = PayHosApiClient;
59
+ //# sourceMappingURL=api.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.service.js","sourceRoot":"","sources":["../../src/services/api.service.ts"],"names":[],"mappings":";;;AAAA,iCAA0B;AAG1B,MAAa,eAAe;IAI1B,YAAY,GAAW;QAFf,YAAO,GAAG,+DAA+D,CAAC;QAGhF,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;IACnB,CAAC;IAEO,MAAM;QACZ,IAAI,CAA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K,CAAC,CAAC,CAAC,EAAE;gBACX,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAI,GAAW,EAAE,MAAoB;QAChD,OAAO,IAAI,CAAC,iBAAiB,CAC3B,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAClD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,OAAO,CAAI,GAAW,EAAE,IAAc,EAAE,MAAoB;QACvE,OAAO,IAAI,CAAC,iBAAiB,CAC3B,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CACzD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,MAAM,CAAI,GAAW,EAAE,IAAc,EAAE,MAAoB;QACtE,OAAO,IAAI,CAAC,iBAAiB,CAC3B,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CACxD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,SAAS,CAAI,GAAW,EAAE,MAAoB;QACzD,OAAO,IAAI,CAAC,iBAAiB,CAC3B,eAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;CACF;AAzED,0CAyEC"}
@@ -0,0 +1 @@
1
+ export declare const formatPhoneNumber: (phone: string) => string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPhoneNumber = void 0;
4
+ const formatPhoneNumber = (phone) => {
5
+ let phoneNumber;
6
+ if (phone.startsWith('0')) {
7
+ phoneNumber = phone;
8
+ }
9
+ else if (phone.startsWith('234')) {
10
+ phoneNumber = '0' + phone.substring(3);
11
+ }
12
+ else if (phone.startsWith('+234')) {
13
+ phoneNumber = '0' + phone.substring(4);
14
+ }
15
+ else {
16
+ return '';
17
+ }
18
+ // removes space from with number characters
19
+ phoneNumber = phoneNumber.replace(new RegExp(' ', 'g'), '');
20
+ const noNonDigit = !(/\D/i.test(phoneNumber));
21
+ if (phoneNumber.length === 11 && noNonDigit) {
22
+ return phoneNumber;
23
+ }
24
+ else {
25
+ return '';
26
+ }
27
+ };
28
+ exports.formatPhoneNumber = formatPhoneNumber;
29
+ //# sourceMappingURL=utilities.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.service.js","sourceRoot":"","sources":["../../src/services/utilities.service.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE;IACzD,IAAI,WAAmB,CAAC;IAExB,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACzB,WAAW,GAAG,KAAK,CAAC;KACrB;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QAClC,WAAW,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACxC;SAAM,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACnC,WAAW,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACxC;SAAM;QACL,OAAO,EAAE,CAAC;KACX;IAED,4CAA4C;IAC5C,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAE5D,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC9C,IAAI,WAAW,CAAC,MAAM,KAAK,EAAE,IAAI,UAAU,EAAE;QAC3C,OAAO,WAAW,CAAC;KACpB;SAAM;QACL,OAAO,EAAE,CAAC;KACX;AACH,CAAC,CAAA;AAtBY,QAAA,iBAAiB,qBAsB7B"}
package/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/test.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ const app = new index_1.PayHos('TOKEN_STRING');
5
+ console.log(app.sms);
6
+ //# sourceMappingURL=test.js.map
package/test.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,mCAAiC;AAEjC,MAAM,GAAG,GAAG,IAAI,cAAM,CAAC,cAAc,CAAC,CAAC;AACvC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}