From 5edc1fbd4ea413bee796372c307e0dc2261eac0c Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Mon, 17 Feb 2020 21:22:42 -0300 Subject: [PATCH] fix(setup-timeout): ignore setup timeout for Cloud Functions by default --- main.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index df82066..155e7c1 100644 --- a/main.js +++ b/main.js @@ -120,12 +120,18 @@ const promise = new Promise((resolve, reject) => { return promise } - // timeout to handle setup - setTimeout(() => { - if (!client) { - reject(new Error('You must setup E-Com Plus auth before use SDK')) - } - }, 4000) + if ( + process.env.ECOM_AUTH_SETUP_TIMEOUT !== 'disabled' && + // ignore setup timeout for Google (Firebase) Cloud Functions by default + (!process.env.GCLOUD_PROJECT || process.env.ECOM_AUTH_SETUP_TIMEOUT === 'enabled') + ) { + // timeout to handle setup + setTimeout(() => { + if (!client) { + reject(new Error('You must setup E-Com Plus auth before use SDK')) + } + }, 4000) + } }) if (envDbFilename) {