@ultrst-armada/kloks 1.7.1 → 1.8.0

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.
@@ -14,10 +14,11 @@ import {
14
14
  } from "../chunk-RBF2OGMC.js";
15
15
  import {
16
16
  workspaceGraphService
17
- } from "../chunk-F6IDQLC2.js";
18
- import "../chunk-R45CEV46.js";
17
+ } from "../chunk-5RXXC6GE.js";
19
18
  import "../chunk-6K75XXFD.js";
20
19
  import "../chunk-VAFCR2MS.js";
20
+ import "../chunk-SHZAQTIT.js";
21
+ import "../chunk-KKRWZDMN.js";
21
22
  import "../chunk-TY32TUNI.js";
22
23
  export {
23
24
  CompositeBackend,
@@ -16,8 +16,8 @@ import {
16
16
  getSrklAccounts,
17
17
  srklListBackblazeBuckets
18
18
  } from "../chunk-XHADDA75.js";
19
- import "../chunk-4QEMALXF.js";
20
19
  import "../chunk-VAFCR2MS.js";
20
+ import "../chunk-4QEMALXF.js";
21
21
  export {
22
22
  CANONICAL_SRKL_URL,
23
23
  SrklClient,
@@ -1,5 +1,5 @@
1
- import { B as BaseStorageAdapter, S as StorageConfig, F as FileInfo, D as DeleteFolderResult, R as RenameFolderResult, C as ConnectionTestResult } from '../BaseStorageAdapter-6x_BQiB3.js';
2
- export { a as StorageMode, b as StorageProviderType, U as UploadResult } from '../BaseStorageAdapter-6x_BQiB3.js';
1
+ import { B as BaseStorageAdapter, S as StorageConfig, F as FileInfo, D as DeleteFolderResult, R as RenameFolderResult, C as ConnectionTestResult } from '../BaseStorageAdapter-EUCSvJse.js';
2
+ export { a as StorageMode, b as StorageProviderType, U as UploadResult } from '../BaseStorageAdapter-EUCSvJse.js';
3
3
  import '@ultrst-armada/kloks/functions';
4
4
 
5
5
  declare class LocalFSAdapter extends BaseStorageAdapter {
@@ -1,31 +1,33 @@
1
1
  import {
2
2
  S3Adapter
3
- } from "../chunk-JUPWFW7V.js";
3
+ } from "../chunk-RBQ4CW3T.js";
4
+ import {
5
+ authorizeB2,
6
+ b2DownloadFile,
7
+ b2ListBuckets,
8
+ b2ListFileNames,
9
+ b2UploadFile
10
+ } from "../chunk-4QEMALXF.js";
4
11
  import {
5
12
  BackblazeB2Adapter,
6
- BaseStorageAdapter,
7
- GoogleDriveAdapter,
8
13
  LocalFSAdapter,
9
14
  StorageAdapterFactory,
10
15
  SupabaseStorageAdapter,
11
- createGoogleDriveAuthorizationUrl,
12
16
  ensureS3DirectoryMarker,
13
- exchangeGoogleDriveCode,
14
17
  isSecretMasked,
15
18
  normalizeBackblazeCredentials,
16
19
  permanentDeleteS3Folder,
17
20
  permanentDeleteS3Object,
18
- refreshGoogleDriveAccessToken,
19
21
  renameS3Folder,
20
22
  resolveBackblazeEndpoint
21
- } from "../chunk-R45CEV46.js";
23
+ } from "../chunk-SHZAQTIT.js";
22
24
  import {
23
- authorizeB2,
24
- b2DownloadFile,
25
- b2ListBuckets,
26
- b2ListFileNames,
27
- b2UploadFile
28
- } from "../chunk-4QEMALXF.js";
25
+ BaseStorageAdapter,
26
+ GoogleDriveAdapter,
27
+ createGoogleDriveAuthorizationUrl,
28
+ exchangeGoogleDriveCode,
29
+ refreshGoogleDriveAccessToken
30
+ } from "../chunk-KKRWZDMN.js";
29
31
  export {
30
32
  BackblazeB2Adapter,
31
33
  BaseStorageAdapter,
@@ -1,4 +1,4 @@
1
- import { B as BaseStorageAdapter, F as FileInfo } from '../BaseStorageAdapter-6x_BQiB3.js';
1
+ import { B as BaseStorageAdapter, F as FileInfo } from '../BaseStorageAdapter-EUCSvJse.js';
2
2
  import { SkipoBase } from '@ultrst-armada/kloks/functions';
3
3
 
4
4
  interface WorkspaceDescriptor {
@@ -6,13 +6,14 @@ import {
6
6
  WorkspaceFS,
7
7
  remoteWorkspaceService,
8
8
  workingWorkspaceService
9
- } from "../chunk-6W7OAGNV.js";
9
+ } from "../chunk-BTMIK44G.js";
10
10
  import {
11
11
  formatCanonicalWorkspaceFolderName,
12
12
  sanitizeWorkspaceName
13
13
  } from "../chunk-FZKBTF34.js";
14
14
  import "../chunk-6K75XXFD.js";
15
15
  import "../chunk-VAFCR2MS.js";
16
+ import "../chunk-KKRWZDMN.js";
16
17
  export {
17
18
  RemoteWorkspaceService,
18
19
  SyncEngine,
@@ -1,140 +0,0 @@
1
- // src/auth/SessionManager.ts
2
- var SessionManager = class {
3
- ttl;
4
- constructor(ttlMs = 864e5) {
5
- this.ttl = ttlMs;
6
- }
7
- generateToken(userId) {
8
- return `sess::${userId}::${Date.now()}::${Math.random().toString(36).substring(2, 9)}`;
9
- }
10
- createSession(userId, role) {
11
- return {
12
- token: this.generateToken(userId),
13
- userId,
14
- role,
15
- expiresAt: Date.now() + this.ttl
16
- };
17
- }
18
- isValid(session) {
19
- return Date.now() < session.expiresAt;
20
- }
21
- };
22
-
23
- // src/auth/RateLimiter.ts
24
- var RateLimiter = class {
25
- attempts = /* @__PURE__ */ new Map();
26
- windowMs;
27
- maxUser;
28
- maxAdmin;
29
- constructor(windowMs = 9e5, maxUser = 5, maxAdmin = 3) {
30
- this.windowMs = windowMs;
31
- this.maxUser = maxUser;
32
- this.maxAdmin = maxAdmin;
33
- }
34
- check(identifier, isAdminAttempt = false) {
35
- const now = Date.now();
36
- let record = this.attempts.get(identifier);
37
- if (!record || now - record.windowStart > this.windowMs) {
38
- record = { count: 0, windowStart: now };
39
- this.attempts.set(identifier, record);
40
- }
41
- record.count++;
42
- const limit = isAdminAttempt ? this.maxAdmin : this.maxUser;
43
- if (record.count > limit) {
44
- throw new Error("Too many requests. Please try again later.");
45
- }
46
- }
47
- reset(identifier) {
48
- this.attempts.delete(identifier);
49
- }
50
- };
51
-
52
- // src/auth/UnifiedAuthCore.ts
53
- import bcrypt from "bcryptjs";
54
- async function loginSystemUser(email, rawPass, isAdmin, queryDb) {
55
- const normEmail = (email || "").trim().toLowerCase();
56
- const password = (rawPass || "").trim();
57
- if (!normEmail || !password) {
58
- return { success: false, status: 400, error: "Email and password are required" };
59
- }
60
- try {
61
- if (isAdmin) {
62
- const credRes = await queryDb(`SELECT * FROM "ultrst-credentials" WHERE id = 'system' LIMIT 1`, []);
63
- if (credRes.rows.length > 0) {
64
- const cred = credRes.rows[0];
65
- const matchEmail = (cred.admin_email || "").toLowerCase() === normEmail;
66
- const matchPass = cred.admin_password === password || cred.admin_password && bcrypt.compareSync(password, cred.admin_password);
67
- if (matchEmail && matchPass) {
68
- return {
69
- success: true,
70
- status: 200,
71
- token: `adm_${Date.now()}_${Math.random().toString(36).slice(2)}`,
72
- user: { id: "admin_sys", email: cred.admin_email, username: "System Admin", name: "System Admin", role: "admin", status: "ACTIVE" }
73
- };
74
- }
75
- }
76
- }
77
- const uRes = await queryDb(`SELECT * FROM "ultrst-users" WHERE LOWER(email) = $1 LIMIT 1`, [normEmail]);
78
- if (uRes.rows.length === 0) {
79
- return { success: false, status: 401, error: "Invalid email or password" };
80
- }
81
- const user = uRes.rows[0];
82
- const hash = user.password_hash || "";
83
- let isMatch = false;
84
- if (hash.startsWith("$2a$") || hash.startsWith("$2b$")) {
85
- isMatch = bcrypt.compareSync(password, hash);
86
- } else {
87
- isMatch = hash === password;
88
- }
89
- if (!isMatch) {
90
- return { success: false, status: 401, error: "Invalid email or password" };
91
- }
92
- if (isAdmin && user.role !== "admin") {
93
- return { success: false, status: 403, error: "Insufficient administrative privileges" };
94
- }
95
- return {
96
- success: true,
97
- status: 200,
98
- token: `usr_${Date.now()}_${Math.random().toString(36).slice(2)}`,
99
- user: {
100
- id: user.id,
101
- email: user.email,
102
- username: user.username || user.name || user.email.split("@")[0],
103
- name: user.name || user.username || "Ecosystem User",
104
- role: user.role || "user",
105
- status: user.status || "ACTIVE",
106
- appProfiles: typeof user.app_profiles === "string" ? JSON.parse(user.app_profiles) : user.app_profiles || {}
107
- }
108
- };
109
- } catch (err) {
110
- return { success: false, status: 500, error: err.message };
111
- }
112
- }
113
- async function resolveUserFromToken(tokenOrUserId, queryDb) {
114
- if (!tokenOrUserId) return null;
115
- let targetId = tokenOrUserId;
116
- if (targetId.startsWith("Bearer ")) targetId = targetId.slice(7).trim();
117
- if (targetId.startsWith("sess::")) {
118
- const parts = targetId.split("::");
119
- if (parts[1]) targetId = parts[1];
120
- }
121
- const res = await queryDb(`SELECT * FROM "ultrst-users" WHERE id = $1 OR LOWER(email) = LOWER($1) LIMIT 1`, [targetId]);
122
- if (res.rows.length === 0) return null;
123
- const u = res.rows[0];
124
- return {
125
- id: u.id,
126
- email: u.email,
127
- username: u.username || u.name || u.email.split("@")[0],
128
- name: u.name || u.username || "Ecosystem User",
129
- role: u.role || "user",
130
- status: u.status || "ACTIVE",
131
- appProfiles: typeof u.app_profiles === "string" ? JSON.parse(u.app_profiles) : u.app_profiles || {}
132
- };
133
- }
134
-
135
- export {
136
- SessionManager,
137
- RateLimiter,
138
- loginSystemUser,
139
- resolveUserFromToken
140
- };