@bigbinary/neeto-playwright-commons 3.3.12 → 3.3.13

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
@@ -1129,6 +1129,30 @@ const generateStagingData = (product = "invoice") => {
1129
1129
  email,
1130
1130
  };
1131
1131
  };
1132
+ const DEFAULT_STAGING_ORGANIZATION_TTL_IN_DAYS = 3;
1133
+ const getStagingOrganizationTtlInDays = () => {
1134
+ const ttl = Number(process.env.STAGING_ORGANIZATION_TTL_IN_DAYS);
1135
+ return Number.isFinite(ttl) && ttl > 0
1136
+ ? ttl
1137
+ : DEFAULT_STAGING_ORGANIZATION_TTL_IN_DAYS;
1138
+ };
1139
+ const isStagingOrganizationExpired = (subdomainName) => {
1140
+ if (!subdomainName?.startsWith("cpt"))
1141
+ return false;
1142
+ const match = subdomainName.match(/-(\d{2})(\d{2})-(\d{2})(\d{2})-(\d{2})(\d{3})(?:-\d+)?$/);
1143
+ if (!match)
1144
+ return false;
1145
+ const [, day, month, hour, minute, second, millisecond] = match;
1146
+ const now = dayjs();
1147
+ // The subdomain timestamp does not include a year, so assume the current year.
1148
+ // If that places the creation date in the future, it was created last year.
1149
+ let createdAt = dayjs(`${now.year()}-${month}-${day}T${hour}:${minute}:${second}.${millisecond}`);
1150
+ if (!createdAt.isValid())
1151
+ return false;
1152
+ if (createdAt.isAfter(now))
1153
+ createdAt = createdAt.subtract(1, "year");
1154
+ return now.diff(createdAt, "day") >= getStagingOrganizationTtlInDays();
1155
+ };
1132
1156
 
1133
1157
  const execCommand = (command) => child_process.execSync(command)
1134
1158
  .toString("utf-8")
@@ -1163,11 +1187,12 @@ const updateCredentials = ({ key, value }) => {
1163
1187
  return writeDataToFile(JSON.stringify(data));
1164
1188
  };
1165
1189
  const removeCredentialFile = () => {
1166
- fs__namespace.unlink(STORAGE_STATE, error => {
1167
- if (!error)
1168
- return;
1190
+ try {
1191
+ fs__namespace.existsSync(STORAGE_STATE) && fs__namespace.unlinkSync(STORAGE_STATE);
1192
+ }
1193
+ catch (error) {
1169
1194
  console.log(error);
1170
- });
1195
+ }
1171
1196
  };
1172
1197
  const clearCredentials = () => {
1173
1198
  if (shouldSkipSetupAndTeardown())
@@ -122649,11 +122674,11 @@ const initializeCredentials = (product) => {
122649
122674
  }
122650
122675
  readFileSyncIfExists();
122651
122676
  }
122677
+ isStagingOrganizationExpired(getGlobalUserState()?.subdomainName) &&
122678
+ removeCredentialFile();
122652
122679
  const skipSetup = shouldSkipSetupAndTeardown();
122653
122680
  if (skipSetup) {
122654
- if (IS_STAGING_ENV) {
122655
- process.env.BASE_URL = getGlobalUserState()?.baseUrl;
122656
- }
122681
+ IS_STAGING_ENV && (process.env.BASE_URL = getGlobalUserState()?.baseUrl);
122657
122682
  return;
122658
122683
  }
122659
122684
  const stagingData = generateStagingData(product);
@@ -127326,6 +127351,7 @@ exports.initializeCredentials = initializeCredentials;
127326
127351
  exports.initializeTestData = initializeTestData;
127327
127352
  exports.initializeTotp = initializeTotp;
127328
127353
  exports.isGithubIssueOpen = isGithubIssueOpen;
127354
+ exports.isStagingOrganizationExpired = isStagingOrganizationExpired;
127329
127355
  exports.joinHyphenCase = joinHyphenCase;
127330
127356
  exports.joinString = joinString;
127331
127357
  exports.login = login;