@hasna/connectors 1.4.2 → 1.4.3
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/bin/index.js +1 -5
- package/bin/mcp.js +1 -1
- package/bin/serve.js +1 -1
- package/connectors/clickbank/README.md +2 -2
- package/connectors/split-in-batches/CLAUDE.md +1 -1
- package/connectors/split-in-batches/README.md +1 -1
- package/connectors/split-in-batches/src/api/client.test.ts +16 -17
- package/connectors/split-in-batches/src/api/client.ts +4 -3
- package/connectors/split-in-batches/src/cli/index.ts +1 -1
- package/connectors/spreadsheet-file/.env.example +1 -1
- package/connectors/spreadsheet-file/CLAUDE.md +2 -2
- package/connectors/spreadsheet-file/README.md +3 -3
- package/connectors/spreadsheet-file/src/api/client.test.ts +8 -9
- package/connectors/spreadsheet-file/src/api/client.ts +4 -3
- package/connectors/spreadsheet-file/src/cli/index.ts +1 -1
- package/connectors/sse-trigger/.env.example +1 -1
- package/connectors/sse-trigger/CLAUDE.md +2 -2
- package/connectors/sse-trigger/README.md +1 -1
- package/connectors/sse-trigger/src/api/client.test.ts +12 -8
- package/connectors/sse-trigger/src/api/client.ts +4 -3
- package/connectors/sse-trigger/src/api/index.ts +1 -1
- package/connectors/sse-trigger/src/cli/index.ts +1 -1
- package/connectors/sse-trigger/src/index.ts +1 -1
- package/connectors/stability-api-platform/AGENTS.md +1 -1
- package/connectors/stability-api-platform/CLAUDE.md +1 -1
- package/connectors/stability-api-platform/README.md +2 -2
- package/connectors/stability-api-platform/src/api/client.test.ts +17 -12
- package/connectors/stability-api-platform/src/api/client.ts +4 -3
- package/connectors/stability-api-platform/src/api/index.ts +0 -1
- package/connectors/stability-api-platform/src/cli/index.ts +1 -1
- package/connectors/stability-api-platform/src/index.ts +0 -1
- package/connectors/stop-and-error/.env.example +1 -1
- package/connectors/stop-and-error/CLAUDE.md +1 -1
- package/connectors/stop-and-error/README.md +1 -1
- package/connectors/stop-and-error/src/api/client.test.ts +12 -8
- package/connectors/stop-and-error/src/api/client.ts +4 -3
- package/connectors/stop-and-error/src/cli/index.ts +2 -2
- package/connectors/stripe-financial-connections/.env.example +1 -1
- package/connectors/stripe-financial-connections/CLAUDE.md +2 -2
- package/connectors/stripe-financial-connections/src/api/client.test.ts +34 -0
- package/connectors/stripe-financial-connections/src/api/client.ts +4 -3
- package/connectors/stripe-financial-connections/src/cli/index.ts +1 -1
- package/connectors/sucuri-api-platform/.env.example +1 -1
- package/connectors/sucuri-api-platform/CLAUDE.md +1 -1
- package/connectors/sucuri-api-platform/README.md +2 -2
- package/connectors/sucuri-api-platform/src/api/client.test.ts +9 -7
- package/connectors/sucuri-api-platform/src/api/client.ts +4 -3
- package/connectors/sucuri-api-platform/src/api/index.ts +1 -1
- package/connectors/sucuri-api-platform/src/cli/index.ts +1 -1
- package/connectors/sucuri-api-platform/src/index.ts +1 -1
- package/connectors/tettra-api-platform/CLAUDE.md +1 -1
- package/connectors/tettra-api-platform/README.md +2 -2
- package/connectors/tettra-api-platform/src/api/client.test.ts +7 -8
- package/connectors/tettra-api-platform/src/api/client.ts +4 -3
- package/connectors/tettra-api-platform/src/api/index.ts +1 -1
- package/connectors/tettra-api-platform/src/cli/index.ts +1 -1
- package/connectors/tettra-api-platform/src/index.ts +1 -1
- package/connectors/together-api-platform/.env.example +1 -1
- package/connectors/together-api-platform/CLAUDE.md +1 -1
- package/connectors/together-api-platform/README.md +1 -1
- package/connectors/together-api-platform/src/api/client.test.ts +11 -7
- package/connectors/together-api-platform/src/api/client.ts +4 -4
- package/connectors/together-api-platform/src/api/index.ts +1 -1
- package/connectors/together-api-platform/src/cli/index.ts +1 -1
- package/connectors/together-api-platform/src/index.ts +1 -1
- package/connectors/travo-real-estate/CLAUDE.md +1 -1
- package/connectors/travo-real-estate/README.md +1 -1
- package/connectors/travo-real-estate/src/api/client.test.ts +20 -16
- package/connectors/travo-real-estate/src/api/client.ts +4 -3
- package/connectors/travo-real-estate/src/utils/config.ts +2 -4
- package/connectors/tray-api-platform/CLAUDE.md +1 -1
- package/connectors/tray-api-platform/src/api/client.test.ts +17 -13
- package/connectors/tray-api-platform/src/api/client.ts +4 -3
- package/connectors/tray-api-platform/src/api/index.ts +1 -1
- package/connectors/tray-api-platform/src/cli/index.ts +1 -1
- package/connectors/tray-api-platform/src/index.ts +0 -1
- package/connectors/turso-api-platform/CLAUDE.md +1 -1
- package/connectors/turso-api-platform/README.md +2 -2
- package/connectors/turso-api-platform/src/api/client.test.ts +17 -13
- package/connectors/turso-api-platform/src/api/client.ts +4 -3
- package/connectors/turso-api-platform/src/cli/index.ts +2 -2
- package/connectors/twilio-api-platform/CLAUDE.md +1 -1
- package/connectors/twilio-api-platform/src/api/client.test.ts +11 -11
- package/connectors/twilio-api-platform/src/api/client.ts +4 -3
- package/connectors/twilio-api-platform/src/api/index.ts +1 -1
- package/connectors/twilio-api-platform/src/cli/index.ts +1 -1
- package/connectors/twilio-api-platform/src/index.ts +1 -1
- package/connectors/tyk-api-platform/.env.example +1 -1
- package/connectors/tyk-api-platform/CLAUDE.md +2 -2
- package/connectors/tyk-api-platform/README.md +1 -1
- package/connectors/tyk-api-platform/src/api/client.test.ts +14 -15
- package/connectors/tyk-api-platform/src/api/client.ts +4 -3
- package/connectors/tyk-api-platform/src/api/index.ts +1 -1
- package/connectors/tyk-api-platform/src/cli/index.ts +1 -1
- package/connectors/tyk-api-platform/src/index.ts +1 -1
- package/connectors/vector-legal/.env.example +1 -1
- package/connectors/vector-legal/AGENTS.md +1 -1
- package/connectors/vector-legal/CLAUDE.md +1 -1
- package/connectors/vector-legal/README.md +1 -1
- package/connectors/vector-legal/src/api/client.test.ts +9 -5
- package/connectors/vector-legal/src/api/client.ts +4 -3
- package/connectors/vector-legal/src/api/index.ts +1 -1
- package/connectors/vector-legal/src/cli/index.ts +2 -2
- package/connectors/vector-legal/src/index.ts +0 -1
- package/connectors/vector-legal-api/CLAUDE.md +1 -1
- package/connectors/vector-legal-api/README.md +2 -2
- package/connectors/vector-legal-api/src/api/client.test.ts +12 -7
- package/connectors/vector-legal-api/src/api/client.ts +4 -3
- package/connectors/vector-legal-api/src/api/index.ts +1 -1
- package/connectors/vector-legal-api/src/cli/index.ts +1 -1
- package/connectors/vector-legal-api/src/index.ts +1 -2
- package/connectors/velum-data-quality/.env.example +1 -1
- package/connectors/velum-data-quality/CLAUDE.md +1 -1
- package/connectors/velum-data-quality/src/api/client.test.ts +15 -16
- package/connectors/velum-data-quality/src/api/client.ts +4 -3
- package/connectors/velum-data-quality/src/api/index.ts +1 -1
- package/connectors/velum-data-quality/src/cli/index.ts +1 -1
- package/connectors/velum-data-quality/src/index.ts +0 -1
- package/connectors/vercel-api-platform/.env.example +1 -1
- package/connectors/vercel-api-platform/CLAUDE.md +2 -2
- package/connectors/vercel-api-platform/README.md +2 -2
- package/connectors/vercel-api-platform/src/api/client.test.ts +27 -6
- package/connectors/vercel-api-platform/src/api/client.ts +4 -3
- package/connectors/vercel-api-platform/src/api/index.ts +1 -1
- package/connectors/vercel-api-platform/src/cli/index.ts +2 -2
- package/connectors/vercel-api-platform/src/index.ts +0 -1
- package/connectors/veriphone/README.md +2 -2
- package/connectors/wave-accounting/CLAUDE.md +1 -1
- package/connectors/wave-accounting/src/utils/auth.ts +1 -1
- package/connectors/weaviate-api-platform/CLAUDE.md +1 -1
- package/connectors/weaviate-api-platform/src/api/client.test.ts +32 -7
- package/connectors/weaviate-api-platform/src/api/client.ts +4 -3
- package/connectors/weaviate-api-platform/src/api/index.ts +1 -1
- package/connectors/weaviate-api-platform/src/cli/index.ts +1 -1
- package/connectors/weaviate-api-platform/src/index.ts +1 -1
- package/connectors/workflow-trigger/.env.example +1 -1
- package/connectors/workflow-trigger/CLAUDE.md +1 -1
- package/connectors/workflow-trigger/README.md +1 -1
- package/connectors/workflow-trigger/src/api/client.test.ts +10 -6
- package/connectors/workflow-trigger/src/api/client.ts +4 -3
- package/connectors/workflow-trigger/src/cli/index.ts +1 -1
- package/connectors/write-binary-file/CLAUDE.md +1 -1
- package/connectors/write-binary-file/README.md +1 -1
- package/connectors/write-binary-file/src/api/client.test.ts +16 -12
- package/connectors/write-binary-file/src/api/client.ts +4 -3
- package/connectors/write-binary-file/src/api/index.ts +1 -1
- package/connectors/write-binary-file/src/index.ts +1 -1
- package/connectors/wubookratechecker/src/api/client.test.ts +34 -0
- package/connectors/wubookratechecker/src/api/client.ts +3 -1
- package/connectors/wubookratechecker/src/api/index.ts +1 -1
- package/connectors/wubookratechecker/src/types/index.ts +1 -1
- package/connectors/xai-api-platform/.env.example +1 -1
- package/connectors/xai-api-platform/CLAUDE.md +1 -1
- package/connectors/xai-api-platform/README.md +1 -1
- package/connectors/xai-api-platform/src/api/client.test.ts +33 -8
- package/connectors/xai-api-platform/src/api/client.ts +4 -3
- package/connectors/xai-api-platform/src/api/index.ts +1 -1
- package/connectors/xai-api-platform/src/index.ts +1 -1
- package/connectors/xai-api-platform/src/utils/config.ts +2 -3
- package/connectors/zapier-api-platform/CLAUDE.md +1 -1
- package/connectors/zapier-api-platform/README.md +1 -1
- package/connectors/zapier-api-platform/src/api/client.test.ts +19 -14
- package/connectors/zapier-api-platform/src/api/client.ts +4 -3
- package/connectors/zapier-api-platform/src/api/index.ts +1 -1
- package/connectors/zapier-api-platform/src/cli/index.ts +1 -1
- package/connectors/zapier-api-platform/src/index.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface WuBookrateConfig { apiKey: string; }
|
|
1
|
+
export interface WuBookrateConfig { apiKey: string; baseUrl?: string; }
|
|
2
2
|
|
|
3
3
|
export interface WBBook { isbn: string; title: string; author: string; publisher: string; published_date: string; average_rating: number; ratings_count: number; image_url: string; }
|
|
4
4
|
export interface WBReview { source: string; rating: number; review_count: number; url: string; }
|
|
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code when working with the Xai API Platfor
|
|
|
4
4
|
|
|
5
5
|
## Project Overview
|
|
6
6
|
|
|
7
|
-
`connect-xai-api-platform` is a TypeScript CLI and library for the Xai API Platform REST API at `
|
|
7
|
+
`connect-xai-api-platform` is a TypeScript CLI and library for the Xai API Platform REST API at `configured.example.com/v1`. It is **distinct** from `connect-xai` (Grok at `api.x.ai`).
|
|
8
8
|
|
|
9
9
|
## Build & Run Commands
|
|
10
10
|
|
|
@@ -46,7 +46,7 @@ connect-xai-api-platform raw --path /items [--method GET] [--query '{}'] [--body
|
|
|
46
46
|
| Variable | Description |
|
|
47
47
|
|----------|-------------|
|
|
48
48
|
| `XAI_API_PLATFORM_API_KEY` | API key (Bearer token) |
|
|
49
|
-
| `XAI_API_PLATFORM_BASE_URL` | Optional base URL (default: `
|
|
49
|
+
| `XAI_API_PLATFORM_BASE_URL` | Optional base URL (default: `configured.example.com/v1`) |
|
|
50
50
|
|
|
51
51
|
## Library Usage
|
|
52
52
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { XaiApiPlatformClient } from './client';
|
|
2
3
|
import { XaiApiPlatform } from './index';
|
|
3
4
|
|
|
4
5
|
const realFetch = globalThis.fetch;
|
|
@@ -40,12 +41,12 @@ afterEach(() => {
|
|
|
40
41
|
|
|
41
42
|
describe('XaiApiPlatformClient', () => {
|
|
42
43
|
const apiKey = 'xai' + '-api-platform-key';
|
|
43
|
-
const client = new XaiApiPlatform({ apiKey });
|
|
44
|
+
const client = new XaiApiPlatform({ apiKey, baseUrl: 'https://configured.example.com/v1' });
|
|
44
45
|
|
|
45
46
|
test('listItems uses bearer auth and /items endpoint', async () => {
|
|
46
47
|
const recorded = installFetch();
|
|
47
48
|
await client.listItems();
|
|
48
|
-
expect(recorded[0].url).toBe('https://
|
|
49
|
+
expect(recorded[0].url).toBe('https://configured.example.com/v1/items');
|
|
49
50
|
expect(recorded[0].method).toBe('GET');
|
|
50
51
|
expect(recorded[0].headers.get('Authorization')).toBe(`Bearer ${apiKey}`);
|
|
51
52
|
});
|
|
@@ -53,14 +54,14 @@ describe('XaiApiPlatformClient', () => {
|
|
|
53
54
|
test('getItem URL-encodes path segments', async () => {
|
|
54
55
|
const recorded = installFetch();
|
|
55
56
|
await client.getItem('item-1');
|
|
56
|
-
expect(recorded[0].url).toBe('https://
|
|
57
|
+
expect(recorded[0].url).toBe('https://configured.example.com/v1/items/item-1');
|
|
57
58
|
expect(recorded[0].headers.get('Authorization')).toBe(`Bearer ${apiKey}`);
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
test('createItem posts JSON body to /items', async () => {
|
|
61
62
|
const recorded = installFetch();
|
|
62
63
|
await client.createItem({ name: 'test' });
|
|
63
|
-
expect(recorded[0].url).toBe('https://
|
|
64
|
+
expect(recorded[0].url).toBe('https://configured.example.com/v1/items');
|
|
64
65
|
expect(recorded[0].method).toBe('POST');
|
|
65
66
|
expect(recorded[0].body).toBe(JSON.stringify({ name: 'test' }));
|
|
66
67
|
});
|
|
@@ -68,13 +69,13 @@ describe('XaiApiPlatformClient', () => {
|
|
|
68
69
|
test('listEvents hits /events', async () => {
|
|
69
70
|
const recorded = installFetch();
|
|
70
71
|
await client.listEvents({ limit: 10 });
|
|
71
|
-
expect(recorded[0].url).toBe('https://
|
|
72
|
+
expect(recorded[0].url).toBe('https://configured.example.com/v1/events?limit=10');
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
test('search posts to /search', async () => {
|
|
75
76
|
const recorded = installFetch();
|
|
76
77
|
await client.search({ q: 'hello' });
|
|
77
|
-
expect(recorded[0].url).toBe('https://
|
|
78
|
+
expect(recorded[0].url).toBe('https://configured.example.com/v1/search');
|
|
78
79
|
expect(recorded[0].method).toBe('POST');
|
|
79
80
|
expect(recorded[0].body).toBe(JSON.stringify({ q: 'hello' }));
|
|
80
81
|
});
|
|
@@ -82,11 +83,35 @@ describe('XaiApiPlatformClient', () => {
|
|
|
82
83
|
test('rawRequest supports custom path and method', async () => {
|
|
83
84
|
const recorded = installFetch();
|
|
84
85
|
await client.rawRequest('/custom', { method: 'POST', body: { a: 1 } });
|
|
85
|
-
expect(recorded[0].url).toBe('https://
|
|
86
|
+
expect(recorded[0].url).toBe('https://configured.example.com/v1/custom');
|
|
86
87
|
expect(recorded[0].method).toBe('POST');
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
test('requires API key', () => {
|
|
90
|
-
expect(() => new XaiApiPlatform({ apiKey: '' })).toThrow('API key is required');
|
|
91
|
+
expect(() => new XaiApiPlatform({ apiKey: '', baseUrl: 'https://configured.example.com/v1' })).toThrow('API key is required');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('refuses to send without a configured base URL (no default endpoint)', () => {
|
|
95
|
+
expect(() => new XaiApiPlatformClient({ apiKey: 'test-key' })).toThrow(/baseUrl/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('sends the API key only to the configured base URL', async () => {
|
|
99
|
+
const recorded: string[] = [];
|
|
100
|
+
globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
101
|
+
recorded.push(typeof input === 'string' ? input : input.toString());
|
|
102
|
+
return {
|
|
103
|
+
ok: true,
|
|
104
|
+
status: 200,
|
|
105
|
+
statusText: 'OK',
|
|
106
|
+
headers: new Headers({ 'content-type': 'application/json' }),
|
|
107
|
+
async text() { return JSON.stringify({ ok: true }); },
|
|
108
|
+
async json() { return { ok: true }; },
|
|
109
|
+
} as Response;
|
|
110
|
+
}) as typeof fetch;
|
|
111
|
+
const client = new XaiApiPlatformClient({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
112
|
+
await client.request('/ping');
|
|
113
|
+
expect(recorded).toHaveLength(1);
|
|
114
|
+
expect(recorded[0].startsWith('https://configured.example.com/v1/')).toBe(true);
|
|
115
|
+
expect(recorded[0]).not.toContain('api.xaiapiplatform.com');
|
|
91
116
|
});
|
|
92
117
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { XaiApiPlatformConfig, RawRequestOptions } from '../types';
|
|
2
2
|
import { XaiApiPlatformApiError } from '../types';
|
|
3
3
|
|
|
4
|
-
export const DEFAULT_BASE_URL = 'https://api.xaiapiplatform.com/v1';
|
|
5
|
-
|
|
6
4
|
export interface RequestOptions extends RawRequestOptions {}
|
|
7
5
|
|
|
8
6
|
export class XaiApiPlatformClient {
|
|
@@ -14,7 +12,10 @@ export class XaiApiPlatformClient {
|
|
|
14
12
|
throw new Error('API key is required');
|
|
15
13
|
}
|
|
16
14
|
this.apiKey = config.apiKey;
|
|
17
|
-
|
|
15
|
+
if (!config.baseUrl) {
|
|
16
|
+
throw new Error('baseUrl is required: no default endpoint is configured; set baseUrl (profile, config, or the connector BASE_URL environment variable)');
|
|
17
|
+
}
|
|
18
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
encodePathSegment(segment: string): string {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync } from 'fs';
|
|
2
2
|
import { homedir } from 'os';
|
|
3
3
|
import { join } from 'path';
|
|
4
|
-
import { DEFAULT_BASE_URL } from '../api/client';
|
|
5
4
|
|
|
6
5
|
const CONNECTOR_NAME = 'connect-' + 'xai' + '-api-platform';
|
|
7
6
|
const DEFAULT_PROFILE = 'default';
|
|
@@ -125,8 +124,8 @@ export function getApiKey(): string | undefined {
|
|
|
125
124
|
return process.env.XAI_API_PLATFORM_API_KEY || loadProfile().apiKey;
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
export function getBaseUrl(): string {
|
|
129
|
-
return process.env.XAI_API_PLATFORM_BASE_URL || loadProfile().baseUrl
|
|
127
|
+
export function getBaseUrl(): string | undefined {
|
|
128
|
+
return process.env.XAI_API_PLATFORM_BASE_URL || loadProfile().baseUrl;
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
export function setApiKey(apiKey: string): void {
|
|
@@ -8,7 +8,7 @@ connect-zapier-api-platform is a TypeScript connector for the Zapier API Platfor
|
|
|
8
8
|
|
|
9
9
|
## API Reference
|
|
10
10
|
|
|
11
|
-
- **Base URL**:
|
|
11
|
+
- **Base URL**: no default (must be configured)
|
|
12
12
|
- **Auth**: Bearer token (`Authorization: Bearer <api_key>`)
|
|
13
13
|
- **Override**: `ZAPIER_API_PLATFORM_BASE_URL` environment variable
|
|
14
14
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { ConnectorClient } from './client';
|
|
3
|
+
import { Connector } from './index';
|
|
3
4
|
|
|
4
5
|
const realFetch = globalThis.fetch;
|
|
5
6
|
|
|
@@ -38,43 +39,43 @@ afterEach(() => {
|
|
|
38
39
|
describe('Zapier API Platform client', () => {
|
|
39
40
|
test('listItems uses default base URL and Bearer auth', async () => {
|
|
40
41
|
const recorded = installFetch();
|
|
41
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
42
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
42
43
|
await client.items.list();
|
|
43
|
-
expect(recorded[0].url).toBe(
|
|
44
|
+
expect(recorded[0].url).toBe(`https://configured.example.com/v1/items`);
|
|
44
45
|
expect(recorded[0].method).toBe('GET');
|
|
45
46
|
expect(recorded[0].headers.get('Authorization')).toBe('Bearer test-key');
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
test('getItem encodes item ID in path', async () => {
|
|
49
50
|
const recorded = installFetch();
|
|
50
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
51
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
51
52
|
await client.items.get('item-1');
|
|
52
|
-
expect(recorded[0].url).toBe(
|
|
53
|
+
expect(recorded[0].url).toBe(`https://configured.example.com/v1/items/item-1`);
|
|
53
54
|
expect(recorded[0].headers.get('Authorization')).toBe('Bearer test-key');
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
test('createItem POSTs JSON body to /items', async () => {
|
|
57
58
|
const recorded = installFetch();
|
|
58
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
59
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
59
60
|
await client.items.create({ name: 'example' });
|
|
60
|
-
expect(recorded[0].url).toBe(
|
|
61
|
+
expect(recorded[0].url).toBe(`https://configured.example.com/v1/items`);
|
|
61
62
|
expect(recorded[0].method).toBe('POST');
|
|
62
63
|
expect(recorded[0].headers.get('Authorization')).toBe('Bearer test-key');
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
test('listEvents hits /events', async () => {
|
|
66
67
|
const recorded = installFetch();
|
|
67
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
68
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
68
69
|
await client.events.list();
|
|
69
|
-
expect(recorded[0].url).toBe(
|
|
70
|
+
expect(recorded[0].url).toBe(`https://configured.example.com/v1/events`);
|
|
70
71
|
expect(recorded[0].headers.get('Authorization')).toBe('Bearer test-key');
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
test('search POSTs to /search', async () => {
|
|
74
75
|
const recorded = installFetch();
|
|
75
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
76
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
76
77
|
await client.search.search({ query: 'test' });
|
|
77
|
-
expect(recorded[0].url).toBe(
|
|
78
|
+
expect(recorded[0].url).toBe(`https://configured.example.com/v1/search`);
|
|
78
79
|
expect(recorded[0].method).toBe('POST');
|
|
79
80
|
expect(recorded[0].headers.get('Authorization')).toBe('Bearer test-key');
|
|
80
81
|
});
|
|
@@ -127,7 +128,7 @@ describe('Zapier API Platform client', () => {
|
|
|
127
128
|
} as Response;
|
|
128
129
|
}) as unknown as typeof fetch;
|
|
129
130
|
|
|
130
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
131
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
131
132
|
await expect(client.items.list()).resolves.toEqual({ ok: true });
|
|
132
133
|
expect(calls).toBe(2);
|
|
133
134
|
});
|
|
@@ -137,7 +138,7 @@ describe('Zapier API Platform client', () => {
|
|
|
137
138
|
throw new DOMException('The operation was aborted.', 'AbortError');
|
|
138
139
|
}) as unknown as typeof fetch;
|
|
139
140
|
|
|
140
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
141
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
141
142
|
await expect(client.getClient().request('/items', { retries: 0, timeout: 5 })).rejects.toThrow('Request timeout after 5ms');
|
|
142
143
|
});
|
|
143
144
|
|
|
@@ -160,7 +161,11 @@ describe('Zapier API Platform client', () => {
|
|
|
160
161
|
} as Response;
|
|
161
162
|
}) as unknown as typeof fetch;
|
|
162
163
|
|
|
163
|
-
const client = new Connector({ apiKey: 'test-key' });
|
|
164
|
+
const client = new Connector({ apiKey: 'test-key', baseUrl: 'https://configured.example.com/v1' });
|
|
164
165
|
await expect(client.getClient().request('/items', { retries: 0, timeout: 5 })).rejects.toThrow('Request timeout after 5ms');
|
|
165
166
|
});
|
|
167
|
+
|
|
168
|
+
test('refuses to send without a configured base URL (no default endpoint)', () => {
|
|
169
|
+
expect(() => new ConnectorClient({ apiKey: 'test-key' })).toThrow(/baseUrl/);
|
|
170
|
+
});
|
|
166
171
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ConnectorConfig, OutputFormat } from '../types';
|
|
2
2
|
import { ConnectorApiError, parseApiError } from '../types';
|
|
3
3
|
|
|
4
|
-
export const DEFAULT_BASE_URL = 'https://api.zapierapiplatform.com/v1';
|
|
5
|
-
|
|
6
4
|
export interface RequestOptions {
|
|
7
5
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
8
6
|
params?: Record<string, string | number | boolean | undefined>;
|
|
@@ -23,7 +21,10 @@ export class ConnectorClient {
|
|
|
23
21
|
throw new Error('Zapier API Platform API key is required');
|
|
24
22
|
}
|
|
25
23
|
this.apiKey = key;
|
|
26
|
-
|
|
24
|
+
if (!config.baseUrl) {
|
|
25
|
+
throw new Error('baseUrl is required: no default endpoint is configured; set baseUrl (profile, config, or the connector BASE_URL environment variable)');
|
|
26
|
+
}
|
|
27
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, '');
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
private buildUrl(path: string, params?: Record<string, string | number | boolean | undefined>): string {
|
|
@@ -45,7 +45,7 @@ export class Connector {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export { ConnectorClient
|
|
48
|
+
export { ConnectorClient } from './client';
|
|
49
49
|
export { ItemsApi } from './items';
|
|
50
50
|
export { EventsApi } from './events';
|
|
51
51
|
export { SearchApi } from './search';
|
|
@@ -173,7 +173,7 @@ configCmd
|
|
|
173
173
|
console.log(chalk.bold(`Active Profile: ${profileName}`));
|
|
174
174
|
info(`Config directory: ${getConfigDir()}`);
|
|
175
175
|
info(`API Key: ${apiKey ? `${apiKey.substring(0, 8)}...` : chalk.gray('not set')}`);
|
|
176
|
-
info(`Base URL: ${process.env.ZAPIER_API_PLATFORM_BASE_URL || chalk.gray('
|
|
176
|
+
info(`Base URL: ${process.env.ZAPIER_API_PLATFORM_BASE_URL || chalk.gray('none configured')}`);
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
configCmd
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export { Connector } from './api';
|
|
4
4
|
export * from './types';
|
|
5
5
|
|
|
6
|
-
export { ConnectorClient, ItemsApi, EventsApi, SearchApi, RawApi
|
|
6
|
+
export { ConnectorClient, ItemsApi, EventsApi, SearchApi, RawApi } from './api';
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
9
|
getApiKey,
|
package/dist/index.js
CHANGED
|
@@ -5764,7 +5764,7 @@ function extractGoogleError(body) {
|
|
|
5764
5764
|
// package.json
|
|
5765
5765
|
var package_default = {
|
|
5766
5766
|
name: "@hasna/connectors",
|
|
5767
|
-
version: "1.4.
|
|
5767
|
+
version: "1.4.3",
|
|
5768
5768
|
description: "Open source connector library - Install API connectors with a single command",
|
|
5769
5769
|
type: "module",
|
|
5770
5770
|
bin: {
|