@deliverart/sdk-js-error-handler 0.0.6

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.
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
+ "changelog": "@changesets/cli/changelog",
4
+ "commit": false,
5
+ "fixed": [],
6
+ "linked": [],
7
+ "access": "restricted",
8
+ "baseBranch": "main",
9
+ "updateInternalDependencies": "patch",
10
+ "ignore": []
11
+ }
@@ -0,0 +1,47 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ release:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - uses: pnpm/action-setup@v2
18
+ with:
19
+ version: 8
20
+
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: '20'
24
+ registry-url: 'https://registry.npmjs.org'
25
+ always-auth: true
26
+ env:
27
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
28
+
29
+ - name: Install deps
30
+ run: pnpm install
31
+
32
+ - name: Build
33
+ run: pnpm build
34
+
35
+ - name: Create version and changelog
36
+ run: pnpx @changesets/cli version
37
+
38
+ - name: Publish to NPM
39
+ run: pnpx @changesets/cli publish
40
+ env:
41
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42
+
43
+ - name: Push updated versions and changelogs
44
+ uses: EndBug/add-and-commit@v9
45
+ with:
46
+ message: 'chore(release): version bump'
47
+ add: '.'
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "printWidth": 100,
5
+ "trailingComma": "all",
6
+ "arrowParens": "avoid"
7
+ }
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # sdk-js-error-handler
package/dist/index.cjs ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ApiError: () => ApiError,
24
+ ErrorHandlerPlugin: () => ErrorHandlerPlugin,
25
+ validationErrorDataSchema: () => validationErrorDataSchema
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/errors.ts
30
+ var import_axios = require("axios");
31
+ var ApiError = class extends import_axios.AxiosError {
32
+ };
33
+
34
+ // src/types.ts
35
+ var import_zod = require("zod");
36
+ var validationErrorDataSchema = import_zod.z.object({
37
+ status: import_zod.z.number(),
38
+ violations: import_zod.z.array(
39
+ import_zod.z.object({
40
+ propertyPath: import_zod.z.string(),
41
+ message: import_zod.z.string(),
42
+ code: import_zod.z.string().nullable()
43
+ })
44
+ ),
45
+ detail: import_zod.z.string(),
46
+ type: import_zod.z.string(),
47
+ title: import_zod.z.string()
48
+ });
49
+
50
+ // src/plugin.ts
51
+ var ErrorHandlerPlugin = class {
52
+ setup(client) {
53
+ client.http.interceptors.response.use(
54
+ (response) => response,
55
+ async (error) => {
56
+ if (!error.response) {
57
+ throw new ApiError();
58
+ }
59
+ if (error.response.status === 422) {
60
+ const safeParsed = validationErrorDataSchema.safeParse(error.response.data);
61
+ if (safeParsed.success) {
62
+ throw new ApiError(error.message, error.code, error.config, error.request, {
63
+ ...error.response,
64
+ data: { type: "VALIDATION_ERROR", value: safeParsed.data }
65
+ });
66
+ }
67
+ }
68
+ throw new ApiError(error.message, error.code, error.config, error.request, {
69
+ ...error.response,
70
+ data: { type: "UNKNOWN_ERROR", value: void 0 }
71
+ });
72
+ }
73
+ );
74
+ return {};
75
+ }
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ ApiError,
80
+ ErrorHandlerPlugin,
81
+ validationErrorDataSchema
82
+ });
@@ -0,0 +1,60 @@
1
+ import { AxiosError } from 'axios';
2
+ import { z } from 'zod';
3
+ import { ApiClientPlugin, ApiClient } from '@deliverart/sdk-js-core';
4
+
5
+ declare const validationErrorDataSchema: z.ZodObject<{
6
+ status: z.ZodNumber;
7
+ violations: z.ZodArray<z.ZodObject<{
8
+ propertyPath: z.ZodString;
9
+ message: z.ZodString;
10
+ code: z.ZodNullable<z.ZodString>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ code: string | null;
13
+ message: string;
14
+ propertyPath: string;
15
+ }, {
16
+ code: string | null;
17
+ message: string;
18
+ propertyPath: string;
19
+ }>, "many">;
20
+ detail: z.ZodString;
21
+ type: z.ZodString;
22
+ title: z.ZodString;
23
+ }, "strip", z.ZodTypeAny, {
24
+ status: number;
25
+ violations: {
26
+ code: string | null;
27
+ message: string;
28
+ propertyPath: string;
29
+ }[];
30
+ type: string;
31
+ detail: string;
32
+ title: string;
33
+ }, {
34
+ status: number;
35
+ violations: {
36
+ code: string | null;
37
+ message: string;
38
+ propertyPath: string;
39
+ }[];
40
+ type: string;
41
+ detail: string;
42
+ title: string;
43
+ }>;
44
+ type ValidationErrorData = z.infer<typeof validationErrorDataSchema>;
45
+
46
+ type ApiErrorData = {
47
+ type: 'VALIDATION_ERROR';
48
+ value: ValidationErrorData;
49
+ } | {
50
+ type: 'UNKNOWN_ERROR';
51
+ value: undefined;
52
+ };
53
+ declare class ApiError extends AxiosError<ApiErrorData> {
54
+ }
55
+
56
+ declare class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
57
+ setup(client: ApiClient): {};
58
+ }
59
+
60
+ export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type ValidationErrorData, validationErrorDataSchema };
@@ -0,0 +1,60 @@
1
+ import { AxiosError } from 'axios';
2
+ import { z } from 'zod';
3
+ import { ApiClientPlugin, ApiClient } from '@deliverart/sdk-js-core';
4
+
5
+ declare const validationErrorDataSchema: z.ZodObject<{
6
+ status: z.ZodNumber;
7
+ violations: z.ZodArray<z.ZodObject<{
8
+ propertyPath: z.ZodString;
9
+ message: z.ZodString;
10
+ code: z.ZodNullable<z.ZodString>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ code: string | null;
13
+ message: string;
14
+ propertyPath: string;
15
+ }, {
16
+ code: string | null;
17
+ message: string;
18
+ propertyPath: string;
19
+ }>, "many">;
20
+ detail: z.ZodString;
21
+ type: z.ZodString;
22
+ title: z.ZodString;
23
+ }, "strip", z.ZodTypeAny, {
24
+ status: number;
25
+ violations: {
26
+ code: string | null;
27
+ message: string;
28
+ propertyPath: string;
29
+ }[];
30
+ type: string;
31
+ detail: string;
32
+ title: string;
33
+ }, {
34
+ status: number;
35
+ violations: {
36
+ code: string | null;
37
+ message: string;
38
+ propertyPath: string;
39
+ }[];
40
+ type: string;
41
+ detail: string;
42
+ title: string;
43
+ }>;
44
+ type ValidationErrorData = z.infer<typeof validationErrorDataSchema>;
45
+
46
+ type ApiErrorData = {
47
+ type: 'VALIDATION_ERROR';
48
+ value: ValidationErrorData;
49
+ } | {
50
+ type: 'UNKNOWN_ERROR';
51
+ value: undefined;
52
+ };
53
+ declare class ApiError extends AxiosError<ApiErrorData> {
54
+ }
55
+
56
+ declare class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
57
+ setup(client: ApiClient): {};
58
+ }
59
+
60
+ export { ApiError, type ApiErrorData, ErrorHandlerPlugin, type ValidationErrorData, validationErrorDataSchema };
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ // src/errors.ts
2
+ import { AxiosError } from "axios";
3
+ var ApiError = class extends AxiosError {
4
+ };
5
+
6
+ // src/types.ts
7
+ import { z } from "zod";
8
+ var validationErrorDataSchema = z.object({
9
+ status: z.number(),
10
+ violations: z.array(
11
+ z.object({
12
+ propertyPath: z.string(),
13
+ message: z.string(),
14
+ code: z.string().nullable()
15
+ })
16
+ ),
17
+ detail: z.string(),
18
+ type: z.string(),
19
+ title: z.string()
20
+ });
21
+
22
+ // src/plugin.ts
23
+ var ErrorHandlerPlugin = class {
24
+ setup(client) {
25
+ client.http.interceptors.response.use(
26
+ (response) => response,
27
+ async (error) => {
28
+ if (!error.response) {
29
+ throw new ApiError();
30
+ }
31
+ if (error.response.status === 422) {
32
+ const safeParsed = validationErrorDataSchema.safeParse(error.response.data);
33
+ if (safeParsed.success) {
34
+ throw new ApiError(error.message, error.code, error.config, error.request, {
35
+ ...error.response,
36
+ data: { type: "VALIDATION_ERROR", value: safeParsed.data }
37
+ });
38
+ }
39
+ }
40
+ throw new ApiError(error.message, error.code, error.config, error.request, {
41
+ ...error.response,
42
+ data: { type: "UNKNOWN_ERROR", value: void 0 }
43
+ });
44
+ }
45
+ );
46
+ return {};
47
+ }
48
+ };
49
+ export {
50
+ ApiError,
51
+ ErrorHandlerPlugin,
52
+ validationErrorDataSchema
53
+ };
@@ -0,0 +1,37 @@
1
+ /* eslint-disable */
2
+ // eslint.config.js per @typescript-eslint v8
3
+ import js from '@eslint/js'
4
+ import prettier from 'eslint-config-prettier'
5
+ import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort'
6
+ import tsPlugin from '@typescript-eslint/eslint-plugin'
7
+ import tsParser from '@typescript-eslint/parser'
8
+
9
+ export default [
10
+ js.configs.recommended,
11
+ {
12
+ files: ['**/*.ts'],
13
+ languageOptions: {
14
+ parser: tsParser,
15
+ globals: {
16
+ process: 'readonly',
17
+ },
18
+ parserOptions: {
19
+ project: ['./tsconfig.json'],
20
+ tsconfigRootDir: process.cwd(),
21
+ sourceType: 'module',
22
+ },
23
+ },
24
+ plugins: {
25
+ '@typescript-eslint': tsPlugin,
26
+ 'simple-import-sort': simpleImportSortPlugin,
27
+ },
28
+ rules: {
29
+ 'simple-import-sort/imports': 'error',
30
+ 'simple-import-sort/exports': 'error',
31
+ '@typescript-eslint/no-unused-vars': 'warn',
32
+ },
33
+ },
34
+ prettier,
35
+ ]
36
+
37
+ export const ignores = ['dist', 'node_modules']
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@deliverart/sdk-js-error-handler",
3
+ "description": "Error handling utilities for Deliverart SDK in JavaScript",
4
+ "version": "0.0.6",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ }
13
+ },
14
+ "dependencies": {
15
+ "zod": "^3",
16
+ "axios": "1.9.0",
17
+ "@deliverart/sdk-js-core": "0.0.7"
18
+ },
19
+ "devDependencies": {
20
+ "@changesets/cli": "^2.29.4",
21
+ "@eslint/js": "9.28.0",
22
+ "@types/node": "22.15.30",
23
+ "@typescript-eslint/eslint-plugin": "8.33.1",
24
+ "@typescript-eslint/parser": "8.33.1",
25
+ "eslint": "9.28.0",
26
+ "eslint-config-prettier": "10.1.5",
27
+ "eslint-plugin-simple-import-sort": "12.1.1",
28
+ "prettier": "3.5.3",
29
+ "tsup": "8.5.0",
30
+ "typescript": "5.8.3"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup src/index.ts --dts --format esm,cjs",
37
+ "dev": "tsup src/index.ts --dts --watch",
38
+ "lint": "eslint .",
39
+ "lint:fix": "eslint . --fix",
40
+ "prettier": "prettier --check .",
41
+ "prettier:fix": "prettier --write .",
42
+ "version": "@changesets/cli version",
43
+ "release": "@changesets/cli publish"
44
+ }
45
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { AxiosError } from 'axios'
2
+
3
+ import { ValidationErrorData } from './types'
4
+
5
+ export type ApiErrorData =
6
+ | {
7
+ type: 'VALIDATION_ERROR'
8
+ value: ValidationErrorData
9
+ }
10
+ | {
11
+ type: 'UNKNOWN_ERROR'
12
+ value: undefined
13
+ }
14
+
15
+ export class ApiError extends AxiosError<ApiErrorData> {}
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './errors'
2
+ export * from './plugin'
3
+ export * from './types'
package/src/plugin.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { ApiClient, ApiClientPlugin } from '@deliverart/sdk-js-core'
2
+ import { AxiosError, AxiosResponse } from 'axios'
3
+
4
+ import { ApiError } from './errors'
5
+ import { validationErrorDataSchema } from './types'
6
+
7
+ export class ErrorHandlerPlugin implements ApiClientPlugin<{}> {
8
+ setup(client: ApiClient) {
9
+ client.http.interceptors.response.use(
10
+ (response: AxiosResponse) => response,
11
+ async (error: AxiosError) => {
12
+ if (!error.response) {
13
+ throw new ApiError()
14
+ }
15
+
16
+ if (error.response.status === 422) {
17
+ const safeParsed = validationErrorDataSchema.safeParse(error.response.data)
18
+
19
+ if (safeParsed.success) {
20
+ throw new ApiError(error.message, error.code, error.config, error.request, {
21
+ ...error.response,
22
+ data: { type: 'VALIDATION_ERROR', value: safeParsed.data },
23
+ })
24
+ }
25
+ }
26
+
27
+ throw new ApiError(error.message, error.code, error.config, error.request, {
28
+ ...error.response,
29
+ data: { type: 'UNKNOWN_ERROR', value: undefined },
30
+ })
31
+ },
32
+ )
33
+
34
+ return {}
35
+ }
36
+ }
package/src/types.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod'
2
+
3
+ export const validationErrorDataSchema = z.object({
4
+ status: z.number(),
5
+ violations: z.array(
6
+ z.object({
7
+ propertyPath: z.string(),
8
+ message: z.string(),
9
+ code: z.string().nullable(),
10
+ }),
11
+ ),
12
+ detail: z.string(),
13
+ type: z.string(),
14
+ title: z.string(),
15
+ })
16
+ export type ValidationErrorData = z.infer<typeof validationErrorDataSchema>
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node",
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "strict": true,
9
+ "skipLibCheck": true,
10
+ "outDir": "dist",
11
+ "declaration": true,
12
+ "declarationMap": true
13
+ },
14
+ "include": ["src"]
15
+ }