@linabase/js 0.5.0 → 0.5.2

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.cjs CHANGED
@@ -52,7 +52,12 @@ var DatabaseClient = class {
52
52
  // ─── Query Methods ──────────────────────────────────────
53
53
  /** Select columns. Supports nested joins: "*, comments(*)" and aliases: "full_name:name" */
54
54
  select(columns, options) {
55
- this.method = options?.head ? "HEAD" : "GET";
55
+ const isMutation = this.method === "POST" || this.method === "PATCH" || this.method === "DELETE";
56
+ if (!isMutation) {
57
+ this.method = options?.head ? "HEAD" : "GET";
58
+ } else if (!this.preferHeaders.some((h) => h.startsWith("return="))) {
59
+ this.preferHeaders.push("return=representation");
60
+ }
56
61
  if (columns && columns !== "*") this.params.set("select", columns);
57
62
  if (options?.count) this.preferHeaders.push(`count=${options.count}`);
58
63
  return this;
@@ -1062,6 +1067,41 @@ var AuthClient = class {
1062
1067
  } catch (err) {
1063
1068
  return { error: { message: err.message } };
1064
1069
  }
1070
+ },
1071
+ async listSessions(userId) {
1072
+ try {
1073
+ const res = await request(`/auth/v1/admin/users/${userId}/sessions`);
1074
+ const data = await res.json();
1075
+ if (!res.ok) return { data: null, error: data };
1076
+ return { data: data.sessions, error: null };
1077
+ } catch (err) {
1078
+ return { data: null, error: { message: err.message } };
1079
+ }
1080
+ },
1081
+ async deleteSession(userId, sessionId) {
1082
+ try {
1083
+ const res = await request(`/auth/v1/admin/users/${userId}/sessions/${sessionId}`, {
1084
+ method: "DELETE"
1085
+ });
1086
+ const data = await res.json().catch(() => ({}));
1087
+ if (!res.ok) return { data: null, error: data };
1088
+ return { data, error: null };
1089
+ } catch (err) {
1090
+ return { data: null, error: { message: err.message } };
1091
+ }
1092
+ },
1093
+ async deleteOtherSessions(userId, exceptSessionId) {
1094
+ try {
1095
+ const qs = exceptSessionId ? `?except=${encodeURIComponent(exceptSessionId)}` : "";
1096
+ const res = await request(`/auth/v1/admin/users/${userId}/sessions${qs}`, {
1097
+ method: "DELETE"
1098
+ });
1099
+ const data = await res.json().catch(() => ({}));
1100
+ if (!res.ok) return { data: null, error: data };
1101
+ return { data, error: null };
1102
+ } catch (err) {
1103
+ return { data: null, error: { message: err.message } };
1104
+ }
1065
1105
  }
1066
1106
  };
1067
1107
  }
package/dist/index.d.cts CHANGED
@@ -451,6 +451,18 @@ declare class AuthClient {
451
451
  deleteUser(id: string): Promise<{
452
452
  error: any;
453
453
  }>;
454
+ listSessions(userId: string): Promise<{
455
+ data: any;
456
+ error: any;
457
+ }>;
458
+ deleteSession(userId: string, sessionId: string): Promise<{
459
+ data: any;
460
+ error: any;
461
+ }>;
462
+ deleteOtherSessions(userId: string, exceptSessionId?: string): Promise<{
463
+ data: any;
464
+ error: any;
465
+ }>;
454
466
  };
455
467
  get mfa(): {
456
468
  enroll(params: {
package/dist/index.d.ts CHANGED
@@ -451,6 +451,18 @@ declare class AuthClient {
451
451
  deleteUser(id: string): Promise<{
452
452
  error: any;
453
453
  }>;
454
+ listSessions(userId: string): Promise<{
455
+ data: any;
456
+ error: any;
457
+ }>;
458
+ deleteSession(userId: string, sessionId: string): Promise<{
459
+ data: any;
460
+ error: any;
461
+ }>;
462
+ deleteOtherSessions(userId: string, exceptSessionId?: string): Promise<{
463
+ data: any;
464
+ error: any;
465
+ }>;
454
466
  };
455
467
  get mfa(): {
456
468
  enroll(params: {
package/dist/index.js CHANGED
@@ -20,7 +20,12 @@ var DatabaseClient = class {
20
20
  // ─── Query Methods ──────────────────────────────────────
21
21
  /** Select columns. Supports nested joins: "*, comments(*)" and aliases: "full_name:name" */
22
22
  select(columns, options) {
23
- this.method = options?.head ? "HEAD" : "GET";
23
+ const isMutation = this.method === "POST" || this.method === "PATCH" || this.method === "DELETE";
24
+ if (!isMutation) {
25
+ this.method = options?.head ? "HEAD" : "GET";
26
+ } else if (!this.preferHeaders.some((h) => h.startsWith("return="))) {
27
+ this.preferHeaders.push("return=representation");
28
+ }
24
29
  if (columns && columns !== "*") this.params.set("select", columns);
25
30
  if (options?.count) this.preferHeaders.push(`count=${options.count}`);
26
31
  return this;
@@ -1030,6 +1035,41 @@ var AuthClient = class {
1030
1035
  } catch (err) {
1031
1036
  return { error: { message: err.message } };
1032
1037
  }
1038
+ },
1039
+ async listSessions(userId) {
1040
+ try {
1041
+ const res = await request(`/auth/v1/admin/users/${userId}/sessions`);
1042
+ const data = await res.json();
1043
+ if (!res.ok) return { data: null, error: data };
1044
+ return { data: data.sessions, error: null };
1045
+ } catch (err) {
1046
+ return { data: null, error: { message: err.message } };
1047
+ }
1048
+ },
1049
+ async deleteSession(userId, sessionId) {
1050
+ try {
1051
+ const res = await request(`/auth/v1/admin/users/${userId}/sessions/${sessionId}`, {
1052
+ method: "DELETE"
1053
+ });
1054
+ const data = await res.json().catch(() => ({}));
1055
+ if (!res.ok) return { data: null, error: data };
1056
+ return { data, error: null };
1057
+ } catch (err) {
1058
+ return { data: null, error: { message: err.message } };
1059
+ }
1060
+ },
1061
+ async deleteOtherSessions(userId, exceptSessionId) {
1062
+ try {
1063
+ const qs = exceptSessionId ? `?except=${encodeURIComponent(exceptSessionId)}` : "";
1064
+ const res = await request(`/auth/v1/admin/users/${userId}/sessions${qs}`, {
1065
+ method: "DELETE"
1066
+ });
1067
+ const data = await res.json().catch(() => ({}));
1068
+ if (!res.ok) return { data: null, error: data };
1069
+ return { data, error: null };
1070
+ } catch (err) {
1071
+ return { data: null, error: { message: err.message } };
1072
+ }
1033
1073
  }
1034
1074
  };
1035
1075
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linabase/js",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "JavaScript/TypeScript client SDK for Linabase (database, storage, auth)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,23 +35,24 @@
35
35
  "directory": "packages/sdk-js"
36
36
  },
37
37
  "homepage": "https://linabase.com",
38
- "devDependencies": {
39
- "@types/pg": "^8.11.0",
40
- "@vitest/coverage-v8": "^3.2.4",
41
- "pg": "^8.13.0",
42
- "tsup": "^8.3.0",
43
- "typescript": "^5.7.0",
44
- "vitest": "^3.2.1",
45
- "@linabase/rest-api": "0.0.1",
46
- "@linabase/db": "0.0.1"
47
- },
48
38
  "scripts": {
49
39
  "build": "tsup",
50
40
  "dev": "tsup --watch",
41
+ "prepublishOnly": "tsup",
51
42
  "test": "vitest run",
52
43
  "test:watch": "vitest",
53
44
  "test:coverage": "vitest run --coverage",
54
45
  "typecheck": "tsc --noEmit",
55
46
  "lint": "eslint src/"
47
+ },
48
+ "devDependencies": {
49
+ "@linabase/db": "workspace:*",
50
+ "@linabase/rest-api": "workspace:*",
51
+ "@types/pg": "^8.11.0",
52
+ "@vitest/coverage-v8": "^3.2.4",
53
+ "pg": "^8.13.0",
54
+ "tsup": "^8.3.0",
55
+ "typescript": "^5.7.0",
56
+ "vitest": "^3.2.1"
56
57
  }
57
- }
58
+ }