New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@spaship/sync-service

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spaship/sync-service - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

.eslintrc

79

lib/deploy.js

@@ -0,4 +1,8 @@

const fsp = require("fs").promises;
const path = require("path");
const decompress = require("decompress");
const config = require("../config");
const mvdir = require("mvdir");
const tmp = require("tmp-promise");
const common = require("@spaship/common");
const { write: writeMetadata } = require("./metadata");

@@ -11,23 +15,66 @@

// remove starting slashes in paths
const appPathNoSlash = appPath.replace(/^\//, "");
const destDir = path.resolve(config.get("webroot"), appPathNoSlash);
// create a dir in the tmp_dir location, but keep the random archive name
let tmpDir = `${spaArchive}-extracted`;
await fsp.mkdir(tmpDir);
// const tmpDir = await fsp.m({ template: path.join(config.get("tmp_dir"), " });
console.log(`created tmp dir ${tmpDir}`);
// extract the archive
try {
await decompress(spaArchive, destDir);
await decompress(spaArchive, tmpDir);
// detect if the archive was created with `npm pack`. npm pack creates a
// tarball with a "package" dir. we want what's in the package dir but not
// the dir itself.
let isNpmPack;
try {
const packageStat = await fsp.lstat(path.join(tmpDir, "package"));
isNpmPack = packageStat.isDirectory();
} catch (e) {
isNpmPack = false;
}
// if the archive was generated by `npm pack`, move into the "package"
// directory where all the goodies are.
if (isNpmPack) {
console.log(`detected npm pack archive, moving into package/`);
tmpDir = path.join(tmpDir, "package");
}
let spaConfig = { name, path: appPath };
let hasYaml = false;
const yamlFilePath = path.join(tmpDir, "spaship.yaml");
try {
spaConfig = await common.config.read(yamlFilePath);
hasYaml = true;
} catch (e) {}
const valid = common.config.validate(spaConfig);
console.log("VALID?", valid);
if (!valid) {
throw new Error("spa config is not valid");
}
// remove starting slashes in paths
const flatPath = common.flatpath.toDir(spaConfig.path);
const destDir = path.join(config.get("webroot"), flatPath);
// move the goodies dir to the final destination in the webroot
console.log(`moving from ${tmpDir} to ${destDir}`);
await mvdir(tmpDir, destDir);
// write spa metadata to filesystem
writeMetadata({
appName: name,
appPath: destDir,
type: "ref",
value: ref
});
writeMetadata({
appName: name,
appPath: destDir,
type: "name",
value: name
});
if (!hasYaml) {
writeMetadata(path.join(destDir, "spaship.yaml"), {
name,
path: spaConfig.path
});
}
if (ref) {
writeMetadata(path.join(destDir, "spaship.yaml"), {
ref
});
}

@@ -34,0 +81,0 @@ console.log(`[deploy] extracted "${name}" to ${destDir}, deploy complete.`);

const path = require("path");
const fsp = require("fs").promises;
const config = require("../config");
const common = require("@spaship/common");
const { flow, map, filter } = require("lodash/fp");

@@ -13,23 +14,4 @@

async function write({ appName, appPath, type, value } = {}) {
const appMetaDir = getMetaDir(appPath);
const filePath = path.resolve(appMetaDir, type);
try {
await fsp.mkdir(appMetaDir);
} catch (e) {
if (e.code !== "EEXIST") {
console.error(e);
return;
}
}
try {
await fsp.writeFile(filePath, value);
console.log(
`[deploy] wrote ${appName}'s "${type}" metadata to ${filePath}`
);
} catch (e) {
console.error(e);
}
async function write(filename, extraData) {
await common.config.append(filename, extraData);
}

@@ -75,13 +57,5 @@

// read the contents of the ref and name files
const [ref, name] = await Promise.all([
readMetaFile(spaDir, "ref"),
readMetaFile(spaDir, "name")
]);
return {
path: `/${spaDir}`,
ref,
name
};
return await common.config.read(path.join(spaDir, "spaship.yaml"));
}
module.exports = { write, getAll, get };
{
"name": "@spaship/sync-service",
"version": "0.0.13",
"version": "0.0.14",
"description": "The file synchronization service for the SPAship platform.",

@@ -31,2 +31,3 @@ "homepage": "https://github.com/spaship/sync-service",

"dependencies": {
"@spaship/common": "^0.0.0",
"axios": "^0.19.0",

@@ -42,3 +43,5 @@ "cors": "^2.8.5",

"multer": "^1.4.2",
"mvdir": "^1.0.5",
"nconf": "^0.10.0",
"tmp-promise": "^2.0.2",
"url-join": "^4.0.1"

@@ -53,21 +56,3 @@ },

"standard-version": "7.0.0"
},
"eslintConfig": {
"extends": [
"prettier"
],
"env": {
"shared-node-browser": true
},
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error"
},
"plugins": [
"prettier"
]
}
}
const path = require("path");
const fsp = require("fs").promises;
const decompress = require("decompress");

@@ -8,22 +9,28 @@ const multer = require("multer");

const multerUpload = multer({
dest: config.get("upload_dir"),
fileFilter: (req, file, cb) => {
// to reject file uploads: cb(null, false);
cb(null, true);
}
});
// return an array of expressjs callbacks, the first using multer to support
// uploading multipart forms (ie, files), and the second to handle extraction
function createDeployMiddleware() {
const multerUpload = multer({
dest: config.get("upload_dir"),
fileFilter: (req, file, cb) => {
// to reject file uploads: cb(null, false);
cb(null, true);
}
});
const upload = multerUpload.single("upload");
const extract = (req, res) => {
const extract = (req, res, next) => {
const { name, path: appPath, ref } = req.body;
const { path: spaArchive } = req.file;
deploy({ name, spaArchive, appPath, ref });
res.send("SPA uploaded, deployment continuing in the background.");
deploy({ name, spaArchive, appPath, ref })
.then(result => {
console.log(`extracted successfully`);
res.send("SPA uploaded successfully.");
})
.catch(err => {
res.status(403);
console.log(err);
});
};

@@ -30,0 +37,0 @@

Sorry, the diff of this file is not supported yet

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