@zendesk/zcli-apps
Advanced tools
Comparing version 1.0.0-beta.47 to 1.0.0-beta.49
@@ -45,3 +45,4 @@ "use strict"; | ||
core_1.CliUx.ux.action.stop('Failed'); | ||
this.error(chalk.red(error)); | ||
// this.error(chalk.red(error)) | ||
console.log(error); | ||
} | ||
@@ -48,0 +49,0 @@ } |
@@ -11,5 +11,5 @@ import { Command } from '@oclif/core'; | ||
static strict: boolean; | ||
getAppID(appPath: string): string; | ||
installApp(appConfig: ZcliConfigFileContent, uploadId: number, appPath: string, manifest: Manifest): Promise<void>; | ||
getAppID(appConfig: ZcliConfigFileContent): string; | ||
installApp(appConfig: ZcliConfigFileContent, uploadId: number, appPath: string, manifest: Manifest, appID: string): Promise<void>; | ||
run(): Promise<void>; | ||
} |
@@ -12,6 +12,6 @@ "use strict"; | ||
const appPath_1 = require("../../lib/appPath"); | ||
const env_1 = require("@zendesk/zcli-core/src/lib/env"); | ||
class Update extends core_1.Command { | ||
getAppID(appPath) { | ||
const allConfigs = (0, appConfig_1.getAllConfigs)(appPath); | ||
const app_id = allConfigs ? allConfigs.app_id : undefined; | ||
getAppID(appConfig) { | ||
const app_id = process.env[env_1.EnvVars.APP_ID] || (appConfig ? appConfig.app_id : undefined); | ||
if (!app_id) { | ||
@@ -22,5 +22,5 @@ throw new errors_1.CLIError(chalk.red('App ID not found')); | ||
} | ||
async installApp(appConfig, uploadId, appPath, manifest) { | ||
async installApp(appConfig, uploadId, appPath, manifest, appID) { | ||
core_1.CliUx.ux.action.start('Deploying app'); | ||
const { job_id } = await (0, createApp_1.deployApp)('PUT', `api/v2/apps/${appConfig.app_id}`, uploadId); | ||
const { job_id } = await (0, createApp_1.deployApp)('PUT', `api/v2/apps/${appID}`, uploadId); | ||
try { | ||
@@ -49,2 +49,3 @@ const { app_id } = await (0, uploadApp_1.getUploadJobStatus)(job_id, appPath); | ||
const appConfig = (0, appConfig_1.getAllConfigs)(appPath) || {}; | ||
const appID = this.getAppID(appConfig); | ||
const manifest = (0, manifest_1.getManifestFile)(appPath); | ||
@@ -59,3 +60,3 @@ const pkgPath = await (0, package_1.createAppPkg)(appPath); | ||
try { | ||
await this.installApp(appConfig, upload_id, appPath, manifest); | ||
await this.installApp(appConfig, upload_id, appPath, manifest, appID); | ||
} | ||
@@ -62,0 +63,0 @@ catch (error) { |
@@ -6,3 +6,2 @@ "use strict"; | ||
const fs = require("fs-extra"); | ||
const FormData = require("form-data"); | ||
const zcli_core_1 = require("@zendesk/zcli-core"); | ||
@@ -12,42 +11,52 @@ const errors_1 = require("@oclif/core/lib/errors"); | ||
const appPath_1 = require("./appPath"); | ||
const FormData = require("form-data"); | ||
const getDateTimeFileName = () => (new Date()).toISOString().replace(/[^0-9]/g, ''); | ||
const createAppPkg = async (relativeAppPath, pkgDir = 'tmp') => { | ||
const appPath = path.resolve(relativeAppPath); | ||
(0, appPath_1.validateAppPath)(appPath); | ||
const pkgName = `app-${getDateTimeFileName()}`; | ||
const pkgPath = `${appPath}/${pkgDir}/${pkgName}.zip`; | ||
await fs.ensureDir(`${appPath}/${pkgDir}`); | ||
const output = fs.createWriteStream(pkgPath); | ||
const archive = archiver('zip'); | ||
archive.pipe(output); | ||
let archiveIgnore = ['tmp/**']; | ||
if (fs.pathExistsSync(`${appPath}/.zcliignore`)) { | ||
archiveIgnore = archiveIgnore.concat(fs.readFileSync(`${appPath}/.zcliignore`).toString().replace(/\r\n/g, '\n').split('\n').filter((item) => { | ||
return (item.trim().startsWith('#') ? null : item.trim()); | ||
})); | ||
} | ||
archive.glob('**', { | ||
cwd: appPath, | ||
ignore: archiveIgnore | ||
const createAppPkg = (relativeAppPath, pkgDir = 'tmp') => { | ||
return new Promise((resolve, reject) => { | ||
const appPath = path.resolve(relativeAppPath); | ||
(0, appPath_1.validateAppPath)(appPath); | ||
const pkgName = `app-${getDateTimeFileName()}`; | ||
const pkgPath = `${appPath}/${pkgDir}/${pkgName}.zip`; | ||
fs.ensureDirSync(`${appPath}/${pkgDir}`); | ||
const output = fs.createWriteStream(pkgPath); | ||
output.on('close', () => { | ||
resolve(pkgPath); | ||
}); | ||
output.on('error', (err) => { | ||
reject(err); | ||
}); | ||
const archive = archiver('zip'); | ||
let archiveIgnore = ['tmp/**']; | ||
if (fs.pathExistsSync(`${appPath}/.zcliignore`)) { | ||
archiveIgnore = archiveIgnore.concat(fs.readFileSync(`${appPath}/.zcliignore`).toString().replace(/\r\n/g, '\n').split('\n').filter((item) => { | ||
return (item.trim().startsWith('#') ? null : item.trim()); | ||
})); | ||
} | ||
archive.glob('**', { | ||
cwd: appPath, | ||
ignore: archiveIgnore | ||
}); | ||
archive.pipe(output); | ||
archive.finalize(); | ||
return pkgPath; | ||
}); | ||
await archive.finalize(); | ||
if (!fs.pathExistsSync(pkgPath)) { | ||
throw new errors_1.CLIError(`Failed to create package at ${pkgPath}`); | ||
} | ||
return pkgPath; | ||
}; | ||
exports.createAppPkg = createAppPkg; | ||
const validatePkg = async (pkgPath) => { | ||
var _a; | ||
if (!fs.pathExistsSync(pkgPath)) { | ||
throw new errors_1.CLIError(`Package not found at ${pkgPath}`); | ||
} | ||
const file = await fs.readFile(pkgPath); | ||
const form = new FormData(); | ||
form.append('file', fs.createReadStream(pkgPath)); | ||
form.append('file', file, { | ||
filename: path.basename(pkgPath) | ||
}); | ||
const res = await zcli_core_1.request.requestAPI('api/v2/apps/validate', { | ||
method: 'POST', | ||
data: form | ||
data: form.getBuffer(), | ||
headers: form.getHeaders() | ||
}); | ||
if (res.status !== 200) { | ||
const { description } = await res.data; | ||
throw new errors_1.CLIError(description); | ||
throw new errors_1.CLIError((_a = res.data) === null || _a === void 0 ? void 0 : _a.description); | ||
} | ||
@@ -54,0 +63,0 @@ return true; |
@@ -11,2 +11,3 @@ "use strict"; | ||
.stub(fs, 'pathExistsSync', () => true) | ||
.stub(fs, 'readFile', () => Promise.resolve('file content')) | ||
.stub(zcli_core_1.request, 'requestAPI', () => Promise.resolve({ status: 200 })) | ||
@@ -18,16 +19,24 @@ .it('should return true if package is valid', async () => { | ||
.stub(fs, 'pathExistsSync', () => true) | ||
.stub(fs, 'readFile', () => Promise.resolve('file content')) | ||
.stub(zcli_core_1.request, 'requestAPI', () => Promise.resolve({ status: 400, data: { description: 'invalid location' } })) | ||
.do(async () => { | ||
await (0, package_1.validatePkg)('./app-path'); | ||
}) | ||
.catch('invalid location') | ||
.it('should throw if package has validation errors'); | ||
.it('should throw if package has validation errors', async () => { | ||
try { | ||
await (0, package_1.validatePkg)('./app-path'); | ||
} | ||
catch (error) { | ||
(0, test_1.expect)(error.message).to.equal('invalid location'); | ||
} | ||
}); | ||
test_1.test | ||
.stub(fs, 'pathExistsSync', () => false) | ||
.do(async () => { | ||
await (0, package_1.validatePkg)('./bad-path'); | ||
}) | ||
.catch('Package not found at ./bad-path') | ||
.it('should throw if app path is invalid'); | ||
.stub(fs, 'readFile', () => Promise.reject(new Error('Package not found at ./bad-path'))) | ||
.it('should throw if app path is invalid', async () => { | ||
try { | ||
await (0, package_1.validatePkg)('./bad-path'); | ||
} | ||
catch (error) { | ||
(0, test_1.expect)(error.message).to.equal('Package not found at ./bad-path'); | ||
} | ||
}); | ||
}); | ||
}); |
@@ -10,2 +10,3 @@ "use strict"; | ||
const chalk = require("chalk"); | ||
const path = require("path"); | ||
const getManifestAppName = (appPath) => { | ||
@@ -16,8 +17,12 @@ return (0, manifest_1.getManifestFile)(appPath).name; | ||
const uploadAppPkg = async (pkgPath) => { | ||
const pkgBuffer = await fs.readFile(pkgPath); | ||
const formData = new FormData(); | ||
const pkgBuffer = fs.createReadStream(pkgPath); | ||
formData.append('uploaded_data', pkgBuffer); | ||
formData.append('uploaded_data', pkgBuffer, { | ||
filename: path.basename(pkgPath), | ||
contentType: 'application/zip' | ||
}); | ||
const response = await zcli_core_1.request.requestAPI('api/v2/apps/uploads.json', { | ||
data: formData, | ||
method: 'POST' | ||
method: 'POST', | ||
data: formData.getBuffer(), | ||
headers: formData.getHeaders() | ||
}); | ||
@@ -24,0 +29,0 @@ // clean up |
{ | ||
"name": "@zendesk/zcli-apps", | ||
"description": "zcli apps commands live here", | ||
"version": "1.0.0-beta.47", | ||
"version": "1.0.0-beta.49", | ||
"author": "@vegemite", | ||
@@ -22,3 +22,3 @@ "npmRegistry": "https://registry.npmjs.org", | ||
"archiver": "^5.3.1", | ||
"axios": "^0.27.2", | ||
"axios": "^1.7.5", | ||
"chalk": "^4.1.2", | ||
@@ -72,3 +72,3 @@ "cors": "^2.8.5", | ||
"types": "lib/index.d.ts", | ||
"gitHead": "3dd84a881a2a1ca9e4d7dfc2a23c2ef106cb7b0b" | ||
"gitHead": "33785c2889a604d3f61b80b5e5c2df755e38d5a5" | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
1860
75614
61
18
+ Addedaxios@1.7.9(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.27.2(transitive)
Updatedaxios@^1.7.5