weshipyou-sdk 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 +33 -0
- package/README.md +49 -0
- package/dist/chunk-KT3VLIZI.mjs +18 -0
- package/dist/chunk-KT3VLIZI.mjs.map +1 -0
- package/dist/chunk-RM3JFTCX.cjs +18 -0
- package/dist/chunk-RM3JFTCX.cjs.map +1 -0
- package/dist/cli.js +20 -0
- package/dist/cli.js.map +1 -0
- package/dist/enterprise.cjs +73 -0
- package/dist/enterprise.cjs.map +1 -0
- package/dist/enterprise.d.mts +398 -0
- package/dist/enterprise.d.ts +398 -0
- package/dist/enterprise.mjs +73 -0
- package/dist/enterprise.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +221 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/update-shipment.use-case-BsHiVqQV.d.mts +504 -0
- package/dist/update-shipment.use-case-BsHiVqQV.d.ts +504 -0
- package/package.json +106 -0
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Router } from 'express';
|
|
3
|
+
|
|
4
|
+
interface HttpRequest {
|
|
5
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
6
|
+
url: string;
|
|
7
|
+
body?: Record<string, unknown>;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
interface HttpResponse<T = unknown> {
|
|
11
|
+
status: number;
|
|
12
|
+
data: T;
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
interface IHttpClient {
|
|
16
|
+
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ITokenManager {
|
|
20
|
+
setToken(token: string, exp: number): void;
|
|
21
|
+
getToken(): string | null;
|
|
22
|
+
isExpired(): boolean;
|
|
23
|
+
clear(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare enum AcceptLanguage {
|
|
27
|
+
EN_US = "en-US",
|
|
28
|
+
ES_ES = "es-ES",
|
|
29
|
+
PT_BR = "pt-BR"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface AuthResponse {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
exp?: number;
|
|
35
|
+
}
|
|
36
|
+
interface IAuthService {
|
|
37
|
+
authenticate(username: string, password: string, lang?: AcceptLanguage): Promise<AuthResponse>;
|
|
38
|
+
}
|
|
39
|
+
declare class AuthService implements IAuthService {
|
|
40
|
+
private readonly httpClient;
|
|
41
|
+
private readonly tokenManager?;
|
|
42
|
+
constructor(httpClient: IHttpClient, tokenManager?: ITokenManager | undefined);
|
|
43
|
+
authenticate(username: string, password: string, lang?: AcceptLanguage): Promise<AuthResponse>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PollingOptions {
|
|
47
|
+
maxAttempts: number;
|
|
48
|
+
baseDelayMs: number;
|
|
49
|
+
abortSignal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
interface IPollingService {
|
|
52
|
+
pollUntil<T>(fn: () => Promise<T>, condition: (result: T) => boolean, opts?: Partial<PollingOptions>): Promise<T>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare class PollingService implements IPollingService {
|
|
56
|
+
pollUntil<T>(fn: () => Promise<T>, condition: (result: T) => boolean, opts?: Partial<PollingOptions>): Promise<T>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface CityState {
|
|
60
|
+
name: string;
|
|
61
|
+
}
|
|
62
|
+
interface City {
|
|
63
|
+
name: string;
|
|
64
|
+
state: CityState;
|
|
65
|
+
}
|
|
66
|
+
interface RatesAddress {
|
|
67
|
+
city: City;
|
|
68
|
+
street: string;
|
|
69
|
+
postalCode: string;
|
|
70
|
+
}
|
|
71
|
+
interface SenderRecipientBase {
|
|
72
|
+
address: RatesAddress;
|
|
73
|
+
country: {
|
|
74
|
+
isoCode: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
type DimUnit = 'cm' | 'in';
|
|
78
|
+
type WeightUnit = 'gm' | 'kg' | 'oz' | 'lb';
|
|
79
|
+
type Incoterms = 'DDU' | 'DDP';
|
|
80
|
+
interface ParcelItemCategory {
|
|
81
|
+
slug: string;
|
|
82
|
+
}
|
|
83
|
+
interface ParcelItemCurrency {
|
|
84
|
+
name: string;
|
|
85
|
+
code: string;
|
|
86
|
+
prefix: string;
|
|
87
|
+
}
|
|
88
|
+
interface ParcelItem {
|
|
89
|
+
sku?: string;
|
|
90
|
+
description: string;
|
|
91
|
+
category: ParcelItemCategory;
|
|
92
|
+
price: number;
|
|
93
|
+
qty: number;
|
|
94
|
+
originCountry?: {
|
|
95
|
+
isoCode: string;
|
|
96
|
+
};
|
|
97
|
+
weight?: number;
|
|
98
|
+
currency: string | ParcelItemCurrency;
|
|
99
|
+
}
|
|
100
|
+
interface Parcel {
|
|
101
|
+
dimUnit: DimUnit;
|
|
102
|
+
width: number;
|
|
103
|
+
length: number;
|
|
104
|
+
height: number;
|
|
105
|
+
weightUnit: WeightUnit;
|
|
106
|
+
weight: number;
|
|
107
|
+
parcel_items: ParcelItem[];
|
|
108
|
+
}
|
|
109
|
+
interface IRateRequest {
|
|
110
|
+
accountId: string;
|
|
111
|
+
totalValue: number;
|
|
112
|
+
incoterms: Incoterms;
|
|
113
|
+
insurance?: boolean;
|
|
114
|
+
sender: SenderRecipientBase;
|
|
115
|
+
recipient: SenderRecipientBase;
|
|
116
|
+
parcels: Parcel[];
|
|
117
|
+
}
|
|
118
|
+
interface ShipmentSender {
|
|
119
|
+
name: string;
|
|
120
|
+
email: string;
|
|
121
|
+
phone: string;
|
|
122
|
+
companyName?: string;
|
|
123
|
+
taxId?: string;
|
|
124
|
+
taxIdCountry?: {
|
|
125
|
+
isoCode: string;
|
|
126
|
+
};
|
|
127
|
+
address: RatesAddress;
|
|
128
|
+
country: {
|
|
129
|
+
isoCode: string;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
interface ShipmentRecipient {
|
|
133
|
+
name: string;
|
|
134
|
+
email: string;
|
|
135
|
+
phone: string;
|
|
136
|
+
companyName?: string;
|
|
137
|
+
taxId?: string;
|
|
138
|
+
taxIdCountry?: {
|
|
139
|
+
isoCode: string;
|
|
140
|
+
};
|
|
141
|
+
address: RatesAddress;
|
|
142
|
+
country: {
|
|
143
|
+
isoCode: string;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
interface IShipmentRequest {
|
|
147
|
+
accountId: string;
|
|
148
|
+
totalValue: number;
|
|
149
|
+
incoterms: Incoterms;
|
|
150
|
+
insurance?: boolean;
|
|
151
|
+
externalReferenceCode?: string;
|
|
152
|
+
externalCustomerId?: string;
|
|
153
|
+
sender: ShipmentSender;
|
|
154
|
+
recipient: ShipmentRecipient;
|
|
155
|
+
parcels: Parcel[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface IShipmentService {
|
|
159
|
+
getRates(payload: IRateRequest, lang?: AcceptLanguage): Promise<unknown>;
|
|
160
|
+
createShipment(payload: IShipmentRequest, lang?: AcceptLanguage): Promise<unknown>;
|
|
161
|
+
updateShipment(id: string, payload: Partial<IShipmentRequest>, lang?: AcceptLanguage): Promise<unknown>;
|
|
162
|
+
getCountryCategories(countryCode: string, lang?: AcceptLanguage): Promise<unknown>;
|
|
163
|
+
}
|
|
164
|
+
declare class ShipmentService implements IShipmentService {
|
|
165
|
+
private readonly httpClient;
|
|
166
|
+
private categoryCache;
|
|
167
|
+
constructor(httpClient: IHttpClient);
|
|
168
|
+
getRates(payload: IRateRequest, lang?: AcceptLanguage): Promise<unknown>;
|
|
169
|
+
createShipment(payload: IShipmentRequest, lang?: AcceptLanguage): Promise<unknown>;
|
|
170
|
+
updateShipment(id: string, payload: Partial<IShipmentRequest>, lang?: AcceptLanguage): Promise<unknown>;
|
|
171
|
+
getCountryCategories(countryCode: string, lang?: AcceptLanguage): Promise<unknown>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class GetRatesUseCase {
|
|
175
|
+
private readonly authService;
|
|
176
|
+
private readonly shipmentService;
|
|
177
|
+
constructor(authService: IAuthService, shipmentService: IShipmentService);
|
|
178
|
+
execute(username: string, password: string, payload: IRateRequest, lang?: AcceptLanguage): Promise<unknown>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
declare class CreateShipmentUseCase {
|
|
182
|
+
private readonly authService;
|
|
183
|
+
private readonly shipmentService;
|
|
184
|
+
constructor(authService: IAuthService, shipmentService: IShipmentService);
|
|
185
|
+
execute(username: string, password: string, payload: IShipmentRequest, lang?: AcceptLanguage): Promise<unknown>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare const AddSubAccountSchema: z.ZodObject<{
|
|
189
|
+
accountUid: z.ZodOptional<z.ZodString>;
|
|
190
|
+
externalAccountNumber: z.ZodOptional<z.ZodString>;
|
|
191
|
+
name: z.ZodString;
|
|
192
|
+
displayName: z.ZodString;
|
|
193
|
+
systemUnits: z.ZodEnum<["imperial", "metric"]>;
|
|
194
|
+
email: z.ZodString;
|
|
195
|
+
notificationEmail: z.ZodString;
|
|
196
|
+
website: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
197
|
+
phone: z.ZodString;
|
|
198
|
+
emergencyPhone: z.ZodString;
|
|
199
|
+
taxId: z.ZodOptional<z.ZodString>;
|
|
200
|
+
taxIdCountry: z.ZodOptional<z.ZodObject<{
|
|
201
|
+
isoCode: z.ZodString;
|
|
202
|
+
}, "strip", z.ZodTypeAny, {
|
|
203
|
+
isoCode: string;
|
|
204
|
+
}, {
|
|
205
|
+
isoCode: string;
|
|
206
|
+
}>>;
|
|
207
|
+
isBusiness: z.ZodDefault<z.ZodBoolean>;
|
|
208
|
+
allowBankAccountPayments: z.ZodDefault<z.ZodBoolean>;
|
|
209
|
+
address: z.ZodOptional<z.ZodObject<{
|
|
210
|
+
street: z.ZodString;
|
|
211
|
+
city: z.ZodString;
|
|
212
|
+
state: z.ZodString;
|
|
213
|
+
postalCode: z.ZodString;
|
|
214
|
+
countryIsoCode: z.ZodString;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
street: string;
|
|
217
|
+
city: string;
|
|
218
|
+
state: string;
|
|
219
|
+
postalCode: string;
|
|
220
|
+
countryIsoCode: string;
|
|
221
|
+
}, {
|
|
222
|
+
street: string;
|
|
223
|
+
city: string;
|
|
224
|
+
state: string;
|
|
225
|
+
postalCode: string;
|
|
226
|
+
countryIsoCode: string;
|
|
227
|
+
}>>;
|
|
228
|
+
}, "strip", z.ZodTypeAny, {
|
|
229
|
+
name: string;
|
|
230
|
+
displayName: string;
|
|
231
|
+
systemUnits: "imperial" | "metric";
|
|
232
|
+
email: string;
|
|
233
|
+
notificationEmail: string;
|
|
234
|
+
phone: string;
|
|
235
|
+
emergencyPhone: string;
|
|
236
|
+
isBusiness: boolean;
|
|
237
|
+
allowBankAccountPayments: boolean;
|
|
238
|
+
accountUid?: string | undefined;
|
|
239
|
+
externalAccountNumber?: string | undefined;
|
|
240
|
+
website?: string | undefined;
|
|
241
|
+
taxId?: string | undefined;
|
|
242
|
+
taxIdCountry?: {
|
|
243
|
+
isoCode: string;
|
|
244
|
+
} | undefined;
|
|
245
|
+
address?: {
|
|
246
|
+
street: string;
|
|
247
|
+
city: string;
|
|
248
|
+
state: string;
|
|
249
|
+
postalCode: string;
|
|
250
|
+
countryIsoCode: string;
|
|
251
|
+
} | undefined;
|
|
252
|
+
}, {
|
|
253
|
+
name: string;
|
|
254
|
+
displayName: string;
|
|
255
|
+
systemUnits: "imperial" | "metric";
|
|
256
|
+
email: string;
|
|
257
|
+
notificationEmail: string;
|
|
258
|
+
phone: string;
|
|
259
|
+
emergencyPhone: string;
|
|
260
|
+
accountUid?: string | undefined;
|
|
261
|
+
externalAccountNumber?: string | undefined;
|
|
262
|
+
website?: string | undefined;
|
|
263
|
+
taxId?: string | undefined;
|
|
264
|
+
taxIdCountry?: {
|
|
265
|
+
isoCode: string;
|
|
266
|
+
} | undefined;
|
|
267
|
+
isBusiness?: boolean | undefined;
|
|
268
|
+
allowBankAccountPayments?: boolean | undefined;
|
|
269
|
+
address?: {
|
|
270
|
+
street: string;
|
|
271
|
+
city: string;
|
|
272
|
+
state: string;
|
|
273
|
+
postalCode: string;
|
|
274
|
+
countryIsoCode: string;
|
|
275
|
+
} | undefined;
|
|
276
|
+
}>;
|
|
277
|
+
type AddSubAccountInput = z.infer<typeof AddSubAccountSchema>;
|
|
278
|
+
|
|
279
|
+
interface IAccountService {
|
|
280
|
+
addSubAccount(payload: AddSubAccountInput, lang?: AcceptLanguage): Promise<unknown>;
|
|
281
|
+
addFunds(payload: {
|
|
282
|
+
paymentMethod?: string;
|
|
283
|
+
accountUid?: string;
|
|
284
|
+
transaction: {
|
|
285
|
+
zelleTransaction: string;
|
|
286
|
+
amount: number;
|
|
287
|
+
};
|
|
288
|
+
}, lang?: AcceptLanguage): Promise<unknown>;
|
|
289
|
+
}
|
|
290
|
+
declare class AccountService implements IAccountService {
|
|
291
|
+
private readonly httpClient;
|
|
292
|
+
constructor(httpClient: IHttpClient);
|
|
293
|
+
addSubAccount(payload: AddSubAccountInput, lang?: AcceptLanguage): Promise<unknown>;
|
|
294
|
+
addFunds(payload: {
|
|
295
|
+
paymentMethod?: string;
|
|
296
|
+
accountUid?: string;
|
|
297
|
+
transaction: {
|
|
298
|
+
zelleTransaction: string;
|
|
299
|
+
amount: number;
|
|
300
|
+
};
|
|
301
|
+
}, lang?: AcceptLanguage): Promise<unknown>;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
declare class CreateSubAccountUseCase {
|
|
305
|
+
private readonly authService;
|
|
306
|
+
private readonly accountService;
|
|
307
|
+
constructor(authService: IAuthService, accountService: IAccountService);
|
|
308
|
+
execute(username: string, password: string, payload: unknown, lang?: AcceptLanguage): Promise<unknown>;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
declare const CreateRechargeSchema: z.ZodObject<{
|
|
312
|
+
paymentMethod: z.ZodDefault<z.ZodEnum<["zelle", "credit_card", "balance"]>>;
|
|
313
|
+
accountUid: z.ZodOptional<z.ZodString>;
|
|
314
|
+
rechargeable_product: z.ZodObject<{
|
|
315
|
+
id: z.ZodNumber;
|
|
316
|
+
}, "strip", z.ZodTypeAny, {
|
|
317
|
+
id: number;
|
|
318
|
+
}, {
|
|
319
|
+
id: number;
|
|
320
|
+
}>;
|
|
321
|
+
scheduleDate: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
322
|
+
amount: z.ZodNumber;
|
|
323
|
+
account_rechargeable_contact: z.ZodObject<{
|
|
324
|
+
name: z.ZodString;
|
|
325
|
+
accountNumber: z.ZodString;
|
|
326
|
+
}, "strip", z.ZodTypeAny, {
|
|
327
|
+
name: string;
|
|
328
|
+
accountNumber: string;
|
|
329
|
+
}, {
|
|
330
|
+
name: string;
|
|
331
|
+
accountNumber: string;
|
|
332
|
+
}>;
|
|
333
|
+
}, "strip", z.ZodTypeAny, {
|
|
334
|
+
paymentMethod: "zelle" | "credit_card" | "balance";
|
|
335
|
+
rechargeable_product: {
|
|
336
|
+
id: number;
|
|
337
|
+
};
|
|
338
|
+
amount: number;
|
|
339
|
+
account_rechargeable_contact: {
|
|
340
|
+
name: string;
|
|
341
|
+
accountNumber: string;
|
|
342
|
+
};
|
|
343
|
+
accountUid?: string | undefined;
|
|
344
|
+
scheduleDate?: string | null | undefined;
|
|
345
|
+
}, {
|
|
346
|
+
rechargeable_product: {
|
|
347
|
+
id: number;
|
|
348
|
+
};
|
|
349
|
+
amount: number;
|
|
350
|
+
account_rechargeable_contact: {
|
|
351
|
+
name: string;
|
|
352
|
+
accountNumber: string;
|
|
353
|
+
};
|
|
354
|
+
accountUid?: string | undefined;
|
|
355
|
+
paymentMethod?: "zelle" | "credit_card" | "balance" | undefined;
|
|
356
|
+
scheduleDate?: string | null | undefined;
|
|
357
|
+
}>;
|
|
358
|
+
type CreateRechargeInput = z.infer<typeof CreateRechargeSchema>;
|
|
359
|
+
|
|
360
|
+
interface IMobileRechargeService {
|
|
361
|
+
createRecharge(payload: CreateRechargeInput, lang?: AcceptLanguage): Promise<unknown>;
|
|
362
|
+
getRecharges(limit?: number, lang?: AcceptLanguage): Promise<unknown>;
|
|
363
|
+
}
|
|
364
|
+
declare class MobileRechargeService implements IMobileRechargeService {
|
|
365
|
+
private readonly httpClient;
|
|
366
|
+
constructor(httpClient: IHttpClient);
|
|
367
|
+
createRecharge(payload: CreateRechargeInput, lang?: AcceptLanguage): Promise<unknown>;
|
|
368
|
+
getRecharges(limit?: number, lang?: AcceptLanguage): Promise<unknown>;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
declare class ExecuteRechargeUseCase {
|
|
372
|
+
private readonly authService;
|
|
373
|
+
private readonly rechargeService;
|
|
374
|
+
constructor(authService: IAuthService, rechargeService: IMobileRechargeService);
|
|
375
|
+
execute(username: string, password: string, payload: unknown, lang?: AcceptLanguage): Promise<unknown>;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
type CircuitState = 'CLOSED' | 'OPEN' | 'HALF-OPEN';
|
|
379
|
+
interface ICircuitBreaker {
|
|
380
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
381
|
+
getState(): CircuitState;
|
|
382
|
+
reset(): void;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
interface ShipmentStatus {
|
|
386
|
+
id: string;
|
|
387
|
+
status: string;
|
|
388
|
+
trackingNumber?: string;
|
|
389
|
+
updatedAt: string;
|
|
390
|
+
}
|
|
391
|
+
declare class TrackShipmentUseCase {
|
|
392
|
+
private readonly httpClient;
|
|
393
|
+
private readonly pollingService;
|
|
394
|
+
private readonly circuitBreaker;
|
|
395
|
+
constructor(httpClient: IHttpClient, pollingService: IPollingService, circuitBreaker: ICircuitBreaker);
|
|
396
|
+
execute(shipmentId: string, targetStatus: string, abortSignal?: AbortSignal, lang?: AcceptLanguage): Promise<ShipmentStatus>;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
interface IWebhookEvent {
|
|
400
|
+
eventType: string;
|
|
401
|
+
payload: unknown;
|
|
402
|
+
timestamp: string;
|
|
403
|
+
}
|
|
404
|
+
interface IWebhookHandler {
|
|
405
|
+
verifySignature(rawBody: string, signature: string, secret?: string, algorithm?: string): boolean;
|
|
406
|
+
handle(event: IWebhookEvent): Promise<void>;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
declare class HandleWebhookUseCase implements IWebhookHandler {
|
|
410
|
+
private readonly secret;
|
|
411
|
+
private readonly algorithm;
|
|
412
|
+
constructor(secret: string, algorithm?: string);
|
|
413
|
+
verifySignature(rawBody: string, signature: string, secret?: string, algorithm?: string): boolean;
|
|
414
|
+
handle(event: IWebhookEvent): Promise<void>;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
interface MetricsSnapshot {
|
|
418
|
+
totalRequests: number;
|
|
419
|
+
failedRequests: number;
|
|
420
|
+
circuitBreakerTrips: number;
|
|
421
|
+
averageResponseTimeMs: number;
|
|
422
|
+
}
|
|
423
|
+
declare class MetricsCollector {
|
|
424
|
+
private totalRequests;
|
|
425
|
+
private failedRequests;
|
|
426
|
+
private circuitBreakerTrips;
|
|
427
|
+
private responseTimes;
|
|
428
|
+
private readonly maxSamples;
|
|
429
|
+
recordRequest(durationMs: number, success: boolean): void;
|
|
430
|
+
recordCircuitBreakerTrip(): void;
|
|
431
|
+
snapshot(): MetricsSnapshot;
|
|
432
|
+
reset(): void;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
interface IRateLimiter {
|
|
436
|
+
consume(key: string, tokens?: number): Promise<{
|
|
437
|
+
remaining: number;
|
|
438
|
+
limit: number;
|
|
439
|
+
retryAfter?: number;
|
|
440
|
+
}>;
|
|
441
|
+
getMiddleware(): (req: any, res: any, next: any) => void;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
interface ITracer {
|
|
445
|
+
startSpan(name: string, attributes?: Record<string, string | number | boolean>): ISpan;
|
|
446
|
+
}
|
|
447
|
+
interface ISpan {
|
|
448
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
449
|
+
end(): void;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
interface Services {
|
|
453
|
+
auth: AuthService;
|
|
454
|
+
httpClient: IHttpClient;
|
|
455
|
+
getRates: GetRatesUseCase;
|
|
456
|
+
createShipment: CreateShipmentUseCase;
|
|
457
|
+
createSubAccount: CreateSubAccountUseCase;
|
|
458
|
+
executeRecharge: ExecuteRechargeUseCase;
|
|
459
|
+
trackShipment: TrackShipmentUseCase;
|
|
460
|
+
webhookHandler: HandleWebhookUseCase;
|
|
461
|
+
pollingService: PollingService;
|
|
462
|
+
circuitBreaker: ICircuitBreaker;
|
|
463
|
+
metricsCollector: MetricsCollector;
|
|
464
|
+
rateLimiter: IRateLimiter;
|
|
465
|
+
tracer: ITracer;
|
|
466
|
+
router: Router;
|
|
467
|
+
}
|
|
468
|
+
interface WebhookConfig {
|
|
469
|
+
secret: string;
|
|
470
|
+
algorithm?: string;
|
|
471
|
+
}
|
|
472
|
+
declare function bootstrap(baseURL: string, webhookConfig?: WebhookConfig | string, otelEndpoint?: string): Services;
|
|
473
|
+
|
|
474
|
+
interface DomainEvent {
|
|
475
|
+
eventId: string;
|
|
476
|
+
aggregateId: string;
|
|
477
|
+
type: string;
|
|
478
|
+
payload: Record<string, unknown>;
|
|
479
|
+
timestamp: string;
|
|
480
|
+
version: number;
|
|
481
|
+
}
|
|
482
|
+
interface IEventStore {
|
|
483
|
+
append(aggregateId: string, events: DomainEvent[]): Promise<void>;
|
|
484
|
+
getByAggregate(aggregateId: string, sinceVersion?: number): Promise<DomainEvent[]>;
|
|
485
|
+
replay(sinceTimestamp?: string, handler?: (event: DomainEvent) => Promise<void>): Promise<void>;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
declare class SqliteEventStore implements IEventStore {
|
|
489
|
+
private db;
|
|
490
|
+
constructor(dbPath?: string);
|
|
491
|
+
append(aggregateId: string, events: DomainEvent[]): Promise<void>;
|
|
492
|
+
getByAggregate(aggregateId: string, sinceVersion?: number): Promise<DomainEvent[]>;
|
|
493
|
+
replay(sinceTimestamp?: string, handler?: (event: DomainEvent) => Promise<void>): Promise<void>;
|
|
494
|
+
close(): void;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
declare class UpdateShipmentUseCase {
|
|
498
|
+
private readonly authService;
|
|
499
|
+
private readonly shipmentService;
|
|
500
|
+
constructor(authService: IAuthService, shipmentService: IShipmentService);
|
|
501
|
+
execute(username: string, password: string, shipmentId: string, payload: Partial<IShipmentRequest>, lang?: AcceptLanguage): Promise<unknown>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export { AcceptLanguage as A, type ShipmentSender as B, CreateShipmentUseCase as C, type DomainEvent as D, ExecuteRechargeUseCase as E, ShipmentService as F, GetRatesUseCase as G, type HttpRequest as H, type IHttpClient as I, type ShipmentStatus as J, type WeightUnit as K, bootstrap as L, MetricsCollector as M, type Parcel as P, type RatesAddress as R, SqliteEventStore as S, TrackShipmentUseCase as T, UpdateShipmentUseCase as U, type WebhookConfig as W, type IShipmentRequest as a, type IEventStore as b, type Services as c, type ITokenManager as d, type HttpResponse as e, type ICircuitBreaker as f, type CircuitState as g, type IRateLimiter as h, type ITracer as i, type ISpan as j, AccountService as k, AuthService as l, CreateSubAccountUseCase as m, type DimUnit as n, HandleWebhookUseCase as o, type IPollingService as p, type IRateRequest as q, type IWebhookEvent as r, type IWebhookHandler as s, type Incoterms as t, MobileRechargeService as u, type ParcelItem as v, type PollingOptions as w, PollingService as x, type SenderRecipientBase as y, type ShipmentRecipient as z };
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "weshipyou-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK oficial para la API de WeShipYou — envíos, tarifas, recargas móviles, webhooks, multi-tenancy y CQRS",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"weshipyou",
|
|
7
|
+
"shipping",
|
|
8
|
+
"courier",
|
|
9
|
+
"logistics",
|
|
10
|
+
"api",
|
|
11
|
+
"sdk",
|
|
12
|
+
"typescript",
|
|
13
|
+
"multi-tenant",
|
|
14
|
+
"cqrs",
|
|
15
|
+
"webhook",
|
|
16
|
+
"openapi"
|
|
17
|
+
],
|
|
18
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
19
|
+
"author": "Dazai Osamu <dazaiosamu.2b2t@gmail.com>",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/OsamuDasai/weshipyou-sdk.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/OsamuDasai/weshipyou-sdk#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/OsamuDasai/weshipyou-sdk/issues"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build:sdk": "npx tsx scripts/build-sdk.ts",
|
|
38
|
+
"start": "node dist/main.js",
|
|
39
|
+
"test": "jest --runInBand",
|
|
40
|
+
"test:unit": "jest --runInBand tests/unit",
|
|
41
|
+
"test:integration": "jest --runInBand tests/integration",
|
|
42
|
+
"test:e2e": "jest --runInBand tests/e2e",
|
|
43
|
+
"cli": "node dist/cli.js",
|
|
44
|
+
"codegen": "npx ts-node openapi/codegen.config.ts",
|
|
45
|
+
"docs": "typedoc",
|
|
46
|
+
"playground": "npx tsx scripts/playground.ts",
|
|
47
|
+
"chaos:test": "npx tsx scripts/chaos-test.ts",
|
|
48
|
+
"compliance:report": "npx tsx scripts/compliance-report.ts",
|
|
49
|
+
"audit:keygen": "npx tsx scripts/generate-audit-keypair.ts",
|
|
50
|
+
"prepublishOnly": "npm run build:sdk"
|
|
51
|
+
},
|
|
52
|
+
"bin": {
|
|
53
|
+
"weshipyou": "dist/cli.js"
|
|
54
|
+
},
|
|
55
|
+
"main": "./dist/index.cjs",
|
|
56
|
+
"module": "./dist/index.mjs",
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"exports": {
|
|
59
|
+
".": {
|
|
60
|
+
"types": "./dist/index.d.ts",
|
|
61
|
+
"import": "./dist/index.mjs",
|
|
62
|
+
"require": "./dist/index.cjs"
|
|
63
|
+
},
|
|
64
|
+
"./enterprise": {
|
|
65
|
+
"types": "./dist/enterprise.d.ts",
|
|
66
|
+
"import": "./dist/enterprise.mjs",
|
|
67
|
+
"require": "./dist/enterprise.cjs"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@opentelemetry/api": "^1.9.1",
|
|
72
|
+
"@opentelemetry/auto-instrumentations-node": "^0.77.0",
|
|
73
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.219.0",
|
|
74
|
+
"@opentelemetry/sdk-node": "^0.219.0",
|
|
75
|
+
"axios": "^1.6.0",
|
|
76
|
+
"better-sqlite3": "^12.11.1",
|
|
77
|
+
"commander": "^12.0.0",
|
|
78
|
+
"cors": "^2.8.6",
|
|
79
|
+
"dotenv": "^16.3.1",
|
|
80
|
+
"express": "^5.2.1",
|
|
81
|
+
"express-rate-limit": "^8.5.2",
|
|
82
|
+
"helmet": "^8.2.0",
|
|
83
|
+
"opossum": "^9.0.0",
|
|
84
|
+
"pg": "^8.21.0",
|
|
85
|
+
"pino": "^8.16.0",
|
|
86
|
+
"redis": "^6.0.0",
|
|
87
|
+
"zod": "^3.22.4"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
91
|
+
"@types/cors": "^2.8.19",
|
|
92
|
+
"@types/express": "^5.0.6",
|
|
93
|
+
"@types/jest": "^29.5.8",
|
|
94
|
+
"@types/node": "^20.9.0",
|
|
95
|
+
"@types/pg": "^8.20.0",
|
|
96
|
+
"jest": "^29.7.0",
|
|
97
|
+
"msw": "^2.14.6",
|
|
98
|
+
"openapi-typescript": "^7.13.0",
|
|
99
|
+
"pino-pretty": "^10.2.3",
|
|
100
|
+
"ts-jest": "^29.1.1",
|
|
101
|
+
"ts-node": "^10.9.2",
|
|
102
|
+
"tsup": "^8.5.1",
|
|
103
|
+
"typedoc": "^0.28.19",
|
|
104
|
+
"typescript": "^5.3.2"
|
|
105
|
+
}
|
|
106
|
+
}
|