@blinkdotnew/dev-sdk 2.3.3 → 2.3.4-dev.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/dist/index.d.mts CHANGED
@@ -946,6 +946,10 @@ declare class HttpClient {
946
946
  dbPost<T = any>(table: string, body: any, options?: {
947
947
  returning?: boolean;
948
948
  }): Promise<BlinkResponse<T | T[]>>;
949
+ dbUpsert<T = any>(table: string, body: any, options?: {
950
+ onConflict?: string;
951
+ returning?: boolean;
952
+ }): Promise<BlinkResponse<T | T[]>>;
949
953
  dbPatch<T = any>(table: string, body: any, searchParams?: Record<string, string>, options?: {
950
954
  returning?: boolean;
951
955
  }): Promise<BlinkResponse<T[]>>;
package/dist/index.d.ts CHANGED
@@ -946,6 +946,10 @@ declare class HttpClient {
946
946
  dbPost<T = any>(table: string, body: any, options?: {
947
947
  returning?: boolean;
948
948
  }): Promise<BlinkResponse<T | T[]>>;
949
+ dbUpsert<T = any>(table: string, body: any, options?: {
950
+ onConflict?: string;
951
+ returning?: boolean;
952
+ }): Promise<BlinkResponse<T | T[]>>;
949
953
  dbPatch<T = any>(table: string, body: any, searchParams?: Record<string, string>, options?: {
950
954
  returning?: boolean;
951
955
  }): Promise<BlinkResponse<T[]>>;
package/dist/index.js CHANGED
@@ -397,7 +397,7 @@ function convertKeysToCamelCase(obj) {
397
397
  }
398
398
  var HttpClient = class {
399
399
  authUrl = "https://blink.new";
400
- coreUrl = "https://core.blink.new";
400
+ coreUrl = "https://dev.core.blink.new";
401
401
  projectId;
402
402
  publishableKey;
403
403
  secretKey;
@@ -531,6 +531,28 @@ var HttpClient = class {
531
531
  data: convertedData
532
532
  };
533
533
  }
534
+ async dbUpsert(table, body, options = {}) {
535
+ const headers = {};
536
+ if (options.returning) {
537
+ headers.Prefer = "return=representation";
538
+ }
539
+ const convertedBody = convertKeysToSnakeCase(body);
540
+ const onConflict = options.onConflict || "id";
541
+ const response = await this.request(
542
+ `/api/db/${this.projectId}/rest/v1/${table}`,
543
+ {
544
+ method: "POST",
545
+ body: convertedBody,
546
+ headers,
547
+ searchParams: { on_conflict: onConflict }
548
+ }
549
+ );
550
+ const convertedData = convertKeysToCamelCase(response.data);
551
+ return {
552
+ ...response,
553
+ data: convertedData
554
+ };
555
+ }
534
556
  async dbPatch(table, body, searchParams, options = {}) {
535
557
  const headers = {};
536
558
  if (options.returning) {
@@ -3252,21 +3274,12 @@ var BlinkTable = class {
3252
3274
  * Upsert a single record (insert or update on conflict)
3253
3275
  */
3254
3276
  async upsert(data, options = {}) {
3255
- const headers = {};
3256
- if (options.returning !== false) {
3257
- headers.Prefer = "return=representation";
3258
- }
3259
- if (options.onConflict) {
3260
- headers["Prefer"] = `${headers["Prefer"] || ""} resolution=merge-duplicates`.trim();
3261
- }
3262
3277
  const record = ensureRecordId(data);
3263
- const response = await this.httpClient.request(
3264
- `/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
3265
- {
3266
- method: "POST",
3267
- body: record,
3268
- headers
3269
- }
3278
+ const onConflict = options.onConflict || "id";
3279
+ const response = await this.httpClient.dbUpsert(
3280
+ this.actualTableName,
3281
+ record,
3282
+ { onConflict, returning: options.returning !== false }
3270
3283
  );
3271
3284
  const result = Array.isArray(response.data) ? response.data[0] : response.data;
3272
3285
  if (!result) {
@@ -3279,20 +3292,11 @@ var BlinkTable = class {
3279
3292
  */
3280
3293
  async upsertMany(data, options = {}) {
3281
3294
  const records = data.map(ensureRecordId);
3282
- const headers = {};
3283
- if (options.returning !== false) {
3284
- headers.Prefer = "return=representation";
3285
- }
3286
- if (options.onConflict) {
3287
- headers["Prefer"] = `${headers["Prefer"] || ""} resolution=merge-duplicates`.trim();
3288
- }
3289
- const response = await this.httpClient.request(
3290
- `/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
3291
- {
3292
- method: "POST",
3293
- body: records,
3294
- headers
3295
- }
3295
+ const onConflict = options.onConflict || "id";
3296
+ const response = await this.httpClient.dbUpsert(
3297
+ this.actualTableName,
3298
+ records,
3299
+ { onConflict, returning: options.returning !== false }
3296
3300
  );
3297
3301
  const results = Array.isArray(response.data) ? response.data : [response.data];
3298
3302
  return results;
package/dist/index.mjs CHANGED
@@ -395,7 +395,7 @@ function convertKeysToCamelCase(obj) {
395
395
  }
396
396
  var HttpClient = class {
397
397
  authUrl = "https://blink.new";
398
- coreUrl = "https://core.blink.new";
398
+ coreUrl = "https://dev.core.blink.new";
399
399
  projectId;
400
400
  publishableKey;
401
401
  secretKey;
@@ -529,6 +529,28 @@ var HttpClient = class {
529
529
  data: convertedData
530
530
  };
531
531
  }
532
+ async dbUpsert(table, body, options = {}) {
533
+ const headers = {};
534
+ if (options.returning) {
535
+ headers.Prefer = "return=representation";
536
+ }
537
+ const convertedBody = convertKeysToSnakeCase(body);
538
+ const onConflict = options.onConflict || "id";
539
+ const response = await this.request(
540
+ `/api/db/${this.projectId}/rest/v1/${table}`,
541
+ {
542
+ method: "POST",
543
+ body: convertedBody,
544
+ headers,
545
+ searchParams: { on_conflict: onConflict }
546
+ }
547
+ );
548
+ const convertedData = convertKeysToCamelCase(response.data);
549
+ return {
550
+ ...response,
551
+ data: convertedData
552
+ };
553
+ }
532
554
  async dbPatch(table, body, searchParams, options = {}) {
533
555
  const headers = {};
534
556
  if (options.returning) {
@@ -3250,21 +3272,12 @@ var BlinkTable = class {
3250
3272
  * Upsert a single record (insert or update on conflict)
3251
3273
  */
3252
3274
  async upsert(data, options = {}) {
3253
- const headers = {};
3254
- if (options.returning !== false) {
3255
- headers.Prefer = "return=representation";
3256
- }
3257
- if (options.onConflict) {
3258
- headers["Prefer"] = `${headers["Prefer"] || ""} resolution=merge-duplicates`.trim();
3259
- }
3260
3275
  const record = ensureRecordId(data);
3261
- const response = await this.httpClient.request(
3262
- `/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
3263
- {
3264
- method: "POST",
3265
- body: record,
3266
- headers
3267
- }
3276
+ const onConflict = options.onConflict || "id";
3277
+ const response = await this.httpClient.dbUpsert(
3278
+ this.actualTableName,
3279
+ record,
3280
+ { onConflict, returning: options.returning !== false }
3268
3281
  );
3269
3282
  const result = Array.isArray(response.data) ? response.data[0] : response.data;
3270
3283
  if (!result) {
@@ -3277,20 +3290,11 @@ var BlinkTable = class {
3277
3290
  */
3278
3291
  async upsertMany(data, options = {}) {
3279
3292
  const records = data.map(ensureRecordId);
3280
- const headers = {};
3281
- if (options.returning !== false) {
3282
- headers.Prefer = "return=representation";
3283
- }
3284
- if (options.onConflict) {
3285
- headers["Prefer"] = `${headers["Prefer"] || ""} resolution=merge-duplicates`.trim();
3286
- }
3287
- const response = await this.httpClient.request(
3288
- `/api/db/${this.httpClient.projectId}/rest/v1/${this.actualTableName}?on_conflict=${options.onConflict || "id"}`,
3289
- {
3290
- method: "POST",
3291
- body: records,
3292
- headers
3293
- }
3293
+ const onConflict = options.onConflict || "id";
3294
+ const response = await this.httpClient.dbUpsert(
3295
+ this.actualTableName,
3296
+ records,
3297
+ { onConflict, returning: options.returning !== false }
3294
3298
  );
3295
3299
  const results = Array.isArray(response.data) ? response.data : [response.data];
3296
3300
  return results;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/dev-sdk",
3
- "version": "2.3.3",
3
+ "version": "2.3.4-dev.1",
4
4
  "description": "Blink TypeScript SDK for client-side applications - Zero-boilerplate CRUD + auth + AI + analytics + notifications for modern SaaS/AI apps",
5
5
  "keywords": [
6
6
  "blink",