@tinybirdco/sdk 0.0.30 → 0.0.32

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.
Files changed (80) hide show
  1. package/README.md +29 -4
  2. package/dist/cli/auth.d.ts.map +1 -1
  3. package/dist/cli/auth.js +1 -0
  4. package/dist/cli/auth.js.map +1 -1
  5. package/dist/cli/commands/branch.js +5 -5
  6. package/dist/cli/commands/branch.js.map +1 -1
  7. package/dist/cli/commands/build.d.ts.map +1 -1
  8. package/dist/cli/commands/build.js +2 -2
  9. package/dist/cli/commands/build.js.map +1 -1
  10. package/dist/cli/commands/build.test.d.ts +2 -0
  11. package/dist/cli/commands/build.test.d.ts.map +1 -0
  12. package/dist/cli/commands/build.test.js +266 -0
  13. package/dist/cli/commands/build.test.js.map +1 -0
  14. package/dist/cli/commands/clear.d.ts.map +1 -1
  15. package/dist/cli/commands/clear.js +2 -2
  16. package/dist/cli/commands/clear.js.map +1 -1
  17. package/dist/cli/commands/deploy.js +2 -2
  18. package/dist/cli/commands/deploy.js.map +1 -1
  19. package/dist/cli/commands/dev.js +12 -12
  20. package/dist/cli/commands/dev.js.map +1 -1
  21. package/dist/cli/commands/info.js +2 -2
  22. package/dist/cli/commands/info.js.map +1 -1
  23. package/dist/cli/commands/info.test.js +11 -13
  24. package/dist/cli/commands/info.test.js.map +1 -1
  25. package/dist/cli/commands/init.d.ts.map +1 -1
  26. package/dist/cli/commands/init.js +44 -26
  27. package/dist/cli/commands/init.js.map +1 -1
  28. package/dist/cli/commands/init.test.js +44 -25
  29. package/dist/cli/commands/init.test.js.map +1 -1
  30. package/dist/cli/commands/login.d.ts.map +1 -1
  31. package/dist/cli/commands/login.js +7 -6
  32. package/dist/cli/commands/login.js.map +1 -1
  33. package/dist/cli/commands/login.test.js +1 -1
  34. package/dist/cli/commands/login.test.js.map +1 -1
  35. package/dist/cli/commands/preview.d.ts.map +1 -1
  36. package/dist/cli/commands/preview.js +2 -2
  37. package/dist/cli/commands/preview.js.map +1 -1
  38. package/dist/cli/config-loader.d.ts +18 -0
  39. package/dist/cli/config-loader.d.ts.map +1 -0
  40. package/dist/cli/config-loader.js +57 -0
  41. package/dist/cli/config-loader.js.map +1 -0
  42. package/dist/cli/config-types.d.ts +28 -0
  43. package/dist/cli/config-types.d.ts.map +1 -0
  44. package/dist/cli/config-types.js +8 -0
  45. package/dist/cli/config-types.js.map +1 -0
  46. package/dist/cli/config.d.ts +63 -29
  47. package/dist/cli/config.d.ts.map +1 -1
  48. package/dist/cli/config.js +139 -43
  49. package/dist/cli/config.js.map +1 -1
  50. package/dist/cli/config.test.js +73 -9
  51. package/dist/cli/config.test.js.map +1 -1
  52. package/dist/cli/index.js +4 -0
  53. package/dist/cli/index.js.map +1 -1
  54. package/dist/client/base.d.ts.map +1 -1
  55. package/dist/client/base.js +21 -9
  56. package/dist/client/base.js.map +1 -1
  57. package/dist/index.d.ts +1 -0
  58. package/dist/index.d.ts.map +1 -1
  59. package/package.json +1 -1
  60. package/src/cli/auth.ts +1 -0
  61. package/src/cli/commands/branch.ts +5 -5
  62. package/src/cli/commands/build.test.ts +310 -0
  63. package/src/cli/commands/build.ts +2 -2
  64. package/src/cli/commands/clear.ts +2 -2
  65. package/src/cli/commands/deploy.ts +2 -2
  66. package/src/cli/commands/dev.ts +12 -12
  67. package/src/cli/commands/info.test.ts +11 -13
  68. package/src/cli/commands/info.ts +2 -2
  69. package/src/cli/commands/init.test.ts +53 -37
  70. package/src/cli/commands/init.ts +49 -30
  71. package/src/cli/commands/login.test.ts +1 -1
  72. package/src/cli/commands/login.ts +7 -6
  73. package/src/cli/commands/preview.ts +2 -2
  74. package/src/cli/config-loader.ts +87 -0
  75. package/src/cli/config-types.ts +29 -0
  76. package/src/cli/config.test.ts +95 -8
  77. package/src/cli/config.ts +179 -70
  78. package/src/cli/index.ts +3 -0
  79. package/src/client/base.ts +33 -16
  80. package/src/index.ts +4 -0
@@ -130,9 +130,11 @@ export class TinybirdClient {
130
130
  try {
131
131
  // Dynamic import to avoid circular dependencies and to keep CLI code
132
132
  // out of the client bundle when not using dev mode
133
- const { loadConfig } = await import("../cli/config.js");
133
+ const { loadConfigAsync } = await import("../cli/config.js");
134
134
  const { getOrCreateBranch } = await import("../api/branches.js");
135
- const { isPreviewEnvironment, getPreviewBranchName } = await import("./preview.js");
135
+ const { isPreviewEnvironment, getPreviewBranchName } = await import(
136
+ "./preview.js"
137
+ );
136
138
 
137
139
  // In preview environments (Vercel preview, CI), the token was already resolved
138
140
  // by resolveToken() in project.ts - skip branch creation to avoid conflicts
@@ -140,9 +142,14 @@ export class TinybirdClient {
140
142
  const gitBranchName = getPreviewBranchName();
141
143
  // Preview branches use the tmp_ci_ prefix (matches what tinybird preview creates)
142
144
  const sanitized = gitBranchName
143
- ? gitBranchName.replace(/[^a-zA-Z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "")
145
+ ? gitBranchName
146
+ .replace(/[^a-zA-Z0-9_]/g, "_")
147
+ .replace(/_+/g, "_")
148
+ .replace(/^_|_$/g, "")
149
+ : undefined;
150
+ const tinybirdBranchName = sanitized
151
+ ? `tmp_ci_${sanitized}`
144
152
  : undefined;
145
- const tinybirdBranchName = sanitized ? `tmp_ci_${sanitized}` : undefined;
146
153
  return this.buildContext({
147
154
  token: this.config.token,
148
155
  isBranchToken: !!tinybirdBranchName,
@@ -153,12 +160,16 @@ export class TinybirdClient {
153
160
 
154
161
  // Use configDir if provided (important for monorepo setups where process.cwd()
155
162
  // may not be in the same directory tree as tinybird.json)
156
- const config = loadConfig(this.config.configDir);
163
+ const config = await loadConfigAsync(this.config.configDir);
157
164
  const gitBranch = config.gitBranch ?? undefined;
158
165
 
159
166
  // If on main branch, use the workspace token
160
167
  if (config.isMainBranch || !config.tinybirdBranch) {
161
- return this.buildContext({ token: this.config.token, isBranchToken: false, gitBranch });
168
+ return this.buildContext({
169
+ token: this.config.token,
170
+ isBranchToken: false,
171
+ gitBranch,
172
+ });
162
173
  }
163
174
 
164
175
  const branchName = config.tinybirdBranch;
@@ -171,7 +182,11 @@ export class TinybirdClient {
171
182
 
172
183
  if (!branch.token) {
173
184
  // Fall back to workspace token if no branch token
174
- return this.buildContext({ token: this.config.token, isBranchToken: false, gitBranch });
185
+ return this.buildContext({
186
+ token: this.config.token,
187
+ isBranchToken: false,
188
+ gitBranch,
189
+ });
175
190
  }
176
191
 
177
192
  return this.buildContext({
@@ -180,9 +195,11 @@ export class TinybirdClient {
180
195
  branchName,
181
196
  gitBranch,
182
197
  });
183
- } catch {
184
- // If anything fails, fall back to the workspace token
185
- return this.buildContext({ token: this.config.token, isBranchToken: false });
198
+ } catch (error) {
199
+ throw new TinybirdError(
200
+ `Failed to resolve branch context: ${(error as Error).message}`,
201
+ 500
202
+ );
186
203
  }
187
204
  }
188
205
 
@@ -240,7 +257,11 @@ export class TinybirdClient {
240
257
  const token = await this.getToken();
241
258
 
242
259
  try {
243
- return await this.getApi(token).ingestBatch(datasourceName, events, options);
260
+ return await this.getApi(token).ingestBatch(
261
+ datasourceName,
262
+ events,
263
+ options
264
+ );
244
265
  } catch (error) {
245
266
  this.rethrowApiError(error);
246
267
  }
@@ -310,11 +331,7 @@ export class TinybirdClient {
310
331
 
311
332
  private rethrowApiError(error: unknown): never {
312
333
  if (error instanceof TinybirdApiError) {
313
- throw new TinybirdError(
314
- error.message,
315
- error.statusCode,
316
- error.response
317
- );
334
+ throw new TinybirdError(error.message, error.statusCode, error.response);
318
335
  }
319
336
 
320
337
  throw error;
package/src/index.ts CHANGED
@@ -245,3 +245,7 @@ export {
245
245
  getLocalDashboardUrl,
246
246
  } from "./api/dashboard.js";
247
247
  export type { RegionInfo } from "./api/dashboard.js";
248
+
249
+ // ============ Config Types ============
250
+ // Import from config-types.ts to avoid bundling esbuild in client code
251
+ export type { TinybirdConfig, DevMode } from "./cli/config-types.js";