From d0dba940ae76a5143a13592d5969111d9f55ae6b Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Wed, 17 Jan 2024 19:13:54 +0100 Subject: [PATCH] fix: haven't admin permission ask for tenant name --- bin/osts-cli.js | 2 +- bin/osts-utils.js | 20 ++++++++++++++------ package-lock.json | 16 ++++++++-------- src/osts-cli.ts | 2 +- src/osts-utils.ts | 27 ++++++++++++++++++++------- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/bin/osts-cli.js b/bin/osts-cli.js index 489cdfa..678e6f8 100644 --- a/bin/osts-cli.js +++ b/bin/osts-cli.js @@ -13,7 +13,7 @@ ${chalk.blue("osts-cli version: ")}${chalk.bgBlue(version)} Usage: ======== -osts list[--path] // list OSTS packages in SPO path. +osts list [--path] // list OSTS packages in SPO path. osts unpack [--path, -p [--dts] ] // download OSTS package and extract body (.ts) to dest dir (default '${DEFAULT_PATH}'). // If --dts is specified an Office Script Simplified TS Declaration file will be copied in dest dir diff --git a/bin/osts-utils.js b/bin/osts-utils.js index 894c6bf..c078742 100644 --- a/bin/osts-utils.js +++ b/bin/osts-utils.js @@ -102,7 +102,7 @@ export async function copyOfficeScriptSimplifiedDeclaration(bodyDirPath) { export async function listOfficeScript(prefs) { const list_parameters = [ '--webUrl', prefs.weburl, - '--folder', prefs.folder, + '--folderUrl', prefs.folder, '--query', "[?ends_with(Name, '.osts')]", '--recursive' ]; @@ -119,10 +119,18 @@ export const getWebUrl = async () => { const args = [ '--query', `[?Owner=='${status.connectedAs}'].Url | [0]` ]; - const cmd_list = await $ `m365 onedrive list ${args}`.quiet(); - const url = JSON.parse(cmd_list.stdout); - if (url === null) { - throw `Owner '${status.connectedAs}' not found!`; + try { + const cmd_list = await $ `m365 onedrive list ${args}`.quiet(); + const url = JSON.parse(cmd_list.stdout); + if (url === null) { + throw `Owner '${status.connectedAs}' not found!`; + } + return url; + } + catch (e) { + const tenant = await question(`give me tenant name: `); + const url = `https://${tenant}-my.sharepoint.com/personal/${status.connectedAs.replace(/[.@]/g, '_')}`; + // console.debug( 'url', url) + return url; } - return url; }; diff --git a/package-lock.json b/package-lock.json index cf5e374..07559a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bsorrentino/osts-cli", - "version": "1.2.0", + "version": "1.3.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@bsorrentino/osts-cli", - "version": "1.2.0", + "version": "1.3.4", "license": "MIT", "dependencies": { "minimist": "^1.2.8", @@ -86,9 +86,9 @@ "integrity": "sha512-vVmHeo4tpF8zsknALU90Hh24VueYdu45ZlXzYWFbom61YR4avJqTFDC3QlWzjuTdAv6/3xHaxiO9NrtVZXrkmw==" }, "node_modules/@types/office-js": { - "version": "1.0.344", - "resolved": "https://registry.npmjs.org/@types/office-js/-/office-js-1.0.344.tgz", - "integrity": "sha512-BYOvioBTLUcLrCp2eDDiDZ818dEnZwKeP6gpql3ulufM7b4HcrPRwoxZ86Xjzy6WPVZDX5MFauXTKwhNO4+2MA==", + "version": "1.0.364", + "resolved": "https://registry.npmjs.org/@types/office-js/-/office-js-1.0.364.tgz", + "integrity": "sha512-sEoI3Rhtyz83WjMo3GamshNU7/j8CNY/UVrSVr3n6yOTWo6eG94pZvT4f00g0bvOYlY7Wi+OTZWEqY+MtQ81MQ==", "dev": true }, "node_modules/@types/ps-tree": { @@ -705,9 +705,9 @@ "integrity": "sha512-vVmHeo4tpF8zsknALU90Hh24VueYdu45ZlXzYWFbom61YR4avJqTFDC3QlWzjuTdAv6/3xHaxiO9NrtVZXrkmw==" }, "@types/office-js": { - "version": "1.0.344", - "resolved": "https://registry.npmjs.org/@types/office-js/-/office-js-1.0.344.tgz", - "integrity": "sha512-BYOvioBTLUcLrCp2eDDiDZ818dEnZwKeP6gpql3ulufM7b4HcrPRwoxZ86Xjzy6WPVZDX5MFauXTKwhNO4+2MA==", + "version": "1.0.364", + "resolved": "https://registry.npmjs.org/@types/office-js/-/office-js-1.0.364.tgz", + "integrity": "sha512-sEoI3Rhtyz83WjMo3GamshNU7/j8CNY/UVrSVr3n6yOTWo6eG94pZvT4f00g0bvOYlY7Wi+OTZWEqY+MtQ81MQ==", "dev": true }, "@types/ps-tree": { diff --git a/src/osts-cli.ts b/src/osts-cli.ts index 459331d..eb0d937 100644 --- a/src/osts-cli.ts +++ b/src/osts-cli.ts @@ -18,7 +18,7 @@ ${chalk.blue("osts-cli version: ")}${chalk.bgBlue(version)} Usage: ======== -osts list[--path] // list OSTS packages in SPO path. +osts list [--path] // list OSTS packages in SPO path. osts unpack [--path, -p [--dts] ] // download OSTS package and extract body (.ts) to dest dir (default '${DEFAULT_PATH}'). // If --dts is specified an Office Script Simplified TS Declaration file will be copied in dest dir diff --git a/src/osts-utils.ts b/src/osts-utils.ts index f717f6d..db6d105 100644 --- a/src/osts-utils.ts +++ b/src/osts-utils.ts @@ -180,10 +180,11 @@ export async function copyOfficeScriptSimplifiedDeclaration( bodyDirPath:string const list_parameters = [ '--webUrl', prefs.weburl, - '--folder', prefs.folder, + '--folderUrl', prefs.folder, '--query', "[?ends_with(Name, '.osts')]", '--recursive' ] + const result = await $`m365 spo file list ${list_parameters}`.quiet() const spoFileListResult = JSON.parse( result.stdout ) as Array @@ -211,13 +212,25 @@ export const getWebUrl = async () => { '--query', `[?Owner=='${status.connectedAs}'].Url | [0]` ] - const cmd_list = await $`m365 onedrive list ${args}`.quiet() - - const url = JSON.parse(cmd_list.stdout) + try { + const cmd_list = await $`m365 onedrive list ${args}`.quiet() - if( url === null ) { - throw `Owner '${status.connectedAs}' not found!` + const url = JSON.parse(cmd_list.stdout) + + if( url === null ) { + throw `Owner '${status.connectedAs}' not found!` + } + + return url + } + catch( e ) { + + const tenant = await question( `give me tenant name: `) - return url + const url = `https://${tenant}-my.sharepoint.com/personal/${status.connectedAs.replace(/[.@]/g, '_')}` + + // console.debug( 'url', url) + return url + } } \ No newline at end of file