diff --git a/.changeset/dull-berries-hide.md b/.changeset/dull-berries-hide.md new file mode 100644 index 0000000..fe6bc80 --- /dev/null +++ b/.changeset/dull-berries-hide.md @@ -0,0 +1,5 @@ +--- +"@coinbase-platform/commerce": minor +--- + +feat: add `commerce` package diff --git a/examples/commerce_create-charge/README.md b/examples/commerce_create-charge/README.md new file mode 100644 index 0000000..ab4e376 --- /dev/null +++ b/examples/commerce_create-charge/README.md @@ -0,0 +1,7 @@ +# Create charge - Commerce + +Run + +```sh +$ bun run index.ts +``` diff --git a/examples/commerce_create-charge/index.ts b/examples/commerce_create-charge/index.ts new file mode 100644 index 0000000..1bd6604 --- /dev/null +++ b/examples/commerce_create-charge/index.ts @@ -0,0 +1,21 @@ +import { + type CreateChargeParameters, + createCharge, +} from "@coinbase-platform/commerce"; + +const apiKey = process.env.API_KEY; +if (!apiKey) throw new Error("API_KEY not found"); + +const parameters: CreateChargeParameters = { + name: "Nvidia RTX 4080", + description: "Graphic Card", + pricing_type: "fixed_price", + local_price: { + amount: "1000.00", + currency: "USD", + }, +}; + +const response = await createCharge(parameters, apiKey); + +console.log(JSON.stringify(response, null, 2)); diff --git a/examples/commerce_create-charge/package.json b/examples/commerce_create-charge/package.json new file mode 100644 index 0000000..9976c0c --- /dev/null +++ b/examples/commerce_create-charge/package.json @@ -0,0 +1,16 @@ +{ + "name": "@examples/commerce_create-charge", + "private": true, + "module": "index.ts", + "type": "module", + "scripts": { + "clean": "rimraf ./node_modules", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@coinbase-platform/commerce": "workspace:*" + }, + "devDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/examples/commerce_create-charge/tsconfig.json b/examples/commerce_create-charge/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/examples/commerce_create-charge/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/examples/commerce_create-checkout/README.md b/examples/commerce_create-checkout/README.md new file mode 100644 index 0000000..a9e3edb --- /dev/null +++ b/examples/commerce_create-checkout/README.md @@ -0,0 +1,7 @@ +# Create checkout - Commerce + +Run + +```sh +$ bun run index.ts +``` diff --git a/examples/commerce_create-checkout/index.ts b/examples/commerce_create-checkout/index.ts new file mode 100644 index 0000000..7677e4b --- /dev/null +++ b/examples/commerce_create-checkout/index.ts @@ -0,0 +1,23 @@ +import { + type CreateCheckoutParameters, + createCheckout, +} from "@coinbase-platform/commerce"; + +const apiKey = process.env.API_KEY; +if (!apiKey) throw new Error("API_KEY not found"); + +const parameters: CreateCheckoutParameters = { + name: "Nvidia RTX 4080", + description: "Graphic Card", + pricing_type: "fixed_price", + local_price: { + amount: "1000.00", + currency: "USD", + }, + logo_url: "", + requested_info: [], +}; + +const response = await createCheckout(parameters, apiKey); + +console.log(JSON.stringify(response, null, 2)); diff --git a/examples/commerce_create-checkout/package.json b/examples/commerce_create-checkout/package.json new file mode 100644 index 0000000..1a80fe5 --- /dev/null +++ b/examples/commerce_create-checkout/package.json @@ -0,0 +1,16 @@ +{ + "name": "@examples/commerce_create-checkout", + "private": true, + "module": "index.ts", + "type": "module", + "scripts": { + "clean": "rimraf ./node_modules", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@coinbase-platform/commerce": "workspace:*" + }, + "devDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/examples/commerce_create-checkout/tsconfig.json b/examples/commerce_create-checkout/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/examples/commerce_create-checkout/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/examples/commerce_get-charges/README.md b/examples/commerce_get-charges/README.md new file mode 100644 index 0000000..aae519a --- /dev/null +++ b/examples/commerce_get-charges/README.md @@ -0,0 +1,7 @@ +# Get charge - Commerce + +Run + +```sh +$ bun run index.ts +``` diff --git a/examples/commerce_get-charges/index.ts b/examples/commerce_get-charges/index.ts new file mode 100644 index 0000000..7bb7d67 --- /dev/null +++ b/examples/commerce_get-charges/index.ts @@ -0,0 +1,13 @@ +import { getCharge, getCharges } from "@coinbase-platform/commerce"; + +const apiKey = process.env.API_KEY; +if (!apiKey) throw new Error("API_KEY not found"); + +// Get a charge by id +const chargeId = "fb86d331-1db8-44f2-a96c-235d2a855ad3"; +const charge = await getCharge(chargeId, apiKey); +console.log(JSON.stringify(charge, null, 2)); + +// Get all charges +const charges = await getCharges(apiKey); +console.log(JSON.stringify(charges, null, 2)); diff --git a/examples/commerce_get-charges/package.json b/examples/commerce_get-charges/package.json new file mode 100644 index 0000000..8f1bd93 --- /dev/null +++ b/examples/commerce_get-charges/package.json @@ -0,0 +1,16 @@ +{ + "name": "@examples/commerce_get-charges", + "private": true, + "module": "index.ts", + "type": "module", + "scripts": { + "clean": "rimraf ./node_modules", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@coinbase-platform/commerce": "workspace:*" + }, + "devDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/examples/commerce_get-charges/tsconfig.json b/examples/commerce_get-charges/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/examples/commerce_get-charges/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/examples/commerce_get-checkouts/README.md b/examples/commerce_get-checkouts/README.md new file mode 100644 index 0000000..4ed0a86 --- /dev/null +++ b/examples/commerce_get-checkouts/README.md @@ -0,0 +1,7 @@ +# Get checkout - Commerce + +Run + +```sh +$ bun run index.ts +``` diff --git a/examples/commerce_get-checkouts/index.ts b/examples/commerce_get-checkouts/index.ts new file mode 100644 index 0000000..2bef1f1 --- /dev/null +++ b/examples/commerce_get-checkouts/index.ts @@ -0,0 +1,13 @@ +import { getCheckout, getCheckouts } from "@coinbase-platform/commerce"; + +const apiKey = process.env.API_KEY; +if (!apiKey) throw new Error("API_KEY not found"); + +// Get a checkout by id +const checkoutId = "a6e9fdd6-877d-4b2d-9d2e-70e810211b52"; +const checkout = await getCheckout(checkoutId, apiKey); +console.log(JSON.stringify(checkout, null, 2)); + +// Get all checkouts +const checkouts = await getCheckouts(apiKey); +console.log(JSON.stringify(checkouts, null, 2)); diff --git a/examples/commerce_get-checkouts/package.json b/examples/commerce_get-checkouts/package.json new file mode 100644 index 0000000..5d95cd4 --- /dev/null +++ b/examples/commerce_get-checkouts/package.json @@ -0,0 +1,16 @@ +{ + "name": "@examples/commerce_get-checkouts", + "private": true, + "module": "index.ts", + "type": "module", + "scripts": { + "clean": "rimraf ./node_modules", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@coinbase-platform/commerce": "workspace:*" + }, + "devDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/examples/commerce_get-checkouts/tsconfig.json b/examples/commerce_get-checkouts/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/examples/commerce_get-checkouts/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/examples/commerce_get-events/README.md b/examples/commerce_get-events/README.md new file mode 100644 index 0000000..b131558 --- /dev/null +++ b/examples/commerce_get-events/README.md @@ -0,0 +1,7 @@ +# Get events - Commerce + +Run + +```sh +$ bun run index.ts +``` diff --git a/examples/commerce_get-events/index.ts b/examples/commerce_get-events/index.ts new file mode 100644 index 0000000..32406f1 --- /dev/null +++ b/examples/commerce_get-events/index.ts @@ -0,0 +1,13 @@ +import { getEvent, getEvents } from "@coinbase-platform/commerce"; + +const apiKey = process.env.API_KEY; +if (!apiKey) throw new Error("API_KEY not found"); + +// Get an event by id +const eventId = "400ecd4e-9952-412b-9726-bdb173762b05"; +const event = await getEvent(eventId, apiKey); +console.log(JSON.stringify(event, null, 2)); + +// Get all events +const events = await getEvents(apiKey); +console.log(JSON.stringify(events.data, null, 2)); diff --git a/examples/commerce_get-events/package.json b/examples/commerce_get-events/package.json new file mode 100644 index 0000000..c93cebd --- /dev/null +++ b/examples/commerce_get-events/package.json @@ -0,0 +1,16 @@ +{ + "name": "@examples/commerce_get-events", + "private": true, + "module": "index.ts", + "type": "module", + "scripts": { + "clean": "rimraf ./node_modules", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@coinbase-platform/commerce": "workspace:*" + }, + "devDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/examples/commerce_get-events/tsconfig.json b/examples/commerce_get-events/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/examples/commerce_get-events/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/packages/commerce/package.json b/packages/commerce/package.json new file mode 100644 index 0000000..9a9ff61 --- /dev/null +++ b/packages/commerce/package.json @@ -0,0 +1,53 @@ +{ + "name": "@coinbase-platform/commerce", + "version": "0.0.0", + "description": "Coinbase Platform Commerce package", + "author": "roushou ", + "license": "MIT", + "homepage": "https://github.com/roushou/coinbase-platform#readme", + "type": "module", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", + "typings": "./dist/index.d.ts", + "repository": { + "type": "git", + "url": "git+https://github.com/roushou/coinbase-platform.git", + "directory": "packages/commerce" + }, + "bugs": { + "url": "https://github.com/roushou/coinbase-platform/issues" + }, + "publishConfig": { + "access": "public" + }, + "keywords": ["coinbase", "coinbase platform"], + "scripts": { + "build": "pnpm clean && tsup", + "clean": "rimraf ./dist", + "typecheck": "tsc --noEmit" + }, + "devDependencies": { + "@coinbase-platform/utils": "workspace:*" + }, + "peerDependencies": { + "typescript": ">=5.0.4" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + }, + "exports": { + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "./package.json": "./package.json" + }, + "files": ["src", "dist"], + "engine": { + "node": "^18.0.0 || >=20.0.0" + } +} diff --git a/packages/commerce/src/charge.ts b/packages/commerce/src/charge.ts new file mode 100644 index 0000000..85efb3c --- /dev/null +++ b/packages/commerce/src/charge.ts @@ -0,0 +1,171 @@ +import * as http from "@coinbase-platform/utils/http"; +import { BASE_URL } from "./constants"; + +export type GetChargeResponse = { + data: Charge; + warnings: string[]; +}; + +export async function getCharge( + id: string, + apiKey: string, +): Promise { + return await http.get(`${BASE_URL}/charges/${id}`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + }); +} + +export type GetChargesResponse = { + data: Charge[]; + warnings: string[]; +}; + +export async function getCharges(apiKey: string): Promise { + return await http.get(`${BASE_URL}/charges`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + }); +} + +export type CreateChargeParameters = { + name: string; + description: string; + pricing_type: ChargePricingType; + local_price: { + amount: string; + currency: string; + }; +}; + +export type CreateChargeResponse = { + data: Charge; + warnings: string[]; +}; + +export async function createCharge( + parameters: CreateChargeParameters, + apiKey: string, +): Promise { + return await http.post(`${BASE_URL}/charges`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + body: JSON.stringify(parameters), + }); +} + +export type ChargePricingType = "fixed_price" | "no_price"; + +export type Charge = { + brand_color: string; + brand_logo_url: string; + charge_kind: "WEB3"; + checkout: { + id: string; + }; + code: string; + collected_email: boolean; + confirmed_at: string; + created_at: string; + description: string; + expires_at: string; + hosted_url: string; + id: string; + // TODO: add type + // metadata: any; + name: string; + organization_name: string; + // TODO: check type + payments: string[]; + pricing: { + local: { + amount: string; + currency: string; + }; + settlement: { + amount: string; + currency: string; + }; + }; + pricing_type: ChargePricingType; + pwcb_only: boolean; + redirects: { + cancel_url: string; + success_url: string; + will_redirect_after_success: boolean; + }; + support_email: string; + third_party_provider: string; + timeline: { + status: "COMPLETED" | "EXPIRED" | "FAILED" | "NEW" | "PENDING" | "SIGNED"; + time: string; + }; + web3_data: { + contract_caller_request_id: string; + failure_events: Array<{ + input_token_address: string; + network_fee_paid: string; + reason: string; + sender: string; + timestamp: string; + tx_hash: string; + }>; + settlement_currency_addresses: Record; + subsidized_payments_chain_to_tokens: Record< + string, + { tokenAddresses: string[] } + >; + success_events: Array<{ + finalized: boolean; + input_token_address: string; + input_token_amount: string; + network_fee_paid: string; + recipient: string; + sender: string; + timestamp: string; + tx_hash: string; + }>; + transfer_intent: { + call_data: { + deadline: string; + fee_amount: string; + id: string; + operator: string; + prefix: string; + recipient: string; + recipient_amount: string; + recipient_currency: string; + refund_destination: string; + signature: string; + }; + metadata: { + chain_id: number; + contract_address: string; + sender: string; + }; + contract_address: string; + contract_addresses: Record; + } | null; + }; + web3_retail_payment_metadata: { + quote_id: string; + source_amount: { + amount: string | null; + currency: string | null; + }; + exchange_rate_with_spread: { + amount: string | null; + currency: string | null; + }; + exchange_rate_without_spread: { + amount: string | null; + currency: string | null; + }; + max_retail_payment_value_usd: number; + fees: string[]; + }; + web3_retail_payments_enabled: boolean; +}; diff --git a/packages/commerce/src/checkout.ts b/packages/commerce/src/checkout.ts new file mode 100644 index 0000000..5a6cc27 --- /dev/null +++ b/packages/commerce/src/checkout.ts @@ -0,0 +1,92 @@ +import * as http from "@coinbase-platform/utils/http"; +import { BASE_URL } from "./constants"; + +type GetCheckoutResponse = { + data: Checkout; + warning: string[]; +}; + +export async function getCheckout( + id: string, + apiKey: string, +): Promise { + return await http.get(`${BASE_URL}/checkouts/${id}`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + }); +} + +type GetCheckoutsResponse = { + data: Checkout[]; + warning: string[]; +}; + +export async function getCheckouts( + apiKey: string, +): Promise { + return await http.get(`${BASE_URL}/checkouts`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + }); +} + +type CheckoutRequestInfo = + | "name" + | "email" + | "address" + | "phone" + | "employer" + | "occupation"; + +export type CreateCheckoutParameters = { + name: string; + description: string; + local_price: { + amount: string; + currency: string; + }; + logo_url: string; + pricing_type: CheckoutPricingType; + requested_info: CheckoutRequestInfo[]; +}; + +export type CreateCheckoutResponse = { + data: Checkout; + warnings: string[]; +}; + +export async function createCheckout( + parameters: CreateCheckoutParameters, + apiKey: string, +): Promise { + return await http.post(`${BASE_URL}/checkouts`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + body: JSON.stringify(parameters), + }); +} + +export type CheckoutPricingType = "fixed_price" | "no_price"; + +export type Checkout = { + brand_color: string; + brand_logo_url: string; + coinbase_managed_merchant: boolean; + created_at: string; + description: string; + id: string; + local_price: { + amount: string | null; + currency: string | null; + }; + logo_url: string; + name: string; + organization_name: string; + pricing_type: CheckoutPricingType; + requested_info: CheckoutRequestInfo[]; + resource: string; + updated_at: string; +}; diff --git a/packages/commerce/src/client.ts b/packages/commerce/src/client.ts new file mode 100644 index 0000000..ae1060c --- /dev/null +++ b/packages/commerce/src/client.ts @@ -0,0 +1,75 @@ +import { + type Charge, + type CreateChargeParameters, + createCharge, + getCharge, + getCharges, +} from "./charge"; +import { + type Checkout, + type CreateCheckoutParameters, + createCheckout, + getCheckout, + getCheckouts, +} from "./checkout"; +import { BASE_URL } from "./constants"; +import { type Event, getEvent, getEvents } from "./events"; + +export type Client = { + __url: string; + createCharge: (parameters: CreateChargeParameters) => Promise; + createCheckout: (parameters: CreateCheckoutParameters) => Promise; + getCharge: (id: string) => Promise; + getCharges: () => Promise; + getCheckout: (id: string) => Promise; + getCheckouts: () => Promise; + getEvent: (id: string) => Promise; + getEvents: () => Promise; +}; + +export type ClientConfig = { + apiKey: string; + baseUrl?: string; +}; + +export function createClient(config: ClientConfig): Client { + const url = config.baseUrl ?? BASE_URL; + + const client: Client = { + __url: url, + createCharge: async (parameters) => { + const response = await createCharge(parameters, config.apiKey); + return response.data; + }, + createCheckout: async (parameters) => { + const response = await createCheckout(parameters, config.apiKey); + return response.data; + }, + getCharge: async (id) => { + const response = await getCharge(id, config.apiKey); + return response.data; + }, + getCharges: async () => { + const response = await getCharges(config.apiKey); + return response.data; + }, + getCheckout: async (id) => { + const response = await getCheckout(id, config.apiKey); + return response.data; + }, + getCheckouts: async () => { + const response = await getCheckouts(config.apiKey); + return response.data; + }, + getEvent: async (id) => { + const response = await getEvent(id, config.apiKey); + return response.data; + }, + getEvents: async () => { + const response = await getEvents(config.apiKey); + return response.data; + }, + }; + + return client; +} diff --git a/packages/commerce/src/constants.ts b/packages/commerce/src/constants.ts new file mode 100644 index 0000000..f6d0c19 --- /dev/null +++ b/packages/commerce/src/constants.ts @@ -0,0 +1 @@ +export const BASE_URL = "https://api.commerce.coinbase.com"; diff --git a/packages/commerce/src/events.ts b/packages/commerce/src/events.ts new file mode 100644 index 0000000..bf89c49 --- /dev/null +++ b/packages/commerce/src/events.ts @@ -0,0 +1,53 @@ +import * as http from "@coinbase-platform/utils/http"; +import type { Charge } from "./charge"; +import type { Checkout } from "./checkout"; +import { BASE_URL } from "./constants"; + +export type GetEventResponse = { + data: Event; + warnings: string[]; +}; + +export async function getEvent( + id: string, + apiKey: string, +): Promise { + return await http.get(`${BASE_URL}/events/${id}`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + }); +} + +export type GetEventsResponse = { + pagination: { + order: "asc" | "desc"; + starting_after: string | null; + ending_before: string | null; + total: number; + limit: number; + yielded: number; + cursor_range: string[]; + previous_uri: string[]; + next_uri: string; + }; + data: Array; +}; + +export async function getEvents(apiKey: string): Promise { + return await http.get(`${BASE_URL}/events`, { + headers: { + "X-CC-Api-Key": apiKey, + }, + }); +} + +export type Event = { + api_version: string; + created_at: string; + data: Charge | Checkout; + id: string; + resource: "event"; + // TODO: should be a union + type: string; +}; diff --git a/packages/commerce/src/index.ts b/packages/commerce/src/index.ts new file mode 100644 index 0000000..45b00e1 --- /dev/null +++ b/packages/commerce/src/index.ts @@ -0,0 +1,19 @@ +export { createClient } from "./client"; +export type { Client, ClientConfig } from "./client"; +export { createCharge, getCharge, getCharges } from "./charge"; +export type { + Charge, + ChargePricingType, + CreateChargeParameters, + CreateChargeResponse, + GetChargeResponse, + GetChargesResponse, +} from "./charge"; +export { createCheckout, getCheckout, getCheckouts } from "./checkout"; +export type { + CheckoutPricingType, + CreateCheckoutParameters, + CreateCheckoutResponse, +} from "./checkout"; +export { getEvent, getEvents } from "./events"; +export type { Event, GetEventResponse, GetEventsResponse } from "./events"; diff --git a/packages/commerce/tsconfig.json b/packages/commerce/tsconfig.json new file mode 100644 index 0000000..280ad24 --- /dev/null +++ b/packages/commerce/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "allowJs": false, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": true, + "noUnusedParameters": true, + "noPropertyAccessFromIndexSignature": false, + + "types": ["vitest/importMeta"] + } +} diff --git a/packages/commerce/tsup.config.ts b/packages/commerce/tsup.config.ts new file mode 100644 index 0000000..03cd41d --- /dev/null +++ b/packages/commerce/tsup.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["./src/index.ts"], + format: ["esm"], + splitting: true, + dts: true, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c185a1b..2d4e900 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,56 @@ importers: specifier: ^1.6.0 version: 1.6.0(@types/node@20.14.5)(@vitest/ui@1.6.0) + examples/commerce_create-charge: + dependencies: + '@coinbase-platform/commerce': + specifier: workspace:* + version: link:../../packages/commerce + devDependencies: + typescript: + specifier: ^5.0.0 + version: 5.4.5 + + examples/commerce_create-checkout: + dependencies: + '@coinbase-platform/commerce': + specifier: workspace:* + version: link:../../packages/commerce + devDependencies: + typescript: + specifier: ^5.0.0 + version: 5.4.5 + + examples/commerce_get-charges: + dependencies: + '@coinbase-platform/commerce': + specifier: workspace:* + version: link:../../packages/commerce + devDependencies: + typescript: + specifier: ^5.0.0 + version: 5.4.5 + + examples/commerce_get-checkouts: + dependencies: + '@coinbase-platform/commerce': + specifier: workspace:* + version: link:../../packages/commerce + devDependencies: + typescript: + specifier: ^5.0.0 + version: 5.4.5 + + examples/commerce_get-events: + dependencies: + '@coinbase-platform/commerce': + specifier: workspace:* + version: link:../../packages/commerce + devDependencies: + typescript: + specifier: ^5.0.0 + version: 5.4.5 + examples/onchain_list-address-transactions: dependencies: '@coinbase-platform/onchain': @@ -116,6 +166,16 @@ importers: specifier: ^5.0.0 version: 5.4.5 + packages/commerce: + dependencies: + typescript: + specifier: '>=5.0.4' + version: 5.4.5 + devDependencies: + '@coinbase-platform/utils': + specifier: workspace:* + version: link:../utils + packages/onchain: dependencies: typescript: