Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentful/app-scripts

Package Overview
Dependencies
Maintainers
99
Versions
512
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/app-scripts - npm Package Compare versions

Comparing version 0.8.8 to 0.8.9-alpha.11

8

lib/activate/activate-bundle.js

@@ -9,2 +9,3 @@ const ora = require('ora');

const plainClient = createClient({ accessToken }, { type: 'plain' });
const defaultLocations = [{location: 'dialog'}];

@@ -23,2 +24,5 @@ const currentDefinition = await plainClient.appDefinition.get({

};
if (!currentDefinition.locations.length) {
currentDefinition.locations = defaultLocations;
}
delete currentDefinition.src;

@@ -43,4 +47,4 @@

console.log(
`${chalk.cyan('Success!')} Your app bundle was activated for ${chalk.cyan(
console.log(`
${chalk.cyan('Success!')} Your app bundle was activated for ${chalk.cyan(
definition.name

@@ -47,0 +51,0 @@ )} in ${chalk.bold(organization.name)}.

@@ -26,2 +26,3 @@ const { stub, match } = require('sinon');

bundle: undefined,
locations: []
};

@@ -50,5 +51,6 @@

it('updates definition with bundle and sets src to undefined', async () => {
it('updates definition with bundle, sets default location, and sets src to undefined', async () => {
await activateBundle(mockedSettings);
assert.strictEqual(definitionMock.bundle.sys.id, mockedSettings.bundleId);
assert.strictEqual(definitionMock.locations.length, 1);
assert.strictEqual(definitionMock.src, undefined);

@@ -55,0 +57,0 @@ assert.strictEqual(updateStub.called, true);

@@ -5,6 +5,10 @@ const path = require('path');

const chalk = require('chalk');
const inquirer = require('inquirer');
const { isString, isPlainObject, has } = require('lodash');
const { throwValidationException } = require('../utils');
const { throwValidationException, selectFromList } = require('../utils');
const { cacheEnvVars } = require('../../utils/cache-credential');
const {
ORG_ID_ENV_KEY,
APP_DEF_ENV_KEY,
} = require('../../utils/constants');

@@ -62,14 +66,6 @@ async function fetchOrganizations(client) {

const client = createClient({ accessToken });
const organizations = await fetchOrganizations(client);
const { organizationId } = await inquirer.prompt([
{
name: 'organizationId',
message: 'Select an organization for your app:',
type: 'list',
choices: organizations,
},
]);
const selectedOrg = organizations.find((org) => org.value === organizationId);
const selectedOrg = await selectFromList(organizations, 'Select an organization for your app:', ORG_ID_ENV_KEY);
const organizationId = selectedOrg.value;

@@ -97,2 +93,5 @@ const appName = appDefinitionSettings.name || path.basename(process.cwd());

const createdAppDefinition = await organization.createAppDefinition(body);
await cacheEnvVars({
[APP_DEF_ENV_KEY]: createdAppDefinition.sys.id
});

@@ -99,0 +98,0 @@ console.log(`

const proxyquire = require('proxyquire');
const { stub, match } = require('sinon');
const assert = require('assert');
const {
APP_DEF_ENV_KEY,
} = require('../../utils/constants');

@@ -9,3 +12,3 @@ const organizationId = 'orgId';

describe('createAppDefinition', () => {
let subject, clientMock, promptMock;
let subject, clientMock, selectFromListMock, cachedEnvVarsMock;

@@ -26,6 +29,7 @@ beforeEach(() => {

promptMock = stub();
cachedEnvVarsMock = stub().resolves(undefined);
selectFromListMock = stub();
({ createAppDefinition: subject } = proxyquire('./create-app-definition', {
inquirer: { prompt: promptMock },
'contentful-management': {

@@ -35,2 +39,8 @@ createClient: () => {

}
},
'../../utils/cache-credential': {
cacheEnvVars: cachedEnvVarsMock
},
'../utils': {
selectFromList: selectFromListMock
}

@@ -52,3 +62,3 @@ }));

clientMock.getOrganizations = stub().resolves({ items: [{ name: 'name', sys: { id: organizationId } }] });
promptMock.returns({ organizationId });
selectFromListMock.returns({ name: 'name', value: organizationId });

@@ -69,3 +79,3 @@ await assert.rejects(() => subject(token, { locations: [] }));

clientMock.getOrganizations = stub().resolves({ items: [{ name: 'name', sys: { id: organizationId } }] });
promptMock.returns({ organizationId });
selectFromListMock.returns({ name: 'name', value: organizationId });

@@ -80,3 +90,4 @@ await assert.doesNotReject(() => subject(token, { locations: [] }));

assert(loggedMessage.includes(tutorialLink));
assert.deepStrictEqual(cachedEnvVarsMock.args[0][0], {[APP_DEF_ENV_KEY]: 'appId'});
});
});
const {buildAppDefinitionSettings} = require('./build-app-definition-settings')
const {createAppDefinition} = require('./create-app-definition')
const {getManagementToken} = require('./get-management-token')
const {getManagementToken} = require('../get-management-token')

@@ -5,0 +5,0 @@ module.exports = {

const ora = require('ora');
const { selectFromList } = require('./utils');
const { throwError } = require('./utils');
const { APP_DEF_ENV_KEY } = require('../utils/constants')

@@ -26,3 +27,3 @@ async function fetchDefinitions(client, orgId) {

return await selectFromList(definitions, 'Select an app for your upload:');
return await selectFromList(definitions, 'Select an app for your upload:', APP_DEF_ENV_KEY);
}

@@ -29,0 +30,0 @@

@@ -6,3 +6,19 @@ /* eslint-disable no-console, no-process-exit */

const inquirer = require('inquirer');
const { cacheEnvVars } = require('../utils/cache-credential');
const { createClient } = require('contentful-management');
const {
ACCESS_TOKEN_ENV_KEY
} = require('../utils/constants');
const checkTokenValidity = async (accessToken) => {
try {
const client = createClient({ accessToken });
await client.getCurrentUser();
return true;
} catch(err) {
return false;
}
}
async function getManagementToken() {

@@ -14,2 +30,10 @@ const redirectUrl = 'https://www.contentful.com/developers/cli-oauth-page/';

)}`;
const cachedAccessToken = process.env[ACCESS_TOKEN_ENV_KEY];
const cachedTokenValid = await checkTokenValidity(cachedAccessToken);
if (cachedTokenValid) {
return cachedAccessToken;
}
try {

@@ -38,2 +62,4 @@ open(oauthUrl);

await cacheEnvVars({[ACCESS_TOKEN_ENV_KEY]: mgmtToken});
return mgmtToken;

@@ -40,0 +66,0 @@ }

@@ -22,3 +22,12 @@ const proxyquire = require('proxyquire');

inquirer: { prompt: promptMock },
open: openMock
open: openMock,
'contentful-management': {
createClient() {
return {
async getOrganizations() {
throw new Error();
}
}
}
}
}));

@@ -25,0 +34,0 @@ });

const ora = require('ora');
const { selectFromList } = require('./utils');
const { throwError } = require('./utils');
const { ORG_ID_ENV_KEY } = require('../utils/constants');

@@ -24,2 +25,3 @@ async function fetchOrganizations(client) {

let organizations = null;
try {

@@ -34,3 +36,4 @@ organizations = await fetchOrganizations(client);

}
return await selectFromList(organizations, 'Select an organization for your app:');
return await selectFromList(organizations, 'Select an organization for your app:', ORG_ID_ENV_KEY);
}

@@ -37,0 +40,0 @@

@@ -11,4 +11,4 @@ // @ts-check

name: 'bundleDirectory',
message: `Bundle directory, if not current:`,
default: '.',
message: `Bundle directory, if not default:`,
default: './build',
});

@@ -15,0 +15,0 @@ }

@@ -33,9 +33,8 @@ const chalk = require('chalk');

appUpload = await createAppUpload(settings);
console.log(
`${chalk.yellow(
'Done!'
)} Your files were successfully uploaded and a new AppUpload (${chalk.dim(
appUpload.sys.id
)}) has been created.`
);
console.log(`
${chalk.yellow(
'Done!'
)} Your files were successfully uploaded and a new AppUpload (${chalk.dim(
appUpload.sys.id
)}) has been created.`);
} catch (err) {

@@ -47,3 +46,4 @@ showCreationError('app upload', err.message);

console.log('----------------------------');
console.log("")
console.log(` ----------------------------`);
const appBundle = await createAppBundleFromUpload(settings, appUpload.sys.id);

@@ -50,0 +50,0 @@

@@ -9,6 +9,10 @@ const chalk = require('chalk');

zip.addLocalFolder(path);
console.log('----------------------------');
console.log(`${chalk.yellow('Done!')} Files from ${chalk.dim(path)} successfully zipped.`);
console.log('----------------------------');
console.log("");
console.log(` ----------------------------
${chalk.yellow('Done!')} Files from ${chalk.dim(path)} successfully zipped.
----------------------------`);
console.log("");
return zip.toBuffer();

@@ -15,0 +19,0 @@ } catch (err) {

const chalk = require('chalk');
const inquirer = require('inquirer');
const { cacheEnvVars } = require('../utils/cache-credential');

@@ -32,12 +33,29 @@ const throwValidationException = (subject, message, details) => {

const selectFromList = async (list, message) => {
const { elementId } = await inquirer.prompt([
{
name: 'elementId',
message: message,
type: 'list',
choices: list,
},
]);
return list.find((el) => el.value === elementId);
const selectFromList = async (list, message, cachedOptionEnvVar) => {
const cachedEnvVar = process.env[cachedOptionEnvVar]
const cachedElement = list.find(item => item.value === cachedEnvVar);
if (cachedElement) {
console.log(`
${message}
Using environment variable: ${cachedElement.name} (${chalk.blue(cachedElement.value)})
`)
return cachedElement;
} else {
const { elementId } = await inquirer.prompt([
{
name: 'elementId',
message: message,
type: 'list',
choices: list,
},
]);
if (cachedOptionEnvVar) {
await cacheEnvVars({[cachedOptionEnvVar]: elementId});
}
return list.find((el) => el.value === elementId);
}
};

@@ -44,0 +62,0 @@

{
"name": "@contentful/app-scripts",
"version": "0.8.8",
"version": "0.8.9-alpha.11+0d8f53f",
"description": "A collection of scripts for building Contentful Apps",

@@ -64,3 +64,3 @@ "author": "Contentful GmbH",

},
"gitHead": "24223cf165c76cb140cfb2d7f61700412e058f73"
"gitHead": "0d8f53f97e59e17721cb9e6b146a9b543562d158"
}
const proxyquire = require('proxyquire');
const { DOTENV_FILE } = require('../constants');
const { DOTENV_FILE, ACCESS_TOKEN_ENV_KEY } = require('../constants');
const assert = require('assert');

@@ -43,3 +43,3 @@

it('should create .env file if its missing', async () => {
await cacheEnvVars({'CONTENTFUL_TOKEN': 'test_value'});
await cacheEnvVars({[ACCESS_TOKEN_ENV_KEY]: 'test_value'});

@@ -52,9 +52,9 @@ const fileExists = await mockedFs.promises.access(DOTENV_FILE, mockedFs.constants.F_OK) === undefined;

const envData = `CONTENTFUL_APP_DEF_ID=some_app_def_id\n
CONTENTFUL_TOKEN=old_value`;
${ACCESS_TOKEN_ENV_KEY}=old_value`;
const expectedData = `CONTENTFUL_APP_DEF_ID=some_app_def_id
CONTENTFUL_TOKEN=new_value`;
${ACCESS_TOKEN_ENV_KEY}=new_value`;
await mockedFs.promises.writeFile(DOTENV_FILE, envData, {encoding: 'utf-8'});
await cacheEnvVars({'CONTENTFUL_TOKEN': 'new_value'});
await cacheEnvVars({[ACCESS_TOKEN_ENV_KEY]: 'new_value'});
const fileData = await mockedFs.promises.readFile(DOTENV_FILE, {encoding: 'utf-8'});

@@ -67,7 +67,7 @@ assert.strictEqual(fileData, expectedData);

const expectedData = `CONTENTFUL_APP_DEF_ID=some_app_def_id
CONTENTFUL_TOKEN=new_value_2`;
${ACCESS_TOKEN_ENV_KEY}=new_value_2`;
await mockedFs.promises.writeFile(DOTENV_FILE, envData, {encoding: 'utf-8'});
await cacheEnvVars({'CONTENTFUL_TOKEN': 'new_value_2'});
await cacheEnvVars({[ACCESS_TOKEN_ENV_KEY]: 'new_value_2'});
const fileData = await mockedFs.promises.readFile(DOTENV_FILE, {encoding: 'utf-8'});

@@ -74,0 +74,0 @@ assert.strictEqual(fileData, expectedData);

@@ -1,5 +0,11 @@

const DOTENV_FILE = '.env'
const DOTENV_FILE = '.env';
const ACCESS_TOKEN_ENV_KEY = 'CONTENTFUL_ACCESS_TOKEN';
const ORG_ID_ENV_KEY = 'CONTENTFUL_ORG_ID';
const APP_DEF_ENV_KEY = 'CONTENTFUL_APP_DEF_ID';
module.exports = {
DOTENV_FILE
DOTENV_FILE,
ACCESS_TOKEN_ENV_KEY,
ORG_ID_ENV_KEY,
APP_DEF_ENV_KEY,
}
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