@sylphx/sdk 0.26.0 → 0.27.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 CHANGED
@@ -59,8 +59,13 @@ import { WIRE_CONTRACT_PACKAGE, WIRE_CONTRACT_REVISION } from '@sylphx/sdk'
59
59
 
60
60
  ## CLI
61
61
 
62
- Operator CLI remains **Rust** binary `sylphx` (`sylphx-cli` on crates.io).
63
- TS `@sylphx/cli` is not the product path.
62
+ Operator CLI is the **Rust** binary `sylphx` (crate `sylphx-cli`). Install via
63
+ either channel — same binary product:
64
+
65
+ ```bash
66
+ npm install -g @sylphx/cli # npm channel (native binary optionalDeps)
67
+ cargo install sylphx-cli # crates.io channel
68
+ ```
64
69
 
65
70
  ## Install (commercial)
66
71
 
@@ -71,8 +76,7 @@ npm install @sylphx/sdk
71
76
  # Rust libraries
72
77
  # Cargo.toml: sylphx-sdk = "0.1", sylphx-sdk-management = "0.1"
73
78
 
74
- # Operator CLI (Rust only — not npm @sylphx/cli)
75
- cargo install sylphx-cli
79
+ # Operator CLI (Rust binary — npm or cargo)
80
+ npm install -g @sylphx/cli
81
+ # or: cargo install sylphx-cli
76
82
  ```
77
-
78
- **Not product:** `npm install @sylphx/cli` (retired TypeScript CLI).
package/dist/index.d.ts CHANGED
@@ -76,6 +76,74 @@ interface PlatformRealtimeDeleteChannelResult {
76
76
  readonly success: boolean;
77
77
  }
78
78
 
79
+ /**
80
+ * Database Pricing Configuration (SSOT)
81
+ *
82
+ * All database billing constants centralized here.
83
+ * Used by billing calculations, usage tracking, and cost display.
84
+ *
85
+ * Pricing Strategy:
86
+ * - Self-hosted infra on AX162-R: flat ~$270/month
87
+ * - Competitive pricing with 75-99% margins
88
+ *
89
+ * Customer Prices (updated for self-hosted, 2026-02):
90
+ * - Compute: $0.08/hour (25% below Neon $0.106/hr)
91
+ * - Storage: $0.25/GB-month (29% below Neon $0.35/GB)
92
+ * - Transfer: $0.09/GB (matches Supabase)
93
+ */
94
+ /** Price per compute hour in microdollars ($0.08/hour = 80,000 microdollars) */
95
+ declare const COMPUTE_PRICE_PER_HOUR_MICRODOLLARS = 80000;
96
+ /** Free compute hours per month (platform free tier) */
97
+ declare const FREE_COMPUTE_HOURS = 3;
98
+ /** Price per GB-month in microdollars ($0.25/GB-month = 250,000 microdollars) */
99
+ declare const STORAGE_PRICE_PER_GB_MONTH_MICRODOLLARS = 250000;
100
+ /** Free storage in GB (256 MB) */
101
+ declare const FREE_STORAGE_GB = 0.25;
102
+ /** Price per GB data transfer ($0.09/GB = 90,000 microdollars) */
103
+ declare const TRANSFER_PRICE_PER_GB_MICRODOLLARS = 90000;
104
+ /** KV free storage in GB (256 MB) */
105
+ declare const KV_FREE_STORAGE_GB = 0.25;
106
+ /** Hours per month (AWS/GCP standard for billing) */
107
+ declare const HOURS_PER_MONTH = 730;
108
+
109
+ /**
110
+ * Referrals Configuration (SSOT)
111
+ *
112
+ * Single source of truth for referral system configuration.
113
+ * Used by: referral router, SDK referral endpoints
114
+ */
115
+ /** Default points awarded per successful referral */
116
+ declare const DEFAULT_POINTS_REWARD = 100;
117
+ /** Number of months the referral discount is valid */
118
+ declare const DISCOUNT_DURATION_MONTHS = 3;
119
+ /** Default discount percentage */
120
+ declare const DISCOUNT_PERCENT = 20;
121
+ /** Premium trial days from referral */
122
+ declare const PREMIUM_TRIAL_DAYS = 7;
123
+ /**
124
+ * Generate a cryptographically secure referral code
125
+ *
126
+ * Uses crypto.getRandomValues for uniform random bytes (0-255).
127
+ * Since REFERRAL_CODE_CHARS has exactly 32 characters and 256 / 32 = 8,
128
+ * byte % 32 produces perfectly uniform distribution with zero modulo bias.
129
+ *
130
+ * Entropy: 8 chars * log2(32) = 40 bits (~1.1 trillion possible codes)
131
+ *
132
+ * Format: 8 uppercase alphanumeric characters (excluding ambiguous: 0, O, I, L, 1)
133
+ */
134
+ declare function generateReferralCode(): string;
135
+
136
+ declare function getErrorMessage$1(error: unknown, fallback?: string): string;
137
+ interface ErrorDetails$1 {
138
+ message: string;
139
+ code?: string;
140
+ name?: string;
141
+ stack?: string;
142
+ status?: number;
143
+ cause?: unknown;
144
+ }
145
+ declare function getErrorDetails$1(error: unknown, fallbackMessage?: string): ErrorDetails$1;
146
+
79
147
  type Credential = {
80
148
  kind: 'bearer';
81
149
  token: string;
@@ -142,15 +210,11 @@ declare function encodePathSegment(s: string): string;
142
210
  /** Contract package identity (matches sylphx-wire). */
143
211
  declare const WIRE_CONTRACT_PACKAGE: "sylphx.platform.v1";
144
212
  /** Contract revision (matches sylphx-wire). */
145
- declare const WIRE_CONTRACT_REVISION: "0.3.0";
213
+ declare const WIRE_CONTRACT_REVISION: "0.4.0";
146
214
  interface PageRequest {
147
215
  pageToken?: string;
148
216
  pageSize?: number;
149
217
  }
150
- interface PageInfo {
151
- nextPageToken?: string;
152
- hasMore?: boolean;
153
- }
154
218
  /** Proto KvSetRequest; REST body uses decoded `value` JSON field. */
155
219
  interface KvSetRequest$1 {
156
220
  key: string;
@@ -256,6 +320,168 @@ interface ErrorEnvelope {
256
320
  };
257
321
  message?: string;
258
322
  }
323
+ interface PageInfo {
324
+ nextPageToken?: string;
325
+ hasMore?: boolean;
326
+ }
327
+ interface PageInfo {
328
+ nextPageToken?: string;
329
+ hasMore?: boolean;
330
+ totalSize?: number;
331
+ }
332
+ interface CreateDeployResponse {
333
+ id: string;
334
+ status: string;
335
+ projectId?: string;
336
+ environmentId?: string;
337
+ message?: string;
338
+ }
339
+ interface RollbackResponse {
340
+ id: string;
341
+ status: string;
342
+ projectId?: string;
343
+ message?: string;
344
+ }
345
+ interface ProjectStatusResponse {
346
+ projectId: string;
347
+ status: string;
348
+ environmentId?: string;
349
+ deploymentId?: string;
350
+ message?: string;
351
+ }
352
+ interface EnvVar$1 {
353
+ key: string;
354
+ value?: string;
355
+ secret: boolean;
356
+ envType?: string;
357
+ envId?: string;
358
+ }
359
+ interface ListEnvVarsResponse {
360
+ object: string;
361
+ data: EnvVar$1[];
362
+ }
363
+ interface SetEnvVarResponse {
364
+ envVar?: EnvVar$1;
365
+ created: boolean;
366
+ }
367
+ interface DeleteEnvVarResponse {
368
+ deleted: boolean;
369
+ key: string;
370
+ }
371
+ interface LogLine {
372
+ timestamp: string;
373
+ message: string;
374
+ level?: string;
375
+ service?: string;
376
+ source?: string;
377
+ }
378
+ interface ListLogsResponse {
379
+ object: string;
380
+ data: LogLine[];
381
+ }
382
+ interface Resource {
383
+ id: string;
384
+ kind: string;
385
+ name: string;
386
+ status: string;
387
+ projectId?: string;
388
+ storageGb?: number;
389
+ tier?: string;
390
+ message?: string;
391
+ }
392
+ interface ListResourcesResponse {
393
+ object: string;
394
+ data: Resource[];
395
+ page?: PageInfo;
396
+ }
397
+ interface CreateResourceResponse {
398
+ resource?: Resource;
399
+ message?: string;
400
+ }
401
+ interface DeleteResourceResponse {
402
+ deleted: boolean;
403
+ id: string;
404
+ }
405
+ interface BindResourceResponse {
406
+ bound: boolean;
407
+ resourceId: string;
408
+ environmentId: string;
409
+ }
410
+ interface BranchResourceResponse {
411
+ resource?: Resource;
412
+ }
413
+ interface ProjectStorage {
414
+ id: string;
415
+ name: string;
416
+ projectId: string;
417
+ publicUrl?: string;
418
+ status?: string;
419
+ }
420
+ interface CreateProjectStorageResponse {
421
+ storage?: ProjectStorage;
422
+ }
423
+ interface ListProjectStorageResponse {
424
+ object: string;
425
+ data: ProjectStorage[];
426
+ }
427
+ interface Task {
428
+ id: string;
429
+ name: string;
430
+ status: string;
431
+ mode?: string;
432
+ projectId?: string;
433
+ handler?: string;
434
+ }
435
+ interface ListTasksResponse {
436
+ object: string;
437
+ data: Task[];
438
+ page?: PageInfo;
439
+ }
440
+ interface CreateTaskResponse {
441
+ task?: Task;
442
+ }
443
+ interface Backup {
444
+ id: string;
445
+ status: string;
446
+ resourceId?: string;
447
+ tag?: string;
448
+ createdAt?: string;
449
+ }
450
+ interface ListBackupsResponse {
451
+ object: string;
452
+ data: Backup[];
453
+ }
454
+ interface CreateBackupResponse {
455
+ backup?: Backup;
456
+ }
457
+ interface RestoreBackupResponse {
458
+ id: string;
459
+ status: string;
460
+ message?: string;
461
+ }
462
+ interface Flag {
463
+ key: string;
464
+ enabled: boolean;
465
+ description?: string;
466
+ projectId?: string;
467
+ }
468
+ interface ListFlagsResponse {
469
+ object: string;
470
+ data: Flag[];
471
+ }
472
+ interface CreateFlagResponse {
473
+ flag?: Flag;
474
+ }
475
+ interface ToggleFlagResponse {
476
+ flag?: Flag;
477
+ }
478
+ interface PreviewCostResponse {
479
+ projectId: string;
480
+ prNumber: string;
481
+ total: number;
482
+ currency: string;
483
+ breakdownJson?: string;
484
+ }
259
485
 
260
486
  interface AppClientOptions {
261
487
  /** App secret `sk_…` / `pk_…`. */
@@ -314,6 +540,32 @@ declare class AppClientBuilder {
314
540
  /** Convenience factory (product name; not Effect-era createClient). */
315
541
  declare function createAppClient(key: string, tenantSlug: string): Client;
316
542
 
543
+ /** Map wire KvSetRequest → REST JSON body `{ key, value, ex? }`. */
544
+ declare function kvSetToRest(req: KvSetRequest$1): {
545
+ key: string;
546
+ value: unknown;
547
+ ex?: number;
548
+ };
549
+ /** Map REST get body → wire KvGetResponse. */
550
+ declare function kvGetFromRest(body: Record<string, unknown>): KvGetResponse;
551
+
552
+ /** Typed SDK failure (transport, auth, decode, or API). */
553
+ declare class SdkError extends Error {
554
+ readonly status?: number;
555
+ readonly code?: string;
556
+ readonly body?: unknown;
557
+ constructor(message: string, opts?: {
558
+ status?: number;
559
+ code?: string;
560
+ body?: unknown;
561
+ cause?: unknown;
562
+ });
563
+ static invalidCredential(message: string): SdkError;
564
+ static transport(message: string, cause?: unknown): SdkError;
565
+ static decode(message: string, body?: unknown): SdkError;
566
+ static fromHttp(status: number, bodyText: string): SdkError;
567
+ }
568
+
317
569
  interface ListOptions {
318
570
  pageToken?: string;
319
571
  pageSize?: number;
@@ -339,6 +591,121 @@ declare class ManagementClient {
339
591
  /** `GET /projects/{projectId}/deployments` — wire ListDeployments. */
340
592
  listDeployments(projectId: string, page?: ListOptions, orgId?: string): Promise<ListDeploymentsResponse>;
341
593
  listDeploymentItems(projectId: string, page?: ListOptions, orgId?: string): Promise<Deployment[]>;
594
+ createProject(name: string, opts?: {
595
+ slug?: string;
596
+ orgId?: string;
597
+ description?: string;
598
+ ref?: string;
599
+ }): Promise<Project>;
600
+ createDeploy(projectId: string, opts?: {
601
+ envType?: string;
602
+ envId?: string;
603
+ ref?: string;
604
+ serviceId?: string;
605
+ orgId?: string;
606
+ }): Promise<CreateDeployResponse>;
607
+ rollback(projectId: string, opts?: {
608
+ envId?: string;
609
+ deploymentRecordId?: string;
610
+ serviceId?: string;
611
+ orgId?: string;
612
+ }): Promise<RollbackResponse>;
613
+ getProjectStatus(projectId: string, orgId?: string): Promise<ProjectStatusResponse>;
614
+ listEnvVars(projectId: string, opts?: {
615
+ envType?: string;
616
+ envId?: string;
617
+ orgId?: string;
618
+ }): Promise<ListEnvVarsResponse>;
619
+ setEnvVar(projectId: string, key: string, value: string, opts?: {
620
+ secret?: boolean;
621
+ envType?: string;
622
+ envId?: string;
623
+ orgId?: string;
624
+ }): Promise<SetEnvVarResponse>;
625
+ deleteEnvVar(projectId: string, key: string, opts?: {
626
+ envType?: string;
627
+ envId?: string;
628
+ orgId?: string;
629
+ }): Promise<DeleteEnvVarResponse>;
630
+ listLogs(opts: {
631
+ projectId?: string;
632
+ environmentId?: string;
633
+ logType?: string;
634
+ envType?: string;
635
+ limit?: number;
636
+ level?: string;
637
+ service?: string;
638
+ grep?: string;
639
+ orgId?: string;
640
+ }): Promise<ListLogsResponse>;
641
+ listResources(opts?: {
642
+ kind?: string;
643
+ projectId?: string;
644
+ orgId?: string;
645
+ }): Promise<ListResourcesResponse>;
646
+ getResource(id: string, orgId?: string): Promise<Resource>;
647
+ createResource(kind: string, name: string, opts?: {
648
+ projectId?: string;
649
+ tier?: string;
650
+ storageGb?: number;
651
+ orgId?: string;
652
+ }): Promise<CreateResourceResponse>;
653
+ deleteResource(id: string, orgId?: string): Promise<DeleteResourceResponse>;
654
+ bindResource(resourceId: string, environmentId: string, opts?: {
655
+ projectId?: string;
656
+ orgId?: string;
657
+ }): Promise<BindResourceResponse>;
658
+ branchResource(resourceId: string, name: string, opts?: {
659
+ envId?: string;
660
+ orgId?: string;
661
+ }): Promise<BranchResourceResponse>;
662
+ createProjectStorage(projectId: string, name: string, opts?: {
663
+ envType?: string;
664
+ orgId?: string;
665
+ }): Promise<CreateProjectStorageResponse>;
666
+ listProjectStorage(projectId: string, orgId?: string): Promise<ListProjectStorageResponse>;
667
+ listTasks(opts?: {
668
+ projectId?: string;
669
+ orgId?: string;
670
+ }): Promise<ListTasksResponse>;
671
+ createTask(name: string, opts?: {
672
+ projectId?: string;
673
+ mode?: string;
674
+ handler?: string;
675
+ cron?: string;
676
+ callbackUrl?: string;
677
+ orgId?: string;
678
+ }): Promise<CreateTaskResponse>;
679
+ getTask(id: string, orgId?: string): Promise<Task>;
680
+ listBackups(opts?: {
681
+ resourceId?: string;
682
+ orgId?: string;
683
+ }): Promise<ListBackupsResponse>;
684
+ createBackup(opts?: {
685
+ resourceId?: string;
686
+ tag?: string;
687
+ orgId?: string;
688
+ }): Promise<CreateBackupResponse>;
689
+ restoreBackup(backupId: string, opts?: {
690
+ resourceId?: string;
691
+ orgId?: string;
692
+ }): Promise<RestoreBackupResponse>;
693
+ listFlags(opts?: {
694
+ projectId?: string;
695
+ orgId?: string;
696
+ }): Promise<ListFlagsResponse>;
697
+ createFlag(key: string, opts?: {
698
+ description?: string;
699
+ projectId?: string;
700
+ enabled?: boolean;
701
+ orgId?: string;
702
+ }): Promise<CreateFlagResponse>;
703
+ toggleFlag(key: string, opts?: {
704
+ enabled?: boolean;
705
+ projectId?: string;
706
+ orgId?: string;
707
+ }): Promise<ToggleFlagResponse>;
708
+ getPreviewCost(projectId: string, prNumber: string, orgId?: string): Promise<PreviewCostResponse>;
342
709
  /** Escape hatch: authenticated raw Management REST. */
343
710
  api(method: string, path: string, body?: unknown, orgId?: string): Promise<{
344
711
  status: number;
@@ -360,100 +727,6 @@ declare class ManagementClientBuilder {
360
727
  }
361
728
  declare function createManagementClient(token: string): ManagementClient;
362
729
 
363
- /** Typed SDK failure (transport, auth, decode, or API). */
364
- declare class SdkError extends Error {
365
- readonly status?: number;
366
- readonly code?: string;
367
- readonly body?: unknown;
368
- constructor(message: string, opts?: {
369
- status?: number;
370
- code?: string;
371
- body?: unknown;
372
- cause?: unknown;
373
- });
374
- static invalidCredential(message: string): SdkError;
375
- static transport(message: string, cause?: unknown): SdkError;
376
- static decode(message: string, body?: unknown): SdkError;
377
- static fromHttp(status: number, bodyText: string): SdkError;
378
- }
379
-
380
- /** Map wire KvSetRequest → REST JSON body `{ key, value, ex? }`. */
381
- declare function kvSetToRest(req: KvSetRequest$1): {
382
- key: string;
383
- value: unknown;
384
- ex?: number;
385
- };
386
- /** Map REST get body → wire KvGetResponse. */
387
- declare function kvGetFromRest(body: Record<string, unknown>): KvGetResponse;
388
-
389
- /**
390
- * Database Pricing Configuration (SSOT)
391
- *
392
- * All database billing constants centralized here.
393
- * Used by billing calculations, usage tracking, and cost display.
394
- *
395
- * Pricing Strategy:
396
- * - Self-hosted infra on AX162-R: flat ~$270/month
397
- * - Competitive pricing with 75-99% margins
398
- *
399
- * Customer Prices (updated for self-hosted, 2026-02):
400
- * - Compute: $0.08/hour (25% below Neon $0.106/hr)
401
- * - Storage: $0.25/GB-month (29% below Neon $0.35/GB)
402
- * - Transfer: $0.09/GB (matches Supabase)
403
- */
404
- /** Price per compute hour in microdollars ($0.08/hour = 80,000 microdollars) */
405
- declare const COMPUTE_PRICE_PER_HOUR_MICRODOLLARS = 80000;
406
- /** Free compute hours per month (platform free tier) */
407
- declare const FREE_COMPUTE_HOURS = 3;
408
- /** Price per GB-month in microdollars ($0.25/GB-month = 250,000 microdollars) */
409
- declare const STORAGE_PRICE_PER_GB_MONTH_MICRODOLLARS = 250000;
410
- /** Free storage in GB (256 MB) */
411
- declare const FREE_STORAGE_GB = 0.25;
412
- /** Price per GB data transfer ($0.09/GB = 90,000 microdollars) */
413
- declare const TRANSFER_PRICE_PER_GB_MICRODOLLARS = 90000;
414
- /** KV free storage in GB (256 MB) */
415
- declare const KV_FREE_STORAGE_GB = 0.25;
416
- /** Hours per month (AWS/GCP standard for billing) */
417
- declare const HOURS_PER_MONTH = 730;
418
-
419
- /**
420
- * Referrals Configuration (SSOT)
421
- *
422
- * Single source of truth for referral system configuration.
423
- * Used by: referral router, SDK referral endpoints
424
- */
425
- /** Default points awarded per successful referral */
426
- declare const DEFAULT_POINTS_REWARD = 100;
427
- /** Number of months the referral discount is valid */
428
- declare const DISCOUNT_DURATION_MONTHS = 3;
429
- /** Default discount percentage */
430
- declare const DISCOUNT_PERCENT = 20;
431
- /** Premium trial days from referral */
432
- declare const PREMIUM_TRIAL_DAYS = 7;
433
- /**
434
- * Generate a cryptographically secure referral code
435
- *
436
- * Uses crypto.getRandomValues for uniform random bytes (0-255).
437
- * Since REFERRAL_CODE_CHARS has exactly 32 characters and 256 / 32 = 8,
438
- * byte % 32 produces perfectly uniform distribution with zero modulo bias.
439
- *
440
- * Entropy: 8 chars * log2(32) = 40 bits (~1.1 trillion possible codes)
441
- *
442
- * Format: 8 uppercase alphanumeric characters (excluding ambiguous: 0, O, I, L, 1)
443
- */
444
- declare function generateReferralCode(): string;
445
-
446
- declare function getErrorMessage$1(error: unknown, fallback?: string): string;
447
- interface ErrorDetails$1 {
448
- message: string;
449
- code?: string;
450
- name?: string;
451
- stack?: string;
452
- status?: number;
453
- cause?: unknown;
454
- }
455
- declare function getErrorDetails$1(error: unknown, fallbackMessage?: string): ErrorDetails$1;
456
-
457
730
  /**
458
731
  * Sylphx Connection URL — Single Source of Truth (ADR-123)
459
732
  *