Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const epoch = Date.now();
// Decide which file to send to remote
let file;
if (type === 'remote') {
file = path.join(rootFolder, constants.META_DIR, constants.META_REMOTE);
} else {
file = path.join(rootFolder, constants.META_DIR, constants.META_LOCAL);
}
// Read the file we need to push
const files = fs.readJsonSync(file, 'utf8').files;
// Push resource to google drive
const script = google.script('v1');
script.projects.updateContent({
auth,
scriptId: projectId,
resource: {
files,
},
}, (err, result) => {
if (err) {
triageGoogleError(err, 'pushToRemote').then((triaged) => {
reject(triaged);
}).catch((notTriaged) => {
reject(notTriaged);
});
} else {
resolve(result.data);
}
// },
// "isLocalCreds": true
// }
// API settings
// @see https://developers.google.com/oauthplayground/
const REDIRECT_URI_OOB = 'urn:ietf:wg:oauth:2.0:oob';
const globalOauth2ClientSettings: OAuth2ClientOptions = {
clientId: '1072944905499-vm2v2i5dvn0a0d2o4ca36i1vge8cvbn0.apps.googleusercontent.com',
clientSecret: 'v6V3fKV_zWU7iw1DrpO1rknX',
redirectUri: 'http://localhost',
};
const globalOAuth2Client = new OAuth2Client(globalOauth2ClientSettings);
let localOAuth2Client: OAuth2Client; // Must be set up after authorize.
// *Global* Google API clients
export const script = google.script({ version: 'v1', auth: globalOAuth2Client });
export const logger = google.logging({ version: 'v2', auth: globalOAuth2Client });
export const drive = google.drive({ version: 'v3', auth: globalOAuth2Client });
export const discovery = google.discovery({ version: 'v1' });
export const serviceUsage = google.serviceusage({
version: 'v1',
auth: globalOAuth2Client,
});
/**
* Gets the local OAuth client for the Google Apps Script API.
* Only the Apps Script API needs to use local credential for the Execution API (script.run).
* @see https://developers.google.com/apps-script/api/how-tos/execute
*/
export async function getLocalScript(): Promise {
return google.script({ version: 'v1', auth: localOAuth2Client });
}
function callAppsScript(auth) {
const script = google.script({version: 'v1', auth});
script.projects.create({
resource: {
title: 'My Script',
},
}, (err, res) => {
if (err) return console.log(`The API create method returned an error: ${err}`);
script.projects.updateContent({
scriptId: res.data.scriptId,
auth,
resource: {
files: [{
name: 'hello',
type: 'SERVER_JS',
source: 'function helloWorld() {\n console.log("Hello, world!");\n}',
}, {
name: 'appsscript',
var secrets = {
VERB8TM_SRT_API: "",
VERB8TM_TIMESTAMP_API: ""
};
for (var k in secrets) {
secrets[k] = process.env["anno_docs_" + k];
}
var config = require("./app_config.json");
var scriptId = config.script_project;
var server = args.env == "production" ? config.production : config.staging;
var auth = login.getClient();
var scriptAPI = google.script({ version: "v1", auth });
var tasks = {
login: async function() {
await login.authenticate([
"https://www.googleapis.com/auth/script.projects",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.deployments",
"https://www.googleapis.com/auth/documents",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/script.send_mail",
"https://www.googleapis.com/auth/spreadsheets"
]);
process.exit();
},
setup: async function() {
const metadata = await new Promise((resolve, reject) => {
const script = google.script('v1');
script.projects.get({
auth,
projectId: identifier,
}, (err, result) => {
if (err) {
resolve(false);
} else {
resolve(result.data);
}
return;
});
});
if (metadata) {
export async function getLocalScript(): Promise {
return google.script({ version: 'v1', auth: localOAuth2Client });
}
return new Promise((resolve, reject) => {
const script = google.script('v1');
script.projects.deployments.list({
auth,
scriptId: projectId,
}, (error, deployments) => {
if (error) {
triageGoogleError(error, 'getDeployments').then((triaged) => {
reject(triaged);
}).catch((notTriaged) => {
reject(notTriaged);
});
} else {
resolve(deployments.data);
}
return;
});
});
return new Promise((resolve, reject) => {
const script = google.script('v1');
script.projects.deployments.create({
auth,
scriptId: projectId,
resource: {
versionNumber,
manifestFileName: 'appsscript',
description,
},
}, (err, res) => {
if (err) {
triageGoogleError(err, 'createDeployment').then((triaged) => {
reject(triaged);
}).catch((notTriaged) => {
reject(notTriaged);
});
} else {
if (method === 'clone' && fs.existsSync(path.join('.', dir))) {
reject({
message: `Oops, the directory '${dir}' seems to exist already.\nRemove this folder or use 'gas link' to link your project to the correct folder.`,
print: true,
});
return;
}
const file = {
name: path.join(gasDir, constants.META_ID),
source: projectId,
};
createFile(file);
const remote = path.join(gasDir, constants.META_REMOTE);
const script = google.script('v1');
script.projects.getContent({
auth,
scriptId: projectId,
}, (err, content) => {
if (err) {
fs.removeSync(remote);
triageGoogleError(err, 'downloadRemote').then((triaged) => {
reject(triaged);
}).catch((notTriaged) => {
reject(notTriaged);
});
} else {
createFile({
name: remote,
source: JSON.stringify(content.data),
return new Promise((resolve, reject) => {
const script = google.script('v1');
script.projects.versions.create({
auth,
scriptId: projectId,
description,
}, (err, res) => {
if (err) {
triageGoogleError(err, 'createVersion').then((triaged) => {
reject(triaged);
}).catch((notTriaged) => {
reject(notTriaged);
});
} else {
resolve(res.data);
}
return;
});