@softr/sdk 0.0.5 → 0.0.7

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.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as defineVisibility, C as AccessReason, D as SoftrUserGroups, E as SoftrUserGroupId, F as q, M as isAlreadySignedInError, N as isForbiddenError, O as User, P as isUnauthenticatedError, S as AccessError, T as SoftrContext, _ as SoftrUser, a as CreateOptions, b as AccessBehaviour, c as GetOptions, d as MetricOptions, f as MetricResult, g as SoftrSDK, h as SoftrRecord, i as ChartDataResult, j as isAccessError, k as VisibilityHandle, l as ListOptions, m as SoftrPermissions, n as AuthAPI, o as DatasourceAPI, p as SoftrMe, r as ChartDataOptions, s as DatasourcePermissions, t as AggregationFunction, u as ListResult, v as UpdateOptions, w as RouteVisibility, x as AccessCheck, y as WorkflowAPI } from "./types-BYfW8LV3.js";
1
+ import { A as VisibilityHandle, C as AccessError, D as SoftrUserGroupId, E as SoftrContext, F as isUnauthenticatedError, I as q, M as isAccessError, N as isAlreadySignedInError, O as SoftrUserGroups, P as isForbiddenError, S as AccessCheck, T as RouteVisibility, _ as SoftrSDK, a as CreateOptions, b as WorkflowAPI, c as GetOptions, d as ListResult, f as MetricOptions, g as SoftrRecord, h as SoftrPermissions, i as ChartDataResult, j as defineVisibility, k as User, l as IntegrationAPI, m as SoftrMe, n as AuthAPI, o as DatasourceAPI, p as MetricResult, r as ChartDataOptions, s as DatasourcePermissions, t as AggregationFunction, u as ListOptions, v as SoftrUser, w as AccessReason, x as AccessBehaviour, y as UpdateOptions } from "./types-CjB4xUg-.js";
2
2
  import * as _tanstack_react_start0 from "@tanstack/react-start";
3
3
 
4
4
  //#region src/auth/session.d.ts
@@ -34,4 +34,4 @@ declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddleware
34
34
  user: User | null;
35
35
  }>;
36
36
  //#endregion
37
- export { type AccessBehaviour, type AccessCheck, type AccessError, type AccessReason, type AggregationFunction, type AuthAPI, type ChartDataOptions, type ChartDataResult, type CreateOptions, type DatasourceAPI, type DatasourcePermissions, type GetOptions, type ListOptions, type ListResult, type MetricOptions, type MetricResult, type RouteVisibility, type SoftrContext, type SoftrMe, type SoftrPermissions, type SoftrRecord, type SoftrSDK, type SoftrUser, type SoftrUserGroupId, type SoftrUserGroups, type UpdateOptions, type User, type VisibilityHandle, type WorkflowAPI, defineVisibility, getSoftrUser, isAccessError, isAlreadySignedInError, isForbiddenError, isUnauthenticatedError, q, softrAuthMiddleware };
37
+ export { type AccessBehaviour, type AccessCheck, type AccessError, type AccessReason, type AggregationFunction, type AuthAPI, type ChartDataOptions, type ChartDataResult, type CreateOptions, type DatasourceAPI, type DatasourcePermissions, type GetOptions, type IntegrationAPI, type ListOptions, type ListResult, type MetricOptions, type MetricResult, type RouteVisibility, type SoftrContext, type SoftrMe, type SoftrPermissions, type SoftrRecord, type SoftrSDK, type SoftrUser, type SoftrUserGroupId, type SoftrUserGroups, type UpdateOptions, type User, type VisibilityHandle, type WorkflowAPI, defineVisibility, getSoftrUser, isAccessError, isAlreadySignedInError, isForbiddenError, isUnauthenticatedError, q, softrAuthMiddleware };
@@ -0,0 +1,4 @@
1
+ //#region src/react.d.ts
2
+ declare function useUserTimezone(): void;
3
+ //#endregion
4
+ export { useUserTimezone };
package/dist/react.js ADDED
@@ -0,0 +1,11 @@
1
+ import { useEffect } from "react";
2
+
3
+ //#region src/react.ts
4
+ function useUserTimezone() {
5
+ useEffect(() => {
6
+ document.cookie = `user-timezone=${Intl.DateTimeFormat().resolvedOptions().timeZone}; path=/`;
7
+ }, []);
8
+ }
9
+
10
+ //#endregion
11
+ export { useUserTimezone };
@@ -1,4 +1,4 @@
1
- import { g as SoftrSDK } from "./types-BYfW8LV3.js";
1
+ import { _ as SoftrSDK } from "./types-CjB4xUg-.js";
2
2
 
3
3
  //#region src/tanstack.d.ts
4
4
 
package/dist/tanstack.js CHANGED
@@ -4,13 +4,14 @@ import { createMiddleware } from "@tanstack/start";
4
4
  //#region src/core/datasource.ts
5
5
  const MAX_RECORD_COUNT = 100;
6
6
  const COUNT_CNT = "COUNT_CNT";
7
- const APP_TIMEZONE = "UTC";
8
7
  var DatasourceAPIImpl = class {
9
8
  id;
10
9
  fetch;
11
- constructor(id, fetch$1) {
10
+ userTimezone;
11
+ constructor(id, fetch$1, userTimezone = "UTC") {
12
12
  this.id = id;
13
13
  this.fetch = fetch$1;
14
+ this.userTimezone = userTimezone;
14
15
  }
15
16
  async list(options = {}) {
16
17
  const { select, where, orderBy } = options;
@@ -22,13 +23,10 @@ var DatasourceAPIImpl = class {
22
23
  method: "POST",
23
24
  headers: {
24
25
  "Content-Type": "application/json",
25
- "X-User-Timezone": APP_TIMEZONE
26
+ "X-User-Timezone": options.timeZone ?? this.userTimezone
26
27
  },
27
28
  body: JSON.stringify({
28
- options: {
29
- timeZone: APP_TIMEZONE,
30
- userLocale: "en-US"
31
- },
29
+ options: { userLocale: "en-US" },
32
30
  filterCriteria,
33
31
  sortingOption,
34
32
  pagingOption: {
@@ -56,12 +54,9 @@ var DatasourceAPIImpl = class {
56
54
  method: "POST",
57
55
  headers: {
58
56
  "Content-Type": "application/json",
59
- "X-User-Timezone": APP_TIMEZONE
57
+ "X-User-Timezone": options.timeZone ?? this.userTimezone
60
58
  },
61
- body: JSON.stringify({ options: {
62
- timeZone: APP_TIMEZONE,
63
- userLocale: "en-US"
64
- } })
59
+ body: JSON.stringify({ options: { userLocale: "en-US" } })
65
60
  });
66
61
  if (!res.ok) throw new Error(`Softr datasource get failed for "${this.id}": ${res.status}`);
67
62
  const contentLength = res.headers.get("Content-Length");
@@ -70,7 +65,8 @@ var DatasourceAPIImpl = class {
70
65
  }
71
66
  return (await this.list({
72
67
  where: options.where,
73
- limit: 1
68
+ limit: 1,
69
+ timeZone: options.timeZone
74
70
  })).records[0] ?? null;
75
71
  }
76
72
  async create(options) {
@@ -104,13 +100,10 @@ var DatasourceAPIImpl = class {
104
100
  method: "POST",
105
101
  headers: {
106
102
  "Content-Type": "application/json",
107
- "X-User-Timezone": APP_TIMEZONE
103
+ "X-User-Timezone": options.timeZone ?? this.userTimezone
108
104
  },
109
105
  body: JSON.stringify({
110
- options: {
111
- timeZone: APP_TIMEZONE,
112
- userLocale: "en-US"
113
- },
106
+ options: { userLocale: "en-US" },
114
107
  calculationField: {
115
108
  field: fieldId,
116
109
  aggregation
@@ -145,9 +138,10 @@ var DatasourceAPIImpl = class {
145
138
  method: "POST",
146
139
  headers: {
147
140
  "Content-Type": "application/json",
148
- "X-User-Timezone": APP_TIMEZONE
141
+ "X-User-Timezone": options.timeZone ?? this.userTimezone
149
142
  },
150
143
  body: JSON.stringify({
144
+ options: { userLocale: "en-US" },
151
145
  filterCriteria,
152
146
  sortingOption,
153
147
  xAxisFields: groupByFields,
@@ -184,6 +178,38 @@ function aliasFields(fields, aliases) {
184
178
  return result;
185
179
  }
186
180
 
181
+ //#endregion
182
+ //#region src/core/integration.ts
183
+ var IntegrationAPIImpl = class {
184
+ id;
185
+ request;
186
+ constructor(id, fetch$1) {
187
+ this.id = id;
188
+ this.request = fetch$1;
189
+ }
190
+ async fetch(input, init) {
191
+ const req = new Request(input, init);
192
+ if (req.signal.aborted) throw req.signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
193
+ const headers = {};
194
+ new Headers(req.headers).forEach((value, key) => {
195
+ headers[key] = value;
196
+ });
197
+ const payload = {
198
+ method: req.method,
199
+ url: req.url,
200
+ headers
201
+ };
202
+ const method = req.method.toUpperCase();
203
+ if (method !== "GET" && method !== "HEAD" && req.body !== null) payload.body = await req.clone().text();
204
+ return this.request(`/api/integrations/${this.id}/proxy`, {
205
+ method: "POST",
206
+ headers: { "Content-Type": "application/json" },
207
+ body: JSON.stringify(payload),
208
+ signal: req.signal
209
+ });
210
+ }
211
+ };
212
+
187
213
  //#endregion
188
214
  //#region src/core/workflow.ts
189
215
  var WorkflowAPIImpl = class {
@@ -209,10 +235,12 @@ var WorkflowAPIImpl = class {
209
235
  //#region src/core/sdk.ts
210
236
  var SoftrSDKImpl = class {
211
237
  baseUrl;
238
+ userTimezone;
212
239
  extraHeaders;
213
240
  cachedMe = null;
214
241
  constructor(config) {
215
242
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
243
+ this.userTimezone = config.userTimezone ?? import.meta.env.VITE_APP_TIMEZONE ?? "UTC";
216
244
  this.extraHeaders = config.headers;
217
245
  }
218
246
  async me() {
@@ -242,7 +270,10 @@ var SoftrSDKImpl = class {
242
270
  }
243
271
  };
244
272
  datasource(id) {
245
- return new DatasourceAPIImpl(id, this._fetch.bind(this));
273
+ return new DatasourceAPIImpl(id, this._fetch.bind(this), this.userTimezone);
274
+ }
275
+ integration(id) {
276
+ return new IntegrationAPIImpl(id, this._fetch.bind(this));
246
277
  }
247
278
  workflow(id) {
248
279
  return new WorkflowAPIImpl(id, this._fetch.bind(this));
@@ -259,11 +290,16 @@ var SoftrSDKImpl = class {
259
290
  }
260
291
  };
261
292
  function createSoftrSDKFromRequest(request, baseUrl) {
293
+ const cookieHeader = request.headers.get("cookie") ?? "";
262
294
  return new SoftrSDKImpl({
263
295
  baseUrl,
264
- headers: { cookie: request.headers.get("cookie") ?? "" }
296
+ userTimezone: parseCookie(cookieHeader, "user-timezone"),
297
+ headers: { cookie: cookieHeader }
265
298
  });
266
299
  }
300
+ function parseCookie(cookieHeader, name) {
301
+ return cookieHeader.split(";").map((c) => c.trim().split("=")).find(([k]) => k === name)?.[1];
302
+ }
267
303
 
268
304
  //#endregion
269
305
  //#region src/tanstack.ts
@@ -537,10 +537,12 @@ interface SoftrMe {
537
537
  type GetByIdOptions = {
538
538
  id: string;
539
539
  where?: never;
540
+ timeZone?: string;
540
541
  };
541
542
  type GetByWhereOptions = {
542
543
  id?: never;
543
544
  where: AnyConstructable;
545
+ timeZone?: string;
544
546
  };
545
547
  type GetOptions = GetByIdOptions | GetByWhereOptions;
546
548
  interface ListOptions {
@@ -560,6 +562,8 @@ interface ListOptions {
560
562
  * Omit or pass `null` to start from the beginning.
561
563
  */
562
564
  offset?: number | null;
565
+ /** Override the timezone for this request. */
566
+ timeZone?: string;
563
567
  }
564
568
  interface ListResult<T = SoftrRecord> {
565
569
  records: T[];
@@ -578,6 +582,8 @@ interface MetricOptions {
578
582
  aggregation: AggregationFunction;
579
583
  /** Field alias (resolved via select) or raw field ID. Not required for COUNT. */
580
584
  field?: string;
585
+ /** Override the timezone for this request. */
586
+ timeZone?: string;
581
587
  }
582
588
  interface MetricResult {
583
589
  value: number | null;
@@ -593,6 +599,8 @@ interface ChartDataOptions {
593
599
  aggregation: AggregationFunction;
594
600
  }>;
595
601
  orderBy?: ConstructableOrderBy;
602
+ /** Override the timezone for this request. */
603
+ timeZone?: string;
596
604
  }
597
605
  interface ChartDataResult {
598
606
  data: Record<string, unknown>[];
@@ -614,6 +622,18 @@ interface DatasourceAPI {
614
622
  metric(options: MetricOptions): Promise<MetricResult>;
615
623
  chartData(options: ChartDataOptions): Promise<ChartDataResult>;
616
624
  }
625
+ /**
626
+ * Proxy fetch for a configured integration (e.g. Google Calendar).
627
+ * Behaves like the native `fetch` API — requests are forwarded through
628
+ * Softr's proxy, which handles authentication with the third-party service.
629
+ *
630
+ * ⚠️ Caveats (same as the vibe block's `useProxyFetch`):
631
+ * - Body must be a string — FormData and other binary types are not supported.
632
+ * - Multi-value headers are flattened.
633
+ */
634
+ interface IntegrationAPI {
635
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
636
+ }
617
637
  interface WorkflowAPI {
618
638
  trigger(payload?: Record<string, unknown>): Promise<void>;
619
639
  }
@@ -634,7 +654,8 @@ interface SoftrSDK {
634
654
  me(): Promise<SoftrMe>;
635
655
  auth: AuthAPI;
636
656
  datasource(id: string): DatasourceAPI;
657
+ integration(id: string): IntegrationAPI;
637
658
  workflow(id: string): WorkflowAPI;
638
659
  }
639
660
  //#endregion
640
- export { defineVisibility as A, AccessReason as C, SoftrUserGroups as D, SoftrUserGroupId as E, q as F, isAlreadySignedInError as M, isForbiddenError as N, User as O, isUnauthenticatedError as P, AccessError as S, SoftrContext as T, SoftrUser as _, CreateOptions as a, AccessBehaviour as b, GetOptions as c, MetricOptions as d, MetricResult as f, SoftrSDK as g, SoftrRecord as h, ChartDataResult as i, isAccessError as j, VisibilityHandle as k, ListOptions as l, SoftrPermissions as m, AuthAPI as n, DatasourceAPI as o, SoftrMe as p, ChartDataOptions as r, DatasourcePermissions as s, AggregationFunction as t, ListResult as u, UpdateOptions as v, RouteVisibility as w, AccessCheck as x, WorkflowAPI as y };
661
+ export { VisibilityHandle as A, AccessError as C, SoftrUserGroupId as D, SoftrContext as E, isUnauthenticatedError as F, q as I, isAccessError as M, isAlreadySignedInError as N, SoftrUserGroups as O, isForbiddenError as P, AccessCheck as S, RouteVisibility as T, SoftrSDK as _, CreateOptions as a, WorkflowAPI as b, GetOptions as c, ListResult as d, MetricOptions as f, SoftrRecord as g, SoftrPermissions as h, ChartDataResult as i, defineVisibility as j, User as k, IntegrationAPI as l, SoftrMe as m, AuthAPI as n, DatasourceAPI as o, MetricResult as p, ChartDataOptions as r, DatasourcePermissions as s, AggregationFunction as t, ListOptions as u, SoftrUser as v, AccessReason as w, AccessBehaviour as x, UpdateOptions as y };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
7
7
  "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" },
8
- "./tanstack": { "types": "./dist/tanstack.d.ts", "import": "./dist/tanstack.js" }
8
+ "./tanstack": { "types": "./dist/tanstack.d.ts", "import": "./dist/tanstack.js" },
9
+ "./react": { "types": "./dist/react.d.ts", "import": "./dist/react.js" }
9
10
  },
10
11
  "files": ["dist"],
11
12
  "publishConfig": { "access": "public" },
@@ -30,11 +31,15 @@
30
31
  "vite": "^8.0.0"
31
32
  },
32
33
  "peerDependencies": {
34
+ "react": ">=18",
33
35
  "vite": "^8.0.0",
34
36
  "@tanstack/react-router": "^1.168.0",
35
37
  "@tanstack/react-start": "^1.168.0"
36
38
  },
37
39
  "peerDependenciesMeta": {
40
+ "react": {
41
+ "optional": true
42
+ },
38
43
  "vite": {
39
44
  "optional": true
40
45
  }