@hachej/boring-core 0.1.41 → 0.1.43

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.
@@ -1,4 +1,4 @@
1
- export { g as CapabilitiesResponse, h as ConfigFetchError, i as ConfigValidationError, j as CoreCapabilities, C as CoreConfig, E as ERROR_CODES, k as ErrorCode, H as HttpError, J as JsonValue, M as MemberRole, l as RateLimitEndpointOverride, R as RuntimeConfig, m as SessionPayload, S as SessionState, U as User, W as Workspace, b as WorkspaceInvite, a as WorkspaceMember, c as WorkspaceRuntime } from '../types-CbMOXLBf.js';
1
+ export { g as CapabilitiesResponse, h as ConfigFetchError, i as ConfigValidationError, j as CoreCapabilities, C as CoreConfig, E as ERROR_CODES, k as ErrorCode, H as HttpError, J as JsonValue, M as MemberRole, l as RateLimitEndpointOverride, R as RuntimeConfig, m as SessionPayload, S as SessionState, U as User, W as Workspace, b as WorkspaceInvite, a as WorkspaceMember, c as WorkspaceRuntime } from '../types-CWtJ4kgd.js';
2
2
 
3
3
  interface TelemetrySink {
4
4
  capture(event: TelemetryEvent): void | Promise<void>;
@@ -7,7 +7,7 @@ import {
7
7
  ConfigValidationError,
8
8
  ERROR_CODES,
9
9
  HttpError
10
- } from "../chunk-H5KU6R6Y.js";
10
+ } from "../chunk-LIBHVT7V.js";
11
11
  import "../chunk-MLKGABMK.js";
12
12
  export {
13
13
  ConfigFetchError,
@@ -22,6 +22,9 @@ declare const ERROR_CODES: {
22
22
  readonly MAIL_DISABLED: "mail_disabled";
23
23
  readonly DB_UNAVAILABLE: "db_unavailable";
24
24
  readonly INTERNAL_ERROR: "internal_error";
25
+ readonly PAYMENT_REQUIRED: "payment_required";
26
+ readonly INVALID_PACK: "invalid_pack";
27
+ readonly CHECKOUT_FAILED: "checkout_failed";
25
28
  };
26
29
  type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
27
30
  declare class HttpError extends Error {
@@ -0,0 +1,57 @@
1
+ CREATE TABLE IF NOT EXISTS "boring_credit_grants" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "user_id" text NOT NULL,
4
+ "amount_micros" bigint NOT NULL,
5
+ "reason" text NOT NULL,
6
+ "expires_at" timestamp,
7
+ "created_at" timestamp DEFAULT now() NOT NULL,
8
+ CONSTRAINT "boring_credit_grants_amount_check" CHECK ("amount_micros" > 0)
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE UNIQUE INDEX IF NOT EXISTS "boring_credit_grants_user_reason_idx" ON "boring_credit_grants" USING btree ("user_id", "reason");
12
+ --> statement-breakpoint
13
+ CREATE TABLE IF NOT EXISTS "boring_usage_reservations" (
14
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
15
+ "user_id" text NOT NULL,
16
+ "workspace_id" text,
17
+ "session_id" text,
18
+ "run_id" text NOT NULL,
19
+ "source" text DEFAULT '' NOT NULL,
20
+ "amount_micros" bigint NOT NULL,
21
+ "status" text DEFAULT 'active' NOT NULL,
22
+ "created_at" timestamp DEFAULT now() NOT NULL,
23
+ "expires_at" timestamp NOT NULL,
24
+ CONSTRAINT "boring_usage_reservations_amount_check" CHECK ("amount_micros" > 0),
25
+ CONSTRAINT "boring_usage_reservations_status_check" CHECK ("status" IN ('active', 'settled', 'released', 'expired'))
26
+ );
27
+ --> statement-breakpoint
28
+ CREATE UNIQUE INDEX IF NOT EXISTS "boring_usage_reservations_active_run_idx" ON "boring_usage_reservations" USING btree ("run_id") WHERE "status" = 'active';
29
+ --> statement-breakpoint
30
+ CREATE INDEX IF NOT EXISTS "boring_usage_reservations_user_status_idx" ON "boring_usage_reservations" USING btree ("user_id", "status", "expires_at");
31
+ --> statement-breakpoint
32
+ CREATE TABLE IF NOT EXISTS "boring_usage_ledger" (
33
+ "id" text PRIMARY KEY NOT NULL,
34
+ "user_id" text NOT NULL,
35
+ "workspace_id" text,
36
+ "session_id" text,
37
+ "run_id" text,
38
+ "message_id" text,
39
+ "source" text DEFAULT '' NOT NULL,
40
+ "provider" text,
41
+ "model" text,
42
+ "input_tokens" bigint DEFAULT 0 NOT NULL,
43
+ "output_tokens" bigint DEFAULT 0 NOT NULL,
44
+ "cache_read_tokens" bigint DEFAULT 0 NOT NULL,
45
+ "cache_write_tokens" bigint DEFAULT 0 NOT NULL,
46
+ "provider_cost_micros" bigint DEFAULT 0 NOT NULL,
47
+ "billed_cost_micros" bigint NOT NULL,
48
+ "stop_reason" text,
49
+ "metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
50
+ "created_at" timestamp DEFAULT now() NOT NULL,
51
+ CONSTRAINT "boring_usage_ledger_billed_check" CHECK ("billed_cost_micros" >= 0),
52
+ CONSTRAINT "boring_usage_ledger_tokens_check" CHECK ("input_tokens" >= 0 AND "output_tokens" >= 0 AND "cache_read_tokens" >= 0 AND "cache_write_tokens" >= 0 AND "provider_cost_micros" >= 0)
53
+ );
54
+ --> statement-breakpoint
55
+ CREATE INDEX IF NOT EXISTS "boring_usage_ledger_user_created_idx" ON "boring_usage_ledger" USING btree ("user_id", "created_at");
56
+ --> statement-breakpoint
57
+ CREATE INDEX IF NOT EXISTS "boring_usage_ledger_run_idx" ON "boring_usage_ledger" USING btree ("run_id");
@@ -0,0 +1,9 @@
1
+ CREATE TABLE IF NOT EXISTS "boring_credit_purchases" (
2
+ "order_id" text PRIMARY KEY NOT NULL,
3
+ "user_id" text NOT NULL,
4
+ "amount_micros" bigint NOT NULL,
5
+ "source" text DEFAULT 'lemonsqueezy' NOT NULL,
6
+ "created_at" timestamp DEFAULT now() NOT NULL
7
+ );
8
+ --> statement-breakpoint
9
+ CREATE INDEX IF NOT EXISTS "boring_credit_purchases_user_idx" ON "boring_credit_purchases" USING btree ("user_id");
@@ -0,0 +1,28 @@
1
+ -- Purchase lifecycle: allow a refund-before-grant tombstone and a money-safety
2
+ -- amount check. user_id/amount_micros become nullable so a refund that arrives
3
+ -- before order_created can write a 'refunded' tombstone that blocks a later grant.
4
+ ALTER TABLE "boring_credit_purchases" ALTER COLUMN "user_id" DROP NOT NULL;
5
+ --> statement-breakpoint
6
+ ALTER TABLE "boring_credit_purchases" ALTER COLUMN "amount_micros" DROP NOT NULL;
7
+ --> statement-breakpoint
8
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "status" text DEFAULT 'granted' NOT NULL;
9
+ --> statement-breakpoint
10
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "refunded_at" timestamp;
11
+ --> statement-breakpoint
12
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "refunded_micros" bigint;
13
+ --> statement-breakpoint
14
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "pending_refund_ppm" bigint;
15
+ --> statement-breakpoint
16
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "store_id" text;
17
+ --> statement-breakpoint
18
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "test_mode" boolean;
19
+ --> statement-breakpoint
20
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "currency" text;
21
+ --> statement-breakpoint
22
+ ALTER TABLE "boring_credit_purchases" ADD COLUMN "variant_id" text;
23
+ --> statement-breakpoint
24
+ ALTER TABLE "boring_credit_purchases" ADD CONSTRAINT "boring_credit_purchases_amount_check" CHECK ("amount_micros" IS NULL OR "amount_micros" > 0);
25
+ --> statement-breakpoint
26
+ ALTER TABLE "boring_credit_purchases" ADD CONSTRAINT "boring_credit_purchases_status_check" CHECK ("status" IN ('granted', 'refunded', 'refund_pending'));
27
+ --> statement-breakpoint
28
+ ALTER TABLE "boring_credit_purchases" ADD CONSTRAINT "boring_credit_purchases_granted_check" CHECK ("status" IN ('refunded', 'refund_pending') OR ("user_id" IS NOT NULL AND "amount_micros" IS NOT NULL));
@@ -0,0 +1,7 @@
1
+ -- Durable terminal-charge intent for reservations. Set true when the metering
2
+ -- coordinator decided a run must be charged the fallback hold (started/successful
3
+ -- run with no billable usage, or a failed usage write) BEFORE attempting the
4
+ -- charge. If that charge write then fails transiently, the stale-expiry sweep still
5
+ -- charges the hold for a marked reservation even when it has zero billed usage rows
6
+ -- — so a started run can't go free on a brief finalization-time DB outage.
7
+ ALTER TABLE "boring_usage_reservations" ADD COLUMN "charge_on_expire" boolean DEFAULT false NOT NULL;
@@ -78,6 +78,34 @@
78
78
  "when": 1779537600000,
79
79
  "tag": "0010_telemetry_events",
80
80
  "breakpoints": true
81
+ },
82
+ {
83
+ "idx": 11,
84
+ "version": "7",
85
+ "when": 1781308800000,
86
+ "tag": "0011_usage_metering",
87
+ "breakpoints": true
88
+ },
89
+ {
90
+ "idx": 12,
91
+ "version": "7",
92
+ "when": 1781395200000,
93
+ "tag": "0012_credit_purchases",
94
+ "breakpoints": true
95
+ },
96
+ {
97
+ "idx": 13,
98
+ "version": "7",
99
+ "when": 1781481600000,
100
+ "tag": "0013_credit_purchase_lifecycle",
101
+ "breakpoints": true
102
+ },
103
+ {
104
+ "idx": 14,
105
+ "version": "7",
106
+ "when": 1781568000000,
107
+ "tag": "0014_reservation_charge_on_expire",
108
+ "breakpoints": true
81
109
  }
82
110
  ]
83
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hachej/boring-core",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Foundation package for boring-ui-v2 apps: DB, auth, config, HTTP app factory, and frontend app shell.",
@@ -79,9 +79,9 @@
79
79
  "react-router-dom": "^7.14.2",
80
80
  "smol-toml": "^1.6.1",
81
81
  "zod": "^3.25.76",
82
- "@hachej/boring-agent": "0.1.41",
83
- "@hachej/boring-workspace": "0.1.41",
84
- "@hachej/boring-ui-kit": "0.1.41"
82
+ "@hachej/boring-agent": "0.1.43",
83
+ "@hachej/boring-workspace": "0.1.43",
84
+ "@hachej/boring-ui-kit": "0.1.43"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@testing-library/jest-dom": "^6.9.1",
@@ -1,8 +0,0 @@
1
- import { C as CoreConfig } from './types-CbMOXLBf.js';
2
-
3
- interface RunMigrationsOptions {
4
- migrationsFolder?: string;
5
- }
6
- declare function runMigrations(config: CoreConfig, options?: RunMigrationsOptions): Promise<void>;
7
-
8
- export { type RunMigrationsOptions as R, runMigrations as r };