@neus/sdk 1.1.0 → 1.1.1

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/errors.js CHANGED
@@ -1,189 +1,154 @@
1
- export class SDKError extends Error {
2
- constructor(message, code = 'SDK_ERROR', details = {}) {
3
- super(message);
4
- this.name = 'SDKError';
5
- this.code = code;
6
- this.details = details;
7
- this.timestamp = Date.now();
8
-
9
- if (Error.captureStackTrace) {
10
- Error.captureStackTrace(this, SDKError);
11
- }
12
- }
13
-
14
- toJSON() {
15
- return {
16
- name: this.name,
17
- message: this.message,
18
- code: this.code,
19
- details: this.details,
20
- timestamp: this.timestamp
21
- };
22
- }
23
- }
24
-
25
- export class ApiError extends SDKError {
26
- constructor(message, statusCode = 500, code = 'API_ERROR', response = null) {
27
- super(message, code);
28
- this.name = 'ApiError';
29
- this.statusCode = statusCode;
30
- this.response = response;
31
-
32
- this.isClientError = statusCode >= 400 && statusCode < 500;
33
- this.isServerError = statusCode >= 500;
34
- this.isRetryable = this.isServerError || statusCode === 429; // Server errors or rate limit
35
- }
36
-
37
- static fromResponse(response, responseData) {
38
- const statusCode = response.status;
39
- const message = responseData?.error?.message ||
40
- responseData?.message ||
41
- `API request failed with status ${statusCode}`;
42
- const code = responseData?.error?.code || 'API_ERROR';
43
-
44
- return new ApiError(message, statusCode, code, responseData);
45
- }
46
-
47
- toJSON() {
48
- return {
49
- ...super.toJSON(),
50
- statusCode: this.statusCode,
51
- isClientError: this.isClientError,
52
- isServerError: this.isServerError,
53
- isRetryable: this.isRetryable
54
- };
55
- }
56
- }
57
-
58
- export class ValidationError extends SDKError {
59
- constructor(message, field = null, value = null) {
60
- super(message, 'VALIDATION_ERROR');
61
- this.name = 'ValidationError';
62
- this.field = field;
63
- this.value = value;
64
- this.isRetryable = false; // Validation errors are not retryable
65
- }
66
-
67
- toJSON() {
68
- return {
69
- ...super.toJSON(),
70
- field: this.field,
71
- value: this.value,
72
- isRetryable: this.isRetryable
73
- };
74
- }
75
- }
76
-
77
- export class NetworkError extends SDKError {
78
- constructor(message, code = 'NETWORK_ERROR', originalError = null) {
79
- super(message, code);
80
- this.name = 'NetworkError';
81
- this.originalError = originalError;
82
- this.isRetryable = true; // Network errors are retryable
83
- }
84
-
85
- static isNetworkError(error) {
86
- return error instanceof NetworkError ||
87
- error.name === 'TypeError' && error.message.includes('fetch') ||
88
- error.name === 'AbortError' ||
89
- error.code === 'ENOTFOUND' ||
90
- error.code === 'ECONNREFUSED' ||
91
- error.code === 'ETIMEDOUT';
92
- }
93
-
94
- toJSON() {
95
- return {
96
- ...super.toJSON(),
97
- isRetryable: this.isRetryable,
98
- originalError: this.originalError ? {
99
- name: this.originalError.name,
100
- message: this.originalError.message,
101
- code: this.originalError.code
102
- } : null
103
- };
104
- }
105
- }
106
-
107
- export class ConfigurationError extends SDKError {
108
- constructor(message, configKey = null) {
109
- super(message, 'CONFIGURATION_ERROR');
110
- this.name = 'ConfigurationError';
111
- this.configKey = configKey;
112
- this.isRetryable = false; // Config errors require user intervention
113
- }
114
-
115
- toJSON() {
116
- return {
117
- ...super.toJSON(),
118
- configKey: this.configKey,
119
- isRetryable: this.isRetryable
120
- };
121
- }
122
- }
123
-
124
- export class VerificationError extends SDKError {
125
- constructor(message, verifierId = null, code = 'VERIFICATION_ERROR') {
126
- super(message, code);
127
- this.name = 'VerificationError';
128
- this.verifierId = verifierId;
129
- this.isRetryable = true; // Some verification errors might be retryable
130
- }
131
-
132
- toJSON() {
133
- return {
134
- ...super.toJSON(),
135
- verifierId: this.verifierId,
136
- isRetryable: this.isRetryable
137
- };
138
- }
139
- }
140
-
141
- export class AuthenticationError extends SDKError {
142
- constructor(message, code = 'AUTHENTICATION_ERROR') {
143
- super(message, code);
144
- this.name = 'AuthenticationError';
145
- this.isRetryable = false; // Auth errors require user intervention
146
- }
147
-
148
- toJSON() {
149
- return {
150
- ...super.toJSON(),
151
- isRetryable: this.isRetryable
152
- };
153
- }
154
- }
155
-
156
- export function createErrorFromGeneric(error, context = {}) {
157
- if (error instanceof SDKError) {
158
- return error;
159
- }
160
-
161
- if (NetworkError.isNetworkError(error)) {
162
- return new NetworkError(
163
- error.message || 'Network error occurred',
164
- error.code || 'NETWORK_ERROR',
165
- error
166
- );
167
- }
168
-
169
- if (error.name === 'AbortError' || error.message.includes('timeout')) {
170
- return new NetworkError('Request timeout', 'TIMEOUT', error);
171
- }
172
-
173
- return new SDKError(
174
- error.message || 'Unknown error occurred',
175
- error.code || 'UNKNOWN_ERROR',
176
- { originalError: error, context }
177
- );
178
- }
179
-
180
- export default {
181
- SDKError,
182
- ApiError,
183
- ValidationError,
184
- NetworkError,
185
- ConfigurationError,
186
- VerificationError,
187
- AuthenticationError,
188
- createErrorFromGeneric
189
- };
1
+ export class SDKError extends Error {
2
+ constructor(message, code = 'SDK_ERROR', details = {}) {
3
+ super(message);
4
+ this.name = 'SDKError';
5
+ this.code = code;
6
+ this.details = details;
7
+ this.timestamp = Date.now();
8
+
9
+ if (Error.captureStackTrace) {
10
+ Error.captureStackTrace(this, SDKError);
11
+ }
12
+ }
13
+
14
+ toJSON() {
15
+ return {
16
+ name: this.name,
17
+ message: this.message,
18
+ code: this.code,
19
+ details: this.details,
20
+ timestamp: this.timestamp
21
+ };
22
+ }
23
+ }
24
+
25
+ export class ApiError extends SDKError {
26
+ constructor(message, statusCode = 500, code = 'API_ERROR', response = null) {
27
+ super(message, code);
28
+ this.name = 'ApiError';
29
+ this.statusCode = statusCode;
30
+ this.response = response;
31
+
32
+ this.isClientError = statusCode >= 400 && statusCode < 500;
33
+ this.isServerError = statusCode >= 500;
34
+ this.isRetryable = this.isServerError || statusCode === 429; // Server errors or rate limit
35
+ }
36
+
37
+ static fromResponse(response, responseData) {
38
+ const statusCode = response.status;
39
+ const message = responseData?.error?.message ||
40
+ responseData?.message ||
41
+ `API request failed with status ${statusCode}`;
42
+ const code = responseData?.error?.code || 'API_ERROR';
43
+
44
+ return new ApiError(message, statusCode, code, responseData);
45
+ }
46
+
47
+ toJSON() {
48
+ return {
49
+ ...super.toJSON(),
50
+ statusCode: this.statusCode,
51
+ isClientError: this.isClientError,
52
+ isServerError: this.isServerError,
53
+ isRetryable: this.isRetryable
54
+ };
55
+ }
56
+ }
57
+
58
+ export class ValidationError extends SDKError {
59
+ constructor(message, field = null, value = null) {
60
+ super(message, 'VALIDATION_ERROR');
61
+ this.name = 'ValidationError';
62
+ this.field = field;
63
+ this.value = value;
64
+ this.isRetryable = false; // Validation errors are not retryable
65
+ }
66
+
67
+ toJSON() {
68
+ return {
69
+ ...super.toJSON(),
70
+ field: this.field,
71
+ value: this.value,
72
+ isRetryable: this.isRetryable
73
+ };
74
+ }
75
+ }
76
+
77
+ export class NetworkError extends SDKError {
78
+ constructor(message, code = 'NETWORK_ERROR', originalError = null) {
79
+ super(message, code);
80
+ this.name = 'NetworkError';
81
+ this.originalError = originalError;
82
+ this.isRetryable = true; // Network errors are retryable
83
+ }
84
+
85
+ static isNetworkError(error) {
86
+ return error instanceof NetworkError ||
87
+ error.name === 'TypeError' && error.message.includes('fetch') ||
88
+ error.name === 'AbortError' ||
89
+ error.code === 'ENOTFOUND' ||
90
+ error.code === 'ECONNREFUSED' ||
91
+ error.code === 'ETIMEDOUT';
92
+ }
93
+
94
+ toJSON() {
95
+ return {
96
+ ...super.toJSON(),
97
+ isRetryable: this.isRetryable,
98
+ originalError: this.originalError ? {
99
+ name: this.originalError.name,
100
+ message: this.originalError.message,
101
+ code: this.originalError.code
102
+ } : null
103
+ };
104
+ }
105
+ }
106
+
107
+ export class ConfigurationError extends SDKError {
108
+ constructor(message, configKey = null) {
109
+ super(message, 'CONFIGURATION_ERROR');
110
+ this.name = 'ConfigurationError';
111
+ this.configKey = configKey;
112
+ this.isRetryable = false; // Config errors require user intervention
113
+ }
114
+
115
+ toJSON() {
116
+ return {
117
+ ...super.toJSON(),
118
+ configKey: this.configKey,
119
+ isRetryable: this.isRetryable
120
+ };
121
+ }
122
+ }
123
+
124
+ export class VerificationError extends SDKError {
125
+ constructor(message, verifierId = null, code = 'VERIFICATION_ERROR') {
126
+ super(message, code);
127
+ this.name = 'VerificationError';
128
+ this.verifierId = verifierId;
129
+ this.isRetryable = true; // Some verification errors might be retryable
130
+ }
131
+
132
+ toJSON() {
133
+ return {
134
+ ...super.toJSON(),
135
+ verifierId: this.verifierId,
136
+ isRetryable: this.isRetryable
137
+ };
138
+ }
139
+ }
140
+
141
+ export class AuthenticationError extends SDKError {
142
+ constructor(message, code = 'AUTHENTICATION_ERROR') {
143
+ super(message, code);
144
+ this.name = 'AuthenticationError';
145
+ this.isRetryable = false; // Auth errors require user intervention
146
+ }
147
+
148
+ toJSON() {
149
+ return {
150
+ ...super.toJSON(),
151
+ isRetryable: this.isRetryable
152
+ };
153
+ }
154
+ }
package/gates.js CHANGED
@@ -51,23 +51,3 @@ export function combineGates(...gates) {
51
51
 
52
52
  return combined;
53
53
  }
54
-
55
- export default {
56
- HOUR,
57
- DAY,
58
- WEEK,
59
- MONTH,
60
- YEAR,
61
- GATE_NFT_HOLDER,
62
- GATE_TOKEN_HOLDER,
63
- GATE_CONTRACT_ADMIN,
64
- GATE_DOMAIN_OWNER,
65
- GATE_LINKED_WALLETS,
66
- GATE_AGENT_IDENTITY,
67
- GATE_AGENT_DELEGATION,
68
- GATE_CONTENT_MODERATION,
69
- GATE_WALLET_RISK,
70
- GATE_PSEUDONYM,
71
- createGate,
72
- combineGates
73
- };
package/index.js CHANGED
@@ -55,6 +55,8 @@ export {
55
55
  combineGates
56
56
  } from './gates.js';
57
57
 
58
+ export { fetchSponsorGrant } from './sponsor.js';
59
+
58
60
  export {
59
61
  SDKError,
60
62
  ApiError,
package/package.json CHANGED
@@ -1,143 +1,142 @@
1
- {
2
- "name": "@neus/sdk",
3
- "version": "1.1.0",
4
- "description": "NEUS makes trust portable across the internet — so people, apps, and AI agents can prove what is real before access, payout, or execution.",
5
- "bin": {
6
- "neus": "cli/neus.mjs"
7
- },
8
- "main": "index.js",
9
- "type": "module",
10
- "types": "types.d.ts",
11
- "exports": {
12
- ".": {
13
- "types": "./types.d.ts",
14
- "import": "./index.js",
15
- "require": "./cjs/index.cjs"
16
- },
17
- "./client": {
18
- "types": "./types.d.ts",
19
- "import": "./client.js",
20
- "require": "./cjs/client.cjs"
21
- },
22
- "./utils": {
23
- "import": "./utils.js",
24
- "require": "./cjs/utils.cjs"
25
- },
26
- "./errors": {
27
- "import": "./errors.js",
28
- "require": "./cjs/errors.cjs"
29
- },
30
- "./gates": {
31
- "import": "./gates.js",
32
- "require": "./cjs/gates.cjs"
33
- },
34
- "./widgets": {
35
- "types": "./types.d.ts",
36
- "import": "./widgets/index.js",
37
- "require": "./widgets.cjs"
38
- },
39
- "./widgets/verify-gate": {
40
- "types": "./types.d.ts",
41
- "import": "./widgets/verify-gate/index.js",
42
- "require": "./widgets.cjs"
43
- }
44
- },
45
- "sideEffects": false,
46
- "scripts": {
47
- "test": "npm run build:cjs && vitest run",
48
- "test:coverage": "vitest run --coverage",
49
- "lint": "eslint . --ignore-pattern widgets/verify-gate/dist/**",
50
- "format": "prettier --write \"**/*.js\"",
51
- "build": "npm run build:widgets && npm run build:cjs",
52
- "build:widgets": "npx esbuild widgets/verify-gate/VerifyGate.jsx widgets/verify-gate/ProofBadge.jsx --bundle --platform=browser --format=esm --outdir=widgets/verify-gate/dist --jsx=automatic --legal-comments=none --loader:.svg=dataurl --external:react --external:react-dom --external:react/jsx-runtime --external:@neus/sdk/client",
53
- "build:cjs": "npx esbuild index.js client.js utils.js errors.js gates.js --bundle --platform=node --format=cjs --outdir=cjs --out-extension:.js=.cjs --legal-comments=none --external:ethers --external:@zkpassport/sdk --external:react --external:react-dom --external:react/jsx-runtime",
54
- "prepack": "npm run build",
55
- "prepublishOnly": "npm run lint && npm test && npm run build"
56
- },
57
- "keywords": [
58
- "neus",
59
- "verification",
60
- "cryptographic-proofs",
61
- "identity",
62
- "authentication",
63
- "blockchain",
64
- "cross-chain",
65
- "web3",
66
- "passwordless",
67
- "universal-protocol",
68
- "proof",
69
- "ownership",
70
- "sdk",
71
- "mcp",
72
- "model-context-protocol",
73
- "oauth"
74
- ],
75
- "author": "NEUS Network",
76
- "license": "Apache-2.0",
77
- "repository": {
78
- "type": "git",
79
- "url": "git+https://github.com/neus/network.git",
80
- "directory": "sdk"
81
- },
82
- "bugs": {
83
- "url": "https://github.com/neus/network/issues"
84
- },
85
- "homepage": "https://neus.network",
86
- "publishConfig": {
87
- "access": "public",
88
- "registry": "https://registry.npmjs.org"
89
- },
90
- "engines": {
91
- "node": ">=20.0.0"
92
- },
93
- "peerDependencies": {
94
- "ethers": "^6.0.0",
95
- "react": ">=17.0.0",
96
- "react-dom": ">=17.0.0"
97
- },
98
- "peerDependenciesMeta": {
99
- "@zkpassport/sdk": {
100
- "optional": true
101
- },
102
- "react": {
103
- "optional": true
104
- },
105
- "react-dom": {
106
- "optional": true
107
- }
108
- },
109
- "optionalDependencies": {
110
- "@zkpassport/sdk": "^0.14.0"
111
- },
112
- "dependencies": {
113
- "bs58": "^6.0.0"
114
- },
115
- "devDependencies": {
116
- "@vitest/coverage-v8": "^4.1.3",
117
- "esbuild": "^0.28.0",
118
- "eslint": "^8.56.0",
119
- "eslint-plugin-react": "^7.37.2",
120
- "prettier": "^3.2.0",
121
- "vitest": "^4.1.3"
122
- },
123
- "files": [
124
- "cli/neus.mjs",
125
- "index.js",
126
- "client.js",
127
- "utils.js",
128
- "errors.js",
129
- "gates.js",
130
- "cjs/**",
131
- "widgets.cjs",
132
- "types.d.ts",
133
- "README.md",
134
- "CHANGELOG.md",
135
- "SECURITY.md",
136
- "LICENSE",
137
- "neus-logo.svg",
138
- "widgets/index.js",
139
- "widgets/verify-gate/index.js",
140
- "widgets/verify-gate/dist/VerifyGate.js",
141
- "widgets/verify-gate/dist/ProofBadge.js"
142
- ]
143
- }
1
+ {
2
+ "name": "@neus/sdk",
3
+ "version": "1.1.1",
4
+ "description": "NEUS makes trust portable across the internet — so people, apps, and AI agents can prove what is real before access, payout, or execution.",
5
+ "bin": {
6
+ "neus": "cli/neus.mjs"
7
+ },
8
+ "main": "index.js",
9
+ "type": "module",
10
+ "types": "types.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./types.d.ts",
14
+ "import": "./index.js",
15
+ "require": "./cjs/index.cjs"
16
+ },
17
+ "./client": {
18
+ "types": "./types.d.ts",
19
+ "import": "./client.js",
20
+ "require": "./cjs/client.cjs"
21
+ },
22
+ "./utils": {
23
+ "import": "./utils.js",
24
+ "require": "./cjs/utils.cjs"
25
+ },
26
+ "./errors": {
27
+ "import": "./errors.js",
28
+ "require": "./cjs/errors.cjs"
29
+ },
30
+ "./gates": {
31
+ "import": "./gates.js",
32
+ "require": "./cjs/gates.cjs"
33
+ },
34
+ "./widgets": {
35
+ "types": "./types.d.ts",
36
+ "import": "./widgets/index.js",
37
+ "require": "./widgets.cjs"
38
+ },
39
+ "./widgets/verify-gate": {
40
+ "types": "./types.d.ts",
41
+ "import": "./widgets/verify-gate/index.js",
42
+ "require": "./widgets.cjs"
43
+ }
44
+ },
45
+ "sideEffects": false,
46
+ "scripts": {
47
+ "test": "npm run build:cjs && vitest run",
48
+ "test:coverage": "vitest run --coverage",
49
+ "lint": "eslint . --ignore-pattern widgets/verify-gate/dist/**",
50
+ "format": "prettier --write \"**/*.js\"",
51
+ "build": "npm run build:widgets && npm run build:cjs",
52
+ "build:widgets": "npx esbuild widgets/verify-gate/VerifyGate.jsx widgets/verify-gate/ProofBadge.jsx --bundle --platform=browser --format=esm --outdir=widgets/verify-gate/dist --jsx=automatic --legal-comments=none --loader:.svg=dataurl --external:react --external:react-dom --external:react/jsx-runtime --external:@neus/sdk/client",
53
+ "build:cjs": "npx esbuild index.js client.js utils.js errors.js gates.js --bundle --platform=node --format=cjs --outdir=cjs --out-extension:.js=.cjs --legal-comments=none --external:ethers --external:@zkpassport/sdk --external:react --external:react-dom --external:react/jsx-runtime",
54
+ "prepack": "npm run build",
55
+ "prepublishOnly": "npm run lint && npm test && npm run build"
56
+ },
57
+ "keywords": [
58
+ "neus",
59
+ "verification",
60
+ "cryptographic-proofs",
61
+ "identity",
62
+ "authentication",
63
+ "blockchain",
64
+ "cross-chain",
65
+ "web3",
66
+ "passwordless",
67
+ "universal-protocol",
68
+ "proof",
69
+ "ownership",
70
+ "sdk",
71
+ "mcp",
72
+ "model-context-protocol",
73
+ "oauth"
74
+ ],
75
+ "author": "NEUS Network",
76
+ "license": "Apache-2.0",
77
+ "repository": {
78
+ "type": "git",
79
+ "url": "git+https://github.com/neus/network.git",
80
+ "directory": "sdk"
81
+ },
82
+ "bugs": {
83
+ "url": "https://github.com/neus/network/issues"
84
+ },
85
+ "homepage": "https://neus.network",
86
+ "publishConfig": {
87
+ "access": "public",
88
+ "registry": "https://registry.npmjs.org"
89
+ },
90
+ "engines": {
91
+ "node": ">=20.0.0"
92
+ },
93
+ "peerDependencies": {
94
+ "ethers": "^6.0.0",
95
+ "react": ">=17.0.0",
96
+ "react-dom": ">=17.0.0"
97
+ },
98
+ "peerDependenciesMeta": {
99
+ "@zkpassport/sdk": {
100
+ "optional": true
101
+ },
102
+ "react": {
103
+ "optional": true
104
+ },
105
+ "react-dom": {
106
+ "optional": true
107
+ }
108
+ },
109
+ "optionalDependencies": {
110
+ "@zkpassport/sdk": "^0.14.0"
111
+ },
112
+ "dependencies": {
113
+ "bs58": "^6.0.0"
114
+ },
115
+ "devDependencies": {
116
+ "@vitest/coverage-v8": "^4.1.3",
117
+ "esbuild": "^0.28.0",
118
+ "eslint": "^8.56.0",
119
+ "eslint-plugin-react": "^7.37.2",
120
+ "prettier": "^3.2.0",
121
+ "vitest": "^4.1.3"
122
+ },
123
+ "files": [
124
+ "cli/neus.mjs",
125
+ "index.js",
126
+ "client.js",
127
+ "utils.js",
128
+ "errors.js",
129
+ "gates.js",
130
+ "sponsor.js",
131
+ "cjs/**",
132
+ "widgets.cjs",
133
+ "types.d.ts",
134
+ "README.md",
135
+ "SECURITY.md",
136
+ "LICENSE",
137
+ "widgets/index.js",
138
+ "widgets/verify-gate/index.js",
139
+ "widgets/verify-gate/dist/VerifyGate.js",
140
+ "widgets/verify-gate/dist/ProofBadge.js"
141
+ ]
142
+ }