@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,375 @@
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.getValue = getValue;
37
+ exports.getConfigValue = getConfigValue;
38
+ exports.setValue = setValue;
39
+ exports.replaceVariables = replaceVariables;
40
+ exports.debugVars = debugVars;
41
+ exports.parseLooseJson = parseLooseJson;
42
+ exports.loadFileEntries = loadFileEntries;
43
+ exports.initVars = initVars;
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ let importedVars = {};
47
+ const patternDirs = [
48
+ path.resolve(process.env.PLAYQ_PROJECT_ROOT || process.cwd(), "resources/patterns"),
49
+ path.resolve(process.env.PLAYQ_PROJECT_ROOT || process.cwd(), "extend/addons/pattern"),
50
+ ];
51
+ const storedVars = {};
52
+ const loggedMissingKeys = new Set();
53
+ function getValue(key, ifEmpty) {
54
+ if (!key) {
55
+ console.warn("⚠️ Empty key provided to getValue");
56
+ return ifEmpty ? "" : key;
57
+ }
58
+ key = key.trim();
59
+ if (key.startsWith("env.")) {
60
+ const envKey = key.slice(4);
61
+ const envValue = process.env[envKey];
62
+ if (!envValue) {
63
+ return ifEmpty ? "" : key;
64
+ }
65
+ return envValue;
66
+ }
67
+ if (key in storedVars)
68
+ return (ifEmpty && storedVars[key] === key) ? "" : storedVars[key];
69
+ // Only log when this is not an existence check
70
+ if (!ifEmpty && !loggedMissingKeys.has(key)) {
71
+ console.warn(`⚠️ Variable not found for key: "${key}"`);
72
+ loggedMissingKeys.add(key);
73
+ }
74
+ return ifEmpty ? "" : key;
75
+ }
76
+ function getConfigValue(key, ifEmpty) {
77
+ // Support environment variable overrides using PLAYQ__ dotted path mapping.
78
+ // Example: config.browser.browserType -> PLAYQ__browser__browserType
79
+ const rawKey = key.trim();
80
+ const envKey = 'PLAYQ__' + rawKey.replace(/\./g, '__');
81
+ if (process.env[envKey])
82
+ return process.env[envKey];
83
+ const fullKey = 'config.' + rawKey;
84
+ if (fullKey in storedVars)
85
+ return storedVars[fullKey];
86
+ if (!loggedMissingKeys.has(fullKey)) {
87
+ loggedMissingKeys.add(fullKey);
88
+ if (ifEmpty)
89
+ return '';
90
+ }
91
+ return fullKey;
92
+ }
93
+ function setValue(key, value) {
94
+ storedVars[key] = value;
95
+ if (key.startsWith("var.static.")) {
96
+ updateVarStaticJson(key.slice(11), value);
97
+ }
98
+ }
99
+ function updateVarStaticJson(key, value) {
100
+ const jsonFilePath = path.resolve(process.cwd(), "resources/var.static.json");
101
+ let data = {};
102
+ // Read existing file if it exists
103
+ if (fs.existsSync(jsonFilePath)) {
104
+ try {
105
+ const fileContent = fs.readFileSync(jsonFilePath, "utf-8");
106
+ data = JSON.parse(fileContent);
107
+ console.log(`📖 Existing data:`, data); // Debug log
108
+ }
109
+ catch (error) {
110
+ console.warn(`Warning: Could not parse existing var.static.json:`, error.message);
111
+ data = {};
112
+ }
113
+ }
114
+ else {
115
+ console.log(`📝 Creating new var.static.json file`);
116
+ }
117
+ // Store old value for comparison
118
+ const oldValue = data[key];
119
+ // Update or add the key-value pair
120
+ data[key] = value;
121
+ console.log(`🔄 Updating key "${key}": "${oldValue}" → "${value}"`); // Debug log
122
+ console.log(`📦 Final data:`, data); // Debug log
123
+ // Ensure the directory exists
124
+ const dir = path.dirname(jsonFilePath);
125
+ if (!fs.existsSync(dir)) {
126
+ fs.mkdirSync(dir, { recursive: true });
127
+ }
128
+ // Write the updated data back to the file
129
+ try {
130
+ fs.writeFileSync(jsonFilePath, JSON.stringify(data, null, 2), "utf-8");
131
+ if (oldValue !== undefined) {
132
+ console.log(`✅ Updated var.static.json: ${key} = ${value} (was: ${oldValue})`);
133
+ }
134
+ else {
135
+ console.log(`✅ Added to var.static.json: ${key} = ${value}`);
136
+ }
137
+ }
138
+ catch (error) {
139
+ console.error(`❌ Failed to write to var.static.json:`, error.message);
140
+ throw error;
141
+ }
142
+ }
143
+ function replaceVariables(input) {
144
+ if (typeof input !== "string")
145
+ input = input.toString();
146
+ return input.replace(/\#\{([^}]+)\}/g, (_, varName) => {
147
+ if (varName.startsWith("pwd.")) {
148
+ const encryptedValue = varName.replace(/^pwd\./, "");
149
+ try {
150
+ const crypto = require("../util/utilities/cryptoUtil");
151
+ return crypto.decrypt(encryptedValue);
152
+ }
153
+ catch (error) {
154
+ console.warn('Warning: Could not decrypt pwd value:', error.message);
155
+ return varName;
156
+ }
157
+ }
158
+ else if (varName.startsWith("enc.")) {
159
+ const encryptedValue = varName.replace(/^enc\./, "");
160
+ try {
161
+ const crypto = require("../util/utilities/cryptoUtil");
162
+ return crypto.decrypt(encryptedValue);
163
+ }
164
+ catch (error) {
165
+ console.warn('Warning: Could not decrypt enc value:', error.message);
166
+ return varName;
167
+ }
168
+ }
169
+ if (varName.endsWith(".(toNumber)")) {
170
+ const baseVar = varName.replace(".(toNumber)", "");
171
+ const value = getValue(baseVar);
172
+ return value !== undefined && value !== null && value !== ""
173
+ ? Number(value)
174
+ : "";
175
+ }
176
+ return getValue(varName);
177
+ });
178
+ }
179
+ function debugVars() {
180
+ console.log("📦 Static Vars:", storedVars);
181
+ }
182
+ function flattenConfig(obj, prefix = "config") {
183
+ const entries = {};
184
+ for (const key in obj) {
185
+ const fullKey = `${prefix}.${key}`;
186
+ if (typeof obj[key] === "object" && obj[key] !== null && !Array.isArray(obj[key])) {
187
+ Object.assign(entries, flattenConfig(obj[key], fullKey));
188
+ }
189
+ else if (Array.isArray(obj[key])) {
190
+ entries[fullKey] = obj[key].join(";");
191
+ }
192
+ else {
193
+ entries[fullKey] = String(obj[key]);
194
+ }
195
+ }
196
+ return entries;
197
+ }
198
+ function loadPatternEntries() {
199
+ var _a;
200
+ const files = [];
201
+ for (const dir of patternDirs) {
202
+ if (fs.existsSync(dir)) {
203
+ try {
204
+ const dirFiles = fs
205
+ .readdirSync(dir)
206
+ .filter((file) => {
207
+ const isTS = file.endsWith(".pattern.ts");
208
+ const isAddonDir = dir.includes("extend/addons/pattern");
209
+ if (!isTS)
210
+ return false;
211
+ if (isAddonDir)
212
+ return file.startsWith("_");
213
+ return !file.startsWith("_");
214
+ })
215
+ .map((file) => path.join(dir, file));
216
+ files.push(...dirFiles);
217
+ }
218
+ catch (error) {
219
+ console.warn(`Warning: Could not read pattern directory ${dir}:`, error.message);
220
+ }
221
+ }
222
+ }
223
+ for (const file of files) {
224
+ try {
225
+ const fileName = path.basename(file, ".pattern.ts");
226
+ if (!/^[a-zA-Z0-9_]+$/.test(fileName)) {
227
+ console.warn(`❌ Invalid pattern file name "${fileName}". Only alphanumeric characters and underscores are allowed.`);
228
+ continue;
229
+ }
230
+ delete require.cache[require.resolve(file)];
231
+ const patternModule = require(file);
232
+ const exported = patternModule[fileName] || ((_a = patternModule.default) === null || _a === void 0 ? void 0 : _a[fileName]);
233
+ if (!exported) {
234
+ console.warn(`❌ Exported const '${fileName}' not found in: ${file}`);
235
+ continue;
236
+ }
237
+ const flattened = flattenConfig(exported, `pattern.${fileName}`);
238
+ Object.assign(storedVars, flattened);
239
+ }
240
+ catch (error) {
241
+ console.warn(`Warning: Could not load pattern file ${file}:`, error.message);
242
+ }
243
+ }
244
+ }
245
+ function loadFileEntries(file, constName, prefix) {
246
+ console.log(`🔍 Loading file: ${file} with constName: ${constName} and prefix: ${prefix}`);
247
+ const absPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file);
248
+ if (!fs.existsSync(absPath)) {
249
+ throw new Error(`❌ Load file not found: ${absPath}`);
250
+ }
251
+ const ext = path.extname(absPath);
252
+ let data;
253
+ if (ext === ".ts" || ext === ".js") {
254
+ delete require.cache[require.resolve(absPath)];
255
+ const module = require(absPath);
256
+ data = module[constName] || (module.default && module.default[constName]) || module.default || module;
257
+ if (!data) {
258
+ throw new Error(`❌ Exported const '${constName}' not found in: ${file}`);
259
+ }
260
+ }
261
+ else if (ext === ".json") {
262
+ data = JSON.parse(fs.readFileSync(absPath, "utf-8"));
263
+ }
264
+ else {
265
+ throw new Error(`❌ Unsupported file extension: ${ext}`);
266
+ }
267
+ const flat = flattenConfig(data, prefix || "");
268
+ Object.assign(storedVars, flat);
269
+ }
270
+ function resolveModulePath(basePath) {
271
+ const candidates = [".ts", ".js", ".mjs", ".cjs", ".json"];
272
+ for (const ext of candidates) {
273
+ const candidate = basePath + ext;
274
+ if (fs.existsSync(candidate))
275
+ return candidate;
276
+ }
277
+ return basePath; // fall back to base (may still resolve via require paths)
278
+ }
279
+ function parseLooseJson(str) {
280
+ if (!str || str.trim() === "" || str.trim() === '""')
281
+ return {};
282
+ const needsBraces = !str.trim().startsWith("{") || !str.trim().endsWith("}");
283
+ let wrappedStr = needsBraces ? `{${str}}` : str;
284
+ try {
285
+ const locatorRegex = /(["']?locator["']?\s*:\s*)(xpath=[^,\}\n\r]+|css=[^,\}\n\r]+|chain=[^,\}\n\r]+)/g;
286
+ const locatorPlaceholders = [];
287
+ let maskedStr = wrappedStr.replace(locatorRegex, (match, p1, p2) => {
288
+ locatorPlaceholders.push(`"${p2.trim()}"`);
289
+ return `${p1}__LOCATOR_PLACEHOLDER_${locatorPlaceholders.length - 1}__`;
290
+ });
291
+ maskedStr = maskedStr.replace(/:\s*'((?:[^']|\\')*)'/g, (match, p1) => {
292
+ return `: "${p1}"`;
293
+ });
294
+ let normalized = maskedStr
295
+ .replace(/([{,]\s*)([a-zA-Z0-9_]+)\s*:/g, '$1"$2":')
296
+ .replace(/:\s*True\b/g, ": true")
297
+ .replace(/:\s*False\b/g, ": false")
298
+ .replace(/:\s*None\b/g, ": null")
299
+ .replace(/,(\s*[}\]])/g, "$1");
300
+ locatorPlaceholders.forEach((value, index) => {
301
+ normalized = normalized.replace(`__LOCATOR_PLACEHOLDER_${index}__`, value);
302
+ });
303
+ return JSON.parse(normalized);
304
+ }
305
+ catch (err) {
306
+ throw new Error(`❌ Failed to parse options string: "${str}". Error: ${err.message}`);
307
+ }
308
+ }
309
+ function loadDefaults() {
310
+ try {
311
+ // defaultEntries sits next to this file; load it relatively to avoid env/path issues
312
+ const { default: defaultEntries } = require('./defaultEntries');
313
+ if (Array.isArray(defaultEntries)) {
314
+ defaultEntries.forEach((item) => {
315
+ let value = getValue('env.' + item.name, true) ? getValue('env.' + item.name) : (getValue(item.name, true) ? getValue(item.name) : item.value);
316
+ setValue(item.name, value);
317
+ });
318
+ }
319
+ }
320
+ catch (error) {
321
+ console.warn('Warning: Could not load default entries:', error.message);
322
+ }
323
+ }
324
+ function initVars(vars) {
325
+ try {
326
+ // Load config with error handling
327
+ let configEntries = {};
328
+ try {
329
+ const importConfigBase = path.resolve(process.env.PLAYQ_PROJECT_ROOT, 'resources/config');
330
+ const importConfigPath = resolveModulePath(importConfigBase);
331
+ console.log('🔎 [core] Requiring config from:', importConfigPath);
332
+ const configModule = require(importConfigPath);
333
+ configEntries = configModule.config || configModule.default || {};
334
+ }
335
+ catch (error) {
336
+ console.warn('Warning: Could not load config file, using empty config');
337
+ }
338
+ // Load static variables preferring resources/var.static.json
339
+ let variablesEntries = {};
340
+ const varStaticPath = path.resolve(process.env.PLAYQ_PROJECT_ROOT, 'resources/var.static.json');
341
+ if (fs.existsSync(varStaticPath)) {
342
+ try {
343
+ console.log('🔎 [core] Loading var.static.json:', varStaticPath);
344
+ const fileContent = fs.readFileSync(varStaticPath, 'utf-8');
345
+ variablesEntries = JSON.parse(fileContent) || {};
346
+ }
347
+ catch (error) {
348
+ console.warn('Warning: Could not parse var.static.json, using empty variables:', error.message);
349
+ }
350
+ }
351
+ else {
352
+ // Fallback to legacy resources/variable module if present
353
+ try {
354
+ const importVariableBase = path.resolve(process.env.PLAYQ_PROJECT_ROOT, 'resources/variable');
355
+ const importVariablePath = resolveModulePath(importVariableBase);
356
+ console.log('🔎 [core] Requiring legacy variable module from:', importVariablePath);
357
+ const variableModule = require(importVariablePath);
358
+ variablesEntries = variableModule.var_static || variableModule.default || {};
359
+ }
360
+ catch (error) {
361
+ console.warn('Warning: Could not load variable file (var.static.json or legacy module), using empty variables');
362
+ }
363
+ }
364
+ if (vars) {
365
+ Object.assign(storedVars, vars);
366
+ }
367
+ Object.assign(storedVars, flattenConfig(variablesEntries, "var.static"));
368
+ Object.assign(storedVars, flattenConfig(configEntries, "config"));
369
+ loadPatternEntries();
370
+ loadDefaults();
371
+ }
372
+ catch (error) {
373
+ console.error('Error initializing vars:', error.message);
374
+ }
375
+ }
@@ -0,0 +1,55 @@
1
+ import { faker as baseFaker } from '@faker-js/faker';
2
+ export declare const faker: typeof baseFaker & {
3
+ custom: {
4
+ passport: (options?: {
5
+ countryCode?: string;
6
+ }) => string;
7
+ mobile: {
8
+ number: (options?: {
9
+ countryCode?: string;
10
+ dialCodePrefix?: boolean;
11
+ }) => string;
12
+ };
13
+ postcode: {
14
+ get: (options?: {
15
+ countryCode?: string;
16
+ stateCode?: string;
17
+ }) => string;
18
+ };
19
+ person: {
20
+ fullName: (options?: {
21
+ gender?: "male" | "female";
22
+ withPrefix?: boolean;
23
+ maxLength?: number;
24
+ }) => string;
25
+ birthDate: (options?: {
26
+ min?: number;
27
+ max?: number;
28
+ year?: number;
29
+ format?: "DD-MM-YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD" | "DD/MM/YYYY" | "MM/DD/YYYY" | "YYYY/MM/DD" | "DD-MM-YY" | "MM-DD-YY" | "YY-MM-DD" | "DD/MM/YY" | "MM/DD/YY" | "YY/MM/DD";
30
+ }) => string;
31
+ };
32
+ nric: {
33
+ generate: (options?: {
34
+ prefix?: "S" | "T" | "F" | "G";
35
+ yearOfBirth?: number;
36
+ }) => string;
37
+ getYear: (nric: string) => string;
38
+ };
39
+ datetime: {
40
+ /**
41
+ *
42
+ * @param options Eg: {'format': 'DD/MM/YYYY HH:mm:ss'}, {'format': 'YY-MM-DD HH.mm'}
43
+ * @returns
44
+ */
45
+ generateCurrentDateTime: (options?: {
46
+ format?: string;
47
+ }) => string;
48
+ addMonthsToDate: (dateStr: string, months: number | string, options?: {
49
+ inputFormat?: "DD-MM-YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD" | "DD/MM/YYYY" | "MM/DD/YYYY" | "YYYY/MM/DD" | "DD-MM-YY" | "MM-DD-YY" | "YY-MM-DD" | "DD/MM/YY" | "MM/DD/YY" | "YY/MM/DD";
50
+ outputFormat?: "DD-MM-YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD" | "DD/MM/YYYY" | "MM/DD/YYYY" | "YYYY/MM/DD" | "DD-MM-YY" | "MM-DD-YY" | "YY-MM-DD" | "DD/MM/YY" | "MM/DD/YY" | "YY/MM/DD";
51
+ clampToLastDayOfMonth?: boolean;
52
+ }) => string;
53
+ };
54
+ };
55
+ };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.faker = void 0;
4
+ // src/helper/faker/customFaker.ts
5
+ const faker_1 = require("@faker-js/faker");
6
+ const passport_1 = require("./modules/passport");
7
+ const mobile_1 = require("./modules/mobile");
8
+ const postcode_1 = require("./modules/postcode");
9
+ const person_1 = require("./modules/person");
10
+ const nric_1 = require("./modules/nric");
11
+ const dateTime_1 = require("./modules/dateTime");
12
+ faker_1.faker.custom = {
13
+ passport: passport_1.generatePassportNumber,
14
+ mobile: {
15
+ number: mobile_1.generateMobileNumber
16
+ },
17
+ postcode: {
18
+ get: postcode_1.getValidPostCode
19
+ },
20
+ person: {
21
+ fullName: person_1.generatePersonFullName,
22
+ birthDate: person_1.generateBirthDate
23
+ },
24
+ nric: {
25
+ generate: nric_1.generateNRIC,
26
+ getYear: nric_1.getYearFromNRIC
27
+ },
28
+ datetime: {
29
+ generateCurrentDateTime: dateTime_1.generateCurrentDateTime,
30
+ addMonthsToDate: dateTime_1.addMonthsToDate
31
+ }
32
+ };
33
+ exports.faker = faker_1.faker;
34
+ // // src/helper/faker/customFaker.ts
35
+ // import { faker as baseFaker } from '@faker-js/faker';
36
+ // import { generatePassportNumber } from './modules/passport';
37
+ // import { generateMobileNumber } from './modules/mobile';
38
+ // (baseFaker as any).passport = {
39
+ // number: generatePassportNumber
40
+ // };
41
+ // export const faker = baseFaker as typeof baseFaker & {
42
+ // passport: {
43
+ // number: (countryCode?: string) => string;
44
+ // };
45
+ // };
@@ -0,0 +1,17 @@
1
+ [
2
+ "018937", "049318", "049320", "049712", "059819", "068808", "078867", "089680",
3
+ "098585", "138632", "169208", "178957", "179097", "179098", "188021", "189559",
4
+ "199588", "238882", "238883", "238884", "238885", "238887", "238888",
5
+ "259569", "259571", "259772", "259775", "259776", "259778", "259779",
6
+ "269713", "269716", "269717", "269719", "269720", "269722", "269725", "269726",
7
+ "279116", "279118", "279119", "279121", "279122", "279124", "279125", "279126",
8
+ "307987", "308232", "308275", "308276", "308278", "339511",
9
+ "408600", "408601", "408604", "408605", "408606", "408607",
10
+ "469976", "469977", "469978", "469979", "469980", "469981", "469982", "469983",
11
+ "499936", "499938", "499939", "499941", "499942", "499943",
12
+ "568020", "568021", "568022", "568023", "568024", "568025", "568026", "568027",
13
+ "579799", "579800", "579801", "579804", "579806",
14
+ "608545", "608546", "608547", "608548", "608549", "608550", "608551", "608552",
15
+ "757869", "757870", "757871", "757872", "757873", "757874", "757875", "757876",
16
+ "819642", "819643", "819645", "819646", "819647", "819648", "819649"
17
+ ]
@@ -0,0 +1,18 @@
1
+ interface CurrentDateTimeOptions {
2
+ format?: string;
3
+ }
4
+ export declare function generateCurrentDateTime(options?: CurrentDateTimeOptions): string;
5
+ interface AddMonthsOptions {
6
+ inputFormat?: 'DD-MM-YYYY' | 'MM-DD-YYYY' | 'YYYY-MM-DD' | 'DD/MM/YYYY' | 'MM/DD/YYYY' | 'YYYY/MM/DD' | 'DD-MM-YY' | 'MM-DD-YY' | 'YY-MM-DD' | 'DD/MM/YY' | 'MM/DD/YY' | 'YY/MM/DD';
7
+ outputFormat?: 'DD-MM-YYYY' | 'MM-DD-YYYY' | 'YYYY-MM-DD' | 'DD/MM/YYYY' | 'MM/DD/YYYY' | 'YYYY/MM/DD' | 'DD-MM-YY' | 'MM-DD-YY' | 'YY-MM-DD' | 'DD/MM/YY' | 'MM/DD/YY' | 'YY/MM/DD';
8
+ clampToLastDayOfMonth?: boolean;
9
+ }
10
+ export declare function addMonthsToDate(dateStr: string, months: number | string, options?: AddMonthsOptions): string;
11
+ /**
12
+ * Removes leading zeros from both the day and month in a date string of format DD/MM/YYYY.
13
+ * Example: '03/07/2025' => '3/7/2025'
14
+ * @param dateStr - The date string in DD/MM/YYYY format
15
+ * @returns The date string with leading zeros removed from day and month
16
+ */
17
+ export declare function removeLeadingZeroFromMonthAndDate(dateStr: string): string;
18
+ export {};
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCurrentDateTime = generateCurrentDateTime;
4
+ exports.addMonthsToDate = addMonthsToDate;
5
+ exports.removeLeadingZeroFromMonthAndDate = removeLeadingZeroFromMonthAndDate;
6
+ function generateCurrentDateTime(options = {}) {
7
+ const { format = 'DD-MM-YYYY HH:mm:ss' } = options;
8
+ const date = new Date();
9
+ const dd = String(date.getDate()).padStart(2, '0');
10
+ const mm = String(date.getMonth() + 1).padStart(2, '0');
11
+ const yyyy = date.getFullYear();
12
+ const yy = String(yyyy).slice(-2);
13
+ const hh = String(date.getHours()).padStart(2, '0');
14
+ const min = String(date.getMinutes()).padStart(2, '0');
15
+ const ss = String(date.getSeconds()).padStart(2, '0');
16
+ // Replace tokens in format string
17
+ let result = format;
18
+ result = result.replace(/DD/g, dd)
19
+ .replace(/MM/g, mm)
20
+ .replace(/YYYY/g, String(yyyy))
21
+ .replace(/YY/g, yy)
22
+ .replace(/HH/g, hh)
23
+ .replace(/mm/g, min)
24
+ .replace(/ss/g, ss);
25
+ return result;
26
+ }
27
+ function parseDate(dateStr, format) {
28
+ const sep = format.includes('/') ? '/' : '-';
29
+ const parts = dateStr.split(sep);
30
+ let day = 1, month = 0, year = 1970;
31
+ switch (format) {
32
+ case 'DD-MM-YYYY':
33
+ case 'DD/MM/YYYY':
34
+ [day, month, year] = [parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2])];
35
+ break;
36
+ case 'MM-DD-YYYY':
37
+ case 'MM/DD/YYYY':
38
+ [month, day, year] = [parseInt(parts[0]) - 1, parseInt(parts[1]), parseInt(parts[2])];
39
+ break;
40
+ case 'YYYY-MM-DD':
41
+ case 'YYYY/MM/DD':
42
+ [year, month, day] = [parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2])];
43
+ break;
44
+ case 'DD-MM-YY':
45
+ case 'DD/MM/YY':
46
+ [day, month, year] = [parseInt(parts[0]), parseInt(parts[1]) - 1, 2000 + parseInt(parts[2])];
47
+ break;
48
+ case 'MM-DD-YY':
49
+ case 'MM/DD/YY':
50
+ [month, day, year] = [parseInt(parts[0]) - 1, parseInt(parts[1]), 2000 + parseInt(parts[2])];
51
+ break;
52
+ case 'YY-MM-DD':
53
+ case 'YY/MM/DD':
54
+ [year, month, day] = [2000 + parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2])];
55
+ break;
56
+ default:
57
+ throw new Error('Unsupported input format');
58
+ }
59
+ return new Date(year, month, day);
60
+ }
61
+ function formatDate(date, format) {
62
+ const dd = String(date.getDate()).padStart(2, '0');
63
+ const mm = String(date.getMonth() + 1).padStart(2, '0');
64
+ const yyyy = date.getFullYear();
65
+ const yy = String(yyyy).slice(-2);
66
+ switch (format) {
67
+ case 'YYYY-MM-DD': return `${yyyy}-${mm}-${dd}`;
68
+ case 'YYYY/MM/DD': return `${yyyy}/${mm}/${dd}`;
69
+ case 'MM-DD-YYYY': return `${mm}-${dd}-${yyyy}`;
70
+ case 'MM/DD/YYYY': return `${mm}/${dd}/${yyyy}`;
71
+ case 'DD/MM/YYYY': return `${dd}/${mm}/${yyyy}`;
72
+ case 'DD-MM-YYYY': return `${dd}-${mm}-${yyyy}`;
73
+ case 'DD-MM-YY': return `${dd}-${mm}-${yy}`;
74
+ case 'MM-DD-YY': return `${mm}-${dd}-${yy}`;
75
+ case 'YY-MM-DD': return `${yy}-${mm}-${dd}`;
76
+ case 'DD/MM/YY': return `${dd}/${mm}/${yy}`;
77
+ case 'MM/DD/YY': return `${mm}/${dd}/${yy}`;
78
+ case 'YY/MM/DD': return `${yy}/${mm}/${dd}`;
79
+ default: return `${dd}/${mm}/${yy}`;
80
+ }
81
+ }
82
+ function getLastDayOfMonth(year, month) {
83
+ return new Date(year, month + 1, 0).getDate();
84
+ }
85
+ function addMonthsToDate(dateStr, months, options = {}) {
86
+ const inputFormat = options.inputFormat || 'DD-MM-YY';
87
+ const outputFormat = options.outputFormat || 'DD-MM-YY';
88
+ const clamp = options.clampToLastDayOfMonth || false;
89
+ const date = parseDate(dateStr, inputFormat);
90
+ const originalDay = date.getDate();
91
+ const monthsNum = typeof months === 'string' ? parseInt(months, 10) : months;
92
+ date.setMonth(date.getMonth() + monthsNum);
93
+ if (clamp && date.getDate() !== originalDay) {
94
+ date.setDate(0);
95
+ }
96
+ return formatDate(date, outputFormat);
97
+ }
98
+ /**
99
+ * Removes leading zeros from both the day and month in a date string of format DD/MM/YYYY.
100
+ * Example: '03/07/2025' => '3/7/2025'
101
+ * @param dateStr - The date string in DD/MM/YYYY format
102
+ * @returns The date string with leading zeros removed from day and month
103
+ */
104
+ function removeLeadingZeroFromMonthAndDate(dateStr) {
105
+ return dateStr.replace(/\b0(\d)/g, "$1");
106
+ }
@@ -0,0 +1,4 @@
1
+ export declare function generateMobileNumber(options?: {
2
+ countryCode?: string;
3
+ dialCodePrefix?: boolean;
4
+ }): string;