@terminator-network/core 0.1.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,356 @@
1
+ import { z } from 'zod';
2
+ import Database from 'better-sqlite3';
3
+
4
+ declare const ConfigSchema: z.ZodObject<{
5
+ cfApiToken: z.ZodOptional<z.ZodString>;
6
+ cfAccountId: z.ZodOptional<z.ZodString>;
7
+ cfZoneId: z.ZodOptional<z.ZodString>;
8
+ emailDomain: z.ZodOptional<z.ZodString>;
9
+ twilioAccountSid: z.ZodOptional<z.ZodString>;
10
+ twilioAuthToken: z.ZodOptional<z.ZodString>;
11
+ lithicApiKey: z.ZodOptional<z.ZodString>;
12
+ lithicEnvironment: z.ZodDefault<z.ZodEnum<["sandbox", "production"]>>;
13
+ dbPath: z.ZodDefault<z.ZodString>;
14
+ logLevel: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error"]>>;
15
+ maxIdentities: z.ZodDefault<z.ZodNumber>;
16
+ defaultTtlMinutes: z.ZodDefault<z.ZodNumber>;
17
+ defaultSpendLimitCents: z.ZodDefault<z.ZodNumber>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ lithicEnvironment: "sandbox" | "production";
20
+ dbPath: string;
21
+ logLevel: "debug" | "info" | "warn" | "error";
22
+ maxIdentities: number;
23
+ defaultTtlMinutes: number;
24
+ defaultSpendLimitCents: number;
25
+ cfApiToken?: string | undefined;
26
+ cfAccountId?: string | undefined;
27
+ cfZoneId?: string | undefined;
28
+ emailDomain?: string | undefined;
29
+ twilioAccountSid?: string | undefined;
30
+ twilioAuthToken?: string | undefined;
31
+ lithicApiKey?: string | undefined;
32
+ }, {
33
+ cfApiToken?: string | undefined;
34
+ cfAccountId?: string | undefined;
35
+ cfZoneId?: string | undefined;
36
+ emailDomain?: string | undefined;
37
+ twilioAccountSid?: string | undefined;
38
+ twilioAuthToken?: string | undefined;
39
+ lithicApiKey?: string | undefined;
40
+ lithicEnvironment?: "sandbox" | "production" | undefined;
41
+ dbPath?: string | undefined;
42
+ logLevel?: "debug" | "info" | "warn" | "error" | undefined;
43
+ maxIdentities?: number | undefined;
44
+ defaultTtlMinutes?: number | undefined;
45
+ defaultSpendLimitCents?: number | undefined;
46
+ }>;
47
+ type TerminatorConfig = z.infer<typeof ConfigSchema>;
48
+ declare function loadConfig(overrides?: Partial<TerminatorConfig>): TerminatorConfig;
49
+ declare function getConfiguredProviders(config: TerminatorConfig): {
50
+ email: boolean;
51
+ phone: boolean;
52
+ card: boolean;
53
+ };
54
+
55
+ interface Persona {
56
+ firstName: string;
57
+ lastName: string;
58
+ fullName: string;
59
+ email?: string;
60
+ phone?: string;
61
+ address: {
62
+ line1: string;
63
+ city: string;
64
+ state: string;
65
+ postalCode: string;
66
+ country: string;
67
+ };
68
+ }
69
+ declare function createPersona(): Persona;
70
+
71
+ type IdentityStatus = "created" | "provisioning" | "active" | "killing" | "killed" | "failed";
72
+ type IdentityResources = ("email" | "phone" | "card")[];
73
+ interface Identity {
74
+ id: string;
75
+ persona: Persona;
76
+ status: IdentityStatus;
77
+ email?: string;
78
+ emailProviderId?: string;
79
+ phone?: string;
80
+ phoneProviderId?: string;
81
+ cardLastFour?: string;
82
+ cardProviderId?: string;
83
+ spendLimitCents?: number;
84
+ ttlExpiresAt?: string;
85
+ resources: IdentityResources;
86
+ createdAt: string;
87
+ updatedAt: string;
88
+ }
89
+
90
+ interface EmailInbox {
91
+ address: string;
92
+ providerId: string;
93
+ provider: string;
94
+ }
95
+ interface EmailMessage {
96
+ id: string;
97
+ from: string;
98
+ to: string;
99
+ subject: string;
100
+ text: string;
101
+ html?: string;
102
+ receivedAt: string;
103
+ }
104
+ interface EmailProvider {
105
+ name: string;
106
+ createInbox(identity: Identity): Promise<EmailInbox>;
107
+ getMessages(inbox: EmailInbox, since?: Date): Promise<EmailMessage[]>;
108
+ deleteInbox(inbox: EmailInbox): Promise<void>;
109
+ healthCheck(): Promise<ProviderHealthResult>;
110
+ }
111
+ interface PhoneNumber {
112
+ number: string;
113
+ providerId: string;
114
+ provider: string;
115
+ }
116
+ interface SmsMessage {
117
+ id: string;
118
+ from: string;
119
+ to: string;
120
+ body: string;
121
+ receivedAt: string;
122
+ }
123
+ interface PhoneOptions {
124
+ country?: string;
125
+ areaCode?: number;
126
+ }
127
+ interface PhoneProvider {
128
+ name: string;
129
+ provisionNumber(identity: Identity, options?: PhoneOptions): Promise<PhoneNumber>;
130
+ getMessages(phone: PhoneNumber, since?: Date): Promise<SmsMessage[]>;
131
+ releaseNumber(phone: PhoneNumber): Promise<void>;
132
+ healthCheck(): Promise<ProviderHealthResult>;
133
+ }
134
+ interface VirtualCard {
135
+ lastFour: string;
136
+ providerId: string;
137
+ provider: string;
138
+ }
139
+ interface CardDetails {
140
+ pan: string;
141
+ cvv: string;
142
+ expMonth: number;
143
+ expYear: number;
144
+ lastFour: string;
145
+ }
146
+ interface CardOptions {
147
+ spendLimitCents: number;
148
+ type?: "single_use" | "reusable";
149
+ }
150
+ interface CardProvider {
151
+ name: string;
152
+ createCard(identity: Identity, options: CardOptions): Promise<VirtualCard>;
153
+ getCardDetails(card: VirtualCard): Promise<CardDetails>;
154
+ deactivateCard(card: VirtualCard): Promise<void>;
155
+ healthCheck(): Promise<ProviderHealthResult>;
156
+ }
157
+ interface ProviderHealthResult {
158
+ provider: string;
159
+ healthy: boolean;
160
+ message?: string;
161
+ }
162
+
163
+ type ActivityEventType = "identity.created" | "identity.provisioning" | "identity.active" | "identity.killing" | "identity.killed" | "identity.failed" | "email.inbox_created" | "email.received" | "email.inbox_deleted" | "phone.provisioned" | "phone.sms_received" | "phone.released" | "card.created" | "card.deactivated" | "policy.violated" | "system.error";
164
+ interface ActivityEvent {
165
+ id: string;
166
+ identityId: string | null;
167
+ timestamp: string;
168
+ eventType: ActivityEventType;
169
+ provider: string | null;
170
+ resourceType: string | null;
171
+ resourceId: string | null;
172
+ details: Record<string, unknown> | null;
173
+ costEstimateCents: number | null;
174
+ }
175
+ declare class ActivityLog {
176
+ private db;
177
+ constructor(db: Database.Database);
178
+ append(event: Omit<ActivityEvent, "id" | "timestamp">): ActivityEvent;
179
+ query(options?: {
180
+ identityId?: string;
181
+ eventType?: ActivityEventType;
182
+ limit?: number;
183
+ since?: string;
184
+ }): ActivityEvent[];
185
+ }
186
+
187
+ declare class IdentityStore {
188
+ private db;
189
+ constructor(db: Database.Database);
190
+ create(persona: Persona, resources: IdentityResources, options?: {
191
+ spendLimitCents?: number;
192
+ ttlMinutes?: number;
193
+ }): Identity;
194
+ get(id: string): Identity | null;
195
+ list(status?: IdentityStatus): Identity[];
196
+ updateStatus(id: string, newStatus: IdentityStatus): Identity;
197
+ updateResources(id: string, updates: Partial<Pick<Identity, "email" | "emailProviderId" | "phone" | "phoneProviderId" | "cardLastFour" | "cardProviderId">>): Identity;
198
+ getExpired(): Identity[];
199
+ countActive(): number;
200
+ }
201
+
202
+ interface KillResult {
203
+ identityId: string;
204
+ emailRevoked: boolean;
205
+ phoneRevoked: boolean;
206
+ cardRevoked: boolean;
207
+ errors: string[];
208
+ }
209
+ declare class KillSwitch {
210
+ private identityStore;
211
+ private activityLog;
212
+ private emailProvider?;
213
+ private phoneProvider?;
214
+ private cardProvider?;
215
+ constructor(identityStore: IdentityStore, activityLog: ActivityLog, emailProvider?: EmailProvider | undefined, phoneProvider?: PhoneProvider | undefined, cardProvider?: CardProvider | undefined);
216
+ killIdentity(id: string): Promise<KillResult>;
217
+ killAll(): Promise<KillResult[]>;
218
+ private revokeEmail;
219
+ private revokePhone;
220
+ private revokeCard;
221
+ }
222
+
223
+ type PolicyRuleType = "max_identities" | "max_spend_per_identity" | "default_ttl_minutes" | "require_card_approval";
224
+ interface Policy {
225
+ id: string;
226
+ name: string;
227
+ ruleType: PolicyRuleType;
228
+ ruleValue: unknown;
229
+ enabled: boolean;
230
+ createdAt: string;
231
+ }
232
+ declare class PolicyStore {
233
+ private db;
234
+ constructor(db: Database.Database);
235
+ create(name: string, ruleType: PolicyRuleType, ruleValue: unknown): Policy;
236
+ get(id: string): Policy | null;
237
+ list(): Policy[];
238
+ getEnabled(): Policy[];
239
+ setEnabled(id: string, enabled: boolean): void;
240
+ delete(id: string): void;
241
+ }
242
+
243
+ interface PolicyViolation {
244
+ policy: string;
245
+ ruleType: string;
246
+ message: string;
247
+ }
248
+ declare class PolicyEngine {
249
+ private policyStore;
250
+ private identityStore;
251
+ private config;
252
+ constructor(policyStore: PolicyStore, identityStore: IdentityStore, config: TerminatorConfig);
253
+ checkCreateIdentity(resources: IdentityResources, spendLimitCents?: number): PolicyViolation[];
254
+ private evaluateForCreate;
255
+ }
256
+
257
+ interface TerminatorOptions {
258
+ config?: Partial<TerminatorConfig>;
259
+ emailProvider?: EmailProvider;
260
+ phoneProvider?: PhoneProvider;
261
+ cardProvider?: CardProvider;
262
+ inMemory?: boolean;
263
+ }
264
+ interface CreateIdentityOptions {
265
+ resources?: IdentityResources;
266
+ spendLimitCents?: number;
267
+ ttlMinutes?: number;
268
+ confirm?: boolean;
269
+ }
270
+ declare class Terminator {
271
+ readonly config: TerminatorConfig;
272
+ readonly identityStore: IdentityStore;
273
+ readonly activityLog: ActivityLog;
274
+ readonly policyStore: PolicyStore;
275
+ readonly policyEngine: PolicyEngine;
276
+ readonly killSwitch: KillSwitch;
277
+ private emailProvider?;
278
+ private phoneProvider?;
279
+ private cardProvider?;
280
+ private db;
281
+ constructor(options?: TerminatorOptions);
282
+ createIdentity(options?: CreateIdentityOptions): Promise<Identity>;
283
+ getIdentity(id: string): Identity | null;
284
+ listIdentities(status?: "active" | "killed" | "all"): Identity[];
285
+ readMessages(identityId: string, since?: Date): Promise<{
286
+ emails: EmailMessage[];
287
+ sms: SmsMessage[];
288
+ }>;
289
+ getCardDetails(identityId: string): Promise<CardDetails>;
290
+ extractCode(identityId: string): Promise<string | null>;
291
+ killIdentity(id: string): Promise<KillResult>;
292
+ killAll(): Promise<KillResult[]>;
293
+ getActivityLog(options?: {
294
+ identityId?: string;
295
+ eventType?: ActivityEventType;
296
+ limit?: number;
297
+ since?: string;
298
+ }): ActivityEvent[];
299
+ checkStatus(): Promise<{
300
+ providers: ProviderHealthResult[];
301
+ activeIdentities: number;
302
+ configuredProviders: {
303
+ email: boolean;
304
+ phone: boolean;
305
+ card: boolean;
306
+ };
307
+ }>;
308
+ close(): void;
309
+ }
310
+ declare class PolicyViolationError extends Error {
311
+ violations: PolicyViolation[];
312
+ constructor(violations: PolicyViolation[]);
313
+ }
314
+
315
+ declare function canTransition(from: IdentityStatus, to: IdentityStatus): boolean;
316
+ declare function assertTransition(from: IdentityStatus, to: IdentityStatus): void;
317
+
318
+ declare class MockEmailProvider implements EmailProvider {
319
+ name: string;
320
+ private inboxes;
321
+ createInbox(identity: Identity): Promise<EmailInbox>;
322
+ getMessages(inbox: EmailInbox, since?: Date): Promise<EmailMessage[]>;
323
+ deleteInbox(inbox: EmailInbox): Promise<void>;
324
+ healthCheck(): Promise<ProviderHealthResult>;
325
+ injectMessage(address: string, message: Omit<EmailMessage, "id" | "receivedAt">): void;
326
+ }
327
+
328
+ declare class MockPhoneProvider implements PhoneProvider {
329
+ name: string;
330
+ private numbers;
331
+ provisionNumber(_identity: Identity, _options?: PhoneOptions): Promise<PhoneNumber>;
332
+ getMessages(phone: PhoneNumber, since?: Date): Promise<SmsMessage[]>;
333
+ releaseNumber(phone: PhoneNumber): Promise<void>;
334
+ healthCheck(): Promise<ProviderHealthResult>;
335
+ injectSms(number: string, message: Omit<SmsMessage, "id" | "receivedAt">): void;
336
+ }
337
+
338
+ declare class MockCardProvider implements CardProvider {
339
+ name: string;
340
+ private cards;
341
+ createCard(_identity: Identity, options: CardOptions): Promise<VirtualCard>;
342
+ getCardDetails(card: VirtualCard): Promise<CardDetails>;
343
+ deactivateCard(card: VirtualCard): Promise<void>;
344
+ healthCheck(): Promise<ProviderHealthResult>;
345
+ }
346
+
347
+ declare function createDatabase(dbPath: string): Database.Database;
348
+ declare function createInMemoryDatabase(): Database.Database;
349
+
350
+ interface VerificationCodeResult {
351
+ code: string;
352
+ pattern: string;
353
+ }
354
+ declare function parseVerificationCode(text: string): VerificationCodeResult | null;
355
+
356
+ export { type ActivityEvent, type ActivityEventType, ActivityLog, type CardDetails, type CardOptions, type CardProvider, type CreateIdentityOptions, type EmailInbox, type EmailMessage, type EmailProvider, type Identity, type IdentityResources, type IdentityStatus, IdentityStore, type KillResult, KillSwitch, MockCardProvider, MockEmailProvider, MockPhoneProvider, type Persona, type PhoneNumber, type PhoneOptions, type PhoneProvider, type Policy, PolicyEngine, type PolicyRuleType, PolicyStore, type PolicyViolation, PolicyViolationError, type ProviderHealthResult, type SmsMessage, Terminator, type TerminatorConfig, type TerminatorOptions, type VerificationCodeResult, type VirtualCard, assertTransition, canTransition, createDatabase, createInMemoryDatabase, createPersona, getConfiguredProviders, loadConfig, parseVerificationCode };