@onchaindb/sdk 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +3 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -71
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/query-sdk/OnDB.d.ts +27 -0
- package/dist/query-sdk/OnDB.d.ts.map +1 -0
- package/dist/query-sdk/OnDB.js +191 -0
- package/dist/query-sdk/OnDB.js.map +1 -0
- package/dist/query-sdk/index.d.ts +1 -1
- package/dist/query-sdk/index.d.ts.map +1 -1
- package/dist/query-sdk/index.js +3 -3
- package/dist/query-sdk/index.js.map +1 -1
- package/dist/types.d.ts +6 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -8
- package/dist/types.js.map +1 -1
- package/dist/x402/types.d.ts +1 -1
- package/dist/x402/types.d.ts.map +1 -1
- package/dist/x402/utils.js +2 -2
- package/dist/x402/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/batch.d.ts +3 -3
- package/src/batch.js +1 -1
- package/src/client.ts +73 -106
- package/src/database.d.ts +1 -1
- package/src/database.js +4 -4
- package/src/database.ts +2 -2
- package/src/index.d.ts +18 -18
- package/src/index.js +16 -16
- package/src/index.ts +7 -8
- package/src/query-sdk/{OnChainDB.ts → OnDB.ts} +1 -1
- package/src/query-sdk/README.md +8 -8
- package/src/query-sdk/index.ts +1 -1
- package/src/tests/client-requests.test.ts +3 -3
- package/src/tests/client-validation.test.ts +5 -5
- package/src/types.d.ts +6 -6
- package/src/types.js +8 -8
- package/src/types.ts +10 -46
- package/src/x402/types.ts +3 -3
- package/src/x402/utils.ts +3 -3
- package/examples/blob-upload-example.ts +0 -140
package/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VERSION = exports.createHttpClient = exports.NodeHttpClient = exports.FetchHttpClient = exports.AxiosHttpClient = exports.PaymentVerificationError = exports.PaymentRequiredError = exports.ValidationError = exports.TransactionError = exports.
|
|
3
|
+
exports.VERSION = exports.createHttpClient = exports.NodeHttpClient = exports.FetchHttpClient = exports.AxiosHttpClient = exports.PaymentVerificationError = exports.PaymentRequiredError = exports.ValidationError = exports.TransactionError = exports.OnDBError = exports.createDatabaseManager = exports.DatabaseManager = exports.LogicalOperator = exports.FieldConditionBuilder = exports.SelectionBuilder = exports.QueryBuilder = exports.BulkBuilder = exports.BatchOperations = exports.OnDBClient = void 0;
|
|
4
4
|
exports.createClient = createClient;
|
|
5
5
|
// Main SDK exports
|
|
6
6
|
var client_1 = require("./client");
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "OnDBClient", { enumerable: true, get: function () { return client_1.OnDBClient; } });
|
|
8
8
|
var batch_1 = require("./batch");
|
|
9
9
|
Object.defineProperty(exports, "BatchOperations", { enumerable: true, get: function () { return batch_1.BatchOperations; } });
|
|
10
10
|
Object.defineProperty(exports, "BulkBuilder", { enumerable: true, get: function () { return batch_1.BulkBuilder; } });
|
|
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "DatabaseManager", { enumerable: true, get: funct
|
|
|
20
20
|
Object.defineProperty(exports, "createDatabaseManager", { enumerable: true, get: function () { return database_1.createDatabaseManager; } });
|
|
21
21
|
// Error exports
|
|
22
22
|
var types_1 = require("./types");
|
|
23
|
-
Object.defineProperty(exports, "
|
|
23
|
+
Object.defineProperty(exports, "OnDBError", { enumerable: true, get: function () { return types_1.OnDBError; } });
|
|
24
24
|
Object.defineProperty(exports, "TransactionError", { enumerable: true, get: function () { return types_1.TransactionError; } });
|
|
25
25
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return types_1.ValidationError; } });
|
|
26
26
|
Object.defineProperty(exports, "PaymentRequiredError", { enumerable: true, get: function () { return types_1.PaymentRequiredError; } });
|
|
@@ -28,7 +28,7 @@ Object.defineProperty(exports, "PaymentVerificationError", { enumerable: true, g
|
|
|
28
28
|
const client_2 = require("./client");
|
|
29
29
|
// Convenience factory function
|
|
30
30
|
function createClient(config) {
|
|
31
|
-
return new client_2.
|
|
31
|
+
return new client_2.OnDBClient(config);
|
|
32
32
|
}
|
|
33
33
|
// Re-export HTTP client utilities from ./query-sdk for advanced usage
|
|
34
34
|
var query_sdk_2 = require("./query-sdk");
|
|
@@ -39,9 +39,9 @@ Object.defineProperty(exports, "createHttpClient", { enumerable: true, get: func
|
|
|
39
39
|
// SDK version
|
|
40
40
|
exports.VERSION = '1.0.0';
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* OnDB TypeScript SDK
|
|
43
43
|
*
|
|
44
|
-
* A complete TypeScript SDK for
|
|
44
|
+
* A complete TypeScript SDK for OnDB - the decentralized database
|
|
45
45
|
* built on Celestia blockchain.
|
|
46
46
|
*
|
|
47
47
|
* Features:
|
|
@@ -58,7 +58,7 @@ exports.VERSION = '1.0.0';
|
|
|
58
58
|
*
|
|
59
59
|
* @example Basic Usage
|
|
60
60
|
* ```typescript
|
|
61
|
-
* import { createClient } from '@
|
|
61
|
+
* import { createClient } from '@ondb/sdk';
|
|
62
62
|
*
|
|
63
63
|
* const db = createClient({
|
|
64
64
|
* endpoint: 'http://localhost:9092',
|
|
@@ -67,7 +67,7 @@ exports.VERSION = '1.0.0';
|
|
|
67
67
|
*
|
|
68
68
|
* // Store data
|
|
69
69
|
* const result = await db.store({
|
|
70
|
-
* data: { message: 'Hello
|
|
70
|
+
* data: { message: 'Hello OnDB!', user: 'alice' },
|
|
71
71
|
* collection: 'messages'
|
|
72
72
|
* });
|
|
73
73
|
*
|
|
@@ -85,9 +85,9 @@ exports.VERSION = '1.0.0';
|
|
|
85
85
|
*
|
|
86
86
|
* @example Advanced Usage with Events
|
|
87
87
|
* ```typescript
|
|
88
|
-
* import {
|
|
88
|
+
* import { OnDBClient } from '@ondb/sdk';
|
|
89
89
|
*
|
|
90
|
-
* const db = new
|
|
90
|
+
* const db = new OnDBClient({
|
|
91
91
|
* endpoint: 'http://localhost:9092'
|
|
92
92
|
* });
|
|
93
93
|
*
|
|
@@ -109,9 +109,9 @@ exports.VERSION = '1.0.0';
|
|
|
109
109
|
*
|
|
110
110
|
* @example Batch Operations
|
|
111
111
|
* ```typescript
|
|
112
|
-
* import {
|
|
112
|
+
* import { OnDBClient, BulkBuilder } from '@ondb/sdk';
|
|
113
113
|
*
|
|
114
|
-
* const db = new
|
|
114
|
+
* const db = new OnDBClient({ endpoint: 'http://localhost:9092' });
|
|
115
115
|
* const batch = db.batch();
|
|
116
116
|
*
|
|
117
117
|
* // Build bulk operation
|
|
@@ -133,7 +133,7 @@ exports.VERSION = '1.0.0';
|
|
|
133
133
|
*
|
|
134
134
|
* @example Database Management
|
|
135
135
|
* ```typescript
|
|
136
|
-
* import { createClient } from '@
|
|
136
|
+
* import { createClient } from '@ondb/sdk';
|
|
137
137
|
*
|
|
138
138
|
* const client = createClient({
|
|
139
139
|
* endpoint: 'http://localhost:9092',
|
|
@@ -169,7 +169,7 @@ exports.VERSION = '1.0.0';
|
|
|
169
169
|
*
|
|
170
170
|
* @example Error Handling
|
|
171
171
|
* ```typescript
|
|
172
|
-
* import {
|
|
172
|
+
* import { OnDBError, TransactionError, ValidationError } from '@ondb/sdk';
|
|
173
173
|
*
|
|
174
174
|
* try {
|
|
175
175
|
* await db.store({ data: { test: 'data' } });
|
|
@@ -178,8 +178,8 @@ exports.VERSION = '1.0.0';
|
|
|
178
178
|
* console.log('Validation failed:', error.message);
|
|
179
179
|
* } else if (error instanceof TransactionError) {
|
|
180
180
|
* console.log('Transaction failed:', error.transactionId);
|
|
181
|
-
* } else if (error instanceof
|
|
182
|
-
* console.log('
|
|
181
|
+
* } else if (error instanceof OnDBError) {
|
|
182
|
+
* console.log('OnDB error:', error.code);
|
|
183
183
|
* }
|
|
184
184
|
* }
|
|
185
185
|
* ```
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Main SDK exports
|
|
2
|
-
export {
|
|
2
|
+
export { OnDBClient } from './client';
|
|
3
3
|
export { QueryBuilder } from './query-sdk';
|
|
4
4
|
export { DatabaseManager, createDatabaseManager } from './database';
|
|
5
5
|
|
|
6
6
|
// Core type exports
|
|
7
7
|
export type {
|
|
8
|
-
|
|
8
|
+
OnDBConfig,
|
|
9
9
|
StoreRequest,
|
|
10
10
|
StoreResponse,
|
|
11
11
|
TransactionStatus,
|
|
@@ -22,7 +22,6 @@ export type {
|
|
|
22
22
|
RetrieveBlobRequest,
|
|
23
23
|
BlobMetadata,
|
|
24
24
|
PricingQuoteRequest,
|
|
25
|
-
PricingQuoteResponse,
|
|
26
25
|
SimpleCollectionSchema,
|
|
27
26
|
SimpleFieldDefinition,
|
|
28
27
|
SimpleCollectionSchemaWithSharding,
|
|
@@ -81,7 +80,7 @@ export type {
|
|
|
81
80
|
|
|
82
81
|
// Error exports
|
|
83
82
|
export {
|
|
84
|
-
|
|
83
|
+
OnDBError,
|
|
85
84
|
TransactionError,
|
|
86
85
|
ValidationError,
|
|
87
86
|
PaymentRequiredError,
|
|
@@ -89,11 +88,11 @@ export {
|
|
|
89
88
|
} from './types';
|
|
90
89
|
|
|
91
90
|
// Convenience factory function
|
|
92
|
-
import {
|
|
93
|
-
import {
|
|
91
|
+
import { OnDBConfig } from './types';
|
|
92
|
+
import { OnDBClient } from './client';
|
|
94
93
|
|
|
95
|
-
export function createClient(config:
|
|
96
|
-
return new
|
|
94
|
+
export function createClient(config: OnDBConfig): OnDBClient {
|
|
95
|
+
return new OnDBClient(config);
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
// SDK version
|
|
@@ -3,7 +3,7 @@ import {SelectionBuilder} from './SelectionBuilder';
|
|
|
3
3
|
import {FieldMap, HttpClient, QueryRequest, QueryResponse, QueryValue} from "./index";
|
|
4
4
|
|
|
5
5
|
// Main SDK class providing static methods for query building
|
|
6
|
-
export class
|
|
6
|
+
export class OnDB {
|
|
7
7
|
private static httpClient?: HttpClient;
|
|
8
8
|
private static serverUrl?: string;
|
|
9
9
|
private static apiKey?: string;
|
package/src/query-sdk/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OnDB Query SDK
|
|
2
2
|
|
|
3
3
|
Fluent API for building queries with server-side JOINs, logical operators, field conditions, and aggregations.
|
|
4
4
|
|
|
@@ -92,7 +92,7 @@ All operators available on `whereField()` and `FieldConditionBuilder`:
|
|
|
92
92
|
### FieldConditionBuilder directly
|
|
93
93
|
|
|
94
94
|
```typescript
|
|
95
|
-
import { FieldConditionBuilder } from '@
|
|
95
|
+
import { FieldConditionBuilder } from '@ondb/sdk';
|
|
96
96
|
|
|
97
97
|
const condition = new FieldConditionBuilder('user.profile.bio').contains('Developer');
|
|
98
98
|
condition.toComposable(); // { user: { profile: { bio: { includes: 'Developer' } } } }
|
|
@@ -101,7 +101,7 @@ condition.toComposable(); // { user: { profile: { bio: { includes: 'Developer' }
|
|
|
101
101
|
## Logical Operators
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
|
-
import { LogicalOperator } from '@
|
|
104
|
+
import { LogicalOperator } from '@ondb/sdk';
|
|
105
105
|
|
|
106
106
|
const result = await db.queryBuilder()
|
|
107
107
|
.collection('posts')
|
|
@@ -297,7 +297,7 @@ db.queryBuilder().collection('users').selectAll().execute();
|
|
|
297
297
|
### SelectionBuilder
|
|
298
298
|
|
|
299
299
|
```typescript
|
|
300
|
-
import { SelectionBuilder } from '@
|
|
300
|
+
import { SelectionBuilder } from '@ondb/sdk';
|
|
301
301
|
|
|
302
302
|
// Field-by-field
|
|
303
303
|
const sel = new SelectionBuilder().field('id').field('name').build();
|
|
@@ -342,7 +342,7 @@ const result = await db.queryBuilder()
|
|
|
342
342
|
### NestedConditionBuilder
|
|
343
343
|
|
|
344
344
|
```typescript
|
|
345
|
-
import { NestedConditionBuilder } from '@
|
|
345
|
+
import { NestedConditionBuilder } from '@ondb/sdk';
|
|
346
346
|
|
|
347
347
|
const result = await db.queryBuilder()
|
|
348
348
|
.collection('users')
|
|
@@ -362,7 +362,7 @@ const result = await db.queryBuilder()
|
|
|
362
362
|
A lightweight wrapper around query response data for convenient access. Aggregation, sorting, filtering, and joining are handled server-side via `QueryBuilder`.
|
|
363
363
|
|
|
364
364
|
```typescript
|
|
365
|
-
import { createQueryResult } from '@
|
|
365
|
+
import { createQueryResult } from '@ondb/sdk';
|
|
366
366
|
|
|
367
367
|
const result = createQueryResult(response.records);
|
|
368
368
|
|
|
@@ -385,13 +385,13 @@ import {
|
|
|
385
385
|
AxiosHttpClient, // Axios (browser or Node.js)
|
|
386
386
|
NodeHttpClient, // Node.js native HTTP
|
|
387
387
|
createHttpClient // Auto-detect best for environment
|
|
388
|
-
} from '@
|
|
388
|
+
} from '@ondb/sdk';
|
|
389
389
|
```
|
|
390
390
|
|
|
391
391
|
### Custom HTTP Client
|
|
392
392
|
|
|
393
393
|
```typescript
|
|
394
|
-
import { HttpClient } from '@
|
|
394
|
+
import { HttpClient } from '@ondb/sdk';
|
|
395
395
|
|
|
396
396
|
class MyHttpClient implements HttpClient {
|
|
397
397
|
async post(url: string, data: any, headers?: Record<string, string>): Promise<any> {
|
package/src/query-sdk/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface DateRange {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Main SDK exports
|
|
44
|
-
export {
|
|
44
|
+
export {OnDB} from './OnDB';
|
|
45
45
|
export {QueryBuilder, JoinBuilder, ServerJoinConfig, GroupByQueryBuilder} from './QueryBuilder';
|
|
46
46
|
export {SelectionBuilder} from './SelectionBuilder';
|
|
47
47
|
export {ConditionBuilder} from './ConditionBuilder';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { OnDBClient } from '../client';
|
|
3
3
|
import { CreateQueryRequest } from '../types';
|
|
4
4
|
|
|
5
5
|
// Spy on axios.create so we can capture the instance handed to the client
|
|
@@ -11,7 +11,7 @@ let mockHttp: {
|
|
|
11
11
|
interceptors: { request: { use: jest.Mock }; response: { use: jest.Mock } };
|
|
12
12
|
};
|
|
13
13
|
let createSpy: jest.SpyInstance;
|
|
14
|
-
let client:
|
|
14
|
+
let client: OnDBClient;
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
17
17
|
mockHttp = {
|
|
@@ -25,7 +25,7 @@ beforeEach(() => {
|
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
createSpy = jest.spyOn(axios, 'create').mockReturnValue(mockHttp as any);
|
|
28
|
-
client = new
|
|
28
|
+
client = new OnDBClient({
|
|
29
29
|
endpoint: 'http://localhost:9092',
|
|
30
30
|
appId: 'test_app',
|
|
31
31
|
appKey: 'key123',
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OnDBClient } from '../client';
|
|
2
2
|
import { ValidationError } from '../types';
|
|
3
3
|
|
|
4
4
|
// These tests cover pure validation logic that throws before any HTTP is made.
|
|
5
5
|
// No axios mock required — the errors fire synchronously before any await.
|
|
6
6
|
|
|
7
|
-
const clientWithApp = new
|
|
7
|
+
const clientWithApp = new OnDBClient({
|
|
8
8
|
endpoint: 'http://localhost:9092',
|
|
9
9
|
appId: 'test_app',
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
const clientNoApp = new
|
|
12
|
+
const clientNoApp = new OnDBClient({
|
|
13
13
|
endpoint: 'http://localhost:9092',
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('OnDBClient — store() validation', () => {
|
|
17
17
|
test('throws when data is empty array', async () => {
|
|
18
18
|
await expect(
|
|
19
19
|
clientWithApp.store({ collection: 'col', data: [] })
|
|
@@ -52,7 +52,7 @@ describe('OnChainDBClient — store() validation', () => {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
describe('
|
|
55
|
+
describe('OnDBClient — appId-required methods throw ValidationError when appId is missing', () => {
|
|
56
56
|
const cases: Array<[string, () => Promise<any>]> = [
|
|
57
57
|
['setupSharding()', () => clientNoApp.setupSharding('col', { keys: [], enforce_in_queries: false })],
|
|
58
58
|
['syncCollection()', () => clientNoApp.syncCollection({ name: 'col', fields: {} })],
|
package/src/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryValue } from "./query-sdk";
|
|
2
|
-
export interface
|
|
2
|
+
export interface OnDBConfig {
|
|
3
3
|
endpoint: string;
|
|
4
4
|
apiKey?: string;
|
|
5
5
|
appId?: string;
|
|
@@ -68,25 +68,25 @@ export interface TransactionEvents {
|
|
|
68
68
|
'transaction:failed': (tx: TransactionStatus) => void;
|
|
69
69
|
'error': (error: Error) => void;
|
|
70
70
|
}
|
|
71
|
-
export declare class
|
|
71
|
+
export declare class OnDBError extends Error {
|
|
72
72
|
code: string;
|
|
73
73
|
statusCode?: number | undefined;
|
|
74
74
|
details?: any | undefined;
|
|
75
75
|
constructor(message: string, code: string, statusCode?: number | undefined, details?: any | undefined);
|
|
76
76
|
}
|
|
77
|
-
export declare class TransactionError extends
|
|
77
|
+
export declare class TransactionError extends OnDBError {
|
|
78
78
|
transactionId: string;
|
|
79
79
|
constructor(message: string, transactionId: string, details?: any);
|
|
80
80
|
}
|
|
81
|
-
export declare class ValidationError extends
|
|
81
|
+
export declare class ValidationError extends OnDBError {
|
|
82
82
|
constructor(message: string, details?: any);
|
|
83
83
|
}
|
|
84
|
-
export declare class PaymentRequiredError extends
|
|
84
|
+
export declare class PaymentRequiredError extends OnDBError {
|
|
85
85
|
requiredAmount: number;
|
|
86
86
|
providedAmount?: number | undefined;
|
|
87
87
|
constructor(message: string, requiredAmount: number, providedAmount?: number | undefined, details?: any);
|
|
88
88
|
}
|
|
89
|
-
export declare class PaymentVerificationError extends
|
|
89
|
+
export declare class PaymentVerificationError extends OnDBError {
|
|
90
90
|
txHash: string;
|
|
91
91
|
constructor(message: string, txHash: string, details?: any);
|
|
92
92
|
}
|
package/src/types.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PaymentVerificationError = exports.PaymentRequiredError = exports.ValidationError = exports.TransactionError = exports.
|
|
3
|
+
exports.PaymentVerificationError = exports.PaymentRequiredError = exports.ValidationError = exports.TransactionError = exports.OnDBError = void 0;
|
|
4
4
|
// Error Types
|
|
5
|
-
class
|
|
5
|
+
class OnDBError extends Error {
|
|
6
6
|
constructor(message, code, statusCode, details) {
|
|
7
7
|
super(message);
|
|
8
8
|
this.code = code;
|
|
9
9
|
this.statusCode = statusCode;
|
|
10
10
|
this.details = details;
|
|
11
|
-
this.name = '
|
|
11
|
+
this.name = 'OnDBError';
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
exports.
|
|
15
|
-
class TransactionError extends
|
|
14
|
+
exports.OnDBError = OnDBError;
|
|
15
|
+
class TransactionError extends OnDBError {
|
|
16
16
|
constructor(message, transactionId, details) {
|
|
17
17
|
super(message, 'TRANSACTION_ERROR', undefined, details);
|
|
18
18
|
this.transactionId = transactionId;
|
|
@@ -20,14 +20,14 @@ class TransactionError extends OnChainDBError {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
exports.TransactionError = TransactionError;
|
|
23
|
-
class ValidationError extends
|
|
23
|
+
class ValidationError extends OnDBError {
|
|
24
24
|
constructor(message, details) {
|
|
25
25
|
super(message, 'VALIDATION_ERROR', 400, details);
|
|
26
26
|
this.name = 'ValidationError';
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
exports.ValidationError = ValidationError;
|
|
30
|
-
class PaymentRequiredError extends
|
|
30
|
+
class PaymentRequiredError extends OnDBError {
|
|
31
31
|
constructor(message, requiredAmount, providedAmount, details) {
|
|
32
32
|
super(message, 'PAYMENT_REQUIRED', 402, details);
|
|
33
33
|
this.requiredAmount = requiredAmount;
|
|
@@ -36,7 +36,7 @@ class PaymentRequiredError extends OnChainDBError {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.PaymentRequiredError = PaymentRequiredError;
|
|
39
|
-
class PaymentVerificationError extends
|
|
39
|
+
class PaymentVerificationError extends OnDBError {
|
|
40
40
|
constructor(message, txHash, details) {
|
|
41
41
|
super(message, 'PAYMENT_VERIFICATION_FAILED', 402, details);
|
|
42
42
|
this.txHash = txHash;
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// Core
|
|
1
|
+
// Core OnDB Types
|
|
2
2
|
import {QueryValue} from "./query-sdk";
|
|
3
3
|
import {X402Quote} from "./x402/types";
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface OnDBConfig {
|
|
6
6
|
endpoint: string;
|
|
7
7
|
apiKey?: string; // Deprecated: use appKey instead
|
|
8
8
|
appKey?: string; // App API key for write operations (X-App-Key header)
|
|
@@ -149,8 +149,8 @@ export interface QueryRequest {
|
|
|
149
149
|
export interface AdvancedQueryRequest {
|
|
150
150
|
root?: string; // Format: "app::collection" - ONLY NEW THING
|
|
151
151
|
collection?: string; // Collection name (will be combined with appId if provided)
|
|
152
|
-
find?: any; // Flexible find conditions from
|
|
153
|
-
select?: any; // Selection map from
|
|
152
|
+
find?: any; // Flexible find conditions from onDBSDK
|
|
153
|
+
select?: any; // Selection map from onDBSDK
|
|
154
154
|
|
|
155
155
|
// All existing functionality stays the same
|
|
156
156
|
filters?: Record<string, any>;
|
|
@@ -200,7 +200,7 @@ export interface TransactionEvents {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
// Error Types
|
|
203
|
-
export class
|
|
203
|
+
export class OnDBError extends Error {
|
|
204
204
|
constructor(
|
|
205
205
|
message: string,
|
|
206
206
|
public code: string,
|
|
@@ -208,11 +208,11 @@ export class OnChainDBError extends Error {
|
|
|
208
208
|
public details?: any
|
|
209
209
|
) {
|
|
210
210
|
super(message);
|
|
211
|
-
this.name = '
|
|
211
|
+
this.name = 'OnDBError';
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
export class TransactionError extends
|
|
215
|
+
export class TransactionError extends OnDBError {
|
|
216
216
|
constructor(
|
|
217
217
|
message: string,
|
|
218
218
|
public transactionId: string,
|
|
@@ -223,14 +223,14 @@ export class TransactionError extends OnChainDBError {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
export class ValidationError extends
|
|
226
|
+
export class ValidationError extends OnDBError {
|
|
227
227
|
constructor(message: string, details?: any) {
|
|
228
228
|
super(message, 'VALIDATION_ERROR', 400, details);
|
|
229
229
|
this.name = 'ValidationError';
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
export class PaymentRequiredError extends
|
|
233
|
+
export class PaymentRequiredError extends OnDBError {
|
|
234
234
|
constructor(
|
|
235
235
|
message: string,
|
|
236
236
|
public quote: X402Quote,
|
|
@@ -241,7 +241,7 @@ export class PaymentRequiredError extends OnChainDBError {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
export class PaymentVerificationError extends
|
|
244
|
+
export class PaymentVerificationError extends OnDBError {
|
|
245
245
|
constructor(
|
|
246
246
|
message: string,
|
|
247
247
|
public txHash: string,
|
|
@@ -329,42 +329,6 @@ export interface PricingQuoteRequest {
|
|
|
329
329
|
data?: any; // Sample data for price index calculation
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
export interface PricingQuoteResponse {
|
|
333
|
-
type: 'write_quote_with_indexing' | 'read_quote';
|
|
334
|
-
// Base costs
|
|
335
|
-
base_celestia_cost: number;
|
|
336
|
-
base_celestia_cost_utia: number;
|
|
337
|
-
broker_fee: number;
|
|
338
|
-
broker_fee_utia: number;
|
|
339
|
-
// Indexing costs per field
|
|
340
|
-
indexing_costs: Record<string, number>;
|
|
341
|
-
indexing_costs_utia: Record<string, number>;
|
|
342
|
-
// Total before price index fees
|
|
343
|
-
base_total_cost: number;
|
|
344
|
-
base_total_cost_utia: number;
|
|
345
|
-
// Final total (includes price index fees if any)
|
|
346
|
-
total_cost: number;
|
|
347
|
-
total_cost_utia: number;
|
|
348
|
-
// Metadata
|
|
349
|
-
indexed_fields_count: number;
|
|
350
|
-
request: PricingQuoteRequest;
|
|
351
|
-
monthly_volume_kb: number;
|
|
352
|
-
currency: string;
|
|
353
|
-
// Optional breakdowns
|
|
354
|
-
creator_premium?: {
|
|
355
|
-
premium_total: number;
|
|
356
|
-
premium_total_utia: number;
|
|
357
|
-
premium_type: string;
|
|
358
|
-
premium_amount: number;
|
|
359
|
-
creator_revenue: number;
|
|
360
|
-
creator_revenue_utia: number;
|
|
361
|
-
platform_revenue: number;
|
|
362
|
-
platform_revenue_utia: number;
|
|
363
|
-
revenue_split: string;
|
|
364
|
-
};
|
|
365
|
-
price?: any; // Price index breakdown (single or multiple fields)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
332
|
// ============================================================================
|
|
369
333
|
// Collection Schema Types (for createCollection convenience method)
|
|
370
334
|
// ============================================================================
|
package/src/x402/types.ts
CHANGED
|
@@ -47,7 +47,7 @@ export interface X402PaymentRequirement {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* x402 Extra field with
|
|
50
|
+
* x402 Extra field with OnDB extensions
|
|
51
51
|
*/
|
|
52
52
|
export interface X402Extra {
|
|
53
53
|
/** Extension identifier */
|
|
@@ -164,8 +164,8 @@ export interface X402PaymentResponse {
|
|
|
164
164
|
export interface X402Quote {
|
|
165
165
|
/** Quote ID */
|
|
166
166
|
quoteId: string;
|
|
167
|
-
/** Total cost
|
|
168
|
-
|
|
167
|
+
/** Total cost */
|
|
168
|
+
totalCost: number;
|
|
169
169
|
/** Amount in smallest units */
|
|
170
170
|
amountRaw: string;
|
|
171
171
|
/** Broker/recipient address */
|
package/src/x402/utils.ts
CHANGED
|
@@ -79,9 +79,9 @@ export function requirementToQuote(
|
|
|
79
79
|
chainType = 'solana';
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// Calculate
|
|
82
|
+
// Calculate total cost (for display purposes)
|
|
83
83
|
const decimals = extra.tokenDecimals || 6;
|
|
84
|
-
const
|
|
84
|
+
const totalCost = parseInt(amountRaw) / Math.pow(10, decimals);
|
|
85
85
|
|
|
86
86
|
// Calculate expiration
|
|
87
87
|
const expiresAt = extra.pricing?.expiresAt ||
|
|
@@ -89,7 +89,7 @@ export function requirementToQuote(
|
|
|
89
89
|
|
|
90
90
|
return {
|
|
91
91
|
quoteId: extra.quoteId || '',
|
|
92
|
-
|
|
92
|
+
totalCost,
|
|
93
93
|
amountRaw,
|
|
94
94
|
brokerAddress: requirement.payTo,
|
|
95
95
|
description: requirement.description,
|