payweave 0.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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +272 -0
  3. package/dist/_tsup-dts-rollup.d.ts +19470 -0
  4. package/dist/chunk-4R5OGOCC.js +94 -0
  5. package/dist/chunk-4R5OGOCC.js.map +1 -0
  6. package/dist/chunk-535Q3GUN.js +175 -0
  7. package/dist/chunk-535Q3GUN.js.map +1 -0
  8. package/dist/chunk-67NRYGRC.js +192 -0
  9. package/dist/chunk-67NRYGRC.js.map +1 -0
  10. package/dist/chunk-CGQ73I4I.js +568 -0
  11. package/dist/chunk-CGQ73I4I.js.map +1 -0
  12. package/dist/chunk-CJEYDHY6.js +18 -0
  13. package/dist/chunk-CJEYDHY6.js.map +1 -0
  14. package/dist/chunk-CR63JAAS.js +3 -0
  15. package/dist/chunk-CR63JAAS.js.map +1 -0
  16. package/dist/chunk-E633MKVX.js +1507 -0
  17. package/dist/chunk-E633MKVX.js.map +1 -0
  18. package/dist/chunk-FBPOCXRZ.js +1135 -0
  19. package/dist/chunk-FBPOCXRZ.js.map +1 -0
  20. package/dist/chunk-HTRGMZFH.js +267 -0
  21. package/dist/chunk-HTRGMZFH.js.map +1 -0
  22. package/dist/chunk-IUVGM3K7.js +765 -0
  23. package/dist/chunk-IUVGM3K7.js.map +1 -0
  24. package/dist/chunk-JD4OZHRI.js +326 -0
  25. package/dist/chunk-JD4OZHRI.js.map +1 -0
  26. package/dist/chunk-NV3MZF7L.js +139 -0
  27. package/dist/chunk-NV3MZF7L.js.map +1 -0
  28. package/dist/chunk-NXQBP35U.js +13 -0
  29. package/dist/chunk-NXQBP35U.js.map +1 -0
  30. package/dist/chunk-QJHXDZYC.js +412 -0
  31. package/dist/chunk-QJHXDZYC.js.map +1 -0
  32. package/dist/chunk-TWZK62TZ.js +83 -0
  33. package/dist/chunk-TWZK62TZ.js.map +1 -0
  34. package/dist/cli/index.js +35381 -0
  35. package/dist/core/index.d.ts +85 -0
  36. package/dist/core/index.js +6 -0
  37. package/dist/core/index.js.map +1 -0
  38. package/dist/db/drizzle/index.d.ts +6 -0
  39. package/dist/db/drizzle/index.js +1532 -0
  40. package/dist/db/drizzle/index.js.map +1 -0
  41. package/dist/db/index.d.ts +43 -0
  42. package/dist/db/index.js +3 -0
  43. package/dist/db/index.js.map +1 -0
  44. package/dist/db/mongodb/index.d.ts +3 -0
  45. package/dist/db/mongodb/index.js +934 -0
  46. package/dist/db/mongodb/index.js.map +1 -0
  47. package/dist/db/mysql/index.d.ts +1 -0
  48. package/dist/db/mysql/index.js +12 -0
  49. package/dist/db/mysql/index.js.map +1 -0
  50. package/dist/db/postgres/index.d.ts +5 -0
  51. package/dist/db/postgres/index.js +791 -0
  52. package/dist/db/postgres/index.js.map +1 -0
  53. package/dist/db/prisma/index.d.ts +1 -0
  54. package/dist/db/prisma/index.js +12 -0
  55. package/dist/db/prisma/index.js.map +1 -0
  56. package/dist/db/sqlite/index.d.ts +5 -0
  57. package/dist/db/sqlite/index.js +750 -0
  58. package/dist/db/sqlite/index.js.map +1 -0
  59. package/dist/express/index.d.ts +1 -0
  60. package/dist/express/index.js +3 -0
  61. package/dist/express/index.js.map +1 -0
  62. package/dist/fastify/index.d.ts +1 -0
  63. package/dist/fastify/index.js +3 -0
  64. package/dist/fastify/index.js.map +1 -0
  65. package/dist/flutterwave/index.d.ts +27 -0
  66. package/dist/flutterwave/index.js +9 -0
  67. package/dist/flutterwave/index.js.map +1 -0
  68. package/dist/index.d.ts +85 -0
  69. package/dist/index.js +3677 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/next/index.d.ts +1 -0
  72. package/dist/next/index.js +3 -0
  73. package/dist/next/index.js.map +1 -0
  74. package/dist/paystack/index.d.ts +33 -0
  75. package/dist/paystack/index.js +9 -0
  76. package/dist/paystack/index.js.map +1 -0
  77. package/dist/products/index.d.ts +22 -0
  78. package/dist/products/index.js +7 -0
  79. package/dist/products/index.js.map +1 -0
  80. package/dist/testing/index.d.ts +11 -0
  81. package/dist/testing/index.js +69 -0
  82. package/dist/testing/index.js.map +1 -0
  83. package/dist/unified/index.d.ts +41 -0
  84. package/dist/unified/index.js +6 -0
  85. package/dist/unified/index.js.map +1 -0
  86. package/dist/webhooks/index.d.ts +8 -0
  87. package/dist/webhooks/index.js +8 -0
  88. package/dist/webhooks/index.js.map +1 -0
  89. package/package.json +164 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/db/migrations/errors.ts","../src/db/migrations/ledger.ts","../src/db/migrations/ddl.ts","../src/db/migrations/definitions.ts","../src/db/migrations/engine.ts"],"names":["migration"],"mappings":";;;;;AAcO,IAAM,sBAAA,GAAN,cAAqC,aAAA,CAAc;AAAA,EACxD,WAAA,CAAY,OAAA,EAAiB,OAAA,GAAgC,EAAC,EAAG;AAC/D,IAAA,KAAA,CAAM,SAAS,EAAE,WAAA,EAAa,KAAA,EAAO,GAAG,SAAS,CAAA;AACjD,IAAA,IAAA,CAAK,IAAA,GAAO,wBAAA;AAAA,EACd;AACF,CAAA;AAoBO,IAAM,6BAAA,GAAN,cAA4C,sBAAA,CAAuB;AAAA;AAAA,EAE/D,WAAA;AAAA,EACA,MAAA;AAAA,EAET,WAAA,CACE,OAAA,EACA,OAAA,EACA,OAAA,GAAgC,EAAC,EACjC;AACA,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,+BAAA;AACZ,IAAA,IAAA,CAAK,cAAc,OAAA,CAAQ,WAAA;AAC3B,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AAAA,EACxB;AAAA,EAES,MAAA,GAAkC;AACzC,IAAA,OAAO,EAAE,GAAG,KAAA,CAAM,MAAA,EAAO,EAAG,aAAa,IAAA,CAAK,WAAA,EAAa,MAAA,EAAQ,IAAA,CAAK,MAAA,EAAO;AAAA,EACjF;AACF,CAAA;;;AC1CO,IAAM,yBAA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,CAAW,MAAM,CAAA,CAAA,CAAA;AAAA,YACvG,EAAE,KAAA;AAAM,WACV;AAAA,QACF;AAAA,MACF;AACA,MAAA,IAAI;AACF,QAAA,MAAM,EAAA,CAAG,KAAA;AAAA,UACP,gBAAgB,OAAO,CAAA;AAAA,UACvB,kBAAA,CAAmB,SAASA,UAAAA,CAAU,EAAA,EAAI,kBAAkBA,UAAS,CAAA,kBAAG,IAAI,IAAA,EAAM;AAAA,SACpF;AAAA,MACF,SAAS,KAAA,EAAO;AACd,QAAA,MAAM,IAAI,sBAAA;AAAA,UACR,CAAA,oBAAA,EAAuBA,WAAU,EAAE,CAAA,gEAAA,CAAA;AAAA,UACnC,EAAE,KAAA;AAAM,SACV;AAAA,MACF;AAAA,IACF,CAAA;AAEA,IAAA,IAAI,SAAS,WAAA,EAAa;AACxB,MAAA,MAAM,QAAA,CAAS,YAAY,MAAM,CAAA;AAAA,IACnC,CAAA,MAAO;AACL,MAAA,MAAM,OAAO,QAAQ,CAAA;AAAA,IACvB;AACA,IAAA,OAAA,CAAQ,IAAA,CAAKA,WAAU,EAAE,CAAA;AAAA,EAC3B;AACA,EAAA,OAAO,EAAE,OAAA,EAAQ;AACnB","file":"chunk-QJHXDZYC.js","sourcesContent":["/**\n * Error classes thrown by the SQL migrations engine (docs/v1/database.md §4,\n * PW-703). Both extend {@link PayweaveError} so adapter `migrations.status()`\n * / `migrations.apply()` methods satisfy the golden rule that public SDK\n * methods only ever throw `PayweaveError` subclasses.\n */\nimport { PayweaveError, type PayweaveErrorOptions } from \"../../core/errors\";\n\n/**\n * Base class for every failure the SQL migrations engine raises itself:\n * execution failures (with the driver error as `cause`), malformed embedded\n * migration sets, malformed ledger rows, unsupported dialects. Never\n * retryable — migrations are operator actions, not hot-path calls.\n */\nexport class PayweaveMigrationError extends PayweaveError {\n constructor(message: string, options: PayweaveErrorOptions = {}) {\n super(message, { isRetryable: false, ...options });\n this.name = \"PayweaveMigrationError\";\n }\n}\n\n/** Why a {@link PayweaveMigrationHistoryError} was raised. */\nexport type PwMigrationHistoryErrorReason = \"checksum-mismatch\" | \"unknown-migration\";\n\n/**\n * Mutated-history detection (database.md §4 — \"never re-run mutated\n * history\"). Raised by BOTH `planMigrations` and `applyMigrations` when the\n * `pw_migrations` ledger disagrees with the migrations embedded in this\n * build:\n *\n * - `\"checksum-mismatch\"` — an applied migration's recorded checksum no\n * longer matches the embedded content: someone edited an applied migration.\n * - `\"unknown-migration\"` — the ledger names a migration this build does not\n * embed: the database was migrated by a different/newer build, or the\n * ledger was edited by hand.\n *\n * The engine refuses to plan or apply ANYTHING once history is inconsistent;\n * there is no override flag by design.\n */\nexport class PayweaveMigrationHistoryError extends PayweaveMigrationError {\n /** The ledger `name` (= embedded migration `id`) that failed verification. */\n readonly migrationId: string;\n readonly reason: PwMigrationHistoryErrorReason;\n\n constructor(\n message: string,\n details: { migrationId: string; reason: PwMigrationHistoryErrorReason },\n options: PayweaveErrorOptions = {},\n ) {\n super(message, options);\n this.name = \"PayweaveMigrationHistoryError\";\n this.migrationId = details.migrationId;\n this.reason = details.reason;\n }\n\n override toJSON(): Record<string, unknown> {\n return { ...super.toJSON(), migrationId: this.migrationId, reason: this.reason };\n }\n}\n","/**\n * `pw_migrations` checksum-ledger SQL (docs/v1/database.md §2/§4, PW-703).\n * One row per applied migration: `name` (PK — the embedded migration's `id`),\n * `applied_at`, `checksum`. The engine bootstraps the ledger with\n * `CREATE TABLE IF NOT EXISTS` before every read, and `0001_init` embeds the\n * SAME statement so the DDL set alone realizes the full §2 schema.\n *\n * Placeholder + parameter conventions (kept here so PW-704/705/706 executors\n * stay pass-through): postgres uses `$1…`, mysql/sqlite use `?`; `applied_at`\n * binds a `Date` on postgres/mysql and an epoch-millisecond integer on sqlite\n * (sqlite stores all timestamps as `INTEGER` epoch ms — see `./ddl`).\n */\nimport { PW_TABLES } from \"../schema\";\nimport type { PwSqlDialect } from \"./types\";\n\n/** Canonical ledger table name (`pw_migrations`). */\nexport const MIGRATION_LEDGER_TABLE = PW_TABLES.migrations;\n\n/**\n * Idempotent ledger bootstrap. Also embedded verbatim as the first statement\n * of `0001_init`, where re-execution is a no-op.\n */\nexport function ledgerEnsureSql(dialect: PwSqlDialect): string {\n switch (dialect) {\n case \"postgres\":\n return `CREATE TABLE IF NOT EXISTS ${MIGRATION_LEDGER_TABLE} (\n name TEXT PRIMARY KEY,\n applied_at TIMESTAMPTZ NOT NULL,\n checksum TEXT NOT NULL\n)`;\n case \"mysql\":\n return `CREATE TABLE IF NOT EXISTS ${MIGRATION_LEDGER_TABLE} (\n name VARCHAR(255) NOT NULL,\n applied_at DATETIME(3) NOT NULL,\n checksum VARCHAR(255) NOT NULL,\n PRIMARY KEY (name)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`;\n case \"sqlite\":\n return `CREATE TABLE IF NOT EXISTS ${MIGRATION_LEDGER_TABLE} (\n name TEXT PRIMARY KEY,\n applied_at INTEGER NOT NULL,\n checksum TEXT NOT NULL\n)`;\n }\n}\n\n/**\n * Full ledger read for history verification. Identical text on every dialect\n * (no parameters); ordered for deterministic output.\n */\nexport function ledgerSelectSql(dialect: PwSqlDialect): string {\n void dialect; // Same shape everywhere today; keeps the call sites uniform.\n return `SELECT name, checksum FROM ${MIGRATION_LEDGER_TABLE} ORDER BY name`;\n}\n\n/** Ledger append for one applied migration; see {@link ledgerInsertParams}. */\nexport function ledgerInsertSql(dialect: PwSqlDialect): string {\n const placeholders = dialect === \"postgres\" ? \"$1, $2, $3\" : \"?, ?, ?\";\n return `INSERT INTO ${MIGRATION_LEDGER_TABLE} (name, applied_at, checksum) VALUES (${placeholders})`;\n}\n\n/**\n * Parameters for {@link ledgerInsertSql}, in column order\n * (`name`, `applied_at`, `checksum`). sqlite binds `applied_at` as epoch ms.\n */\nexport function ledgerInsertParams(\n dialect: PwSqlDialect,\n migrationId: string,\n checksum: string,\n appliedAt: Date,\n): readonly unknown[] {\n return [migrationId, dialect === \"sqlite\" ? appliedAt.getTime() : appliedAt, checksum];\n}\n","/**\n * Embedded DDL for migration `0001_init` — the full docs/v1/database.md §2\n * logical schema, per dialect. These string constants ARE the\n * migration content: they are hashed byte-for-byte into the `pw_migrations`\n * checksum, so **once `0001_init` has been applied anywhere it is immutable\n * forever** — even a whitespace edit is mutated history and makes every\n * existing database fail loudly. Schema changes ship as\n * `0002_...`, never as edits here. Forward-only: no down migrations exist.\n *\n * Per-dialect storage mapping (build-time resolutions, recorded in\n * database.md §4):\n *\n * | logical | postgres | mysql | sqlite |\n * |--------------------|---------------|----------------------------|-------------------|\n * | timestamp (UTC) | `TIMESTAMPTZ` | `DATETIME(3)` (UTC session)| `INTEGER` epoch ms|\n * | JSON | `JSONB` | `JSON` | `TEXT` |\n * | boolean | `BOOLEAN` | `TINYINT(1)` | `INTEGER` 0|1 |\n * | money/usage int | `BIGINT` | `BIGINT` | `INTEGER` (64-bit)|\n * | id / key string | `TEXT` | `VARCHAR(255)` | `TEXT` |\n *\n * - NO float/decimal column exists anywhere — money is integer minor units +\n * currency code (golden rule 7 applies to storage; database.md §2).\n * - MySQL sessions must run in UTC (`time_zone = '+00:00'`) — PW-705 forces\n * this in the pool config; `DATETIME` has no zone of its own.\n * - MySQL tables are `utf8mb4` with BINARY collation (`utf8mb4_bin`) so key\n * comparisons stay case-sensitive, matching postgres/sqlite semantics.\n * - `group` and `limit` are reserved words: quoted `\"...\"` on\n * postgres/sqlite, `` `...` `` on mysql. Adapters must match this quoting.\n * - sqlite booleans carry `CHECK (col IN (0, 1))` because sqlite is otherwise\n * dynamically typed; no other CHECK constraints exist (row validity is\n * enforced by the zod row schemas at the adapter boundary).\n *\n * THE PARTIAL-UNIQUE ACTIVE-SUBSCRIPTION RULE: at most one\n * `pw_subscriptions` row per (`customer_id`, `group`) with `status` in\n * ('active', 'past_due', 'trialing').\n *\n * - postgres + sqlite: native partial unique index\n * (`CREATE UNIQUE INDEX ... WHERE status IN (...)`).\n * - mysql: NO partial indexes exist, so the rule is emulated with a STORED\n * generated column `active_slot` — `'x'` when `status` is in the active\n * set, `NULL` otherwise — plus a composite unique index on\n * (`customer_id`, `group`, `active_slot`). MySQL unique indexes never\n * treat NULLs as equal, so inactive rows can pile up freely while a second\n * active-set row collides. `active_slot` is generated storage: adapters\n * must NEVER write it (an INSERT that names it errors — that is the DDL\n * working). Recorded in database.md §4 (PW-703 build-time resolution).\n */\nimport { PW_ACTIVE_SUBSCRIPTION_STATUSES, PW_TABLES } from \"../schema\";\nimport { ledgerEnsureSql } from \"./ledger\";\n\n/**\n * The active-status set of the partial-unique rule, as a SQL `IN (...)` list.\n * Derived from {@link PW_ACTIVE_SUBSCRIPTION_STATUSES} so the DDL can never\n * drift from the contract constant.\n */\nconst ACTIVE_STATUS_SQL_LIST = PW_ACTIVE_SUBSCRIPTION_STATUSES.map((s) => `'${s}'`).join(\", \");\n\nconst freezeSql = (statements: readonly string[]): readonly string[] =>\n Object.freeze([...statements]);\n\n// ── postgres ─────────────────────────────────────────────────────────────────\n\n/** `0001_init` statements, postgres dialect. IMMUTABLE — see module header. */\nexport const POSTGRES_INIT_STATEMENTS: readonly string[] = freezeSql([\n ledgerEnsureSql(\"postgres\"),\n `CREATE TABLE ${PW_TABLES.customers} (\n id TEXT PRIMARY KEY,\n external_id TEXT NOT NULL,\n provider_ids JSONB NOT NULL,\n email TEXT,\n created_at TIMESTAMPTZ NOT NULL,\n updated_at TIMESTAMPTZ NOT NULL,\n CONSTRAINT pw_customers_external_id_uq UNIQUE (external_id)\n)`,\n `CREATE TABLE ${PW_TABLES.plans} (\n id TEXT PRIMARY KEY,\n plan_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n \"group\" TEXT NOT NULL,\n is_default BOOLEAN NOT NULL,\n name TEXT,\n price_minor BIGINT,\n price_currency TEXT,\n price_interval TEXT,\n features JSONB NOT NULL,\n provider_refs JSONB NOT NULL,\n pushed_at TIMESTAMPTZ NOT NULL,\n CONSTRAINT pw_plans_plan_id_version_uq UNIQUE (plan_id, version)\n)`,\n `CREATE TABLE ${PW_TABLES.subscriptions} (\n id TEXT PRIMARY KEY,\n customer_id TEXT NOT NULL,\n plan_id TEXT NOT NULL,\n plan_version INTEGER NOT NULL,\n \"group\" TEXT NOT NULL,\n status TEXT NOT NULL,\n provider TEXT,\n provider_subscription_ref TEXT,\n current_period_start TIMESTAMPTZ NOT NULL,\n current_period_end TIMESTAMPTZ NOT NULL,\n cancel_at_period_end BOOLEAN NOT NULL,\n created_at TIMESTAMPTZ NOT NULL,\n updated_at TIMESTAMPTZ NOT NULL,\n CONSTRAINT pw_subscriptions_customer_id_fk FOREIGN KEY (customer_id) REFERENCES ${PW_TABLES.customers} (id)\n)`,\n `CREATE UNIQUE INDEX pw_subscriptions_active_uq\n ON ${PW_TABLES.subscriptions} (customer_id, \"group\")\n WHERE status IN (${ACTIVE_STATUS_SQL_LIST})`,\n `CREATE TABLE ${PW_TABLES.featureBalances} (\n id TEXT PRIMARY KEY,\n customer_id TEXT NOT NULL,\n feature_id TEXT NOT NULL,\n \"group\" TEXT NOT NULL,\n used BIGINT NOT NULL,\n \"limit\" BIGINT NOT NULL,\n reset_interval TEXT NOT NULL,\n anchor TIMESTAMPTZ NOT NULL,\n period_start TIMESTAMPTZ NOT NULL,\n period_end TIMESTAMPTZ NOT NULL,\n plan_id TEXT NOT NULL,\n plan_version INTEGER NOT NULL,\n updated_at TIMESTAMPTZ NOT NULL,\n CONSTRAINT pw_feature_balances_customer_id_fk FOREIGN KEY (customer_id) REFERENCES ${PW_TABLES.customers} (id),\n CONSTRAINT pw_feature_balances_customer_feature_group_uq UNIQUE (customer_id, feature_id, \"group\")\n)`,\n `CREATE TABLE ${PW_TABLES.webhookEvents} (\n dedupe_key TEXT PRIMARY KEY,\n provider TEXT NOT NULL,\n type TEXT NOT NULL,\n received_at TIMESTAMPTZ NOT NULL,\n claimed_at TIMESTAMPTZ,\n applied_at TIMESTAMPTZ\n)`,\n]);\n\n// ── mysql ────────────────────────────────────────────────────────────────────\n\n/** `0001_init` statements, mysql dialect. IMMUTABLE — see module header. */\nexport const MYSQL_INIT_STATEMENTS: readonly string[] = freezeSql([\n ledgerEnsureSql(\"mysql\"),\n `CREATE TABLE ${PW_TABLES.customers} (\n id VARCHAR(255) NOT NULL,\n external_id VARCHAR(255) NOT NULL,\n provider_ids JSON NOT NULL,\n email VARCHAR(255) NULL,\n created_at DATETIME(3) NOT NULL,\n updated_at DATETIME(3) NOT NULL,\n PRIMARY KEY (id),\n CONSTRAINT pw_customers_external_id_uq UNIQUE (external_id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`,\n `CREATE TABLE ${PW_TABLES.plans} (\n id VARCHAR(255) NOT NULL,\n plan_id VARCHAR(255) NOT NULL,\n version INT NOT NULL,\n \\`group\\` VARCHAR(255) NOT NULL,\n is_default TINYINT(1) NOT NULL,\n name VARCHAR(255) NULL,\n price_minor BIGINT NULL,\n price_currency VARCHAR(255) NULL,\n price_interval VARCHAR(255) NULL,\n features JSON NOT NULL,\n provider_refs JSON NOT NULL,\n pushed_at DATETIME(3) NOT NULL,\n PRIMARY KEY (id),\n CONSTRAINT pw_plans_plan_id_version_uq UNIQUE (plan_id, version)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`,\n `CREATE TABLE ${PW_TABLES.subscriptions} (\n id VARCHAR(255) NOT NULL,\n customer_id VARCHAR(255) NOT NULL,\n plan_id VARCHAR(255) NOT NULL,\n plan_version INT NOT NULL,\n \\`group\\` VARCHAR(255) NOT NULL,\n status VARCHAR(255) NOT NULL,\n provider VARCHAR(255) NULL,\n provider_subscription_ref VARCHAR(255) NULL,\n current_period_start DATETIME(3) NOT NULL,\n current_period_end DATETIME(3) NOT NULL,\n cancel_at_period_end TINYINT(1) NOT NULL,\n created_at DATETIME(3) NOT NULL,\n updated_at DATETIME(3) NOT NULL,\n active_slot CHAR(1) GENERATED ALWAYS AS (\n CASE WHEN status IN (${ACTIVE_STATUS_SQL_LIST}) THEN 'x' ELSE NULL END\n ) STORED,\n PRIMARY KEY (id),\n CONSTRAINT pw_subscriptions_customer_id_fk FOREIGN KEY (customer_id) REFERENCES ${PW_TABLES.customers} (id),\n CONSTRAINT pw_subscriptions_active_uq UNIQUE (customer_id, \\`group\\`, active_slot)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`,\n `CREATE TABLE ${PW_TABLES.featureBalances} (\n id VARCHAR(255) NOT NULL,\n customer_id VARCHAR(255) NOT NULL,\n feature_id VARCHAR(255) NOT NULL,\n \\`group\\` VARCHAR(255) NOT NULL,\n used BIGINT NOT NULL,\n \\`limit\\` BIGINT NOT NULL,\n reset_interval VARCHAR(255) NOT NULL,\n anchor DATETIME(3) NOT NULL,\n period_start DATETIME(3) NOT NULL,\n period_end DATETIME(3) NOT NULL,\n plan_id VARCHAR(255) NOT NULL,\n plan_version INT NOT NULL,\n updated_at DATETIME(3) NOT NULL,\n PRIMARY KEY (id),\n CONSTRAINT pw_feature_balances_customer_id_fk FOREIGN KEY (customer_id) REFERENCES ${PW_TABLES.customers} (id),\n CONSTRAINT pw_feature_balances_customer_feature_group_uq UNIQUE (customer_id, feature_id, \\`group\\`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`,\n `CREATE TABLE ${PW_TABLES.webhookEvents} (\n dedupe_key VARCHAR(255) NOT NULL,\n provider VARCHAR(255) NOT NULL,\n type VARCHAR(255) NOT NULL,\n received_at DATETIME(3) NOT NULL,\n claimed_at DATETIME(3) NULL,\n applied_at DATETIME(3) NULL,\n PRIMARY KEY (dedupe_key)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`,\n]);\n\n// ── sqlite ───────────────────────────────────────────────────────────────────\n\n/** `0001_init` statements, sqlite dialect. IMMUTABLE — see module header. */\nexport const SQLITE_INIT_STATEMENTS: readonly string[] = freezeSql([\n ledgerEnsureSql(\"sqlite\"),\n `CREATE TABLE ${PW_TABLES.customers} (\n id TEXT PRIMARY KEY,\n external_id TEXT NOT NULL,\n provider_ids TEXT NOT NULL,\n email TEXT,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n CONSTRAINT pw_customers_external_id_uq UNIQUE (external_id)\n)`,\n `CREATE TABLE ${PW_TABLES.plans} (\n id TEXT PRIMARY KEY,\n plan_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n \"group\" TEXT NOT NULL,\n is_default INTEGER NOT NULL CHECK (is_default IN (0, 1)),\n name TEXT,\n price_minor INTEGER,\n price_currency TEXT,\n price_interval TEXT,\n features TEXT NOT NULL,\n provider_refs TEXT NOT NULL,\n pushed_at INTEGER NOT NULL,\n CONSTRAINT pw_plans_plan_id_version_uq UNIQUE (plan_id, version)\n)`,\n `CREATE TABLE ${PW_TABLES.subscriptions} (\n id TEXT PRIMARY KEY,\n customer_id TEXT NOT NULL,\n plan_id TEXT NOT NULL,\n plan_version INTEGER NOT NULL,\n \"group\" TEXT NOT NULL,\n status TEXT NOT NULL,\n provider TEXT,\n provider_subscription_ref TEXT,\n current_period_start INTEGER NOT NULL,\n current_period_end INTEGER NOT NULL,\n cancel_at_period_end INTEGER NOT NULL CHECK (cancel_at_period_end IN (0, 1)),\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n CONSTRAINT pw_subscriptions_customer_id_fk FOREIGN KEY (customer_id) REFERENCES ${PW_TABLES.customers} (id)\n)`,\n `CREATE UNIQUE INDEX pw_subscriptions_active_uq\n ON ${PW_TABLES.subscriptions} (customer_id, \"group\")\n WHERE status IN (${ACTIVE_STATUS_SQL_LIST})`,\n `CREATE TABLE ${PW_TABLES.featureBalances} (\n id TEXT PRIMARY KEY,\n customer_id TEXT NOT NULL,\n feature_id TEXT NOT NULL,\n \"group\" TEXT NOT NULL,\n used INTEGER NOT NULL,\n \"limit\" INTEGER NOT NULL,\n reset_interval TEXT NOT NULL,\n anchor INTEGER NOT NULL,\n period_start INTEGER NOT NULL,\n period_end INTEGER NOT NULL,\n plan_id TEXT NOT NULL,\n plan_version INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n CONSTRAINT pw_feature_balances_customer_id_fk FOREIGN KEY (customer_id) REFERENCES ${PW_TABLES.customers} (id),\n CONSTRAINT pw_feature_balances_customer_feature_group_uq UNIQUE (customer_id, feature_id, \"group\")\n)`,\n `CREATE TABLE ${PW_TABLES.webhookEvents} (\n dedupe_key TEXT PRIMARY KEY,\n provider TEXT NOT NULL,\n type TEXT NOT NULL,\n received_at INTEGER NOT NULL,\n claimed_at INTEGER,\n applied_at INTEGER\n)`,\n]);\n","/**\n * The embedded, ordered migration list per SQL dialect (docs/v1/database.md\n * §4, PW-703). Pure data: no filesystem reads, no drivers — `dist` never\n * touches runtime files. Ordering is id-lexicographic (zero-padded numeric\n * prefixes), and the list is APPEND-ONLY: a migration that has been applied\n * anywhere is immutable forever; changes ship as the next id.\n */\nimport { PayweaveMigrationError } from \"./errors\";\nimport {\n MYSQL_INIT_STATEMENTS,\n POSTGRES_INIT_STATEMENTS,\n SQLITE_INIT_STATEMENTS,\n} from \"./ddl\";\nimport type { PwSqlDialect, PwSqlMigration } from \"./types\";\n\nconst migration = (\n id: string,\n name: string,\n statements: readonly string[],\n): PwSqlMigration => Object.freeze({ id, name, statements });\n\n/**\n * Ids of every embedded migration, in execution order. Identical across\n * dialects by construction — only the statement TEXT varies per dialect.\n */\nexport const PW_MIGRATION_IDS = Object.freeze([\"0001_init\"] as const);\n\nconst MIGRATIONS_BY_DIALECT: Record<PwSqlDialect, readonly PwSqlMigration[]> = {\n postgres: Object.freeze([migration(\"0001_init\", \"init\", POSTGRES_INIT_STATEMENTS)]),\n mysql: Object.freeze([migration(\"0001_init\", \"init\", MYSQL_INIT_STATEMENTS)]),\n sqlite: Object.freeze([migration(\"0001_init\", \"init\", SQLITE_INIT_STATEMENTS)]),\n};\n\n/**\n * The embedded migration list for `dialect`, in execution order. Pure and\n * deterministic — same input, same (frozen) output. Throws\n * {@link PayweaveMigrationError} for any non-SQL dialect: mongodb has NO SQL\n * migrations (its adapter ensures collections/indexes itself) and\n * prisma/drizzle users own their migrations.\n */\nexport function migrationsFor(dialect: PwSqlDialect): readonly PwSqlMigration[] {\n switch (dialect) {\n case \"postgres\":\n case \"mysql\":\n case \"sqlite\":\n return MIGRATIONS_BY_DIALECT[dialect];\n default:\n throw new PayweaveMigrationError(\n `Unsupported SQL migration dialect ${JSON.stringify(dialect satisfies never)} — ` +\n `the Payweave migrations engine covers \"postgres\", \"mysql\" and \"sqlite\" only ` +\n `(docs/v1/database.md §4: mongodb/prisma/drizzle have no Payweave-owned SQL migrations).`,\n );\n }\n}\n","/**\n * The driver-agnostic SQL migrations engine (docs/v1/database.md §4, PW-703).\n * SQL adapters (PW-704/705/706) expose it as `DatabaseAdapter.migrations`:\n *\n * ```ts\n * migrations: {\n * status: () => planMigrations(executor, \"postgres\"),\n * apply: () => applyMigrations(executor, \"postgres\"),\n * }\n * ```\n *\n * Mechanics:\n * - Embedded + ordered: migrations are string constants compiled into the\n * build (`./definitions`) — no filesystem reads, no drivers, ever.\n * - Checksum ledger: every applied migration is recorded in `pw_migrations`\n * (`name` = migration id, `applied_at`, `checksum`). The ledger table is\n * created with `CREATE TABLE IF NOT EXISTS` before every read, so both\n * `planMigrations` and `applyMigrations` work on a fresh database (a plan\n * against an empty database therefore performs that one idempotent DDL\n * write).\n * - Forward-only: no down migrations exist in v1, and none are scaffolded.\n * - Mutated history FAILS LOUDLY: ledger↔embedded verification runs on BOTH\n * plan and apply — see {@link PayweaveMigrationHistoryError}.\n *\n * CHECKSUM SCHEME (stable by contract — changing it would invalidate every\n * ledger in the wild): `\"sha256:\" + hex(SHA-256(stmt₀ ‖ NUL ‖ stmt₁ ‖ NUL ‖ …))`\n * over the exact UTF-8 bytes of each statement, each terminated by a NUL\n * separator (so `[\"ab\"]` and `[\"a\",\"b\"]` hash differently). NO normalization\n * of any kind — a whitespace or comment edit IS a content change by design.\n */\nimport { createHash } from \"node:crypto\";\nimport { PayweaveMigrationError, PayweaveMigrationHistoryError } from \"./errors\";\nimport { migrationsFor } from \"./definitions\";\nimport { ledgerEnsureSql, ledgerInsertParams, ledgerInsertSql, ledgerSelectSql } from \"./ledger\";\nimport type { MigrationExecutor, PwSqlDialect, PwSqlMigration } from \"./types\";\n\n/**\n * Stable content hash of a migration's statements (`sha256:<64 hex>`); the\n * value recorded in — and verified against — the `pw_migrations.checksum`\n * column. See the module header for the exact scheme.\n */\nexport function migrationChecksum(migration: Pick<PwSqlMigration, \"statements\">): string {\n const hash = createHash(\"sha256\");\n for (const statement of migration.statements) {\n hash.update(statement, \"utf8\");\n hash.update(\"\\u0000\", \"utf8\");\n }\n return `sha256:${hash.digest(\"hex\")}`;\n}\n\n/**\n * Validate + order a migration set: ids unique, statements non-empty, and\n * execution order id-lexicographic (codepoint order — locale-independent)\n * regardless of input order.\n */\nfunction normalizeMigrationSet(migrations: readonly PwSqlMigration[]): readonly PwSqlMigration[] {\n const seen = new Set<string>();\n for (const m of migrations) {\n if (seen.has(m.id)) {\n throw new PayweaveMigrationError(\n `Malformed embedded migration set: duplicate migration id \"${m.id}\".`,\n );\n }\n seen.add(m.id);\n if (m.statements.length === 0 || m.statements.some((s) => s.trim() === \"\")) {\n throw new PayweaveMigrationError(\n `Malformed embedded migration set: migration \"${m.id}\" has an empty statement list or a blank statement.`,\n );\n }\n }\n // Ids are unique (checked above), so the comparator never sees equals.\n return [...migrations].sort((a, b) => (a.id < b.id ? -1 : 1));\n}\n\n/**\n * Bootstrap the ledger if absent, read it, and verify it against the embedded\n * set. Returns the set of applied migration ids. Throws\n * {@link PayweaveMigrationHistoryError} on any ledger↔embedded inconsistency\n * — the loud-failure gate shared by plan and apply.\n */\nasync function readVerifiedLedger(\n executor: MigrationExecutor,\n dialect: PwSqlDialect,\n migrations: readonly PwSqlMigration[],\n): Promise<ReadonlySet<string>> {\n await executor.query(ledgerEnsureSql(dialect));\n const { rows } = await executor.query(ledgerSelectSql(dialect));\n\n const byId = new Map(migrations.map((m) => [m.id, m]));\n const applied = new Set<string>();\n for (const row of rows) {\n const name = row[\"name\"];\n const checksum = row[\"checksum\"];\n if (typeof name !== \"string\" || typeof checksum !== \"string\") {\n throw new PayweaveMigrationError(\n `The pw_migrations ledger returned a malformed row (expected string \"name\" and \"checksum\" columns) — got ${JSON.stringify(row)}.`,\n );\n }\n const embedded = byId.get(name);\n if (embedded === undefined) {\n throw new PayweaveMigrationHistoryError(\n `Payweave migration history mismatch: the pw_migrations ledger contains \"${name}\", ` +\n `which is not among the migrations embedded in this build. Refusing to plan or apply ` +\n `against an unknown migration history — this usually means the database was migrated ` +\n `by a newer Payweave version, or the ledger was edited by hand (docs/v1/database.md §4).`,\n { migrationId: name, reason: \"unknown-migration\" },\n );\n }\n const expected = migrationChecksum(embedded);\n if (checksum !== expected) {\n throw new PayweaveMigrationHistoryError(\n `Payweave migration \"${name}\" was modified after it was applied: ledger checksum ` +\n `${checksum} does not match this build's checksum ${expected}. Applied migrations are ` +\n `immutable — NEVER edit an applied migration; ship the change as a new migration ` +\n `instead (forward-only, docs/v1/database.md §4).`,\n { migrationId: name, reason: \"checksum-mismatch\" },\n );\n }\n applied.add(name);\n }\n return applied;\n}\n\n/**\n * Compute the migration plan without applying anything — the engine behind\n * `DatabaseAdapter.migrations.status()`. Verifies history first and throws\n * {@link PayweaveMigrationHistoryError} on mutation, exactly like apply.\n * Ledger rows for migrations the build doesn't know are NEVER silently\n * ignored; ledger gaps (an unapplied migration ordered before an applied one)\n * are reported as pending and applied in embedded order.\n *\n * @param executor Adapter-supplied executor; see {@link MigrationExecutor}.\n * @param dialect SQL dialect whose embedded migration set to plan against.\n * @param migrations Override of the embedded set — for tests/tooling only;\n * adapters MUST omit it (defaults to `migrationsFor(dialect)`).\n */\nexport async function planMigrations(\n executor: MigrationExecutor,\n dialect: PwSqlDialect,\n migrations: readonly PwSqlMigration[] = migrationsFor(dialect),\n): Promise<{ pending: string[]; applied: string[] }> {\n const ordered = normalizeMigrationSet(migrations);\n const appliedSet = await readVerifiedLedger(executor, dialect, ordered);\n return {\n pending: ordered.filter((m) => !appliedSet.has(m.id)).map((m) => m.id),\n applied: ordered.filter((m) => appliedSet.has(m.id)).map((m) => m.id),\n };\n}\n\n/**\n * Apply every pending migration, in order, forward-only — the engine behind\n * `DatabaseAdapter.migrations.apply()`. Re-running with nothing pending is a\n * no-op (`{ applied: [] }`).\n *\n * Per migration: each statement runs as its own `executor.query()` call, then\n * one ledger row is inserted (`name`, `applied_at` = now, `checksum`). When\n * the executor provides `transaction`, statements + ledger insert run inside\n * ONE transaction per migration, so a failure rolls that migration back\n * whole; without it, execution stops at the failing statement and the error\n * surfaces (already-completed migrations stay recorded either way). Failures\n * are wrapped in {@link PayweaveMigrationError} naming the migration and\n * statement, with the driver error as `cause`.\n *\n * @param executor Adapter-supplied executor; see {@link MigrationExecutor}.\n * @param dialect SQL dialect whose embedded migration set to apply.\n * @param migrations Override of the embedded set — for tests/tooling only;\n * adapters MUST omit it (defaults to `migrationsFor(dialect)`).\n */\nexport async function applyMigrations(\n executor: MigrationExecutor,\n dialect: PwSqlDialect,\n migrations: readonly PwSqlMigration[] = migrationsFor(dialect),\n): Promise<{ applied: string[] }> {\n const ordered = normalizeMigrationSet(migrations);\n const appliedSet = await readVerifiedLedger(executor, dialect, ordered);\n const pending = ordered.filter((m) => !appliedSet.has(m.id));\n\n const applied: string[] = [];\n for (const migration of pending) {\n const runOne = async (tx: MigrationExecutor): Promise<void> => {\n for (const [index, statement] of migration.statements.entries()) {\n try {\n await tx.query(statement);\n } catch (cause) {\n throw new PayweaveMigrationError(\n `Payweave migration \"${migration.id}\" failed at statement ${index + 1} of ${migration.statements.length}.`,\n { cause },\n );\n }\n }\n try {\n await tx.query(\n ledgerInsertSql(dialect),\n ledgerInsertParams(dialect, migration.id, migrationChecksum(migration), new Date()),\n );\n } catch (cause) {\n throw new PayweaveMigrationError(\n `Payweave migration \"${migration.id}\" executed, but recording it in the pw_migrations ledger failed.`,\n { cause },\n );\n }\n };\n\n if (executor.transaction) {\n await executor.transaction(runOne);\n } else {\n await runOne(executor);\n }\n applied.push(migration.id);\n }\n return { applied };\n}\n"]}
@@ -0,0 +1,83 @@
1
+ import { PayweaveValidationError } from './chunk-HTRGMZFH.js';
2
+
3
+ // src/core/money.ts
4
+ var CURRENCY_EXPONENTS = {
5
+ // 0-exponent (no minor unit) — includes the West/Central African CFA francs
6
+ // relevant to Paystack/Flutterwave coverage.
7
+ BIF: 0,
8
+ CLP: 0,
9
+ DJF: 0,
10
+ GNF: 0,
11
+ ISK: 0,
12
+ JPY: 0,
13
+ KMF: 0,
14
+ KRW: 0,
15
+ PYG: 0,
16
+ RWF: 0,
17
+ UGX: 0,
18
+ VND: 0,
19
+ VUV: 0,
20
+ XAF: 0,
21
+ XOF: 0,
22
+ XPF: 0,
23
+ // 3-exponent (thousandths)
24
+ BHD: 3,
25
+ IQD: 3,
26
+ JOD: 3,
27
+ KWD: 3,
28
+ LYD: 3,
29
+ OMR: 3,
30
+ TND: 3
31
+ };
32
+ var DEFAULT_EXPONENT = 2;
33
+ function exponentFor(currency) {
34
+ return CURRENCY_EXPONENTS[currency.toUpperCase()] ?? DEFAULT_EXPONENT;
35
+ }
36
+ function money(value, currency) {
37
+ if (!Number.isSafeInteger(value)) {
38
+ throw new PayweaveValidationError(
39
+ `amount must be integer minor units \u2014 got ${value}; did you mean toMinor(${value}, '${currency}')?`
40
+ );
41
+ }
42
+ return { value, currency: currency.toUpperCase() };
43
+ }
44
+ function assertMoney(m) {
45
+ if (!Number.isSafeInteger(m.value)) {
46
+ throw new PayweaveValidationError(
47
+ `amount must be integer minor units \u2014 got ${m.value}; did you mean toMinor(${m.value}, '${m.currency}')?`
48
+ );
49
+ }
50
+ return m;
51
+ }
52
+ function toMajor(m) {
53
+ assertMoney(m);
54
+ const exp = exponentFor(m.currency);
55
+ if (exp === 0) return m.value;
56
+ return m.value / 10 ** exp;
57
+ }
58
+ function toMinor(major, currency) {
59
+ if (typeof major !== "number" || !Number.isFinite(major)) {
60
+ throw new PayweaveValidationError(
61
+ `amount must be a finite number \u2014 got ${String(major)}`
62
+ );
63
+ }
64
+ const exp = exponentFor(currency);
65
+ const factor = 10 ** exp;
66
+ const scaled = major * factor;
67
+ const rounded = Math.round(scaled);
68
+ if (Math.abs(scaled - rounded) > 1e-6) {
69
+ throw new PayweaveValidationError(
70
+ `amount ${major} has more precision than ${currency.toUpperCase()} allows (${exp} minor-unit digits)`
71
+ );
72
+ }
73
+ if (!Number.isSafeInteger(rounded)) {
74
+ throw new PayweaveValidationError(
75
+ `amount ${major} ${currency.toUpperCase()} exceeds the safe integer range in minor units`
76
+ );
77
+ }
78
+ return { value: rounded, currency: currency.toUpperCase() };
79
+ }
80
+
81
+ export { CURRENCY_EXPONENTS, DEFAULT_EXPONENT, assertMoney, exponentFor, money, toMajor, toMinor };
82
+ //# sourceMappingURL=chunk-TWZK62TZ.js.map
83
+ //# sourceMappingURL=chunk-TWZK62TZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/money.ts"],"names":[],"mappings":";;;AAgBO,IAAM,kBAAA,GAAgD;AAAA;AAAA;AAAA,EAG3D,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA,EACL,GAAA,EAAK,CAAA;AAAA;AAAA,EAEL,GAAA,E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,SAAS,OAAA,CAAQ,OAAe,QAAA,EAAyB;AAC9D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AACxD,IAAA,MAAM,IAAI,uBAAA;AAAA,MACR,CAAA,0CAAA,EAAwC,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,KACvD;AAAA,EACF;AACA,EAAA,MAAM,GAAA,GAAM,YAAY,QAAQ,CAAA;AAChC,EAAA,MAAM,SAAS,EAAA,IAAM,GAAA;AAGrB,EAAA,MAAM,SAAS,KAAA,GAAQ,MAAA;AACvB,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AACjC,EAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,GAAS,OAAO,IAAI,IAAA,EAAM;AACrC,IAAA,MAAM,IAAI,uBAAA;AAAA,MACR,UAAU,KAAK,CAAA,yBAAA,EAA4B,SAAS,WAAA,EAAa,YAAY,GAAG,CAAA,mBAAA;AAAA,KAClF;AAAA,EACF;AACA,EAAA,IAAI,CAAC,MAAA,CAAO,aAAA,CAAc,OAAO,CAAA,EAAG;AAClC,IAAA,MAAM,IAAI,uBAAA;AAAA,MACR,CAAA,OAAA,EAAU,KAAK,CAAA,CAAA,EAAI,QAAA,CAAS,aAAa,CAAA,8CAAA;AAAA,KAC3C;AAAA,EACF;AACA,EAAA,OAAO,EAAE,KAAA,EAAO,OAAA,EAAS,QAAA,EAAU,QAAA,CAAS,aAAY,EAAE;AAC5D","file":"chunk-TWZK62TZ.js","sourcesContent":["/**\n * Money — integer minor units, always (TDD §6.4, PRD §6.2). No floating-point\n * amounts ever cross a provider boundary. `value` is an integer count of the\n * currency's minor unit (kobo, cents, …); `currency` is an ISO-4217 code.\n */\nimport { PayweaveValidationError } from \"./errors\";\n\n/** A monetary amount. `value` is ALWAYS an integer in the currency's minor units. */\nexport type Money = { value: number; currency: string };\n\n/**\n * ISO-4217 minor-unit exponents that are NOT the default of 2. Zero-exponent\n * currencies have no minor unit (₦-style kobo does not exist for them), so a\n * \"major\" amount already equals the \"minor\" amount. Three-exponent currencies\n * (Gulf dinars) use thousandths. Anything absent defaults to 2.\n */\nexport const CURRENCY_EXPONENTS: Record<string, 0 | 2 | 3> = {\n // 0-exponent (no minor unit) — includes the West/Central African CFA francs\n // relevant to Paystack/Flutterwave coverage.\n BIF: 0,\n CLP: 0,\n DJF: 0,\n GNF: 0,\n ISK: 0,\n JPY: 0,\n KMF: 0,\n KRW: 0,\n PYG: 0,\n RWF: 0,\n UGX: 0,\n VND: 0,\n VUV: 0,\n XAF: 0,\n XOF: 0,\n XPF: 0,\n // 3-exponent (thousandths)\n BHD: 3,\n IQD: 3,\n JOD: 3,\n KWD: 3,\n LYD: 3,\n OMR: 3,\n TND: 3,\n};\n\n/** Default minor-unit exponent for any currency not in {@link CURRENCY_EXPONENTS}. */\nexport const DEFAULT_EXPONENT = 2;\n\n/**\n * Minor-unit exponent for a currency code (case-insensitive). Unknown codes\n * fall back to {@link DEFAULT_EXPONENT} (2) — the adapter layer logs a warning\n * for unknown currencies; this pure function does not.\n */\nexport function exponentFor(currency: string): number {\n return CURRENCY_EXPONENTS[currency.toUpperCase()] ?? DEFAULT_EXPONENT;\n}\n\n/**\n * Construct a validated {@link Money} from a MINOR-unit value. Rejects\n * non-integers (a float here almost always means the caller passed major units)\n * with a fix-it message pointing at {@link toMinor}.\n *\n * @example money(500000, \"NGN\") // ₦5,000 as { value: 500000, currency: \"NGN\" }\n */\nexport function money(value: number, currency: string): Money {\n if (!Number.isSafeInteger(value)) {\n throw new PayweaveValidationError(\n `amount must be integer minor units — got ${value}; did you mean toMinor(${value}, '${currency}')?`,\n );\n }\n return { value, currency: currency.toUpperCase() };\n}\n\n/**\n * Assert an existing {@link Money} carries an integer minor-unit value. Returns\n * the same object for convenient chaining; throws {@link PayweaveValidationError}\n * on a non-integer.\n */\nexport function assertMoney(m: Money): Money {\n if (!Number.isSafeInteger(m.value)) {\n throw new PayweaveValidationError(\n `amount must be integer minor units — got ${m.value}; did you mean toMinor(${m.value}, '${m.currency}')?`,\n );\n }\n return m;\n}\n\n/**\n * Convert a MINOR-unit {@link Money} to a major-unit number (for display or for\n * providers that expect major units, e.g. Flutterwave v3). Validates the source\n * value is an integer first.\n *\n * @example toMajor({ value: 500000, currency: \"NGN\" }) // 5000\n */\nexport function toMajor(m: Money): number {\n assertMoney(m);\n const exp = exponentFor(m.currency);\n if (exp === 0) return m.value;\n return m.value / 10 ** exp;\n}\n\n/**\n * Convert a MAJOR-unit amount to a minor-unit {@link Money} using integer-safe\n * math (never `value / 100`). A rounding guard rejects amounts with more\n * fractional precision than the currency permits (e.g. `50.555` for a\n * 2-exponent currency) rather than silently truncating.\n *\n * @example toMinor(5000, \"NGN\") // { value: 500000, currency: \"NGN\" }\n * @example toMinor(50.5, \"NGN\") // { value: 5050, currency: \"NGN\" }\n * @example toMinor(1000, \"XOF\") // { value: 1000, currency: \"XOF\" } (0-exponent)\n */\nexport function toMinor(major: number, currency: string): Money {\n if (typeof major !== \"number\" || !Number.isFinite(major)) {\n throw new PayweaveValidationError(\n `amount must be a finite number — got ${String(major)}`,\n );\n }\n const exp = exponentFor(currency);\n const factor = 10 ** exp;\n // Scale then round; the guard below catches any precision the currency can't\n // represent, so the rounding only ever absorbs floating-point noise.\n const scaled = major * factor;\n const rounded = Math.round(scaled);\n if (Math.abs(scaled - rounded) > 1e-6) {\n throw new PayweaveValidationError(\n `amount ${major} has more precision than ${currency.toUpperCase()} allows (${exp} minor-unit digits)`,\n );\n }\n if (!Number.isSafeInteger(rounded)) {\n throw new PayweaveValidationError(\n `amount ${major} ${currency.toUpperCase()} exceeds the safe integer range in minor units`,\n );\n }\n return { value: rounded, currency: currency.toUpperCase() };\n}\n"]}