rutter-ts 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -0
- package/dist/api.cjs +175 -0
- package/dist/api.d.cts +41 -0
- package/dist/api.d.ts +41 -0
- package/dist/api.js +168 -0
- package/dist/chunk-LLGYUOGX.js +36 -0
- package/dist/chunk-LPP3MIOV.cjs +39 -0
- package/dist/client-sPbSz2i_.d.cts +34 -0
- package/dist/client-sPbSz2i_.d.ts +34 -0
- package/dist/index.cjs +11 -209
- package/dist/index.d.cts +3 -72
- package/dist/index.d.ts +3 -72
- package/dist/index.js +3 -200
- package/package.json +11 -1
package/dist/index.js
CHANGED
|
@@ -1,46 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RutterError } from './chunk-LLGYUOGX.js';
|
|
2
|
+
export { RutterError, RutterSchemaMismatchError } from './chunk-LLGYUOGX.js';
|
|
3
3
|
|
|
4
4
|
// src/constants.ts
|
|
5
5
|
var RUTTER_SANDBOX_BASE_URL = "https://sandbox.rutterapi.com/versioned";
|
|
6
6
|
var RUTTER_PRODUCTION_BASE_URL = "https://production.rutterapi.com/versioned";
|
|
7
7
|
var RUTTER_API_VERSION = "2024-08-31";
|
|
8
8
|
|
|
9
|
-
// src/errors.ts
|
|
10
|
-
var RutterError = class extends Error {
|
|
11
|
-
status;
|
|
12
|
-
errorType;
|
|
13
|
-
errorCode;
|
|
14
|
-
metadata;
|
|
15
|
-
constructor(body, status) {
|
|
16
|
-
super(body.error_message);
|
|
17
|
-
this.name = "RutterError";
|
|
18
|
-
this.status = status;
|
|
19
|
-
this.errorType = body.error_type;
|
|
20
|
-
this.errorCode = body.error_code;
|
|
21
|
-
this.metadata = body.error_metadata;
|
|
22
|
-
}
|
|
23
|
-
get isRateLimited() {
|
|
24
|
-
return this.status === 429 || this.status === 452;
|
|
25
|
-
}
|
|
26
|
-
get isUserActionable() {
|
|
27
|
-
return this.status === 400 || this.status === 409 || this.status === 410 || this.status === 450;
|
|
28
|
-
}
|
|
29
|
-
get humanReadableMessage() {
|
|
30
|
-
return this.metadata?.human_readable ?? this.message;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var RutterSchemaMismatchError = class extends Error {
|
|
34
|
-
endpoint;
|
|
35
|
-
constructor(endpoint, issues) {
|
|
36
|
-
super(
|
|
37
|
-
`Rutter response from ${endpoint} failed schema validation: ${issues}`
|
|
38
|
-
);
|
|
39
|
-
this.name = "RutterSchemaMismatchError";
|
|
40
|
-
this.endpoint = endpoint;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
9
|
// src/client.ts
|
|
45
10
|
var RutterClient = class {
|
|
46
11
|
baseUrl;
|
|
@@ -115,167 +80,5 @@ var RutterClient = class {
|
|
|
115
80
|
return this.request("DELETE", this.buildPath(path, params));
|
|
116
81
|
}
|
|
117
82
|
};
|
|
118
|
-
var RutterConnectionsApi = class {
|
|
119
|
-
constructor(client) {
|
|
120
|
-
this.client = client;
|
|
121
|
-
}
|
|
122
|
-
async create(params) {
|
|
123
|
-
const endpoint = "/connections";
|
|
124
|
-
const response = await this.client.post(endpoint, params);
|
|
125
|
-
const result = zConnectionResponse.safeParse(response);
|
|
126
|
-
if (!result.success) {
|
|
127
|
-
throw new RutterSchemaMismatchError(
|
|
128
|
-
endpoint,
|
|
129
|
-
z2.prettifyError(result.error)
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
return result.data;
|
|
133
|
-
}
|
|
134
|
-
async list() {
|
|
135
|
-
const endpoint = "/connections";
|
|
136
|
-
const response = await this.client.get(endpoint);
|
|
137
|
-
const result = zListConnectionsResponse.safeParse(response);
|
|
138
|
-
if (!result.success) {
|
|
139
|
-
throw new RutterSchemaMismatchError(
|
|
140
|
-
endpoint,
|
|
141
|
-
z2.prettifyError(result.error)
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
return result.data;
|
|
145
|
-
}
|
|
146
|
-
async get(accessToken) {
|
|
147
|
-
const endpoint = "/connections";
|
|
148
|
-
const response = await this.client.get(endpoint, {
|
|
149
|
-
access_token: accessToken
|
|
150
|
-
});
|
|
151
|
-
const result = zGetAccessTokenConnectionResponse.safeParse(response);
|
|
152
|
-
if (!result.success) {
|
|
153
|
-
throw new RutterSchemaMismatchError(
|
|
154
|
-
endpoint,
|
|
155
|
-
z2.prettifyError(result.error)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
return result.data;
|
|
159
|
-
}
|
|
160
|
-
async exchangeToken(params) {
|
|
161
|
-
const endpoint = "/item/public_token/exchange";
|
|
162
|
-
const response = await this.client.post(endpoint, params);
|
|
163
|
-
const result = zExchangeTokenResponse.safeParse(response);
|
|
164
|
-
if (!result.success) {
|
|
165
|
-
throw new RutterSchemaMismatchError(
|
|
166
|
-
endpoint,
|
|
167
|
-
z2.prettifyError(result.error)
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
return result.data;
|
|
171
|
-
}
|
|
172
|
-
async delete(accessToken) {
|
|
173
|
-
const endpoint = "/connections";
|
|
174
|
-
const response = await this.client.delete(endpoint, {
|
|
175
|
-
access_token: accessToken
|
|
176
|
-
});
|
|
177
|
-
const result = zDeleteConnectionResponse.safeParse(response);
|
|
178
|
-
if (!result.success) {
|
|
179
|
-
throw new RutterSchemaMismatchError(
|
|
180
|
-
endpoint,
|
|
181
|
-
z2.prettifyError(result.error)
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
return result.data;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
var RutterAccountingApi = class {
|
|
188
|
-
constructor(client) {
|
|
189
|
-
this.client = client;
|
|
190
|
-
}
|
|
191
|
-
async getCompanyInfo(accessToken) {
|
|
192
|
-
const endpoint = "/accounting/company_info";
|
|
193
|
-
const response = await this.client.get(endpoint, {
|
|
194
|
-
access_token: accessToken
|
|
195
|
-
});
|
|
196
|
-
const result = zCompanyInfo20240430ResponseWithConnection.safeParse(response);
|
|
197
|
-
if (!result.success) {
|
|
198
|
-
throw new RutterSchemaMismatchError(
|
|
199
|
-
endpoint,
|
|
200
|
-
z2.prettifyError(result.error)
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
return result.data;
|
|
204
|
-
}
|
|
205
|
-
async listAccounts(accessToken, params) {
|
|
206
|
-
const endpoint = "/accounting/accounts";
|
|
207
|
-
const response = await this.client.get(endpoint, {
|
|
208
|
-
access_token: accessToken,
|
|
209
|
-
...params
|
|
210
|
-
});
|
|
211
|
-
const result = zListAccountResponseWithConnection.safeParse(response);
|
|
212
|
-
if (!result.success) {
|
|
213
|
-
throw new RutterSchemaMismatchError(
|
|
214
|
-
endpoint,
|
|
215
|
-
z2.prettifyError(result.error)
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
return result.data;
|
|
219
|
-
}
|
|
220
|
-
async getAccount(accessToken, id) {
|
|
221
|
-
const endpoint = `/accounting/accounts/${id}`;
|
|
222
|
-
const response = await this.client.get(endpoint, {
|
|
223
|
-
access_token: accessToken
|
|
224
|
-
});
|
|
225
|
-
const result = zAccountResponseWithConnection.safeParse(response);
|
|
226
|
-
if (!result.success) {
|
|
227
|
-
throw new RutterSchemaMismatchError(
|
|
228
|
-
endpoint,
|
|
229
|
-
z2.prettifyError(result.error)
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
return result.data;
|
|
233
|
-
}
|
|
234
|
-
async listInvoices(accessToken, params) {
|
|
235
|
-
const endpoint = "/accounting/invoices";
|
|
236
|
-
const response = await this.client.get(endpoint, {
|
|
237
|
-
access_token: accessToken,
|
|
238
|
-
...params
|
|
239
|
-
});
|
|
240
|
-
const result = zListInvoiceResponseWithConnection.safeParse(response);
|
|
241
|
-
if (!result.success) {
|
|
242
|
-
throw new RutterSchemaMismatchError(
|
|
243
|
-
endpoint,
|
|
244
|
-
z2.prettifyError(result.error)
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
return result.data;
|
|
248
|
-
}
|
|
249
|
-
async getInvoice(accessToken, id) {
|
|
250
|
-
const endpoint = `/accounting/invoices/${id}`;
|
|
251
|
-
const response = await this.client.get(endpoint, {
|
|
252
|
-
access_token: accessToken
|
|
253
|
-
});
|
|
254
|
-
const result = zInvoiceResponseWithConnection.safeParse(response);
|
|
255
|
-
if (!result.success) {
|
|
256
|
-
throw new RutterSchemaMismatchError(
|
|
257
|
-
endpoint,
|
|
258
|
-
z2.prettifyError(result.error)
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
return result.data;
|
|
262
|
-
}
|
|
263
|
-
async createInvoice(accessToken, params, idempotencyKey) {
|
|
264
|
-
const endpoint = "/accounting/invoices";
|
|
265
|
-
const response = await this.client.post(
|
|
266
|
-
`${endpoint}?access_token=${encodeURIComponent(accessToken)}`,
|
|
267
|
-
params,
|
|
268
|
-
idempotencyKey ? { idempotencyKey } : void 0
|
|
269
|
-
);
|
|
270
|
-
const result = zCreateInvoiceResponse.safeParse(response);
|
|
271
|
-
if (!result.success) {
|
|
272
|
-
throw new RutterSchemaMismatchError(
|
|
273
|
-
endpoint,
|
|
274
|
-
z2.prettifyError(result.error)
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
return result.data;
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
83
|
|
|
281
|
-
export { RUTTER_API_VERSION, RUTTER_PRODUCTION_BASE_URL, RUTTER_SANDBOX_BASE_URL,
|
|
84
|
+
export { RUTTER_API_VERSION, RUTTER_PRODUCTION_BASE_URL, RUTTER_SANDBOX_BASE_URL, RutterClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rutter-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for the Rutter API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
"default": "./dist/index.cjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
+
"./api": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/api.d.ts",
|
|
23
|
+
"default": "./dist/api.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/api.d.cts",
|
|
27
|
+
"default": "./dist/api.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
20
30
|
"./generated": {
|
|
21
31
|
"import": {
|
|
22
32
|
"types": "./dist/generated.d.ts",
|