@singularlogic/coreplatts 0.0.9 → 0.0.11

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 { AxiosInstance } from 'axios';
1
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
2
 
3
3
  interface Updated {
4
4
  by?: string;
@@ -38,6 +38,23 @@ interface FolderList {
38
38
  files: FileModel[];
39
39
  folder: FolderModel[];
40
40
  }
41
+ interface MultipartWrapper {
42
+ file: string;
43
+ folder: string;
44
+ parts: PartInfo[];
45
+ }
46
+ interface PartInfo {
47
+ number: number;
48
+ presigned_url: string;
49
+ etag: string;
50
+ uploaded: boolean;
51
+ }
52
+ interface ErrorReport {
53
+ internal_status?: string;
54
+ status: number;
55
+ message?: string;
56
+ reason: string;
57
+ }
41
58
 
42
59
  declare class File$1 implements FileModel {
43
60
  protected _httpClient: AxiosInstance;
@@ -95,7 +112,7 @@ interface UserAccess {
95
112
  impersonate: boolean;
96
113
  manage: boolean;
97
114
  }
98
- interface User$1 {
115
+ interface User {
99
116
  id: string;
100
117
  username: string;
101
118
  firstName: string;
@@ -112,7 +129,7 @@ interface User$1 {
112
129
  access: UserAccess;
113
130
  }
114
131
 
115
- interface Group$1 {
132
+ interface Group {
116
133
  id?: string;
117
134
  name: string;
118
135
  path: string;
@@ -135,44 +152,79 @@ interface Bucket {
135
152
  creation_date?: Date;
136
153
  }
137
154
 
155
+ type TokenProvider = () => string | Promise<string>;
138
156
  interface IClient$1 {
139
157
  login(email: string, password: string): Promise<OidcToken>;
140
- myUser(token?: string): Promise<User$1>;
141
- allOrganizations(token?: string): Promise<Group$1[]>;
142
- myOrganizations(token?: string): Promise<Group$1[]>;
143
- organizationByID(id: string, token?: string): Promise<Group$1>;
144
- organizationByName(name: string, token?: string): Promise<Group$1>;
158
+ myUser(token?: string): Promise<User>;
159
+ allOrganizations(token?: string): Promise<Group[]>;
160
+ myOrganizations(token?: string): Promise<Group[]>;
161
+ organizationByID(id: string, token?: string): Promise<Group>;
162
+ organizationByName(name: string, token?: string): Promise<Group>;
163
+ addToOrganization(organization: string, users: UserRoles, token?: string): Promise<void>;
164
+ register(email: string, password: string, password_confirm: string, firstName: string, lastName: string): Promise<void>;
145
165
  createOrganization(name: string, token?: string): Promise<Bucket>;
146
- addToOrganization(organization: string, users: UserRoles, token?: string): void;
166
+ removeOrganizationByID(organization: string, token?: string): Promise<Bucket>;
147
167
  getFolderByName(name: string, token?: string): Promise<Folder>;
148
168
  getFolderByID(id: string, token?: string): Promise<Folder>;
149
- removeOrganizationByID(organization: string, token?: string): Promise<Bucket>;
150
- register(email: string, password: string, password_confirm: string, firstName: string, lastName: string): void;
151
169
  }
170
+ /**
171
+ * Client supports:
172
+ * - Keycloak mode: setTokenProvider(() => auth.getValidToken())
173
+ * - Legacy mode: login(email, pass) -> stores tokens in sessionStorage
174
+ *
175
+ * For SPAs with Keycloak: DO NOT store tokens. Use setTokenProvider.
176
+ */
152
177
  declare class Client implements IClient$1 {
153
178
  private _userConsumer;
154
179
  private _groupConsumer;
155
180
  private _bucketConsumer;
156
181
  private _folderConsumer;
157
- constructor(_managementURL: string, _accountURL: string);
182
+ private _axiosAccount;
183
+ private _axiosManagement;
184
+ private _tokenProvider?;
185
+ constructor(managementURL: string, accountURL: string);
186
+ /**
187
+ * Set a token provider (Keycloak-friendly).
188
+ * Example from Angular:
189
+ * client.setTokenProvider(() => auth.getValidToken())
190
+ */
191
+ setTokenProvider(provider: TokenProvider): void;
192
+ /**
193
+ * Optional legacy mode.
194
+ * If you call login(), it stores tokens in sessionStorage
195
+ * and the default token provider will read them.
196
+ *
197
+ * For Keycloak SPA: do NOT use this.
198
+ */
199
+ login(email: string, password: string): Promise<OidcToken>;
158
200
  setSession(session: OidcToken): void;
159
201
  getSessionVariable(key: string): string | null;
160
- login(email: string, password: string): Promise<OidcToken>;
161
- myUser(token?: string): Promise<User$1>;
162
- allOrganizations(token?: string): Promise<Group$1[]>;
163
- myOrganizations(token?: string): Promise<Group$1[]>;
164
- organizationByID(id: string, token?: string): Promise<Group$1>;
165
- organizationByName(name: string, token?: string): Promise<Group$1>;
202
+ private _attachAuthInterceptor;
203
+ /**
204
+ * If your consumers already accept `token?: string` and set headers inside,
205
+ * you can leave them as-is and just pass token through.
206
+ *
207
+ * But the best pattern is: do not pass token in SPA and let interceptor handle it.
208
+ */
209
+ myUser(token?: string): Promise<User>;
210
+ allOrganizations(token?: string): Promise<Group[]>;
211
+ myOrganizations(token?: string): Promise<Group[]>;
212
+ organizationByID(id: string, token?: string): Promise<Group>;
213
+ organizationByName(name: string, token?: string): Promise<Group>;
214
+ addToOrganization(organization: string, users: UserRoles, token?: string): Promise<void>;
215
+ register(email: string, password: string, password_confirm: string, firstName: string, lastName: string): Promise<void>;
166
216
  createOrganization(name: string, token?: string): Promise<Bucket>;
167
217
  removeOrganizationByID(organization: string, token?: string): Promise<Bucket>;
168
- addToOrganization(organization: string, users: UserRoles, token?: string): void;
169
- register(email: string, password: string, password_confirm: string, firstName: string, lastName: string): Promise<any>;
170
218
  getFolderByName(name: string, token?: string): Promise<Folder>;
171
219
  getFolderByID(id: string, token?: string): Promise<Folder>;
220
+ get accountAxios(): AxiosInstance;
221
+ get managementAxios(): AxiosInstance;
222
+ /**
223
+ * Make an axios request using an explicit token without passing it through every method:
224
+ */
225
+ requestWithToken<T>(instance: AxiosInstance, token: string, config: AxiosRequestConfig): Promise<T>;
172
226
  }
173
227
 
174
- type User = User$1;
175
- type Group = Group$1;
176
228
  type IClient = IClient$1;
177
229
 
178
- export { Client, type Group, type IClient, type User };
230
+ export { type Bucket, Client, type ErrorReport, type FileModel, type FolderList, type FolderModel, type Group, type IClient, type Meta, type MultipartWrapper, type OidcToken, type PartInfo, Role, type Updated, type User, type UserRoles };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __getProtoOf = Object.getPrototypeOf;
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
19
21
  }
20
22
  return a;
21
23
  };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
25
  var __export = (target, all) => {
23
26
  for (var name in all)
24
27
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -64,10 +67,18 @@ var __async = (__this, __arguments, generator) => {
64
67
  // src/index.ts
65
68
  var index_exports = {};
66
69
  __export(index_exports, {
67
- Client: () => Client
70
+ Client: () => Client,
71
+ Role: () => Role
68
72
  });
69
73
  module.exports = __toCommonJS(index_exports);
70
74
 
75
+ // src/models/group.account.models.ts
76
+ var Role = /* @__PURE__ */ ((Role2) => {
77
+ Role2["ADMIN"] = "admin";
78
+ Role2["MEMBER"] = "member";
79
+ return Role2;
80
+ })(Role || {});
81
+
71
82
  // src/client.ts
72
83
  var import_axios = __toESM(require("axios"));
73
84
 
@@ -783,65 +794,87 @@ var FolderConsumer = class extends BaseConsumer {
783
794
 
784
795
  // src/client.ts
785
796
  var Client = class {
786
- constructor(_managementURL, _accountURL) {
787
- const configManagement = {
788
- baseURL: _managementURL
789
- };
790
- const configAccount = {
791
- baseURL: _accountURL
792
- };
793
- const axiosManagement = import_axios.default.create(configManagement);
794
- const axiosAccount = import_axios.default.create(configAccount);
797
+ constructor(managementURL, accountURL) {
798
+ const axiosManagement = import_axios.default.create({ baseURL: managementURL });
799
+ const axiosAccount = import_axios.default.create({ baseURL: accountURL });
800
+ this._axiosManagement = axiosManagement;
801
+ this._axiosAccount = axiosAccount;
802
+ this._attachAuthInterceptor(this._axiosAccount);
803
+ this._attachAuthInterceptor(this._axiosManagement);
795
804
  this._userConsumer = new UserConsumer(axiosAccount);
796
805
  this._groupConsumer = new GroupConsumer(axiosAccount);
797
806
  this._bucketConsumer = new BucketConsumer(axiosManagement);
798
807
  this._folderConsumer = new FolderConsumer(axiosManagement);
799
- this.addToOrganization = withValidToken(this.addToOrganization.bind(this), _accountURL);
800
- this.myUser = withValidToken(this.myUser.bind(this), _accountURL);
801
- this.removeOrganizationByID = withValidToken(this.removeOrganizationByID.bind(this), _accountURL);
802
- this.organizationByName = withValidToken(this.organizationByName.bind(this), _accountURL);
803
- this.allOrganizations = withValidToken(this.allOrganizations.bind(this), _accountURL);
804
- this.myOrganizations = withValidToken(this.myOrganizations.bind(this), _accountURL);
805
- this.organizationByID = withValidToken(this.organizationByID.bind(this), _accountURL);
806
- this.createOrganization = withValidToken(this.createOrganization.bind(this), _accountURL);
807
- this.getFolderByName = withValidToken(this.getFolderByName.bind(this), _accountURL);
808
- this.getFolderByID = withValidToken(this.getFolderByID.bind(this), _accountURL);
809
808
  }
809
+ /**
810
+ * Set a token provider (Keycloak-friendly).
811
+ * Example from Angular:
812
+ * client.setTokenProvider(() => auth.getValidToken())
813
+ */
814
+ setTokenProvider(provider) {
815
+ this._tokenProvider = provider;
816
+ }
817
+ /**
818
+ * Optional legacy mode.
819
+ * If you call login(), it stores tokens in sessionStorage
820
+ * and the default token provider will read them.
821
+ *
822
+ * For Keycloak SPA: do NOT use this.
823
+ */
824
+ login(email, password) {
825
+ return __async(this, null, function* () {
826
+ const resp = yield this._userConsumer.login(email, password);
827
+ this.setSession(resp);
828
+ if (!this._tokenProvider) {
829
+ this._tokenProvider = () => {
830
+ var _a;
831
+ return (_a = this.getSessionVariable("access_token")) != null ? _a : "";
832
+ };
833
+ }
834
+ return resp;
835
+ });
836
+ }
837
+ // -----------------------------
838
+ // Token / session helpers
839
+ // -----------------------------
810
840
  setSession(session) {
811
- const storage = typeof window !== "undefined" ? sessionStorage : global.sessionStorage;
841
+ if (typeof window === "undefined" || !window.sessionStorage) return;
812
842
  const now = Math.floor(Date.now() / 1e3);
813
- if (storage) {
814
- storage.setItem("access_token", session.access_token);
815
- storage.setItem("refresh_token", session.refresh_token);
816
- storage.setItem("refresh_expires_in", String(now + session.expires_in));
817
- storage.setItem("refresh_exp", String(now + session.refresh_expires_in));
818
- } else {
819
- console.warn("Session storage is not available.");
820
- }
843
+ sessionStorage.setItem("access_token", session.access_token);
844
+ sessionStorage.setItem("refresh_token", session.refresh_token);
845
+ sessionStorage.setItem("exp", String(now + session.expires_in));
846
+ sessionStorage.setItem("refresh_exp", String(now + session.refresh_expires_in));
821
847
  }
822
848
  getSessionVariable(key) {
823
- const storage = typeof window !== "undefined" ? sessionStorage : global.sessionStorage;
824
- return storage ? storage.getItem(key) : null;
825
- }
826
- // private _setSession(session: OidcToken): void {
827
- // const now = Math.floor(Date.now() / 1000);
828
- // if (typeof localStorage !== "undefined") {
829
- // localStorage.setItem('token', session.access_token);
830
- // localStorage.setItem('refresh_token', session.refresh_token);
831
- // localStorage.setItem('exp', String(now + session.expires_in));
832
- // localStorage.setItem('refresh_exp', String(now + session.refresh_expires_in));
833
- // } else {
834
- // console.warn("⚠️ Local Storage not available. You will need to pass tokens manually.");
835
- // }
836
- // }
837
- login(email, password) {
838
- return this._userConsumer.login(email, password).then(
839
- (resp) => {
840
- this.setSession(resp);
841
- return resp;
849
+ if (typeof window === "undefined" || !window.sessionStorage) return null;
850
+ return sessionStorage.getItem(key);
851
+ }
852
+ _attachAuthInterceptor(instance) {
853
+ instance.interceptors.request.use((config) => __async(this, null, function* () {
854
+ var _a, _b, _c, _d, _e, _f;
855
+ const anyConfig = config;
856
+ if (anyConfig._token && typeof anyConfig._token === "string") {
857
+ (_c = (_b = (_a = config.headers) == null ? void 0 : _a.set) == null ? void 0 : _b.call(_a, "Authorization", `Bearer ${anyConfig._token}`)) != null ? _c : config.headers["Authorization"] = `Bearer ${anyConfig._token}`;
858
+ return config;
842
859
  }
843
- );
844
- }
860
+ if (this._tokenProvider) {
861
+ const token = yield this._tokenProvider();
862
+ if (token) {
863
+ (_f = (_e = (_d = config.headers) == null ? void 0 : _d.set) == null ? void 0 : _e.call(_d, "Authorization", `Bearer ${token}`)) != null ? _f : config.headers["Authorization"] = `Bearer ${token}`;
864
+ }
865
+ }
866
+ return config;
867
+ }));
868
+ }
869
+ /**
870
+ * If your consumers already accept `token?: string` and set headers inside,
871
+ * you can leave them as-is and just pass token through.
872
+ *
873
+ * But the best pattern is: do not pass token in SPA and let interceptor handle it.
874
+ */
875
+ // -----------------------------
876
+ // Account APIs
877
+ // -----------------------------
845
878
  myUser(token) {
846
879
  return this._userConsumer.getUser(token);
847
880
  }
@@ -857,35 +890,33 @@ var Client = class {
857
890
  organizationByName(name, token) {
858
891
  return this._groupConsumer.getGroupByName(name, token);
859
892
  }
860
- createOrganization(name, token) {
861
- return this._groupConsumer.postGroup(name, token).then(
862
- (group) => {
863
- return this._bucketConsumer.postBucket(group.id, name, token);
864
- }
865
- );
866
- }
867
- removeOrganizationByID(organization, token) {
868
- return this._groupConsumer.deleteGroup(organization, token).then(
869
- () => {
870
- return this._bucketConsumer.deleteBucket(organization, token).then(
871
- (bucket) => {
872
- if (!bucket) {
873
- throw new Error(`Bucket with ID ${organization} could not be deleted.`);
874
- }
875
- return bucket;
876
- }
877
- );
878
- }
879
- );
880
- }
881
893
  addToOrganization(organization, users, token) {
882
- return this._groupConsumer.addUsers(organization, users, token);
894
+ return __async(this, null, function* () {
895
+ yield this._groupConsumer.addUsers(organization, users, token);
896
+ });
883
897
  }
884
898
  register(email, password, password_confirm, firstName, lastName) {
885
- if (password != password_confirm) {
886
- throw new Error("Passwords do not match");
887
- }
888
- return this._userConsumer.register(email, password, firstName, lastName);
899
+ return __async(this, null, function* () {
900
+ if (password !== password_confirm) throw new Error("Passwords do not match");
901
+ yield this._userConsumer.register(email, password, firstName, lastName);
902
+ });
903
+ }
904
+ // -----------------------------
905
+ // Management APIs
906
+ // -----------------------------
907
+ createOrganization(name, token) {
908
+ return __async(this, null, function* () {
909
+ const group = yield this._groupConsumer.postGroup(name, token);
910
+ return this._bucketConsumer.postBucket(group.id, name, token);
911
+ });
912
+ }
913
+ removeOrganizationByID(organization, token) {
914
+ return __async(this, null, function* () {
915
+ yield this._groupConsumer.deleteGroup(organization, token);
916
+ const bucket = yield this._bucketConsumer.deleteBucket(organization, token);
917
+ if (!bucket) throw new Error(`Bucket with ID ${organization} could not be deleted.`);
918
+ return bucket;
919
+ });
889
920
  }
890
921
  getFolderByName(name, token) {
891
922
  return this._folderConsumer.getFolderByName(name, token);
@@ -893,8 +924,29 @@ var Client = class {
893
924
  getFolderByID(id, token) {
894
925
  return this._folderConsumer.getFolderByID(id, token);
895
926
  }
927
+ // ---------------------------------------------------
928
+ // OPTIONAL helpers for “explicit token per call”
929
+ // without changing all your consumers:
930
+ // ---------------------------------------------------
931
+ get accountAxios() {
932
+ return this._axiosAccount;
933
+ }
934
+ get managementAxios() {
935
+ return this._axiosManagement;
936
+ }
937
+ /**
938
+ * Make an axios request using an explicit token without passing it through every method:
939
+ */
940
+ requestWithToken(instance, token, config) {
941
+ return __async(this, null, function* () {
942
+ const cfg = __spreadProps(__spreadValues({}, config), { _token: token });
943
+ const res = yield instance.request(cfg);
944
+ return res.data;
945
+ });
946
+ }
896
947
  };
897
948
  // Annotate the CommonJS export names for ESM import in node:
898
949
  0 && (module.exports = {
899
- Client
950
+ Client,
951
+ Role
900
952
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularlogic/coreplatts",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [