sr-npm 1.7.318 → 1.7.319

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.
@@ -0,0 +1,31 @@
1
+ import { secrets } from '@wix/secrets';
2
+ import { auth } from '@wix/essentials';
3
+ import { fetch } from 'wix-fetch';
4
+
5
+ const elevatedGetSecretValue = auth.elevate(secrets.getSecretValue);
6
+
7
+ export async function htmlToRichContent(htmlString) {
8
+ if (!htmlString) {
9
+ return null;
10
+ }
11
+
12
+ const serverlessAuthSecret = await elevatedGetSecretValue('serverless_auth');
13
+ const token = serverlessAuthSecret && (serverlessAuthSecret.value || serverlessAuthSecret);
14
+
15
+ const requestOptions = {
16
+ method: 'post',
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ 'Authorization': `Bearer ${token}`
20
+ },
21
+ body: JSON.stringify({ content: htmlString })
22
+ };
23
+
24
+ const response = await fetch('https://www.wixapis.com/data-sync/v1/abmp-content-converter', requestOptions);
25
+ if (!response.ok) {
26
+ throw new Error(`content-converter failed with status ${response.status}`);
27
+ }
28
+ const data = await response.json();
29
+ return data.richContent || null;
30
+ }
31
+
@@ -0,0 +1,11 @@
1
+ const secretsData = require('./secretsData');
2
+
3
+ // Expose only what the client needs via web module
4
+ export async function getServerlessAuth() {
5
+ return await secretsData.getServerlessAuth();
6
+ }
7
+
8
+ export async function getCompanyId() {
9
+ return await secretsData.getCompanyId();
10
+ }
11
+
package/backend/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { getServerlessAuth } = require('./secretsData');
2
+
1
3
  async function chunkedBulkOperation({ items, chunkSize, processChunk }) {
2
4
  for (let i = 0; i < items.length; i += chunkSize) {
3
5
  const chunk = items.slice(i, i + chunkSize);
@@ -72,6 +74,12 @@ function sanitizeId(input) {
72
74
  return withAnd.replace(/[^A-Za-z0-9-]/g, '');
73
75
  }
74
76
 
77
+ function htmlToRichContent(htmlString) {
78
+ console.log("htmlString **********",htmlString)
79
+ const serverlessAuth = getServerlessAuth()
80
+ console.log("serverlessAuth **********",serverlessAuth)
81
+ }
82
+
75
83
  module.exports = {
76
84
  chunkedBulkOperation,
77
85
  delay,
@@ -80,4 +88,5 @@ module.exports = {
80
88
  prepareToSaveArray,
81
89
  normalizeCityName,
82
90
  sanitizeId,
91
+ htmlToRichContent
83
92
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.318",
3
+ "version": "1.7.319",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,8 +1,7 @@
1
1
  const {
2
- htmlToText,
3
- htmlToRichContent
2
+ htmlToText
4
3
  } = require('../public/utils');
5
-
4
+ const { htmlToRichContent } = require('../backend/utils');
6
5
  async function positionPageOnReady(_$w) {
7
6
 
8
7
  await bind(_$w);
package/public/utils.js CHANGED
@@ -1,5 +1,4 @@
1
- const { fetch } = require('wix-fetch');
2
- const { getServerlessAuth } = require('../backend/secretsData');
1
+ // Note: Do NOT import backend modules here. This file runs on the client.
3
2
  // const { secrets } = require("wix-secrets-backend.v2");
4
3
  // const { elevate } = require("wix-auth");
5
4
 
@@ -34,44 +33,7 @@ function htmlToText(html) {
34
33
  return text.replace(/\n\s*\n+/g, '\n\n').replace(/[ \t]+\n/g, '\n').trim();
35
34
  }
36
35
 
37
- async function htmlToRichContent(htmlString) {
38
- console.log("htmlString **********",htmlString)
39
- const serverlessAuth = getServerlessAuth()
40
- console.log("serverlessAuth **********",serverlessAuth)
41
- // const raw = JSON.stringify({
42
- // "content": htmlString
43
- // });
44
-
45
-
46
- // const requestOptions = {
47
- // method: "post",
48
- // headers: {
49
- // "Content-Type": "application/json",
50
- // "Cookie": "XSRF-TOKEN=1753949844|p--a7HsuVjR4",
51
- // "Authorization": "Bearer 2e19efe5f44d29d74480f5b744a5a90f19ba6ca7012ced19e7b14edb1ad6a641"
52
-
53
- // },
54
- // body: raw
55
- // };
56
-
57
-
58
- // try{
59
- // const response = await fetch("https://www.wixapis.com/data-sync/v1/abmp-content-converter", requestOptions);
60
- // if (response.ok) {
61
- // const data = await response.json();
62
- // return data.richContent;
63
- // }
64
-
65
- // else
66
- // {
67
- // console.error(`error in fetching data, response: ${response}`);
68
-
69
- // }
70
- // }
71
- // catch(error){
72
- // console.error("error in fetching data",error);
73
- // }
74
- }
36
+ // htmlToRichContent moved to backend web module to avoid exposing secrets.
75
37
 
76
38
  function filterBrokenMarkers(items) {
77
39
  return items
@@ -92,6 +54,5 @@ function filterBrokenMarkers(items) {
92
54
 
93
55
  module.exports = {
94
56
  htmlToText,
95
- filterBrokenMarkers,
96
- htmlToRichContent
57
+ filterBrokenMarkers
97
58
  };