verant_id_cloud_scan 1.4.5-beta.4 → 1.4.5-beta.5

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/Api.js CHANGED
@@ -4,47 +4,87 @@ import { FIELD_MAPPING, FIELD_DEFAULTS, getFieldValue } from "./FieldMapping.js"
4
4
  import { sanitizeFieldForDmv } from "./FormatUtils.js";
5
5
 
6
6
  /**
7
- * Environment Detection
7
+ * Environment Detection & Management
8
8
  *
9
- * Automatically detects staging vs production based on hostname.
10
- * Defaults to PRODUCTION for backwards compatibility with existing customers.
11
- * Only switches to staging for VerantID's own staging domains.
9
+ * Defaults to PRODUCTION for all hosts (including localhost).
10
+ * Only verify-staging.verantid.com automatically uses staging.
11
+ * Host apps can explicitly override via setEnvironment('staging' | 'production').
12
12
  */
13
- function getEnvironment() {
14
- // Default to production for safety and backwards compatibility
13
+
14
+ // Current environment - starts as null to trigger detection on first use
15
+ let currentEnvironment = null;
16
+
17
+ /**
18
+ * Detect environment based on hostname
19
+ * @returns {'staging' | 'production'}
20
+ */
21
+ function detectEnvironment() {
22
+ // Default to production for all hosts
15
23
  let environment = 'production';
16
24
 
17
- // Only override to staging if explicitly on a VerantID staging domain
25
+ // Only auto-switch to staging for VerantID's staging domain
18
26
  if (typeof window !== 'undefined') {
19
27
  const hostname = window.location.hostname;
20
28
 
21
- // ONLY switch to staging for VerantID's own staging domains
22
- if (hostname === 'verify-staging.verantid.com' ||
23
- hostname === 'localhost' ||
24
- hostname === '127.0.0.1' ||
25
- hostname.startsWith('localhost:')) {
29
+ // ONLY verify-staging.verantid.com uses staging by default
30
+ if (hostname === 'verify-staging.verantid.com') {
26
31
  environment = 'staging';
27
32
  }
28
33
 
29
- // All other hostnames (customer sites, verify.verantid.com, etc.) use production
34
+ // All other hostnames (localhost, customer sites, verify.verantid.com, etc.) use production
30
35
  }
31
36
 
32
37
  console.log('[CloudScan] Environment detected:', environment, 'on', typeof window !== 'undefined' ? window.location.hostname : 'server');
33
38
  return environment;
34
39
  }
35
40
 
36
- const env = getEnvironment();
41
+ /**
42
+ * Get current environment (detects if not already set)
43
+ * @returns {'staging' | 'production'}
44
+ */
45
+ function getEnvironment() {
46
+ if (currentEnvironment === null) {
47
+ currentEnvironment = detectEnvironment();
48
+ }
49
+ return currentEnvironment;
50
+ }
37
51
 
38
- const licenseServerAddress = env === 'staging'
39
- ? "https://lic-staging.verantid.com/api/v1"
40
- : "https://lic.verantid.com/api/v1";
52
+ /**
53
+ * Explicitly set the environment
54
+ * @param {'staging' | 'production'} environment
55
+ * @throws {Error} If environment is not 'staging' or 'production'
56
+ */
57
+ export function setEnvironment(environment) {
58
+ if (environment !== 'staging' && environment !== 'production') {
59
+ throw new Error(`Invalid environment: "${environment}". Must be "staging" or "production".`);
60
+ }
61
+ currentEnvironment = environment;
62
+ }
63
+
64
+ /**
65
+ * Get license server address based on current environment
66
+ * @returns {string}
67
+ */
68
+ function getLicenseServerAddress() {
69
+ const env = getEnvironment();
70
+ return env === 'staging'
71
+ ? "https://lic-staging.verantid.com/api/v1"
72
+ : "https://lic.verantid.com/api/v1";
73
+ }
41
74
 
42
- const dmvServerAddress = env === 'staging'
43
- ? "https://dmv-check-server-staging-fcaab48bec21.herokuapp.com/api/v1/dmv_check"
44
- : "https://dmv.verantid.com/api/v1/dmv_check";
75
+ /**
76
+ * Get DMV server address based on current environment
77
+ * @returns {string}
78
+ */
79
+ function getDmvServerAddress() {
80
+ const env = getEnvironment();
81
+ return env === 'staging'
82
+ ? "https://dmv-check-server-staging-fcaab48bec21.herokuapp.com/api/v1/dmv_check"
83
+ : "https://dmv.verantid.com/api/v1/dmv_check";
84
+ }
45
85
 
46
86
  export const dmvCheck = async (clientId, scannerType, licenseData) => {
47
- const url = dmvServerAddress;
87
+ const url = getDmvServerAddress();
48
88
 
49
89
  // Build the driver object dynamically.
50
90
  const driver = {};
@@ -135,7 +175,7 @@ export const dmvCheck = async (clientId, scannerType, licenseData) => {
135
175
  };
136
176
 
137
177
  export const checkDmvFeatureLicense = async (clientId) => {
138
- const url = licenseServerAddress + "/dmv_verifications/check_license";
178
+ const url = getLicenseServerAddress() + "/dmv_verifications/check_license";
139
179
  const data = { client_id: clientId };
140
180
 
141
181
  try {
@@ -169,7 +209,7 @@ export const checkDmvFeatureLicense = async (clientId) => {
169
209
  };
170
210
 
171
211
  export const checkFaceComparisonFeatureLicense = async (clientId) => {
172
- const url = licenseServerAddress + "/facial_scans/check_license";
212
+ const url = getLicenseServerAddress() + "/facial_scans/check_license";
173
213
  const data = { client_id: clientId };
174
214
 
175
215
  try {
@@ -203,7 +243,7 @@ export const checkFaceComparisonFeatureLicense = async (clientId) => {
203
243
  }
204
244
 
205
245
  export const checkLicense = async (clientId, macAddress) => {
206
- const url = licenseServerAddress + "/check_license";
246
+ const url = getLicenseServerAddress() + "/check_license";
207
247
  const data = { client_id: clientId, mac_address: macAddress };
208
248
 
209
249
  try {
@@ -238,7 +278,7 @@ export const checkLicense = async (clientId, macAddress) => {
238
278
  * @returns {Promise<boolean>} True if autoDmv is enabled
239
279
  */
240
280
  export const checkAutoDmvEnabled = async (clientId) => {
241
- const url = licenseServerAddress + "/check_feature_license";
281
+ const url = getLicenseServerAddress() + "/check_feature_license";
242
282
  const data = { client_id: clientId };
243
283
 
244
284
  try {
@@ -263,7 +303,7 @@ export const checkAutoDmvEnabled = async (clientId) => {
263
303
  }
264
304
  };
265
305
  export const getBarcodeLicenseKey = async () => {
266
- const url = licenseServerAddress + "/get_barcode_license_key";
306
+ const url = getLicenseServerAddress() + "/get_barcode_license_key";
267
307
 
268
308
  try {
269
309
  const response = await fetch(url, {
package/CloudScan.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  scannerPresent,
16
16
  } from "./ScannerApi.js";
17
17
  import { VerificationModal } from "./VerificationModal.js";
18
- import { checkAutoDmvEnabled } from "./Api.js";
18
+ import { checkAutoDmvEnabled, setEnvironment } from "./Api.js";
19
19
  import { formatSexCodeForDisplay, formatHeightForDisplay } from "./FormatUtils.js";
20
20
 
21
21
  let cachedLicenseFrontBase64 = "";
@@ -36,7 +36,7 @@ export const checkFaceCompareFeature = async (clientId) => {
36
36
  return await checkFaceComparisonFeatureLicense(clientId);
37
37
  }
38
38
 
39
- export { scannerPresent };
39
+ export { scannerPresent, setEnvironment };
40
40
 
41
41
  export async function readImageBarcode(imageFile, clientId = null, scannerType = 'Upload') {
42
42
  let returnObj = {
package/index.d.ts CHANGED
@@ -77,3 +77,11 @@ declare module "verant_id_cloud_scan" {
77
77
  }
78
78
 
79
79
  export function scannerPresent(scannerAddress: string): Promise<boolean>;
80
+
81
+ /**
82
+ * Explicitly set the API environment.
83
+ * By default, production is used for all hosts (including localhost).
84
+ * Only verify-staging.verantid.com automatically uses staging.
85
+ * @param environment - 'staging' or 'production'
86
+ */
87
+ export function setEnvironment(environment: 'staging' | 'production'): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verant_id_cloud_scan",
3
- "version": "1.4.5-beta.4",
3
+ "version": "1.4.5-beta.5",
4
4
  "description": "Verant ID Cloud Scan NPM Library",
5
5
  "main": "CloudScan.js",
6
6
  "types": "index.d.ts",