Skip to content
Snippets Groups Projects
onDeleteAccount.js 7.67 MiB
Newer Older
  • Learn to ignore specific revisions
  • build-token's avatar
    build-token committed
        log('info', 'Account rev exist')
    
        const accountData = await getAccountForDelete(ACCOUNT_ID, accountRev)
    
    build-token's avatar
    build-token committed
        // Parse local info for deletion test
        if (isLocal()) {
    
          log('warn', 'Local run')
    
    build-token's avatar
    build-token committed
          const fields = JSON.parse(
            process.env.COZY_FIELDS ? process.env.COZY_FIELDS : '{}'
    
    build-token's avatar
    build-token committed
          process.env.COZY_FIELDS = JSON.stringify({
            ...fields,
            ...accountData.auth,
          })
        }
        const secrets = getAccountSecret()
    
    build-token's avatar
    build-token committed
        const userConsent = await getBoConsent(
          secrets.boBaseUrl,
          secrets.boToken,
          accountData.data.consentId
        )
    
    build-token's avatar
    build-token committed
        log('info', `isAlpha: ${isDev()}`)
    
        log('info', `userConsent: ${JSON.stringify(userConsent)}`)
    
    build-token's avatar
    build-token committed
        if (userConsent.ID && userConsent.pointID) {
          log('log', `Consent ${userConsent.ID} found for user`)
          if (userConsent.serviceID) {
            await deleteBoConsent(
              secrets.boBaseUrl,
              secrets.boToken,
              userConsent.ID
            )
    
            // Verify if it's dev env to prevent delete of real data
    
    build-token's avatar
    build-token committed
            if (!isDev()) {
    
              await terminateContract(
                secrets.wso2BaseUrl,
                secrets.apiToken,
                secrets.sgeLogin,
                secrets.contractId,
                userConsent.pointID,
                userConsent.serviceID
              )
            }
    
    build-token's avatar
    build-token committed
          } else {
            log('error', `No service id retrieved from BO`)
            throw errors.VENDOR_DOWN
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          }
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        }
    
    build-token's avatar
    build-token committed
    
        log('info', 'Deleting account succeed')
      } else {
        log(
          'error',
          'No account revision was found, something went wrong during the deletion of said account'
        )
        throw errors.VENDOR_DOWN
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      }
    }
    
    onDeleteAccount().then(
      () => {
        log('info', `onDeleteAccount: Successfully delete consent and account.`)
      },
      err => {
        log(
          'error',
          `onDeleteAccount: An error occured during script: ${err.message}`
        )
        throw errors.VENDOR_DOWN
      }
    )
    
    module.exports = { onDeleteAccount }
    
    
    /***/ }),
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    const { log } = __webpack_require__(1)
    
    const { isLocal } = __webpack_require__(1650)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    
    function getAccountId() {
      log('info', `getAccountId`)
      try {
        return JSON.parse(process.env.COZY_FIELDS).account
      } catch (err) {
        throw new Error(`You must provide 'account' in COZY_FIELDS: ${err.message}`)
      }
    }
    
    function getAccountRev() {
      log('info', `getAccountRev`)
    
      log('info', `getAccountRev: ${JSON.stringify(process.env.COZY_FIELDS)}`)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      try {
    
        return isLocal()
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          ? 'fakeAccountRev'
          : JSON.parse(process.env.COZY_FIELDS).account_rev
      } catch (err) {
        throw new Error(`You must provide 'account' in COZY_FIELDS: ${err.message}`)
      }
    }
    
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    /**
     * Return account secrets.
     * For local testing, change value with values from your konnector-dev-config.json
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
     */
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    function getAccountSecret() {
    
      log('info', `getAccountSecret`)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      try {
    
        return isLocal()
    
          ? JSON.parse(process.env.COZY_FIELDS)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          : JSON.parse(process.env.COZY_PARAMETERS).secret
      } catch (err) {
        throw new Error(
          `You must provide 'account-types' in COZY_PARAMETERS: ${err.message}`
        )
      }
    }
    module.exports = { getAccountId, getAccountRev, getAccountSecret }
    
    
    /***/ })
    /******/ 	]);
    /************************************************************************/
    /******/ 	// The module cache
    /******/ 	var __webpack_module_cache__ = {};
    /******/ 	
    /******/ 	// The require function
    /******/ 	function __webpack_require__(moduleId) {
    /******/ 		// Check if module is in cache
    /******/ 		var cachedModule = __webpack_module_cache__[moduleId];
    /******/ 		if (cachedModule !== undefined) {
    /******/ 			return cachedModule.exports;
    /******/ 		}
    /******/ 		// Create a new module (and put it into the cache)
    /******/ 		var module = __webpack_module_cache__[moduleId] = {
    /******/ 			id: moduleId,
    /******/ 			loaded: false,
    /******/ 			exports: {}
    /******/ 		};
    /******/ 	
    /******/ 		// Execute the module function
    /******/ 		__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
    /******/ 	
    /******/ 		// Flag the module as loaded
    /******/ 		module.loaded = true;
    /******/ 	
    /******/ 		// Return the exports of the module
    /******/ 		return module.exports;
    /******/ 	}
    /******/ 	
    /******/ 	// expose the module cache
    /******/ 	__webpack_require__.c = __webpack_module_cache__;
    /******/ 	
    /************************************************************************/
    /******/ 	/* webpack/runtime/compat get default export */
    /******/ 	(() => {
    /******/ 		// getDefaultExport function for compatibility with non-harmony modules
    /******/ 		__webpack_require__.n = (module) => {
    /******/ 			var getter = module && module.__esModule ?
    /******/ 				() => (module['default']) :
    /******/ 				() => (module);
    /******/ 			__webpack_require__.d(getter, { a: getter });
    /******/ 			return getter;
    /******/ 		};
    /******/ 	})();
    /******/ 	
    /******/ 	/* webpack/runtime/define property getters */
    /******/ 	(() => {
    /******/ 		// define getter functions for harmony exports
    /******/ 		__webpack_require__.d = (exports, definition) => {
    /******/ 			for(var key in definition) {
    /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    /******/ 				}
    /******/ 			}
    /******/ 		};
    /******/ 	})();
    /******/ 	
    /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    /******/ 	(() => {
    /******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
    /******/ 	})();
    /******/ 	
    /******/ 	/* webpack/runtime/make namespace object */
    /******/ 	(() => {
    /******/ 		// define __esModule on exports
    /******/ 		__webpack_require__.r = (exports) => {
    /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    /******/ 			}
    /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    /******/ 		};
    /******/ 	})();
    /******/ 	
    /******/ 	/* webpack/runtime/node module decorator */
    /******/ 	(() => {
    /******/ 		__webpack_require__.nmd = (module) => {
    /******/ 			module.paths = [];
    /******/ 			if (!module.children) module.children = [];
    /******/ 			return module;
    /******/ 		};
    /******/ 	})();
    /******/ 	
    /************************************************************************/
    /******/ 	
    /******/ 	// module cache are used so entry inlining is disabled
    /******/ 	// startup
    /******/ 	// Load entry module and return exports
    
    /******/ 	var __webpack_exports__ = __webpack_require__(__webpack_require__.s = 1651);
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    /******/ 	
    /******/ })()
    ;