@rewritetoday/types 1.0.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/LICENSE +201 -0
- package/README.md +85 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/v1/index.d.ts +9 -0
- package/dist/v1/index.js +9 -0
- package/dist/v1/resources/apiKeys.d.ts +38 -0
- package/dist/v1/resources/apiKeys.js +17 -0
- package/dist/v1/resources/globals.d.ts +8 -0
- package/dist/v1/resources/globals.js +1 -0
- package/dist/v1/resources/logs.d.ts +40 -0
- package/dist/v1/resources/logs.js +8 -0
- package/dist/v1/resources/message.d.ts +96 -0
- package/dist/v1/resources/message.js +40 -0
- package/dist/v1/resources/otp.d.ts +16 -0
- package/dist/v1/resources/otp.js +1 -0
- package/dist/v1/resources/templates.d.ts +31 -0
- package/dist/v1/resources/templates.js +1 -0
- package/dist/v1/resources/webhooks.d.ts +52 -0
- package/dist/v1/resources/webhooks.js +32 -0
- package/dist/v1/rest.d.ts +202 -0
- package/dist/v1/rest.js +1 -0
- package/dist/v1/routes.d.ts +56 -0
- package/dist/v1/routes.js +96 -0
- package/dist/v1/utils.d.ts +2 -0
- package/dist/v1/utils.js +3 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.js +9 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Rewrite Types
|
|
4
|
+
|
|
5
|
+
[@rewritetoday/types](https://www.npmjs.com/package/@rewritetoday/types), an official **TypeScript types** for the **Rewrite API**.
|
|
6
|
+
|
|
7
|
+
This package provides shared resource models, request/response contracts, and route builders used by Rewrite SDKs and applications. It is designed to keep API integrations strongly typed and consistent across projects.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
You can use this package with your *favorite package manager*
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add @rewritetoday/types
|
|
17
|
+
# Or
|
|
18
|
+
npm install @rewritetoday/types
|
|
19
|
+
# Or
|
|
20
|
+
pnpm install @rewritetoday/types
|
|
21
|
+
# Or
|
|
22
|
+
yarn add @rewritetoday/types
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
<div align="center">
|
|
26
|
+
|
|
27
|
+
## Using
|
|
28
|
+
|
|
29
|
+
### How we document our types
|
|
30
|
+
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
- Prefix `API*`
|
|
34
|
+
Represents general API structures (returned objects, internal models, etc.).
|
|
35
|
+
|
|
36
|
+
- Prefix `REST<HTTPMethod>*`
|
|
37
|
+
Types used in direct API requests.
|
|
38
|
+
- Suffix Body → request body payload
|
|
39
|
+
E.g.: `RESTPostCreateTemplateBody`
|
|
40
|
+
|
|
41
|
+
- Suffix `QueryParams` → query string parameters
|
|
42
|
+
E.g.: `RESTGetListWebhooksQueryParams`
|
|
43
|
+
|
|
44
|
+
- Suffix `Data` → data returned by the API
|
|
45
|
+
E.g.: `RESTGetListWebhooksData`
|
|
46
|
+
|
|
47
|
+
<div align="center">
|
|
48
|
+
|
|
49
|
+
### Typing API Responses
|
|
50
|
+
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { REST } from '@rewritetoday/rest';
|
|
55
|
+
import { Routes, type RESTGetProjectData } from '@rewritetoday/types/v1';
|
|
56
|
+
|
|
57
|
+
const rest = new REST(process.env.REWRITE_API_KEY);
|
|
58
|
+
|
|
59
|
+
// Return type: Promise<RESTGetWebhooksData>
|
|
60
|
+
async function fetchHooks() {
|
|
61
|
+
const data = await rest.get<RESTGetWebhooksData>(Routes.webhooks.list());
|
|
62
|
+
|
|
63
|
+
return data
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
<div align="center">
|
|
68
|
+
|
|
69
|
+
### Using Route Builders
|
|
70
|
+
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { API_VERSION API_BASE_URL, Routes } from '@rewritetoday/types/v1';
|
|
75
|
+
|
|
76
|
+
// https://api.rewritetoday.com/v1/templates
|
|
77
|
+
const CREATE_TEMPLATE_URL = `${API_BASE_URL}/${API_VERSION}/${Routes.templates.create()}`;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
<div align="center">
|
|
81
|
+
|
|
82
|
+
Made with 🤍 by the Rewrite team. <br />
|
|
83
|
+
SMS the way it should be.
|
|
84
|
+
|
|
85
|
+
</div>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { version } from './version';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { version } from './version';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './resources/apiKeys';
|
|
2
|
+
export * from './resources/globals';
|
|
3
|
+
export * from './resources/logs';
|
|
4
|
+
export * from './resources/message';
|
|
5
|
+
export * from './resources/otp';
|
|
6
|
+
export * from './resources/templates';
|
|
7
|
+
export * from './resources/webhooks';
|
|
8
|
+
export * from './rest';
|
|
9
|
+
export { API_BASE_URL, Routes } from './routes';
|
package/dist/v1/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './resources/apiKeys';
|
|
2
|
+
export * from './resources/globals';
|
|
3
|
+
export * from './resources/logs';
|
|
4
|
+
export * from './resources/message';
|
|
5
|
+
export * from './resources/otp';
|
|
6
|
+
export * from './resources/templates';
|
|
7
|
+
export * from './resources/webhooks';
|
|
8
|
+
export * from './rest';
|
|
9
|
+
export { API_BASE_URL, Routes } from './routes';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Snowflake } from './globals';
|
|
2
|
+
/**
|
|
3
|
+
* https://docs.rewritetoday.com/api-reference/api-keys
|
|
4
|
+
*/
|
|
5
|
+
export interface APIAPIKey {
|
|
6
|
+
/** API key ID in {@link Snowflake} format. */
|
|
7
|
+
id: Snowflake;
|
|
8
|
+
/** Display name of the API key (1-32 max). */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Project ID in {@link Snowflake} format. */
|
|
11
|
+
projectId: Snowflake;
|
|
12
|
+
/** Allowed scopes for this key. */
|
|
13
|
+
scopes: APIKeyScope[];
|
|
14
|
+
/** Prefix used in the API key. */
|
|
15
|
+
prefix: string;
|
|
16
|
+
/** Timestamp when the API key was last used (~5 minutes late). */
|
|
17
|
+
lastUsedAt?: string;
|
|
18
|
+
/** Optional description of the API key (1-62 max). */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Timestamp when Rewrite created the API key. */
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* https://docs.rewritetoday.com/api-reference/api-keys
|
|
25
|
+
*/
|
|
26
|
+
export declare enum APIKeyScope {
|
|
27
|
+
Wildcard = "*",
|
|
28
|
+
ReadProject = "project:read",
|
|
29
|
+
ReadAPIKeys = "project:api_keys:read",
|
|
30
|
+
WriteProject = "project:write",
|
|
31
|
+
ReadWebhooks = "project:webhooks:read",
|
|
32
|
+
WriteTemplate = "project:templates:write",
|
|
33
|
+
ReadTemplates = "project:templates:read",
|
|
34
|
+
WriteWebhooks = "project:webhooks:write",
|
|
35
|
+
WriteMessages = "message:write",
|
|
36
|
+
ReadMessages = "message:read",
|
|
37
|
+
ReadLogs = "project:logs:read"
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://docs.rewritetoday.com/api-reference/api-keys
|
|
3
|
+
*/
|
|
4
|
+
export var APIKeyScope;
|
|
5
|
+
(function (APIKeyScope) {
|
|
6
|
+
APIKeyScope["Wildcard"] = "*";
|
|
7
|
+
APIKeyScope["ReadProject"] = "project:read";
|
|
8
|
+
APIKeyScope["ReadAPIKeys"] = "project:api_keys:read";
|
|
9
|
+
APIKeyScope["WriteProject"] = "project:write";
|
|
10
|
+
APIKeyScope["ReadWebhooks"] = "project:webhooks:read";
|
|
11
|
+
APIKeyScope["WriteTemplate"] = "project:templates:write";
|
|
12
|
+
APIKeyScope["ReadTemplates"] = "project:templates:read";
|
|
13
|
+
APIKeyScope["WriteWebhooks"] = "project:webhooks:write";
|
|
14
|
+
APIKeyScope["WriteMessages"] = "message:write";
|
|
15
|
+
APIKeyScope["ReadMessages"] = "message:read";
|
|
16
|
+
APIKeyScope["ReadLogs"] = "project:logs:read";
|
|
17
|
+
})(APIKeyScope || (APIKeyScope = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A unique identifier for a resource.
|
|
3
|
+
*/
|
|
4
|
+
export type Snowflake = `${bigint}`;
|
|
5
|
+
/**
|
|
6
|
+
* Country codes used in templates i18n.
|
|
7
|
+
*/
|
|
8
|
+
export type CountryCode = 'ac' | 'ad' | 'ae' | 'af' | 'ag' | 'ai' | 'al' | 'am' | 'ao' | 'ar' | 'as' | 'at' | 'au' | 'aw' | 'ax' | 'az' | 'ba' | 'bb' | 'bd' | 'be' | 'bf' | 'bg' | 'bh' | 'bi' | 'bj' | 'bl' | 'bm' | 'bn' | 'bo' | 'bq' | 'br' | 'bs' | 'bt' | 'bw' | 'by' | 'bz' | 'ca' | 'cc' | 'cd' | 'cf' | 'cg' | 'ch' | 'ci' | 'ck' | 'cl' | 'cm' | 'cn' | 'co' | 'cr' | 'cu' | 'cv' | 'cw' | 'cx' | 'cy' | 'cz' | 'de' | 'dj' | 'dk' | 'dm' | 'do' | 'dz' | 'ec' | 'ee' | 'eg' | 'eh' | 'er' | 'es' | 'et' | 'fi' | 'fj' | 'fk' | 'fm' | 'fo' | 'fr' | 'ga' | 'gb' | 'gd' | 'ge' | 'gf' | 'gg' | 'gh' | 'gi' | 'gl' | 'gm' | 'gn' | 'gp' | 'gq' | 'gr' | 'gt' | 'gu' | 'gw' | 'gy' | 'hk' | 'hn' | 'hr' | 'ht' | 'hu' | 'id' | 'ie' | 'il' | 'im' | 'in' | 'io' | 'iq' | 'ir' | 'is' | 'it' | 'je' | 'jm' | 'jo' | 'jp' | 'ke' | 'kg' | 'kh' | 'ki' | 'km' | 'kn' | 'kp' | 'kr' | 'kw' | 'ky' | 'kz' | 'la' | 'lb' | 'lc' | 'li' | 'lk' | 'lr' | 'ls' | 'lt' | 'lu' | 'lv' | 'ly' | 'ma' | 'mc' | 'md' | 'me' | 'mf' | 'mg' | 'mh' | 'mk' | 'ml' | 'mm' | 'mn' | 'mo' | 'mp' | 'mq' | 'mr' | 'ms' | 'mt' | 'mu' | 'mv' | 'mw' | 'mx' | 'my' | 'mz' | 'na' | 'nc' | 'ne' | 'nf' | 'ng' | 'ni' | 'nl' | 'no' | 'np' | 'nr' | 'nu' | 'nz' | 'om' | 'pa' | 'pe' | 'pf' | 'pg' | 'ph' | 'pk' | 'pl' | 'pm' | 'pr' | 'ps' | 'pt' | 'pw' | 'py' | 'qa' | 're' | 'ro' | 'rs' | 'ru' | 'rw' | 'sa' | 'sb' | 'sc' | 'sd' | 'se' | 'sg' | 'sh' | 'si' | 'sj' | 'sk' | 'sl' | 'sm' | 'sn' | 'so' | 'sr' | 'ss' | 'st' | 'sv' | 'sx' | 'sy' | 'sz' | 'ta' | 'tc' | 'td' | 'tg' | 'th' | 'tj' | 'tk' | 'tl' | 'tm' | 'tn' | 'to' | 'tr' | 'tt' | 'tv' | 'tw' | 'tz' | 'ua' | 'ug' | 'us' | 'uy' | 'uz' | 'va' | 'vc' | 've' | 'vg' | 'vi' | 'vn' | 'vu' | 'wf' | 'ws' | 'xk' | 'ye' | 'yt' | 'za' | 'zm' | 'zw';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Snowflake } from './globals';
|
|
2
|
+
import type { WebhookEventType } from './webhooks';
|
|
3
|
+
/**
|
|
4
|
+
* https://docs.rewritetoday.com/api-reference/logs
|
|
5
|
+
*/
|
|
6
|
+
export interface APIWebhookLog {
|
|
7
|
+
/** Webhook log in {@link Snowflake} format. */
|
|
8
|
+
id: Snowflake;
|
|
9
|
+
/** Timestamp when Rewrite recorded the delivery attempt. */
|
|
10
|
+
createdAt: string;
|
|
11
|
+
/** Webhook identifier associated with the log entry. */
|
|
12
|
+
webhookId: Snowflake | null;
|
|
13
|
+
/** Message identifier associated with the delivery attempt, when available. */
|
|
14
|
+
messageId: Snowflake | null;
|
|
15
|
+
/** Webhook event type delivered in this attempt. See {@link WebhookEventType} */
|
|
16
|
+
type: WebhookEventType;
|
|
17
|
+
/** Transport or application error captured for the attempt. */
|
|
18
|
+
error: string | null;
|
|
19
|
+
/** Delivery outcome recorded by Rewrite. See {@link WebhookDeliveryStatus} */
|
|
20
|
+
status: WebhookDeliveryStatus;
|
|
21
|
+
/** Endpoint URL that received the delivery attempt. */
|
|
22
|
+
url: string;
|
|
23
|
+
/** HTTP status code returned by the destination endpoint. */
|
|
24
|
+
code: number | null;
|
|
25
|
+
/** Event payload delivered during this attempt. */
|
|
26
|
+
payload: object;
|
|
27
|
+
/** Attempt number for this delivery. */
|
|
28
|
+
attempt: number;
|
|
29
|
+
/**Round-trip time in milliseconds. */
|
|
30
|
+
latency: number | null;
|
|
31
|
+
/** Next scheduled retry time, when the attempt failed and will retry. */
|
|
32
|
+
retryAt: string | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* https://docs.rewritetoday.com/api-reference/logs
|
|
36
|
+
*/
|
|
37
|
+
export declare enum WebhookDeliveryStatus {
|
|
38
|
+
Success = "SUCCESS",
|
|
39
|
+
Failed = "FAILED"
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://docs.rewritetoday.com/api-reference/logs
|
|
3
|
+
*/
|
|
4
|
+
export var WebhookDeliveryStatus;
|
|
5
|
+
(function (WebhookDeliveryStatus) {
|
|
6
|
+
WebhookDeliveryStatus["Success"] = "SUCCESS";
|
|
7
|
+
WebhookDeliveryStatus["Failed"] = "FAILED";
|
|
8
|
+
})(WebhookDeliveryStatus || (WebhookDeliveryStatus = {}));
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { CountryCode, Snowflake } from './globals';
|
|
2
|
+
/**
|
|
3
|
+
* https://docs.rewritetoday.com/api-reference/messages
|
|
4
|
+
*/
|
|
5
|
+
export interface APIMessage {
|
|
6
|
+
/** Message ID in {@link Snowflake} format. */
|
|
7
|
+
id: Snowflake;
|
|
8
|
+
/** Timestamp when Rewrite accepted the message. */
|
|
9
|
+
createdAt: Snowflake;
|
|
10
|
+
/** Segmentation analysis for the SMS content accepted by Rewrite. */
|
|
11
|
+
analysis: APIMessageAnalysis;
|
|
12
|
+
/** Destination number in E.164 format. */
|
|
13
|
+
to: string;
|
|
14
|
+
/** Message type stored by Rewrite. See {@link MessageType} */
|
|
15
|
+
type: MessageType;
|
|
16
|
+
/** Metadata attached to the message. */
|
|
17
|
+
tags: APIMessageTag[];
|
|
18
|
+
/** Latest delivery status known by Rewrite. See {@link MessageStatus} */
|
|
19
|
+
status: MessageStatus;
|
|
20
|
+
/** Country inferred from the destination number. See {@link CountryCode} */
|
|
21
|
+
country: CountryCode;
|
|
22
|
+
/** Final SMS content sent to the destination number. */
|
|
23
|
+
content: string;
|
|
24
|
+
/** Encoding used by the provider when sending the SMS. See {@link MessageEncoding} */
|
|
25
|
+
encoding: MessageEncoding;
|
|
26
|
+
/** Template used to render the message, when applicable. */
|
|
27
|
+
templateId: Snowflake | null;
|
|
28
|
+
/** Timestamp when the provider confirmed final delivery. */
|
|
29
|
+
deliveredAt: string | null;
|
|
30
|
+
/** Scheduled send time, when the message was delayed intentionally. */
|
|
31
|
+
scheduledAt: string | null;
|
|
32
|
+
/** Whether the message consumed pay-as-you-go balance instead of subscription quota. */
|
|
33
|
+
isPayAsYouGo: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
36
|
+
export declare enum MessageEncoding {
|
|
37
|
+
GMS7 = "GMS7",
|
|
38
|
+
UCS2 = "UCS2"
|
|
39
|
+
}
|
|
40
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
41
|
+
export declare enum MessageStatus {
|
|
42
|
+
Sent = "SENT",
|
|
43
|
+
Queued = "QUEUED",
|
|
44
|
+
Failed = "FAILED",
|
|
45
|
+
Canceled = "CANCELED",
|
|
46
|
+
Scheduled = "SCHEDULED",
|
|
47
|
+
Delivered = "DELIVERED"
|
|
48
|
+
}
|
|
49
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
50
|
+
export interface APIMessageTag {
|
|
51
|
+
/** Tag key attached to the message. */
|
|
52
|
+
name: string;
|
|
53
|
+
/** Tag value attached to the message. */
|
|
54
|
+
value: string;
|
|
55
|
+
}
|
|
56
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
57
|
+
export declare enum MessageType {
|
|
58
|
+
SMS = "SMS",
|
|
59
|
+
OTP = "OTP"
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* https://docs.rewritetoday.com/api-reference/messages
|
|
63
|
+
*/
|
|
64
|
+
export interface APIMessageAnalysis {
|
|
65
|
+
/** Total character count in the rendered SMS content. */
|
|
66
|
+
characters: number;
|
|
67
|
+
/** Encoding detected for the rendered SMS content. */
|
|
68
|
+
encoding: MessageAnalysisEncoding;
|
|
69
|
+
/** Segments result. */
|
|
70
|
+
segments: {
|
|
71
|
+
/** Number of SMS segments required to send the message. */
|
|
72
|
+
count: number;
|
|
73
|
+
/** Maximum characters allowed when the message fits in a single SMS. */
|
|
74
|
+
single: number;
|
|
75
|
+
/** Maximum characters allowed per segment in multipart SMS. */
|
|
76
|
+
concat: number;
|
|
77
|
+
/** Why Rewrite selected the reported segmentation result. */
|
|
78
|
+
reason: MessageAnalysisReason;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* https://docs.rewritetoday.com/api-reference/messages
|
|
83
|
+
*/
|
|
84
|
+
export declare enum MessageAnalysisReason {
|
|
85
|
+
FitsSingleSegment = "fits",
|
|
86
|
+
SmartEncodingApplied = "smart",
|
|
87
|
+
ExceedsSingleSegmentLimit = "singleLimit",
|
|
88
|
+
ContainsNonGsm7Characters = "nonGsm7"
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* https://docs.rewritetoday.com/api-reference/messages
|
|
92
|
+
*/
|
|
93
|
+
export declare enum MessageAnalysisEncoding {
|
|
94
|
+
GSM7 = "gsm7",
|
|
95
|
+
UCS2 = "ucs2"
|
|
96
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
2
|
+
export var MessageEncoding;
|
|
3
|
+
(function (MessageEncoding) {
|
|
4
|
+
MessageEncoding["GMS7"] = "GMS7";
|
|
5
|
+
MessageEncoding["UCS2"] = "UCS2";
|
|
6
|
+
})(MessageEncoding || (MessageEncoding = {}));
|
|
7
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
8
|
+
export var MessageStatus;
|
|
9
|
+
(function (MessageStatus) {
|
|
10
|
+
MessageStatus["Sent"] = "SENT";
|
|
11
|
+
MessageStatus["Queued"] = "QUEUED";
|
|
12
|
+
MessageStatus["Failed"] = "FAILED";
|
|
13
|
+
MessageStatus["Canceled"] = "CANCELED";
|
|
14
|
+
MessageStatus["Scheduled"] = "SCHEDULED";
|
|
15
|
+
MessageStatus["Delivered"] = "DELIVERED";
|
|
16
|
+
})(MessageStatus || (MessageStatus = {}));
|
|
17
|
+
/** https://docs.rewritetoday.com/api-reference/messages */
|
|
18
|
+
export var MessageType;
|
|
19
|
+
(function (MessageType) {
|
|
20
|
+
MessageType["SMS"] = "SMS";
|
|
21
|
+
MessageType["OTP"] = "OTP";
|
|
22
|
+
})(MessageType || (MessageType = {}));
|
|
23
|
+
/**
|
|
24
|
+
* https://docs.rewritetoday.com/api-reference/messages
|
|
25
|
+
*/
|
|
26
|
+
export var MessageAnalysisReason;
|
|
27
|
+
(function (MessageAnalysisReason) {
|
|
28
|
+
MessageAnalysisReason["FitsSingleSegment"] = "fits";
|
|
29
|
+
MessageAnalysisReason["SmartEncodingApplied"] = "smart";
|
|
30
|
+
MessageAnalysisReason["ExceedsSingleSegmentLimit"] = "singleLimit";
|
|
31
|
+
MessageAnalysisReason["ContainsNonGsm7Characters"] = "nonGsm7";
|
|
32
|
+
})(MessageAnalysisReason || (MessageAnalysisReason = {}));
|
|
33
|
+
/**
|
|
34
|
+
* https://docs.rewritetoday.com/api-reference/messages
|
|
35
|
+
*/
|
|
36
|
+
export var MessageAnalysisEncoding;
|
|
37
|
+
(function (MessageAnalysisEncoding) {
|
|
38
|
+
MessageAnalysisEncoding["GSM7"] = "gsm7";
|
|
39
|
+
MessageAnalysisEncoding["UCS2"] = "ucs2";
|
|
40
|
+
})(MessageAnalysisEncoding || (MessageAnalysisEncoding = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Snowflake } from './globals';
|
|
2
|
+
/**
|
|
3
|
+
* https://docs.rewritetoday.com/api-reference/otp
|
|
4
|
+
*/
|
|
5
|
+
export interface APIOTPMessage {
|
|
6
|
+
/** OTP message in {@link Snowflake} format. */
|
|
7
|
+
id: Snowflake;
|
|
8
|
+
/** Destination number used for the OTP. */
|
|
9
|
+
to: string;
|
|
10
|
+
/** Brand prefix included in the OTP SMS. */
|
|
11
|
+
prefix: string;
|
|
12
|
+
/** Timestamp when Rewrite accepted the OTP request. */
|
|
13
|
+
createdAt: string;
|
|
14
|
+
/** Timestamp when the OTP becomes invalid. */
|
|
15
|
+
expiresAt: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CountryCode, Snowflake } from './globals';
|
|
2
|
+
/**
|
|
3
|
+
* https://docs.rewritetoday.com/api-reference/templates
|
|
4
|
+
*/
|
|
5
|
+
export interface APITemplate {
|
|
6
|
+
/** Template ID in {@link Snowflake} format. */
|
|
7
|
+
id: Snowflake;
|
|
8
|
+
/** Template name. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Project ID in {@link Snowflake} format. */
|
|
11
|
+
projectId: Snowflake;
|
|
12
|
+
/** Default SMS content stored for the template. */
|
|
13
|
+
content: string;
|
|
14
|
+
/** Human-readable description saved with the template (1-72 max.). */
|
|
15
|
+
description?: string;
|
|
16
|
+
/** Locale-specific overrides available for the template. */
|
|
17
|
+
i18n: Partial<Record<CountryCode, string>>;
|
|
18
|
+
/** Template variables as {@link APITemplateVariable}. */
|
|
19
|
+
variables: APITemplateVariable[];
|
|
20
|
+
/** Timestamp when the template was created. */
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* https://docs.rewritetoday.com/api-reference/templates
|
|
25
|
+
*/
|
|
26
|
+
export interface APITemplateVariable {
|
|
27
|
+
/** Variable name. */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Optional default value. */
|
|
30
|
+
fallback?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Snowflake } from './globals';
|
|
2
|
+
/**
|
|
3
|
+
* https://docs.rewritetoday.com/api-reference/webhooks
|
|
4
|
+
*/
|
|
5
|
+
export interface APIWebhook {
|
|
6
|
+
/** Webhook ID in {@link Snowflake} format. */
|
|
7
|
+
id: Snowflake;
|
|
8
|
+
/** Webhook name (1-32 max). */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Secret content to send in events. */
|
|
11
|
+
secret: string;
|
|
12
|
+
/** Destination URL for webhook events. */
|
|
13
|
+
endpoint: string;
|
|
14
|
+
/** Subscribed events as {@link WebhookEventType}. */
|
|
15
|
+
events: WebhookEventType[];
|
|
16
|
+
/** Current status as {@link WebhookStatus}. */
|
|
17
|
+
status: WebhookStatus;
|
|
18
|
+
/** Project ID in {@link Snowflake} format. */
|
|
19
|
+
projectId: Snowflake;
|
|
20
|
+
/** Timestamp when the webhook endpoint was created. */
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* https://docs.rewritetoday.com/api-reference/webhooks
|
|
25
|
+
*/
|
|
26
|
+
export declare enum WebhookEventType {
|
|
27
|
+
/** Fired when an OTP SMS was sent. */
|
|
28
|
+
SMSOTP = "sms.otp",
|
|
29
|
+
/** Fired when a message was sent. */
|
|
30
|
+
MessageSent = "message.sent",
|
|
31
|
+
/** Fired when a batch message was sent. */
|
|
32
|
+
MessageBatch = "message.batch",
|
|
33
|
+
/** Fired when an message enters the queue. */
|
|
34
|
+
MessageQueued = "message.queued",
|
|
35
|
+
/** Fired when an message reaches the destination. */
|
|
36
|
+
MessageDelivered = "message.delivered",
|
|
37
|
+
/** Fired when an message is scheduled for later. */
|
|
38
|
+
MessageScheduled = "message.scheduled",
|
|
39
|
+
/** Fired when an message delivery fails. */
|
|
40
|
+
MessageFailed = "message.failed",
|
|
41
|
+
/** Fired when an message is canceled before delivery. */
|
|
42
|
+
MessageCanceled = "message.canceled"
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* https://docs.rewritetoday.com/api-reference/webhooks
|
|
46
|
+
*/
|
|
47
|
+
export declare enum WebhookStatus {
|
|
48
|
+
/** The webhook is active and receiving events. */
|
|
49
|
+
Active = "ACTIVE",
|
|
50
|
+
/** The webhook is paused and not receiving events. */
|
|
51
|
+
Inactive = "INACTIVE"
|
|
52
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://docs.rewritetoday.com/api-reference/webhooks
|
|
3
|
+
*/
|
|
4
|
+
export var WebhookEventType;
|
|
5
|
+
(function (WebhookEventType) {
|
|
6
|
+
/** Fired when an OTP SMS was sent. */
|
|
7
|
+
WebhookEventType["SMSOTP"] = "sms.otp";
|
|
8
|
+
/** Fired when a message was sent. */
|
|
9
|
+
WebhookEventType["MessageSent"] = "message.sent";
|
|
10
|
+
/** Fired when a batch message was sent. */
|
|
11
|
+
WebhookEventType["MessageBatch"] = "message.batch";
|
|
12
|
+
/** Fired when an message enters the queue. */
|
|
13
|
+
WebhookEventType["MessageQueued"] = "message.queued";
|
|
14
|
+
/** Fired when an message reaches the destination. */
|
|
15
|
+
WebhookEventType["MessageDelivered"] = "message.delivered";
|
|
16
|
+
/** Fired when an message is scheduled for later. */
|
|
17
|
+
WebhookEventType["MessageScheduled"] = "message.scheduled";
|
|
18
|
+
/** Fired when an message delivery fails. */
|
|
19
|
+
WebhookEventType["MessageFailed"] = "message.failed";
|
|
20
|
+
/** Fired when an message is canceled before delivery. */
|
|
21
|
+
WebhookEventType["MessageCanceled"] = "message.canceled";
|
|
22
|
+
})(WebhookEventType || (WebhookEventType = {}));
|
|
23
|
+
/**
|
|
24
|
+
* https://docs.rewritetoday.com/api-reference/webhooks
|
|
25
|
+
*/
|
|
26
|
+
export var WebhookStatus;
|
|
27
|
+
(function (WebhookStatus) {
|
|
28
|
+
/** The webhook is active and receiving events. */
|
|
29
|
+
WebhookStatus["Active"] = "ACTIVE";
|
|
30
|
+
/** The webhook is paused and not receiving events. */
|
|
31
|
+
WebhookStatus["Inactive"] = "INACTIVE";
|
|
32
|
+
})(WebhookStatus || (WebhookStatus = {}));
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { CountryCode, Snowflake } from './resources/globals';
|
|
2
|
+
import type { APIWebhookLog } from './resources/logs';
|
|
3
|
+
import type { APIMessage, APIMessageTag, MessageStatus } from './resources/message';
|
|
4
|
+
import type { APIOTPMessage } from './resources/otp';
|
|
5
|
+
import type { APITemplate } from './resources/templates';
|
|
6
|
+
import type { APIWebhook, WebhookEventType, WebhookStatus } from './resources/webhooks';
|
|
7
|
+
/** https://docs.rewritetoday.com/en/api/pagination */
|
|
8
|
+
export interface RESTCursorOptions {
|
|
9
|
+
/** The maximum number of items returned per page. */
|
|
10
|
+
limit?: number;
|
|
11
|
+
/** Forward cursor in {@link Snowflake} format. */
|
|
12
|
+
after?: Snowflake;
|
|
13
|
+
/** Backward cursor in {@link Snowflake} format. */
|
|
14
|
+
before?: Snowflake;
|
|
15
|
+
}
|
|
16
|
+
/** https://docs.rewritetoday.com/en/api/introduction#response-conventions */
|
|
17
|
+
export type APIResponse<Data> = {
|
|
18
|
+
/** Indicates a successful response. */
|
|
19
|
+
ok: true;
|
|
20
|
+
/** Response payload. */
|
|
21
|
+
data: Data;
|
|
22
|
+
} | {
|
|
23
|
+
/** Indicates a failed response. */
|
|
24
|
+
ok: false;
|
|
25
|
+
error?: {
|
|
26
|
+
/** Human-readable error message. */
|
|
27
|
+
message: string;
|
|
28
|
+
/** Machine-readable error code. */
|
|
29
|
+
code: string;
|
|
30
|
+
/** Optional detailed error (Only sent in `INVALID_JSON_BODY` code.). */
|
|
31
|
+
detailed?: object;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** https://docs.rewritetoday.com/en/api/introduction#response-conventions */
|
|
35
|
+
export type APIResponseWithCursor<Data> = {
|
|
36
|
+
/** Indicates a successful response. */
|
|
37
|
+
ok: true;
|
|
38
|
+
/** Response payload. */
|
|
39
|
+
data: Data;
|
|
40
|
+
cursor: {
|
|
41
|
+
/** When `true`, another page is available using the returned cursor values. */
|
|
42
|
+
persist: boolean;
|
|
43
|
+
/** Cursor to request the next page. */
|
|
44
|
+
next?: Snowflake;
|
|
45
|
+
/** Cursor to request the previous page. */
|
|
46
|
+
prev?: Snowflake;
|
|
47
|
+
};
|
|
48
|
+
} | {
|
|
49
|
+
/** Indicates a failed response. */
|
|
50
|
+
ok: false;
|
|
51
|
+
error?: {
|
|
52
|
+
/** Human-readable error message. */
|
|
53
|
+
message: string;
|
|
54
|
+
/** Machine-readable error code. */
|
|
55
|
+
code: string;
|
|
56
|
+
/** Optional detailed error (Only sent in `INVALID_JSON_BODY` code.). */
|
|
57
|
+
detailed?: object;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
61
|
+
export type RESTGetWebhookData = APIResponse<APIWebhook>;
|
|
62
|
+
/** `POST https://api.rewritetoday.com/v1/webhooks`. */
|
|
63
|
+
export type RESTPostCreateWebhookData = APIResponse<Pick<APIWebhook, 'id' | 'secret' | 'createdAt'>>;
|
|
64
|
+
/** `POST https://api.rewritetoday.com/v1/webhooks`. */
|
|
65
|
+
export interface RESTPostCreateWebhookBody {
|
|
66
|
+
/** Webhook name. */
|
|
67
|
+
name?: APIWebhook['name'];
|
|
68
|
+
/** Destination URL for webhook events. */
|
|
69
|
+
endpoint: APIWebhook['endpoint'];
|
|
70
|
+
/** Subscribed events as {@link WebhookEventType}. */
|
|
71
|
+
events: APIWebhook['events'];
|
|
72
|
+
/** Secret to use in the webhook requests. */
|
|
73
|
+
secret?: string;
|
|
74
|
+
}
|
|
75
|
+
/** `DELETE https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
76
|
+
export type RESTDeleteWebhookData = APIResponse<null>;
|
|
77
|
+
/** `PATCH https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
78
|
+
export type RESTPatchUpdateWebhookData = APIResponse<APIWebhook>;
|
|
79
|
+
/** `PATCH https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
80
|
+
export interface RESTPatchUpdateWebhookBody {
|
|
81
|
+
/** Optional webhook name. */
|
|
82
|
+
name?: APIWebhook['name'];
|
|
83
|
+
/** Optional webhook endpoint URL. */
|
|
84
|
+
endpoint?: APIWebhook['endpoint'];
|
|
85
|
+
/** Optional subscribed events as {@link WebhookEventType}. */
|
|
86
|
+
events?: APIWebhook['events'];
|
|
87
|
+
/** Optional status as {@link WebhookStatus}. */
|
|
88
|
+
status?: WebhookStatus;
|
|
89
|
+
/** Optional secret to send in webhook requests. */
|
|
90
|
+
secret?: string;
|
|
91
|
+
}
|
|
92
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks`. */
|
|
93
|
+
export type RESTGetListWebhooksData = APIResponseWithCursor<APIWebhook[]>;
|
|
94
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks`. */
|
|
95
|
+
export type RESTGetListWebhooksQueryParams = RESTCursorOptions;
|
|
96
|
+
/** `GET https://api.rewritetoday.com/v1/templates`. */
|
|
97
|
+
export type RESTGetListTemplatesData = APIResponseWithCursor<APITemplate[]>;
|
|
98
|
+
/** `GET https://api.rewritetoday.com/v1/templates`. */
|
|
99
|
+
export interface RESTGetListTemplatesQueryParams extends RESTCursorOptions {
|
|
100
|
+
/** When `true`, include the template `i18n` map in list/detail responses. */
|
|
101
|
+
with18n?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/** `POST https://api.rewritetoday.com/v1/templates`. */
|
|
104
|
+
export type RESTPostCreateTemplateData = APIResponse<Pick<APITemplate, 'id' | 'createdAt'>>;
|
|
105
|
+
/** `POST https://api.rewritetoday.com/v1/templates`. */
|
|
106
|
+
export type RESTPostCreateTemplateBody = Pick<APITemplate, 'name' | 'i18n' | 'content' | 'variables' | 'description'>;
|
|
107
|
+
/** `PATCH https://api.rewritetoday.com/v1/templates/:id`. */
|
|
108
|
+
export type RESTPatchUpdateTemplateData = APIResponse<null>;
|
|
109
|
+
/** `PATCH https://api.rewritetoday.com/v1/templates/:id`. */
|
|
110
|
+
export type RESTPatchUpdateTemplateBody = Omit<Partial<RESTPostCreateTemplateBody>, 'name'>;
|
|
111
|
+
/** `DELETE https://api.rewritetoday.com/v1/templates/:id`. */
|
|
112
|
+
export type RESTDeleteTemplateData = APIResponse<null>;
|
|
113
|
+
/** `GET https://api.rewritetoday.com/v1/templates/:id`. */
|
|
114
|
+
export type RESTGetTemplateData = APIResponse<APITemplate>;
|
|
115
|
+
/** `DELETE https://api.rewritetoday.com/v1/api-keys/:key`. */
|
|
116
|
+
export type RESTDeleteAPIKeyData = APIResponse<null>;
|
|
117
|
+
/** `GET https://api.rewritetoday.com/v1/logs/:id`. */
|
|
118
|
+
export type RESTGetWebhookLogData = APIResponse<APIWebhookLog>;
|
|
119
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id/logs`. */
|
|
120
|
+
export type RESTGetListWebhookLogsData = APIResponseWithCursor<Omit<APIWebhookLog, 'payload'>[]>;
|
|
121
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id/logs`. */
|
|
122
|
+
export interface RESTGetListWebhookLogsQueryParams extends RESTCursorOptions {
|
|
123
|
+
/** Webhook event type to include in the result set. */
|
|
124
|
+
type?: WebhookEventType;
|
|
125
|
+
/** Delivery status to include in the result set. */
|
|
126
|
+
status?: WebhookStatus;
|
|
127
|
+
}
|
|
128
|
+
/** `POST https://api.rewritetoday.com/v1/otp` */
|
|
129
|
+
export interface RESTPostSendOTPMessageBody {
|
|
130
|
+
/** Destination number that should receive the OTP. */
|
|
131
|
+
to: string;
|
|
132
|
+
/** Short brand prefix included in the OTP SMS. */
|
|
133
|
+
prefix?: string;
|
|
134
|
+
/** Minutes until the OTP expires (Max 15). */
|
|
135
|
+
expiresIn?: number;
|
|
136
|
+
}
|
|
137
|
+
/** `POST https://api.rewritetoday.com/v1/otp` */
|
|
138
|
+
export type RESTPostSendOTPMessageData = APIResponse<APIOTPMessage>;
|
|
139
|
+
/** `POST https://api.rewritetoday.com/v1/otp/:id/verify` */
|
|
140
|
+
export interface RESTPostVerifyOTPCodeBody {
|
|
141
|
+
/** Destination number used when the OTP was created. */
|
|
142
|
+
to: string;
|
|
143
|
+
/** Numeric OTP code provided by the user. */
|
|
144
|
+
code: string;
|
|
145
|
+
}
|
|
146
|
+
/** `POST https://api.rewritetoday.com/v1/otp/:id/verify` */
|
|
147
|
+
export type RESTPostVerifyOTPCodeData = APIResponse<{
|
|
148
|
+
/** OTP identifier being verified. */
|
|
149
|
+
id: string;
|
|
150
|
+
/** Always `true` when the OTP verification succeeds. */
|
|
151
|
+
valid: boolean;
|
|
152
|
+
/** Timestamp when Rewrite marked the OTP as verified. */
|
|
153
|
+
verifiedAt: string | null;
|
|
154
|
+
}>;
|
|
155
|
+
/** `POST https://api.rewritetoday.com/v1/messages` */
|
|
156
|
+
export type RESTPostSendMessageData = APIResponse<Pick<APIMessage, 'id' | 'createdAt' | 'analysis'>>;
|
|
157
|
+
/** `POST https://api.rewritetoday.com/v1/messages` */
|
|
158
|
+
export type RESTPostSendMessageBody = {
|
|
159
|
+
/** Destination number in E.164 format. */
|
|
160
|
+
to: string;
|
|
161
|
+
/** Optional metadata stored with the message. */
|
|
162
|
+
tags: APIMessageTag[];
|
|
163
|
+
/** When provided, Rewrite schedules the message for later delivery. */
|
|
164
|
+
scheduledAt?: string;
|
|
165
|
+
/** Optional segmentation rules for long SMS bodies. */
|
|
166
|
+
segmentation?: {
|
|
167
|
+
/** Maximum number of SMS segments Rewrite is allowed to send. */
|
|
168
|
+
max: number;
|
|
169
|
+
/** How Rewrite should behave when the message exceeds the allowed segment count. */
|
|
170
|
+
mode?: 'fail' | 'trim' | 'send';
|
|
171
|
+
/** When `true`, Rewrite may optimize the content to fit GSM-7 when possible. */
|
|
172
|
+
smart?: boolean;
|
|
173
|
+
};
|
|
174
|
+
} & ({
|
|
175
|
+
/** Rendered SMS content to send. */
|
|
176
|
+
content: string;
|
|
177
|
+
} | {
|
|
178
|
+
/** Template identifier to render before sending. */
|
|
179
|
+
templateId: Snowflake;
|
|
180
|
+
/** Variable values used when rendering the selected template. */
|
|
181
|
+
variables: Record<string, string>;
|
|
182
|
+
});
|
|
183
|
+
/** `POST https://api.rewritetoday.com/v1/messages/batch` */
|
|
184
|
+
export type RESTPostSendBatchMessagesBody = RESTPostSendMessageBody[];
|
|
185
|
+
/** `POST https://api.rewritetoday.com/v1/messages/batch` */
|
|
186
|
+
export type RESTPostSendBatchMessagesData = APIResponse<{
|
|
187
|
+
/** Identifiers for the messages accepted into the batch request. */
|
|
188
|
+
ids: Snowflake[];
|
|
189
|
+
}>;
|
|
190
|
+
/** `POST https://api.rewritetoday.com/v1/messages/cancel` */
|
|
191
|
+
export type RESTPostCancelMessageData = APIResponse<null>;
|
|
192
|
+
/** `GET https://api.rewritetoday.com/v1/messages/:id` */
|
|
193
|
+
export type RESTGetMessageData = APIResponse<Omit<APIMessage, 'analysis'>>;
|
|
194
|
+
/** `GET https://api.rewritetoday.com/v1/messages` */
|
|
195
|
+
export interface RESTGetListMessagesQueryParams extends RESTCursorOptions {
|
|
196
|
+
/** Filter by message status. */
|
|
197
|
+
status?: MessageStatus;
|
|
198
|
+
/** Lowercase ISO 3166-1 alpha-2 country code inferred from the destination number. */
|
|
199
|
+
country?: CountryCode;
|
|
200
|
+
}
|
|
201
|
+
/** `GET https://api.rewritetoday.com/v1/messages` */
|
|
202
|
+
export type RESTGetListMessagesData = APIResponseWithCursor<Omit<APIMessage, 'analysis'>[]>;
|
package/dist/v1/rest.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { RESTCursorOptions } from './rest';
|
|
2
|
+
export declare const API_BASE_URL = "https://api.rewritetoday.com";
|
|
3
|
+
export declare const Routes: {
|
|
4
|
+
otp: {
|
|
5
|
+
/** `POST https://api.rewritetoday.com/v1/otp`. */
|
|
6
|
+
send(): string;
|
|
7
|
+
/** `POST https://api.rewritetoday.com/v1/otp/:id/verify`. */
|
|
8
|
+
verify(id: string): string;
|
|
9
|
+
};
|
|
10
|
+
messages: {
|
|
11
|
+
/** `POST https://api.rewritetoday.com/v1/messages`. */
|
|
12
|
+
send(): string;
|
|
13
|
+
/** `POST https://api.rewritetoday.com/v1/messages/batch`. */
|
|
14
|
+
batch(): string;
|
|
15
|
+
/** `GET https://api.rewritetoday.com/v1/messages`. */
|
|
16
|
+
list(): string;
|
|
17
|
+
/** `GET https://api.rewritetoday.com/v1/messages/:id`. */
|
|
18
|
+
get(id: string): string;
|
|
19
|
+
/** `POST https://api.rewritetoday.com/v1/messages/:id/cancel`. */
|
|
20
|
+
cancel(id: string): string;
|
|
21
|
+
};
|
|
22
|
+
webhooks: {
|
|
23
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks`. */
|
|
24
|
+
list(options?: RESTCursorOptions): string;
|
|
25
|
+
/** `POST https://api.rewritetoday.com/v1/webhooks`. */
|
|
26
|
+
create(): string;
|
|
27
|
+
/** `PATCH https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
28
|
+
update(id: string): string;
|
|
29
|
+
/** `DELETE https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
30
|
+
delete(id: string): string;
|
|
31
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
32
|
+
get(id: string): string;
|
|
33
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id/logs`. */
|
|
34
|
+
logs(id: string): string;
|
|
35
|
+
};
|
|
36
|
+
templates: {
|
|
37
|
+
/** `GET https://api.rewritetoday.com/v1/templates`. */
|
|
38
|
+
list(options?: RESTCursorOptions): string;
|
|
39
|
+
/** `POST https://api.rewritetoday.com/v1/templates`. */
|
|
40
|
+
create(): string;
|
|
41
|
+
/** `PATCH https://api.rewritetoday.com/v1/templates/:id`. */
|
|
42
|
+
update(id: string): string;
|
|
43
|
+
/** `DELETE https://api.rewritetoday.com/v1/projects/:id/templates/:id`. */
|
|
44
|
+
delete(id: string): string;
|
|
45
|
+
/** `GET https://api.rewritetoday.com/v1/projects/:id/templates/:id`. */
|
|
46
|
+
get(id: string): string;
|
|
47
|
+
};
|
|
48
|
+
apiKeys: {
|
|
49
|
+
/** `DELETE https://api.rewritetoday.com/v1/api-keys/:key`. */
|
|
50
|
+
delete(id: string): string;
|
|
51
|
+
};
|
|
52
|
+
logs: {
|
|
53
|
+
/** `GET /logs/:id`. */
|
|
54
|
+
get(id: string): string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createCursorQuery } from './utils';
|
|
2
|
+
export const API_BASE_URL = 'https://api.rewritetoday.com';
|
|
3
|
+
export const Routes = {
|
|
4
|
+
otp: {
|
|
5
|
+
/** `POST https://api.rewritetoday.com/v1/otp`. */
|
|
6
|
+
send() {
|
|
7
|
+
return '/otp';
|
|
8
|
+
},
|
|
9
|
+
/** `POST https://api.rewritetoday.com/v1/otp/:id/verify`. */
|
|
10
|
+
verify(id) {
|
|
11
|
+
return `/otp/${id}/verify`;
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
/** `POST https://api.rewritetoday.com/v1/messages`. */
|
|
16
|
+
send() {
|
|
17
|
+
return '/messages';
|
|
18
|
+
},
|
|
19
|
+
/** `POST https://api.rewritetoday.com/v1/messages/batch`. */
|
|
20
|
+
batch() {
|
|
21
|
+
return '/messages/batch';
|
|
22
|
+
},
|
|
23
|
+
/** `GET https://api.rewritetoday.com/v1/messages`. */
|
|
24
|
+
list() {
|
|
25
|
+
return '/messages';
|
|
26
|
+
},
|
|
27
|
+
/** `GET https://api.rewritetoday.com/v1/messages/:id`. */
|
|
28
|
+
get(id) {
|
|
29
|
+
return `/messages/:${id}`;
|
|
30
|
+
},
|
|
31
|
+
/** `POST https://api.rewritetoday.com/v1/messages/:id/cancel`. */
|
|
32
|
+
cancel(id) {
|
|
33
|
+
return `/messages/${id}/cancel`;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
webhooks: {
|
|
37
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks`. */
|
|
38
|
+
list(options) {
|
|
39
|
+
return `/webhooks?${createCursorQuery(options)}`;
|
|
40
|
+
},
|
|
41
|
+
/** `POST https://api.rewritetoday.com/v1/webhooks`. */
|
|
42
|
+
create() {
|
|
43
|
+
return '/webhooks';
|
|
44
|
+
},
|
|
45
|
+
/** `PATCH https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
46
|
+
update(id) {
|
|
47
|
+
return `/webhooks/${id}`;
|
|
48
|
+
},
|
|
49
|
+
/** `DELETE https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
50
|
+
delete(id) {
|
|
51
|
+
return `/webhooks/${id}`;
|
|
52
|
+
},
|
|
53
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id`. */
|
|
54
|
+
get(id) {
|
|
55
|
+
return `/webhooks/${id}`;
|
|
56
|
+
},
|
|
57
|
+
/** `GET https://api.rewritetoday.com/v1/webhooks/:id/logs`. */
|
|
58
|
+
logs(id) {
|
|
59
|
+
return `/webhooks/${id}/logs`;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
templates: {
|
|
63
|
+
/** `GET https://api.rewritetoday.com/v1/templates`. */
|
|
64
|
+
list(options) {
|
|
65
|
+
return `/templates?${createCursorQuery(options)}`;
|
|
66
|
+
},
|
|
67
|
+
/** `POST https://api.rewritetoday.com/v1/templates`. */
|
|
68
|
+
create() {
|
|
69
|
+
return '/templates';
|
|
70
|
+
},
|
|
71
|
+
/** `PATCH https://api.rewritetoday.com/v1/templates/:id`. */
|
|
72
|
+
update(id) {
|
|
73
|
+
return `/templates/${id}`;
|
|
74
|
+
},
|
|
75
|
+
/** `DELETE https://api.rewritetoday.com/v1/projects/:id/templates/:id`. */
|
|
76
|
+
delete(id) {
|
|
77
|
+
return `/templates/${id}`;
|
|
78
|
+
},
|
|
79
|
+
/** `GET https://api.rewritetoday.com/v1/projects/:id/templates/:id`. */
|
|
80
|
+
get(id) {
|
|
81
|
+
return `/templates/${id}`;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
apiKeys: {
|
|
85
|
+
/** `DELETE https://api.rewritetoday.com/v1/api-keys/:key`. */
|
|
86
|
+
delete(id) {
|
|
87
|
+
return `/api-keys/${id}`;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
logs: {
|
|
91
|
+
/** `GET /logs/:id`. */
|
|
92
|
+
get(id) {
|
|
93
|
+
return `/logs/${id}`;
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
package/dist/v1/utils.js
ADDED
package/dist/version.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"name": "@rewritetoday/types",
|
|
4
|
+
"description": "Official Rewrite API typings that are always up to date",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/v1/index.js",
|
|
7
|
+
"types": "./dist/v1/index.d.ts",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/v1/index.js",
|
|
12
|
+
"types": "./dist/v1/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./v1": {
|
|
15
|
+
"import": "./dist/v1/index.js",
|
|
16
|
+
"types": "./dist/v1/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./v1/*": {
|
|
19
|
+
"import": "./dist/v1/*.js",
|
|
20
|
+
"types": "./dist/v1/*.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./v*": null
|
|
23
|
+
},
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
"*": {
|
|
26
|
+
"v1": [
|
|
27
|
+
"dist/v1/index.d.ts"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "bun run scripts/version.ts && tsc",
|
|
36
|
+
"prepublishOnly": "bun run build",
|
|
37
|
+
"biome:check": "bunx biome check --write .",
|
|
38
|
+
"test": "bun test",
|
|
39
|
+
"test:types": "bun test && bunx tsc"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@biomejs/biome": "^2.4.8",
|
|
43
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
44
|
+
"@types/bun": "^1.3.11",
|
|
45
|
+
"commitlint": "^20.5.0",
|
|
46
|
+
"typescript": "^5.9.3"
|
|
47
|
+
},
|
|
48
|
+
"maintainers": [
|
|
49
|
+
{
|
|
50
|
+
"name": "Almeida",
|
|
51
|
+
"url": "https://github.com/almeidazs"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"keywords": [
|
|
55
|
+
"api",
|
|
56
|
+
"types",
|
|
57
|
+
"typescript",
|
|
58
|
+
"rewrite"
|
|
59
|
+
],
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "git+https://github.com/RewriteToday/types.git"
|
|
66
|
+
}
|
|
67
|
+
}
|