diff --git a/README.md b/README.md index 72931e8..ec69cbc 100644 --- a/README.md +++ b/README.md @@ -103,14 +103,6 @@ errors.match(e, { }) ``` -## Note for Developers - -This starter recommends using [npm Trusted Publisher](https://github.com/e18e/ecosystem-issues/issues/201), where the release is done on CI to ensure the security of the packages. - -To do so, you need to run `pnpm publish` manually for the very first time to create the package on npm, and then go to `https://www.npmjs.com/package//access` to set the connection to your GitHub repo. - -Then for future releases, you can run `pnpm run release` and the GitHub Actions will take care of the release process. - ## License [MIT](./LICENSE) License © [Franco P. Romano L.](https://github.com/fprl) diff --git a/packages/errata/package.json b/packages/errata/package.json index 451059f..6c69ca6 100644 --- a/packages/errata/package.json +++ b/packages/errata/package.json @@ -1,7 +1,7 @@ { "name": "errata", "type": "module", - "version": "0.0.0", + "version": "1.0.0", "packageManager": "pnpm@10.20.0", "description": "A typed error registry for TypeScript. Errors are data—define them like it.", "author": "Franco P. Romano L. ", @@ -15,14 +15,8 @@ "keywords": [], "sideEffects": false, "exports": { - ".": { - "types": "./dist/index.d.mts", - "import": "./dist/index.mjs" - }, - "./client": { - "types": "./dist/client.d.mts", - "import": "./dist/client.mjs" - }, + ".": "./dist/index.mjs", + "./client": "./dist/client.mjs", "./package.json": "./package.json" }, "main": "./dist/index.mjs", diff --git a/packages/errata/src/client.ts b/packages/errata/src/client.ts index 4852a3b..fb3b2e0 100644 --- a/packages/errata/src/client.ts +++ b/packages/errata/src/client.ts @@ -68,7 +68,7 @@ export type ClientMatchHandlers = ClientMatchHand /** * Client-side surface derived from a server `errors` type. */ -export interface ErrorClient { +export interface ErrataClient { /** Client-side ErrataError constructor for instanceof checks. */ ErrataError: new ( payload: SerializedError, any> @@ -133,7 +133,7 @@ type InferCodes = T extends ErrataInstance ? TCodes : CodesRecord -export interface ErrorClientOptions { +export interface ErrataClientOptions { /** Optional app identifier for debugging. */ app?: string /** Optional lifecycle plugins (payload adaptation, logging). */ @@ -152,9 +152,9 @@ export interface ErrorClientOptions { * Create a client that understands the server codes (type-only). * @param options - Optional configuration including plugins. */ -export function createErrorClient>( - options: ErrorClientOptions = {}, -): ErrorClient> { +export function createErrataClient>( + options: ErrataClientOptions = {}, +): ErrataClient> { const { app, plugins = [], onUnknown } = options type TCodes = InferCodes @@ -302,7 +302,7 @@ export function createErrorClient>( const patterns = Array.isArray(pattern) ? pattern : [pattern] return patterns.some(p => matchesPattern(err.code, p as string)) - }) as ErrorClient['is'] + }) as ErrataClient['is'] /** Pattern matcher with priority: exact match > longest wildcard > default. */ const match = (( @@ -318,7 +318,7 @@ export function createErrorClient>( : (handlers as any).default return handler ? handler(errataErr) : undefined - }) as ErrorClient['match'] + }) as ErrataClient['match'] /** Check whether an error carries a given tag. */ const hasTag = ( @@ -347,7 +347,7 @@ export function createErrorClient>( catch (err) { return [null, ensure(err)] } - }) as ErrorClient['safe'] + }) as ErrataClient['safe'] return { ErrataError: ErrataClientError, diff --git a/packages/errata/src/index.ts b/packages/errata/src/index.ts index c0bb688..5bfa7fe 100644 --- a/packages/errata/src/index.ts +++ b/packages/errata/src/index.ts @@ -1,50 +1,16 @@ export { - createErrorClient, + type ClientMatchHandlers, + createErrataClient, + type ErrataClient, ErrataClientError, - type ErrorClient, - type ErrorClientOptions, + type ErrataClientOptions, } from './client' export { code, defineClientPlugin, defineCodes, definePlugin, props } from './define' -export { - errata, - type ErrataInstance, - type ErrataOptions, - type MatchHandlers, -} from './errata' +export { errata, type ErrataInstance, type ErrataOptions, type MatchHandlers } from './errata' export { ErrataError, type SerializedError } from './errata-error' export type { - ClientConfig, - ClientContext, CodeConfig, CodeConfigRecord, - CodesOf, - DetailsOf, - ErrataClientErrorForCodes, ErrataClientPlugin, - ErrataConfig, - ErrataContext, - ErrataErrorForCodes, ErrataPlugin, - InternalCode, - InternalDetails, - MatchingCodes, - MatchingCodesFromUnion, - MatchingErrataClientError, - MatchingErrataClientErrorForCodes, - MatchingErrataError, - MatchingErrataErrorForCodes, - MergePluginCodes, - MessageResolver, - Pattern, - PatternForCodes, - PatternInputForCodes, - PluginCodes, - ResolveMatchingCodes, - ResolveMatchingCodesFromUnion, } from './types' -export { - findBestMatchingPattern, - getWildcardPrefix, - isWildcardPattern, - matchesPattern, -} from './utils/pattern-matching' diff --git a/packages/errata/test/client-plugins.test.ts b/packages/errata/test/client-plugins.test.ts index 3369744..5ef20ca 100644 --- a/packages/errata/test/client-plugins.test.ts +++ b/packages/errata/test/client-plugins.test.ts @@ -3,7 +3,7 @@ import type { ErrataClientPlugin } from '../src' import type { errors } from './fixtures' import { describe, expect, it, vi } from 'vitest' -import { createErrorClient, defineClientPlugin, ErrataClientError } from '../src' +import { createErrataClient, defineClientPlugin, ErrataClientError } from '../src' // ─── 5. onDeserialize Adaptation (The "RFC 7807" Case) ──────────────────────── @@ -41,7 +41,7 @@ describe('client plugin onDeserialize adaptation', () => { }, } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [rfc7807Plugin], }) @@ -60,7 +60,7 @@ describe('client plugin onDeserialize adaptation', () => { onDeserialize: () => null, } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [noopPlugin], }) @@ -78,7 +78,7 @@ describe('client plugin onDeserialize adaptation', () => { }) it('returns errata.unknown_error for invalid payloads without plugins', () => { - const client = createErrorClient() + const client = createErrataClient() const invalidPayload = { no_code_here: true } const err = client.deserialize(invalidPayload) @@ -109,7 +109,7 @@ describe('client plugin onDeserialize adaptation', () => { onDeserialize: spyB, } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [pluginA, pluginB], }) @@ -129,7 +129,7 @@ describe('client plugin onDeserialize adaptation', () => { }, } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [crashingPlugin], }) @@ -159,7 +159,7 @@ describe('client plugin onCreate', () => { }, } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [loggingPlugin], }) @@ -198,7 +198,7 @@ describe('client plugin onCreate', () => { onCreate: error => logSpy(error.code), } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [adapterPlugin, loggingPlugin], }) @@ -221,7 +221,7 @@ describe('client plugin onCreate', () => { onCreate: () => spyB(), } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [pluginA, pluginB], }) @@ -247,7 +247,7 @@ describe('client plugin onCreate', () => { onCreate: () => safeSpy(), } - const client = createErrorClient({ + const client = createErrataClient({ plugins: [crashingPlugin, safePlugin], }) @@ -275,7 +275,7 @@ describe('client plugin onCreate', () => { }, } - const client = createErrorClient({ + const client = createErrataClient({ app: 'my-client-app', plugins: [configPlugin], }) @@ -292,7 +292,7 @@ describe('client plugin validation', () => { it('warns on duplicate plugin names', () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) - createErrorClient({ + createErrataClient({ plugins: [ { name: 'duplicate' }, { name: 'duplicate' }, @@ -322,7 +322,7 @@ describe('client plugin validation', () => { }, }) - const client = createErrorClient({ + const client = createErrataClient({ app: 'test-app', plugins: [myPlugin], }) diff --git a/packages/errata/test/client.test.ts b/packages/errata/test/client.test.ts index 35afe18..7e9bc53 100644 --- a/packages/errata/test/client.test.ts +++ b/packages/errata/test/client.test.ts @@ -1,13 +1,13 @@ -import type { CodesOf, InternalCode } from '../src' +import type { CodesOf, InternalCode } from '../src/types' import type { ErrorCode } from './fixtures' import { describe, expect, expectTypeOf, it } from 'vitest' -import { createErrorClient } from '../src' +import { createErrataClient } from '../src' import { errors } from './fixtures' describe('client error client', () => { - const client = createErrorClient() + const client = createErrataClient() it('deserializes and matches codes', () => { const serverErr = errors.create('auth.invalid_token', { reason: 'expired' }) @@ -46,7 +46,7 @@ describe('client error client', () => { }) describe('client pattern matching: is()', () => { - const client = createErrorClient() + const client = createErrataClient() describe('wildcard pattern matching', () => { it('matches codes starting with prefix using auth.*', () => { @@ -116,7 +116,7 @@ describe('client pattern matching: is()', () => { }) describe('client pattern matching: match()', () => { - const client = createErrorClient() + const client = createErrataClient() describe('wildcard handlers', () => { it('calls wildcard handler when no exact match', () => { @@ -223,7 +223,7 @@ describe('client pattern matching: match()', () => { }) describe('client hasTag()', () => { - const client = createErrorClient() + const client = createErrataClient() it('returns true when error has tag', () => { const err = client.deserialize( @@ -277,7 +277,7 @@ describe('client hasTag()', () => { }) describe('client deserialize (robust)', () => { - const client = createErrorClient() + const client = createErrataClient() it('deserializes a valid payload', () => { const payload = errors.serialize(errors.create('auth.invalid_token', { reason: 'expired' })) @@ -316,7 +316,7 @@ describe('client deserialize (robust)', () => { }) describe('client safe()', () => { - const client = createErrorClient() + const client = createErrataClient() it('normalizes network TypeError via ensure (no magic mapping)', async () => { const [data, err] = await client.safe(Promise.reject(new TypeError('dns'))) @@ -358,7 +358,7 @@ describe('client safe()', () => { }) describe('client onUnknown hook', () => { - const client = createErrorClient({ + const client = createErrataClient({ onUnknown: err => err instanceof TypeError ? 'analytics.event_dropped' : null, }) diff --git a/packages/errata/test/define-codes.test.ts b/packages/errata/test/define-codes.test.ts index 1bb7c95..9bda868 100644 --- a/packages/errata/test/define-codes.test.ts +++ b/packages/errata/test/define-codes.test.ts @@ -1,4 +1,4 @@ -import type { DetailsOf } from '../src' +import type { DetailsOf } from '../src/types' import { describe, expect, expectTypeOf, it } from 'vitest' diff --git a/packages/errata/test/errata.test.ts b/packages/errata/test/errata.test.ts index 0a2d509..538db95 100644 --- a/packages/errata/test/errata.test.ts +++ b/packages/errata/test/errata.test.ts @@ -1,4 +1,4 @@ -import type { InternalCode } from '../src' +import type { InternalCode } from '../src/types' import type { ErrorCode } from './fixtures' import { describe, expect, expectTypeOf, it } from 'vitest'