Socket
Socket
Sign inDemoInstall

@commercetools/frontend-netlify-plugin

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/frontend-netlify-plugin - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

src/backend-check.js

2

package.json
{
"name": "@commercetools/frontend-netlify-plugin",
"version": "0.0.2",
"version": "0.0.3",
"description": "Netlify Build plugin - Commercetools Frontend build extension",

@@ -5,0 +5,0 @@ "type": "module",

import * as dotenv from 'dotenv'
import * as fs from 'fs'
import fetch from 'node-fetch'
import { waitForBackend } from "./backend-check.js";

@@ -50,61 +50,1 @@ dotenv.config()

}
/*
* Checks if the backend is ready
* Does an HTTP request to the appropriate extension runner
*/
export const checkBackend = async (version, path) => {
console.log('Calling ' + path, 'Version ' + version)
const actualInit = {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'Commercetools-Frontend-Extension-Version': version,
},
}
try {
const response = await fetch(path, actualInit)
if (response) {
return await response.json()
}
} catch (e) {
console.log(`Error while calling extension runner ${path}:`, e)
}
return { up: false }
}
/**
* Waits for the backend extension to be ready.
* Will attempt the number of tries passed on the maxTries parameter.
* If the extension is not up after the maxTries an error is thrown.
*
* @param shortCommitHash the extension version
* @param maxTries the max number of attempts
* @param path the path to be tested
* @returns {Promise<void>}
*/
export const waitForBackend = async (shortCommitHash, maxTries, path) => {
for (let i = 0; i < maxTries; i++) {
const attempt = i + 1
console.log('Checking if extension is up, attempt: ', attempt)
const { up } = await checkBackend(shortCommitHash, path)
if (!up) {
console.error(
'Extension is not available, waiting for',
attempt,
'seconds',
)
await sleep(i * 1000)
} else {
console.log('Extension is up!')
return
}
}
throw new Error('Extension is not up')
}
export const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms))
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc