platform5-sdk 0.1.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/dist/cjs/client.js +105 -0
  4. package/dist/cjs/client.js.map +1 -0
  5. package/dist/cjs/errors.js +62 -0
  6. package/dist/cjs/errors.js.map +1 -0
  7. package/dist/cjs/index.js +13 -0
  8. package/dist/cjs/index.js.map +1 -0
  9. package/dist/cjs/package.json +1 -0
  10. package/dist/cjs/services/account.service.js +14 -0
  11. package/dist/cjs/services/account.service.js.map +1 -0
  12. package/dist/cjs/services/email.service.js +19 -0
  13. package/dist/cjs/services/email.service.js.map +1 -0
  14. package/dist/cjs/services/messages.service.js +14 -0
  15. package/dist/cjs/services/messages.service.js.map +1 -0
  16. package/dist/cjs/services/sms.service.js +19 -0
  17. package/dist/cjs/services/sms.service.js.map +1 -0
  18. package/dist/cjs/types.js +2 -0
  19. package/dist/cjs/types.js.map +1 -0
  20. package/dist/cjs/utils.js +10 -0
  21. package/dist/cjs/utils.js.map +1 -0
  22. package/dist/esm/client.js +100 -0
  23. package/dist/esm/client.js.map +1 -0
  24. package/dist/esm/errors.js +53 -0
  25. package/dist/esm/errors.js.map +1 -0
  26. package/dist/esm/index.js +3 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/services/account.service.js +11 -0
  29. package/dist/esm/services/account.service.js.map +1 -0
  30. package/dist/esm/services/email.service.js +16 -0
  31. package/dist/esm/services/email.service.js.map +1 -0
  32. package/dist/esm/services/messages.service.js +11 -0
  33. package/dist/esm/services/messages.service.js.map +1 -0
  34. package/dist/esm/services/sms.service.js +16 -0
  35. package/dist/esm/services/sms.service.js.map +1 -0
  36. package/dist/esm/types.js +2 -0
  37. package/dist/esm/types.js.map +1 -0
  38. package/dist/esm/utils.js +8 -0
  39. package/dist/esm/utils.js.map +1 -0
  40. package/dist/types/client.d.ts +31 -0
  41. package/dist/types/client.d.ts.map +1 -0
  42. package/dist/types/errors.d.ts +27 -0
  43. package/dist/types/errors.d.ts.map +1 -0
  44. package/dist/types/index.d.ts +5 -0
  45. package/dist/types/index.d.ts.map +1 -0
  46. package/dist/types/services/account.service.d.ts +8 -0
  47. package/dist/types/services/account.service.d.ts.map +1 -0
  48. package/dist/types/services/email.service.d.ts +8 -0
  49. package/dist/types/services/email.service.d.ts.map +1 -0
  50. package/dist/types/services/messages.service.d.ts +8 -0
  51. package/dist/types/services/messages.service.d.ts.map +1 -0
  52. package/dist/types/services/sms.service.d.ts +8 -0
  53. package/dist/types/services/sms.service.d.ts.map +1 -0
  54. package/dist/types/types.d.ts +57 -0
  55. package/dist/types/types.d.ts.map +1 -0
  56. package/dist/types/utils.d.ts +2 -0
  57. package/dist/types/utils.d.ts.map +1 -0
  58. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nixoncode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # platform5-sdk
2
+
3
+ TypeScript SDK for the Platform5 Developer API.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install platform5-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Platform5 } from "platform5-sdk"
15
+
16
+ const app = Platform5({
17
+ apiKey: "p5_live_abc123def456",
18
+ baseUrl: "https://api.platform5.tech",
19
+ })
20
+
21
+ // Send an SMS
22
+ const sms = await app.sms.send({
23
+ to: "+254712345678",
24
+ message: "Your appointment is confirmed for tomorrow at 10 AM.",
25
+ from: "MyBrand",
26
+ })
27
+ console.log(sms.message_id, sms.parts, sms.cost)
28
+
29
+ // Send an email
30
+ const email = await app.email.send({
31
+ to: "user@example.com",
32
+ subject: "Welcome to Platform5",
33
+ body: "Hello, thank you for signing up!",
34
+ from: "MyBrand",
35
+ })
36
+
37
+ // Check message status
38
+ const status = await app.messages.get("msg-uuid-here")
39
+
40
+ // Check balance
41
+ const balance = await app.account.getBalance()
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ ```typescript
47
+ Platform5({
48
+ apiKey: "p5_live_abc123def456", // required: your API key
49
+ baseUrl: "http://localhost:8084", // optional: defaults to http://localhost:8084
50
+ })
51
+ ```
52
+
53
+ ## API
54
+
55
+ ### `app.sms`
56
+
57
+ | Method | Description |
58
+ | ------------------ | ------------------- |
59
+ | `send(req, opts?)` | Send an SMS message |
60
+
61
+ #### SendSMSRequest
62
+
63
+ | Field | Type | Description |
64
+ | --------- | -------- | --------------------------------------------- |
65
+ | `to` | `string` | Recipient phone number (E.164 format) |
66
+ | `message` | `string` | Message content (up to ~1600 characters) |
67
+ | `from` | `string` | Verified Sender ID / alphanumeric sender name |
68
+
69
+ #### RequestOptions
70
+
71
+ | Field | Type | Description |
72
+ | ---------------- | ------------- | ------------------------------------------------------- |
73
+ | `idempotencyKey` | `string` | Custom idempotency key (auto-generated UUID by default) |
74
+ | `signal` | `AbortSignal` | Optional AbortSignal for request cancellation |
75
+
76
+ ### `app.email`
77
+
78
+ | Method | Description |
79
+ | ------------------ | ------------- |
80
+ | `send(req, opts?)` | Send an email |
81
+
82
+ #### SendEmailRequest
83
+
84
+ | Field | Type | Required | Description |
85
+ | ----------- | ------------------ | -------- | -------------------------------- |
86
+ | `to` | `string` | yes | Recipient email address |
87
+ | `subject` | `string` | yes | Email subject line |
88
+ | `body` | `string` | yes | Email body content |
89
+ | `body_type` | `"text" \| "html"` | no | Content type (default: `"text"`) |
90
+ | `from` | `string` | yes | Verified sender name |
91
+
92
+ ### `app.messages`
93
+
94
+ | Method | Description |
95
+ | --------- | -------------------------------- |
96
+ | `get(id)` | Get delivery status of a message |
97
+
98
+ ### `app.account`
99
+
100
+ | Method | Description |
101
+ | -------------- | ----------------------------------------- |
102
+ | `getBalance()` | Get available and current account balance |
103
+
104
+ ### `app.health()`
105
+
106
+ Check if the API is reachable. Throws on failure, returns `void` on success.
107
+
108
+ ## Error Handling
109
+
110
+ Every non-2xx response throws a typed error:
111
+
112
+ ```typescript
113
+ import {
114
+ UnauthorizedError,
115
+ InsufficientBalanceError,
116
+ ForbiddenError,
117
+ NotFoundError,
118
+ ValidationError,
119
+ RateLimitError,
120
+ Platform5Error,
121
+ } from "platform5-sdk"
122
+
123
+ try {
124
+ await app.sms.send({ to: "+254712345678", message: "Hello", from: "MyBrand" })
125
+ } catch (err) {
126
+ if (err instanceof RateLimitError) {
127
+ console.error(`Rate limited: ${err.limit} req/s, ${err.remaining} remaining`)
128
+ } else if (err instanceof Platform5Error) {
129
+ console.error(`API error ${err.status}: ${err.message}`)
130
+ }
131
+ }
132
+ ```
133
+
134
+ | Error | Status | When |
135
+ | -------------------------- | ------ | ---------------------------------------------------- |
136
+ | `UnauthorizedError` | 401 | Missing or invalid API key |
137
+ | `InsufficientBalanceError` | 402 | Not enough balance |
138
+ | `ForbiddenError` | 403 | Key lacks required scope |
139
+ | `NotFoundError` | 404 | Message ID not found |
140
+ | `ValidationError` | 422 | Invalid request data |
141
+ | `RateLimitError` | 429 | Too many requests (includes `limit` and `remaining`) |
142
+ | `Platform5Error` | any | Catch-all for other non-2xx responses |
143
+
144
+ Network errors (connection refused, DNS failure, timeout) are thrown as `Platform5Error` with status `0`.
145
+
146
+ ## Idempotency
147
+
148
+ `sms.send()` and `email.send()` automatically generate an `Idempotency-Key` header (UUID v4) for every request. This prevents duplicate charges on retry. Provide a custom key via `opts.idempotencyKey` if needed.
149
+
150
+ ## Retry Pattern
151
+
152
+ ```typescript
153
+ import { Platform5, Platform5Error } from "platform5-sdk"
154
+
155
+ async function sendWithRetry(to: string, message: string, from: string, retries = 3) {
156
+ for (let attempt = 1; attempt <= retries; attempt++) {
157
+ try {
158
+ return await app.sms.send({ to, message, from })
159
+ } catch (err) {
160
+ if (err instanceof Platform5Error && err.status >= 500) {
161
+ if (attempt < retries) {
162
+ const delay = Math.min(1000 * 2 ** attempt, 10000)
163
+ await new Promise((r) => setTimeout(r, delay))
164
+ continue
165
+ }
166
+ }
167
+ throw err
168
+ }
169
+ }
170
+ }
171
+ ```
172
+
173
+ ## Requirements
174
+
175
+ - Node.js 18+ (native `fetch` support)
176
+ - TypeScript 5+ (for type definitions)
177
+
178
+ ## Build
179
+
180
+ ```sh
181
+ npm run build # ESM + CJS
182
+ npm run typecheck # type-check only
183
+ npm run test # run tests
184
+ ```
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Platform5Client = exports.HttpClient = void 0;
4
+ exports.Platform5 = Platform5;
5
+ const errors_js_1 = require("./errors.js");
6
+ const sms_service_js_1 = require("./services/sms.service.js");
7
+ const email_service_js_1 = require("./services/email.service.js");
8
+ const messages_service_js_1 = require("./services/messages.service.js");
9
+ const account_service_js_1 = require("./services/account.service.js");
10
+ const DEFAULT_BASE_URL = "http://localhost:8084";
11
+ class HttpClient {
12
+ apiKey;
13
+ baseUrl;
14
+ constructor(config) {
15
+ this.apiKey = config.apiKey;
16
+ this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
17
+ }
18
+ async request(method, path, options) {
19
+ const url = new URL(path, this.baseUrl);
20
+ const headers = {
21
+ "Content-Type": "application/json",
22
+ "X-API-Key": this.apiKey,
23
+ };
24
+ if (options?.idempotencyKey) {
25
+ headers["Idempotency-Key"] = options.idempotencyKey;
26
+ }
27
+ let response;
28
+ try {
29
+ response = await fetch(url.toString(), {
30
+ method,
31
+ headers,
32
+ body: options?.body ? JSON.stringify(options.body) : undefined,
33
+ signal: options?.signal,
34
+ });
35
+ }
36
+ catch (err) {
37
+ throw new errors_js_1.Platform5Error(0, err.message, null, null);
38
+ }
39
+ const requestId = response.headers.get("X-Request-ID");
40
+ const limitHeader = response.headers.get("X-RateLimit-Limit");
41
+ const remainingHeader = response.headers.get("X-RateLimit-Remaining");
42
+ const rateLimit = limitHeader
43
+ ? { limit: parseInt(limitHeader, 10), remaining: parseInt(remainingHeader ?? "0", 10) }
44
+ : undefined;
45
+ const body = (await response.json().catch(() => ({
46
+ success: false,
47
+ message: response.statusText || "Unknown error",
48
+ data: null,
49
+ errors: null,
50
+ })));
51
+ if (!response.ok) {
52
+ throw this.toError(response.status, body, requestId, rateLimit);
53
+ }
54
+ return body;
55
+ }
56
+ toError(status, body, requestId, rateLimit) {
57
+ const { message, errors } = body;
58
+ switch (status) {
59
+ case 401:
60
+ return new errors_js_1.UnauthorizedError(status, message, errors, requestId);
61
+ case 402:
62
+ return new errors_js_1.InsufficientBalanceError(status, message, errors, requestId);
63
+ case 403:
64
+ return new errors_js_1.ForbiddenError(status, message, errors, requestId);
65
+ case 404:
66
+ return new errors_js_1.NotFoundError(status, message, errors, requestId);
67
+ case 422:
68
+ return new errors_js_1.ValidationError(status, message, errors, requestId);
69
+ case 429:
70
+ return new errors_js_1.RateLimitError(status, message, errors, requestId, rateLimit?.limit ?? NaN, rateLimit?.remaining ?? NaN);
71
+ default:
72
+ return new errors_js_1.Platform5Error(status, message, errors, requestId);
73
+ }
74
+ }
75
+ }
76
+ exports.HttpClient = HttpClient;
77
+ class Platform5Client {
78
+ http;
79
+ _sms;
80
+ _email;
81
+ _messages;
82
+ _account;
83
+ constructor(config) {
84
+ this.http = new HttpClient(config);
85
+ }
86
+ get sms() {
87
+ return (this._sms ??= new sms_service_js_1.SmsService(this.http));
88
+ }
89
+ get email() {
90
+ return (this._email ??= new email_service_js_1.EmailService(this.http));
91
+ }
92
+ get messages() {
93
+ return (this._messages ??= new messages_service_js_1.MessagesService(this.http));
94
+ }
95
+ get account() {
96
+ return (this._account ??= new account_service_js_1.AccountService(this.http));
97
+ }
98
+ async health() {
99
+ await this.http.request("GET", "/health");
100
+ }
101
+ }
102
+ exports.Platform5Client = Platform5Client;
103
+ function Platform5(config) {
104
+ return new Platform5Client(config);
105
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAuHA,8BAEC;AAxHD,2CAQoB;AACpB,8DAAsD;AACtD,kEAA0D;AAC1D,wEAAgE;AAChE,sEAA8D;AAE9D,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAEhD,MAAa,UAAU;IACb,MAAM,CAAQ;IACd,OAAO,CAAQ;IAEvB,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,IAAY,EACZ,OAA2E;QAE3E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACvC,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,IAAI,CAAC,MAAM;SACzB,CAAA;QAED,IAAI,OAAO,EAA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I,OAAO;QACT,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,mCAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAC3C,CAAC;CACF;AA9BD,0CA8BC;AAED,SAAgB,SAAS,CAAC,MAAuB;IAC/C,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.ForbiddenError = exports.InsufficientBalanceError = exports.UnauthorizedError = exports.Platform5Error = void 0;
4
+ class Platform5Error extends Error {
5
+ status;
6
+ errors;
7
+ requestId;
8
+ constructor(status, message, errors, requestId) {
9
+ super(message);
10
+ this.status = status;
11
+ this.errors = errors;
12
+ this.requestId = requestId;
13
+ this.name = "Platform5Error";
14
+ }
15
+ }
16
+ exports.Platform5Error = Platform5Error;
17
+ class UnauthorizedError extends Platform5Error {
18
+ constructor(status, message, errors, requestId) {
19
+ super(status, message, errors, requestId);
20
+ this.name = "UnauthorizedError";
21
+ }
22
+ }
23
+ exports.UnauthorizedError = UnauthorizedError;
24
+ class InsufficientBalanceError extends Platform5Error {
25
+ constructor(status, message, errors, requestId) {
26
+ super(status, message, errors, requestId);
27
+ this.name = "InsufficientBalanceError";
28
+ }
29
+ }
30
+ exports.InsufficientBalanceError = InsufficientBalanceError;
31
+ class ForbiddenError extends Platform5Error {
32
+ constructor(status, message, errors, requestId) {
33
+ super(status, message, errors, requestId);
34
+ this.name = "ForbiddenError";
35
+ }
36
+ }
37
+ exports.ForbiddenError = ForbiddenError;
38
+ class NotFoundError extends Platform5Error {
39
+ constructor(status, message, errors, requestId) {
40
+ super(status, message, errors, requestId);
41
+ this.name = "NotFoundError";
42
+ }
43
+ }
44
+ exports.NotFoundError = NotFoundError;
45
+ class ValidationError extends Platform5Error {
46
+ constructor(status, message, errors, requestId) {
47
+ super(status, message, errors, requestId);
48
+ this.name = "ValidationError";
49
+ }
50
+ }
51
+ exports.ValidationError = ValidationError;
52
+ class RateLimitError extends Platform5Error {
53
+ limit;
54
+ remaining;
55
+ constructor(status, message, errors, requestId, limit, remaining) {
56
+ super(status, message, errors, requestId);
57
+ this.name = "RateLimitError";
58
+ this.limit = limit;
59
+ this.remaining = remaining;
60
+ }
61
+ }
62
+ exports.RateLimitError = RateLimitError;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,cAAe,SAAQ,KAAK;IAE9B;IAEA;IACA;IAJT,YACS,MAAc,EACrB,OAAe,EACR,MAAqB,EACrB,SAAwB;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAA;QALP,WAAM,GAAN,MAAM,CAAQ;QAEd,WAAM,GAAN,MAAM,CAAe;QACrB,cAAS,GAAT,SAAS,CAAe;QAG/B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF;AAVD,wCAUC;AAED,MAAa,iBAAkB,SAAQ,cAAc;IACnD,YAAY,MAAc,EAAE,OAAe,EAAE,MAAqB,EAAE,SAAwB;QAC1F,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AALD,8CAKC;AAED,MAAa,wBAAyB,SAAQ,cAAc;IAC1D,YAAY,MAAc,EAAE,OAAe,EAAE,MAAqB,EAAE,SAAwB;QAC1F,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;CACF;AALD,4DAKC;AAED,MAAa,cAAe,SAAQ,cAAc;IAChD,YAAY,MAAc,EAAE,OAAe,EAAE,MAAqB,EAAE,SAAwB;QAC1F,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF;AALD,wCAKC;AAED,MAAa,aAAc,SAAQ,cAAc;IAC/C,YAAY,MAAc,EAAE,OAAe,EAAE,MAAqB,EAAE,SAAwB;QAC1F,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF;AALD,sCAKC;AAED,MAAa,eAAgB,SAAQ,cAAc;IACjD,YAAY,MAAc,EAAE,OAAe,EAAE,MAAqB,EAAE,SAAwB;QAC1F,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AALD,0CAKC;AAED,MAAa,cAAe,SAAQ,cAAc;IAChD,KAAK,CAAQ;IACb,SAAS,CAAQ;IAEjB,YACE,MAAc,EACd,OAAe,EACf,MAAqB,EACrB,SAAwB,EACxB,KAAa,EACb,SAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CACF;AAjBD,wCAiBC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.ForbiddenError = exports.InsufficientBalanceError = exports.UnauthorizedError = exports.Platform5Error = exports.Platform5 = void 0;
4
+ var client_js_1 = require("./client.js");
5
+ Object.defineProperty(exports, "Platform5", { enumerable: true, get: function () { return client_js_1.Platform5; } });
6
+ var errors_js_1 = require("./errors.js");
7
+ Object.defineProperty(exports, "Platform5Error", { enumerable: true, get: function () { return errors_js_1.Platform5Error; } });
8
+ Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return errors_js_1.UnauthorizedError; } });
9
+ Object.defineProperty(exports, "InsufficientBalanceError", { enumerable: true, get: function () { return errors_js_1.InsufficientBalanceError; } });
10
+ Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return errors_js_1.ForbiddenError; } });
11
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
12
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_js_1.ValidationError; } });
13
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAGlB,yCAQoB;AAPlB,2GAAA,cAAc,OAAA;AACd,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,2GAAA,cAAc,OAAA;AACd,0GAAA,aAAa,OAAA;AACb,4GAAA,eAAe,OAAA;AACf,2GAAA,cAAc,OAAA"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountService = void 0;
4
+ class AccountService {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ async getBalance() {
10
+ const res = await this.client.request("GET", "/v1/balance");
11
+ return res.data;
12
+ }
13
+ }
14
+ exports.AccountService = AccountService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.service.js","sourceRoot":"","sources":["../../../src/services/account.service.ts"],"names":[],"mappings":";;;AAGA,MAAa,cAAc;IACL;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,UAAU;QACd,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAkB,KAAK,EAAE,aAAa,CAAC,CAAA;QAC5E,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF;AAPD,wCAOC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmailService = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ class EmailService {
6
+ client;
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ async send(req, opts) {
11
+ const res = await this.client.request("POST", "/v1/email/send", {
12
+ body: req,
13
+ idempotencyKey: opts?.idempotencyKey ?? (0, utils_js_1.generateUUID)(),
14
+ signal: opts?.signal,
15
+ });
16
+ return res.data;
17
+ }
18
+ }
19
+ exports.EmailService = EmailService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.service.js","sourceRoot":"","sources":["../../../src/services/email.service.ts"],"names":[],"mappings":";;;AAEA,0CAA0C;AAE1C,MAAa,YAAY;IACH;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,IAAI,CAAC,GAAqB,EAAE,IAAqB;QACrD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAoB,MAAM,EAAE,gBAAgB,EAAE;YACjF,IAAI,EAAE,GAAG;YACT,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,IAAA,uBAAY,GAAE;YACtD,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF;AAXD,oCAWC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessagesService = void 0;
4
+ class MessagesService {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ async get(id) {
10
+ const res = await this.client.request("GET", `/v1/messages/${encodeURIComponent(id)}`);
11
+ return res.data;
12
+ }
13
+ }
14
+ exports.MessagesService = MessagesService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.service.js","sourceRoot":"","sources":["../../../src/services/messages.service.ts"],"names":[],"mappings":";;;AAGA,MAAa,eAAe;IACN;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAwB,KAAK,EAAE,gBAAgB,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;QAC7G,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF;AAPD,0CAOC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmsService = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ class SmsService {
6
+ client;
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ async send(req, opts) {
11
+ const res = await this.client.request("POST", "/v1/sms/send", {
12
+ body: req,
13
+ idempotencyKey: opts?.idempotencyKey ?? (0, utils_js_1.generateUUID)(),
14
+ signal: opts?.signal,
15
+ });
16
+ return res.data;
17
+ }
18
+ }
19
+ exports.SmsService = SmsService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sms.service.js","sourceRoot":"","sources":["../../../src/services/sms.service.ts"],"names":[],"mappings":";;;AAEA,0CAA0C;AAE1C,MAAa,UAAU;IACD;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,IAAI,CAAC,GAAmB,EAAE,IAAqB;QACnD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAkB,MAAM,EAAE,cAAc,EAAE;YAC7E,IAAI,EAAE,GAAG;YACT,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,IAAA,uBAAY,GAAE;YACtD,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF;AAXD,gCAWC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateUUID = generateUUID;
4
+ function generateUUID() {
5
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
6
+ const r = (Math.random() * 16) | 0;
7
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
8
+ return v.toString(16);
9
+ });
10
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;AAAA,oCAMC;AAND,SAAgB,YAAY;IAC1B,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;QAClC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;QACzC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,100 @@
1
+ import { ForbiddenError, InsufficientBalanceError, NotFoundError, Platform5Error, RateLimitError, UnauthorizedError, ValidationError, } from "./errors.js";
2
+ import { SmsService } from "./services/sms.service.js";
3
+ import { EmailService } from "./services/email.service.js";
4
+ import { MessagesService } from "./services/messages.service.js";
5
+ import { AccountService } from "./services/account.service.js";
6
+ const DEFAULT_BASE_URL = "http://localhost:8084";
7
+ export class HttpClient {
8
+ apiKey;
9
+ baseUrl;
10
+ constructor(config) {
11
+ this.apiKey = config.apiKey;
12
+ this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
13
+ }
14
+ async request(method, path, options) {
15
+ const url = new URL(path, this.baseUrl);
16
+ const headers = {
17
+ "Content-Type": "application/json",
18
+ "X-API-Key": this.apiKey,
19
+ };
20
+ if (options?.idempotencyKey) {
21
+ headers["Idempotency-Key"] = options.idempotencyKey;
22
+ }
23
+ let response;
24
+ try {
25
+ response = await fetch(url.toString(), {
26
+ method,
27
+ headers,
28
+ body: options?.body ? JSON.stringify(options.body) : undefined,
29
+ signal: options?.signal,
30
+ });
31
+ }
32
+ catch (err) {
33
+ throw new Platform5Error(0, err.message, null, null);
34
+ }
35
+ const requestId = response.headers.get("X-Request-ID");
36
+ const limitHeader = response.headers.get("X-RateLimit-Limit");
37
+ const remainingHeader = response.headers.get("X-RateLimit-Remaining");
38
+ const rateLimit = limitHeader
39
+ ? { limit: parseInt(limitHeader, 10), remaining: parseInt(remainingHeader ?? "0", 10) }
40
+ : undefined;
41
+ const body = (await response.json().catch(() => ({
42
+ success: false,
43
+ message: response.statusText || "Unknown error",
44
+ data: null,
45
+ errors: null,
46
+ })));
47
+ if (!response.ok) {
48
+ throw this.toError(response.status, body, requestId, rateLimit);
49
+ }
50
+ return body;
51
+ }
52
+ toError(status, body, requestId, rateLimit) {
53
+ const { message, errors } = body;
54
+ switch (status) {
55
+ case 401:
56
+ return new UnauthorizedError(status, message, errors, requestId);
57
+ case 402:
58
+ return new InsufficientBalanceError(status, message, errors, requestId);
59
+ case 403:
60
+ return new ForbiddenError(status, message, errors, requestId);
61
+ case 404:
62
+ return new NotFoundError(status, message, errors, requestId);
63
+ case 422:
64
+ return new ValidationError(status, message, errors, requestId);
65
+ case 429:
66
+ return new RateLimitError(status, message, errors, requestId, rateLimit?.limit ?? NaN, rateLimit?.remaining ?? NaN);
67
+ default:
68
+ return new Platform5Error(status, message, errors, requestId);
69
+ }
70
+ }
71
+ }
72
+ export class Platform5Client {
73
+ http;
74
+ _sms;
75
+ _email;
76
+ _messages;
77
+ _account;
78
+ constructor(config) {
79
+ this.http = new HttpClient(config);
80
+ }
81
+ get sms() {
82
+ return (this._sms ??= new SmsService(this.http));
83
+ }
84
+ get email() {
85
+ return (this._email ??= new EmailService(this.http));
86
+ }
87
+ get messages() {
88
+ return (this._messages ??= new MessagesService(this.http));
89
+ }
90
+ get account() {
91
+ return (this._account ??= new AccountService(this.http));
92
+ }
93
+ async health() {
94
+ await this.http.request("GET", "/health");
95
+ }
96
+ }
97
+ export function Platform5(config) {
98
+ return new Platform5Client(config);
99
+ }
100
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAEhD,MAAM,OAAO,UAAU;IACb,M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3C,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAAC,MAAuB;IAC/C,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,53 @@
1
+ export class Platform5Error extends Error {
2
+ status;
3
+ errors;
4
+ requestId;
5
+ constructor(status, message, errors, requestId) {
6
+ super(message);
7
+ this.status = status;
8
+ this.errors = errors;
9
+ this.requestId = requestId;
10
+ this.name = "Platform5Error";
11
+ }
12
+ }
13
+ export class UnauthorizedError extends Platform5Error {
14
+ constructor(status, message, errors, requestId) {
15
+ super(status, message, errors, requestId);
16
+ this.name = "UnauthorizedError";
17
+ }
18
+ }
19
+ export class InsufficientBalanceError extends Platform5Error {
20
+ constructor(status, message, errors, requestId) {
21
+ super(status, message, errors, requestId);
22
+ this.name = "InsufficientBalanceError";
23
+ }
24
+ }
25
+ export class ForbiddenError extends Platform5Error {
26
+ constructor(status, message, errors, requestId) {
27
+ super(status, message, errors, requestId);
28
+ this.name = "ForbiddenError";
29
+ }
30
+ }
31
+ export class NotFoundError extends Platform5Error {
32
+ constructor(status, message, errors, requestId) {
33
+ super(status, message, errors, requestId);
34
+ this.name = "NotFoundError";
35
+ }
36
+ }
37
+ export class ValidationError extends Platform5Error {
38
+ constructor(status, message, errors, requestId) {
39
+ super(status, message, errors, requestId);
40
+ this.name = "ValidationError";
41
+ }
42
+ }
43
+ export class RateLimitError extends Platform5Error {
44
+ limit;
45
+ remaining;
46
+ constructor(status, message, errors, requestId, limit, remaining) {
47
+ super(status, message, errors, requestId);
48
+ this.name = "RateLimitError";
49
+ this.limit = limit;
50
+ this.remaining = remaining;
51
+ }
52
+ }
53
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAE9B;IAEA;IACA;IAJT,YACS,MAAc,EACrB,OAAe,EACR,MAAqB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AC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,cAAc;IAChD,KAAK,CAAQ;IACb,SAAS,CAAQ;IAEjB,YACE,MAAc,EACd,OAAe,EACf,MAAqB,EACrB,SAAwB,EACxB,KAAa,EACb,SAAiB;QAEjB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { Platform5 } from "./client.js";
2
+ export { Platform5Error, UnauthorizedError, InsufficientBalanceError, ForbiddenError, NotFoundError, ValidationError, RateLimitError, } from "./errors.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,aAAa,CAAA"}
@@ -0,0 +1,11 @@
1
+ export class AccountService {
2
+ client;
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ async getBalance() {
7
+ const res = await this.client.request("GET", "/v1/balance");
8
+ return res.data;
9
+ }
10
+ }
11
+ //# sourceMappingURL=account.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.service.js","sourceRoot":"","sources":["../../../src/services/account.service.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,cAAc;IACL;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,UAAU;QACd,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAkB,KAAK,EAAE,aAAa,CAAC,CAAA;QAC5E,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { generateUUID } from "../utils.js";
2
+ export class EmailService {
3
+ client;
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+ async send(req, opts) {
8
+ const res = await this.client.request("POST", "/v1/email/send", {
9
+ body: req,
10
+ idempotencyKey: opts?.idempotencyKey ?? generateUUID(),
11
+ signal: opts?.signal,
12
+ });
13
+ return res.data;
14
+ }
15
+ }
16
+ //# sourceMappingURL=email.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.service.js","sourceRoot":"","sources":["../../../src/services/email.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,OAAO,YAAY;IACH;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,IAAI,CAAC,GAAqB,EAAE,IAAqB;QACrD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAoB,MAAM,EAAE,gBAAgB,EAAE;YACjF,IAAI,EAAE,GAAG;YACT,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,YAAY,EAAE;YACtD,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ export class MessagesService {
2
+ client;
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ async get(id) {
7
+ const res = await this.client.request("GET", `/v1/messages/${encodeURIComponent(id)}`);
8
+ return res.data;
9
+ }
10
+ }
11
+ //# sourceMappingURL=messages.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.service.js","sourceRoot":"","sources":["../../../src/services/messages.service.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,eAAe;IACN;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAwB,KAAK,EAAE,gBAAgB,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;QAC7G,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { generateUUID } from "../utils.js";
2
+ export class SmsService {
3
+ client;
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+ async send(req, opts) {
8
+ const res = await this.client.request("POST", "/v1/sms/send", {
9
+ body: req,
10
+ idempotencyKey: opts?.idempotencyKey ?? generateUUID(),
11
+ signal: opts?.signal,
12
+ });
13
+ return res.data;
14
+ }
15
+ }
16
+ //# sourceMappingURL=sms.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sms.service.js","sourceRoot":"","sources":["../../../src/services/sms.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,OAAO,UAAU;IACD;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C,KAAK,CAAC,IAAI,CAAC,GAAmB,EAAE,IAAqB;QACnD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAkB,MAAM,EAAE,cAAc,EAAE;YAC7E,IAAI,EAAE,GAAG;YACT,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,YAAY,EAAE;YACtD,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,IAAK,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export function generateUUID() {
2
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
3
+ const r = (Math.random() * 16) | 0;
4
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
5
+ return v.toString(16);
6
+ });
7
+ }
8
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY;IAC1B,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAA;QAClC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;QACzC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { APIResponse, Platform5Config } from "./types.js";
2
+ import { SmsService } from "./services/sms.service.js";
3
+ import { EmailService } from "./services/email.service.js";
4
+ import { MessagesService } from "./services/messages.service.js";
5
+ import { AccountService } from "./services/account.service.js";
6
+ export declare class HttpClient {
7
+ private apiKey;
8
+ private baseUrl;
9
+ constructor(config: Platform5Config);
10
+ request<T>(method: string, path: string, options?: {
11
+ body?: unknown;
12
+ idempotencyKey?: string;
13
+ signal?: AbortSignal;
14
+ }): Promise<APIResponse<T>>;
15
+ private toError;
16
+ }
17
+ export declare class Platform5Client {
18
+ private http;
19
+ private _sms?;
20
+ private _email?;
21
+ private _messages?;
22
+ private _account?;
23
+ constructor(config: Platform5Config);
24
+ get sms(): SmsService;
25
+ get email(): EmailService;
26
+ get messages(): MessagesService;
27
+ get account(): AccountService;
28
+ health(): Promise<void>;
29
+ }
30
+ export declare function Platform5(config: Platform5Config): Platform5Client;
31
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAU9D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAI9D,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,eAAe;IAK7B,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAC1E,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IA6C1B,OAAO,CAAC,OAAO;CA+BhB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,IAAI,CAAC,CAAY;IACzB,OAAO,CAAC,MAAM,CAAC,CAAc;IAC7B,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,QAAQ,CAAC,CAAgB;gBAErB,MAAM,EAAE,eAAe;IAInC,IAAI,GAAG,IAAI,UAAU,CAEpB;IAED,IAAI,KAAK,IAAI,YAAY,CAExB;IAED,IAAI,QAAQ,IAAI,eAAe,CAE9B;IAED,IAAI,OAAO,IAAI,cAAc,CAE5B;IAEK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAElE"}
@@ -0,0 +1,27 @@
1
+ export declare class Platform5Error extends Error {
2
+ status: number;
3
+ errors: string | null;
4
+ requestId: string | null;
5
+ constructor(status: number, message: string, errors: string | null, requestId: string | null);
6
+ }
7
+ export declare class UnauthorizedError extends Platform5Error {
8
+ constructor(status: number, message: string, errors: string | null, requestId: string | null);
9
+ }
10
+ export declare class InsufficientBalanceError extends Platform5Error {
11
+ constructor(status: number, message: string, errors: string | null, requestId: string | null);
12
+ }
13
+ export declare class ForbiddenError extends Platform5Error {
14
+ constructor(status: number, message: string, errors: string | null, requestId: string | null);
15
+ }
16
+ export declare class NotFoundError extends Platform5Error {
17
+ constructor(status: number, message: string, errors: string | null, requestId: string | null);
18
+ }
19
+ export declare class ValidationError extends Platform5Error {
20
+ constructor(status: number, message: string, errors: string | null, requestId: string | null);
21
+ }
22
+ export declare class RateLimitError extends Platform5Error {
23
+ limit: number;
24
+ remaining: number;
25
+ constructor(status: number, message: string, errors: string | null, requestId: string | null, limit: number, remaining: number);
26
+ }
27
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;IAE9B,MAAM,EAAE,MAAM;IAEd,MAAM,EAAE,MAAM,GAAG,IAAI;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI;gBAHxB,MAAM,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACR,MAAM,EAAE,MAA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ientBalanceError, ForbiddenError, NotFoundError, ValidationError, RateLimitError, } from "./errors.js";
4
+ export type { Platform5Config, RequestOptions, APIResponse, SendSMSRequest, SendSMSResponse, SendEmailRequest, SendEmailResponse, MessageStatusResponse, BalanceResponse, } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,aAAa,CAAA;AAEpB,YAAY,EACV,eAAe,EACf,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,GAChB,MAAM,YAAY,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { BalanceResponse } from "../types.js";
3
+ export declare class AccountService {
4
+ private client;
5
+ constructor(client: HttpClient);
6
+ getBalance(): Promise<BalanceResponse>;
7
+ }
8
+ //# sourceMappingURL=account.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.service.d.ts","sourceRoot":"","sources":["../../../src/services/account.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEhC,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;CAI7C"}
@@ -0,0 +1,8 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { RequestOptions, SendEmailRequest, SendEmailResponse } from "../types.js";
3
+ export declare class EmailService {
4
+ private client;
5
+ constructor(client: HttpClient);
6
+ send(req: SendEmailRequest, opts?: RequestOptions): Promise<SendEmailResponse>;
7
+ }
8
+ //# sourceMappingURL=email.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.service.d.ts","sourceRoot":"","sources":["../../../src/services/email.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAGtF,qBAAa,YAAY;IACX,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEhC,IAAI,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAQrF"}
@@ -0,0 +1,8 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { MessageStatusResponse } from "../types.js";
3
+ export declare class MessagesService {
4
+ private client;
5
+ constructor(client: HttpClient);
6
+ get(id: string): Promise<MessageStatusResponse>;
7
+ }
8
+ //# sourceMappingURL=messages.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.service.d.ts","sourceRoot":"","sources":["../../../src/services/messages.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEhC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAItD"}
@@ -0,0 +1,8 @@
1
+ import type { HttpClient } from "../client.js";
2
+ import type { RequestOptions, SendSMSRequest, SendSMSResponse } from "../types.js";
3
+ export declare class SmsService {
4
+ private client;
5
+ constructor(client: HttpClient);
6
+ send(req: SendSMSRequest, opts?: RequestOptions): Promise<SendSMSResponse>;
7
+ }
8
+ //# sourceMappingURL=sms.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sms.service.d.ts","sourceRoot":"","sources":["../../../src/services/sms.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGlF,qBAAa,UAAU;IACT,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEhC,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAQjF"}
@@ -0,0 +1,57 @@
1
+ export interface Platform5Config {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ export interface RequestOptions {
6
+ idempotencyKey?: string;
7
+ signal?: AbortSignal;
8
+ }
9
+ export interface APIResponse<T> {
10
+ success: boolean;
11
+ message: string;
12
+ data: T;
13
+ errors: string | null;
14
+ }
15
+ export interface SendSMSRequest {
16
+ to: string;
17
+ message: string;
18
+ from: string;
19
+ }
20
+ export interface SendSMSResponse {
21
+ message_id: string;
22
+ to: string;
23
+ sender_name: string;
24
+ parts: number;
25
+ cost: number;
26
+ currency: string;
27
+ status: "queued";
28
+ }
29
+ export interface SendEmailRequest {
30
+ to: string;
31
+ subject: string;
32
+ body: string;
33
+ body_type?: "text" | "html";
34
+ from: string;
35
+ }
36
+ export interface SendEmailResponse {
37
+ message_id: string;
38
+ status: "queued";
39
+ }
40
+ export interface MessageStatusResponse {
41
+ id: string;
42
+ to: string;
43
+ sender_name: string;
44
+ parts: number;
45
+ cost: number;
46
+ status: "queued" | "forwarded" | "sent" | "delivered" | "failed" | "rejected";
47
+ created_at: string;
48
+ sent_at: string | null;
49
+ delivered_at: string | null;
50
+ error: string | null;
51
+ }
52
+ export interface BalanceResponse {
53
+ available_balance: number;
54
+ current_balance: number;
55
+ currency: string;
56
+ }
57
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,QAAQ,CAAA;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,QAAQ,CAAA;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC7E,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAA;IACzB,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;CACjB"}
@@ -0,0 +1,2 @@
1
+ export declare function generateUUID(): string;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,IAAI,MAAM,CAMrC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "platform5-sdk",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for the Platform5 Developer API — send SMS, email, and more",
5
+ "keywords": [
6
+ "platform5",
7
+ "sms",
8
+ "email",
9
+ "api",
10
+ "sdk",
11
+ "typescript",
12
+ "communications"
13
+ ],
14
+ "author": "nixoncode",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/nixoncode/platform5-sdk-typescript.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/nixoncode/platform5-sdk-typescript/issues"
22
+ },
23
+ "homepage": "https://github.com/nixoncode/platform5-sdk-typescript#readme",
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/esm/index.js",
28
+ "require": "./dist/cjs/index.js",
29
+ "types": "./dist/types/index.d.ts"
30
+ }
31
+ },
32
+ "main": "./dist/cjs/index.js",
33
+ "module": "./dist/esm/index.js",
34
+ "types": "./dist/types/index.d.ts",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "npm run build:esm && npm run build:cjs",
40
+ "build:esm": "tsc -p tsconfig.json",
41
+ "build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
42
+ "typecheck": "tsc --noEmit -p tsconfig.json",
43
+ "lint": "eslint src/",
44
+ "format": "prettier --write .",
45
+ "format:check": "prettier --check .",
46
+ "test": "vitest run",
47
+ "prepublishOnly": "npm run build"
48
+ },
49
+ "devDependencies": {
50
+ "@eslint/js": "^10.0.1",
51
+ "eslint": "^10.7.0",
52
+ "eslint-config-prettier": "^10.1.8",
53
+ "prettier": "^3.9.5",
54
+ "typescript": "^5.7.0",
55
+ "typescript-eslint": "^8.64.0",
56
+ "vitest": "^3.0.0"
57
+ },
58
+ "packageManager": "npm@11.12.1"
59
+ }