@softr/sdk 0.0.6 → 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 +1 -1
- package/dist/react.d.ts +4 -0
- package/dist/react.js +11 -0
- package/dist/tanstack.d.ts +1 -1
- package/dist/tanstack.js +22 -21
- package/dist/{types-CtUT4jd7.d.ts → types-CjB4xUg-.d.ts} +8 -0
- package/package.json +7 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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
|
package/dist/react.d.ts
ADDED
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 };
|
package/dist/tanstack.d.ts
CHANGED
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
|
-
|
|
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":
|
|
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":
|
|
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":
|
|
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":
|
|
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,
|
|
@@ -241,10 +235,12 @@ var WorkflowAPIImpl = class {
|
|
|
241
235
|
//#region src/core/sdk.ts
|
|
242
236
|
var SoftrSDKImpl = class {
|
|
243
237
|
baseUrl;
|
|
238
|
+
userTimezone;
|
|
244
239
|
extraHeaders;
|
|
245
240
|
cachedMe = null;
|
|
246
241
|
constructor(config) {
|
|
247
242
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
243
|
+
this.userTimezone = config.userTimezone ?? import.meta.env.VITE_APP_TIMEZONE ?? "UTC";
|
|
248
244
|
this.extraHeaders = config.headers;
|
|
249
245
|
}
|
|
250
246
|
async me() {
|
|
@@ -274,7 +270,7 @@ var SoftrSDKImpl = class {
|
|
|
274
270
|
}
|
|
275
271
|
};
|
|
276
272
|
datasource(id) {
|
|
277
|
-
return new DatasourceAPIImpl(id, this._fetch.bind(this));
|
|
273
|
+
return new DatasourceAPIImpl(id, this._fetch.bind(this), this.userTimezone);
|
|
278
274
|
}
|
|
279
275
|
integration(id) {
|
|
280
276
|
return new IntegrationAPIImpl(id, this._fetch.bind(this));
|
|
@@ -294,11 +290,16 @@ var SoftrSDKImpl = class {
|
|
|
294
290
|
}
|
|
295
291
|
};
|
|
296
292
|
function createSoftrSDKFromRequest(request, baseUrl) {
|
|
293
|
+
const cookieHeader = request.headers.get("cookie") ?? "";
|
|
297
294
|
return new SoftrSDKImpl({
|
|
298
295
|
baseUrl,
|
|
299
|
-
|
|
296
|
+
userTimezone: parseCookie(cookieHeader, "user-timezone"),
|
|
297
|
+
headers: { cookie: cookieHeader }
|
|
300
298
|
});
|
|
301
299
|
}
|
|
300
|
+
function parseCookie(cookieHeader, name) {
|
|
301
|
+
return cookieHeader.split(";").map((c) => c.trim().split("=")).find(([k]) => k === name)?.[1];
|
|
302
|
+
}
|
|
302
303
|
|
|
303
304
|
//#endregion
|
|
304
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>[];
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softr/sdk",
|
|
3
|
-
"version": "0.0.
|
|
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
|
}
|