@hasna/connectors 0.5.7 → 0.5.9
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/README.md +48 -9
- package/bin/index.js +57 -1
- package/bin/mcp.js +57 -1
- package/bin/serve.js +56 -0
- package/connectors/connect-chargebee/.env.example +11 -0
- package/connectors/connect-chargebee/CLAUDE.md +272 -0
- package/connectors/connect-chargebee/README.md +193 -0
- package/connectors/connect-chargebee/package.json +51 -0
- package/connectors/connect-chargebee/scripts/release.ts +179 -0
- package/connectors/connect-chargebee/src/api/client.ts +213 -0
- package/connectors/connect-chargebee/src/api/example.ts +48 -0
- package/connectors/connect-chargebee/src/api/index.ts +51 -0
- package/connectors/connect-chargebee/src/cli/index.ts +254 -0
- package/connectors/connect-chargebee/src/index.ts +103 -0
- package/connectors/connect-chargebee/src/types/index.ts +237 -0
- package/connectors/connect-chargebee/src/utils/auth.ts +274 -0
- package/connectors/connect-chargebee/src/utils/bulk.ts +212 -0
- package/connectors/connect-chargebee/src/utils/config.ts +326 -0
- package/connectors/connect-chargebee/src/utils/output.ts +175 -0
- package/connectors/connect-chargebee/src/utils/settings.ts +114 -0
- package/connectors/connect-chargebee/src/utils/storage.ts +198 -0
- package/connectors/connect-chargebee/tsconfig.json +16 -0
- package/connectors/connect-databricks/.env.example +11 -0
- package/connectors/connect-databricks/CLAUDE.md +272 -0
- package/connectors/connect-databricks/README.md +193 -0
- package/connectors/connect-databricks/package.json +51 -0
- package/connectors/connect-databricks/scripts/release.ts +179 -0
- package/connectors/connect-databricks/src/api/client.ts +213 -0
- package/connectors/connect-databricks/src/api/example.ts +48 -0
- package/connectors/connect-databricks/src/api/index.ts +51 -0
- package/connectors/connect-databricks/src/cli/index.ts +254 -0
- package/connectors/connect-databricks/src/index.ts +103 -0
- package/connectors/connect-databricks/src/types/index.ts +237 -0
- package/connectors/connect-databricks/src/utils/auth.ts +274 -0
- package/connectors/connect-databricks/src/utils/bulk.ts +212 -0
- package/connectors/connect-databricks/src/utils/config.ts +326 -0
- package/connectors/connect-databricks/src/utils/output.ts +175 -0
- package/connectors/connect-databricks/src/utils/settings.ts +114 -0
- package/connectors/connect-databricks/src/utils/storage.ts +198 -0
- package/connectors/connect-databricks/tsconfig.json +16 -0
- package/connectors/connect-datadog/.env.example +11 -0
- package/connectors/connect-datadog/CLAUDE.md +170 -0
- package/connectors/connect-datadog/README.md +193 -0
- package/connectors/connect-datadog/package.json +53 -0
- package/connectors/connect-datadog/src/api/client.ts +150 -0
- package/connectors/connect-datadog/src/api/index.ts +537 -0
- package/connectors/connect-datadog/src/cli/index.ts +958 -0
- package/connectors/connect-datadog/src/index.ts +26 -0
- package/connectors/connect-datadog/src/types/index.ts +654 -0
- package/connectors/connect-datadog/src/utils/config.ts +219 -0
- package/connectors/connect-datadog/src/utils/output.ts +119 -0
- package/connectors/connect-datadog/tsconfig.json +16 -0
- package/connectors/connect-fathom/.env.example +11 -0
- package/connectors/connect-fathom/CLAUDE.md +272 -0
- package/connectors/connect-fathom/README.md +193 -0
- package/connectors/connect-fathom/package.json +51 -0
- package/connectors/connect-fathom/scripts/release.ts +179 -0
- package/connectors/connect-fathom/src/api/client.ts +213 -0
- package/connectors/connect-fathom/src/api/example.ts +48 -0
- package/connectors/connect-fathom/src/api/index.ts +51 -0
- package/connectors/connect-fathom/src/cli/index.ts +254 -0
- package/connectors/connect-fathom/src/index.ts +103 -0
- package/connectors/connect-fathom/src/types/index.ts +237 -0
- package/connectors/connect-fathom/src/utils/auth.ts +274 -0
- package/connectors/connect-fathom/src/utils/bulk.ts +212 -0
- package/connectors/connect-fathom/src/utils/config.ts +326 -0
- package/connectors/connect-fathom/src/utils/output.ts +175 -0
- package/connectors/connect-fathom/src/utils/settings.ts +114 -0
- package/connectors/connect-fathom/src/utils/storage.ts +198 -0
- package/connectors/connect-fathom/tsconfig.json +16 -0
- package/connectors/connect-grafana/.env.example +11 -0
- package/connectors/connect-grafana/CLAUDE.md +272 -0
- package/connectors/connect-grafana/README.md +193 -0
- package/connectors/connect-grafana/package.json +51 -0
- package/connectors/connect-grafana/scripts/release.ts +179 -0
- package/connectors/connect-grafana/src/api/client.ts +213 -0
- package/connectors/connect-grafana/src/api/example.ts +48 -0
- package/connectors/connect-grafana/src/api/index.ts +51 -0
- package/connectors/connect-grafana/src/cli/index.ts +254 -0
- package/connectors/connect-grafana/src/index.ts +103 -0
- package/connectors/connect-grafana/src/types/index.ts +237 -0
- package/connectors/connect-grafana/src/utils/auth.ts +274 -0
- package/connectors/connect-grafana/src/utils/bulk.ts +212 -0
- package/connectors/connect-grafana/src/utils/config.ts +326 -0
- package/connectors/connect-grafana/src/utils/output.ts +175 -0
- package/connectors/connect-grafana/src/utils/settings.ts +114 -0
- package/connectors/connect-grafana/src/utils/storage.ts +198 -0
- package/connectors/connect-grafana/tsconfig.json +16 -0
- package/connectors/connect-paddle/.env.example +11 -0
- package/connectors/connect-paddle/CLAUDE.md +272 -0
- package/connectors/connect-paddle/README.md +193 -0
- package/connectors/connect-paddle/package.json +51 -0
- package/connectors/connect-paddle/scripts/release.ts +179 -0
- package/connectors/connect-paddle/src/api/client.ts +213 -0
- package/connectors/connect-paddle/src/api/example.ts +48 -0
- package/connectors/connect-paddle/src/api/index.ts +51 -0
- package/connectors/connect-paddle/src/cli/index.ts +254 -0
- package/connectors/connect-paddle/src/index.ts +103 -0
- package/connectors/connect-paddle/src/types/index.ts +237 -0
- package/connectors/connect-paddle/src/utils/auth.ts +274 -0
- package/connectors/connect-paddle/src/utils/bulk.ts +212 -0
- package/connectors/connect-paddle/src/utils/config.ts +326 -0
- package/connectors/connect-paddle/src/utils/output.ts +175 -0
- package/connectors/connect-paddle/src/utils/settings.ts +114 -0
- package/connectors/connect-paddle/src/utils/storage.ts +198 -0
- package/connectors/connect-paddle/tsconfig.json +16 -0
- package/connectors/connect-snowflake/.env.example +11 -0
- package/connectors/connect-snowflake/CLAUDE.md +272 -0
- package/connectors/connect-snowflake/README.md +193 -0
- package/connectors/connect-snowflake/package.json +51 -0
- package/connectors/connect-snowflake/scripts/release.ts +179 -0
- package/connectors/connect-snowflake/src/api/client.ts +213 -0
- package/connectors/connect-snowflake/src/api/example.ts +48 -0
- package/connectors/connect-snowflake/src/api/index.ts +51 -0
- package/connectors/connect-snowflake/src/cli/index.ts +254 -0
- package/connectors/connect-snowflake/src/index.ts +103 -0
- package/connectors/connect-snowflake/src/types/index.ts +237 -0
- package/connectors/connect-snowflake/src/utils/auth.ts +274 -0
- package/connectors/connect-snowflake/src/utils/bulk.ts +212 -0
- package/connectors/connect-snowflake/src/utils/config.ts +326 -0
- package/connectors/connect-snowflake/src/utils/output.ts +175 -0
- package/connectors/connect-snowflake/src/utils/settings.ts +114 -0
- package/connectors/connect-snowflake/src/utils/storage.ts +198 -0
- package/connectors/connect-snowflake/tsconfig.json +16 -0
- package/connectors/connect-square/.env.example +11 -0
- package/connectors/connect-square/CLAUDE.md +128 -0
- package/connectors/connect-square/README.md +193 -0
- package/connectors/connect-square/package.json +52 -0
- package/connectors/connect-square/src/api/client.ts +152 -0
- package/connectors/connect-square/src/api/index.ts +343 -0
- package/connectors/connect-square/src/cli/index.ts +579 -0
- package/connectors/connect-square/src/index.ts +21 -0
- package/connectors/connect-square/src/types/index.ts +809 -0
- package/connectors/connect-square/src/utils/config.ts +209 -0
- package/connectors/connect-square/src/utils/output.ts +119 -0
- package/connectors/connect-square/tsconfig.json +16 -0
- package/dist/index.js +56 -0
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { SquareConfig, OutputFormat } from '../types';
|
|
2
|
+
import { SquareApiError } from '../types';
|
|
3
|
+
|
|
4
|
+
// Square API base URLs
|
|
5
|
+
const DEFAULT_BASE_URL = 'https://connect.squareup.com';
|
|
6
|
+
const SANDBOX_BASE_URL = 'https://connect.squareupsandbox.com';
|
|
7
|
+
|
|
8
|
+
export interface RequestOptions {
|
|
9
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
10
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
11
|
+
body?: Record<string, unknown> | unknown[] | string;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
format?: OutputFormat;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class SquareClient {
|
|
17
|
+
private readonly accessToken: string;
|
|
18
|
+
private readonly baseUrl: string;
|
|
19
|
+
|
|
20
|
+
constructor(config: SquareConfig) {
|
|
21
|
+
if (!config.accessToken) {
|
|
22
|
+
throw new Error('Access token is required');
|
|
23
|
+
}
|
|
24
|
+
this.accessToken = config.accessToken;
|
|
25
|
+
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the sandbox base URL for testing
|
|
30
|
+
*/
|
|
31
|
+
static getSandboxUrl(): string {
|
|
32
|
+
return SANDBOX_BASE_URL;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the production base URL
|
|
37
|
+
*/
|
|
38
|
+
static getProductionUrl(): string {
|
|
39
|
+
return DEFAULT_BASE_URL;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private buildUrl(path: string, params?: Record<string, string | number | boolean | undefined>): string {
|
|
43
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
44
|
+
|
|
45
|
+
if (params) {
|
|
46
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
47
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
48
|
+
url.searchParams.append(key, String(value));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return url.toString();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Make an authenticated request to the Square API
|
|
58
|
+
* Square uses Bearer token authentication
|
|
59
|
+
*/
|
|
60
|
+
async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
|
61
|
+
const { method = 'GET', params, body, headers = {} } = options;
|
|
62
|
+
|
|
63
|
+
const url = this.buildUrl(path, params);
|
|
64
|
+
|
|
65
|
+
// Square uses Bearer token authentication with API version header
|
|
66
|
+
const requestHeaders: Record<string, string> = {
|
|
67
|
+
'Authorization': `Bearer ${this.accessToken}`,
|
|
68
|
+
'Square-Version': '2024-01-18',
|
|
69
|
+
'Accept': 'application/json',
|
|
70
|
+
...headers,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (body && ['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
74
|
+
requestHeaders['Content-Type'] = 'application/json';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const fetchOptions: RequestInit = {
|
|
78
|
+
method,
|
|
79
|
+
headers: requestHeaders,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (body && ['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
83
|
+
fetchOptions.body = typeof body === 'string' ? body : JSON.stringify(body);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const response = await fetch(url, fetchOptions);
|
|
87
|
+
|
|
88
|
+
// Handle 204 No Content
|
|
89
|
+
if (response.status === 204) {
|
|
90
|
+
return {} as T;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Parse response
|
|
94
|
+
let data: unknown;
|
|
95
|
+
const contentType = response.headers.get('content-type') || '';
|
|
96
|
+
|
|
97
|
+
if (contentType.includes('application/json')) {
|
|
98
|
+
const text = await response.text();
|
|
99
|
+
if (text) {
|
|
100
|
+
try {
|
|
101
|
+
data = JSON.parse(text);
|
|
102
|
+
} catch {
|
|
103
|
+
data = text;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
data = await response.text();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Handle errors
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
const errorData = data as { errors?: Array<{ detail?: string; category: string; code: string }> };
|
|
113
|
+
throw new SquareApiError(
|
|
114
|
+
errorData?.errors?.[0]?.detail || `Square API error: ${response.status}`,
|
|
115
|
+
response.status,
|
|
116
|
+
errorData?.errors
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return data as T;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async get<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T> {
|
|
124
|
+
return this.request<T>(path, { method: 'GET', params });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async post<T>(path: string, body?: Record<string, unknown> | unknown[] | string | object, params?: Record<string, string | number | boolean | undefined>): Promise<T> {
|
|
128
|
+
return this.request<T>(path, { method: 'POST', body: body as Record<string, unknown>, params });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async put<T>(path: string, body?: Record<string, unknown> | object, params?: Record<string, string | number | boolean | undefined>): Promise<T> {
|
|
132
|
+
return this.request<T>(path, { method: 'PUT', body: body as Record<string, unknown>, params });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async patch<T>(path: string, body?: Record<string, unknown> | object, params?: Record<string, string | number | boolean | undefined>): Promise<T> {
|
|
136
|
+
return this.request<T>(path, { method: 'PATCH', body: body as Record<string, unknown>, params });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async delete<T>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T> {
|
|
140
|
+
return this.request<T>(path, { method: 'DELETE', params });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get a preview of the access token (for display/debugging)
|
|
145
|
+
*/
|
|
146
|
+
getAccessTokenPreview(): string {
|
|
147
|
+
if (this.accessToken.length > 10) {
|
|
148
|
+
return `${this.accessToken.substring(0, 6)}...${this.accessToken.substring(this.accessToken.length - 4)}`;
|
|
149
|
+
}
|
|
150
|
+
return '***';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SquareConfig,
|
|
3
|
+
LocationsListResponse,
|
|
4
|
+
Location,
|
|
5
|
+
CustomersListResponse,
|
|
6
|
+
CustomerResponse,
|
|
7
|
+
CreateCustomerRequest,
|
|
8
|
+
PaymentsListResponse,
|
|
9
|
+
PaymentResponse,
|
|
10
|
+
CreatePaymentRequest,
|
|
11
|
+
OrderResponse,
|
|
12
|
+
OrdersSearchResponse,
|
|
13
|
+
CreateOrderRequest,
|
|
14
|
+
CatalogListResponse,
|
|
15
|
+
CatalogObjectResponse,
|
|
16
|
+
} from '../types';
|
|
17
|
+
import { SquareClient } from './client';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Square Connector
|
|
21
|
+
* Payments, orders, customers, and catalog API
|
|
22
|
+
*/
|
|
23
|
+
export class Square {
|
|
24
|
+
private readonly client: SquareClient;
|
|
25
|
+
|
|
26
|
+
constructor(config: SquareConfig) {
|
|
27
|
+
this.client = new SquareClient(config);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a client from environment variables
|
|
32
|
+
* Looks for SQUARE_ACCESS_TOKEN
|
|
33
|
+
*/
|
|
34
|
+
static fromEnv(): Square {
|
|
35
|
+
const accessToken = process.env.SQUARE_ACCESS_TOKEN;
|
|
36
|
+
const baseUrl = process.env.SQUARE_BASE_URL;
|
|
37
|
+
|
|
38
|
+
if (!accessToken) {
|
|
39
|
+
throw new Error('SQUARE_ACCESS_TOKEN environment variable is required');
|
|
40
|
+
}
|
|
41
|
+
return new Square({ accessToken, baseUrl });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get a preview of the access token (for debugging)
|
|
46
|
+
*/
|
|
47
|
+
getAccessTokenPreview(): string {
|
|
48
|
+
return this.client.getAccessTokenPreview();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get the underlying client for direct API access
|
|
53
|
+
*/
|
|
54
|
+
getClient(): SquareClient {
|
|
55
|
+
return this.client;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ============================================
|
|
59
|
+
// Locations API
|
|
60
|
+
// ============================================
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* List all locations for this seller
|
|
64
|
+
*/
|
|
65
|
+
async listLocations(): Promise<LocationsListResponse> {
|
|
66
|
+
return this.client.get<LocationsListResponse>('/v2/locations');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get a single location by ID
|
|
71
|
+
*/
|
|
72
|
+
async getLocation(locationId: string): Promise<{ location?: Location }> {
|
|
73
|
+
return this.client.get<{ location?: Location }>(`/v2/locations/${locationId}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ============================================
|
|
77
|
+
// Customers API
|
|
78
|
+
// ============================================
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* List customers
|
|
82
|
+
*/
|
|
83
|
+
async listCustomers(options?: {
|
|
84
|
+
cursor?: string;
|
|
85
|
+
limit?: number;
|
|
86
|
+
sort_field?: 'DEFAULT' | 'CREATED_AT';
|
|
87
|
+
sort_order?: 'ASC' | 'DESC';
|
|
88
|
+
}): Promise<CustomersListResponse> {
|
|
89
|
+
return this.client.get<CustomersListResponse>('/v2/customers', options as Record<string, string>);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get a customer by ID
|
|
94
|
+
*/
|
|
95
|
+
async getCustomer(customerId: string): Promise<CustomerResponse> {
|
|
96
|
+
return this.client.get<CustomerResponse>(`/v2/customers/${customerId}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create a new customer
|
|
101
|
+
*/
|
|
102
|
+
async createCustomer(customer: CreateCustomerRequest): Promise<CustomerResponse> {
|
|
103
|
+
return this.client.post<CustomerResponse>('/v2/customers', customer);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Update a customer
|
|
108
|
+
*/
|
|
109
|
+
async updateCustomer(customerId: string, customer: Partial<CreateCustomerRequest>): Promise<CustomerResponse> {
|
|
110
|
+
return this.client.put<CustomerResponse>(`/v2/customers/${customerId}`, customer);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Delete a customer
|
|
115
|
+
*/
|
|
116
|
+
async deleteCustomer(customerId: string): Promise<{ errors?: unknown[] }> {
|
|
117
|
+
return this.client.delete<{ errors?: unknown[] }>(`/v2/customers/${customerId}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Search customers
|
|
122
|
+
*/
|
|
123
|
+
async searchCustomers(query: {
|
|
124
|
+
limit?: number;
|
|
125
|
+
cursor?: string;
|
|
126
|
+
query?: {
|
|
127
|
+
filter?: {
|
|
128
|
+
email_address?: { exact?: string };
|
|
129
|
+
phone_number?: { exact?: string };
|
|
130
|
+
reference_id?: { exact?: string };
|
|
131
|
+
};
|
|
132
|
+
sort?: {
|
|
133
|
+
field?: 'DEFAULT' | 'CREATED_AT';
|
|
134
|
+
order?: 'ASC' | 'DESC';
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
}): Promise<CustomersListResponse> {
|
|
138
|
+
return this.client.post<CustomersListResponse>('/v2/customers/search', query);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ============================================
|
|
142
|
+
// Payments API
|
|
143
|
+
// ============================================
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* List payments
|
|
147
|
+
*/
|
|
148
|
+
async listPayments(options?: {
|
|
149
|
+
begin_time?: string;
|
|
150
|
+
end_time?: string;
|
|
151
|
+
sort_order?: 'ASC' | 'DESC';
|
|
152
|
+
cursor?: string;
|
|
153
|
+
location_id?: string;
|
|
154
|
+
total?: number;
|
|
155
|
+
last_4?: string;
|
|
156
|
+
card_brand?: string;
|
|
157
|
+
limit?: number;
|
|
158
|
+
}): Promise<PaymentsListResponse> {
|
|
159
|
+
return this.client.get<PaymentsListResponse>('/v2/payments', options as Record<string, string>);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get a payment by ID
|
|
164
|
+
*/
|
|
165
|
+
async getPayment(paymentId: string): Promise<PaymentResponse> {
|
|
166
|
+
return this.client.get<PaymentResponse>(`/v2/payments/${paymentId}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Create a payment
|
|
171
|
+
*/
|
|
172
|
+
async createPayment(payment: CreatePaymentRequest): Promise<PaymentResponse> {
|
|
173
|
+
return this.client.post<PaymentResponse>('/v2/payments', payment);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Cancel a payment
|
|
178
|
+
*/
|
|
179
|
+
async cancelPayment(paymentId: string): Promise<PaymentResponse> {
|
|
180
|
+
return this.client.post<PaymentResponse>(`/v2/payments/${paymentId}/cancel`, {});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Complete a payment
|
|
185
|
+
*/
|
|
186
|
+
async completePayment(paymentId: string, versionToken?: string): Promise<PaymentResponse> {
|
|
187
|
+
return this.client.post<PaymentResponse>(`/v2/payments/${paymentId}/complete`, {
|
|
188
|
+
version_token: versionToken,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ============================================
|
|
193
|
+
// Orders API
|
|
194
|
+
// ============================================
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Create an order
|
|
198
|
+
*/
|
|
199
|
+
async createOrder(order: CreateOrderRequest): Promise<OrderResponse> {
|
|
200
|
+
return this.client.post<OrderResponse>('/v2/orders', order);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get an order by ID
|
|
205
|
+
*/
|
|
206
|
+
async getOrder(orderId: string): Promise<OrderResponse> {
|
|
207
|
+
return this.client.get<OrderResponse>(`/v2/orders/${orderId}`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Update an order
|
|
212
|
+
*/
|
|
213
|
+
async updateOrder(orderId: string, order: {
|
|
214
|
+
order?: Partial<CreateOrderRequest['order']>;
|
|
215
|
+
fields_to_clear?: string[];
|
|
216
|
+
idempotency_key?: string;
|
|
217
|
+
}): Promise<OrderResponse> {
|
|
218
|
+
return this.client.put<OrderResponse>(`/v2/orders/${orderId}`, order);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Search orders
|
|
223
|
+
*/
|
|
224
|
+
async searchOrders(query: {
|
|
225
|
+
location_ids?: string[];
|
|
226
|
+
cursor?: string;
|
|
227
|
+
query?: {
|
|
228
|
+
filter?: {
|
|
229
|
+
state_filter?: { states?: string[] };
|
|
230
|
+
date_time_filter?: {
|
|
231
|
+
created_at?: { start_at?: string; end_at?: string };
|
|
232
|
+
updated_at?: { start_at?: string; end_at?: string };
|
|
233
|
+
closed_at?: { start_at?: string; end_at?: string };
|
|
234
|
+
};
|
|
235
|
+
fulfillment_filter?: { fulfillment_types?: string[]; fulfillment_states?: string[] };
|
|
236
|
+
source_filter?: { source_names?: string[] };
|
|
237
|
+
customer_filter?: { customer_ids?: string[] };
|
|
238
|
+
};
|
|
239
|
+
sort?: {
|
|
240
|
+
sort_field?: 'CREATED_AT' | 'UPDATED_AT' | 'CLOSED_AT';
|
|
241
|
+
sort_order?: 'ASC' | 'DESC';
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
limit?: number;
|
|
245
|
+
return_entries?: boolean;
|
|
246
|
+
}): Promise<OrdersSearchResponse> {
|
|
247
|
+
return this.client.post<OrdersSearchResponse>('/v2/orders/search', query);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Pay for an order
|
|
252
|
+
*/
|
|
253
|
+
async payOrder(orderId: string, payment: {
|
|
254
|
+
idempotency_key: string;
|
|
255
|
+
order_version?: number;
|
|
256
|
+
payment_ids?: string[];
|
|
257
|
+
}): Promise<OrderResponse> {
|
|
258
|
+
return this.client.post<OrderResponse>(`/v2/orders/${orderId}/pay`, payment);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// ============================================
|
|
262
|
+
// Catalog API
|
|
263
|
+
// ============================================
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* List catalog items
|
|
267
|
+
*/
|
|
268
|
+
async listCatalog(options?: {
|
|
269
|
+
cursor?: string;
|
|
270
|
+
types?: string;
|
|
271
|
+
catalog_version?: number;
|
|
272
|
+
}): Promise<CatalogListResponse> {
|
|
273
|
+
return this.client.get<CatalogListResponse>('/v2/catalog/list', options as Record<string, string>);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Get a catalog object by ID
|
|
278
|
+
*/
|
|
279
|
+
async getCatalogObject(objectId: string, options?: {
|
|
280
|
+
include_related_objects?: boolean;
|
|
281
|
+
catalog_version?: number;
|
|
282
|
+
}): Promise<CatalogObjectResponse> {
|
|
283
|
+
return this.client.get<CatalogObjectResponse>(`/v2/catalog/object/${objectId}`, options as Record<string, string>);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Batch get catalog objects
|
|
288
|
+
*/
|
|
289
|
+
async batchGetCatalogObjects(request: {
|
|
290
|
+
object_ids: string[];
|
|
291
|
+
include_related_objects?: boolean;
|
|
292
|
+
catalog_version?: number;
|
|
293
|
+
}): Promise<CatalogListResponse> {
|
|
294
|
+
return this.client.post<CatalogListResponse>('/v2/catalog/batch-retrieve', request);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Search catalog
|
|
299
|
+
*/
|
|
300
|
+
async searchCatalog(query: {
|
|
301
|
+
cursor?: string;
|
|
302
|
+
object_types?: string[];
|
|
303
|
+
include_deleted_objects?: boolean;
|
|
304
|
+
include_related_objects?: boolean;
|
|
305
|
+
begin_time?: string;
|
|
306
|
+
query?: {
|
|
307
|
+
exact_query?: { attribute_name: string; attribute_value: string };
|
|
308
|
+
prefix_query?: { attribute_name: string; attribute_prefix: string };
|
|
309
|
+
range_query?: { attribute_name: string; attribute_min_value?: number; attribute_max_value?: number };
|
|
310
|
+
sorted_attribute_query?: { attribute_name: string; initial_attribute_value?: string; sort_order?: 'ASC' | 'DESC' };
|
|
311
|
+
text_query?: { keywords: string[] };
|
|
312
|
+
items_for_tax_query?: { tax_ids: string[] };
|
|
313
|
+
items_for_modifier_list_query?: { modifier_list_ids: string[] };
|
|
314
|
+
items_for_item_options_query?: { item_option_ids: string[] };
|
|
315
|
+
};
|
|
316
|
+
limit?: number;
|
|
317
|
+
}): Promise<CatalogListResponse> {
|
|
318
|
+
return this.client.post<CatalogListResponse>('/v2/catalog/search', query);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Upsert catalog object
|
|
323
|
+
*/
|
|
324
|
+
async upsertCatalogObject(request: {
|
|
325
|
+
idempotency_key: string;
|
|
326
|
+
object: {
|
|
327
|
+
type: string;
|
|
328
|
+
id: string;
|
|
329
|
+
[key: string]: unknown;
|
|
330
|
+
};
|
|
331
|
+
}): Promise<CatalogObjectResponse> {
|
|
332
|
+
return this.client.post<CatalogObjectResponse>('/v2/catalog/object', request);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Delete catalog object
|
|
337
|
+
*/
|
|
338
|
+
async deleteCatalogObject(objectId: string): Promise<{ deleted_object_ids?: string[]; deleted_at?: string }> {
|
|
339
|
+
return this.client.delete<{ deleted_object_ids?: string[]; deleted_at?: string }>(`/v2/catalog/object/${objectId}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { SquareClient } from './client';
|