sharetribe-flex-build-sdk 1.15.0 → 1.15.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharetribe-flex-build-sdk",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "SDK for building and managing Sharetribe Flex transaction processes",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/api/client.ts CHANGED
@@ -8,13 +8,11 @@ import { get, post, del, request, postTransit, HttpResponse } from './http-clien
8
8
  import { createMultipartBody, MultipartField } from './multipart.js';
9
9
  import { encodeTransit, decodeTransit } from './transit.js';
10
10
  import { readAuth } from '../auth-storage.js';
11
+ import { getApiBaseUrl } from '../config.js';
11
12
 
12
13
  // Re-export MultipartField for use in commands
13
14
  export type { MultipartField };
14
15
 
15
- // API base URL - must match flex-cli exactly
16
- const API_BASE_URL = 'https://flex-build-api.sharetribe.com/v1/build-api';
17
-
18
16
  export interface ApiError {
19
17
  code: string;
20
18
  message: string;
@@ -81,7 +79,7 @@ function handleResponse<T>(response: HttpResponse): T {
81
79
  * @returns API response
82
80
  */
83
81
  export async function apiGet<T>(apiKey: string | undefined, endpoint: string, queryParams?: Record<string, string>): Promise<T> {
84
- const url = new URL(API_BASE_URL + endpoint);
82
+ const url = new URL(getApiBaseUrl() + endpoint);
85
83
  if (queryParams) {
86
84
  Object.entries(queryParams).forEach(([key, value]) => {
87
85
  url.searchParams.append(key, value);
@@ -107,7 +105,7 @@ export async function apiPost<T>(
107
105
  queryParams?: Record<string, string>,
108
106
  body?: unknown
109
107
  ): Promise<T> {
110
- const url = new URL(API_BASE_URL + endpoint);
108
+ const url = new URL(getApiBaseUrl() + endpoint);
111
109
  if (queryParams) {
112
110
  Object.entries(queryParams).forEach(([key, value]) => {
113
111
  url.searchParams.append(key, value);
@@ -131,7 +129,7 @@ export async function apiDelete<T>(
131
129
  endpoint: string,
132
130
  queryParams?: Record<string, string>
133
131
  ): Promise<T> {
134
- const url = new URL(API_BASE_URL + endpoint);
132
+ const url = new URL(getApiBaseUrl() + endpoint);
135
133
  if (queryParams) {
136
134
  Object.entries(queryParams).forEach(([key, value]) => {
137
135
  url.searchParams.append(key, value);
@@ -157,7 +155,7 @@ export async function apiPostMultipart<T>(
157
155
  queryParams: Record<string, string>,
158
156
  fields: MultipartField[]
159
157
  ): Promise<T> {
160
- const url = new URL(API_BASE_URL + endpoint);
158
+ const url = new URL(getApiBaseUrl() + endpoint);
161
159
  Object.entries(queryParams).forEach(([key, value]) => {
162
160
  url.searchParams.append(key, value);
163
161
  });
@@ -194,7 +192,7 @@ export async function apiPostTransit<T>(
194
192
  queryParams: Record<string, string>,
195
193
  body: unknown
196
194
  ): Promise<T> {
197
- const url = new URL(API_BASE_URL + endpoint);
195
+ const url = new URL(getApiBaseUrl() + endpoint);
198
196
  Object.entries(queryParams).forEach(([key, value]) => {
199
197
  url.searchParams.append(key, value);
200
198
  });
package/src/config.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Configuration helpers matching flex-cli behavior.
3
+ */
4
+
5
+ import { existsSync, readFileSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ import edn from 'jsedn';
8
+
9
+ const ENV_FILE = '.env.edn';
10
+ const DEFAULT_API_BASE_URL = 'https://flex-build-api.sharetribe.com/v1/build-api';
11
+
12
+ let envFileContent: any | null | undefined;
13
+
14
+ function readEnvFile(): any | null {
15
+ const envPath = join(process.cwd(), ENV_FILE);
16
+ if (!existsSync(envPath)) {
17
+ return null;
18
+ }
19
+
20
+ try {
21
+ const content = readFileSync(envPath, 'utf-8');
22
+ return edn.parse(content);
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ function getEnvValue(name: string): string | undefined {
29
+ const envValue = process.env[name];
30
+ if (envValue) {
31
+ return envValue;
32
+ }
33
+
34
+ if (envFileContent === undefined) {
35
+ envFileContent = readEnvFile();
36
+ }
37
+
38
+ if (envFileContent && typeof envFileContent.at === 'function') {
39
+ const value = envFileContent.at(name);
40
+ if (typeof value === 'string') {
41
+ return value;
42
+ }
43
+ }
44
+
45
+ return undefined;
46
+ }
47
+
48
+ export function getApiBaseUrl(): string {
49
+ return getEnvValue('FLEX_API_BASE_URL') || DEFAULT_API_BASE_URL;
50
+ }
51
+
52
+ export function getConfigMap(): Record<string, string> {
53
+ return {
54
+ 'api-base-url': getApiBaseUrl(),
55
+ };
56
+ }
57
+
58
+ export { DEFAULT_API_BASE_URL };
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ export {
64
64
 
65
65
  // Export authentication functions
66
66
  export {
67
+ readAuth,
67
68
  writeAuth,
68
69
  clearAuth,
69
70
  type AuthData,
@@ -99,3 +100,10 @@ export {
99
100
  SUPPORTED_STRIPE_VERSIONS,
100
101
  type StripeApiVersion,
101
102
  } from './stripe.js';
103
+
104
+ // Export configuration helpers
105
+ export {
106
+ getApiBaseUrl,
107
+ getConfigMap,
108
+ DEFAULT_API_BASE_URL,
109
+ } from './config.js';