@x402jobs/sdk 0.1.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/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/index.d.mts +106 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +238 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +208 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 x402jobs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @x402jobs/sdk
|
|
2
|
+
|
|
3
|
+
The official SDK for [x402.jobs](https://x402.jobs) — trust, discovery, and resource management for the x402 ecosystem.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @x402jobs/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Check if a resource is reliable
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { check } from '@x402jobs/sdk'
|
|
17
|
+
|
|
18
|
+
const score = await check('https://api.example.com/resource')
|
|
19
|
+
// {
|
|
20
|
+
// url: "https://api.example.com/resource",
|
|
21
|
+
// success_rate: 0.94,
|
|
22
|
+
// calls: 1240,
|
|
23
|
+
// value_processed: "$12.4k",
|
|
24
|
+
// last_called: "2m ago"
|
|
25
|
+
// }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Browse top resources
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { check } from '@x402jobs/sdk'
|
|
32
|
+
|
|
33
|
+
const top = await check.top({ limit: 20 })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Search resources
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
import { resources } from '@x402jobs/sdk'
|
|
40
|
+
|
|
41
|
+
const results = await resources.search({
|
|
42
|
+
query: 'image generation',
|
|
43
|
+
minSuccessRate: 0.9
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Register your resource
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
import { resources, configure } from '@x402jobs/sdk'
|
|
51
|
+
|
|
52
|
+
configure({ apiKey: 'your-api-key' })
|
|
53
|
+
|
|
54
|
+
await resources.register({
|
|
55
|
+
url: 'https://my-api.com/endpoint',
|
|
56
|
+
name: 'My API',
|
|
57
|
+
price: '$0.01'
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Why?
|
|
62
|
+
|
|
63
|
+
You can index x402 endpoints all day. Doesn't mean they work.
|
|
64
|
+
|
|
65
|
+
x402jobs gives you reliability scores backed by real paid usage — not synthetic pings.
|
|
66
|
+
|
|
67
|
+
We ran the transactions. We paid the fees. Now you get the data.
|
|
68
|
+
|
|
69
|
+
## API Reference
|
|
70
|
+
|
|
71
|
+
### Trust / Verification
|
|
72
|
+
|
|
73
|
+
| Function | Description |
|
|
74
|
+
|----------|-------------|
|
|
75
|
+
| `check(url)` | Get reliability score for a resource |
|
|
76
|
+
| `check.many(urls)` | Check multiple resources |
|
|
77
|
+
| `check.exists(url)` | Check if resource is indexed |
|
|
78
|
+
| `check.top(options)` | Get top-ranked resources |
|
|
79
|
+
|
|
80
|
+
### Resources
|
|
81
|
+
|
|
82
|
+
| Function | Description |
|
|
83
|
+
|----------|-------------|
|
|
84
|
+
| `resources.list()` | Get all resources |
|
|
85
|
+
| `resources.get(url)` | Get single resource |
|
|
86
|
+
| `resources.search(options)` | Search resources |
|
|
87
|
+
| `resources.register(input)` | Register new resource |
|
|
88
|
+
| `resources.update(id, input)` | Update resource |
|
|
89
|
+
| `resources.delete(id)` | Delete resource |
|
|
90
|
+
|
|
91
|
+
### Configuration
|
|
92
|
+
|
|
93
|
+
| Function | Description |
|
|
94
|
+
|----------|-------------|
|
|
95
|
+
| `configure({ apiKey })` | Set API key for unlimited access |
|
|
96
|
+
| `configure({ baseUrl })` | Set custom API URL |
|
|
97
|
+
|
|
98
|
+
## Error Handling
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
import { X402Error } from '@x402jobs/sdk'
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const score = await check(url)
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof X402Error) {
|
|
107
|
+
console.log(err.code) // Error code
|
|
108
|
+
console.log(err.message) // Human readable
|
|
109
|
+
console.log(err.status) // HTTP status
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Error Codes
|
|
115
|
+
|
|
116
|
+
| Code | Description |
|
|
117
|
+
|------|-------------|
|
|
118
|
+
| `NOT_FOUND` | Resource not indexed |
|
|
119
|
+
| `PAYMENT_REQUIRED` | x402 payment failed |
|
|
120
|
+
| `RATE_LIMITED` | Too many requests |
|
|
121
|
+
| `UNAUTHORIZED` | Invalid or missing API key |
|
|
122
|
+
| `FORBIDDEN` | Not allowed |
|
|
123
|
+
| `VALIDATION_ERROR` | Invalid input |
|
|
124
|
+
| `SERVER_ERROR` | x402jobs API error |
|
|
125
|
+
|
|
126
|
+
## TypeScript
|
|
127
|
+
|
|
128
|
+
Full TypeScript support with exported types:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import type {
|
|
132
|
+
Score,
|
|
133
|
+
Resource,
|
|
134
|
+
ResourceSearchOptions
|
|
135
|
+
} from '@x402jobs/sdk'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Docs
|
|
139
|
+
|
|
140
|
+
Full documentation at [x402.jobs/docs](https://x402.jobs/docs)
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
interface Score {
|
|
2
|
+
url: string;
|
|
3
|
+
success_rate: number | null;
|
|
4
|
+
calls: number;
|
|
5
|
+
value_processed: string;
|
|
6
|
+
last_called: string | null;
|
|
7
|
+
}
|
|
8
|
+
interface TopOptions {
|
|
9
|
+
limit?: number;
|
|
10
|
+
category?: string;
|
|
11
|
+
}
|
|
12
|
+
interface Resource {
|
|
13
|
+
id: string;
|
|
14
|
+
url: string;
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
icon_url: string | null;
|
|
18
|
+
category: string;
|
|
19
|
+
price: string;
|
|
20
|
+
owner_id: string;
|
|
21
|
+
created_at: string;
|
|
22
|
+
updated_at: string;
|
|
23
|
+
success_rate: number | null;
|
|
24
|
+
calls: number;
|
|
25
|
+
value_processed: string;
|
|
26
|
+
last_called: string | null;
|
|
27
|
+
}
|
|
28
|
+
interface ResourceSearchOptions {
|
|
29
|
+
query?: string;
|
|
30
|
+
category?: string;
|
|
31
|
+
minSuccessRate?: number;
|
|
32
|
+
minCalls?: number;
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
}
|
|
36
|
+
interface ResourceCreateInput {
|
|
37
|
+
url: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
category?: string;
|
|
41
|
+
price: string;
|
|
42
|
+
icon_url?: string;
|
|
43
|
+
}
|
|
44
|
+
interface ResourceUpdateInput {
|
|
45
|
+
name?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
category?: string;
|
|
48
|
+
price?: string;
|
|
49
|
+
icon_url?: string;
|
|
50
|
+
}
|
|
51
|
+
interface WalletConfig {
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
interface ConfigOptions {
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
baseUrl?: string;
|
|
57
|
+
wallet?: WalletConfig;
|
|
58
|
+
}
|
|
59
|
+
type ErrorCode = 'NOT_FOUND' | 'PAYMENT_REQUIRED' | 'RATE_LIMITED' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'VALIDATION_ERROR' | 'SERVER_ERROR';
|
|
60
|
+
|
|
61
|
+
declare function checkUrl(url: string): Promise<Score>;
|
|
62
|
+
declare function checkMany(urls: string[]): Promise<Score[]>;
|
|
63
|
+
declare function checkExists(url: string): Promise<boolean>;
|
|
64
|
+
declare function checkTop(options?: TopOptions): Promise<Score[]>;
|
|
65
|
+
type CheckFunction = typeof checkUrl & {
|
|
66
|
+
many: typeof checkMany;
|
|
67
|
+
exists: typeof checkExists;
|
|
68
|
+
top: typeof checkTop;
|
|
69
|
+
};
|
|
70
|
+
declare const check: CheckFunction;
|
|
71
|
+
|
|
72
|
+
type GetInput = string | {
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
75
|
+
declare function list(): Promise<Resource[]>;
|
|
76
|
+
declare function get(input: GetInput): Promise<Resource>;
|
|
77
|
+
declare function search(options?: ResourceSearchOptions): Promise<Resource[]>;
|
|
78
|
+
declare function register(input: ResourceCreateInput): Promise<Resource>;
|
|
79
|
+
declare function update(id: string, input: ResourceUpdateInput): Promise<Resource>;
|
|
80
|
+
declare function remove(id: string): Promise<void>;
|
|
81
|
+
declare const resources: {
|
|
82
|
+
list: typeof list;
|
|
83
|
+
get: typeof get;
|
|
84
|
+
search: typeof search;
|
|
85
|
+
register: typeof register;
|
|
86
|
+
update: typeof update;
|
|
87
|
+
delete: typeof remove;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
declare function configure(options: ConfigOptions): void;
|
|
91
|
+
|
|
92
|
+
declare class X402Error extends Error {
|
|
93
|
+
readonly code: ErrorCode;
|
|
94
|
+
readonly status: number;
|
|
95
|
+
constructor(code: ErrorCode, message: string, status: number);
|
|
96
|
+
static notFound(message?: string): X402Error;
|
|
97
|
+
static paymentRequired(message?: string): X402Error;
|
|
98
|
+
static rateLimited(message?: string): X402Error;
|
|
99
|
+
static unauthorized(message?: string): X402Error;
|
|
100
|
+
static forbidden(message?: string): X402Error;
|
|
101
|
+
static validationError(message: string): X402Error;
|
|
102
|
+
static serverError(message?: string): X402Error;
|
|
103
|
+
static fromStatus(status: number, message?: string): X402Error;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { type ConfigOptions, type ErrorCode, type Resource, type ResourceCreateInput, type ResourceSearchOptions, type ResourceUpdateInput, type Score, type TopOptions, type WalletConfig, X402Error, check, configure, resources };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
interface Score {
|
|
2
|
+
url: string;
|
|
3
|
+
success_rate: number | null;
|
|
4
|
+
calls: number;
|
|
5
|
+
value_processed: string;
|
|
6
|
+
last_called: string | null;
|
|
7
|
+
}
|
|
8
|
+
interface TopOptions {
|
|
9
|
+
limit?: number;
|
|
10
|
+
category?: string;
|
|
11
|
+
}
|
|
12
|
+
interface Resource {
|
|
13
|
+
id: string;
|
|
14
|
+
url: string;
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
icon_url: string | null;
|
|
18
|
+
category: string;
|
|
19
|
+
price: string;
|
|
20
|
+
owner_id: string;
|
|
21
|
+
created_at: string;
|
|
22
|
+
updated_at: string;
|
|
23
|
+
success_rate: number | null;
|
|
24
|
+
calls: number;
|
|
25
|
+
value_processed: string;
|
|
26
|
+
last_called: string | null;
|
|
27
|
+
}
|
|
28
|
+
interface ResourceSearchOptions {
|
|
29
|
+
query?: string;
|
|
30
|
+
category?: string;
|
|
31
|
+
minSuccessRate?: number;
|
|
32
|
+
minCalls?: number;
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
}
|
|
36
|
+
interface ResourceCreateInput {
|
|
37
|
+
url: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
category?: string;
|
|
41
|
+
price: string;
|
|
42
|
+
icon_url?: string;
|
|
43
|
+
}
|
|
44
|
+
interface ResourceUpdateInput {
|
|
45
|
+
name?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
category?: string;
|
|
48
|
+
price?: string;
|
|
49
|
+
icon_url?: string;
|
|
50
|
+
}
|
|
51
|
+
interface WalletConfig {
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
interface ConfigOptions {
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
baseUrl?: string;
|
|
57
|
+
wallet?: WalletConfig;
|
|
58
|
+
}
|
|
59
|
+
type ErrorCode = 'NOT_FOUND' | 'PAYMENT_REQUIRED' | 'RATE_LIMITED' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'VALIDATION_ERROR' | 'SERVER_ERROR';
|
|
60
|
+
|
|
61
|
+
declare function checkUrl(url: string): Promise<Score>;
|
|
62
|
+
declare function checkMany(urls: string[]): Promise<Score[]>;
|
|
63
|
+
declare function checkExists(url: string): Promise<boolean>;
|
|
64
|
+
declare function checkTop(options?: TopOptions): Promise<Score[]>;
|
|
65
|
+
type CheckFunction = typeof checkUrl & {
|
|
66
|
+
many: typeof checkMany;
|
|
67
|
+
exists: typeof checkExists;
|
|
68
|
+
top: typeof checkTop;
|
|
69
|
+
};
|
|
70
|
+
declare const check: CheckFunction;
|
|
71
|
+
|
|
72
|
+
type GetInput = string | {
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
75
|
+
declare function list(): Promise<Resource[]>;
|
|
76
|
+
declare function get(input: GetInput): Promise<Resource>;
|
|
77
|
+
declare function search(options?: ResourceSearchOptions): Promise<Resource[]>;
|
|
78
|
+
declare function register(input: ResourceCreateInput): Promise<Resource>;
|
|
79
|
+
declare function update(id: string, input: ResourceUpdateInput): Promise<Resource>;
|
|
80
|
+
declare function remove(id: string): Promise<void>;
|
|
81
|
+
declare const resources: {
|
|
82
|
+
list: typeof list;
|
|
83
|
+
get: typeof get;
|
|
84
|
+
search: typeof search;
|
|
85
|
+
register: typeof register;
|
|
86
|
+
update: typeof update;
|
|
87
|
+
delete: typeof remove;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
declare function configure(options: ConfigOptions): void;
|
|
91
|
+
|
|
92
|
+
declare class X402Error extends Error {
|
|
93
|
+
readonly code: ErrorCode;
|
|
94
|
+
readonly status: number;
|
|
95
|
+
constructor(code: ErrorCode, message: string, status: number);
|
|
96
|
+
static notFound(message?: string): X402Error;
|
|
97
|
+
static paymentRequired(message?: string): X402Error;
|
|
98
|
+
static rateLimited(message?: string): X402Error;
|
|
99
|
+
static unauthorized(message?: string): X402Error;
|
|
100
|
+
static forbidden(message?: string): X402Error;
|
|
101
|
+
static validationError(message: string): X402Error;
|
|
102
|
+
static serverError(message?: string): X402Error;
|
|
103
|
+
static fromStatus(status: number, message?: string): X402Error;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { type ConfigOptions, type ErrorCode, type Resource, type ResourceCreateInput, type ResourceSearchOptions, type ResourceUpdateInput, type Score, type TopOptions, type WalletConfig, X402Error, check, configure, resources };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
X402Error: () => X402Error,
|
|
24
|
+
check: () => check,
|
|
25
|
+
configure: () => configure,
|
|
26
|
+
resources: () => resources
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/config.ts
|
|
31
|
+
var DEFAULT_BASE_URL = "https://x402.jobs/api/v1";
|
|
32
|
+
var config = {
|
|
33
|
+
apiKey: null,
|
|
34
|
+
baseUrl: DEFAULT_BASE_URL,
|
|
35
|
+
wallet: null
|
|
36
|
+
};
|
|
37
|
+
function configure(options) {
|
|
38
|
+
if (options.apiKey !== void 0) {
|
|
39
|
+
config.apiKey = options.apiKey;
|
|
40
|
+
}
|
|
41
|
+
if (options.baseUrl !== void 0) {
|
|
42
|
+
config.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
43
|
+
}
|
|
44
|
+
if (options.wallet !== void 0) {
|
|
45
|
+
config.wallet = options.wallet;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getConfig() {
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/errors.ts
|
|
53
|
+
var X402Error = class _X402Error extends Error {
|
|
54
|
+
constructor(code, message, status) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = "X402Error";
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.status = status;
|
|
59
|
+
if (Error.captureStackTrace) {
|
|
60
|
+
Error.captureStackTrace(this, _X402Error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
static notFound(message = "Resource not found") {
|
|
64
|
+
return new _X402Error("NOT_FOUND", message, 404);
|
|
65
|
+
}
|
|
66
|
+
static paymentRequired(message = "Payment required") {
|
|
67
|
+
return new _X402Error("PAYMENT_REQUIRED", message, 402);
|
|
68
|
+
}
|
|
69
|
+
static rateLimited(message = "Too many requests") {
|
|
70
|
+
return new _X402Error("RATE_LIMITED", message, 429);
|
|
71
|
+
}
|
|
72
|
+
static unauthorized(message = "Invalid or missing API key") {
|
|
73
|
+
return new _X402Error("UNAUTHORIZED", message, 401);
|
|
74
|
+
}
|
|
75
|
+
static forbidden(message = "Access denied") {
|
|
76
|
+
return new _X402Error("FORBIDDEN", message, 403);
|
|
77
|
+
}
|
|
78
|
+
static validationError(message) {
|
|
79
|
+
return new _X402Error("VALIDATION_ERROR", message, 400);
|
|
80
|
+
}
|
|
81
|
+
static serverError(message = "Internal server error") {
|
|
82
|
+
return new _X402Error("SERVER_ERROR", message, 500);
|
|
83
|
+
}
|
|
84
|
+
static fromStatus(status, message) {
|
|
85
|
+
switch (status) {
|
|
86
|
+
case 400:
|
|
87
|
+
return _X402Error.validationError(message ?? "Invalid request");
|
|
88
|
+
case 401:
|
|
89
|
+
return _X402Error.unauthorized(message);
|
|
90
|
+
case 402:
|
|
91
|
+
return _X402Error.paymentRequired(message);
|
|
92
|
+
case 403:
|
|
93
|
+
return _X402Error.forbidden(message);
|
|
94
|
+
case 404:
|
|
95
|
+
return _X402Error.notFound(message);
|
|
96
|
+
case 429:
|
|
97
|
+
return _X402Error.rateLimited(message);
|
|
98
|
+
default:
|
|
99
|
+
return _X402Error.serverError(message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/http.ts
|
|
105
|
+
function buildUrl(path, params) {
|
|
106
|
+
const { baseUrl } = getConfig();
|
|
107
|
+
const url = new URL(path, baseUrl);
|
|
108
|
+
if (params) {
|
|
109
|
+
for (const [key, value] of Object.entries(params)) {
|
|
110
|
+
if (value !== void 0) {
|
|
111
|
+
url.searchParams.set(key, String(value));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return url.toString();
|
|
116
|
+
}
|
|
117
|
+
function getHeaders() {
|
|
118
|
+
const { apiKey } = getConfig();
|
|
119
|
+
const headers = {
|
|
120
|
+
"Content-Type": "application/json",
|
|
121
|
+
Accept: "application/json"
|
|
122
|
+
};
|
|
123
|
+
if (apiKey) {
|
|
124
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
125
|
+
}
|
|
126
|
+
return headers;
|
|
127
|
+
}
|
|
128
|
+
async function parseResponse(response) {
|
|
129
|
+
const contentType = response.headers.get("content-type");
|
|
130
|
+
if (!contentType?.includes("application/json")) {
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw X402Error.fromStatus(response.status, response.statusText);
|
|
133
|
+
}
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
const errorData = data;
|
|
139
|
+
const message = errorData?.error?.message ?? response.statusText;
|
|
140
|
+
throw X402Error.fromStatus(response.status, message);
|
|
141
|
+
}
|
|
142
|
+
return data;
|
|
143
|
+
}
|
|
144
|
+
async function request(path, options = {}) {
|
|
145
|
+
const { method = "GET", body, params } = options;
|
|
146
|
+
const url = buildUrl(path, params);
|
|
147
|
+
const headers = getHeaders();
|
|
148
|
+
const fetchOptions = {
|
|
149
|
+
method,
|
|
150
|
+
headers
|
|
151
|
+
};
|
|
152
|
+
if (body !== void 0) {
|
|
153
|
+
fetchOptions.body = JSON.stringify(body);
|
|
154
|
+
}
|
|
155
|
+
const response = await fetch(url, fetchOptions);
|
|
156
|
+
return parseResponse(response);
|
|
157
|
+
}
|
|
158
|
+
var http = {
|
|
159
|
+
get(path, params) {
|
|
160
|
+
return request(path, { method: "GET", params });
|
|
161
|
+
},
|
|
162
|
+
post(path, body) {
|
|
163
|
+
return request(path, { method: "POST", body });
|
|
164
|
+
},
|
|
165
|
+
patch(path, body) {
|
|
166
|
+
return request(path, { method: "PATCH", body });
|
|
167
|
+
},
|
|
168
|
+
delete(path) {
|
|
169
|
+
return request(path, { method: "DELETE" });
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/check.ts
|
|
174
|
+
async function checkUrl(url) {
|
|
175
|
+
return http.get("/resources/score", { url });
|
|
176
|
+
}
|
|
177
|
+
async function checkMany(urls) {
|
|
178
|
+
return Promise.all(urls.map((url) => checkUrl(url)));
|
|
179
|
+
}
|
|
180
|
+
async function checkExists(url) {
|
|
181
|
+
const result = await http.get("/resources/exists", { url });
|
|
182
|
+
return result.exists;
|
|
183
|
+
}
|
|
184
|
+
async function checkTop(options = {}) {
|
|
185
|
+
const { limit = 20, category } = options;
|
|
186
|
+
return http.get("/resources/top", { limit, category });
|
|
187
|
+
}
|
|
188
|
+
var check = Object.assign(checkUrl, {
|
|
189
|
+
many: checkMany,
|
|
190
|
+
exists: checkExists,
|
|
191
|
+
top: checkTop
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// src/resources.ts
|
|
195
|
+
async function list() {
|
|
196
|
+
return http.get("/resources");
|
|
197
|
+
}
|
|
198
|
+
async function get(input) {
|
|
199
|
+
if (typeof input === "string") {
|
|
200
|
+
return http.get("/resources", { url: input });
|
|
201
|
+
}
|
|
202
|
+
return http.get(`/resources/${input.id}`);
|
|
203
|
+
}
|
|
204
|
+
async function search(options = {}) {
|
|
205
|
+
const params = {};
|
|
206
|
+
if (options.query) params["q"] = options.query;
|
|
207
|
+
if (options.category) params["category"] = options.category;
|
|
208
|
+
if (options.minSuccessRate !== void 0) params["min_success_rate"] = options.minSuccessRate;
|
|
209
|
+
if (options.minCalls !== void 0) params["min_calls"] = options.minCalls;
|
|
210
|
+
if (options.limit !== void 0) params["limit"] = options.limit;
|
|
211
|
+
if (options.offset !== void 0) params["offset"] = options.offset;
|
|
212
|
+
return http.get("/resources/search", params);
|
|
213
|
+
}
|
|
214
|
+
async function register(input) {
|
|
215
|
+
return http.post("/resources", input);
|
|
216
|
+
}
|
|
217
|
+
async function update(id, input) {
|
|
218
|
+
return http.patch(`/resources/${id}`, input);
|
|
219
|
+
}
|
|
220
|
+
async function remove(id) {
|
|
221
|
+
await http.delete(`/resources/${id}`);
|
|
222
|
+
}
|
|
223
|
+
var resources = {
|
|
224
|
+
list,
|
|
225
|
+
get,
|
|
226
|
+
search,
|
|
227
|
+
register,
|
|
228
|
+
update,
|
|
229
|
+
delete: remove
|
|
230
|
+
};
|
|
231
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
+
0 && (module.exports = {
|
|
233
|
+
X402Error,
|
|
234
|
+
check,
|
|
235
|
+
configure,
|
|
236
|
+
resources
|
|
237
|
+
});
|
|
238
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/errors.ts","../src/http.ts","../src/check.ts","../src/resources.ts"],"sourcesContent":["// Main exports\nexport { check } from './check'\nexport { resources } from './resources'\nexport { configure } from './config'\nexport { X402Error } from './errors'\n\n// Type exports\nexport type {\n Score,\n TopOptions,\n Resource,\n ResourceSearchOptions,\n ResourceCreateInput,\n ResourceUpdateInput,\n ConfigOptions,\n WalletConfig,\n ErrorCode,\n} from './types'\n","import type { ConfigOptions, WalletConfig } from './types'\n\nconst DEFAULT_BASE_URL = 'https://x402.jobs/api/v1'\n\ninterface InternalConfig {\n apiKey: string | null\n baseUrl: string\n wallet: WalletConfig | null\n}\n\nconst config: InternalConfig = {\n apiKey: null,\n baseUrl: DEFAULT_BASE_URL,\n wallet: null,\n}\n\nexport function configure(options: ConfigOptions): void {\n if (options.apiKey !== undefined) {\n config.apiKey = options.apiKey\n }\n if (options.baseUrl !== undefined) {\n config.baseUrl = options.baseUrl.replace(/\\/$/, '') // Remove trailing slash\n }\n if (options.wallet !== undefined) {\n config.wallet = options.wallet\n }\n}\n\nexport function getConfig(): Readonly<InternalConfig> {\n return config\n}\n\nexport function resetConfig(): void {\n config.apiKey = null\n config.baseUrl = DEFAULT_BASE_URL\n config.wallet = null\n}\n","import type { ErrorCode } from './types'\n\nexport class X402Error extends Error {\n readonly code: ErrorCode\n readonly status: number\n\n constructor(code: ErrorCode, message: string, status: number) {\n super(message)\n this.name = 'X402Error'\n this.code = code\n this.status = status\n\n // Maintains proper stack trace for where error was thrown (V8 engines)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, X402Error)\n }\n }\n\n static notFound(message = 'Resource not found'): X402Error {\n return new X402Error('NOT_FOUND', message, 404)\n }\n\n static paymentRequired(message = 'Payment required'): X402Error {\n return new X402Error('PAYMENT_REQUIRED', message, 402)\n }\n\n static rateLimited(message = 'Too many requests'): X402Error {\n return new X402Error('RATE_LIMITED', message, 429)\n }\n\n static unauthorized(message = 'Invalid or missing API key'): X402Error {\n return new X402Error('UNAUTHORIZED', message, 401)\n }\n\n static forbidden(message = 'Access denied'): X402Error {\n return new X402Error('FORBIDDEN', message, 403)\n }\n\n static validationError(message: string): X402Error {\n return new X402Error('VALIDATION_ERROR', message, 400)\n }\n\n static serverError(message = 'Internal server error'): X402Error {\n return new X402Error('SERVER_ERROR', message, 500)\n }\n\n static fromStatus(status: number, message?: string): X402Error {\n switch (status) {\n case 400:\n return X402Error.validationError(message ?? 'Invalid request')\n case 401:\n return X402Error.unauthorized(message)\n case 402:\n return X402Error.paymentRequired(message)\n case 403:\n return X402Error.forbidden(message)\n case 404:\n return X402Error.notFound(message)\n case 429:\n return X402Error.rateLimited(message)\n default:\n return X402Error.serverError(message)\n }\n }\n}\n","import { getConfig } from './config'\nimport { X402Error } from './errors'\n\ntype HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE'\n\ninterface RequestOptions {\n method?: HttpMethod\n body?: unknown\n params?: Record<string, string | number | boolean | undefined>\n}\n\nfunction buildUrl(path: string, params?: RequestOptions['params']): string {\n const { baseUrl } = getConfig()\n const url = new URL(path, baseUrl)\n\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value))\n }\n }\n }\n\n return url.toString()\n}\n\nfunction getHeaders(): Record<string, string> {\n const { apiKey } = getConfig()\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n }\n\n if (apiKey) {\n headers['Authorization'] = `Bearer ${apiKey}`\n }\n\n return headers\n}\n\nasync function parseResponse<T>(response: Response): Promise<T> {\n const contentType = response.headers.get('content-type')\n\n if (!contentType?.includes('application/json')) {\n if (!response.ok) {\n throw X402Error.fromStatus(response.status, response.statusText)\n }\n return undefined as T\n }\n\n const data = (await response.json()) as { error?: { code?: string; message?: string } } | T\n\n if (!response.ok) {\n const errorData = data as { error?: { code?: string; message?: string } }\n const message = errorData?.error?.message ?? response.statusText\n throw X402Error.fromStatus(response.status, message)\n }\n\n return data as T\n}\n\nexport async function request<T>(\n path: string,\n options: RequestOptions = {}\n): Promise<T> {\n const { method = 'GET', body, params } = options\n const url = buildUrl(path, params)\n const headers = getHeaders()\n\n const fetchOptions: RequestInit = {\n method,\n headers,\n }\n\n if (body !== undefined) {\n fetchOptions.body = JSON.stringify(body)\n }\n\n const response = await fetch(url, fetchOptions)\n return parseResponse<T>(response)\n}\n\nexport const http = {\n get<T>(path: string, params?: RequestOptions['params']): Promise<T> {\n return request<T>(path, { method: 'GET', params })\n },\n\n post<T>(path: string, body?: unknown): Promise<T> {\n return request<T>(path, { method: 'POST', body })\n },\n\n patch<T>(path: string, body?: unknown): Promise<T> {\n return request<T>(path, { method: 'PATCH', body })\n },\n\n delete<T>(path: string): Promise<T> {\n return request<T>(path, { method: 'DELETE' })\n },\n}\n","import { http } from './http'\nimport type { Score, TopOptions } from './types'\n\nasync function checkUrl(url: string): Promise<Score> {\n return http.get<Score>('/resources/score', { url })\n}\n\nasync function checkMany(urls: string[]): Promise<Score[]> {\n // Phase 2: Use batch endpoint when available\n // For now, run checks in parallel\n return Promise.all(urls.map((url) => checkUrl(url)))\n}\n\nasync function checkExists(url: string): Promise<boolean> {\n const result = await http.get<{ exists: boolean }>('/resources/exists', { url })\n return result.exists\n}\n\nasync function checkTop(options: TopOptions = {}): Promise<Score[]> {\n const { limit = 20, category } = options\n return http.get<Score[]>('/resources/top', { limit, category })\n}\n\n// Create the check function with additional methods attached\ntype CheckFunction = typeof checkUrl & {\n many: typeof checkMany\n exists: typeof checkExists\n top: typeof checkTop\n}\n\nexport const check: CheckFunction = Object.assign(checkUrl, {\n many: checkMany,\n exists: checkExists,\n top: checkTop,\n})\n","import { http } from './http'\nimport type {\n Resource,\n ResourceSearchOptions,\n ResourceCreateInput,\n ResourceUpdateInput,\n} from './types'\n\ntype GetInput = string | { id: string }\n\nasync function list(): Promise<Resource[]> {\n return http.get<Resource[]>('/resources')\n}\n\nasync function get(input: GetInput): Promise<Resource> {\n if (typeof input === 'string') {\n // Treat string as URL\n return http.get<Resource>('/resources', { url: input })\n }\n // Get by ID\n return http.get<Resource>(`/resources/${input.id}`)\n}\n\nasync function search(options: ResourceSearchOptions = {}): Promise<Resource[]> {\n const params: Record<string, string | number | undefined> = {}\n\n if (options.query) params['q'] = options.query\n if (options.category) params['category'] = options.category\n if (options.minSuccessRate !== undefined) params['min_success_rate'] = options.minSuccessRate\n if (options.minCalls !== undefined) params['min_calls'] = options.minCalls\n if (options.limit !== undefined) params['limit'] = options.limit\n if (options.offset !== undefined) params['offset'] = options.offset\n\n return http.get<Resource[]>('/resources/search', params)\n}\n\nasync function register(input: ResourceCreateInput): Promise<Resource> {\n return http.post<Resource>('/resources', input)\n}\n\nasync function update(id: string, input: ResourceUpdateInput): Promise<Resource> {\n return http.patch<Resource>(`/resources/${id}`, input)\n}\n\nasync function remove(id: string): Promise<void> {\n await http.delete(`/resources/${id}`)\n}\n\nexport const resources = {\n list,\n get,\n search,\n register,\n update,\n delete: remove,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAM,mBAAmB;AAQzB,IAAM,SAAyB;AAAA,EAC7B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AACV;AAEO,SAAS,UAAU,SAA8B;AACtD,MAAI,QAAQ,WAAW,QAAW;AAChC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACA,MAAI,QAAQ,YAAY,QAAW;AACjC,WAAO,UAAU,QAAQ,QAAQ,QAAQ,OAAO,EAAE;AAAA,EACpD;AACA,MAAI,QAAQ,WAAW,QAAW;AAChC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACF;AAEO,SAAS,YAAsC;AACpD,SAAO;AACT;;;AC5BO,IAAM,YAAN,MAAM,mBAAkB,MAAM;AAAA,EAInC,YAAY,MAAiB,SAAiB,QAAgB;AAC5D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,SAAS;AAGd,QAAI,MAAM,mBAAmB;AAC3B,YAAM,kBAAkB,M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AAM,SAAsD,CAAC;AAE7D,MAAI,QAAQ,MAAO,QAAO,GAAG,IAAI,QAAQ;AACzC,MAAI,QAAQ,SAAU,QAAO,UAAU,IAAI,QAAQ;AACnD,MAAI,QAAQ,mBAAmB,OAAW,QAAO,kBAAkB,IAAI,QAAQ;AAC/E,MAAI,QAAQ,aAAa,OAAW,QAAO,WAAW,IAAI,QAAQ;AAClE,MAAI,QAAQ,UAAU,OAAW,QAAO,OAAO,IAAI,QAAQ;AAC3D,MAAI,QAAQ,WAAW,OAAW,QAAO,QAAQ,IAAI,QAAQ;AAE7D,SAAO,KAAK,IAAgB,qBAAqB,MAAM;AACzD;AAEA,eAAe,SAAS,OAA+C;AACrE,SAAO,KAAK,KAAe,cAAc,KAAK;AAChD;AAEA,eAAe,OAAO,IAAY,OAA+C;AAC/E,SAAO,KAAK,MAAgB,cAAc,EAAE,IAAI,KAAK;AACvD;AAEA,eAAe,OAAO,IAA2B;AAC/C,QAAM,KAAK,OAAO,cAAc,EAAE,EAAE;AACtC;AAEO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AACV;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
var DEFAULT_BASE_URL = "https://x402.jobs/api/v1";
|
|
3
|
+
var config = {
|
|
4
|
+
apiKey: null,
|
|
5
|
+
baseUrl: DEFAULT_BASE_URL,
|
|
6
|
+
wallet: null
|
|
7
|
+
};
|
|
8
|
+
function configure(options) {
|
|
9
|
+
if (options.apiKey !== void 0) {
|
|
10
|
+
config.apiKey = options.apiKey;
|
|
11
|
+
}
|
|
12
|
+
if (options.baseUrl !== void 0) {
|
|
13
|
+
config.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
14
|
+
}
|
|
15
|
+
if (options.wallet !== void 0) {
|
|
16
|
+
config.wallet = options.wallet;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function getConfig() {
|
|
20
|
+
return config;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/errors.ts
|
|
24
|
+
var X402Error = class _X402Error extends Error {
|
|
25
|
+
constructor(code, message, status) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = "X402Error";
|
|
28
|
+
this.code = code;
|
|
29
|
+
this.status = status;
|
|
30
|
+
if (Error.captureStackTrace) {
|
|
31
|
+
Error.captureStackTrace(this, _X402Error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static notFound(message = "Resource not found") {
|
|
35
|
+
return new _X402Error("NOT_FOUND", message, 404);
|
|
36
|
+
}
|
|
37
|
+
static paymentRequired(message = "Payment required") {
|
|
38
|
+
return new _X402Error("PAYMENT_REQUIRED", message, 402);
|
|
39
|
+
}
|
|
40
|
+
static rateLimited(message = "Too many requests") {
|
|
41
|
+
return new _X402Error("RATE_LIMITED", message, 429);
|
|
42
|
+
}
|
|
43
|
+
static unauthorized(message = "Invalid or missing API key") {
|
|
44
|
+
return new _X402Error("UNAUTHORIZED", message, 401);
|
|
45
|
+
}
|
|
46
|
+
static forbidden(message = "Access denied") {
|
|
47
|
+
return new _X402Error("FORBIDDEN", message, 403);
|
|
48
|
+
}
|
|
49
|
+
static validationError(message) {
|
|
50
|
+
return new _X402Error("VALIDATION_ERROR", message, 400);
|
|
51
|
+
}
|
|
52
|
+
static serverError(message = "Internal server error") {
|
|
53
|
+
return new _X402Error("SERVER_ERROR", message, 500);
|
|
54
|
+
}
|
|
55
|
+
static fromStatus(status, message) {
|
|
56
|
+
switch (status) {
|
|
57
|
+
case 400:
|
|
58
|
+
return _X402Error.validationError(message ?? "Invalid request");
|
|
59
|
+
case 401:
|
|
60
|
+
return _X402Error.unauthorized(message);
|
|
61
|
+
case 402:
|
|
62
|
+
return _X402Error.paymentRequired(message);
|
|
63
|
+
case 403:
|
|
64
|
+
return _X402Error.forbidden(message);
|
|
65
|
+
case 404:
|
|
66
|
+
return _X402Error.notFound(message);
|
|
67
|
+
case 429:
|
|
68
|
+
return _X402Error.rateLimited(message);
|
|
69
|
+
default:
|
|
70
|
+
return _X402Error.serverError(message);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/http.ts
|
|
76
|
+
function buildUrl(path, params) {
|
|
77
|
+
const { baseUrl } = getConfig();
|
|
78
|
+
const url = new URL(path, baseUrl);
|
|
79
|
+
if (params) {
|
|
80
|
+
for (const [key, value] of Object.entries(params)) {
|
|
81
|
+
if (value !== void 0) {
|
|
82
|
+
url.searchParams.set(key, String(value));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return url.toString();
|
|
87
|
+
}
|
|
88
|
+
function getHeaders() {
|
|
89
|
+
const { apiKey } = getConfig();
|
|
90
|
+
const headers = {
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
Accept: "application/json"
|
|
93
|
+
};
|
|
94
|
+
if (apiKey) {
|
|
95
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
96
|
+
}
|
|
97
|
+
return headers;
|
|
98
|
+
}
|
|
99
|
+
async function parseResponse(response) {
|
|
100
|
+
const contentType = response.headers.get("content-type");
|
|
101
|
+
if (!contentType?.includes("application/json")) {
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw X402Error.fromStatus(response.status, response.statusText);
|
|
104
|
+
}
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
const data = await response.json();
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
const errorData = data;
|
|
110
|
+
const message = errorData?.error?.message ?? response.statusText;
|
|
111
|
+
throw X402Error.fromStatus(response.status, message);
|
|
112
|
+
}
|
|
113
|
+
return data;
|
|
114
|
+
}
|
|
115
|
+
async function request(path, options = {}) {
|
|
116
|
+
const { method = "GET", body, params } = options;
|
|
117
|
+
const url = buildUrl(path, params);
|
|
118
|
+
const headers = getHeaders();
|
|
119
|
+
const fetchOptions = {
|
|
120
|
+
method,
|
|
121
|
+
headers
|
|
122
|
+
};
|
|
123
|
+
if (body !== void 0) {
|
|
124
|
+
fetchOptions.body = JSON.stringify(body);
|
|
125
|
+
}
|
|
126
|
+
const response = await fetch(url, fetchOptions);
|
|
127
|
+
return parseResponse(response);
|
|
128
|
+
}
|
|
129
|
+
var http = {
|
|
130
|
+
get(path, params) {
|
|
131
|
+
return request(path, { method: "GET", params });
|
|
132
|
+
},
|
|
133
|
+
post(path, body) {
|
|
134
|
+
return request(path, { method: "POST", body });
|
|
135
|
+
},
|
|
136
|
+
patch(path, body) {
|
|
137
|
+
return request(path, { method: "PATCH", body });
|
|
138
|
+
},
|
|
139
|
+
delete(path) {
|
|
140
|
+
return request(path, { method: "DELETE" });
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/check.ts
|
|
145
|
+
async function checkUrl(url) {
|
|
146
|
+
return http.get("/resources/score", { url });
|
|
147
|
+
}
|
|
148
|
+
async function checkMany(urls) {
|
|
149
|
+
return Promise.all(urls.map((url) => checkUrl(url)));
|
|
150
|
+
}
|
|
151
|
+
async function checkExists(url) {
|
|
152
|
+
const result = await http.get("/resources/exists", { url });
|
|
153
|
+
return result.exists;
|
|
154
|
+
}
|
|
155
|
+
async function checkTop(options = {}) {
|
|
156
|
+
const { limit = 20, category } = options;
|
|
157
|
+
return http.get("/resources/top", { limit, category });
|
|
158
|
+
}
|
|
159
|
+
var check = Object.assign(checkUrl, {
|
|
160
|
+
many: checkMany,
|
|
161
|
+
exists: checkExists,
|
|
162
|
+
top: checkTop
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// src/resources.ts
|
|
166
|
+
async function list() {
|
|
167
|
+
return http.get("/resources");
|
|
168
|
+
}
|
|
169
|
+
async function get(input) {
|
|
170
|
+
if (typeof input === "string") {
|
|
171
|
+
return http.get("/resources", { url: input });
|
|
172
|
+
}
|
|
173
|
+
return http.get(`/resources/${input.id}`);
|
|
174
|
+
}
|
|
175
|
+
async function search(options = {}) {
|
|
176
|
+
const params = {};
|
|
177
|
+
if (options.query) params["q"] = options.query;
|
|
178
|
+
if (options.category) params["category"] = options.category;
|
|
179
|
+
if (options.minSuccessRate !== void 0) params["min_success_rate"] = options.minSuccessRate;
|
|
180
|
+
if (options.minCalls !== void 0) params["min_calls"] = options.minCalls;
|
|
181
|
+
if (options.limit !== void 0) params["limit"] = options.limit;
|
|
182
|
+
if (options.offset !== void 0) params["offset"] = options.offset;
|
|
183
|
+
return http.get("/resources/search", params);
|
|
184
|
+
}
|
|
185
|
+
async function register(input) {
|
|
186
|
+
return http.post("/resources", input);
|
|
187
|
+
}
|
|
188
|
+
async function update(id, input) {
|
|
189
|
+
return http.patch(`/resources/${id}`, input);
|
|
190
|
+
}
|
|
191
|
+
async function remove(id) {
|
|
192
|
+
await http.delete(`/resources/${id}`);
|
|
193
|
+
}
|
|
194
|
+
var resources = {
|
|
195
|
+
list,
|
|
196
|
+
get,
|
|
197
|
+
search,
|
|
198
|
+
register,
|
|
199
|
+
update,
|
|
200
|
+
delete: remove
|
|
201
|
+
};
|
|
202
|
+
export {
|
|
203
|
+
X402Error,
|
|
204
|
+
check,
|
|
205
|
+
configure,
|
|
206
|
+
resources
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/errors.ts","../src/http.ts","../src/check.ts","../src/resources.ts"],"sourcesContent":["import type { ConfigOptions, WalletConfig } from './types'\n\nconst DEFAULT_BASE_URL = 'https://x402.jobs/api/v1'\n\ninterface InternalConfig {\n apiKey: string | null\n baseUrl: string\n wallet: WalletConfig | null\n}\n\nconst config: InternalConfig = {\n apiKey: null,\n baseUrl: DEFAULT_BASE_URL,\n wallet: null,\n}\n\nexport function configure(options: ConfigOptions): void {\n if (options.apiKey !== undefined) {\n config.apiKey = options.apiKey\n }\n if (options.baseUrl !== undefined) {\n config.baseUrl = options.baseUrl.replace(/\\/$/, '') // Remove trailing slash\n }\n if (options.wallet !== undefined) {\n config.wallet = options.wallet\n }\n}\n\nexport function getConfig(): Readonly<InternalConfig> {\n return config\n}\n\nexport function resetConfig(): void {\n config.apiKey = null\n config.baseUrl = DEFAULT_BASE_URL\n config.wallet = null\n}\n","import type { ErrorCode } from './types'\n\nexport class X402Error extends Error {\n readonly code: ErrorCode\n readonly status: number\n\n constructor(code: ErrorCode, message: string, status: number) {\n super(message)\n this.name = 'X402Error'\n this.code = code\n this.status = status\n\n // Maintains proper stack trace for where error was thrown (V8 engines)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, X402Error)\n }\n }\n\n static notFound(message = 'Resource not found'): X402Error {\n return new X402Error('NOT_FOUND', message, 404)\n }\n\n static paymentRequired(message = 'Payment required'): X402Error {\n return new X402Error('PAYMENT_REQUIRED', message, 402)\n }\n\n static rateLimited(message = 'Too many requests'): X402Error {\n return new X402Error('RATE_LIMITED', message, 429)\n }\n\n static unauthorized(message = 'Invalid or missing API key'): X402Error {\n return new X402Error('UNAUTHORIZED', message, 401)\n }\n\n static forbidden(message = 'Access denied'): X402Error {\n return new X402Error('FORBIDDEN', message, 403)\n }\n\n static validationError(message: string): X402Error {\n return new X402Error('VALIDATION_ERROR', message, 400)\n }\n\n static serverError(message = 'Internal server error'): X402Error {\n return new X402Error('SERVER_ERROR', message, 500)\n }\n\n static fromStatus(status: number, message?: string): X402Error {\n switch (status) {\n case 400:\n return X402Error.validationError(message ?? 'Invalid request')\n case 401:\n return X402Error.unauthorized(message)\n case 402:\n return X402Error.paymentRequired(message)\n case 403:\n return X402Error.forbidden(message)\n case 404:\n return X402Error.notFound(message)\n case 429:\n return X402Error.rateLimited(message)\n default:\n return X402Error.serverError(message)\n }\n }\n}\n","import { getConfig } from './config'\nimport { X402Error } from './errors'\n\ntype HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE'\n\ninterface RequestOptions {\n method?: HttpMethod\n body?: unknown\n params?: Record<string, string | number | boolean | undefined>\n}\n\nfunction buildUrl(path: string, params?: RequestOptions['params']): string {\n const { baseUrl } = getConfig()\n const url = new URL(path, baseUrl)\n\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value))\n }\n }\n }\n\n return url.toString()\n}\n\nfunction getHeaders(): Record<string, string> {\n const { apiKey } = getConfig()\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n }\n\n if (apiKey) {\n headers['Authorization'] = `Bearer ${apiKey}`\n }\n\n return headers\n}\n\nasync function parseResponse<T>(response: Response): Promise<T> {\n const contentType = response.headers.get('content-type')\n\n if (!contentType?.includes('application/json')) {\n if (!response.ok) {\n throw X402Error.fromStatus(response.status, response.statusText)\n }\n return undefined as T\n }\n\n const data = (await response.json()) as { error?: { code?: string; message?: string } } | T\n\n if (!response.ok) {\n const errorData = data as { error?: { code?: string; message?: string } }\n const message = errorData?.error?.message ?? response.statusText\n throw X402Error.fromStatus(response.status, message)\n }\n\n return data as T\n}\n\nexport async function request<T>(\n path: string,\n options: RequestOptions = {}\n): Promise<T> {\n const { method = 'GET', body, params } = options\n const url = buildUrl(path, params)\n const headers = getHeaders()\n\n const fetchOptions: RequestInit = {\n method,\n headers,\n }\n\n if (body !== undefined) {\n fetchOptions.body = JSON.stringify(body)\n }\n\n const response = await fetch(url, fetchOptions)\n return parseResponse<T>(response)\n}\n\nexport const http = {\n get<T>(path: string, params?: RequestOptions['params']): Promise<T> {\n return request<T>(path, { method: 'GET', params })\n },\n\n post<T>(path: string, body?: unknown): Promise<T> {\n return request<T>(path, { method: 'POST', body })\n },\n\n patch<T>(path: string, body?: unknown): Promise<T> {\n return request<T>(path, { method: 'PATCH', body })\n },\n\n delete<T>(path: string): Promise<T> {\n return request<T>(path, { method: 'DELETE' })\n },\n}\n","import { http } from './http'\nimport type { Score, TopOptions } from './types'\n\nasync function checkUrl(url: string): Promise<Score> {\n return http.get<Score>('/resources/score', { url })\n}\n\nasync function checkMany(urls: string[]): Promise<Score[]> {\n // Phase 2: Use batch endpoint when available\n // For now, run checks in parallel\n return Promise.all(urls.map((url) => checkUrl(url)))\n}\n\nasync function checkExists(url: string): Promise<boolean> {\n const result = await http.get<{ exists: boolean }>('/resources/exists', { url })\n return result.exists\n}\n\nasync function checkTop(options: TopOptions = {}): Promise<Score[]> {\n const { limit = 20, category } = options\n return http.get<Score[]>('/resources/top', { limit, category })\n}\n\n// Create the check function with additional methods attached\ntype CheckFunction = typeof checkUrl & {\n many: typeof checkMany\n exists: typeof checkExists\n top: typeof checkTop\n}\n\nexport const check: CheckFunction = Object.assign(checkUrl, {\n many: checkMany,\n exists: checkExists,\n top: checkTop,\n})\n","import { http } from './http'\nimport type {\n Resource,\n ResourceSearchOptions,\n ResourceCreateInput,\n ResourceUpdateInput,\n} from './types'\n\ntype GetInput = string | { id: string }\n\nasync function list(): Promise<Resource[]> {\n return http.get<Resource[]>('/resources')\n}\n\nasync function get(input: GetInput): Promise<Resource> {\n if (typeof input === 'string') {\n // Treat string as URL\n return http.get<Resource>('/resources', { url: input })\n }\n // Get by ID\n return http.get<Resource>(`/resources/${input.id}`)\n}\n\nasync function search(options: ResourceSearchOptions = {}): Promise<Resource[]> {\n const params: Record<string, string | number | undefined> = {}\n\n if (options.query) params['q'] = options.query\n if (options.category) params['category'] = options.category\n if (options.minSuccessRate !== undefined) params['min_success_rate'] = options.minSuccessRate\n if (options.minCalls !== undefined) params['min_calls'] = options.minCalls\n if (options.limit !== undefined) params['limit'] = options.limit\n if (options.offset !== undefined) params['offset'] = options.offset\n\n return http.get<Resource[]>('/resources/search', params)\n}\n\nasync function register(input: ResourceCreateInput): Promise<Resource> {\n return http.post<Resource>('/resources', input)\n}\n\nasync function update(id: string, input: ResourceUpdateInput): Promise<Resource> {\n return http.patch<Resource>(`/resources/${id}`, input)\n}\n\nasync function remove(id: string): Promise<void> {\n await http.delete(`/resources/${id}`)\n}\n\nexport const resources = {\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;AAC/C,QAAM,KAAK,OAAO,cAAc,EAAE,EAAE;AACtC;AAEO,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AACV;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@x402jobs/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The official SDK for x402.jobs — trust, discovery, and resource management for x402",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"test:run": "vitest run",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"lint": "eslint src",
|
|
25
|
+
"prepublishOnly": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"x402",
|
|
29
|
+
"trust",
|
|
30
|
+
"reliability",
|
|
31
|
+
"api",
|
|
32
|
+
"resources",
|
|
33
|
+
"micropayments",
|
|
34
|
+
"verification"
|
|
35
|
+
],
|
|
36
|
+
"author": "x402jobs",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/x402jobs/sdk"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://x402.jobs",
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.0.0",
|
|
45
|
+
"tsup": "^8.0.0",
|
|
46
|
+
"typescript": "^5.0.0",
|
|
47
|
+
"vitest": "^1.0.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18"
|
|
51
|
+
}
|
|
52
|
+
}
|