@murabei-data-science/pumpwood-services 1.0.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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +504 -0
  3. package/dist/example-usage.d.ts +8 -0
  4. package/dist/example-usage.d.ts.map +1 -0
  5. package/dist/example-usage.js +156 -0
  6. package/dist/example-usage.js.map +1 -0
  7. package/dist/index.d.ts +22 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +43 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/jest.setup.d.ts +2 -0
  12. package/dist/jest.setup.d.ts.map +1 -0
  13. package/dist/jest.setup.js +8 -0
  14. package/dist/jest.setup.js.map +1 -0
  15. package/dist/src/core/api-service.d.ts +58 -0
  16. package/dist/src/core/api-service.d.ts.map +1 -0
  17. package/dist/src/core/api-service.js +192 -0
  18. package/dist/src/core/api-service.js.map +1 -0
  19. package/dist/src/core/pumpwood-client.d.ts +46 -0
  20. package/dist/src/core/pumpwood-client.d.ts.map +1 -0
  21. package/dist/src/core/pumpwood-client.js +110 -0
  22. package/dist/src/core/pumpwood-client.js.map +1 -0
  23. package/dist/src/core/safe-await.d.ts +20 -0
  24. package/dist/src/core/safe-await.d.ts.map +1 -0
  25. package/dist/src/core/safe-await.js +31 -0
  26. package/dist/src/core/safe-await.js.map +1 -0
  27. package/dist/src/services/delete.d.ts +17 -0
  28. package/dist/src/services/delete.d.ts.map +1 -0
  29. package/dist/src/services/delete.js +28 -0
  30. package/dist/src/services/delete.js.map +1 -0
  31. package/dist/src/services/execute-action-file.d.ts +43 -0
  32. package/dist/src/services/execute-action-file.d.ts.map +1 -0
  33. package/dist/src/services/execute-action-file.js +50 -0
  34. package/dist/src/services/execute-action-file.js.map +1 -0
  35. package/dist/src/services/execute-action.d.ts +47 -0
  36. package/dist/src/services/execute-action.d.ts.map +1 -0
  37. package/dist/src/services/execute-action.js +54 -0
  38. package/dist/src/services/execute-action.js.map +1 -0
  39. package/dist/src/services/execute-static-action-file.d.ts +46 -0
  40. package/dist/src/services/execute-static-action-file.d.ts.map +1 -0
  41. package/dist/src/services/execute-static-action-file.js +55 -0
  42. package/dist/src/services/execute-static-action-file.js.map +1 -0
  43. package/dist/src/services/execute-static-action.d.ts +33 -0
  44. package/dist/src/services/execute-static-action.d.ts.map +1 -0
  45. package/dist/src/services/execute-static-action.js +44 -0
  46. package/dist/src/services/execute-static-action.js.map +1 -0
  47. package/dist/src/services/get-sso-token.d.ts +19 -0
  48. package/dist/src/services/get-sso-token.d.ts.map +1 -0
  49. package/dist/src/services/get-sso-token.js +58 -0
  50. package/dist/src/services/get-sso-token.js.map +1 -0
  51. package/dist/src/services/list-without-pag.d.ts +23 -0
  52. package/dist/src/services/list-without-pag.d.ts.map +1 -0
  53. package/dist/src/services/list-without-pag.js +37 -0
  54. package/dist/src/services/list-without-pag.js.map +1 -0
  55. package/dist/src/services/list.d.ts +18 -0
  56. package/dist/src/services/list.d.ts.map +1 -0
  57. package/dist/src/services/list.js +32 -0
  58. package/dist/src/services/list.js.map +1 -0
  59. package/dist/src/services/login-sso.d.ts +16 -0
  60. package/dist/src/services/login-sso.d.ts.map +1 -0
  61. package/dist/src/services/login-sso.js +50 -0
  62. package/dist/src/services/login-sso.js.map +1 -0
  63. package/dist/src/services/login.d.ts +21 -0
  64. package/dist/src/services/login.d.ts.map +1 -0
  65. package/dist/src/services/login.js +54 -0
  66. package/dist/src/services/login.js.map +1 -0
  67. package/dist/src/services/retrieve-file.d.ts +25 -0
  68. package/dist/src/services/retrieve-file.d.ts.map +1 -0
  69. package/dist/src/services/retrieve-file.js +36 -0
  70. package/dist/src/services/retrieve-file.js.map +1 -0
  71. package/dist/src/services/retrieve-options.d.ts +18 -0
  72. package/dist/src/services/retrieve-options.d.ts.map +1 -0
  73. package/dist/src/services/retrieve-options.js +29 -0
  74. package/dist/src/services/retrieve-options.js.map +1 -0
  75. package/dist/src/services/retrieve.d.ts +13 -0
  76. package/dist/src/services/retrieve.d.ts.map +1 -0
  77. package/dist/src/services/retrieve.js +26 -0
  78. package/dist/src/services/retrieve.js.map +1 -0
  79. package/dist/src/services/save.d.ts +18 -0
  80. package/dist/src/services/save.d.ts.map +1 -0
  81. package/dist/src/services/save.js +31 -0
  82. package/dist/src/services/save.js.map +1 -0
  83. package/dist/src/services/upload.d.ts +25 -0
  84. package/dist/src/services/upload.d.ts.map +1 -0
  85. package/dist/src/services/upload.js +41 -0
  86. package/dist/src/services/upload.js.map +1 -0
  87. package/dist/src/types/error.d.ts +13 -0
  88. package/dist/src/types/error.d.ts.map +1 -0
  89. package/dist/src/types/error.js +53 -0
  90. package/dist/src/types/error.js.map +1 -0
  91. package/dist/src/types/http.d.ts +42 -0
  92. package/dist/src/types/http.d.ts.map +1 -0
  93. package/dist/src/types/http.js +3 -0
  94. package/dist/src/types/http.js.map +1 -0
  95. package/package.json +34 -0
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ /**
6
+ * Fetches a list of items for a given model from the API.
7
+ * @template T - The expected type of the list response data.
8
+ * @param {ApiService} api - An instance of the ApiService.
9
+ * @param {string} modelClass - The name of the model class to list.
10
+ * @param {any} [body] - Optional request body for the list operation.
11
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
12
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
13
+ *
14
+ * @example
15
+ * const [users, error] = await ListService<User[]>(api, "users", { limit: 10 });
16
+ * if (error) console.error("Failed to fetch users:", error);
17
+ * else console.log("Users:", users);
18
+ */
19
+ const ListService = async (api, modelClass, body, queryParams) => {
20
+ const requestBody = body || {};
21
+ const normalizedModelClass = modelClass.toLowerCase();
22
+ const [response, error] = await (0, safe_await_js_1.safeAwait)(queryParams
23
+ ? api.request("POST", `/${normalizedModelClass}/list/`, requestBody, queryParams)
24
+ : api.request("POST", `/${normalizedModelClass}/list/`, requestBody));
25
+ if (error) {
26
+ console.error("==> ListService ERROR:", error);
27
+ return [null, error];
28
+ }
29
+ return [response, null];
30
+ };
31
+ exports.ListService = ListService;
32
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/services/list.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,GAAe,EACf,UAAkB,EAClB,IAAU,EACV,WAAoC,EACI,EAAE;IAC1C,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,oBAAoB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAEtD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,yBAAS,EACvC,WAAW;QACT,CAAC,CAAC,GAAG,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,oBAAoB,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAC;QACpF,CAAC,CAAC,GAAG,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,oBAAoB,QAAQ,EAAE,WAAW,CAAC,CAC1E,CAAC;IAEF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AArBW,QAAA,WAAW,eAqBtB"}
@@ -0,0 +1,16 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { ILoginSSOResult } from "../types/http.js";
3
+ /**
4
+ * Initiates an SSO login flow, returning the OAuth2 redirect URL.
5
+ *
6
+ * @param {string} baseUrl - The base URL of the API (e.g. "https://api.example.com").
7
+ * @param {string} email - The user's email address to identify the SSO provider.
8
+ * @returns {Promise<[ILoginSSOResult | null, IErrorDict | null]>} A tuple with the redirect URL or an error.
9
+ *
10
+ * @example
11
+ * const [result, error] = await LoginSSOService("https://api.example.com", "user@example.com");
12
+ * if (error) console.error("SSO init failed:", error.message);
13
+ * else window.location.href = result.redirect_url;
14
+ */
15
+ export declare const LoginSSOService: (baseUrl: string, email: string) => Promise<[ILoginSSOResult | null, IErrorDict | null]>;
16
+ //# sourceMappingURL=login-sso.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-sso.d.ts","sourceRoot":"","sources":["../../../src/services/login-sso.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIxD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,OAAO,MAAM,KACZ,OAAO,CAAC,CAAC,eAAe,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CAyCrD,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginSSOService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ const error_js_1 = require("../types/error.js");
6
+ /**
7
+ * Initiates an SSO login flow, returning the OAuth2 redirect URL.
8
+ *
9
+ * @param {string} baseUrl - The base URL of the API (e.g. "https://api.example.com").
10
+ * @param {string} email - The user's email address to identify the SSO provider.
11
+ * @returns {Promise<[ILoginSSOResult | null, IErrorDict | null]>} A tuple with the redirect URL or an error.
12
+ *
13
+ * @example
14
+ * const [result, error] = await LoginSSOService("https://api.example.com", "user@example.com");
15
+ * if (error) console.error("SSO init failed:", error.message);
16
+ * else window.location.href = result.redirect_url;
17
+ */
18
+ const LoginSSOService = async (baseUrl, email) => {
19
+ if (!baseUrl) {
20
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginSSOService: baseUrl is required"))];
21
+ }
22
+ if (!email) {
23
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginSSOService: email is required"))];
24
+ }
25
+ const url = `${baseUrl.replace(/\/$/, "")}/registration/oauth2-login/`;
26
+ const [response, fetchError] = await (0, safe_await_js_1.safeAwait)(fetch(url, {
27
+ method: "POST",
28
+ credentials: "omit",
29
+ headers: { "Content-Type": "application/json" },
30
+ body: JSON.stringify({ email }),
31
+ }));
32
+ if (fetchError) {
33
+ return [null, fetchError];
34
+ }
35
+ if (!response.ok) {
36
+ const errorText = await response.text();
37
+ return [null, (0, error_js_1.normalizeToErrorDict)((0, error_js_1.createHttpError)(response.status, `HTTP ${response.status}: ${errorText}`))];
38
+ }
39
+ const [jsonData, jsonError] = await (0, safe_await_js_1.safeAwait)(response.json());
40
+ if (jsonError) {
41
+ return [null, jsonError];
42
+ }
43
+ const redirectUrl = jsonData.mfa_method_result?.authorization_url;
44
+ if (!redirectUrl) {
45
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginSSOService: response did not contain authorization_url"))];
46
+ }
47
+ return [{ redirect_url: redirectUrl }, null];
48
+ };
49
+ exports.LoginSSOService = LoginSSOService;
50
+ //# sourceMappingURL=login-sso.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-sso.js","sourceRoot":"","sources":["../../../src/services/login-sso.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAClD,gDAA0E;AAE1E;;;;;;;;;;;GAWG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,OAAe,EACf,KAAa,EACyC,EAAE;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,EAAE,IAAA,+BAAoB,EAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC,CAAC;IACzF,CAAC;IACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,EAA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,CAAC,CAAC;IAChH,CAAC;IAED,OAAO,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC,CAAC;AA5CW,QAAA,eAAe,mBA4C1B"}
@@ -0,0 +1,21 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { ILoginResult } from "../types/http.js";
3
+ /**
4
+ * Authenticates with username and password against the Pumpwood login endpoint.
5
+ *
6
+ * @param {string} baseUrl - The base URL of the API (e.g. "https://api.example.com").
7
+ * @param {object} credentials - The login credentials.
8
+ * @param {string} credentials.username - The username.
9
+ * @param {string} credentials.password - The password.
10
+ * @returns {Promise<[ILoginResult | null, IErrorDict | null]>} A tuple with the login result or an error.
11
+ *
12
+ * @example
13
+ * const [result, error] = await LoginService("https://api.example.com", { username: "john", password: "secret" });
14
+ * if (error) console.error("Login failed:", error.message);
15
+ * else setCookie("PumpwoodAuthorization", result.token);
16
+ */
17
+ export declare const LoginService: (baseUrl: string, { username, password }: {
18
+ username: string;
19
+ password: string;
20
+ }) => Promise<[ILoginResult | null, IErrorDict | null]>;
21
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/services/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GACvB,SAAS,MAAM,EACf,wBAAwB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAC7D,OAAO,CAAC,CAAC,YAAY,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CA0ClD,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ const error_js_1 = require("../types/error.js");
6
+ /**
7
+ * Authenticates with username and password against the Pumpwood login endpoint.
8
+ *
9
+ * @param {string} baseUrl - The base URL of the API (e.g. "https://api.example.com").
10
+ * @param {object} credentials - The login credentials.
11
+ * @param {string} credentials.username - The username.
12
+ * @param {string} credentials.password - The password.
13
+ * @returns {Promise<[ILoginResult | null, IErrorDict | null]>} A tuple with the login result or an error.
14
+ *
15
+ * @example
16
+ * const [result, error] = await LoginService("https://api.example.com", { username: "john", password: "secret" });
17
+ * if (error) console.error("Login failed:", error.message);
18
+ * else setCookie("PumpwoodAuthorization", result.token);
19
+ */
20
+ const LoginService = async (baseUrl, { username, password }) => {
21
+ if (!baseUrl) {
22
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginService: baseUrl is required"))];
23
+ }
24
+ if (!username) {
25
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginService: username is required"))];
26
+ }
27
+ if (!password) {
28
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginService: password is required"))];
29
+ }
30
+ const url = `${baseUrl.replace(/\/$/, "")}/registration/login/`;
31
+ const [response, fetchError] = await (0, safe_await_js_1.safeAwait)(fetch(url, {
32
+ method: "POST",
33
+ credentials: "omit",
34
+ headers: { "Content-Type": "application/json" },
35
+ body: JSON.stringify({ username, password }),
36
+ }));
37
+ if (fetchError) {
38
+ return [null, fetchError];
39
+ }
40
+ if (!response.ok) {
41
+ const errorText = await response.text();
42
+ return [null, (0, error_js_1.normalizeToErrorDict)((0, error_js_1.createHttpError)(response.status, `HTTP ${response.status}: ${errorText}`))];
43
+ }
44
+ const [jsonData, jsonError] = await (0, safe_await_js_1.safeAwait)(response.json());
45
+ if (jsonError) {
46
+ return [null, jsonError];
47
+ }
48
+ if (!jsonData.token) {
49
+ return [null, (0, error_js_1.normalizeToErrorDict)(new Error("LoginService: response did not contain a token"))];
50
+ }
51
+ return [{ token: jsonData.token }, null];
52
+ };
53
+ exports.LoginService = LoginService;
54
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/services/login.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAClD,gDAA0E;AAE1E;;;;;;;;;;;;;GAaG;AACI,MAAM,YAAY,GAAG,KAAK,EAC/B,OAAe,EACf,EAAE,QAAQ,EAAE,QAAQ,EAA0C,EACX,EAAE;IACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,EAAE,IAAA,+BAAoB,EAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,IAAI,EAAE,IAAA,+BAAoB,EAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,IAAI,EAAE,IAAA,+BAAoB,EAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAEhE,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,MAAM,IAAA,yBAAS,EAC5C,KAAK,CAAC,GAAG,EAAE;QACT,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,MAAM;QACnB,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;KAC7C,CAAC,CACH,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,IAAA,+BAAoB,EAAC,IAAA,0BAAe,EAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,MAAM,IAAA,yBAAS,EAAoB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAElF,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,EAAE,IAAA,+BAAoB,EAAC,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC,CAAC,CAAC;IACnG,CAAC;IAED,OAAO,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC,CAAC;AA7CW,QAAA,YAAY,gBA6CvB"}
@@ -0,0 +1,25 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { IFileData } from "../types/http.js";
3
+ import type { ApiService } from "../core/api-service.js";
4
+ /**
5
+ * Retrieves a file for a given model from the API.
6
+ * Returns a Blob that allows the caller to manage URL lifecycle (create/revoke).
7
+ * ⚠️ NOT SERIALIZABLE for SSR - use only on client-side or same-side server operations.
8
+ * @param {ApiService} api - An instance of the ApiService.
9
+ * @param {string} modelClass - The name of the model class to retrieve from.
10
+ * @param {number} pk - The primary key of the item to retrieve.
11
+ * @param {string} fileField - The name of the file field to retrieve (default: "file").
12
+ * @returns {Promise<[IFileData | null, IErrorDict | null]>} A tuple containing the file data (blob) or an error.
13
+ *
14
+ * @example
15
+ * const [fileData, error] = await RetrieveFileService(api, "documents", 123, "file");
16
+ * if (error) console.error("Failed to retrieve file:", error);
17
+ * else {
18
+ * const url = URL.createObjectURL(fileData.blob);
19
+ * window.open(url);
20
+ * // Don't forget to revoke when done:
21
+ * URL.revokeObjectURL(url);
22
+ * }
23
+ */
24
+ export declare const RetrieveFileService: (api: ApiService, modelClass: string, pk: number, fileField?: string) => Promise<[IFileData | null, IErrorDict | null]>;
25
+ //# sourceMappingURL=retrieve-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieve-file.d.ts","sourceRoot":"","sources":["../../../src/services/retrieve-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,UAAU,EACf,YAAY,MAAM,EAClB,IAAI,MAAM,EACV,YAAW,MAAe,KACzB,OAAO,CAAC,CAAC,SAAS,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CAc/C,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RetrieveFileService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ /**
6
+ * Retrieves a file for a given model from the API.
7
+ * Returns a Blob that allows the caller to manage URL lifecycle (create/revoke).
8
+ * ⚠️ NOT SERIALIZABLE for SSR - use only on client-side or same-side server operations.
9
+ * @param {ApiService} api - An instance of the ApiService.
10
+ * @param {string} modelClass - The name of the model class to retrieve from.
11
+ * @param {number} pk - The primary key of the item to retrieve.
12
+ * @param {string} fileField - The name of the file field to retrieve (default: "file").
13
+ * @returns {Promise<[IFileData | null, IErrorDict | null]>} A tuple containing the file data (blob) or an error.
14
+ *
15
+ * @example
16
+ * const [fileData, error] = await RetrieveFileService(api, "documents", 123, "file");
17
+ * if (error) console.error("Failed to retrieve file:", error);
18
+ * else {
19
+ * const url = URL.createObjectURL(fileData.blob);
20
+ * window.open(url);
21
+ * // Don't forget to revoke when done:
22
+ * URL.revokeObjectURL(url);
23
+ * }
24
+ */
25
+ const RetrieveFileService = async (api, modelClass, pk, fileField = "file") => {
26
+ const normalizedModelClass = modelClass.toLowerCase();
27
+ const queryParams = { "file-field": fileField };
28
+ const [response, error] = await (0, safe_await_js_1.safeAwait)(api.fileRequest(`/${normalizedModelClass}/retrieve-file/${String(pk)}/`, queryParams));
29
+ if (error) {
30
+ console.error("==> RetrieveFileService ERROR:", error);
31
+ return [null, error];
32
+ }
33
+ return [response, null];
34
+ };
35
+ exports.RetrieveFileService = RetrieveFileService;
36
+ //# sourceMappingURL=retrieve-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieve-file.js","sourceRoot":"","sources":["../../../src/services/retrieve-file.ts"],"names":[],"mappings":";;;AAGA,yDAAkD;AAElD;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,mBAAmB,GAAG,KAAK,EACtC,GAAe,EACf,UAAkB,EAClB,EAAU,EACV,YAAoB,MAAM,EACsB,EAAE;IAClD,MAAM,oBAAoB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IACtD,MAAM,WAAW,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IAEhD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,yBAAS,EACvC,GAAG,CAAC,WAAW,CAAC,IAAI,oBAAoB,kBAAkB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CACtF,CAAC;IAEF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAnBW,QAAA,mBAAmB,uBAmB9B"}
@@ -0,0 +1,18 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { ApiService } from "../core/api-service.js";
3
+ /**
4
+ * Retrieves the options/metadata for a given model class from the API.
5
+ * Useful for fetching field definitions, choices, and validation rules.
6
+ * @template T - The expected type of the options response data.
7
+ * @param {ApiService} api - An instance of the ApiService.
8
+ * @param {string} modelClass - The name of the model class to retrieve options for.
9
+ * @param {Record<string, any>} [body] - Optional body parameters to send in the POST request.
10
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the options data or an error.
11
+ *
12
+ * @example
13
+ * const [options, error] = await RetrieveOptionsService(api, "descriptiongeoarea");
14
+ * if (error) console.error("Failed to fetch options:", error);
15
+ * else console.log("Field options:", options);
16
+ */
17
+ export declare const RetrieveOptionsService: <T>(api: ApiService, modelClass: string, body?: Record<string, any>) => Promise<[T | null, IErrorDict | null]>;
18
+ //# sourceMappingURL=retrieve-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieve-options.d.ts","sourceRoot":"","sources":["../../../src/services/retrieve-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,GAAU,CAAC,EAC5C,KAAK,UAAU,EACf,YAAY,MAAM,EAClB,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KACzB,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CAavC,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RetrieveOptionsService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ /**
6
+ * Retrieves the options/metadata for a given model class from the API.
7
+ * Useful for fetching field definitions, choices, and validation rules.
8
+ * @template T - The expected type of the options response data.
9
+ * @param {ApiService} api - An instance of the ApiService.
10
+ * @param {string} modelClass - The name of the model class to retrieve options for.
11
+ * @param {Record<string, any>} [body] - Optional body parameters to send in the POST request.
12
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the options data or an error.
13
+ *
14
+ * @example
15
+ * const [options, error] = await RetrieveOptionsService(api, "descriptiongeoarea");
16
+ * if (error) console.error("Failed to fetch options:", error);
17
+ * else console.log("Field options:", options);
18
+ */
19
+ const RetrieveOptionsService = async (api, modelClass, body) => {
20
+ const normalizedModelClass = modelClass.toLowerCase();
21
+ const [response, error] = await (0, safe_await_js_1.safeAwait)(api.request("POST", `/${normalizedModelClass}/retrieve-options/`, body ?? {}));
22
+ if (error) {
23
+ console.error("==> RetrieveOptionsService ERROR:", error);
24
+ return [null, error];
25
+ }
26
+ return [response, null];
27
+ };
28
+ exports.RetrieveOptionsService = RetrieveOptionsService;
29
+ //# sourceMappingURL=retrieve-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieve-options.js","sourceRoot":"","sources":["../../../src/services/retrieve-options.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,GAAe,EACf,UAAkB,EAClB,IAA0B,EACc,EAAE;IAC1C,MAAM,oBAAoB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAEtD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,yBAAS,EACvC,GAAG,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,oBAAoB,oBAAoB,EAAE,IAAI,IAAI,EAAE,CAAC,CACjF,CAAC;IAEF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAjBW,QAAA,sBAAsB,0BAiBjC"}
@@ -0,0 +1,13 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { ApiService } from "../core/api-service.js";
3
+ /**
4
+ * Retrieves a single item for a given model from the API.
5
+ * @template T - The expected type of the retrieve response data.
6
+ * @param {ApiService} api - An instance of the ApiService.
7
+ * @param {string} modelClass - The name of the model class to retrieve from.
8
+ * @param {number} pk - The primary key of the item to retrieve.
9
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
10
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
11
+ */
12
+ export declare const RetrieveService: <T>(api: ApiService, modelClass: string, pk: number, queryParams?: Record<string, string>) => Promise<[T | null, IErrorDict | null]>;
13
+ //# sourceMappingURL=retrieve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieve.d.ts","sourceRoot":"","sources":["../../../src/services/retrieve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAU,CAAC,EACrC,KAAK,UAAU,EACf,YAAY,MAAM,EAClB,IAAI,MAAM,EACV,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACnC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CAevC,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RetrieveService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ /**
6
+ * Retrieves a single item for a given model from the API.
7
+ * @template T - The expected type of the retrieve response data.
8
+ * @param {ApiService} api - An instance of the ApiService.
9
+ * @param {string} modelClass - The name of the model class to retrieve from.
10
+ * @param {number} pk - The primary key of the item to retrieve.
11
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
12
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
13
+ */
14
+ const RetrieveService = async (api, modelClass, pk, queryParams) => {
15
+ const normalizedModelClass = modelClass.toLowerCase();
16
+ const [response, error] = await (0, safe_await_js_1.safeAwait)(queryParams
17
+ ? api.request("GET", `/${normalizedModelClass}/retrieve/${String(pk)}/`, undefined, queryParams)
18
+ : api.request("GET", `/${normalizedModelClass}/retrieve/${String(pk)}/`));
19
+ if (error) {
20
+ console.error("==> RetrieveService ERROR:", error);
21
+ return [null, error];
22
+ }
23
+ return [response, null];
24
+ };
25
+ exports.RetrieveService = RetrieveService;
26
+ //# sourceMappingURL=retrieve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieve.js","sourceRoot":"","sources":["../../../src/services/retrieve.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAElD;;;;;;;;GAQG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,GAAe,EACf,UAAkB,EAClB,EAAU,EACV,WAAoC,EACI,EAAE;IAC1C,MAAM,oBAAoB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAEtD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,yBAAS,EACvC,WAAW;QACT,CAAC,CAAC,GAAG,CAAC,OAAO,CAAI,KAAK,EAAE,IAAI,oBAAoB,aAAa,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,EAAE,WAAW,CAAC;QACnG,CAAC,CAAC,GAAG,CAAC,OAAO,CAAI,KAAK,EAAE,IAAI,oBAAoB,aAAa,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAC9E,CAAC;IAEF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QACnD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AApBW,QAAA,eAAe,mBAoB1B"}
@@ -0,0 +1,18 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { ApiService } from "../core/api-service.js";
3
+ /**
4
+ * Saves (creates or updates) an item for a given model to the API.
5
+ * @template T - The expected type of the save response data.
6
+ * @param {ApiService} api - An instance of the ApiService.
7
+ * @param {string} modelClass - The name of the model class to save to.
8
+ * @param {Record<any, any>} body - The data to be saved (typically includes all item fields).
9
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
10
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
11
+ *
12
+ * @example
13
+ * const [savedUser, error] = await SaveService<User>(api, "users", { name: "John", email: "john@example.com" });
14
+ * if (error) console.error("Failed to save user:", error);
15
+ * else console.log("Saved user:", savedUser);
16
+ */
17
+ export declare const SaveService: <T>(api: ApiService, modelClass: string, body: Record<any, any>, queryParams?: Record<string, string>) => Promise<[T | null, IErrorDict | null]>;
18
+ //# sourceMappingURL=save.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../../../src/services/save.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAU,CAAC,EACjC,KAAK,UAAU,EACf,YAAY,MAAM,EAClB,MAAM,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACtB,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACnC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CAevC,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SaveService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ /**
6
+ * Saves (creates or updates) an item for a given model to the API.
7
+ * @template T - The expected type of the save response data.
8
+ * @param {ApiService} api - An instance of the ApiService.
9
+ * @param {string} modelClass - The name of the model class to save to.
10
+ * @param {Record<any, any>} body - The data to be saved (typically includes all item fields).
11
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
12
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
13
+ *
14
+ * @example
15
+ * const [savedUser, error] = await SaveService<User>(api, "users", { name: "John", email: "john@example.com" });
16
+ * if (error) console.error("Failed to save user:", error);
17
+ * else console.log("Saved user:", savedUser);
18
+ */
19
+ const SaveService = async (api, modelClass, body, queryParams) => {
20
+ const normalizedModelClass = modelClass.toLowerCase();
21
+ const [response, error] = await (0, safe_await_js_1.safeAwait)(queryParams
22
+ ? api.request("POST", `/${normalizedModelClass}/save/`, body, queryParams)
23
+ : api.request("POST", `/${normalizedModelClass}/save/`, body));
24
+ if (error) {
25
+ console.error("==> SaveService ERROR:", error);
26
+ return [null, error];
27
+ }
28
+ return [response, null];
29
+ };
30
+ exports.SaveService = SaveService;
31
+ //# sourceMappingURL=save.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save.js","sourceRoot":"","sources":["../../../src/services/save.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,GAAe,EACf,UAAkB,EAClB,IAAsB,EACtB,WAAoC,EACI,EAAE;IAC1C,MAAM,oBAAoB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAEtD,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,yBAAS,EACvC,WAAW;QACT,CAAC,CAAC,GAAG,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,oBAAoB,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC;QAC7E,CAAC,CAAC,GAAG,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,oBAAoB,QAAQ,EAAE,IAAI,CAAC,CACnE,CAAC;IAEF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AApBW,QAAA,WAAW,eAoBtB"}
@@ -0,0 +1,25 @@
1
+ import type { IErrorDict } from "../types/error.js";
2
+ import type { ApiService } from "../core/api-service.js";
3
+ /**
4
+ * Uploads a file with associated JSON data for a given model to the API.
5
+ * @template T - The expected type of the upload response data.
6
+ * @param {ApiService} api - An instance of the ApiService.
7
+ * @param {string} modelClass - The name of the model class to upload to.
8
+ * @param {File} file - The file to be uploaded.
9
+ * @param {Record<string, any>} jsonData - Additional JSON data to be sent with the file.
10
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
11
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
12
+ *
13
+ * @example
14
+ * const file = document.querySelector('input[type="file"]').files[0];
15
+ * const [result, error] = await UploadFileService(
16
+ * api,
17
+ * "documents",
18
+ * file,
19
+ * { origin: "USER_UPLOAD", format_type: "MELTED" }
20
+ * );
21
+ * if (error) console.error("Failed to upload file:", error);
22
+ * else console.log("File uploaded successfully:", result);
23
+ */
24
+ export declare const UploadFileService: <T>(api: ApiService, modelClass: string, file: File, jsonData: Record<string, any>, queryParams?: Record<string, string>) => Promise<[T | null, IErrorDict | null]>;
25
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/services/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,GAAU,CAAC,EACvC,KAAK,UAAU,EACf,YAAY,MAAM,EAClB,MAAM,IAAI,EACV,UAAU,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACnC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC,CAmBvC,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UploadFileService = void 0;
4
+ const safe_await_js_1 = require("../core/safe-await.js");
5
+ /**
6
+ * Uploads a file with associated JSON data for a given model to the API.
7
+ * @template T - The expected type of the upload response data.
8
+ * @param {ApiService} api - An instance of the ApiService.
9
+ * @param {string} modelClass - The name of the model class to upload to.
10
+ * @param {File} file - The file to be uploaded.
11
+ * @param {Record<string, any>} jsonData - Additional JSON data to be sent with the file.
12
+ * @param {Record<string, string>} [queryParams] - Optional query parameters to append to the URL.
13
+ * @returns {Promise<[T | null, IErrorDict | null]>} A tuple containing the response data or an error, consistent with safeAwait.
14
+ *
15
+ * @example
16
+ * const file = document.querySelector('input[type="file"]').files[0];
17
+ * const [result, error] = await UploadFileService(
18
+ * api,
19
+ * "documents",
20
+ * file,
21
+ * { origin: "USER_UPLOAD", format_type: "MELTED" }
22
+ * );
23
+ * if (error) console.error("Failed to upload file:", error);
24
+ * else console.log("File uploaded successfully:", result);
25
+ */
26
+ const UploadFileService = async (api, modelClass, file, jsonData, queryParams) => {
27
+ const normalizedModelClass = modelClass.toLowerCase();
28
+ const formData = new FormData();
29
+ formData.append("__json__", JSON.stringify(jsonData));
30
+ formData.append("file", file);
31
+ const [response, error] = await (0, safe_await_js_1.safeAwait)(queryParams
32
+ ? api.uploadRequest(`/${normalizedModelClass}/save/`, formData, queryParams)
33
+ : api.uploadRequest(`/${normalizedModelClass}/save/`, formData));
34
+ if (error) {
35
+ console.error("==> UploadFileService ERROR:", error);
36
+ return [null, error];
37
+ }
38
+ return [response, null];
39
+ };
40
+ exports.UploadFileService = UploadFileService;
41
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../../src/services/upload.ts"],"names":[],"mappings":";;;AAEA,yDAAkD;AAElD;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAe,EACf,UAAkB,EAClB,IAAU,EACV,QAA6B,EAC7B,WAAoC,EACI,EAAE;IAC1C,MAAM,oBAAoB,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAEtD,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE9B,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,yBAAS,EACvC,WAAW;QACT,CAAC,CAAC,GAAG,CAAC,aAAa,CAAI,IAAI,oBAAoB,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC;QAC/E,CAAC,CAAC,GAAG,CAAC,aAAa,CAAI,IAAI,oBAAoB,QAAQ,EAAE,QAAQ,CAAC,CACrE,CAAC;IAEF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACrD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAzBW,QAAA,iBAAiB,qBAyB5B"}
@@ -0,0 +1,13 @@
1
+ export interface IErrorDict {
2
+ __error__: string;
3
+ type: string;
4
+ message: string;
5
+ message_not_fmt: string;
6
+ payload: Record<string, any>;
7
+ parallel: boolean;
8
+ status?: number;
9
+ }
10
+ export declare function createHttpError(status: number, message: string): Error;
11
+ export declare function isUnauthorizedError(error: IErrorDict | null | undefined): boolean;
12
+ export declare function normalizeToErrorDict(error: unknown): IErrorDict;
13
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/types/error.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAItE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEjF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CA2C/D"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHttpError = createHttpError;
4
+ exports.isUnauthorizedError = isUnauthorizedError;
5
+ exports.normalizeToErrorDict = normalizeToErrorDict;
6
+ function createHttpError(status, message) {
7
+ const error = new Error(message);
8
+ error.status = status;
9
+ return error;
10
+ }
11
+ function isUnauthorizedError(error) {
12
+ return error?.status === 401;
13
+ }
14
+ function normalizeToErrorDict(error) {
15
+ const unknownFallback = (message) => ({
16
+ __error__: "UnknownError",
17
+ type: "UnknownError",
18
+ message,
19
+ message_not_fmt: message,
20
+ payload: {},
21
+ parallel: false,
22
+ });
23
+ if (!(error instanceof Error)) {
24
+ return unknownFallback(String(error));
25
+ }
26
+ const raw = error;
27
+ const isPumpWood = typeof raw.__error__ === "string" && raw.__error__ === "PumpWoodException";
28
+ if (isPumpWood) {
29
+ return {
30
+ __error__: raw.__error__,
31
+ type: typeof raw.type === "string" ? raw.type : "UnknownType",
32
+ message: typeof raw.apiMessage === "string" ? raw.apiMessage : raw.message,
33
+ message_not_fmt: typeof raw.message_not_fmt === "string" ? raw.message_not_fmt : raw.message,
34
+ payload: raw.payload && typeof raw.payload === "object" ? raw.payload : {},
35
+ parallel: typeof raw.parallel === "boolean" ? raw.parallel : false,
36
+ ...(typeof raw.status === "number" && { status: raw.status }),
37
+ };
38
+ }
39
+ if (typeof raw.status === "number") {
40
+ const isUnauthorized = raw.status === 401;
41
+ return {
42
+ __error__: isUnauthorized ? "UnauthorizedError" : "HttpError",
43
+ type: isUnauthorized ? "Unauthorized" : "HttpError",
44
+ message: raw.message,
45
+ message_not_fmt: raw.message,
46
+ payload: {},
47
+ parallel: false,
48
+ status: raw.status,
49
+ };
50
+ }
51
+ return unknownFallback(raw.message);
52
+ }
53
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/types/error.ts"],"names":[],"mappings":";;AAUA,0CAIC;AAED,kDAEC;AAED,oDA2CC;AArDD,SAAgB,eAAe,CAAC,MAAc,EAAE,OAAe;IAC7D,MAAM,KAA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