immortal-js 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 +21 -0
- package/README.md +577 -0
- package/docs/CHANGELOG.md +21 -0
- package/docs/CONTRIBUTING.md +41 -0
- package/docs/api/chaos.md +179 -0
- package/docs/api/dashboard.md +109 -0
- package/docs/api/isolation.md +191 -0
- package/docs/api/lifecycle.md +187 -0
- package/docs/api/monitoring.md +313 -0
- package/docs/api/plugins.md +217 -0
- package/docs/api/recovery.md +267 -0
- package/docs/api/safe-zone.md +236 -0
- package/docs/api/supervision.md +285 -0
- package/docs/guides/configuration.md +168 -0
- package/docs/guides/express.md +171 -0
- package/docs/guides/fastify.md +188 -0
- package/docs/guides/koa.md +102 -0
- package/docs/guides/nestjs.md +182 -0
- package/docs/guides/testing.md +91 -0
- package/examples/express-basic/index.ts +462 -0
- package/examples/express-basic/package.json +21 -0
- package/examples/express-basic/tsconfig.json +24 -0
- package/examples/fastify-microservice/index.ts +342 -0
- package/examples/fastify-microservice/package.json +22 -0
- package/examples/fastify-microservice/tsconfig.json +24 -0
- package/examples/invoice-service/data/invoices.db +0 -0
- package/examples/invoice-service/data/invoices.db-shm +0 -0
- package/examples/invoice-service/data/invoices.db-wal +0 -0
- package/examples/invoice-service/package.json +25 -0
- package/examples/invoice-service/public/index.html +5025 -0
- package/examples/invoice-service/src/db.ts +608 -0
- package/examples/invoice-service/src/pdf.ts +358 -0
- package/examples/invoice-service/src/server.ts +527 -0
- package/examples/invoice-service/src/store.ts +159 -0
- package/examples/invoice-service/src/types.ts +193 -0
- package/examples/invoice-service/tsconfig.json +23 -0
- package/examples/nestjs-enterprise/app.module.ts +561 -0
- package/examples/nestjs-enterprise/main.ts +67 -0
- package/examples/nestjs-enterprise/package.json +26 -0
- package/examples/nestjs-enterprise/tsconfig.json +27 -0
- package/immortal-js-1.0.0.tgz +0 -0
- package/package.json +33 -0
- package/packages/adapter-express/package.json +34 -0
- package/packages/adapter-express/src/index.ts +349 -0
- package/packages/adapter-express/tsconfig.json +14 -0
- package/packages/adapter-fastify/package.json +56 -0
- package/packages/adapter-fastify/src/plugin.ts +226 -0
- package/packages/adapter-fastify/tsconfig.json +14 -0
- package/packages/adapter-koa/package.json +55 -0
- package/packages/adapter-koa/src/index.ts +207 -0
- package/packages/adapter-koa/tsconfig.json +14 -0
- package/packages/adapter-nestjs/package.json +61 -0
- package/packages/adapter-nestjs/src/immortal.module.ts +313 -0
- package/packages/adapter-nestjs/src/index.ts +14 -0
- package/packages/adapter-nestjs/tsconfig.json +16 -0
- package/packages/core/package.json +56 -0
- package/packages/core/src/chaos/ChaosEngine.ts +249 -0
- package/packages/core/src/config/defaults.ts +200 -0
- package/packages/core/src/config/schema.ts +199 -0
- package/packages/core/src/event-bus.ts +168 -0
- package/packages/core/src/index.ts +164 -0
- package/packages/core/src/isolation/BulkheadPool.ts +279 -0
- package/packages/core/src/isolation/WorkerSandbox.ts +306 -0
- package/packages/core/src/isolation/index.ts +8 -0
- package/packages/core/src/lifecycle/GracefulShutdown.ts +161 -0
- package/packages/core/src/logger.ts +104 -0
- package/packages/core/src/monitoring/DiagnosticsChannel.ts +248 -0
- package/packages/core/src/monitoring/HealthMonitor.ts +191 -0
- package/packages/core/src/monitoring/MemoryLeakGuard.ts +340 -0
- package/packages/core/src/monitoring/MetricsCollector.ts +219 -0
- package/packages/core/src/monitoring/index.ts +10 -0
- package/packages/core/src/plugins/BuiltinPlugins.ts +269 -0
- package/packages/core/src/recovery/CircuitBreaker.ts +334 -0
- package/packages/core/src/recovery/FallbackCache.ts +328 -0
- package/packages/core/src/recovery/RetryEngine.ts +225 -0
- package/packages/core/src/recovery/Timeout.ts +97 -0
- package/packages/core/src/recovery/index.ts +11 -0
- package/packages/core/src/runtime.ts +242 -0
- package/packages/core/src/safe-zone/AsyncBoundary.ts +114 -0
- package/packages/core/src/safe-zone/ErrorTrap.ts +347 -0
- package/packages/core/src/safe-zone/SafeWrapper.ts +317 -0
- package/packages/core/src/safe-zone/index.ts +23 -0
- package/packages/core/src/supervision/ClusterManager.ts +243 -0
- package/packages/core/src/supervision/RestartStrategy.ts +68 -0
- package/packages/core/src/supervision/Supervisor.ts +311 -0
- package/packages/core/src/supervision/index.ts +11 -0
- package/packages/core/src/types.ts +470 -0
- package/packages/core/test/bulkhead.test.ts +310 -0
- package/packages/core/test/circuit-breaker.test.ts +153 -0
- package/packages/core/test/memory-guard.test.ts +213 -0
- package/packages/core/test/retry.test.ts +110 -0
- package/packages/core/test/safe-zone.test.ts +271 -0
- package/packages/core/test/supervisor.test.ts +310 -0
- package/packages/core/tsconfig.json +13 -0
- package/packages/dashboard/package.json +56 -0
- package/packages/dashboard/server/DashboardServer.ts +454 -0
- package/packages/dashboard/tsconfig.json +14 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/types.ts
|
|
3
|
+
* @description Invoice Service Pro v3 — Complete Domain Type Definitions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ─── Currency ─────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
export type InvoiceCurrency = "USD" | "EUR" | "GBP" | "AED" | "SAR" | "JPY" | "CAD" | "AUD";
|
|
9
|
+
|
|
10
|
+
export const CURRENCY_META: Record<InvoiceCurrency, { symbol: string; locale: string; name: string }> = {
|
|
11
|
+
USD: { symbol: "$", locale: "en-US", name: "US Dollar" },
|
|
12
|
+
EUR: { symbol: "€", locale: "de-DE", name: "Euro" },
|
|
13
|
+
GBP: { symbol: "£", locale: "en-GB", name: "British Pound" },
|
|
14
|
+
AED: { symbol: "AED", locale: "ar-AE", name: "UAE Dirham" },
|
|
15
|
+
SAR: { symbol: "SAR", locale: "ar-SA", name: "Saudi Riyal" },
|
|
16
|
+
JPY: { symbol: "¥", locale: "ja-JP", name: "Japanese Yen" },
|
|
17
|
+
CAD: { symbol: "CA$", locale: "en-CA", name: "Canadian Dollar"},
|
|
18
|
+
AUD: { symbol: "A$", locale: "en-AU", name: "Australian Dollar"},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ─── Invoice Status ────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
export type InvoiceStatus = "draft" | "sent" | "paid" | "overdue" | "cancelled" | "refunded";
|
|
24
|
+
|
|
25
|
+
// ─── Core Domain Types ─────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
export interface InvoiceParty {
|
|
28
|
+
name: string;
|
|
29
|
+
email: string;
|
|
30
|
+
phone?: string;
|
|
31
|
+
address: string;
|
|
32
|
+
city: string;
|
|
33
|
+
country: string;
|
|
34
|
+
taxId?: string;
|
|
35
|
+
website?: string;
|
|
36
|
+
logoUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface InvoiceLineItem {
|
|
40
|
+
id: string;
|
|
41
|
+
description: string;
|
|
42
|
+
quantity: number;
|
|
43
|
+
unitPrice: number; // in cents
|
|
44
|
+
taxRate: number; // 0–1, e.g. 0.20 = 20%
|
|
45
|
+
discount?: number; // 0–1, e.g. 0.10 = 10% off
|
|
46
|
+
unit?: string; // "hrs", "pcs", "mo", etc.
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface InvoiceActivity {
|
|
50
|
+
id: string;
|
|
51
|
+
invoiceId: string;
|
|
52
|
+
action: "created" | "sent" | "viewed" | "paid" | "overdue" | "cancelled" | "refunded" | "status_changed" | "note_added";
|
|
53
|
+
note?: string;
|
|
54
|
+
performedAt: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Invoice {
|
|
58
|
+
id: string;
|
|
59
|
+
number: string;
|
|
60
|
+
status: InvoiceStatus;
|
|
61
|
+
currency: InvoiceCurrency;
|
|
62
|
+
issuedAt: string;
|
|
63
|
+
dueAt: string;
|
|
64
|
+
paidAt?: string;
|
|
65
|
+
from: InvoiceParty;
|
|
66
|
+
to: InvoiceParty;
|
|
67
|
+
lineItems: InvoiceLineItem[];
|
|
68
|
+
notes?: string;
|
|
69
|
+
terms?: string;
|
|
70
|
+
discount?: number; // global invoice-level discount (0–1)
|
|
71
|
+
reference?: string; // PO number / external reference
|
|
72
|
+
tags?: string[];
|
|
73
|
+
createdAt: string;
|
|
74
|
+
updatedAt: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ─── Computed ─────────────────────────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
export interface InvoiceTotals {
|
|
80
|
+
subtotalCents: number;
|
|
81
|
+
discountCents: number;
|
|
82
|
+
taxCents: number;
|
|
83
|
+
totalCents: number;
|
|
84
|
+
subtotal: string;
|
|
85
|
+
discount: string;
|
|
86
|
+
tax: string;
|
|
87
|
+
total: string;
|
|
88
|
+
effectiveTaxRate: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ─── Client (separate from invoice party) ─────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
export interface Client {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
email: string;
|
|
97
|
+
phone?: string;
|
|
98
|
+
address: string;
|
|
99
|
+
city: string;
|
|
100
|
+
country: string;
|
|
101
|
+
taxId?: string;
|
|
102
|
+
website?: string;
|
|
103
|
+
notes?: string;
|
|
104
|
+
createdAt: string;
|
|
105
|
+
updatedAt: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ─── Analytics ────────────────────────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
export interface DashboardStats {
|
|
111
|
+
totalInvoices: number;
|
|
112
|
+
totalRevenueCents: number;
|
|
113
|
+
outstandingCents: number;
|
|
114
|
+
overdueCents: number;
|
|
115
|
+
draftCount: number;
|
|
116
|
+
sentCount: number;
|
|
117
|
+
paidCount: number;
|
|
118
|
+
overdueCount: number;
|
|
119
|
+
cancelledCount: number;
|
|
120
|
+
totalClients: number;
|
|
121
|
+
avgInvoiceCents: number;
|
|
122
|
+
revenueThisMonth: number;
|
|
123
|
+
revenueLastMonth: number;
|
|
124
|
+
invoicesByStatus: Record<InvoiceStatus, number>;
|
|
125
|
+
recentActivity: InvoiceActivity[];
|
|
126
|
+
topClients: { name: string; totalCents: number; invoiceCount: number }[];
|
|
127
|
+
monthlyRevenue: { month: string; cents: number }[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ─── API Payloads ──────────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
export interface CreateInvoiceDto {
|
|
133
|
+
currency?: InvoiceCurrency;
|
|
134
|
+
issuedAt?: string;
|
|
135
|
+
dueAt?: string;
|
|
136
|
+
reference?: string;
|
|
137
|
+
from: InvoiceParty;
|
|
138
|
+
to: InvoiceParty;
|
|
139
|
+
lineItems: Omit<InvoiceLineItem, "id">[];
|
|
140
|
+
notes?: string;
|
|
141
|
+
terms?: string;
|
|
142
|
+
discount?: number;
|
|
143
|
+
tags?: string[];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface UpdateInvoiceDto {
|
|
147
|
+
status?: InvoiceStatus;
|
|
148
|
+
notes?: string;
|
|
149
|
+
terms?: string;
|
|
150
|
+
reference?: string;
|
|
151
|
+
paidAt?: string;
|
|
152
|
+
tags?: string[];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface CreateClientDto {
|
|
156
|
+
name: string;
|
|
157
|
+
email: string;
|
|
158
|
+
phone?: string;
|
|
159
|
+
address: string;
|
|
160
|
+
city: string;
|
|
161
|
+
country: string;
|
|
162
|
+
taxId?: string;
|
|
163
|
+
website?: string;
|
|
164
|
+
notes?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface ApiError {
|
|
168
|
+
error: string;
|
|
169
|
+
code: string;
|
|
170
|
+
timestamp: string;
|
|
171
|
+
details?: unknown;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface PaginatedResponse<T> {
|
|
175
|
+
data: T[];
|
|
176
|
+
total: number;
|
|
177
|
+
page: number;
|
|
178
|
+
limit: number;
|
|
179
|
+
totalPages: number;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface InvoiceListQuery {
|
|
183
|
+
status?: InvoiceStatus;
|
|
184
|
+
currency?: InvoiceCurrency;
|
|
185
|
+
clientName?: string;
|
|
186
|
+
search?: string;
|
|
187
|
+
page?: number;
|
|
188
|
+
limit?: number;
|
|
189
|
+
sortBy?: "number" | "issuedAt" | "dueAt" | "total" | "status";
|
|
190
|
+
sortDir?: "asc" | "desc";
|
|
191
|
+
dateFrom?: string;
|
|
192
|
+
dateTo?: string;
|
|
193
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "Node16",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"strictNullChecks": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"exactOptionalPropertyTypes": true,
|
|
11
|
+
"noImplicitOverride": true,
|
|
12
|
+
"declaration": false,
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"allowSyntheticDefaultImports": true,
|
|
16
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
"rootDir": "src"
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/**/*.ts"],
|
|
22
|
+
"exclude": ["node_modules", "dist", "public"]
|
|
23
|
+
}
|