typizer 0.3.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -3,12 +3,13 @@ export * from './gen/index.js';
3
3
  import { TypizerClient } from './client.js';
4
4
  import type { Client } from './gen/client/index.js';
5
5
  import type { Typizer as GeneratedTypizer } from './gen/types.gen.js';
6
- export { type BatchCreateParams, Batches, Catalog, type CatalogListParams, type CreateRunParams, DEFAULT_BASE_URL, type ExtractParams, Files, type Format, type ListParams, type Mode, type RunListParams, type RunParams, Runs, TypizerClient, type TypizerCreateParams, type TypizerOptions, Typizers, type TypizerUpdateParams, type WaitParams, WebhookEndpoints, } from './client.js';
6
+ export { type BatchCreateParams, Batches, Catalog, type CatalogListParams, type CreateRunParams, DEFAULT_BASE_URL, type ExtractParams, Files, type Format, type ListParams, type Mode, type RunListParams, type RunParams, Runs, TypizerClient, type TypizerCreateParams, type TypizerOptions, Typizers, type TypizerUpdateParams, Validators, type WaitParams, WebhookEndpoints, } from './client.js';
7
7
  export { APIPromise, type AppInfo, type Logger, type LogLevel, type RequestOptions, type WithResponse, } from './core.js';
8
8
  export { APIConnectionError, APIError, APITimeoutError, AuthenticationError, BadRequestError, ConfigurationError, ConflictError, FileTooLargeError, IdempotencyConflictError, InsufficientBalanceError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, type RateLimitInfo, RunFailedError, ServiceUnavailableError, TypizerError, UnprocessableDocumentError, UnsupportedFileTypeError, WaitTimeoutError, WebhookVerificationError, type WebhookVerificationReason, } from './errors.js';
9
9
  export { type FileInput, MAX_FILE_BYTES, type Uploadable } from './files.js';
10
10
  export { Page, PagePromise } from './pagination.js';
11
- export type { FieldResult, FieldSource, FieldToReview, RunHelpers, TypizerRun } from './run.js';
11
+ export type { FieldCheck, FieldResult, FieldSource, FieldToReview, FieldWarning, RunHelpers, TypizerRun, } from './run.js';
12
+ export type { DeletedValidator, RunCheckUsed, TypizerCheck, Validator, ValidatorBump, ValidatorCreateParams, ValidatorDetail, ValidatorSpec, ValidatorSuggestion, ValidatorSuggestParams, ValidatorTest, ValidatorTestInput, ValidatorTestParams, ValidatorTestResult, ValidatorUpdateParams, ValidatorUpdateResult, ValidatorUsedBy, ValidatorVersion, } from './validators.js';
12
13
  export { VERSION } from './version.js';
13
14
  export { isValidWebhook, type VerifyWebhookOptions, verifyWebhook, type WebhookEvent, type WebhookHeaders, webhooks, } from './webhooks.js';
14
15
  /**
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export * from './gen/index.js';
3
3
  import { TypizerClient } from './client.js';
4
4
  import { anySignal, userAgent } from './core.js';
5
5
  import { createClient, createConfig } from './gen/client/index.js';
6
- export { Batches, Catalog, DEFAULT_BASE_URL, Files, Runs, TypizerClient, Typizers, WebhookEndpoints, } from './client.js';
6
+ export { Batches, Catalog, DEFAULT_BASE_URL, Files, Runs, TypizerClient, Typizers, Validators, WebhookEndpoints, } from './client.js';
7
7
  export { APIPromise, } from './core.js';
8
8
  export { APIConnectionError, APIError, APITimeoutError, AuthenticationError, BadRequestError, ConfigurationError, ConflictError, FileTooLargeError, IdempotencyConflictError, InsufficientBalanceError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, RunFailedError, ServiceUnavailableError, TypizerError, UnprocessableDocumentError, UnsupportedFileTypeError, WaitTimeoutError, WebhookVerificationError, } from './errors.js';
9
9
  export { MAX_FILE_BYTES } from './files.js';
package/dist/run.d.ts CHANGED
@@ -13,14 +13,37 @@ export interface FieldSource {
13
13
  /** The source text. */
14
14
  text: string;
15
15
  }
16
+ /** One check of a field: a built-in requisite check (`inn`, `bik`, …) or a document rule
17
+ * (`doc:sum_of`). */
18
+ export interface FieldCheck {
19
+ ref: string;
20
+ /** Version of the check (`1.0.0`). */
21
+ version?: string;
22
+ /** Russian display name (`ИНН`). */
23
+ name?: string;
24
+ /** `pass`, `fail` or `skipped` (the check could not run); an open enum. */
25
+ status: 'pass' | 'fail' | 'skipped' | (string & {});
26
+ /** What decided the outcome: `checksum`, `format`, … */
27
+ rule?: string;
28
+ /** With `fail`: the reason code. */
29
+ reason?: string;
30
+ /** With `pass`: the check failed on the first reading and passed after the field was read again
31
+ * from the same place («Перечитать при ошибке», `precise` mode). */
32
+ corrected?: boolean;
33
+ }
16
34
  /** The check result of one leaf field (`seller.inn`, `items[0].amount`). */
17
35
  export interface FieldResult {
18
36
  /** `ok`, `warn` (a value that failed a check) or `missing` (no value); an open enum. */
19
37
  status: 'ok' | 'warn' | 'missing' | (string & {});
20
- /** For `warn`: `checksum_mismatch`, `invalid_format`, `sum_mismatch`, `implausible_date`,
21
- * `no_source`, `code_mismatch` (the value contradicts a barcode or QR code printed on the
22
- * document), … */
38
+ /** For `warn`: `checksum_mismatch`, `invalid_format`, `pattern_mismatch`, `not_in_list`,
39
+ * `out_of_range`, `sum_mismatch`, `rule_failed`, `implausible_date`, `no_source`,
40
+ * `code_mismatch` (the value contradicts a barcode or QR code printed on the document), …
41
+ * (an open set). */
23
42
  reason?: string | null;
43
+ /** For `warn`: the same reason as a ready Russian sentence — show this to people. */
44
+ message?: string;
45
+ /** Every check of the field (absent when none applies). */
46
+ checks?: FieldCheck[];
24
47
  sources?: FieldSource[];
25
48
  }
26
49
  /** A field that needs a human look: `fieldsToReview()`. */
@@ -28,6 +51,16 @@ export interface FieldToReview extends FieldResult {
28
51
  /** The field's path in API notation (`seller.inn`, `items[0].amount`). */
29
52
  path: string;
30
53
  }
54
+ /** A field that failed a check, as a person should see it: `run.warnings()`. */
55
+ export interface FieldWarning {
56
+ /** The field's path in API notation (`contract_no`, `items[0].amount`). */
57
+ path: string;
58
+ /** The reason as a ready Russian sentence (`FieldResult.message`); `null` for runs and webhooks
59
+ * made before the API sent it. */
60
+ message: string | null;
61
+ /** The reason code (`pattern_mismatch`, `checksum_mismatch`, …); an open set. */
62
+ reason: string | null;
63
+ }
31
64
  export interface RunHelpers {
32
65
  /** `status` is `succeeded` or `failed`. */
33
66
  readonly isTerminal: boolean;
@@ -35,6 +68,9 @@ export interface RunHelpers {
35
68
  readonly needsReview: boolean;
36
69
  /** Fields with status `warn` or `missing`, in the order of `fields`. */
37
70
  fieldsToReview(): FieldToReview[];
71
+ /** Fields with status `warn` (a value that failed a check) with the message to show and the
72
+ * reason code, in the order of `fields`; `missing` fields are not included. */
73
+ warnings(): FieldWarning[];
38
74
  }
39
75
  /**
40
76
  * A run with the helpers. `status` is open (a new value from the API is kept as a string), and
package/dist/run.js CHANGED
@@ -35,6 +35,23 @@ const HELPERS = {
35
35
  configurable: true,
36
36
  writable: true,
37
37
  },
38
+ warnings: {
39
+ value() {
40
+ const fields = this.fields;
41
+ if (!fields || typeof fields !== 'object')
42
+ return [];
43
+ const out = [];
44
+ for (const [path, f] of Object.entries(fields)) {
45
+ if (f && f.status === 'warn') {
46
+ out.push({ path, message: f.message ?? null, reason: f.reason ?? null });
47
+ }
48
+ }
49
+ return out;
50
+ },
51
+ enumerable: false,
52
+ configurable: true,
53
+ writable: true,
54
+ },
38
55
  };
39
56
  /** Adds the helpers to a run object (in place) and returns it. */
40
57
  export function withRunHelpers(run) {
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Field checks («проверки», SPEC §3, §5.1): the models of `client.validators` as the API sends
3
+ * them — JSON objects as is (unknown fields kept), with the enums open (a new value from the API is
4
+ * kept as a string). A check's `spec` stays free-form JSON: rule kinds are added without a new API
5
+ * version, so the SDK never closes it into types.
6
+ */
7
+ import type { DeletedValidator, Validator as GenValidator, ValidatorSuggestion as GenValidatorSuggestion, ValidatorTest as GenValidatorTest, ValidatorUpdateResult as GenValidatorUpdateResult, ValidatorVersion as GenValidatorVersion, RunCheckUsed, TypizerCheck, ValidatorTestResult, ValidatorUsedBy } from './gen/types.gen.js';
8
+ export type { DeletedValidator, RunCheckUsed, TypizerCheck, ValidatorTestResult, ValidatorUsedBy };
9
+ type Open<T extends string> = T | (string & {});
10
+ /**
11
+ * A check's specification: `{ kind: 'rules', applies_to, rules: […], message }`, or
12
+ * `{ kind: 'native', id: 'inn' }`. Passed and returned as is — the SDK does not validate it.
13
+ */
14
+ export type ValidatorSpec = Record<string, unknown>;
15
+ /** One example of a check: a value that must `pass` or `fail` (a version's contract). */
16
+ export type ValidatorTest = Omit<GenValidatorTest, 'expect'> & {
17
+ /** `pass` or `fail`; an open enum. */
18
+ expect: Open<'pass' | 'fail'>;
19
+ };
20
+ /** One version of a check (`1.0.0`): the spec, its tests and a Russian explanation. */
21
+ export type ValidatorVersion = Omit<GenValidatorVersion, 'spec' | 'tests'> & {
22
+ spec: ValidatorSpec;
23
+ tests: ValidatorTest[];
24
+ };
25
+ /** A check of the organization (`my/contract-no`): reference it in `x-typizer-check` as `my/contract-no@1`. */
26
+ export type Validator = Omit<GenValidator, 'version'> & {
27
+ /** The current version. */
28
+ version: ValidatorVersion;
29
+ };
30
+ /** A check with every version (newest first) and the typizers that use it. */
31
+ export type ValidatorDetail = Validator & {
32
+ versions: ValidatorVersion[];
33
+ used_by: ValidatorUsedBy[];
34
+ };
35
+ /** Which version an update made: `major`, `minor`, `patch` or `none`; an open enum. */
36
+ export type ValidatorBump = Open<'major' | 'minor' | 'patch' | 'none'>;
37
+ /** The result of `validators.update`: the check, the version bump the API chose and why. */
38
+ export type ValidatorUpdateResult = Omit<GenValidatorUpdateResult, 'validator' | 'bump'> & {
39
+ validator: Validator;
40
+ bump: ValidatorBump;
41
+ };
42
+ /** A check drafted by `validators.suggest` from a description and/or examples. */
43
+ export type ValidatorSuggestion = Omit<GenValidatorSuggestion, 'spec' | 'tests' | 'source' | 'candidates_from_catalog'> & {
44
+ spec: ValidatorSpec;
45
+ /** Every example and what the drafted check does with it. */
46
+ tests: Array<{
47
+ value: string | number;
48
+ expect: Open<'pass' | 'fail'>;
49
+ got: Open<'pass' | 'fail'>;
50
+ }>;
51
+ /** `catalog`, `shape` (derived from the examples) or `model`; an open enum. */
52
+ source: Open<'catalog' | 'shape' | 'model'>;
53
+ /** Ready checks that fit: official ones by the field's name and your own that pass the examples. */
54
+ candidates_from_catalog: Array<Omit<GenValidatorSuggestion['candidates_from_catalog'][number], 'kind'> & {
55
+ kind: Open<'official' | 'own'>;
56
+ }>;
57
+ };
58
+ /** A test example for `validators.create` / `update`. */
59
+ export interface ValidatorTestInput {
60
+ value: string | number;
61
+ expect: 'pass' | 'fail';
62
+ note?: string;
63
+ }
64
+ export interface ValidatorCreateParams {
65
+ /** The name people see («Номер договора»). */
66
+ name: string;
67
+ /** The specification, as is (`{ kind: 'rules', … }`). */
68
+ spec: ValidatorSpec;
69
+ /** Examples that must pass or fail (up to 100) — every one must hold, else `BadRequestError` with `param: 'tests/<i>'`. */
70
+ tests?: ValidatorTestInput[];
71
+ /** The reference becomes `my/<slug>`; by default it is made from the name. */
72
+ slug?: string;
73
+ description?: string | null;
74
+ /** What changed — for the version history. */
75
+ changelog?: string;
76
+ }
77
+ export type ValidatorUpdateParams = Partial<Omit<ValidatorCreateParams, 'slug'>>;
78
+ export interface ValidatorTestParams {
79
+ /** 1–100 strings or numbers to check. */
80
+ values: Array<string | number>;
81
+ /** A check reference: `my/contract-no@1`, `inn@1`, `val_…` (exactly one of `ref` and `spec`). */
82
+ ref?: string;
83
+ /** Or a specification object, as is (exactly one of `ref` and `spec`). */
84
+ spec?: ValidatorSpec;
85
+ }
86
+ export interface ValidatorSuggestParams {
87
+ /** Which values are right, in words. */
88
+ description?: string | null;
89
+ /** Values that must pass and must fail (up to 50 each). */
90
+ examples?: {
91
+ pass?: Array<string | number>;
92
+ fail?: Array<string | number>;
93
+ };
94
+ /** The schema field the check is for. */
95
+ field?: {
96
+ name?: string;
97
+ description?: string;
98
+ type?: string;
99
+ };
100
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The SDK version (sent in `User-Agent`); kept equal to package.json by test/client.test.ts. */
2
- export declare const VERSION = "0.3.0";
2
+ export declare const VERSION = "0.4.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The SDK version (sent in `User-Agent`); kept equal to package.json by test/client.test.ts. */
2
- export const VERSION = '0.3.0';
2
+ export const VERSION = '0.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typizer",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Официальный TypeScript SDK для Typizer API — извлечение данных из документов в JSON по вашей схеме",
@@ -45,8 +45,8 @@
45
45
  "devDependencies": {
46
46
  "@hey-api/openapi-ts": "^0.99.0",
47
47
  "typescript": "6.0.3",
48
- "@typizer/sdk-spec": "0.0.0",
49
- "@typizer/config": "0.0.0"
48
+ "@typizer/config": "0.0.0",
49
+ "@typizer/sdk-spec": "0.0.0"
50
50
  },
51
51
  "scripts": {
52
52
  "generate": "openapi-ts",