@neus/sdk 1.0.0 → 1.0.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/cjs/errors.cjs ADDED
@@ -0,0 +1,202 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // errors.js
20
+ var errors_exports = {};
21
+ __export(errors_exports, {
22
+ ApiError: () => ApiError,
23
+ AuthenticationError: () => AuthenticationError,
24
+ ConfigurationError: () => ConfigurationError,
25
+ NetworkError: () => NetworkError,
26
+ SDKError: () => SDKError,
27
+ ValidationError: () => ValidationError,
28
+ VerificationError: () => VerificationError,
29
+ createErrorFromGeneric: () => createErrorFromGeneric,
30
+ default: () => errors_default
31
+ });
32
+ module.exports = __toCommonJS(errors_exports);
33
+ var SDKError = class _SDKError extends Error {
34
+ constructor(message, code = "SDK_ERROR", details = {}) {
35
+ super(message);
36
+ this.name = "SDKError";
37
+ this.code = code;
38
+ this.details = details;
39
+ this.timestamp = Date.now();
40
+ if (Error.captureStackTrace) {
41
+ Error.captureStackTrace(this, _SDKError);
42
+ }
43
+ }
44
+ toJSON() {
45
+ return {
46
+ name: this.name,
47
+ message: this.message,
48
+ code: this.code,
49
+ details: this.details,
50
+ timestamp: this.timestamp
51
+ };
52
+ }
53
+ };
54
+ var ApiError = class _ApiError extends SDKError {
55
+ constructor(message, statusCode = 500, code = "API_ERROR", response = null) {
56
+ super(message, code);
57
+ this.name = "ApiError";
58
+ this.statusCode = statusCode;
59
+ this.response = response;
60
+ this.isClientError = statusCode >= 400 && statusCode < 500;
61
+ this.isServerError = statusCode >= 500;
62
+ this.isRetryable = this.isServerError || statusCode === 429;
63
+ }
64
+ static fromResponse(response, responseData) {
65
+ const statusCode = response.status;
66
+ const message = responseData?.error?.message || responseData?.message || `API request failed with status ${statusCode}`;
67
+ const code = responseData?.error?.code || "API_ERROR";
68
+ return new _ApiError(message, statusCode, code, responseData);
69
+ }
70
+ toJSON() {
71
+ return {
72
+ ...super.toJSON(),
73
+ statusCode: this.statusCode,
74
+ isClientError: this.isClientError,
75
+ isServerError: this.isServerError,
76
+ isRetryable: this.isRetryable
77
+ };
78
+ }
79
+ };
80
+ var ValidationError = class extends SDKError {
81
+ constructor(message, field = null, value = null) {
82
+ super(message, "VALIDATION_ERROR");
83
+ this.name = "ValidationError";
84
+ this.field = field;
85
+ this.value = value;
86
+ this.isRetryable = false;
87
+ }
88
+ toJSON() {
89
+ return {
90
+ ...super.toJSON(),
91
+ field: this.field,
92
+ value: this.value,
93
+ isRetryable: this.isRetryable
94
+ };
95
+ }
96
+ };
97
+ var NetworkError = class _NetworkError extends SDKError {
98
+ constructor(message, code = "NETWORK_ERROR", originalError = null) {
99
+ super(message, code);
100
+ this.name = "NetworkError";
101
+ this.originalError = originalError;
102
+ this.isRetryable = true;
103
+ }
104
+ static isNetworkError(error) {
105
+ return error instanceof _NetworkError || error.name === "TypeError" && error.message.includes("fetch") || error.name === "AbortError" || error.code === "ENOTFOUND" || error.code === "ECONNREFUSED" || error.code === "ETIMEDOUT";
106
+ }
107
+ toJSON() {
108
+ return {
109
+ ...super.toJSON(),
110
+ isRetryable: this.isRetryable,
111
+ originalError: this.originalError ? {
112
+ name: this.originalError.name,
113
+ message: this.originalError.message,
114
+ code: this.originalError.code
115
+ } : null
116
+ };
117
+ }
118
+ };
119
+ var ConfigurationError = class extends SDKError {
120
+ constructor(message, configKey = null) {
121
+ super(message, "CONFIGURATION_ERROR");
122
+ this.name = "ConfigurationError";
123
+ this.configKey = configKey;
124
+ this.isRetryable = false;
125
+ }
126
+ toJSON() {
127
+ return {
128
+ ...super.toJSON(),
129
+ configKey: this.configKey,
130
+ isRetryable: this.isRetryable
131
+ };
132
+ }
133
+ };
134
+ var VerificationError = class extends SDKError {
135
+ constructor(message, verifierId = null, code = "VERIFICATION_ERROR") {
136
+ super(message, code);
137
+ this.name = "VerificationError";
138
+ this.verifierId = verifierId;
139
+ this.isRetryable = true;
140
+ }
141
+ toJSON() {
142
+ return {
143
+ ...super.toJSON(),
144
+ verifierId: this.verifierId,
145
+ isRetryable: this.isRetryable
146
+ };
147
+ }
148
+ };
149
+ var AuthenticationError = class extends SDKError {
150
+ constructor(message, code = "AUTHENTICATION_ERROR") {
151
+ super(message, code);
152
+ this.name = "AuthenticationError";
153
+ this.isRetryable = false;
154
+ }
155
+ toJSON() {
156
+ return {
157
+ ...super.toJSON(),
158
+ isRetryable: this.isRetryable
159
+ };
160
+ }
161
+ };
162
+ function createErrorFromGeneric(error, context = {}) {
163
+ if (error instanceof SDKError) {
164
+ return error;
165
+ }
166
+ if (NetworkError.isNetworkError(error)) {
167
+ return new NetworkError(
168
+ error.message || "Network error occurred",
169
+ error.code || "NETWORK_ERROR",
170
+ error
171
+ );
172
+ }
173
+ if (error.name === "AbortError" || error.message.includes("timeout")) {
174
+ return new NetworkError("Request timeout", "TIMEOUT", error);
175
+ }
176
+ return new SDKError(
177
+ error.message || "Unknown error occurred",
178
+ error.code || "UNKNOWN_ERROR",
179
+ { originalError: error, context }
180
+ );
181
+ }
182
+ var errors_default = {
183
+ SDKError,
184
+ ApiError,
185
+ ValidationError,
186
+ NetworkError,
187
+ ConfigurationError,
188
+ VerificationError,
189
+ AuthenticationError,
190
+ createErrorFromGeneric
191
+ };
192
+ // Annotate the CommonJS export names for ESM import in node:
193
+ 0 && (module.exports = {
194
+ ApiError,
195
+ AuthenticationError,
196
+ ConfigurationError,
197
+ NetworkError,
198
+ SDKError,
199
+ ValidationError,
200
+ VerificationError,
201
+ createErrorFromGeneric
202
+ });
package/cjs/gates.cjs ADDED
@@ -0,0 +1,140 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // gates.js
20
+ var gates_exports = {};
21
+ __export(gates_exports, {
22
+ DAY: () => DAY,
23
+ GATE_AGENT_DELEGATION: () => GATE_AGENT_DELEGATION,
24
+ GATE_AGENT_IDENTITY: () => GATE_AGENT_IDENTITY,
25
+ GATE_CONTENT_MODERATION: () => GATE_CONTENT_MODERATION,
26
+ GATE_CONTRACT_ADMIN: () => GATE_CONTRACT_ADMIN,
27
+ GATE_DOMAIN_OWNER: () => GATE_DOMAIN_OWNER,
28
+ GATE_LINKED_WALLETS: () => GATE_LINKED_WALLETS,
29
+ GATE_NFT_HOLDER: () => GATE_NFT_HOLDER,
30
+ GATE_PSEUDONYM: () => GATE_PSEUDONYM,
31
+ GATE_TOKEN_HOLDER: () => GATE_TOKEN_HOLDER,
32
+ GATE_WALLET_RISK: () => GATE_WALLET_RISK,
33
+ HOUR: () => HOUR,
34
+ MONTH: () => MONTH,
35
+ WEEK: () => WEEK,
36
+ YEAR: () => YEAR,
37
+ combineGates: () => combineGates,
38
+ createGate: () => createGate,
39
+ default: () => gates_default
40
+ });
41
+ module.exports = __toCommonJS(gates_exports);
42
+ var HOUR = 60 * 60 * 1e3;
43
+ var DAY = 24 * HOUR;
44
+ var WEEK = 7 * DAY;
45
+ var MONTH = 30 * DAY;
46
+ var YEAR = 365 * DAY;
47
+ var GATE_NFT_HOLDER = [
48
+ { verifierId: "nft-ownership" }
49
+ ];
50
+ var GATE_TOKEN_HOLDER = [
51
+ { verifierId: "token-holding" }
52
+ ];
53
+ var GATE_CONTRACT_ADMIN = [
54
+ { verifierId: "contract-ownership", maxAgeMs: HOUR }
55
+ ];
56
+ var GATE_DOMAIN_OWNER = [
57
+ { verifierId: "ownership-dns-txt" }
58
+ ];
59
+ var GATE_LINKED_WALLETS = [
60
+ { verifierId: "wallet-link" }
61
+ ];
62
+ var GATE_AGENT_IDENTITY = [
63
+ { verifierId: "agent-identity" }
64
+ ];
65
+ var GATE_AGENT_DELEGATION = [
66
+ { verifierId: "agent-delegation", maxAgeMs: 7 * DAY }
67
+ ];
68
+ var GATE_CONTENT_MODERATION = [
69
+ { verifierId: "ai-content-moderation" }
70
+ ];
71
+ var GATE_WALLET_RISK = [
72
+ { verifierId: "wallet-risk" }
73
+ ];
74
+ var GATE_PSEUDONYM = [
75
+ { verifierId: "ownership-pseudonym" }
76
+ ];
77
+ function createGate(requirements) {
78
+ return requirements.map((req) => {
79
+ if (typeof req === "string") {
80
+ return { verifierId: req };
81
+ }
82
+ return req;
83
+ });
84
+ }
85
+ function combineGates(...gates) {
86
+ const combined = [];
87
+ const seen = /* @__PURE__ */ new Set();
88
+ for (const gate of gates) {
89
+ for (const req of gate) {
90
+ const key = req.verifierId + JSON.stringify(req.match || {});
91
+ if (!seen.has(key)) {
92
+ seen.add(key);
93
+ combined.push(req);
94
+ }
95
+ }
96
+ }
97
+ return combined;
98
+ }
99
+ var gates_default = {
100
+ // Time constants
101
+ HOUR,
102
+ DAY,
103
+ WEEK,
104
+ MONTH,
105
+ YEAR,
106
+ // Recipe gates
107
+ GATE_NFT_HOLDER,
108
+ GATE_TOKEN_HOLDER,
109
+ GATE_CONTRACT_ADMIN,
110
+ GATE_DOMAIN_OWNER,
111
+ GATE_LINKED_WALLETS,
112
+ GATE_AGENT_IDENTITY,
113
+ GATE_AGENT_DELEGATION,
114
+ GATE_CONTENT_MODERATION,
115
+ GATE_WALLET_RISK,
116
+ GATE_PSEUDONYM,
117
+ // Helpers
118
+ createGate,
119
+ combineGates
120
+ };
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ DAY,
124
+ GATE_AGENT_DELEGATION,
125
+ GATE_AGENT_IDENTITY,
126
+ GATE_CONTENT_MODERATION,
127
+ GATE_CONTRACT_ADMIN,
128
+ GATE_DOMAIN_OWNER,
129
+ GATE_LINKED_WALLETS,
130
+ GATE_NFT_HOLDER,
131
+ GATE_PSEUDONYM,
132
+ GATE_TOKEN_HOLDER,
133
+ GATE_WALLET_RISK,
134
+ HOUR,
135
+ MONTH,
136
+ WEEK,
137
+ YEAR,
138
+ combineGates,
139
+ createGate
140
+ });