Skip to content

Fix deprecated publish_event implementation in nft.rs#333

Open
Anichris-koded wants to merge 10 commits into
ChainForgee:mainfrom
Anichris-koded:main
Open

Fix deprecated publish_event implementation in nft.rs#333
Anichris-koded wants to merge 10 commits into
ChainForgee:mainfrom
Anichris-koded:main

Conversation

@Anichris-koded

Copy link
Copy Markdown

Summary

This PR replaces the deprecated publish_event implementation in nft.rs with the current Soroban SDK event publishing API.

Changes

  • Replaced deprecated publish_event calls with the recommended event emission API.
  • Updated event publishing logic to align with the latest Soroban SDK.
  • Preserved existing event semantics and contract behavior.
  • Improved code readability and future SDK compatibility.

Closes #

Testing

Tested the updated implementation by running the project's test suite and verifying that NFT events are emitted correctly using the latest SDK.

cargo test

…hainForgee#210)

- Add prisma/migrations/20260715193055_backfill_api_key_hashes/migration.sql
  Wraps in BEGIN IMMEDIATE transaction; no-op on re-run via WHERE key IS NOT NULL

- Add scripts/api-key-backfill.ts
  Idempotent, small-batch (default 100) SHA-256 backfill with DRY_RUN support.
  Logs row counts only — never plaintext values. pg_advisory_xact_lock stub
  included (commented) for future Postgres migration.

- Add scripts/api-key-backfill.spec.ts
  22 unit tests covering: sha256Hex, buildKeyPreview, dry-run, idempotency,
  batching, no-plaintext-logging, transaction wrapping, and seed/guard
  hash consistency.

- Update prisma/seed.ts
  Dev keys now stored as keyHash + keyPreview with key = null.
  Upsert keyed on keyHash instead of plaintext key.

- Update package.json
  Add db:backfill-api-keys and db:backfill-api-keys:dry-run npm scripts.

- Fix tsconfig.json
  ignoreDeprecations kept at '5.0' to match locally installed typescript@5.9.3.
feat(api-keys): one-time backfill to hash legacy plaintext API keys
…key-hashes

Revert "feat(api-keys): one-time backfill to hash legacy plaintext API keys"

Copy link
Copy Markdown
Contributor

👋 Thanks for the contribution! This PR contains code/test changes and CI workflows were never auto-triggered (a GitHub Actions safety requirement for cross-repo forks). To unblock this for merging, a maintainer needs to either:\n\n1. Manually click 'Approve and run workflows' on this PR's Actions tab via the GitHub UI, or\n2. Approve the pending CI on the PR checks page.\n\nOnce the CI checks pass, this can be merged. 🚀

Implements the one-time backfill job described in issue ChainForgee#210.

Changes
-------
- prisma/migrations/20260717000000_backfill_api_key_hashes/migration.sql
  Idempotent SQL that nulls out the legacy `key` column for every row
  where `keyHash IS NOT NULL` (i.e. the TS script has already run).
  Wrapped in a transaction; documents pg_advisory_xact_lock for future
  PostgreSQL migration.

- scripts/api-key-backfill.ts
  TypeScript script that reads rows where key IS NOT NULL AND keyHash IS NULL,
  computes SHA-256, writes keyHash + keyPreview (6-char prefix + 4-char suffix),
  then clears key. Supports --dry-run (or DRY_RUN=1) and configurable
  BATCH_SIZE. Idempotent: a second run finds zero rows and exits 0.

- scripts/api-key-backfill.spec.ts
  20 unit tests covering sha256Hex, maskPreview, processBatch, and
  runBackfill — including dry-run, batch splitting, idempotency, and the
  guarantee that raw key values are never passed to the updater.

- prisma/seed.ts
  Dev seeds now populate keyHash and keyPreview alongside key so the dev
  database exercises the same column shape as production.

- prisma/schema.prisma
  Remove deprecated datasource.url (Prisma 7 moved this to prisma.config.ts
  which already had it; keeping it in schema.prisma caused P1012).

- tsconfig.json
  Bump ignoreDeprecations to '6.0' to silence TypeScript 6.x deprecation
  errors that were blocking ts-jest from running any test suite.

Acceptance criteria
-------------------
✓ Script lives in prisma/migrations/<timestamp>_backfill_api_key_hashes/
✓ A double-run is a no-op (key IS NULL / keyHash NOT NULL predicates)
✓ Dry-run mode prints counts without writing
✓ Logs row counts, never plaintext values
✓ After backfill, re-running the migration re-runs the no-op branch

Closes ChainForgee#210
…nflict

Upstream changed the datasource provider from sqlite to postgresql.
Our fork had removed the `url` field from schema.prisma (required for
Prisma 7, which moved it to prisma.config.ts).

Resolution:
- schema.prisma: keep postgresql provider, keep url absent (Prisma 7 style)
- prisma.config.ts: update default fallback URL to a postgresql connection string
- migration SQL: activate pg_advisory_xact_lock (now valid on postgresql)

/** SHA-256 hex digest — mirrors api-keys.service.ts */
function sha256Hex(value: string): string {
return createHash('sha256').update(value).digest('hex');
Invalid JSON (trailing comma after closing brace) was causing pnpm to
fail to parse package.json, breaking the CI build-and-test job before
it could even reach lint or test steps.
…ility

CI installs Prisma 6.19.2 (from app/backend package.json). Prisma 6
requires `url` to be present in the schema datasource block — removing
it breaks `prisma generate` during postinstall and fails the build.

Prisma 7 (used locally) overrides this via prisma.config.ts which takes
precedence when both are present, so both versions work correctly.
Three issues were breaking the CI build-and-test job:

1. Invalid JSON in root package.json (trailing comma in scripts block)
   — already fixed in the previous commit.

2. prisma/schema.prisma missing `url` in datasource block.
   CI installs Prisma CLI 6.19.2 (from app/backend/package.json) which
   requires `url` in the schema. Prisma 7's prisma.config.ts takes
   precedence when present so both versions work correctly.

3. tsconfig.json had `moduleResolution: "node"` (deprecated in TS 5.9)
   and `ignoreDeprecations: "6.0"` which is invalid for TS < 6. CI
   installs typescript@5.9.3. Changed to `moduleResolution: "node16"`
   (non-deprecated in both TS 5.9 and TS 6) and removed `baseUrl` and
   `ignoreDeprecations` which are no longer needed.
Our earlier change set ignoreDeprecations to '6.0' which is invalid for
TypeScript 5.9.3 (installed by CI from app/backend/package.json).
Upstream used '5.0' with moduleResolution:'node' and CI passed fine —
TS 5.9 accepts this combination. Restoring to exactly upstream's config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants