@yrpri/api 9.0.220 → 9.0.222

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 (55) hide show
  1. package/agents/managers/subscriptionManager.js +2 -2
  2. package/app.js +11 -8
  3. package/controllers/communities.cjs +3 -1
  4. package/controllers/groups.cjs +1 -1
  5. package/controllers/images.cjs +12 -1
  6. package/models/domain.cjs +1 -1
  7. package/models/image.cjs +90 -24
  8. package/package.json +83 -63
  9. package/scripts/cloning/clearUsersForCommunitiesFromUrl.js +1 -1
  10. package/scripts/cloning/cloneFromUrlScript.js +1 -1
  11. package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +1 -1
  12. package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +1 -1
  13. package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +1 -1
  14. package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +1 -1
  15. package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +1 -1
  16. package/scripts/cloning/copyPostVideosFromURL.js +1 -1
  17. package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +1 -1
  18. package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +1 -1
  19. package/scripts/cloning/setAdminsFromURL.js +1 -1
  20. package/scripts/cloning/setExternalIdsFromURL.js +1 -1
  21. package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +1 -1
  22. package/scripts/landUseGame/export3Ddata.js +1 -1
  23. package/scripts/movePostsToGroupsRecountGroupFromUrl.js +1 -1
  24. package/scripts/recountALLCommunityGroupCounts.js +1 -1
  25. package/scripts/recountCommunitesFromUrl.js +1 -1
  26. package/scripts/recountCommunity.js +1 -1
  27. package/scripts/setLanguageOnGroupCommunitesFromUrl.js +1 -1
  28. package/services/engine/allOurIdeas/aiHelper.d.ts +1 -2
  29. package/services/engine/analytics/manager.cjs +1 -1
  30. package/services/engine/analytics/plausible/manager.cjs +1 -1
  31. package/services/engine/analytics/utils.cjs +1 -1
  32. package/services/engine/notifications/emails_utils.cjs +10 -1
  33. package/services/engine/recommendations/events_manager.cjs +1 -1
  34. package/services/engine/reports/common_utils.cjs +1 -1
  35. package/services/llms/baseChatBot.d.ts +1 -2
  36. package/services/llms/imageGeneration/s3Service.js +72 -11
  37. package/services/scripts/translation_replace_text_from_url.js +1 -1
  38. package/services/utils/redisConnection.cjs +2 -3
  39. package/services/utils/translation_cloning.cjs +1 -1
  40. package/services/utils/translation_helpers.cjs +1 -1
  41. package/tests/emails_utils.test.cjs +130 -0
  42. package/tests/emails_utils.test.d.cts +1 -0
  43. package/tests/imageModel.test.cjs +373 -0
  44. package/tests/imageModel.test.d.cts +1 -0
  45. package/tests/multerSharpS3Compat.test.cjs +229 -0
  46. package/tests/multerSharpS3Compat.test.d.cts +1 -0
  47. package/tests/requestCompat.test.cjs +288 -0
  48. package/tests/requestCompat.test.d.cts +1 -0
  49. package/utils/multerSharpS3Compat.cjs +230 -0
  50. package/utils/multerSharpS3Compat.d.cts +22 -0
  51. package/utils/passportSsoCompat.cjs +15 -0
  52. package/utils/passportSsoCompat.d.cts +2 -0
  53. package/utils/recount_utils.cjs +1 -1
  54. package/utils/requestCompat.cjs +180 -0
  55. package/utils/requestCompat.d.cts +9 -0
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ const axios = require("axios");
3
+ const FormData = require("form-data");
4
+ const { PassThrough } = require("stream");
5
+ const mergeOptions = (defaults, overrides) => {
6
+ return {
7
+ ...defaults,
8
+ ...overrides,
9
+ headers: {
10
+ ...(defaults.headers || {}),
11
+ ...(overrides.headers || {}),
12
+ },
13
+ };
14
+ };
15
+ const normalizeInput = (input, methodOverride) => {
16
+ const options = typeof input === "string"
17
+ ? { url: input }
18
+ : input && typeof input === "object"
19
+ ? { ...input }
20
+ : {};
21
+ options.method = (methodOverride || options.method || "GET").toUpperCase();
22
+ return options;
23
+ };
24
+ const appendFormValue = (form, key, value) => {
25
+ if (Array.isArray(value)) {
26
+ value.forEach((entry) => appendFormValue(form, key, entry));
27
+ return;
28
+ }
29
+ if (value &&
30
+ typeof value === "object" &&
31
+ Object.prototype.hasOwnProperty.call(value, "value")) {
32
+ form.append(key, value.value, value.options || undefined);
33
+ }
34
+ else {
35
+ form.append(key, value == null ? "" : value);
36
+ }
37
+ };
38
+ const buildFormData = (formDataInput) => {
39
+ const form = new FormData();
40
+ Object.entries(formDataInput || {}).forEach(([key, value]) => {
41
+ appendFormValue(form, key, value);
42
+ });
43
+ return form;
44
+ };
45
+ const shouldUseJson = (options) => {
46
+ return options.json !== undefined && options.json !== false;
47
+ };
48
+ const buildAxiosConfig = (options, streamResponse = false) => {
49
+ const headers = { ...(options.headers || {}) };
50
+ const config = {
51
+ url: options.url,
52
+ method: (options.method || "GET").toLowerCase(),
53
+ headers,
54
+ params: options.qs,
55
+ responseType: streamResponse
56
+ ? "stream"
57
+ : options.encoding === null
58
+ ? "arraybuffer"
59
+ : "text",
60
+ responseEncoding: !streamResponse && options.encoding !== null
61
+ ? options.encoding || "utf8"
62
+ : undefined,
63
+ timeout: options.timeout,
64
+ maxBodyLength: Infinity,
65
+ maxContentLength: Infinity,
66
+ validateStatus: () => true,
67
+ };
68
+ if (options.followRedirect === false) {
69
+ config.maxRedirects = 0;
70
+ }
71
+ if (options.formData) {
72
+ const form = buildFormData(options.formData);
73
+ config.data = form;
74
+ Object.assign(headers, form.getHeaders());
75
+ }
76
+ else if (shouldUseJson(options)) {
77
+ if (options.json !== true) {
78
+ config.data = options.json;
79
+ }
80
+ else if (options.body !== undefined) {
81
+ config.data = options.body;
82
+ }
83
+ if (!headers["Content-Type"] && !headers["content-type"]) {
84
+ headers["Content-Type"] = "application/json";
85
+ }
86
+ }
87
+ else if (options.body !== undefined) {
88
+ config.data = options.body;
89
+ }
90
+ return config;
91
+ };
92
+ const normalizeBody = (response, options) => {
93
+ let body = response.data;
94
+ if (options.encoding === null) {
95
+ return Buffer.isBuffer(body) ? body : Buffer.from(body);
96
+ }
97
+ if (Buffer.isBuffer(body)) {
98
+ body = body.toString(options.encoding || "utf8");
99
+ }
100
+ else if (body == null) {
101
+ body = "";
102
+ }
103
+ else if (typeof body !== "string") {
104
+ if (shouldUseJson(options)) {
105
+ return body;
106
+ }
107
+ body = String(body);
108
+ }
109
+ if (shouldUseJson(options) && body !== "") {
110
+ try {
111
+ return JSON.parse(body);
112
+ }
113
+ catch (error) {
114
+ return body;
115
+ }
116
+ }
117
+ return body;
118
+ };
119
+ const buildResponse = (response, body) => {
120
+ return {
121
+ statusCode: response.status,
122
+ statusMessage: response.statusText,
123
+ headers: response.headers,
124
+ body,
125
+ };
126
+ };
127
+ const normalizeTransportError = (error) => {
128
+ if (!error || typeof error !== "object") {
129
+ return error;
130
+ }
131
+ if (!error.errno) {
132
+ error.errno = error.code || error.cause?.code;
133
+ }
134
+ return error;
135
+ };
136
+ const createRequestStream = async (options, output) => {
137
+ try {
138
+ const response = await axios(buildAxiosConfig(options, true));
139
+ const responseMeta = buildResponse(response, response.data);
140
+ output.emit("response", responseMeta);
141
+ response.data.on("error", (error) => output.emit("error", normalizeTransportError(error)));
142
+ response.data.pipe(output);
143
+ }
144
+ catch (error) {
145
+ output.emit("error", normalizeTransportError(error));
146
+ }
147
+ };
148
+ const executeRequest = async (options, callback) => {
149
+ try {
150
+ const response = await axios(buildAxiosConfig(options));
151
+ const body = normalizeBody(response, options);
152
+ const requestResponse = buildResponse(response, body);
153
+ callback(null, requestResponse, body);
154
+ }
155
+ catch (error) {
156
+ callback(normalizeTransportError(error), null, undefined);
157
+ }
158
+ };
159
+ const createRequestClient = (defaultOptions = {}) => {
160
+ const requestClient = (input, callback) => {
161
+ const options = mergeOptions(defaultOptions, normalizeInput(input));
162
+ if (typeof callback === "function") {
163
+ void executeRequest(options, callback);
164
+ return null;
165
+ }
166
+ const output = new PassThrough();
167
+ void createRequestStream(options, output);
168
+ return output;
169
+ };
170
+ requestClient.defaults = (overrides = {}) => {
171
+ return createRequestClient(mergeOptions(defaultOptions, overrides));
172
+ };
173
+ ["get", "post", "put", "head", "delete"].forEach((method) => {
174
+ requestClient[method] = (input, callback) => {
175
+ return requestClient(normalizeInput(input, method.toUpperCase()), callback);
176
+ };
177
+ });
178
+ return requestClient;
179
+ };
180
+ module.exports = createRequestClient();
@@ -0,0 +1,9 @@
1
+ declare function _exports(input: any, callback: any): PassThrough | null;
2
+ declare namespace _exports {
3
+ function defaults(overrides?: {}): {
4
+ (input: any, callback: any): PassThrough | null;
5
+ defaults(overrides?: {}): /*elided*/ any;
6
+ };
7
+ }
8
+ export = _exports;
9
+ import { PassThrough } from "stream";