@bigbinary/neeto-playwright-commons 3.1.0 → 3.1.2

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.
package/index.cjs.js CHANGED
@@ -60529,7 +60529,7 @@ class RailsEmailUtils {
60529
60529
  });
60530
60530
  return otp || undefined;
60531
60531
  };
60532
- getEmailAttachment = async (attachmentName, messageSearchCriteria = {}, { receivedAfter = new Date(new Date().valueOf() - 60 * 60 * 1000), expectedEmailCount = 1, timeout = 10_000, } = {}, shouldThrowErrorOnTimeout = true) => {
60532
+ getEmailAttachment = async ({ name, type }, messageSearchCriteria = {}, { receivedAfter = new Date(new Date().valueOf() - 60 * 60 * 1000), expectedEmailCount = 1, timeout = 10_000, } = {}, shouldThrowErrorOnTimeout = true) => {
60533
60533
  const attachmentDetails = (await this.neetoPlaywrightUtilities.executeRecursively({
60534
60534
  callback: async () => {
60535
60535
  const railsEmail = await this.railsEmailClient.getLatestEmail({
@@ -60538,7 +60538,11 @@ class RailsEmailUtils {
60538
60538
  });
60539
60539
  if (!railsEmail)
60540
60540
  return null;
60541
- const attachment = railsEmail.attachments?.find(att => att.name.includes(attachmentName));
60541
+ const attachment = railsEmail.attachments?.find(att => {
60542
+ const matchesName = name ? att.name?.includes(name) : true;
60543
+ const matchesType = type ? att.type?.startsWith(type) : true;
60544
+ return matchesName && matchesType;
60545
+ });
60542
60546
  if (!attachment)
60543
60547
  return null;
60544
60548
  return {
@@ -60722,19 +60726,26 @@ class MailerUtils {
60722
60726
  return codes?.[0];
60723
60727
  };
60724
60728
  generateRandomEmail = () => faker.faker.internet.email({ provider: process.env.FASTMAIL_DOMAIN_NAME });
60725
- getEmailAttachment = async (attachmentName, messageSearchCriteria = {}, { timeout = 10_000, receivedAfter = dateTimeOneHourAgo(), expectedEmailCount = 1, } = {}, shouldThrowErrorOnTimeout = true) => {
60726
- if (IS_DEV_ENV) {
60727
- return this.railsEmailUtils.getEmailAttachment(attachmentName, messageSearchCriteria, { receivedAfter, expectedEmailCount, timeout: timeout / 3 }, shouldThrowErrorOnTimeout);
60728
- }
60729
+ getEmailAttachment = async ({ name, type }, messageSearchCriteria = {}, { timeout = 10_000, receivedAfter = dateTimeOneHourAgo(), expectedEmailCount = 1, } = {}, shouldThrowErrorOnTimeout = true) => {
60730
+ if (IS_DEV_ENV)
60731
+ return this.railsEmailUtils.getEmailAttachment({ name, type }, messageSearchCriteria, { receivedAfter, expectedEmailCount, timeout: timeout / 3 }, shouldThrowErrorOnTimeout);
60729
60732
  const { blobId, attachments: attachmentNameAndTypes } = await this.findMessage(messageSearchCriteria, { expectedEmailCount, receivedAfter, timeout }, shouldThrowErrorOnTimeout);
60730
- const attachment = attachmentNameAndTypes.find(attachment => attachment.name.includes(attachmentName));
60733
+ const attachment = attachmentNameAndTypes.find(att => {
60734
+ const matchesName = name ? att.name?.includes(name) : true;
60735
+ const matchesType = type ? att.type?.startsWith(type) : true;
60736
+ return matchesName && matchesType;
60737
+ });
60731
60738
  if (!attachment)
60732
60739
  throw new Error("No such attachment exists");
60733
60740
  const emailAttachment = await this.fastmailApi.fetchAttachments(blobId, attachment.name);
60734
60741
  const buffer = await emailAttachment.body();
60735
60742
  const parsedEmail = await mailparserExports.simpleParser(buffer);
60736
60743
  const attachments = parsedEmail.attachments;
60737
- return attachments.find(attachment => attachment.filename.includes(attachmentName));
60744
+ return attachments.find(att => {
60745
+ const matchesName = name ? att.filename?.includes(name) : true;
60746
+ const matchesType = type ? att.contentType?.startsWith(type) : true;
60747
+ return matchesName && matchesType;
60748
+ });
60738
60749
  };
60739
60750
  }
60740
60751
 
@@ -111485,6 +111496,8 @@ function requireConstants$1 () {
111485
111496
  const WIN_SLASH = '\\\\/';
111486
111497
  const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
111487
111498
 
111499
+ const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
111500
+
111488
111501
  /**
111489
111502
  * Posix glob regex
111490
111503
  */
@@ -111548,6 +111561,7 @@ function requireConstants$1 () {
111548
111561
  */
111549
111562
 
111550
111563
  const POSIX_REGEX_SOURCE = {
111564
+ __proto__: null,
111551
111565
  alnum: 'a-zA-Z0-9',
111552
111566
  alpha: 'a-zA-Z',
111553
111567
  ascii: '\\x00-\\x7F',
@@ -111565,6 +111579,7 @@ function requireConstants$1 () {
111565
111579
  };
111566
111580
 
111567
111581
  constants$1 = {
111582
+ DEFAULT_MAX_EXTGLOB_RECURSION,
111568
111583
  MAX_LENGTH: 1024 * 64,
111569
111584
  POSIX_REGEX_SOURCE,
111570
111585
 
@@ -111578,6 +111593,7 @@ function requireConstants$1 () {
111578
111593
 
111579
111594
  // Replace globs with equivalent patterns to reduce parsing time.
111580
111595
  REPLACEMENTS: {
111596
+ __proto__: null,
111581
111597
  '***': '*',
111582
111598
  '**/**': '**',
111583
111599
  '**/**/**': '**'
@@ -112185,6 +112201,277 @@ function requireParse () {
112185
112201
  return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
112186
112202
  };
112187
112203
 
112204
+ const splitTopLevel = input => {
112205
+ const parts = [];
112206
+ let bracket = 0;
112207
+ let paren = 0;
112208
+ let quote = 0;
112209
+ let value = '';
112210
+ let escaped = false;
112211
+
112212
+ for (const ch of input) {
112213
+ if (escaped === true) {
112214
+ value += ch;
112215
+ escaped = false;
112216
+ continue;
112217
+ }
112218
+
112219
+ if (ch === '\\') {
112220
+ value += ch;
112221
+ escaped = true;
112222
+ continue;
112223
+ }
112224
+
112225
+ if (ch === '"') {
112226
+ quote = quote === 1 ? 0 : 1;
112227
+ value += ch;
112228
+ continue;
112229
+ }
112230
+
112231
+ if (quote === 0) {
112232
+ if (ch === '[') {
112233
+ bracket++;
112234
+ } else if (ch === ']' && bracket > 0) {
112235
+ bracket--;
112236
+ } else if (bracket === 0) {
112237
+ if (ch === '(') {
112238
+ paren++;
112239
+ } else if (ch === ')' && paren > 0) {
112240
+ paren--;
112241
+ } else if (ch === '|' && paren === 0) {
112242
+ parts.push(value);
112243
+ value = '';
112244
+ continue;
112245
+ }
112246
+ }
112247
+ }
112248
+
112249
+ value += ch;
112250
+ }
112251
+
112252
+ parts.push(value);
112253
+ return parts;
112254
+ };
112255
+
112256
+ const isPlainBranch = branch => {
112257
+ let escaped = false;
112258
+
112259
+ for (const ch of branch) {
112260
+ if (escaped === true) {
112261
+ escaped = false;
112262
+ continue;
112263
+ }
112264
+
112265
+ if (ch === '\\') {
112266
+ escaped = true;
112267
+ continue;
112268
+ }
112269
+
112270
+ if (/[?*+@!()[\]{}]/.test(ch)) {
112271
+ return false;
112272
+ }
112273
+ }
112274
+
112275
+ return true;
112276
+ };
112277
+
112278
+ const normalizeSimpleBranch = branch => {
112279
+ let value = branch.trim();
112280
+ let changed = true;
112281
+
112282
+ while (changed === true) {
112283
+ changed = false;
112284
+
112285
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
112286
+ value = value.slice(2, -1);
112287
+ changed = true;
112288
+ }
112289
+ }
112290
+
112291
+ if (!isPlainBranch(value)) {
112292
+ return;
112293
+ }
112294
+
112295
+ return value.replace(/\\(.)/g, '$1');
112296
+ };
112297
+
112298
+ const hasRepeatedCharPrefixOverlap = branches => {
112299
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
112300
+
112301
+ for (let i = 0; i < values.length; i++) {
112302
+ for (let j = i + 1; j < values.length; j++) {
112303
+ const a = values[i];
112304
+ const b = values[j];
112305
+ const char = a[0];
112306
+
112307
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
112308
+ continue;
112309
+ }
112310
+
112311
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
112312
+ return true;
112313
+ }
112314
+ }
112315
+ }
112316
+
112317
+ return false;
112318
+ };
112319
+
112320
+ const parseRepeatedExtglob = (pattern, requireEnd = true) => {
112321
+ if ((pattern[0] !== '+' && pattern[0] !== '*') || pattern[1] !== '(') {
112322
+ return;
112323
+ }
112324
+
112325
+ let bracket = 0;
112326
+ let paren = 0;
112327
+ let quote = 0;
112328
+ let escaped = false;
112329
+
112330
+ for (let i = 1; i < pattern.length; i++) {
112331
+ const ch = pattern[i];
112332
+
112333
+ if (escaped === true) {
112334
+ escaped = false;
112335
+ continue;
112336
+ }
112337
+
112338
+ if (ch === '\\') {
112339
+ escaped = true;
112340
+ continue;
112341
+ }
112342
+
112343
+ if (ch === '"') {
112344
+ quote = quote === 1 ? 0 : 1;
112345
+ continue;
112346
+ }
112347
+
112348
+ if (quote === 1) {
112349
+ continue;
112350
+ }
112351
+
112352
+ if (ch === '[') {
112353
+ bracket++;
112354
+ continue;
112355
+ }
112356
+
112357
+ if (ch === ']' && bracket > 0) {
112358
+ bracket--;
112359
+ continue;
112360
+ }
112361
+
112362
+ if (bracket > 0) {
112363
+ continue;
112364
+ }
112365
+
112366
+ if (ch === '(') {
112367
+ paren++;
112368
+ continue;
112369
+ }
112370
+
112371
+ if (ch === ')') {
112372
+ paren--;
112373
+
112374
+ if (paren === 0) {
112375
+ if (requireEnd === true && i !== pattern.length - 1) {
112376
+ return;
112377
+ }
112378
+
112379
+ return {
112380
+ type: pattern[0],
112381
+ body: pattern.slice(2, i),
112382
+ end: i
112383
+ };
112384
+ }
112385
+ }
112386
+ }
112387
+ };
112388
+
112389
+ const getStarExtglobSequenceOutput = pattern => {
112390
+ let index = 0;
112391
+ const chars = [];
112392
+
112393
+ while (index < pattern.length) {
112394
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
112395
+
112396
+ if (!match || match.type !== '*') {
112397
+ return;
112398
+ }
112399
+
112400
+ const branches = splitTopLevel(match.body).map(branch => branch.trim());
112401
+ if (branches.length !== 1) {
112402
+ return;
112403
+ }
112404
+
112405
+ const branch = normalizeSimpleBranch(branches[0]);
112406
+ if (!branch || branch.length !== 1) {
112407
+ return;
112408
+ }
112409
+
112410
+ chars.push(branch);
112411
+ index += match.end + 1;
112412
+ }
112413
+
112414
+ if (chars.length < 1) {
112415
+ return;
112416
+ }
112417
+
112418
+ const source = chars.length === 1
112419
+ ? utils.escapeRegex(chars[0])
112420
+ : `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
112421
+
112422
+ return `${source}*`;
112423
+ };
112424
+
112425
+ const repeatedExtglobRecursion = pattern => {
112426
+ let depth = 0;
112427
+ let value = pattern.trim();
112428
+ let match = parseRepeatedExtglob(value);
112429
+
112430
+ while (match) {
112431
+ depth++;
112432
+ value = match.body.trim();
112433
+ match = parseRepeatedExtglob(value);
112434
+ }
112435
+
112436
+ return depth;
112437
+ };
112438
+
112439
+ const analyzeRepeatedExtglob = (body, options) => {
112440
+ if (options.maxExtglobRecursion === false) {
112441
+ return { risky: false };
112442
+ }
112443
+
112444
+ const max =
112445
+ typeof options.maxExtglobRecursion === 'number'
112446
+ ? options.maxExtglobRecursion
112447
+ : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
112448
+
112449
+ const branches = splitTopLevel(body).map(branch => branch.trim());
112450
+
112451
+ if (branches.length > 1) {
112452
+ if (
112453
+ branches.some(branch => branch === '') ||
112454
+ branches.some(branch => /^[*?]+$/.test(branch)) ||
112455
+ hasRepeatedCharPrefixOverlap(branches)
112456
+ ) {
112457
+ return { risky: true };
112458
+ }
112459
+ }
112460
+
112461
+ for (const branch of branches) {
112462
+ const safeOutput = getStarExtglobSequenceOutput(branch);
112463
+ if (safeOutput) {
112464
+ return { risky: true, safeOutput };
112465
+ }
112466
+
112467
+ if (repeatedExtglobRecursion(branch) > max) {
112468
+ return { risky: true };
112469
+ }
112470
+ }
112471
+
112472
+ return { risky: false };
112473
+ };
112474
+
112188
112475
  /**
112189
112476
  * Parse the given input string.
112190
112477
  * @param {String} input
@@ -112366,6 +112653,8 @@ function requireParse () {
112366
112653
  token.prev = prev;
112367
112654
  token.parens = state.parens;
112368
112655
  token.output = state.output;
112656
+ token.startIndex = state.index;
112657
+ token.tokensIndex = tokens.length;
112369
112658
  const output = (opts.capture ? '(' : '') + token.open;
112370
112659
 
112371
112660
  increment('parens');
@@ -112375,6 +112664,34 @@ function requireParse () {
112375
112664
  };
112376
112665
 
112377
112666
  const extglobClose = token => {
112667
+ const literal = input.slice(token.startIndex, state.index + 1);
112668
+ const body = input.slice(token.startIndex + 2, state.index);
112669
+ const analysis = analyzeRepeatedExtglob(body, opts);
112670
+
112671
+ if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
112672
+ const safeOutput = analysis.safeOutput
112673
+ ? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput)
112674
+ : undefined;
112675
+ const open = tokens[token.tokensIndex];
112676
+
112677
+ open.type = 'text';
112678
+ open.value = literal;
112679
+ open.output = safeOutput || utils.escapeRegex(literal);
112680
+
112681
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
112682
+ tokens[i].value = '';
112683
+ tokens[i].output = '';
112684
+ delete tokens[i].suffix;
112685
+ }
112686
+
112687
+ state.output = token.output + open.output;
112688
+ state.backtrack = true;
112689
+
112690
+ push({ type: 'paren', extglob: true, value, output: '' });
112691
+ decrement('parens');
112692
+ return;
112693
+ }
112694
+
112378
112695
  let output = token.close + (opts.capture ? ')' : '');
112379
112696
  let rest;
112380
112697