@compose-market/core 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Compose.Market
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,17 @@
1
+ # @compose-market/core
2
+
3
+ Shared runtime primitives for Compose.Market SDKs.
4
+
5
+ This package contains the reusable, product-agnostic pieces used by higher-level
6
+ Compose clients:
7
+
8
+ - typed Compose error classes
9
+ - a dependency-free Fetch-based HTTP client with retries and timeouts
10
+ - x402 `PaymentRequired` parsing
11
+ - session-budget and receipt helpers
12
+ - SSE parsing
13
+ - minimal pluggable storage helpers
14
+
15
+ Generated Speakeasy SDK output should remain generated. Higher-level SDKs can
16
+ depend on this package as normal npm code without self-imports or generated-file
17
+ patches.
@@ -0,0 +1,133 @@
1
+ import type { ComposeErrorCode, ComposeReceipt, PaymentRequired } from "./types/index.js";
2
+ export declare class ComposeError extends Error {
3
+ readonly code: ComposeErrorCode;
4
+ readonly status?: number;
5
+ readonly details?: Record<string, unknown>;
6
+ readonly requestId?: string;
7
+ readonly headers?: Record<string, string>;
8
+ readonly body?: unknown;
9
+ constructor(input: {
10
+ code: ComposeErrorCode;
11
+ message: string;
12
+ status?: number;
13
+ details?: Record<string, unknown>;
14
+ requestId?: string;
15
+ headers?: Record<string, string>;
16
+ body?: unknown;
17
+ });
18
+ }
19
+ export declare class ComposeAPIError extends ComposeError {
20
+ constructor(input: {
21
+ code: ComposeErrorCode;
22
+ message: string;
23
+ status: number;
24
+ details?: Record<string, unknown>;
25
+ requestId?: string;
26
+ headers?: Record<string, string>;
27
+ body?: unknown;
28
+ });
29
+ }
30
+ export declare class BadRequestError extends ComposeAPIError {
31
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
32
+ code?: ComposeErrorCode;
33
+ });
34
+ }
35
+ export declare class AuthenticationError extends ComposeAPIError {
36
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
37
+ code?: ComposeErrorCode;
38
+ });
39
+ }
40
+ export declare class PermissionDeniedError extends ComposeAPIError {
41
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
42
+ code?: ComposeErrorCode;
43
+ });
44
+ }
45
+ export declare class NotFoundError extends ComposeAPIError {
46
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
47
+ code?: ComposeErrorCode;
48
+ });
49
+ }
50
+ export declare class ConflictError extends ComposeAPIError {
51
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
52
+ code?: ComposeErrorCode;
53
+ });
54
+ }
55
+ export declare class UnprocessableEntityError extends ComposeAPIError {
56
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
57
+ code?: ComposeErrorCode;
58
+ });
59
+ }
60
+ export declare class RateLimitError extends ComposeAPIError {
61
+ readonly retryAfter?: number;
62
+ constructor(input: Omit<ConstructorParameters<typeof ComposeAPIError>[0], "status" | "code"> & {
63
+ code?: ComposeErrorCode;
64
+ retryAfter?: number;
65
+ });
66
+ }
67
+ export declare class InternalServerError extends ComposeAPIError {
68
+ constructor(input: {
69
+ code?: ComposeErrorCode;
70
+ message: string;
71
+ status?: number;
72
+ details?: Record<string, unknown>;
73
+ requestId?: string;
74
+ headers?: Record<string, string>;
75
+ body?: unknown;
76
+ });
77
+ }
78
+ export declare class ComposePaymentRequiredError extends ComposeAPIError {
79
+ readonly paymentRequired: PaymentRequired | null;
80
+ readonly paymentRequiredHeader: string | null;
81
+ constructor(input: {
82
+ code?: ComposeErrorCode;
83
+ message: string;
84
+ details?: Record<string, unknown>;
85
+ requestId?: string;
86
+ headers?: Record<string, string>;
87
+ body?: unknown;
88
+ paymentRequired: PaymentRequired | null;
89
+ paymentRequiredHeader: string | null;
90
+ });
91
+ }
92
+ export declare class ComposeBudgetExhaustedError extends ComposeAPIError {
93
+ constructor(input: {
94
+ message: string;
95
+ details?: Record<string, unknown>;
96
+ requestId?: string;
97
+ headers?: Record<string, string>;
98
+ body?: unknown;
99
+ });
100
+ }
101
+ export declare class ComposeConnectionError extends ComposeError {
102
+ readonly cause?: unknown;
103
+ constructor(input: {
104
+ message: string;
105
+ cause?: unknown;
106
+ requestId?: string;
107
+ });
108
+ }
109
+ export declare class ComposeTimeoutError extends ComposeError {
110
+ constructor(input: {
111
+ message: string;
112
+ requestId?: string;
113
+ });
114
+ }
115
+ export interface ComposeCallFailure {
116
+ code: ComposeErrorCode;
117
+ message: string;
118
+ details?: Record<string, unknown>;
119
+ receipt?: ComposeReceipt;
120
+ }
121
+ export declare function buildApiError(input: {
122
+ status: number;
123
+ code: ComposeErrorCode;
124
+ message: string;
125
+ details?: Record<string, unknown>;
126
+ requestId?: string;
127
+ headers?: Record<string, string>;
128
+ body?: unknown;
129
+ paymentRequired?: PaymentRequired | null;
130
+ paymentRequiredHeader?: string | null;
131
+ retryAfter?: number;
132
+ }): ComposeAPIError;
133
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,gBAAgB,EAChB,cAAc,EACd,eAAe,EAClB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,YAAa,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEZ,KAAK,EAAE;QACf,IAAI,EAAE,gBAAgB,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,OAAO,CAAC;KAClB;CAUJ;AAED,qBAAa,eAAgB,SAAQ,YAAY;gBACjC,KAAK,EAAE;QACf,IAAI,EAAE,gBAAgB,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,C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M,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,eAAe,CA4BlB"}
package/dist/errors.js ADDED
@@ -0,0 +1,148 @@
1
+ export class ComposeError extends Error {
2
+ code;
3
+ status;
4
+ details;
5
+ requestId;
6
+ headers;
7
+ body;
8
+ constructor(input) {
9
+ super(input.message);
10
+ this.name = "ComposeError";
11
+ this.code = input.code;
12
+ this.status = input.status;
13
+ this.details = input.details;
14
+ this.requestId = input.requestId;
15
+ this.headers = input.headers;
16
+ this.body = input.body;
17
+ }
18
+ }
19
+ export class ComposeAPIError extends ComposeError {
20
+ constructor(input) {
21
+ super(input);
22
+ this.name = "ComposeAPIError";
23
+ }
24
+ }
25
+ export class BadRequestError extends ComposeAPIError {
26
+ constructor(input) {
27
+ super({ code: input.code ?? "validation_error", ...input, status: 400 });
28
+ this.name = "BadRequestError";
29
+ }
30
+ }
31
+ export class AuthenticationError extends ComposeAPIError {
32
+ constructor(input) {
33
+ super({ code: input.code ?? "authentication_failed", ...input, status: 401 });
34
+ this.name = "AuthenticationError";
35
+ }
36
+ }
37
+ export class PermissionDeniedError extends ComposeAPIError {
38
+ constructor(input) {
39
+ super({ code: input.code ?? "forbidden", ...input, status: 403 });
40
+ this.name = "PermissionDeniedError";
41
+ }
42
+ }
43
+ export class NotFoundError extends ComposeAPIError {
44
+ constructor(input) {
45
+ super({ code: input.code ?? "not_found", ...input, status: 404 });
46
+ this.name = "NotFoundError";
47
+ }
48
+ }
49
+ export class ConflictError extends ComposeAPIError {
50
+ constructor(input) {
51
+ super({ code: input.code ?? "conflict", ...input, status: 409 });
52
+ this.name = "ConflictError";
53
+ }
54
+ }
55
+ export class UnprocessableEntityError extends ComposeAPIError {
56
+ constructor(input) {
57
+ super({ code: input.code ?? "validation_error", ...input, status: 422 });
58
+ this.name = "UnprocessableEntityError";
59
+ }
60
+ }
61
+ export class RateLimitError extends ComposeAPIError {
62
+ retryAfter;
63
+ constructor(input) {
64
+ super({ code: input.code ?? "rate_limited", ...input, status: 429 });
65
+ this.name = "RateLimitError";
66
+ this.retryAfter = input.retryAfter;
67
+ }
68
+ }
69
+ export class InternalServerError extends ComposeAPIError {
70
+ constructor(input) {
71
+ super({
72
+ code: input.code ?? "internal_error",
73
+ status: input.status ?? 500,
74
+ message: input.message,
75
+ details: input.details,
76
+ requestId: input.requestId,
77
+ headers: input.headers,
78
+ body: input.body,
79
+ });
80
+ this.name = "InternalServerError";
81
+ }
82
+ }
83
+ export class ComposePaymentRequiredError extends ComposeAPIError {
84
+ paymentRequired;
85
+ paymentRequiredHeader;
86
+ constructor(input) {
87
+ super({ code: input.code ?? "payment_required", ...input, status: 402 });
88
+ this.name = "ComposePaymentRequiredError";
89
+ this.paymentRequired = input.paymentRequired;
90
+ this.paymentRequiredHeader = input.paymentRequiredHeader;
91
+ }
92
+ }
93
+ export class ComposeBudgetExhaustedError extends ComposeAPIError {
94
+ constructor(input) {
95
+ super({ code: "budget_exhausted", ...input, status: 402 });
96
+ this.name = "ComposeBudgetExhaustedError";
97
+ }
98
+ }
99
+ export class ComposeConnectionError extends ComposeError {
100
+ cause;
101
+ constructor(input) {
102
+ super({ code: "network_error", ...input });
103
+ this.name = "ComposeConnectionError";
104
+ this.cause = input.cause;
105
+ }
106
+ }
107
+ export class ComposeTimeoutError extends ComposeError {
108
+ constructor(input) {
109
+ super({ code: "timeout", ...input });
110
+ this.name = "ComposeTimeoutError";
111
+ }
112
+ }
113
+ export function buildApiError(input) {
114
+ const base = {
115
+ code: input.code,
116
+ message: input.message,
117
+ details: input.details,
118
+ requestId: input.requestId,
119
+ headers: input.headers,
120
+ body: input.body,
121
+ };
122
+ if (input.status === 402) {
123
+ if (input.code === "budget_exhausted") {
124
+ return new ComposeBudgetExhaustedError(base);
125
+ }
126
+ return new ComposePaymentRequiredError({
127
+ ...base,
128
+ paymentRequired: input.paymentRequired ?? null,
129
+ paymentRequiredHeader: input.paymentRequiredHeader ?? null,
130
+ });
131
+ }
132
+ if (input.status === 400)
133
+ return new BadRequestError(base);
134
+ if (input.status === 401)
135
+ return new AuthenticationError(base);
136
+ if (input.status === 403)
137
+ return new PermissionDeniedError(base);
138
+ if (input.status === 404)
139
+ return new NotFoundError(base);
140
+ if (input.status === 409)
141
+ return new ConflictError(base);
142
+ if (input.status === 422)
143
+ return new UnprocessableEntityError(base);
144
+ if (input.status === 429)
145
+ return new RateLimitError({ ...base, retryAfter: input.retryAfter });
146
+ return new InternalServerError({ ...base, status: input.status });
147
+ }
148
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC1B,IAAI,CAAmB;IACvB,MAAM,CAAU;IAChB,OAAO,CAA2B;IAClC,SAAS,CAAU;IACnB,OAAO,CAA0B;IACjC,IAAI,CAAW;IAExB,YAAY,KAQX;QACG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IAC3B,CAAC;CACJ;AAED,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC7C,YAAY,KAQX;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+ import type { PaymentRequired } from "./types/index.js";
2
+ export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface RetryPolicy {
4
+ maxRetries: number;
5
+ initialDelayMs: number;
6
+ maxDelayMs: number;
7
+ jitter: boolean;
8
+ }
9
+ export interface HttpClientOptions {
10
+ baseUrl: string;
11
+ fetch: FetchLike;
12
+ timeoutMs: number;
13
+ defaultHeaders: Record<string, string>;
14
+ retry: RetryPolicy;
15
+ userAgent: string;
16
+ logger?: {
17
+ debug?: (msg: string, meta?: Record<string, unknown>) => void;
18
+ warn?: (msg: string, meta?: Record<string, unknown>) => void;
19
+ error?: (msg: string, meta?: Record<string, unknown>) => void;
20
+ };
21
+ }
22
+ export interface HeaderBagInput {
23
+ authJwt?: string;
24
+ composeKey?: string | null;
25
+ userAddress?: string | null;
26
+ chainId?: number | null;
27
+ paymentSignature?: string;
28
+ x402MaxAmountWei?: string;
29
+ idempotencyKey?: string;
30
+ composeRunId?: string;
31
+ requestId?: string;
32
+ extra?: Record<string, string | undefined>;
33
+ }
34
+ export interface RequestOptions {
35
+ method: string;
36
+ path: string;
37
+ query?: Record<string, string | number | boolean | null | undefined>;
38
+ body?: unknown;
39
+ bodyType?: "json" | "form-data" | "raw";
40
+ rawBody?: BodyInit;
41
+ headers?: HeaderBagInput;
42
+ expectStream?: boolean;
43
+ signal?: AbortSignal;
44
+ timeoutMs?: number;
45
+ retry?: Partial<RetryPolicy>;
46
+ doNotRetry?: boolean;
47
+ }
48
+ export interface APIPromise<T> extends PromiseLike<T> {
49
+ asResponse(): Promise<Response>;
50
+ withResponse(): Promise<{
51
+ data: T;
52
+ response: Response;
53
+ }>;
54
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
55
+ finally(onfinally?: (() => void) | null): Promise<T>;
56
+ }
57
+ export declare const SDK_CLIENT_HEADER = "x-compose-sdk";
58
+ export declare function isBrowserLikeRuntime(): boolean;
59
+ export declare function applySdkClientHeaders(headers: Headers, userAgent: string): void;
60
+ export declare function normalizeAtomicAmount(value: string, fieldName: string): string;
61
+ export declare function buildHeaders(input: HeaderBagInput & {
62
+ defaultHeaders: Record<string, string>;
63
+ userAgent: string;
64
+ bodyType?: "json" | "form-data" | "raw";
65
+ }): Headers;
66
+ export declare function extractPaymentRequired(body: unknown, header: string | null): PaymentRequired | null;
67
+ export declare class HttpClient {
68
+ private readonly options;
69
+ constructor(options: HttpClientOptions);
70
+ request<T>(config: RequestOptions): APIPromise<T>;
71
+ private executeRaw;
72
+ private computeBackoff;
73
+ private encodeBody;
74
+ private parseResponseBody;
75
+ private safeReadJson;
76
+ }
77
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGR,eAAe,EAClB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,SAAS,GAAG,CACpB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,MAAM,WAAW,WAAW;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,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