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.
@@ -0,0 +1,398 @@
1
+ import { D as DomainEvent, I as IHttpClient, a as IShipmentRequest, A as AcceptLanguage, C as CreateShipmentUseCase, b as IEventStore, E as ExecuteRechargeUseCase, U as UpdateShipmentUseCase, S as SqliteEventStore, c as Services } from './update-shipment.use-case-BsHiVqQV.mjs';
2
+ import { Request, RequestHandler } from 'express';
3
+ import 'zod';
4
+
5
+ interface TenantContext {
6
+ tenantId: string;
7
+ accountId: string;
8
+ permissions: string[];
9
+ metadata?: Record<string, unknown>;
10
+ }
11
+ interface ITenantContextProvider {
12
+ getCurrent(): TenantContext | null;
13
+ set(context: TenantContext): void;
14
+ clear(): void;
15
+ isolate<T>(context: TenantContext, fn: () => Promise<T>): Promise<T>;
16
+ }
17
+
18
+ interface SchemaIsolationConfig {
19
+ tenantId: string;
20
+ schemaName: string;
21
+ migrationStatements: string[];
22
+ }
23
+ declare class SchemaIsolationManager {
24
+ private tenantProvider;
25
+ private schemas;
26
+ constructor(tenantProvider: ITenantContextProvider);
27
+ register(tenantId: string, config: SchemaIsolationConfig): void;
28
+ getCurrentSchema(): string | null;
29
+ getSchemaFor(tenantId: string): string | null;
30
+ deregister(tenantId: string): void;
31
+ }
32
+
33
+ interface ShipmentReadModel {
34
+ id: string;
35
+ tenantId: string;
36
+ accountId: string;
37
+ status: string;
38
+ trackingNumber?: string;
39
+ totalValue: number;
40
+ incoterms: 'DDU' | 'DDP';
41
+ senderName: string;
42
+ recipientName: string;
43
+ createdAt: string;
44
+ updatedAt: string;
45
+ metadata?: Record<string, unknown>;
46
+ }
47
+ interface IReadModel {
48
+ init(): Promise<void>;
49
+ close(): Promise<void>;
50
+ upsert(shipment: ShipmentReadModel): Promise<void>;
51
+ getById(id: string, tenantId: string): Promise<ShipmentReadModel | null>;
52
+ query(filters: {
53
+ tenantId: string;
54
+ accountId?: string;
55
+ status?: string;
56
+ limit?: number;
57
+ offset?: number;
58
+ }): Promise<ShipmentReadModel[]>;
59
+ }
60
+ interface IProjectionHandler {
61
+ handle(event: DomainEvent): Promise<void>;
62
+ }
63
+
64
+ declare class RedisStreamsProjection {
65
+ private client;
66
+ private streamName;
67
+ private groupName;
68
+ private consumerName;
69
+ constructor(redisUrl: string, streamName?: string, groupName?: string, consumerName?: string);
70
+ init(): Promise<void>;
71
+ publish(event: DomainEvent): Promise<void>;
72
+ consume(handler: IProjectionHandler, timeout?: number): Promise<void>;
73
+ close(): Promise<void>;
74
+ }
75
+
76
+ declare class ShipmentProjection implements IProjectionHandler {
77
+ private readonly readModel;
78
+ constructor(readModel: IReadModel);
79
+ handle(event: DomainEvent): Promise<void>;
80
+ private onShipmentCreated;
81
+ private onStatusChanged;
82
+ }
83
+
84
+ interface AuditLogEntry extends DomainEvent {
85
+ tenantId: string;
86
+ actorId: string;
87
+ actorType: 'user' | 'system' | 'api_key';
88
+ action: string;
89
+ resourceType: string;
90
+ resourceId: string;
91
+ ipAddress?: string;
92
+ userAgent?: string;
93
+ signature: string;
94
+ }
95
+ interface IAuditLogService {
96
+ log(entry: Omit<AuditLogEntry, 'signature'>, privateKey: string): Promise<void>;
97
+ verify(entry: AuditLogEntry, publicKey: string): boolean;
98
+ query(filters: {
99
+ tenantId: string;
100
+ resourceType?: string;
101
+ resourceId?: string;
102
+ since?: string;
103
+ until?: string;
104
+ }): Promise<AuditLogEntry[]>;
105
+ }
106
+
107
+ type SiemFormat = 'json' | 'cef' | 'leef';
108
+ declare class SiemExporter {
109
+ export(entries: AuditLogEntry[], format: SiemFormat): string;
110
+ private toCEF;
111
+ private toLEEF;
112
+ }
113
+
114
+ declare class AuditLogService {
115
+ private readonly auditLog;
116
+ private readonly tenantProvider;
117
+ private readonly privateKey;
118
+ constructor(auditLog: IAuditLogService, tenantProvider: ITenantContextProvider, privateKey: string);
119
+ record(partial: {
120
+ action: string;
121
+ resourceType: string;
122
+ resourceId: string;
123
+ payload: Record<string, unknown>;
124
+ }): Promise<void>;
125
+ }
126
+
127
+ type ChaosAttack = 'latency' | 'error' | 'timeout' | 'crash';
128
+ interface IChaosTester {
129
+ inject(attack: ChaosAttack, durationMs?: number): Promise<void>;
130
+ recover(): Promise<void>;
131
+ isActive(): boolean;
132
+ }
133
+
134
+ declare class HttpChaosTester implements IChaosTester {
135
+ private readonly httpClient;
136
+ private active;
137
+ constructor(httpClient: IHttpClient);
138
+ inject(attack: ChaosAttack, durationMs?: number): Promise<void>;
139
+ recover(): Promise<void>;
140
+ isActive(): boolean;
141
+ private injectLatency;
142
+ private injectErrors;
143
+ private injectTimeout;
144
+ private injectCrash;
145
+ }
146
+
147
+ interface TenantExtractor {
148
+ (req: Request): Promise<{
149
+ tenantId: string;
150
+ accountId: string;
151
+ }>;
152
+ }
153
+ declare function createTenantMiddleware(tenantProvider: ITenantContextProvider, extractTenant: TenantExtractor): RequestHandler;
154
+
155
+ interface EnterpriseConfig {
156
+ postgresUrl: string;
157
+ redisUrl: string;
158
+ auditPrivateKey: string;
159
+ streamName?: string;
160
+ consumerName?: string;
161
+ chaosBaseUrl?: string;
162
+ }
163
+
164
+ interface ICommand<TResult = void> {
165
+ readonly type: string;
166
+ }
167
+ interface ICommandHandler<TCommand extends ICommand<TResult>, TResult = void> {
168
+ execute(command: TCommand): Promise<TResult>;
169
+ }
170
+ interface IQuery<TResult = unknown> {
171
+ readonly type: string;
172
+ }
173
+ interface IQueryHandler<TQuery extends IQuery<TResult>, TResult = unknown> {
174
+ execute(query: TQuery): Promise<TResult>;
175
+ }
176
+
177
+ interface CreateShipmentResult {
178
+ shipmentId: string;
179
+ trackingNumber?: string;
180
+ }
181
+ declare class CreateShipmentCommand implements ICommand<CreateShipmentResult> {
182
+ readonly username: string;
183
+ readonly password: string;
184
+ readonly payload: IShipmentRequest;
185
+ readonly lang: AcceptLanguage;
186
+ readonly type = "CreateShipment";
187
+ constructor(username: string, password: string, payload: IShipmentRequest, lang?: AcceptLanguage);
188
+ }
189
+ declare class CreateShipmentHandler implements ICommandHandler<CreateShipmentCommand, CreateShipmentResult> {
190
+ private readonly createShipmentUseCase;
191
+ private readonly eventStore;
192
+ private readonly tenantId?;
193
+ constructor(createShipmentUseCase: CreateShipmentUseCase, eventStore: IEventStore, tenantId?: string | undefined);
194
+ execute(command: CreateShipmentCommand): Promise<CreateShipmentResult>;
195
+ }
196
+
197
+ interface CancelShipmentResult {
198
+ success: boolean;
199
+ shipmentId: string;
200
+ }
201
+ declare class CancelShipmentCommand implements ICommand<CancelShipmentResult> {
202
+ readonly shipmentId: string;
203
+ readonly tenantId: string;
204
+ readonly accountId: string;
205
+ readonly type = "CancelShipment";
206
+ constructor(shipmentId: string, tenantId: string, accountId: string);
207
+ }
208
+ declare class CancelShipmentHandler implements ICommandHandler<CancelShipmentCommand, CancelShipmentResult> {
209
+ private readonly httpClient;
210
+ private readonly eventStore;
211
+ constructor(httpClient: IHttpClient, eventStore: IEventStore);
212
+ execute(command: CancelShipmentCommand): Promise<CancelShipmentResult>;
213
+ }
214
+
215
+ interface RechargeableProduct {
216
+ id: number;
217
+ }
218
+ interface AccountRechargeableContact {
219
+ name: string;
220
+ accountNumber: string;
221
+ }
222
+ interface CreateRechargeRequest {
223
+ paymentMethod: 'zelle' | 'credit_card' | 'balance';
224
+ accountUid?: string;
225
+ rechargeable_product: RechargeableProduct;
226
+ scheduleDate?: string | null;
227
+ amount: number;
228
+ account_rechargeable_contact: AccountRechargeableContact;
229
+ }
230
+
231
+ interface ExecuteRechargeResult {
232
+ transactionId: string;
233
+ status: string;
234
+ }
235
+ declare class ExecuteRechargeCommand implements ICommand<ExecuteRechargeResult> {
236
+ readonly username: string;
237
+ readonly password: string;
238
+ readonly payload: CreateRechargeRequest;
239
+ readonly lang: AcceptLanguage;
240
+ readonly type = "ExecuteRecharge";
241
+ constructor(username: string, password: string, payload: CreateRechargeRequest, lang?: AcceptLanguage);
242
+ }
243
+ declare class ExecuteRechargeHandler implements ICommandHandler<ExecuteRechargeCommand, ExecuteRechargeResult> {
244
+ private readonly executeRechargeUseCase;
245
+ private readonly eventStore;
246
+ constructor(executeRechargeUseCase: ExecuteRechargeUseCase, eventStore: IEventStore);
247
+ execute(command: ExecuteRechargeCommand): Promise<ExecuteRechargeResult>;
248
+ }
249
+
250
+ interface UpdateShipmentResult {
251
+ shipmentId: string;
252
+ }
253
+ declare class UpdateShipmentCommand implements ICommand<UpdateShipmentResult> {
254
+ readonly username: string;
255
+ readonly password: string;
256
+ readonly shipmentId: string;
257
+ readonly payload: Partial<IShipmentRequest>;
258
+ readonly lang: AcceptLanguage;
259
+ readonly type = "UpdateShipment";
260
+ constructor(username: string, password: string, shipmentId: string, payload: Partial<IShipmentRequest>, lang?: AcceptLanguage);
261
+ }
262
+ declare class UpdateShipmentHandler implements ICommandHandler<UpdateShipmentCommand, UpdateShipmentResult> {
263
+ private readonly updateShipmentUseCase;
264
+ private readonly eventStore;
265
+ private readonly tenantId?;
266
+ constructor(updateShipmentUseCase: UpdateShipmentUseCase, eventStore: IEventStore, tenantId?: string | undefined);
267
+ execute(command: UpdateShipmentCommand): Promise<UpdateShipmentResult>;
268
+ }
269
+
270
+ declare class GetShipmentQuery implements IQuery<ShipmentReadModel | null> {
271
+ readonly shipmentId: string;
272
+ readonly tenantId: string;
273
+ readonly type = "GetShipment";
274
+ constructor(shipmentId: string, tenantId: string);
275
+ }
276
+ declare class GetShipmentHandler implements IQueryHandler<GetShipmentQuery, ShipmentReadModel | null> {
277
+ private readonly readModel;
278
+ constructor(readModel: IReadModel);
279
+ execute(query: GetShipmentQuery): Promise<ShipmentReadModel | null>;
280
+ }
281
+
282
+ interface ListShipmentsFilter {
283
+ tenantId: string;
284
+ accountId?: string;
285
+ status?: string;
286
+ limit?: number;
287
+ offset?: number;
288
+ }
289
+ declare class ListShipmentsQuery implements IQuery<ShipmentReadModel[]> {
290
+ readonly filter: ListShipmentsFilter;
291
+ readonly type = "ListShipments";
292
+ constructor(filter: ListShipmentsFilter);
293
+ }
294
+ declare class ListShipmentsHandler implements IQueryHandler<ListShipmentsQuery, ShipmentReadModel[]> {
295
+ private readonly readModel;
296
+ constructor(readModel: IReadModel);
297
+ execute(query: ListShipmentsQuery): Promise<ShipmentReadModel[]>;
298
+ }
299
+
300
+ declare class GetShipmentHistoryQuery implements IQuery<DomainEvent[]> {
301
+ readonly shipmentId: string;
302
+ readonly sinceVersion?: number | undefined;
303
+ readonly type = "GetShipmentHistory";
304
+ constructor(shipmentId: string, sinceVersion?: number | undefined);
305
+ }
306
+ declare class GetShipmentHistoryHandler implements IQueryHandler<GetShipmentHistoryQuery, DomainEvent[]> {
307
+ private readonly eventStore;
308
+ constructor(eventStore: IEventStore);
309
+ execute(query: GetShipmentHistoryQuery): Promise<DomainEvent[]>;
310
+ }
311
+
312
+ declare class AsyncLocalStorageTenantContext implements ITenantContextProvider {
313
+ private storage;
314
+ getCurrent(): TenantContext | null;
315
+ set(context: TenantContext): void;
316
+ clear(): void;
317
+ isolate<T>(context: TenantContext, fn: () => Promise<T>): Promise<T>;
318
+ }
319
+
320
+ declare class PostgresReadModel implements IReadModel {
321
+ private pool;
322
+ constructor(connectionString: string, poolConfig?: {
323
+ max?: number;
324
+ idleTimeoutMillis?: number;
325
+ connectionTimeoutMillis?: number;
326
+ });
327
+ init(): Promise<void>;
328
+ upsert(shipment: ShipmentReadModel): Promise<void>;
329
+ getById(id: string, tenantId: string): Promise<ShipmentReadModel | null>;
330
+ query(filters: {
331
+ tenantId: string;
332
+ accountId?: string;
333
+ status?: string;
334
+ limit?: number;
335
+ offset?: number;
336
+ }): Promise<ShipmentReadModel[]>;
337
+ close(): Promise<void>;
338
+ }
339
+
340
+ declare class ImmutableAuditLog implements IAuditLogService {
341
+ private db;
342
+ private readonly algorithm;
343
+ constructor(dbPath?: string);
344
+ log(entry: Omit<AuditLogEntry, 'signature'>, privateKey: string): Promise<void>;
345
+ verify(entry: AuditLogEntry, key: string): boolean;
346
+ query(filters: {
347
+ tenantId: string;
348
+ resourceType?: string;
349
+ resourceId?: string;
350
+ since?: string;
351
+ until?: string;
352
+ }): Promise<AuditLogEntry[]>;
353
+ exportToSIEM(format: 'json' | 'cef' | 'leef'): Promise<string>;
354
+ close(): void;
355
+ }
356
+
357
+ interface TenantConfig {
358
+ tenantId: string;
359
+ accountId: string;
360
+ dbSchema?: string;
361
+ features: {
362
+ auditLog: boolean;
363
+ readModel: boolean;
364
+ webhookReplay: boolean;
365
+ };
366
+ rateLimits: {
367
+ requestsPerMinute: number;
368
+ concurrentShipments: number;
369
+ };
370
+ }
371
+
372
+ interface EnterpriseServices {
373
+ tenantProvider: ITenantContextProvider;
374
+ schemaIsolation: SchemaIsolationManager;
375
+ readModel: IReadModel;
376
+ projection: RedisStreamsProjection;
377
+ shipmentProjection: ShipmentProjection;
378
+ eventStore: SqliteEventStore;
379
+ auditLog: IAuditLogService;
380
+ siemExporter: SiemExporter;
381
+ auditService: AuditLogService;
382
+ chaosTester: HttpChaosTester;
383
+ tenantMiddleware: ReturnType<typeof createTenantMiddleware>;
384
+ commands: {
385
+ createShipment: CreateShipmentHandler;
386
+ cancelShipment: CancelShipmentHandler;
387
+ executeRecharge: ExecuteRechargeHandler;
388
+ updateShipment: UpdateShipmentHandler;
389
+ };
390
+ queries: {
391
+ getShipment: GetShipmentHandler;
392
+ listShipments: ListShipmentsHandler;
393
+ getShipmentHistory: GetShipmentHistoryHandler;
394
+ };
395
+ }
396
+ declare function bootstrapEnterprise(base: Services, config: EnterpriseConfig): EnterpriseServices;
397
+
398
+ export { AsyncLocalStorageTenantContext, type AuditLogEntry, AuditLogService, CancelShipmentCommand, CancelShipmentHandler, type CancelShipmentResult, type ChaosAttack, CreateShipmentCommand, CreateShipmentHandler, type CreateShipmentResult, type EnterpriseConfig, type EnterpriseServices, ExecuteRechargeCommand, ExecuteRechargeHandler, type ExecuteRechargeResult, GetShipmentHandler, GetShipmentHistoryHandler, GetShipmentHistoryQuery, GetShipmentQuery, HttpChaosTester, type IAuditLogService, type IChaosTester, type ICommand, type ICommandHandler, type IProjectionHandler, type IQuery, type IQueryHandler, type IReadModel, type ITenantContextProvider, ImmutableAuditLog, ListShipmentsHandler, ListShipmentsQuery, PostgresReadModel, RedisStreamsProjection, SchemaIsolationManager, ShipmentProjection, type ShipmentReadModel, SiemExporter, type TenantConfig, type TenantContext, type TenantExtractor, UpdateShipmentCommand, UpdateShipmentHandler, type UpdateShipmentResult, bootstrapEnterprise, createTenantMiddleware };