@payhos/api 2.3.1 → 2.5.0
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 +58 -4
- package/ai.d.ts +6 -0
- package/ai.js +14 -0
- package/ai.js.map +1 -0
- package/api.service.d.ts +1 -0
- package/api.service.js +1 -0
- package/api.service.js.map +1 -1
- package/config.js +1 -0
- package/config.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 +21 -0
- package/package.json +2 -2
- package/prerender.js +1 -1
- package/prerender.js.map +1 -1
package/README.md
CHANGED
|
@@ -39,9 +39,9 @@ const payhos = new PayHos("<YOUR_API_TOKEN>");
|
|
|
39
39
|
|
|
40
40
|
await payhos.email.send({
|
|
41
41
|
subject: "Hi",
|
|
42
|
-
|
|
43
|
-
recipients: [{ email: "user@example.com" }],
|
|
44
|
-
|
|
42
|
+
html: "<p>Hello</p>",
|
|
43
|
+
recipients: [{ email: "user@example.com", name: "Jane" }],
|
|
44
|
+
sender: { name: "PayHos", email: "noreply@payhos.com" },
|
|
45
45
|
});
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -57,7 +57,61 @@ const resp = await payhos.prerender.page({
|
|
|
57
57
|
url: "https://example.com",
|
|
58
58
|
cacheMs: 86400000,
|
|
59
59
|
});
|
|
60
|
-
console.log(resp.
|
|
60
|
+
console.log(resp.data);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## AI
|
|
64
|
+
|
|
65
|
+
Use the `ai` helper to send prompts to PayHos AI API.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { PayHos } from "@payhos/api";
|
|
69
|
+
const payhos = new PayHos("<YOUR_API_TOKEN>");
|
|
70
|
+
|
|
71
|
+
const resp = await payhos.ai.prompt({
|
|
72
|
+
prompt: "Write a short release note for a payments API update.",
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (resp.success && resp.data) {
|
|
76
|
+
console.log(resp.data.response);
|
|
77
|
+
console.log(resp.data.usage.totalChars, resp.data.usage.cost);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### AI provider selection
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
const geminiResp = await payhos.ai.prompt({
|
|
85
|
+
prompt: "Summarize this in 3 bullets",
|
|
86
|
+
provider: "gemini", // default if omitted
|
|
87
|
+
model: "gemini-2.0-flash-lite",
|
|
88
|
+
temperature: 0.6,
|
|
89
|
+
maxInputChars: 4000,
|
|
90
|
+
maxOutputChars: 1200,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const gptResp = await payhos.ai.prompt({
|
|
94
|
+
prompt: "Create a concise onboarding checklist.",
|
|
95
|
+
provider: "gpt",
|
|
96
|
+
model: "gpt-4o-mini",
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### AI billing
|
|
101
|
+
|
|
102
|
+
- Rate: `0.003 USD` per `1000` characters
|
|
103
|
+
- Metering basis: prompt characters + response characters
|
|
104
|
+
- Usage details are returned in `data.usage`
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
// Example usage payload shape
|
|
108
|
+
// {
|
|
109
|
+
// inputChars: number,
|
|
110
|
+
// outputChars: number,
|
|
111
|
+
// totalChars: number,
|
|
112
|
+
// cost: number,
|
|
113
|
+
// ratePer1000Chars: number
|
|
114
|
+
// }
|
|
61
115
|
```
|
|
62
116
|
|
|
63
117
|
For full API details, see https://docs.payhos.com.
|
package/ai.d.ts
ADDED
package/ai.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AI = void 0;
|
|
4
|
+
const api_service_1 = require("./api.service");
|
|
5
|
+
class AI {
|
|
6
|
+
constructor(key) {
|
|
7
|
+
this._apiKey = key;
|
|
8
|
+
}
|
|
9
|
+
prompt(opts) {
|
|
10
|
+
return api_service_1.apiHandler.post('ai/prompt', opts, (0, api_service_1.apiHeaders)(this._apiKey));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AI = AI;
|
|
14
|
+
//# sourceMappingURL=ai.js.map
|
package/ai.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.js","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":";;;AAAA,+CAAuD;AAGvD,MAAa,EAAE;IAGb,YAAY,GAAW;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAkB;QAC9B,OAAO,wBAAU,CAAC,IAAI,CAAa,WAAW,EAAE,IAAI,EAAE,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAClF,CAAC;CACF;AAVD,gBAUC"}
|
package/api.service.d.ts
CHANGED
package/api.service.js
CHANGED
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;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;
|
|
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;QAClC,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC,CAAA;AANY,QAAA,UAAU,cAMtB"}
|
package/config.js
CHANGED
package/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAW,MAAM,CAAC;AAErB,QAAA,OAAO,GAAG,GAAG,CAAC;AAEzB,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;IACvB,eAAO,GAAG,uBAAuB,CAAC;AACpC,CAAC;KAAM,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;IAC/B,eAAO,GAAG,kCAAkC,CAAC;AAC/C,CAAC"}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC,MAAM,QAAQ,GAAW,MAAM,CAAC;AAErB,QAAA,OAAO,GAAG,GAAG,CAAC;AAEzB,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;IACvB,eAAO,GAAG,uBAAuB,CAAC;AACpC,CAAC;KAAM,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;IAC/B,eAAO,GAAG,kCAAkC,CAAC;AAC/C,CAAC"}
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Email } from './email';
|
|
2
2
|
import { PreRender } from './prerender';
|
|
3
3
|
import { SMS } from './sms';
|
|
4
|
+
import { AI } from './ai';
|
|
4
5
|
export * from './model';
|
|
5
6
|
export declare class PayHos {
|
|
6
7
|
sms: SMS;
|
|
7
8
|
email: Email;
|
|
8
9
|
prerender: PreRender;
|
|
10
|
+
ai: AI;
|
|
9
11
|
constructor(key: string);
|
|
10
12
|
}
|
package/index.js
CHANGED
|
@@ -5,12 +5,14 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const email_1 = require("./email");
|
|
6
6
|
const prerender_1 = require("./prerender");
|
|
7
7
|
const sms_1 = require("./sms");
|
|
8
|
+
const ai_1 = require("./ai");
|
|
8
9
|
tslib_1.__exportStar(require("./model"), exports);
|
|
9
10
|
class PayHos {
|
|
10
11
|
constructor(key) {
|
|
11
12
|
this.sms = new sms_1.SMS(key);
|
|
12
13
|
this.email = new email_1.Email(key);
|
|
13
14
|
this.prerender = new prerender_1.PreRender(key);
|
|
15
|
+
this.ai = new ai_1.AI(key);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
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,2CAAwC;AACxC,+BAA4B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,mCAAgC;AAChC,2CAAwC;AACxC,+BAA4B;AAC5B,6BAA0B;AAE1B,kDAAwB;AAExB,MAAa,MAAM;IAMjB,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;QACpC,IAAI,CAAC,EAAE,GAAG,IAAI,OAAE,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;CACF;AAZD,wBAYC"}
|
package/model.d.ts
CHANGED
|
@@ -29,3 +29,24 @@ export interface PreRenderOpts {
|
|
|
29
29
|
url: string;
|
|
30
30
|
cacheMs?: number;
|
|
31
31
|
}
|
|
32
|
+
export interface AIPromptOpts {
|
|
33
|
+
prompt: string;
|
|
34
|
+
provider?: 'gemini' | 'gpt';
|
|
35
|
+
model?: string;
|
|
36
|
+
temperature?: number;
|
|
37
|
+
maxOutputChars?: number;
|
|
38
|
+
maxInputChars?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface AIResponse {
|
|
41
|
+
id: number;
|
|
42
|
+
provider: 'gemini' | 'gpt';
|
|
43
|
+
model: string;
|
|
44
|
+
response: string;
|
|
45
|
+
usage: {
|
|
46
|
+
inputChars: number;
|
|
47
|
+
outputChars: number;
|
|
48
|
+
totalChars: number;
|
|
49
|
+
cost: number;
|
|
50
|
+
ratePer1000Chars: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.
|
|
4
|
+
"version": "2.5.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "mocha --require ts-node/register test/**/*.ts",
|
|
9
9
|
"deploy": "node copy-models && tsc && node copy-assets && cd dist && npm publish --access=public",
|
|
10
|
-
"unpublish": "npm unpublish @payhos/api@
|
|
10
|
+
"unpublish": "npm unpublish @payhos/api@2.3.0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"axios": "^1.3.5"
|
package/prerender.js
CHANGED
|
@@ -7,7 +7,7 @@ class PreRender {
|
|
|
7
7
|
this._apiKey = key;
|
|
8
8
|
}
|
|
9
9
|
page(opts) {
|
|
10
|
-
const path = `prerender?url=${encodeURIComponent(opts.url)}&cacheMs=${opts.cacheMs || 86400000}`;
|
|
10
|
+
const path = `prerender?url=${encodeURIComponent(opts.url)}&cacheMs=${opts.cacheMs || 86400000 * 3}`;
|
|
11
11
|
return api_service_1.apiHandler.get(path, (0, api_service_1.apiHeaders)(this._apiKey));
|
|
12
12
|
}
|
|
13
13
|
}
|
package/prerender.js.map
CHANGED
|
@@ -1 +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;
|
|
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,GAAG,CAAC,EAAE,CAAC;QACrG,OAAO,wBAAU,CAAC,GAAG,CAAS,IAAI,EAAE,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAChE,CAAC;CACF;AAXD,8BAWC"}
|