@intlayer/api 3.5.8

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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +240 -0
  3. package/dist/cjs/ai.cjs +89 -0
  4. package/dist/cjs/ai.cjs.map +1 -0
  5. package/dist/cjs/auth.cjs +166 -0
  6. package/dist/cjs/auth.cjs.map +1 -0
  7. package/dist/cjs/dictionary.cjs +103 -0
  8. package/dist/cjs/dictionary.cjs.map +1 -0
  9. package/dist/cjs/fetcher.cjs +98 -0
  10. package/dist/cjs/fetcher.cjs.map +1 -0
  11. package/dist/cjs/index.cjs +49 -0
  12. package/dist/cjs/index.cjs.map +1 -0
  13. package/dist/cjs/organization.cjs +121 -0
  14. package/dist/cjs/organization.cjs.map +1 -0
  15. package/dist/cjs/project.cjs +135 -0
  16. package/dist/cjs/project.cjs.map +1 -0
  17. package/dist/cjs/stripe.cjs +55 -0
  18. package/dist/cjs/stripe.cjs.map +1 -0
  19. package/dist/cjs/tag.cjs +77 -0
  20. package/dist/cjs/tag.cjs.map +1 -0
  21. package/dist/cjs/user.cjs +95 -0
  22. package/dist/cjs/user.cjs.map +1 -0
  23. package/dist/esm/ai.mjs +64 -0
  24. package/dist/esm/ai.mjs.map +1 -0
  25. package/dist/esm/auth.mjs +141 -0
  26. package/dist/esm/auth.mjs.map +1 -0
  27. package/dist/esm/dictionary.mjs +78 -0
  28. package/dist/esm/dictionary.mjs.map +1 -0
  29. package/dist/esm/fetcher.mjs +73 -0
  30. package/dist/esm/fetcher.mjs.map +1 -0
  31. package/dist/esm/index.mjs +24 -0
  32. package/dist/esm/index.mjs.map +1 -0
  33. package/dist/esm/organization.mjs +96 -0
  34. package/dist/esm/organization.mjs.map +1 -0
  35. package/dist/esm/project.mjs +110 -0
  36. package/dist/esm/project.mjs.map +1 -0
  37. package/dist/esm/stripe.mjs +31 -0
  38. package/dist/esm/stripe.mjs.map +1 -0
  39. package/dist/esm/tag.mjs +52 -0
  40. package/dist/esm/tag.mjs.map +1 -0
  41. package/dist/esm/user.mjs +70 -0
  42. package/dist/esm/user.mjs.map +1 -0
  43. package/dist/types/ai.d.ts +18 -0
  44. package/dist/types/ai.d.ts.map +1 -0
  45. package/dist/types/auth.d.ts +38 -0
  46. package/dist/types/auth.d.ts.map +1 -0
  47. package/dist/types/dictionary.d.ts +22 -0
  48. package/dist/types/dictionary.d.ts.map +1 -0
  49. package/dist/types/fetcher.d.ts +70 -0
  50. package/dist/types/fetcher.d.ts.map +1 -0
  51. package/dist/types/index.d.ts +157 -0
  52. package/dist/types/index.d.ts.map +1 -0
  53. package/dist/types/organization.d.ts +26 -0
  54. package/dist/types/organization.d.ts.map +1 -0
  55. package/dist/types/project.d.ts +28 -0
  56. package/dist/types/project.d.ts.map +1 -0
  57. package/dist/types/stripe.d.ts +8 -0
  58. package/dist/types/stripe.d.ts.map +1 -0
  59. package/dist/types/tag.d.ts +16 -0
  60. package/dist/types/tag.d.ts.map +1 -0
  61. package/dist/types/user.d.ts +22 -0
  62. package/dist/types/user.d.ts.map +1 -0
  63. package/package.json +99 -0
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var auth_exports = {};
20
+ __export(auth_exports, {
21
+ authAPI: () => authAPI,
22
+ getAuthAPI: () => getAuthAPI
23
+ });
24
+ module.exports = __toCommonJS(auth_exports);
25
+ var import_client = require("@intlayer/config/client");
26
+ var import_fetcher = require('./fetcher.cjs');
27
+ const getAuthAPI = (authAPIOptions = {}, intlayerConfig) => {
28
+ const { backendURL, clientId, clientSecret } = (intlayerConfig ?? (0, import_client.getConfiguration)()).editor;
29
+ const AUTH_API_ROUTE = `${backendURL}/api/auth`;
30
+ const login = async (user, otherOptions = {}) => await (0, import_fetcher.fetcher)(
31
+ `${AUTH_API_ROUTE}/login`,
32
+ authAPIOptions,
33
+ otherOptions,
34
+ {
35
+ method: "POST",
36
+ body: user
37
+ }
38
+ );
39
+ const getLoginWithGitHubURL = (params) => {
40
+ const searchParams = new URLSearchParams(params);
41
+ return `${AUTH_API_ROUTE}/login/github?${searchParams.toString()}`;
42
+ };
43
+ const getLoginWithGoogleURL = (params) => {
44
+ const searchParams = new URLSearchParams(params);
45
+ return `${AUTH_API_ROUTE}/login/google?${searchParams.toString()}`;
46
+ };
47
+ const register = async (user, query = {}, otherOptions = {}) => await (0, import_fetcher.fetcher)(
48
+ `${AUTH_API_ROUTE}/register`,
49
+ authAPIOptions,
50
+ otherOptions,
51
+ {
52
+ method: "POST",
53
+ body: user,
54
+ params: query
55
+ }
56
+ );
57
+ const logout = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
58
+ `${AUTH_API_ROUTE}/logout`,
59
+ authAPIOptions,
60
+ otherOptions,
61
+ {
62
+ method: "POST"
63
+ }
64
+ );
65
+ const askResetPassword = async (email, otherOptions = {}) => await (0, import_fetcher.fetcher)(
66
+ `${AUTH_API_ROUTE}/password/reset`,
67
+ authAPIOptions,
68
+ otherOptions,
69
+ {
70
+ method: "POST",
71
+ body: { email }
72
+ }
73
+ );
74
+ const resetPassword = async (params, otherOptions = {}) => await (0, import_fetcher.fetcher)(
75
+ `${AUTH_API_ROUTE}/password/reset`,
76
+ authAPIOptions,
77
+ otherOptions,
78
+ { params, method: "POST" }
79
+ );
80
+ const changePassword = async (data, otherOptions = {}) => await (0, import_fetcher.fetcher)(
81
+ `${AUTH_API_ROUTE}/password`,
82
+ authAPIOptions,
83
+ otherOptions,
84
+ {
85
+ method: "PUT",
86
+ body: data
87
+ }
88
+ );
89
+ const checkIfUserHasPassword = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
90
+ `${AUTH_API_ROUTE}/password/has`,
91
+ authAPIOptions,
92
+ otherOptions,
93
+ {
94
+ method: "GET"
95
+ }
96
+ );
97
+ const verifyEmail = async ({ userId, secret }, otherOptions = {}) => await (0, import_fetcher.fetcher)(
98
+ `${AUTH_API_ROUTE}/active/${userId}/${secret}`,
99
+ authAPIOptions,
100
+ otherOptions,
101
+ {
102
+ method: "PUT"
103
+ }
104
+ );
105
+ const getVerifyEmailStatusURL = (userId) => `${AUTH_API_ROUTE}/verify-email-status/${String(userId)}`;
106
+ const createSession = async (data, otherOptions = {}) => await (0, import_fetcher.fetcher)(
107
+ `${AUTH_API_ROUTE}/session`,
108
+ authAPIOptions,
109
+ otherOptions,
110
+ {
111
+ method: "POST",
112
+ body: data
113
+ }
114
+ );
115
+ const getSession = async (sessionToken, otherOptions = {}) => await (0, import_fetcher.fetcher)(
116
+ `${backendURL}/session`,
117
+ authAPIOptions,
118
+ otherOptions,
119
+ { params: { session_token: sessionToken } }
120
+ );
121
+ const getCSRFToken = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
122
+ `${backendURL}/csrf-token`,
123
+ authAPIOptions,
124
+ otherOptions
125
+ );
126
+ const getOAuth2AccessToken = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
127
+ `${backendURL}/oauth2/token`,
128
+ authAPIOptions,
129
+ otherOptions,
130
+ {
131
+ method: "POST",
132
+ headers: {
133
+ "Content-Type": "application/x-www-form-urlencoded"
134
+ },
135
+ body: {
136
+ grant_type: "client_credentials",
137
+ client_id: clientId,
138
+ client_secret: clientSecret
139
+ }
140
+ }
141
+ );
142
+ return {
143
+ login,
144
+ getLoginWithGitHubURL,
145
+ getLoginWithGoogleURL,
146
+ register,
147
+ logout,
148
+ resetPassword,
149
+ askResetPassword,
150
+ checkIfUserHasPassword,
151
+ verifyEmail,
152
+ getVerifyEmailStatusURL,
153
+ changePassword,
154
+ createSession,
155
+ getSession,
156
+ getCSRFToken,
157
+ getOAuth2AccessToken
158
+ };
159
+ };
160
+ const authAPI = getAuthAPI();
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ authAPI,
164
+ getAuthAPI
165
+ });
166
+ //# sourceMappingURL=auth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/auth.ts"],"sourcesContent":["import type {\n AskResetPasswordBody,\n AskResetPasswordResult,\n CreateSessionBody,\n CreateSessionResult,\n GetSessionInformationQuery,\n GithubLoginQueryParams,\n GoogleLoginQueryParams,\n GetSessionInformationResult,\n LoginBody,\n LoginResult,\n RegisterBody,\n RegisterQuery,\n RegisterResult,\n ResetPasswordParams,\n ResetPasswordResult,\n UpdatePasswordBody,\n UpdatePasswordResult,\n ValidEmailParams,\n ValidEmailResult,\n SetCSRFTokenResult,\n GetOAuth2TokenBody,\n GetOAuth2TokenResult,\n UserAPI,\n CheckIfUserHasPasswordResult,\n // @ts-ignore @intlayer/backend not build yet\n} from '@intlayer/backend';\nimport { getConfiguration, type IntlayerConfig } from '@intlayer/config/client';\nimport { fetcher, type FetcherOptions } from './fetcher';\n\nexport const getAuthAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const { backendURL, clientId, clientSecret } = (\n intlayerConfig ?? getConfiguration()\n ).editor;\n const AUTH_API_ROUTE = `${backendURL}/api/auth`;\n\n /**\n * Logs in a user with the provided credentials.\n * @param user - User credentials.\n */\n const login = async (user: LoginBody, otherOptions: FetcherOptions = {}) =>\n await fetcher<LoginResult>(\n `${AUTH_API_ROUTE}/login`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: user,\n }\n );\n\n /**\n * Gets the login with GitHub URL.\n * @param params - The parameters for the login with GitHub URL.\n * @returns The login with GitHub URL.\n */\n const getLoginWithGitHubURL = (params: GithubLoginQueryParams): string => {\n const searchParams = new URLSearchParams(params);\n\n return `${AUTH_API_ROUTE}/login/github?${searchParams.toString()}`;\n };\n\n /**\n * Gets the login with Google URL.\n * @param params - The parameters for the login with Google URL.\n * @returns The login with Google URL.\n */\n const getLoginWithGoogleURL = (params: GoogleLoginQueryParams): string => {\n const searchParams = new URLSearchParams(params);\n\n return `${AUTH_API_ROUTE}/login/google?${searchParams.toString()}`;\n };\n\n /**\n * Registers a new user with the provided credentials.\n * @param user - User credentials.\n * @returns User object.\n */\n const register = async (\n user: RegisterBody,\n query: RegisterQuery = {},\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<RegisterResult>(\n `${AUTH_API_ROUTE}/register`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: user,\n params: query,\n }\n );\n\n /**\n * Signs out the user.\n * @returns User object.\n */\n const logout = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<void>(\n `${AUTH_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Ask to resets the password of a user with the provided email address.\n * @param email - Email address of the user.\n * @returns User object.\n */\n const askResetPassword = async (\n email: AskResetPasswordBody['email'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AskResetPasswordResult>(\n `${AUTH_API_ROUTE}/password/reset`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { email },\n }\n );\n\n /**\n * Resets the password of a user with the provided email address.\n * @param email - Email address of the user.\n * @returns User object.\n */\n const resetPassword = async (\n params: ResetPasswordParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<ResetPasswordResult>(\n `${AUTH_API_ROUTE}/password/reset`,\n authAPIOptions,\n otherOptions,\n { params, method: 'POST' }\n );\n\n /**\n * Changes the password of a user with the provided data.\n * @param data - New password and confirmation.\n * @returns User object.\n */\n const changePassword = async (\n data: UpdatePasswordBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdatePasswordResult>(\n `${AUTH_API_ROUTE}/password`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: data,\n }\n );\n\n /**\n * Checks if a user has a password.\n * @param params - User ID.\n * @returns User object.\n */\n const checkIfUserHasPassword = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<CheckIfUserHasPasswordResult>(\n `${AUTH_API_ROUTE}/password/has`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n /**\n * Verifies the email address of a user with the provided token.\n * @param params - User ID and secret key.\n * @returns User object.\n */\n const verifyEmail = async (\n { userId, secret }: ValidEmailParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<ValidEmailResult>(\n `${AUTH_API_ROUTE}/active/${userId}/${secret}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Gets the verify email status URL to use in the SSE.\n * @param userId - User ID.\n * @returns The verify email status URL.\n */\n const getVerifyEmailStatusURL = (userId: string | UserAPI['_id']) =>\n `${AUTH_API_ROUTE}/verify-email-status/${String(userId)}`;\n\n /**\n * Creates a session for a user.\n * @param params - User ID and secret key.\n * @returns User object.\n */\n const createSession = async (\n data: CreateSessionBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreateSessionResult>(\n `${AUTH_API_ROUTE}/session`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: data,\n }\n );\n\n /**\n * Gets a session and user.\n * @param sessionToken - Session token.\n * @param otherOptions - Fetcher options.\n * @returns Session and user information.\n */\n const getSession = async (\n sessionToken?: GetSessionInformationQuery['session_token'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetSessionInformationResult>(\n `${backendURL}/session`,\n authAPIOptions,\n otherOptions,\n { params: { session_token: sessionToken } }\n );\n\n /**\n * Gets the CSRF token.\n * @param otherOptions - Fetcher options.\n * @returns The CSRF token.\n */\n const getCSRFToken = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<SetCSRFTokenResult>(\n `${backendURL}/csrf-token`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Gets an oAuth2 accessToken\n * @return The token information\n */\n const getOAuth2AccessToken = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetOAuth2TokenResult>(\n `${backendURL}/oauth2/token`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: {\n grant_type: 'client_credentials',\n client_id: clientId!,\n client_secret: clientSecret!,\n } satisfies GetOAuth2TokenBody,\n }\n );\n\n return {\n login,\n getLoginWithGitHubURL,\n getLoginWithGoogleURL,\n register,\n logout,\n resetPassword,\n askResetPassword,\n checkIfUserHasPassword,\n verifyEmail,\n getVerifyEmailStatusURL,\n changePassword,\n createSession,\n getSession,\n getCSRFToken,\n getOAuth2AccessToken,\n };\n};\n\nexport const authAPI = getAuthAPI();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,oBAAsD;AACtD,qBAA6C;AAEtC,MAAM,aAAa,CACxB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,EAAE,YAAY,UAAU,aAAa,KACzC,sBAAkB,gCAAiB,GACnC;AACF,QAAM,iBAAiB,GAAG,UAAU;AAMpC,QAAM,QAAQ,OAAO,MAAiB,eAA+B,CAAC,MACpE,UAAM;AAAA,IACJ,GAAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAOF,QAAM,wBAAwB,CAAC,WAA2C;AACxE,UAAM,eAAe,IAAI,gBAAgB,MAAM;AAE/C,WAAO,GAAG,cAAc,iBAAiB,aAAa,SAAS,CAAC;A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AAM;AAAA,IACJ,GAAG,cAAc,WAAW,MAAM,IAAI,MAAM;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EACF;AAOF,QAAM,0BAA0B,CAAC,WAC/B,GAAG,cAAc,wBAAwB,OAAO,MAAM,CAAC;AAOzD,QAAM,gBAAgB,OACpB,MACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAQF,QAAM,aAAa,OACjB,cACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb;AAAA,IACA;AAAA,IACA,EAAE,QAAQ,EAAE,eAAe,aAAa,EAAE;AAAA,EAC5C;AAOF,QAAM,eAAe,OAAO,eAA+B,CAAC,MAC1D,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb;AAAA,IACA;AAAA,EACF;AAMF,QAAM,uBAAuB,OAAO,eAA+B,CAAC,MAClE,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,QACJ,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAEF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,UAAU,WAAW;","names":[]}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var dictionary_exports = {};
20
+ __export(dictionary_exports, {
21
+ dictionaryAPI: () => dictionaryAPI,
22
+ getDictionaryAPI: () => getDictionaryAPI
23
+ });
24
+ module.exports = __toCommonJS(dictionary_exports);
25
+ var import_client = require("@intlayer/config/client");
26
+ var import_fetcher = require('./fetcher.cjs');
27
+ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
28
+ const { backendURL } = (intlayerConfig ?? (0, import_client.getConfiguration)()).editor;
29
+ const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;
30
+ const getDictionaries = async (filters, otherOptions = {}) => await (0, import_fetcher.fetcher)(
31
+ PROJECT_API_ROUTE,
32
+ authAPIOptions,
33
+ otherOptions,
34
+ {
35
+ params: filters
36
+ }
37
+ );
38
+ const getDictionariesKeys = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
39
+ `${PROJECT_API_ROUTE}/keys`,
40
+ authAPIOptions,
41
+ otherOptions
42
+ );
43
+ const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await (0, import_fetcher.fetcher)(
44
+ `${PROJECT_API_ROUTE}/${dictionaryKey}`,
45
+ authAPIOptions,
46
+ otherOptions,
47
+ {
48
+ params: version ? { version: version.toString() } : void 0
49
+ }
50
+ );
51
+ const addDictionary = async (dictionary, otherOptions = {}) => await (0, import_fetcher.fetcher)(
52
+ `${PROJECT_API_ROUTE}`,
53
+ authAPIOptions,
54
+ otherOptions,
55
+ {
56
+ method: "POST",
57
+ body: dictionary
58
+ }
59
+ );
60
+ const pushDictionaries = async (dictionaries, otherOptions = {}) => await (0, import_fetcher.fetcher)(
61
+ `${PROJECT_API_ROUTE}`,
62
+ authAPIOptions,
63
+ otherOptions,
64
+ {
65
+ method: "PATCH",
66
+ body: { dictionaries }
67
+ }
68
+ );
69
+ const updateDictionary = async (dictionaryId, dictionary, otherOptions = {}) => await (0, import_fetcher.fetcher)(
70
+ `${PROJECT_API_ROUTE}/${dictionaryId}`,
71
+ authAPIOptions,
72
+ otherOptions,
73
+ {
74
+ method: "PUT",
75
+ body: dictionary
76
+ }
77
+ );
78
+ const deleteDictionary = async (id, otherOptions = {}) => await (0, import_fetcher.fetcher)(
79
+ `${PROJECT_API_ROUTE}`,
80
+ authAPIOptions,
81
+ otherOptions,
82
+ {
83
+ method: "DELETE",
84
+ body: { id }
85
+ }
86
+ );
87
+ return {
88
+ getDictionaries,
89
+ getDictionariesKeys,
90
+ getDictionary,
91
+ pushDictionaries,
92
+ addDictionary,
93
+ updateDictionary,
94
+ deleteDictionary
95
+ };
96
+ };
97
+ const dictionaryAPI = getDictionaryAPI();
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ dictionaryAPI,
101
+ getDictionaryAPI
102
+ });
103
+ //# sourceMappingURL=dictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/dictionary.ts"],"sourcesContent":["import type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesParams,\n GetDictionariesResult,\n UpdateDictionaryParam,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n GetDictionariesKeysResult,\n // @ts-ignore @intlayer/backend not build yet\n} from '@intlayer/backend';\nimport { getConfiguration, type IntlayerConfig } from '@intlayer/config/client';\nimport { fetcher, type FetcherOptions } from './fetcher';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const { backendURL } = (intlayerConfig ?? getConfiguration()).editor;\n const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n PROJECT_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n `${PROJECT_API_ROUTE}/keys`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryKey}`,\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n dictionary: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: dictionary,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionaryId: UpdateDictionaryParam['dictionaryId'],\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n body: { id },\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionary,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n\nexport const dictionaryAPI = getDictionaryAPI();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,oBAAsD;AACtD,qBAA6C;AAEtC,MAAM,mBAAmB,CAC9B,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,EAAE,WAAW,KAAK,sBAAkB,gCAAiB,GAAG;AAC9D,QAAM,oBAAoB,GAAG,UAAU;AAMvC,QAAM,kBAAkB,OACtB,SACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EACF;AAKF,QAAM,sBAAsB,OAAO,eAA+B,CAAC,MACjE,UAAM;AAAA,IACJ,GAAG,iBAAiB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAOF,QAAM,gBAAgB,OACpB,eACA,SACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,iBAAiB,IAAI,aAAa;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ,UAAU,EAAE,SAAS,QAAQ,SAAS,EAAE,IAAI;AAAA,IACtD;AAAA,EACF;AAMF,QAAM,gBAAgB,OACpB,YACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,iBAAiB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAEF,QAAM,mBAAmB,OACvB,cACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,iBAAiB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM,EAAE,aAAa;AAAA,IACvB;AAAA,EACF;AAMF,QAAM,mBAAmB,OACvB,cACA,YACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,iBAAiB,IAAI,YAAY;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAMF,QAAM,mBAAmB,OACvB,IACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,iBAAiB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM,EAAE,GAAG;AAAA,IACb;AAAA,EACF;AAEF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,MAAM,gBAAgB,iBAAiB;","names":[]}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var fetcher_exports = {};
20
+ __export(fetcher_exports, {
21
+ fetcher: () => fetcher,
22
+ fetcherOptions: () => fetcherOptions
23
+ });
24
+ module.exports = __toCommonJS(fetcher_exports);
25
+ const fetcherOptions = {
26
+ method: "GET",
27
+ // Default HTTP method
28
+ headers: {
29
+ "Content-Type": "application/json"
30
+ // Default content type
31
+ },
32
+ credentials: "include"
33
+ // Include cookies in the request
34
+ };
35
+ const removeUndefined = (obj) => {
36
+ Object.keys(obj).forEach((key) => {
37
+ if (obj[key] === void 0) {
38
+ delete obj[key];
39
+ }
40
+ });
41
+ return obj;
42
+ };
43
+ const deepMerge = (objects) => objects.reduce((acc, obj) => {
44
+ const acc1 = acc ?? {};
45
+ const obj1 = removeUndefined(obj ?? {});
46
+ if (typeof acc1 === "object" && typeof obj1 === "object") {
47
+ return { ...acc1, ...obj1 };
48
+ }
49
+ return obj1 ?? acc1;
50
+ }, {});
51
+ const fetcher = async (url, ...options) => {
52
+ let paramsString = "";
53
+ let bodyString = void 0;
54
+ const otherOptions = options.map(
55
+ ({ body, params: params2, headers, ...otherOptions2 }) => otherOptions2
56
+ );
57
+ const mergedOptions = deepMerge([fetcherOptions, ...otherOptions]);
58
+ const mergedHeaders = deepMerge([
59
+ fetcherOptions.headers,
60
+ ...options.map((option) => option.headers)
61
+ ]);
62
+ const params = deepMerge(options.map((option) => option.params));
63
+ const method = mergedOptions.method;
64
+ if (method !== "GET" && method !== "HEAD") {
65
+ const body = deepMerge(options.map((option) => option.body));
66
+ if (mergedHeaders?.["Content-Type"] === "application/x-www-form-urlencoded") {
67
+ bodyString = new URLSearchParams(
68
+ body
69
+ ).toString();
70
+ } else {
71
+ bodyString = JSON.stringify(body);
72
+ }
73
+ }
74
+ if (Object.entries(params).length > 0) {
75
+ paramsString = `?${new URLSearchParams(
76
+ params
77
+ ).toString()}`;
78
+ }
79
+ const formattedOptions = {
80
+ ...mergedOptions,
81
+ headers: mergedHeaders,
82
+ body: bodyString
83
+ };
84
+ const urlResult = `${url}${paramsString}`;
85
+ const response = await fetch(urlResult, formattedOptions);
86
+ if (!response.ok) {
87
+ const result = await response.json();
88
+ console.error(result);
89
+ throw new Error(JSON.stringify(result.error) ?? "An error occurred");
90
+ }
91
+ return await response.json();
92
+ };
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ fetcher,
96
+ fetcherOptions
97
+ });
98
+ //# sourceMappingURL=fetcher.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fetcher.ts"],"sourcesContent":["/**\n * Type definition for options used in the fetcher function.\n * Extends the standard RequestInit interface (excluding 'body'),\n * and adds 'body' and 'params' properties for convenience.\n */\nexport type FetcherOptions = Omit<RequestInit, 'body'> & {\n /**\n * Body of the request. Should be a key-value pair object.\n */\n body?: Record<string, unknown>;\n /**\n * Query parameters to be appended to the URL.\n */\n params?:\n | Record<string, string | string[] | undefined>\n | string[]\n | URLSearchParams;\n};\n\n/**\n * Default options for the fetcher function.\n * Sets the default method to 'GET', the 'Content-Type' header to 'application/json',\n * and includes credentials in the request.\n */\nexport const fetcherOptions: FetcherOptions = {\n method: 'GET', // Default HTTP method\n headers: {\n 'Content-Type': 'application/json', // Default content type\n },\n credentials: 'include', // Include cookies in the request\n};\n\n/**\n * Utility function to remove properties with undefined values from an object.\n * This helps prevent sending undefined values in the request options.\n *\n * @param obj - The object to clean.\n * @returns The cleaned object without undefined values.\n */\nconst removeUndefined = (obj: object) => {\n Object.keys(obj).forEach((key) => {\n if (obj[key as keyof typeof obj] === undefined) {\n delete obj[key as keyof typeof obj];\n }\n });\n return obj;\n};\n\n/**\n * Deeply merges an array of objects into a single object.\n * Later objects in the array overwrite properties of earlier ones.\n *\n * @template T - The type of objects being merged.\n * @param objects - An array of objects to merge.\n * @returns The merged object.\n */\nconst deepMerge = <T extends object>(objects: (T | undefined)[]): T =>\n objects.reduce((acc, obj) => {\n const acc1: T = (acc ?? {}) as T;\n const obj1: T = removeUndefined(obj ?? {}) as T;\n\n if (typeof acc1 === 'object' && typeof obj1 === 'object') {\n // Merge the two objects\n return { ...acc1, ...obj1 };\n }\n\n // If one of them is not an object, return the defined one\n return obj1 ?? acc1;\n }, {} as T)!;\n\n/**\n * Fetcher function to make HTTP requests.\n * It merges default options with user-provided options,\n * handles query parameters and request body,\n * and returns the parsed JSON response.\n *\n * @template T - The expected type of the response data.\n * @param url - The endpoint URL.\n * @param options - Additional options to customize the request.\n * @returns A promise that resolves with the response data of type T.\n *\n * @example\n * ```typescript\n * // Making a GET request with query parameters\n * const data = await fetcher<MyResponseType>('https://api.example.com/data', {\n * params: { search: 'query' },\n * });\n *\n * // Making a POST request with a JSON body\n * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {\n * method: 'POST',\n * body: { key: 'value' },\n * });\n *\n * // Merge body, headers, and params\n * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {\n * method: 'POST',\n * body: { key: 'value' },\n * headers: { 'Content-Type': 'application/json' },\n * params: { search: 'query' },\n * },\n * {\n * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n * params: { page: 1 },\n * });\n * ```\n *\n * Result:\n * ```typescript\n * {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n * params: { page: 1, search: 'query' },\n * body: { key: 'value' },\n * }\n * ```\n */\nexport const fetcher = async <T>(\n url: string,\n ...options: FetcherOptions[]\n): Promise<T> => {\n // Initialize query parameters string and request body string\n let paramsString = '';\n let bodyString: string | undefined = undefined;\n\n // Extract other options excluding 'body', 'params', and 'headers'\n const otherOptions = options.map(\n ({ body, params, headers, ...otherOptions }) => otherOptions\n );\n\n // Merge default options with user-provided options\n const mergedOptions = deepMerge([fetcherOptions, ...otherOptions]);\n\n // Merge default headers with user-provided headers\n const mergedHeaders = deepMerge([\n fetcherOptions.headers,\n ...options.map((option) => option.headers),\n ]);\n\n // Merge query parameters\n const params = deepMerge(options.map((option) => option.params));\n\n const method = mergedOptions.method;\n\n // If the request method is not 'GET' or 'HEAD', prepare the request body\n if (method !== 'GET' && method !== 'HEAD') {\n // Merge all 'body' options\n const body = deepMerge(options.map((option) => option.body));\n if (\n mergedHeaders?.['Content-Type' as keyof HeadersInit] ===\n 'application/x-www-form-urlencoded'\n ) {\n // If the content type is 'application/x-www-form-urlencoded', encode the body accordingly\n bodyString = new URLSearchParams(\n body as Record<string, string>\n ).toString();\n } else {\n // Otherwise, stringify the body as JSON\n bodyString = JSON.stringify(body);\n }\n }\n\n // If there are query parameters, append them to the URL\n if (Object.entries(params).length > 0) {\n paramsString = `?${new URLSearchParams(\n params as Record<string, string>\n ).toString()}`;\n }\n\n // Prepare the final request options\n const formattedOptions: RequestInit = {\n ...mergedOptions,\n headers: mergedHeaders,\n body: bodyString,\n };\n\n // Construct the full URL with query parameters\n const urlResult = `${url}${paramsString}`;\n\n // Make the HTTP request using fetch\n const response = await fetch(urlResult, formattedOptions);\n\n if (!response.ok) {\n const result = await response.json();\n\n console.error(result);\n\n // You can customize the error message or include more details\n throw new Error(JSON.stringify(result.error) ?? 'An error occurred');\n }\n return await response.json();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,iBAAiC;AAAA,EAC5C,QAAQ;AAAA;AAAA,EACR,SAAS;AAAA,IACP,gBAAgB;AAAA;AAAA,EAClB;AAAA,EACA,aAAa;AAAA;AACf;AASA,MAA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,SAAS,GAAG;AACrC,mBAAe,IAAI,IAAI;AAAA,MACrB;AAAA,IACF,EAAE,SAAS,CAAC;AAAA,EACd;AAGA,QAAM,mBAAgC;AAAA,IACpC,GAAG;AAAA,IACH,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AAGA,QAAM,YAAY,GAAG,GAAG,GAAG,YAAY;AAGvC,QAAM,WAAW,MAAM,MAAM,WAAW,gBAAgB;AAExD,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,SAAS,MAAM,SAAS,KAAK;AAEnC,YAAQ,MAAM,MAAM;AAGpB,UAAM,IAAI,MAAM,KAAK,UAAU,OAAO,KAAK,KAAK,mBAAmB;AAAA,EACrE;AACA,SAAO,MAAM,SAAS,KAAK;AAC7B;","names":["params","otherOptions"]}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ getIntlayerAPI: () => getIntlayerAPI,
22
+ intlayerAPI: () => intlayerAPI
23
+ });
24
+ module.exports = __toCommonJS(src_exports);
25
+ var import_ai = require('./ai.cjs');
26
+ var import_auth = require('./auth.cjs');
27
+ var import_dictionary = require('./dictionary.cjs');
28
+ var import_organization = require('./organization.cjs');
29
+ var import_project = require('./project.cjs');
30
+ var import_stripe = require('./stripe.cjs');
31
+ var import_tag = require('./tag.cjs');
32
+ var import_user = require('./user.cjs');
33
+ const getIntlayerAPI = (authAPIOptions = {}, intlayerConfig) => ({
34
+ organization: (0, import_organization.getOrganizationAPI)(authAPIOptions, intlayerConfig),
35
+ project: (0, import_project.getProjectAPI)(authAPIOptions, intlayerConfig),
36
+ user: (0, import_user.getUserAPI)(authAPIOptions, intlayerConfig),
37
+ auth: (0, import_auth.getAuthAPI)(authAPIOptions, intlayerConfig),
38
+ dictionary: (0, import_dictionary.getDictionaryAPI)(authAPIOptions, intlayerConfig),
39
+ stripe: (0, import_stripe.getStripeAPI)(authAPIOptions, intlayerConfig),
40
+ ai: (0, import_ai.getAiAPI)(authAPIOptions, intlayerConfig),
41
+ tag: (0, import_tag.getTagAPI)(authAPIOptions, intlayerConfig)
42
+ });
43
+ const intlayerAPI = getIntlayerAPI();
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ getIntlayerAPI,
47
+ intlayerAPI
48
+ });
49
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { type IntlayerConfig } from '@intlayer/config/client';\nimport { getAiAPI } from './ai';\nimport { getAuthAPI } from './auth';\nimport { getDictionaryAPI } from './dictionary';\nimport type { FetcherOptions } from './fetcher';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getUserAPI } from './user';\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => ({\n organization: getOrganizationAPI(authAPIOptions, intlayerConfig),\n project: getProjectAPI(authAPIOptions, intlayerConfig),\n user: getUserAPI(authAPIOptions, intlayerConfig),\n auth: getAuthAPI(authAPIOptions, intlayerConfig),\n dictionary: getDictionaryAPI(authAPIOptions, intlayerConfig),\n stripe: getStripeAPI(authAPIOptions, intlayerConfig),\n ai: getAiAPI(authAPIOptions, intlayerConfig),\n tag: getTagAPI(authAPIOptions, intlayerConfig),\n});\n\nexport const intlayerAPI = getIntlayerAPI();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAAyB;AACzB,kBAA2B;AAC3B,wBAAiC;AAEjC,0BAAmC;AACnC,qBAA8B;AAC9B,oBAA6B;AAC7B,iBAA0B;AAC1B,kBAA2B;AAEpB,MAAM,iBAAiB,CAC5B,iBAAiC,CAAC,GAClC,oBACI;AAAA,EACJ,kBAAc,wCAAmB,gBAAgB,cAAc;AAAA,EAC/D,aAAS,8BAAc,gBAAgB,cAAc;AAAA,EACrD,UAAM,wBAAW,gBAAgB,cAAc;AAAA,EAC/C,UAAM,wBAAW,gBAAgB,cAAc;AAAA,EAC/C,gBAAY,oCAAiB,gBAAgB,cAAc;AAAA,EAC3D,YAAQ,4BAAa,gBAAgB,cAAc;AAAA,EACnD,QAAI,oBAAS,gBAAgB,cAAc;AAAA,EAC3C,SAAK,sBAAU,gBAAgB,cAAc;AAC/C;AAEO,MAAM,cAAc,eAAe;","names":[]}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var organization_exports = {};
20
+ __export(organization_exports, {
21
+ getOrganizationAPI: () => getOrganizationAPI,
22
+ organizationAPI: () => organizationAPI
23
+ });
24
+ module.exports = __toCommonJS(organization_exports);
25
+ var import_client = require("@intlayer/config/client");
26
+ var import_fetcher = require('./fetcher.cjs');
27
+ const getOrganizationAPI = (authAPIOptions = {}, intlayerConfig) => {
28
+ const { backendURL } = (intlayerConfig ?? (0, import_client.getConfiguration)()).editor;
29
+ const ORGANIZATION_API_ROUTE = `${backendURL}/api/organization`;
30
+ const getOrganizations = async (filters, otherOptions = {}) => await (0, import_fetcher.fetcher)(
31
+ ORGANIZATION_API_ROUTE,
32
+ authAPIOptions,
33
+ otherOptions,
34
+ {
35
+ params: filters
36
+ }
37
+ );
38
+ const getOrganization = async (organizationId, otherOptions = {}) => await (0, import_fetcher.fetcher)(
39
+ `${ORGANIZATION_API_ROUTE}/${String(organizationId)}`,
40
+ authAPIOptions,
41
+ otherOptions
42
+ );
43
+ const addOrganization = async (organization, otherOptions = {}) => await (0, import_fetcher.fetcher)(
44
+ ORGANIZATION_API_ROUTE,
45
+ authAPIOptions,
46
+ otherOptions,
47
+ {
48
+ method: "POST",
49
+ body: organization
50
+ }
51
+ );
52
+ const updateOrganization = async (organization, otherOptions = {}) => (0, import_fetcher.fetcher)(
53
+ ORGANIZATION_API_ROUTE,
54
+ authAPIOptions,
55
+ otherOptions,
56
+ {
57
+ method: "PUT",
58
+ body: organization
59
+ }
60
+ );
61
+ const updateOrganizationMembers = async (body, otherOptions = {}) => (0, import_fetcher.fetcher)(
62
+ `${ORGANIZATION_API_ROUTE}/members`,
63
+ authAPIOptions,
64
+ otherOptions,
65
+ {
66
+ method: "PUT",
67
+ body
68
+ }
69
+ );
70
+ const addOrganizationMember = async (body, otherOptions = {}) => (0, import_fetcher.fetcher)(
71
+ `${ORGANIZATION_API_ROUTE}/member`,
72
+ authAPIOptions,
73
+ otherOptions,
74
+ {
75
+ method: "POST",
76
+ body
77
+ }
78
+ );
79
+ const deleteOrganization = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
80
+ ORGANIZATION_API_ROUTE,
81
+ authAPIOptions,
82
+ otherOptions,
83
+ {
84
+ method: "DELETE"
85
+ }
86
+ );
87
+ const selectOrganization = async (organizationId, otherOptions = {}) => await (0, import_fetcher.fetcher)(
88
+ `${ORGANIZATION_API_ROUTE}/${String(organizationId)}`,
89
+ authAPIOptions,
90
+ otherOptions,
91
+ {
92
+ method: "PUT"
93
+ }
94
+ );
95
+ const unselectOrganization = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
96
+ `${ORGANIZATION_API_ROUTE}/logout`,
97
+ authAPIOptions,
98
+ otherOptions,
99
+ {
100
+ method: "POST"
101
+ }
102
+ );
103
+ return {
104
+ getOrganizations,
105
+ getOrganization,
106
+ addOrganization,
107
+ addOrganizationMember,
108
+ updateOrganization,
109
+ updateOrganizationMembers,
110
+ deleteOrganization,
111
+ selectOrganization,
112
+ unselectOrganization
113
+ };
114
+ };
115
+ const organizationAPI = getOrganizationAPI();
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ getOrganizationAPI,
119
+ organizationAPI
120
+ });
121
+ //# sourceMappingURL=organization.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/organization.ts"],"sourcesContent":["import type {\n AddOrganizationBody,\n AddOrganizationResult,\n DeleteOrganizationResult,\n GetOrganizationParam,\n GetOrganizationResult,\n GetOrganizationsParams,\n GetOrganizationsResult,\n UpdateOrganizationBody,\n UpdateOrganizationResult,\n SelectOrganizationParam,\n SelectOrganizationResult,\n UnselectOrganizationResult,\n UpdateOrganizationMembersBody,\n UpdateOrganizationMembersResult,\n AddOrganizationMemberBody,\n AddOrganizationMemberResult,\n // @ts-ignore @intlayer/backend not build yet\n} from '@intlayer/backend';\nimport { getConfiguration, type IntlayerConfig } from '@intlayer/config/client';\nimport { fetcher, type FetcherOptions } from './fetcher';\n\nexport const getOrganizationAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const { backendURL } = (intlayerConfig ?? getConfiguration()).editor;\n const ORGANIZATION_API_ROUTE = `${backendURL}/api/organization`;\n\n /**\n * Retrieves a list of organizations based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getOrganizations = async (\n filters?: GetOrganizationsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetOrganizationsResult>(\n ORGANIZATION_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n params: filters,\n }\n );\n\n /**\n * Retrieves an organization by its ID.\n * @param organizationId - Organization ID.\n */\n const getOrganization = async (\n organizationId: GetOrganizationParam['organizationId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetOrganizationResult>(\n `${ORGANIZATION_API_ROUTE}/${String(organizationId)}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Adds a new organization to the database.\n * @param organization - Organization data.\n */\n const addOrganization = async (\n organization: AddOrganizationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddOrganizationResult>(\n ORGANIZATION_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: organization,\n }\n );\n\n /**\n * Updates an existing organization in the database.\n * @param organization - Updated organization data.\n */\n const updateOrganization = async (\n organization: UpdateOrganizationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<UpdateOrganizationResult>(\n ORGANIZATION_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: organization,\n }\n );\n\n /**\n * Update members to the organization in the database.\n * @param body - Updated organization members data.\n */\n const updateOrganizationMembers = async (\n body: UpdateOrganizationMembersBody,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<UpdateOrganizationMembersResult>(\n `${ORGANIZATION_API_ROUTE}/members`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body,\n }\n );\n\n /**\n * Add member to the organization in the database.\n * @param body - Updated organization members data.\n */\n const addOrganizationMember = async (\n body: AddOrganizationMemberBody,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<AddOrganizationMemberResult>(\n `${ORGANIZATION_API_ROUTE}/member`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n /**\n * Deletes an organization from the database by its ID.\n * @param organizationId - Organization ID.\n */\n const deleteOrganization = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<DeleteOrganizationResult>(\n ORGANIZATION_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n /**\n * Select an organization from the database by its ID.\n * @param organizationId - Organization ID.\n */\n const selectOrganization = async (\n organizationId: SelectOrganizationParam['organizationId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SelectOrganizationResult>(\n `${ORGANIZATION_API_ROUTE}/${String(organizationId)}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Unselect an organization from the database by its ID.\n * @param organizationId - Organization ID.\n */\n const unselectOrganization = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<UnselectOrganizationResult>(\n `${ORGANIZATION_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n return {\n getOrganizations,\n getOrganization,\n addOrganization,\n addOrganizationMember,\n updateOrganization,\n updateOrganizationMembers,\n deleteOrganization,\n selectOrganization,\n unselectOrganization,\n };\n};\n\nexport const organizationAPI = getOrganizationAPI();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBA,oBAAsD;AACtD,qBAA6C;AAEtC,MAAM,qBAAqB,CAChC,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,EAAE,WAAW,KAAK,sBAAkB,gCAAiB,GAAG;AAC9D,QAAM,yBAAyB,GAAG,UAAU;AAM5C,QAAM,mBAAmB,OACvB,SACA,e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