@playq/core 0.2.77

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 (225) hide show
  1. package/README.md +41 -0
  2. package/bin/playq.js +175 -0
  3. package/cucumber.js +10 -0
  4. package/dist/exec/featureFileCache.d.ts +21 -0
  5. package/dist/exec/featureFileCache.js +124 -0
  6. package/dist/exec/featureFilePreProcess.d.ts +12 -0
  7. package/dist/exec/featureFilePreProcess.js +208 -0
  8. package/dist/exec/preLoader.d.ts +1 -0
  9. package/dist/exec/preLoader.js +72 -0
  10. package/dist/exec/preProcessEntry.d.ts +1 -0
  11. package/dist/exec/preProcessEntry.js +83 -0
  12. package/dist/exec/preProcess_old_todelete.d.ts +1 -0
  13. package/dist/exec/preProcess_old_todelete.js +258 -0
  14. package/dist/exec/runner.d.ts +1 -0
  15. package/dist/exec/runner.js +221 -0
  16. package/dist/exec/runner_orchestrator.d.ts +1 -0
  17. package/dist/exec/runner_orchestrator.js +85 -0
  18. package/dist/exec/sgGenerator.d.ts +11 -0
  19. package/dist/exec/sgGenerator.js +310 -0
  20. package/dist/global.d.ts +15 -0
  21. package/dist/global.js +185 -0
  22. package/dist/helper/actions/api/apiRequestActions.d.ts +117 -0
  23. package/dist/helper/actions/api/apiRequestActions.js +374 -0
  24. package/dist/helper/actions/api/apiValidationActions.d.ts +119 -0
  25. package/dist/helper/actions/api/apiValidationActions.js +615 -0
  26. package/dist/helper/actions/apiActions.d.ts +18 -0
  27. package/dist/helper/actions/apiActions.js +34 -0
  28. package/dist/helper/actions/apiStepDefs.d.ts +1 -0
  29. package/dist/helper/actions/apiStepDefs.js +64 -0
  30. package/dist/helper/actions/comm/commonActions.d.ts +58 -0
  31. package/dist/helper/actions/comm/commonActions.js +198 -0
  32. package/dist/helper/actions/comm/utilityActions.d.ts +131 -0
  33. package/dist/helper/actions/comm/utilityActions.js +351 -0
  34. package/dist/helper/actions/commActions.d.ts +18 -0
  35. package/dist/helper/actions/commActions.js +34 -0
  36. package/dist/helper/actions/commStepDefs.d.ts +1 -0
  37. package/dist/helper/actions/commStepDefs.js +57 -0
  38. package/dist/helper/actions/stepGroupStepDefs.d.ts +1 -0
  39. package/dist/helper/actions/stepGroupStepDefs.js +15 -0
  40. package/dist/helper/actions/web/alertActions.d.ts +61 -0
  41. package/dist/helper/actions/web/alertActions.js +224 -0
  42. package/dist/helper/actions/web/cookieActions.d.ts +45 -0
  43. package/dist/helper/actions/web/cookieActions.js +186 -0
  44. package/dist/helper/actions/web/downloadActions.d.ts +40 -0
  45. package/dist/helper/actions/web/downloadActions.js +153 -0
  46. package/dist/helper/actions/web/elementReaderActions.d.ts +95 -0
  47. package/dist/helper/actions/web/elementReaderActions.js +326 -0
  48. package/dist/helper/actions/web/formActions.d.ts +122 -0
  49. package/dist/helper/actions/web/formActions.js +423 -0
  50. package/dist/helper/actions/web/iframeActions.d.ts +23 -0
  51. package/dist/helper/actions/web/iframeActions.js +108 -0
  52. package/dist/helper/actions/web/javascriptActions.d.ts +14 -0
  53. package/dist/helper/actions/web/javascriptActions.js +77 -0
  54. package/dist/helper/actions/web/keyboardActions.d.ts +35 -0
  55. package/dist/helper/actions/web/keyboardActions.js +118 -0
  56. package/dist/helper/actions/web/localStorageActions.d.ts +51 -0
  57. package/dist/helper/actions/web/localStorageActions.js +163 -0
  58. package/dist/helper/actions/web/mouseActions.d.ts +240 -0
  59. package/dist/helper/actions/web/mouseActions.js +609 -0
  60. package/dist/helper/actions/web/reportingActions.d.ts +34 -0
  61. package/dist/helper/actions/web/reportingActions.js +58 -0
  62. package/dist/helper/actions/web/screenshotActions.d.ts +34 -0
  63. package/dist/helper/actions/web/screenshotActions.js +151 -0
  64. package/dist/helper/actions/web/testDataActions.d.ts +21 -0
  65. package/dist/helper/actions/web/testDataActions.js +211 -0
  66. package/dist/helper/actions/web/validationActions.d.ts +547 -0
  67. package/dist/helper/actions/web/validationActions.js +1754 -0
  68. package/dist/helper/actions/web/waitActions.d.ts +191 -0
  69. package/dist/helper/actions/web/waitActions.js +589 -0
  70. package/dist/helper/actions/web/webNavigation.d.ts +104 -0
  71. package/dist/helper/actions/web/webNavigation.js +288 -0
  72. package/dist/helper/actions/webActions.d.ts +32 -0
  73. package/dist/helper/actions/webActions.js +48 -0
  74. package/dist/helper/actions/webStepDefs.d.ts +1 -0
  75. package/dist/helper/actions/webStepDefs.js +455 -0
  76. package/dist/helper/browsers/browserManager.d.ts +1 -0
  77. package/dist/helper/browsers/browserManager.js +56 -0
  78. package/dist/helper/bundle/defaultEntries.d.ts +6 -0
  79. package/dist/helper/bundle/defaultEntries.js +200 -0
  80. package/dist/helper/bundle/env.d.ts +1 -0
  81. package/dist/helper/bundle/env.js +157 -0
  82. package/dist/helper/bundle/vars.d.ts +9 -0
  83. package/dist/helper/bundle/vars.js +375 -0
  84. package/dist/helper/faker/customFaker.d.ts +55 -0
  85. package/dist/helper/faker/customFaker.js +45 -0
  86. package/dist/helper/faker/modules/data/postcodes_valid_sg.json +17 -0
  87. package/dist/helper/faker/modules/dateTime.d.ts +18 -0
  88. package/dist/helper/faker/modules/dateTime.js +106 -0
  89. package/dist/helper/faker/modules/mobile.d.ts +4 -0
  90. package/dist/helper/faker/modules/mobile.js +59 -0
  91. package/dist/helper/faker/modules/nric.d.ts +32 -0
  92. package/dist/helper/faker/modules/nric.js +84 -0
  93. package/dist/helper/faker/modules/passport.d.ts +3 -0
  94. package/dist/helper/faker/modules/passport.js +36 -0
  95. package/dist/helper/faker/modules/person.d.ts +14 -0
  96. package/dist/helper/faker/modules/person.js +73 -0
  97. package/dist/helper/faker/modules/postcode.d.ts +6 -0
  98. package/dist/helper/faker/modules/postcode.js +47 -0
  99. package/dist/helper/fixtures/locAggregate.d.ts +7 -0
  100. package/dist/helper/fixtures/locAggregate.js +94 -0
  101. package/dist/helper/fixtures/logFixture.d.ts +8 -0
  102. package/dist/helper/fixtures/logFixture.js +56 -0
  103. package/dist/helper/fixtures/webFixture.d.ts +19 -0
  104. package/dist/helper/fixtures/webFixture.js +186 -0
  105. package/dist/helper/fixtures/webLocFixture.d.ts +2 -0
  106. package/dist/helper/fixtures/webLocFixture.js +144 -0
  107. package/dist/helper/report/allureStepLogger.d.ts +0 -0
  108. package/dist/helper/report/allureStepLogger.js +25 -0
  109. package/dist/helper/report/customiseReport.d.ts +1 -0
  110. package/dist/helper/report/customiseReport.js +55 -0
  111. package/dist/helper/report/init.d.ts +1 -0
  112. package/dist/helper/report/init.js +14 -0
  113. package/dist/helper/report/report.d.ts +1 -0
  114. package/dist/helper/report/report.js +102 -0
  115. package/dist/helper/util/dataLoader.d.ts +10 -0
  116. package/dist/helper/util/dataLoader.js +73 -0
  117. package/dist/helper/util/logger.d.ts +4 -0
  118. package/dist/helper/util/logger.js +61 -0
  119. package/dist/helper/util/session/sessionUtil.d.ts +26 -0
  120. package/dist/helper/util/session/sessionUtil.js +729 -0
  121. package/dist/helper/util/stepHelpers.d.ts +2 -0
  122. package/dist/helper/util/stepHelpers.js +16 -0
  123. package/dist/helper/util/test-data/dataLoader.d.ts +7 -0
  124. package/dist/helper/util/test-data/dataLoader.js +145 -0
  125. package/dist/helper/util/test-data/dataTest.d.ts +10 -0
  126. package/dist/helper/util/test-data/dataTest.js +216 -0
  127. package/dist/helper/util/totp/totpHelper.d.ts +38 -0
  128. package/dist/helper/util/totp/totpHelper.js +117 -0
  129. package/dist/helper/util/utilities/cryptoUtil.d.ts +2 -0
  130. package/dist/helper/util/utilities/cryptoUtil.js +53 -0
  131. package/dist/helper/util/utilities/schemaGeneratorUtil.d.ts +2 -0
  132. package/dist/helper/util/utilities/schemaGeneratorUtil.js +129 -0
  133. package/dist/helper/util/utils.d.ts +2 -0
  134. package/dist/helper/util/utils.js +22 -0
  135. package/dist/helper/wrapper/PlaywrightWrappers.d.ts +8 -0
  136. package/dist/helper/wrapper/PlaywrightWrappers.js +26 -0
  137. package/dist/helper/wrapper/assert.d.ts +9 -0
  138. package/dist/helper/wrapper/assert.js +23 -0
  139. package/dist/index.d.ts +7 -0
  140. package/dist/index.js +57 -0
  141. package/dist/scripts/get-versions.d.ts +1 -0
  142. package/dist/scripts/get-versions.js +98 -0
  143. package/dist/scripts/posttest.d.ts +1 -0
  144. package/dist/scripts/posttest.js +29 -0
  145. package/dist/scripts/pretest.d.ts +1 -0
  146. package/dist/scripts/pretest.js +57 -0
  147. package/dist/scripts/util.d.ts +1 -0
  148. package/dist/scripts/util.js +376 -0
  149. package/package.json +68 -0
  150. package/src/exec/featureFileCache.ts +80 -0
  151. package/src/exec/featureFilePreProcess.ts +239 -0
  152. package/src/exec/preLoader.ts +72 -0
  153. package/src/exec/preProcessEntry.ts +59 -0
  154. package/src/exec/preProcess_old_todelete.ts +289 -0
  155. package/src/exec/runner.ts +241 -0
  156. package/src/exec/runnerCuke.js +90 -0
  157. package/src/exec/runner_orchestrator.ts +91 -0
  158. package/src/exec/sgGenerator.ts +373 -0
  159. package/src/global.ts +130 -0
  160. package/src/helper/actions/api/apiRequestActions.ts +362 -0
  161. package/src/helper/actions/api/apiValidationActions.ts +594 -0
  162. package/src/helper/actions/apiActions.ts +18 -0
  163. package/src/helper/actions/apiStepDefs.ts +80 -0
  164. package/src/helper/actions/comm/commonActions.ts +165 -0
  165. package/src/helper/actions/comm/utilityActions.ts +344 -0
  166. package/src/helper/actions/commActions.ts +18 -0
  167. package/src/helper/actions/commStepDefs.ts +72 -0
  168. package/src/helper/actions/stepGroupStepDefs.ts +17 -0
  169. package/src/helper/actions/web/alertActions.ts +179 -0
  170. package/src/helper/actions/web/cookieActions.ts +124 -0
  171. package/src/helper/actions/web/downloadActions.ts +129 -0
  172. package/src/helper/actions/web/elementReaderActions.ts +323 -0
  173. package/src/helper/actions/web/formActions.ts +469 -0
  174. package/src/helper/actions/web/iframeActions.ts +67 -0
  175. package/src/helper/actions/web/javascriptActions.ts +38 -0
  176. package/src/helper/actions/web/keyboardActions.ts +101 -0
  177. package/src/helper/actions/web/localStorageActions.ts +109 -0
  178. package/src/helper/actions/web/mouseActions.ts +864 -0
  179. package/src/helper/actions/web/reportingActions.ts +53 -0
  180. package/src/helper/actions/web/screenshotActions.ts +124 -0
  181. package/src/helper/actions/web/testDataActions.ts +162 -0
  182. package/src/helper/actions/web/validationActions.ts +2287 -0
  183. package/src/helper/actions/web/waitActions.ts +757 -0
  184. package/src/helper/actions/web/webNavigation.ts +313 -0
  185. package/src/helper/actions/webActions.ts +33 -0
  186. package/src/helper/actions/webStepDefs.ts +505 -0
  187. package/src/helper/browsers/browserManager.ts +23 -0
  188. package/src/helper/bundle/defaultEntries.ts +208 -0
  189. package/src/helper/bundle/env.ts +119 -0
  190. package/src/helper/bundle/vars.ts +368 -0
  191. package/src/helper/faker/customFaker.ts +107 -0
  192. package/src/helper/faker/modules/data/postcodes_valid_sg.json +17 -0
  193. package/src/helper/faker/modules/dateTime.ts +121 -0
  194. package/src/helper/faker/modules/mobile.ts +58 -0
  195. package/src/helper/faker/modules/nric.ts +109 -0
  196. package/src/helper/faker/modules/passport.ts +34 -0
  197. package/src/helper/faker/modules/person.ts +93 -0
  198. package/src/helper/faker/modules/postcode.ts +57 -0
  199. package/src/helper/fixtures/locAggregate.ts +61 -0
  200. package/src/helper/fixtures/logFixture.ts +57 -0
  201. package/src/helper/fixtures/webFixture.ts +206 -0
  202. package/src/helper/fixtures/webLocFixture.ts +143 -0
  203. package/src/helper/report/allureStepLogger.ts +26 -0
  204. package/src/helper/report/customiseReport.ts +61 -0
  205. package/src/helper/report/init.ts +18 -0
  206. package/src/helper/report/report.ts +72 -0
  207. package/src/helper/util/dataLoader.ts +42 -0
  208. package/src/helper/util/logger.ts +32 -0
  209. package/src/helper/util/session/sessionUtil.ts +839 -0
  210. package/src/helper/util/stepHelpers.ts +14 -0
  211. package/src/helper/util/test-data/dataLoader.ts +108 -0
  212. package/src/helper/util/test-data/dataTest.ts +191 -0
  213. package/src/helper/util/test-data/registerUser.json +7 -0
  214. package/src/helper/util/totp/totpHelper.ts +102 -0
  215. package/src/helper/util/utilities/cryptoUtil.ts +53 -0
  216. package/src/helper/util/utilities/schemaGeneratorUtil.ts +143 -0
  217. package/src/helper/util/utils.ts +28 -0
  218. package/src/helper/wrapper/PlaywrightWrappers.ts +28 -0
  219. package/src/helper/wrapper/assert.ts +25 -0
  220. package/src/index.ts +17 -0
  221. package/src/scripts/get-versions.ts +68 -0
  222. package/src/scripts/posttest.ts +32 -0
  223. package/src/scripts/pretest.ts +48 -0
  224. package/src/scripts/util.ts +406 -0
  225. package/tsconfig.json +30 -0
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.encryptUserInput = encryptUserInput;
37
+ const readline = __importStar(require("readline"));
38
+ const global_1 = require("../global");
39
+ const clipboardy = __importStar(require("clipboardy"));
40
+ const crypto = __importStar(require("crypto"));
41
+ const totpHelper_1 = require("../helper/util/totp/totpHelper");
42
+ const fs = __importStar(require("node:fs"));
43
+ const path = __importStar(require("node:path"));
44
+ let encryptedValue = '';
45
+ let outputValue = '';
46
+ const rl = readline.createInterface({
47
+ input: process.stdin,
48
+ output: process.stdout
49
+ });
50
+ // Handle Ctrl+C gracefully
51
+ process.on('SIGINT', () => {
52
+ console.log('\n🚪 Process interrupted by user (Ctrl+C)');
53
+ rl.close();
54
+ process.exit(0);
55
+ });
56
+ async function question(prompt) {
57
+ return new Promise(resolve => {
58
+ rl.question(prompt, (answer) => {
59
+ // Check for specific exit commands
60
+ if (answer.toLowerCase() === 'exit' ||
61
+ answer.toLowerCase() === 'quit' ||
62
+ answer.toLowerCase() === 'q' ||
63
+ answer === '\u001b') {
64
+ console.log('🚪 Exiting...');
65
+ rl.close();
66
+ process.exit(0);
67
+ }
68
+ resolve(answer);
69
+ });
70
+ });
71
+ }
72
+ async function encryptUserInput() {
73
+ try {
74
+ console.log('🔐 PlayQ Utility Helper\n');
75
+ console.log('💡 Type "exit", "quit", "q", or press Ctrl+C to exit anytime\n');
76
+ console.log('What would you like to do?');
77
+ console.log('1. Password (strong encryption)');
78
+ console.log('2. Text (strong encryption)');
79
+ console.log('3. Decrypt');
80
+ console.log('4. Generate 32bit Key');
81
+ console.log('5. Generate TOTP Code');
82
+ console.log('6. Generate API Schema from OpenAPI');
83
+ console.log('7. Exit');
84
+ const choice = await question('\nEnter your choice (1-7): ');
85
+ switch (choice) {
86
+ case '1':
87
+ await encryptPassword();
88
+ break;
89
+ case '2':
90
+ await encryptText();
91
+ break;
92
+ case '3':
93
+ await decrypt();
94
+ break;
95
+ case '4':
96
+ await generate32ByteKey();
97
+ break;
98
+ case '5':
99
+ await generateTotpCode();
100
+ break;
101
+ case '6':
102
+ await generateApiSchema();
103
+ break;
104
+ case '7':
105
+ console.log('🚪 Goodbye!');
106
+ return;
107
+ default:
108
+ console.log('❌ Invalid choice. Please run again.');
109
+ break;
110
+ }
111
+ // Ask user what to copy to clipboard (only for encryption/decryption operations)
112
+ if (choice !== '6') { // Skip clipboard for schema generation
113
+ console.log('\nWhat would you like to copy to clipboard?');
114
+ console.log('1. Copy encrypted value');
115
+ console.log('2. Nothing (skip copy)');
116
+ console.log('3. Exit');
117
+ const copyChoice = await question('Enter choice (1-3): ');
118
+ switch (copyChoice) {
119
+ case '1':
120
+ if (encryptedValue) {
121
+ await copyToClipboard(encryptedValue, 'Encrypted Password');
122
+ }
123
+ else if (outputValue) {
124
+ await copyToClipboard(outputValue, 'Output Value');
125
+ }
126
+ else {
127
+ console.log('❌ No encrypted / output value to copy');
128
+ }
129
+ break;
130
+ case '2':
131
+ console.log('📋 Skipped copying to clipboard');
132
+ break;
133
+ case '3':
134
+ console.log('🚪 Exiting...');
135
+ break;
136
+ default:
137
+ console.log('❌ Invalid choice');
138
+ break;
139
+ }
140
+ }
141
+ }
142
+ catch (error) {
143
+ console.error('❌ Error:', error);
144
+ }
145
+ finally {
146
+ rl.close();
147
+ }
148
+ }
149
+ async function copyToClipboard(text, description) {
150
+ try {
151
+ await clipboardy.default.write(text);
152
+ console.log(`✅ ${description} copied to clipboard!`);
153
+ console.log(`📋 Copied: ${text.length > 50 ? text.substring(0, 50) + '...' : text}`);
154
+ }
155
+ catch (error) {
156
+ console.error('❌ Failed to copy to clipboard:', error);
157
+ console.log('📝 Manual copy:');
158
+ console.log(text);
159
+ }
160
+ }
161
+ async function encryptPassword() {
162
+ const passwordText = await question('Enter password to encrypt (or "exit" to quit): ');
163
+ if (!passwordText) {
164
+ console.log('❌ Password cannot be empty');
165
+ return;
166
+ }
167
+ try {
168
+ console.log('🔄 Encrypting password...');
169
+ encryptedValue = await global_1.comm.encryptPassword(passwordText);
170
+ console.log('\n📋 🔐 Encrypted Password Result:');
171
+ console.log('='.repeat(50));
172
+ console.log(encryptedValue);
173
+ console.log('='.repeat(50));
174
+ }
175
+ catch (error) {
176
+ console.error('❌ Encryption failed:', error);
177
+ }
178
+ }
179
+ async function encryptText() {
180
+ const encryptText = await question('Enter text to encrypt (or "exit" to quit): ');
181
+ if (!encryptText) {
182
+ console.log('❌ Text cannot be empty');
183
+ return;
184
+ }
185
+ try {
186
+ console.log('🔄 Encrypting text...');
187
+ encryptedValue = await global_1.comm.encryptText(encryptText);
188
+ console.log('\n📋 🔐 Encrypted Text Result:');
189
+ console.log('='.repeat(50));
190
+ console.log(encryptedValue);
191
+ console.log('='.repeat(50));
192
+ }
193
+ catch (error) {
194
+ console.error('❌ Encryption failed:', error);
195
+ }
196
+ }
197
+ async function decrypt() {
198
+ const decryptText = await question('Enter text to decrypt (or "exit" to quit): ');
199
+ if (!decryptText) {
200
+ console.log('❌ Text cannot be empty');
201
+ return;
202
+ }
203
+ try {
204
+ console.log('🔄 Decrypting text...');
205
+ encryptedValue = await global_1.vars.replaceVariables('#{' + decryptText + '}');
206
+ console.log('\n📋 🔓 Decrypted Text Result:');
207
+ console.log('='.repeat(50));
208
+ console.log(encryptedValue);
209
+ console.log('='.repeat(50));
210
+ }
211
+ catch (error) {
212
+ console.error('❌ Decryption failed:', error);
213
+ }
214
+ }
215
+ async function generate32ByteKey() {
216
+ try {
217
+ const key = crypto.randomBytes(32).toString('hex');
218
+ encryptedValue = key;
219
+ console.log('\n🔑 32-byte Key Generated:');
220
+ console.log('='.repeat(50));
221
+ console.log(key);
222
+ console.log('='.repeat(50));
223
+ }
224
+ catch (error) {
225
+ console.error('❌ Failed to generate key:', error);
226
+ }
227
+ }
228
+ async function generateTotpCode() {
229
+ try {
230
+ let secretKey = process.env.PLAYQ_TOTP_SECRET_KEY;
231
+ if (!secretKey) {
232
+ const inputSecret = await question('Enter TOTP secret key (or "exit" to quit): ');
233
+ if (!inputSecret) {
234
+ throw new Error('❌ TOTP secret key cannot be empty');
235
+ }
236
+ process.env.PLAYQ_TOTP_SECRET_KEY = inputSecret;
237
+ secretKey = inputSecret;
238
+ }
239
+ if (secretKey.startsWith("enc.")) {
240
+ secretKey = global_1.vars.replaceVariables(`#{${secretKey}}`);
241
+ }
242
+ // const secret = crypto.randomBytes(20).toString('hex');
243
+ const totpHelper = new totpHelper_1.TOTPHelper(secretKey);
244
+ const token = totpHelper.generateToken();
245
+ outputValue = token;
246
+ console.log('\n🔑 TOTP Code Generated:');
247
+ console.log('='.repeat(50));
248
+ console.log(token);
249
+ console.log('='.repeat(50));
250
+ }
251
+ catch (error) {
252
+ console.error('❌ Failed to generate TOTP code:', error);
253
+ }
254
+ }
255
+ async function generateApiSchema() {
256
+ try {
257
+ console.log('\n📋 API Schema Generator');
258
+ console.log('Generate TypeScript schema files from OpenAPI specifications\n');
259
+ console.log('Select input source:');
260
+ console.log('1. URL (HTTP/HTTPS)');
261
+ console.log('2. Local file path');
262
+ const sourceChoice = await question('Enter choice (1-2): ');
263
+ let input = '';
264
+ let url = '';
265
+ if (sourceChoice === '1') {
266
+ url = await question('Enter OpenAPI JSON URL: ');
267
+ if (!url) {
268
+ console.log('❌ URL cannot be empty');
269
+ return;
270
+ }
271
+ }
272
+ else if (sourceChoice === '2') {
273
+ input = await question('Enter path to OpenAPI JSON file: ');
274
+ if (!input) {
275
+ console.log('❌ File path cannot be empty');
276
+ return;
277
+ }
278
+ }
279
+ else {
280
+ console.log('❌ Invalid choice');
281
+ return;
282
+ }
283
+ const outDir = await question('Enter output directory (default: resources/schemas): ') || 'resources/schemas';
284
+ const prefix = await question('Enter export name prefix (optional, e.g., "Api"): ') || '';
285
+ const indexFile = await question('Enter index file name (default: index.ts): ') || 'index.ts';
286
+ console.log('\n🔄 Generating schema files...');
287
+ await generateSchemaFiles({
288
+ input: input || undefined,
289
+ url: url || undefined,
290
+ outDir,
291
+ prefix,
292
+ indexFile
293
+ });
294
+ console.log('✅ Schema generation completed successfully!');
295
+ outputValue = `Schema files generated in: ${path.resolve(outDir)}`;
296
+ }
297
+ catch (error) {
298
+ console.error('❌ Failed to generate API schema:', error);
299
+ }
300
+ }
301
+ async function loadOpenApi(args) {
302
+ if (args.input) {
303
+ const p = path.resolve(args.input);
304
+ const raw = fs.readFileSync(p, "utf8");
305
+ return JSON.parse(raw);
306
+ }
307
+ // URL
308
+ const res = await fetch(args.url, {
309
+ headers: { Accept: "application/json" },
310
+ });
311
+ if (!res.ok) {
312
+ throw new Error(`Failed to fetch OpenAPI JSON from ${args.url}. HTTP ${res.status}`);
313
+ }
314
+ return (await res.json());
315
+ }
316
+ function safeIdent(name) {
317
+ // Make a valid TS identifier-ish name (keeps underscores)
318
+ const cleaned = name.replace(/[^a-zA-Z0-9_]/g, "_");
319
+ // Avoid leading digit
320
+ if (/^\d/.test(cleaned))
321
+ return "_" + cleaned;
322
+ return cleaned;
323
+ }
324
+ function exportNameFor(schemaName, prefix) {
325
+ // AgentVersion -> AgentVersionSchema, optional prefix -> ApiAgentVersionSchema
326
+ const base = `${schemaName}Schema`;
327
+ return prefix ? `${prefix}${base}` : base;
328
+ }
329
+ function ensureOutDir(outDir) {
330
+ fs.mkdirSync(outDir, { recursive: true });
331
+ }
332
+ function writeSchemaFile(outDir, schemaKey, exportName, schema, openapiVersion) {
333
+ const fileName = `${schemaKey}.schema.ts`;
334
+ const fullPath = path.join(outDir, fileName);
335
+ const content = `/* Auto-generated by PlayQ schema generator - OpenAPI ${openapiVersion} */\n` +
336
+ `/* Source schema: #/components/schemas/${schemaKey} */\n\n` +
337
+ `export const ${exportName} = ${JSON.stringify(schema, null, 2)} as const;\n`;
338
+ fs.writeFileSync(fullPath, content, "utf8");
339
+ }
340
+ function writeIndexFile(outDir, indexFile, entries) {
341
+ const fullPath = path.join(outDir, indexFile);
342
+ const lines = entries
343
+ .sort((a, b) => a.schemaKey.localeCompare(b.schemaKey))
344
+ .map(e => `export { ${e.exportName} } from "./${e.schemaKey}.schema";`);
345
+ fs.writeFileSync(fullPath, lines.join("\n") + "\n", "utf8");
346
+ }
347
+ async function generateSchemaFiles(args) {
348
+ var _a, _b, _c;
349
+ const doc = await loadOpenApi(args);
350
+ if (!((_a = doc.openapi) === null || _a === void 0 ? void 0 : _a.startsWith("3.1"))) {
351
+ // still might work, but you said OAS 3.1 and this generator assumes that
352
+ console.warn(`⚠️ OpenAPI version is "${doc.openapi}". Generator is optimised for 3.1.x.`);
353
+ }
354
+ const schemas = (_c = (_b = doc.components) === null || _b === void 0 ? void 0 : _b.schemas) !== null && _c !== void 0 ? _c : {};
355
+ const schemaKeys = Object.keys(schemas);
356
+ if (!schemaKeys.length) {
357
+ throw new Error(`No components.schemas found in the OpenAPI document.`);
358
+ }
359
+ const outDir = path.resolve(args.outDir);
360
+ ensureOutDir(outDir);
361
+ const indexEntries = [];
362
+ for (const rawKey of schemaKeys) {
363
+ const schemaKey = safeIdent(rawKey);
364
+ const exportName = exportNameFor(schemaKey, args.prefix);
365
+ const schema = schemas[rawKey];
366
+ writeSchemaFile(outDir, schemaKey, exportName, schema, doc.openapi);
367
+ indexEntries.push({ schemaKey, exportName });
368
+ }
369
+ writeIndexFile(outDir, args.indexFile, indexEntries);
370
+ console.log(`✅ Generated ${schemaKeys.length} schemas into: ${outDir}`);
371
+ console.log(`✅ Barrel export: ${path.join(outDir, args.indexFile)}`);
372
+ }
373
+ // Main execution
374
+ if (require.main === module) {
375
+ encryptUserInput();
376
+ }
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@playq/core",
3
+ "version": "0.2.77",
4
+ "description": "PlayQ Core (Phase 1) - raw TypeScript sources only.",
5
+ "files": [
6
+ "bin",
7
+ "dist",
8
+ "src",
9
+ "tsconfig.json",
10
+ "cucumber.js",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json || echo 'Skipping build (non-critical errors)'",
16
+ "prepublishOnly": "npm run build",
17
+ "util": "ts-node -r tsconfig-paths/register src/scripts/util.ts"
18
+ },
19
+ "main": "dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.js"
25
+ },
26
+ "./src/*": "./src/*",
27
+ "./dist/*": "./dist/*",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "dependencies": {
31
+ "@e965/xlsx": "^0.20.3",
32
+ "@faker-js/faker": "^9.6.0",
33
+ "allure-js-commons": "^2.14.0",
34
+ "axios": "^1.10.0",
35
+ "clipboardy": "^4.0.0",
36
+ "csv-parser": "^3.2.0",
37
+ "dotenv": "^16.0.3",
38
+ "minimist": "^1.2.8",
39
+ "otplib": "^12.0.1",
40
+ "qrcode": "^1.5.4",
41
+ "ts-node": "^10.9.2",
42
+ "tsconfig-paths": "^4.2.0",
43
+ "winston": "^3.8.2",
44
+ "yargs": "^18.0.0",
45
+ "ajv": "^8.0.0"
46
+ },
47
+ "keywords": [
48
+ "playwright",
49
+ "cucumber",
50
+ "test",
51
+ "automation",
52
+ "playq"
53
+ ],
54
+ "author": "NCS",
55
+ "license": "ISC",
56
+ "peerDependencies": {
57
+ "@cucumber/cucumber": "^12.1.0",
58
+ "@playwright/test": "^1.53.1",
59
+ "playwright": "^1.53.1"
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^20.19.27",
63
+ "typescript": "^5.6.3"
64
+ },
65
+ "bin": {
66
+ "playq": "bin/playq.js"
67
+ }
68
+ }
@@ -0,0 +1,80 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import * as vars from '../helper/bundle/vars';
4
+ const config: any = {};
5
+
6
+ const FEATURE_META_PATH = path.resolve('_Temp/.cache/featureMeta.json');
7
+
8
+ /**
9
+ * Returns the path to the cached feature file inside _Temp/execution/
10
+ */
11
+ export function getCachedFeatureFilePath(originalPath: string): string {
12
+ const filename = path.basename(originalPath);
13
+ return path.resolve('_Temp/execution', filename);
14
+ }
15
+
16
+ /**
17
+ * Determines if the cached feature should be used.
18
+ * Checks:
19
+ * - config.cucumber.featureFileCache is enabled
20
+ * - cached file and metadata exist
21
+ * - cached timestamp is newer than original file
22
+ */
23
+ export function shouldUseCachedFeature(originalPath: string, cachedPath: string): boolean {
24
+ // Logging for cache check
25
+ console.log(`🔍 Cache check started for: ${originalPath}`);
26
+ if (!config?.cucumber?.featureFileCache || vars.getConfigValue('cucumber.featureFileCache')) return false;
27
+ if (!fs.existsSync(cachedPath)) return false;
28
+ if (!fs.existsSync(FEATURE_META_PATH)) return false;
29
+ try {
30
+ const meta = JSON.parse(fs.readFileSync(FEATURE_META_PATH, 'utf-8'));
31
+ const originalStats = fs.statSync(originalPath);
32
+ const cachedMeta = meta[originalPath];
33
+ console.log(`📄 Cached Meta:`, cachedMeta);
34
+ if (!cachedMeta) return false;
35
+ const originalTime = originalStats.mtimeMs;
36
+ const metaTime = new Date(cachedMeta.updatedAt).getTime();
37
+ console.log(`📆 Original mtime: ${originalTime} | Cached updatedAt: ${metaTime}`);
38
+ console.log(`✅ Should use cache: ${metaTime >= originalTime}`);
39
+ return metaTime >= originalTime;
40
+ } catch (err) {
41
+ console.warn(`⚠️ Cache check failed. Proceeding without cache.`, err);
42
+ return false;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Updates the feature cache metadata file.
48
+ * Ensures _Temp/.cache/featureMeta.json exists, and writes { filePath, updatedAt }.
49
+ */
50
+ export function updateFeatureCacheMeta(originalPath: string, cachedPath: string): void {
51
+ const dir = path.dirname(FEATURE_META_PATH);
52
+ if (!fs.existsSync(dir)) {
53
+ fs.mkdirSync(dir, { recursive: true });
54
+ }
55
+ let meta: Record<string, any> = {};
56
+ if (fs.existsSync(FEATURE_META_PATH)) {
57
+ try {
58
+ meta = JSON.parse(fs.readFileSync(FEATURE_META_PATH, 'utf-8'));
59
+ } catch {
60
+ console.warn('⚠️ Failed to parse featureMeta.json. Overwriting.');
61
+ }
62
+ }
63
+ meta[originalPath] = {
64
+ filePath: cachedPath,
65
+ updatedAt: new Date().toISOString()
66
+ };
67
+ fs.writeFileSync(FEATURE_META_PATH, JSON.stringify(meta, null, 2), 'utf-8');
68
+ console.log(`💾 Feature cache metadata updated for: ${originalPath}`);
69
+ }
70
+
71
+ /**
72
+ * Writes feature content to cache if valid.
73
+ */
74
+ export function writeFeatureToCache(cachedPath: string, content: string): void {
75
+ if (!content.trim().startsWith('Feature')) {
76
+ console.warn(`❌ Skipping cache write: Content does not start with "Feature". Content preview:\n${content.substring(0, 100)}`);
77
+ return;
78
+ }
79
+ fs.writeFileSync(cachedPath, content, 'utf8');
80
+ }