@rockcarver/frodo-cli 0.19.0 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.19.2] - 2022-12-30
11
+
12
+ ## [0.19.1] - 2022-12-20
13
+
14
+ ### Fixed
15
+
16
+ - \#161: Frodo now properly allows adding connection profiles with log credentials
17
+
10
18
  ## [0.19.0] - 2022-12-18
11
19
 
12
20
  ### Added
@@ -823,7 +831,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
823
831
  - Fixed problem with adding connection profiles
824
832
  - Miscellaneous bug fixes
825
833
 
826
- [Unreleased]: https://github.com/rockcarver/frodo-cli/compare/v0.19.0...HEAD
834
+ [Unreleased]: https://github.com/rockcarver/frodo-cli/compare/v0.19.2...HEAD
835
+
836
+ [0.19.2]: https://github.com/rockcarver/frodo-cli/compare/v0.19.1...v0.19.2
837
+
838
+ [0.19.1]: https://github.com/rockcarver/frodo-cli/compare/v0.19.0...v0.19.1
827
839
 
828
840
  [0.19.0]: https://github.com/rockcarver/frodo-cli/compare/v0.18.2-18...v0.19.0
829
841
 
@@ -111,9 +111,16 @@ export class FrodoCommand extends FrodoStubCommand {
111
111
 
112
112
  // handle arguments first
113
113
  for (const [i, v] of command.args.entries()) {
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- const handler = stateMap[command._args[i].name()];
116
- handler(v);
114
+ const arg = command._args[i].name();
115
+ // handle only default arguments
116
+ if (Object.keys(stateMap).includes(arg)) {
117
+ debugMessage(`FrodoCommand.handleDefaultArgsAndOpts: Handling default argument '${arg}'.`);
118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
+ const handler = stateMap[arg];
120
+ handler(v);
121
+ } else {
122
+ debugMessage(`FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default argument '${arg}'.`);
123
+ }
117
124
  }
118
125
 
119
126
  // handle options
@@ -1 +1 @@
1
- {"version":3,"file":"FrodoCommand.js","names":["Argument","Command","Option","globalConfig","state","fs","printMessage","createProgressIndicator","updateProgressIndicator","stopProgressIndicator","verboseMessage","debugMessage","curlirizeMessage","hostArgument","realmArgument","default","process","env","FRODO_REALM","DEFAULT_REALM_KEY","usernameArgument","passwordArgument","serviceAccountIdOption","serviceAccountJwkFileOption","deploymentOption","choices","DEPLOYMENT_TYPES","insecureOption","verboseOption","debugOption","curlirizeOption","defaultArgs","defaultOpts","stateMap","name","setHost","setRealm","setUsername","setPassword","attributeName","setServiceAccountId","file","data","readFileSync","jwk","JSON","parse","toString","setServiceAccountJwk","error","message","setDeploymentType","setAllowInsecureConnection","setVerbose","setDebug","setCurlirize","FrodoStubCommand","constructor","helpOption","showHelpAfterError","configureHelp","sortSubcommands","sortOptions","setPrintHandler","setVerboseHandler","setDebugHandler","setCurlirizeHandler","setCreateProgressHandler","setUpdateProgressHandler","setStopProgressHandler","FrodoCommand","omits","arg","includes","addArgument","opt","addOption","handleDefaultArgsAndOpts","args","command","pop","options","i","v","entries","handler","_args","k","Object","keys"],"sources":["cli/FrodoCommand.ts"],"sourcesContent":["import { Argument, Command, Option } from 'commander';\nimport * as globalConfig from '../storage/StaticStorage';\nimport { state } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport {\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n verboseMessage,\n debugMessage,\n curlirizeMessage,\n} from '../utils/Console.js';\n\nconst hostArgument = new Argument(\n '[host]',\n 'Access Management base URL, e.g.: https://cdk.iam.example.com/am. To use a connection profile, just specify a unique substring.'\n);\n\nconst realmArgument = new Argument(\n '[realm]',\n \"Realm. Specify realm as '/' for the root realm or 'realm' or '/parent/child' otherwise.\"\n).default(\n // must check for FRODO_REALM env variable here because otherwise cli will overwrite realm with default value\n process.env.FRODO_REALM || globalConfig.DEFAULT_REALM_KEY,\n '\"alpha\" for Identity Cloud tenants, \"/\" otherwise.'\n);\n\nconst usernameArgument = new Argument(\n '[username]',\n 'Username to login with. Must be an admin user with appropriate rights to manage authentication journeys/trees.'\n);\n\nconst passwordArgument = new Argument('[password]', 'Password.');\n\nconst serviceAccountIdOption = new Option(\n '--sa-id <sa-id>',\n 'Service account id.'\n);\n\nconst serviceAccountJwkFileOption = new Option(\n '--sa-jwk-file <file>',\n 'File containing the java web key (jwk) associated with the the service account.'\n);\n\nconst deploymentOption = new Option(\n '-m, --type <type>',\n 'Override auto-detected deployment type. Valid values for type: \\n\\\nclassic: A classic Access Management-only deployment with custom layout and configuration. \\n\\\ncloud: A ForgeRock Identity Cloud environment. \\n\\\nforgeops: A ForgeOps CDK or CDM deployment. \\n\\\nThe detected or provided deployment type controls certain behavior like obtaining an Identity \\\nManagement admin token or not and whether to export/import referenced email templates or how \\\nto walk through the tenant admin login flow of Identity Cloud and handle MFA'\n).choices(globalConfig.DEPLOYMENT_TYPES);\n\nconst insecureOption = new Option(\n '-k, --insecure',\n 'Allow insecure connections when using SSL/TLS. Has no effect when using a network proxy for https (HTTPS_PROXY=http://<host>:<port>), in that case the proxy must provide this capability.'\n).default(false, \"Don't allow insecure connections\");\n\nconst verboseOption = new Option(\n '--verbose',\n 'Verbose output during command execution. If specified, may or may not produce additional output.'\n);\n\nconst debugOption = new Option(\n '--debug',\n 'Debug output during command execution. If specified, may or may not produce additional output helpful for troubleshooting.'\n);\n\nconst curlirizeOption = new Option(\n '--curlirize',\n 'Output all network calls in curl format.'\n);\n\nconst defaultArgs = [\n hostArgument,\n realmArgument,\n usernameArgument,\n passwordArgument,\n];\n\nconst defaultOpts = [\n serviceAccountIdOption,\n serviceAccountJwkFileOption,\n deploymentOption,\n insecureOption,\n verboseOption,\n debugOption,\n curlirizeOption,\n];\n\nconst stateMap = {\n [hostArgument.name()]: state.setHost,\n [realmArgument.name()]: state.setRealm,\n [usernameArgument.name()]: state.setUsername,\n [passwordArgument.name()]: state.setPassword,\n [serviceAccountIdOption.attributeName()]: state.setServiceAccountId,\n [serviceAccountJwkFileOption.attributeName()]: (file) => {\n try {\n const data = fs.readFileSync(file);\n const jwk = JSON.parse(data.toString());\n state.setServiceAccountJwk(jwk);\n } catch (error) {\n printMessage(\n `Error parsing JWK from file ${file}: ${error.message}`,\n 'error'\n );\n }\n },\n [deploymentOption.attributeName()]: state.setDeploymentType,\n [insecureOption.attributeName()]: state.setAllowInsecureConnection,\n [verboseOption.attributeName()]: state.setVerbose,\n [debugOption.attributeName()]: state.setDebug,\n [curlirizeOption.attributeName()]: state.setCurlirize,\n};\n\n/**\n * Command with default options\n */\nexport class FrodoStubCommand extends Command {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string) {\n super(name);\n\n // other default settings\n this.helpOption('-h, --help', 'Help');\n this.showHelpAfterError();\n this.configureHelp({\n sortSubcommands: true,\n sortOptions: true,\n });\n\n // register default handlers\n state.setPrintHandler(printMessage);\n state.setVerboseHandler(verboseMessage);\n state.setDebugHandler(debugMessage);\n state.setCurlirizeHandler(curlirizeMessage);\n state.setCreateProgressHandler(createProgressIndicator);\n state.setUpdateProgressHandler(updateProgressIndicator);\n state.setStopProgressHandler(stopProgressIndicator);\n }\n}\n\n/**\n * Command with default options\n */\nexport class FrodoCommand extends FrodoStubCommand {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string, omits: string[] = []) {\n super(name);\n\n // register default arguments\n for (const arg of defaultArgs) {\n if (!omits.includes(arg.name())) this.addArgument(arg);\n }\n\n // register default options\n for (const opt of defaultOpts) {\n if (!omits.includes(opt.name())) this.addOption(opt);\n }\n }\n\n /**\n *\n * @param args\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handleDefaultArgsAndOpts(...args: any) {\n const command = args.pop();\n const options = args.pop();\n\n // handle arguments first\n for (const [i, v] of command.args.entries()) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[command._args[i].name()];\n handler(v);\n }\n\n // handle options\n for (const [k, v] of Object.entries(options)) {\n // handle only default options\n if (Object.keys(stateMap).includes(k)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default option '${k}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[k];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default option '${k}'.`\n );\n }\n }\n }\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,MAAM,QAAQ,WAAW;AACrD,OAAO,KAAKC,YAAY,MAAM,0BAA0B;AACxD,SAASC,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SACEC,YAAY,EACZC,uBAAuB,EACvBC,uBAAuB,EACvBC,qBAAqB,EACrBC,cAAc,EACdC,YAAY,EACZC,gBAAgB,QACX,qBAAqB;AAE5B,MAAMC,YAAY,GAAG,IAAIb,QAAQ,CAC/B,QAAQ,EACR,iIAAiI,CAClI;AAED,MAAMc,aAAa,GAAG,IAAId,QAAQ,CAChC,SAAS,EACT,yFAAyF,CAC1F,CAACe,OAAO;AACP;AACAC,OAAO,CAACC,GAAG,CAACC,WAAW,IAAIf,YAAY,CAACgB,iBAAiB,EACzD,oDAAoD,CACrD;AAED,MAAMC,gBAAgB,GAAG,IAAIpB,QAAQ,CACnC,YAAY,EACZ,gHAAgH,CACjH;AAED,MAAMqB,gBAAgB,GAAG,IAAIrB,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;AAEhE,MAAMsB,sBAAsB,GAAG,IAAIpB,MAAM,CACvC,iBAAiB,EACjB,qBAAqB,CACtB;AAED,MAAMqB,2BAA2B,GAAG,IAAIrB,MAAM,CAC5C,sBAAsB,EACtB,iFAAiF,CAClF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CAAC,EAAE;QACrC5E,YAAY,CACT,mEAAkE4E,CAAE,IAAG,CACzE;QACD;QACA,MAAMF,OAAY,GAAGpD,QAAQ,CAACsD,CAAC,CAAC;QAChCF,OAAO,CAACF,CAAC,CAAC;MACZ,CAAC,MAAM;QACLxE,YAAY,CACT,uEAAsE4E,CAAE,IAAG,CAC7E;MACH;IACF;EACF;AACF"}
1
+ {"version":3,"file":"FrodoCommand.js","names":["Argument","Command","Option","globalConfig","state","fs","printMessage","createProgressIndicator","updateProgressIndicator","stopProgressIndicator","verboseMessage","debugMessage","curlirizeMessage","hostArgument","realmArgument","default","process","env","FRODO_REALM","DEFAULT_REALM_KEY","usernameArgument","passwordArgument","serviceAccountIdOption","serviceAccountJwkFileOption","deploymentOption","choices","DEPLOYMENT_TYPES","insecureOption","verboseOption","debugOption","curlirizeOption","defaultArgs","defaultOpts","stateMap","name","setHost","setRealm","setUsername","setPassword","attributeName","setServiceAccountId","file","data","readFileSync","jwk","JSON","parse","toString","setServiceAccountJwk","error","message","setDeploymentType","setAllowInsecureConnection","setVerbose","setDebug","setCurlirize","FrodoStubCommand","constructor","helpOption","showHelpAfterError","configureHelp","sortSubcommands","sortOptions","setPrintHandler","setVerboseHandler","setDebugHandler","setCurlirizeHandler","setCreateProgressHandler","setUpdateProgressHandler","setStopProgressHandler","FrodoCommand","omits","arg","includes","addArgument","opt","addOption","handleDefaultArgsAndOpts","args","command","pop","options","i","v","entries","_args","Object","keys","handler","k"],"sources":["cli/FrodoCommand.ts"],"sourcesContent":["import { Argument, Command, Option } from 'commander';\nimport * as globalConfig from '../storage/StaticStorage';\nimport { state } from '@rockcarver/frodo-lib';\nimport fs from 'fs';\nimport {\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n verboseMessage,\n debugMessage,\n curlirizeMessage,\n} from '../utils/Console.js';\n\nconst hostArgument = new Argument(\n '[host]',\n 'Access Management base URL, e.g.: https://cdk.iam.example.com/am. To use a connection profile, just specify a unique substring.'\n);\n\nconst realmArgument = new Argument(\n '[realm]',\n \"Realm. Specify realm as '/' for the root realm or 'realm' or '/parent/child' otherwise.\"\n).default(\n // must check for FRODO_REALM env variable here because otherwise cli will overwrite realm with default value\n process.env.FRODO_REALM || globalConfig.DEFAULT_REALM_KEY,\n '\"alpha\" for Identity Cloud tenants, \"/\" otherwise.'\n);\n\nconst usernameArgument = new Argument(\n '[username]',\n 'Username to login with. Must be an admin user with appropriate rights to manage authentication journeys/trees.'\n);\n\nconst passwordArgument = new Argument('[password]', 'Password.');\n\nconst serviceAccountIdOption = new Option(\n '--sa-id <sa-id>',\n 'Service account id.'\n);\n\nconst serviceAccountJwkFileOption = new Option(\n '--sa-jwk-file <file>',\n 'File containing the java web key (jwk) associated with the the service account.'\n);\n\nconst deploymentOption = new Option(\n '-m, --type <type>',\n 'Override auto-detected deployment type. Valid values for type: \\n\\\nclassic: A classic Access Management-only deployment with custom layout and configuration. \\n\\\ncloud: A ForgeRock Identity Cloud environment. \\n\\\nforgeops: A ForgeOps CDK or CDM deployment. \\n\\\nThe detected or provided deployment type controls certain behavior like obtaining an Identity \\\nManagement admin token or not and whether to export/import referenced email templates or how \\\nto walk through the tenant admin login flow of Identity Cloud and handle MFA'\n).choices(globalConfig.DEPLOYMENT_TYPES);\n\nconst insecureOption = new Option(\n '-k, --insecure',\n 'Allow insecure connections when using SSL/TLS. Has no effect when using a network proxy for https (HTTPS_PROXY=http://<host>:<port>), in that case the proxy must provide this capability.'\n).default(false, \"Don't allow insecure connections\");\n\nconst verboseOption = new Option(\n '--verbose',\n 'Verbose output during command execution. If specified, may or may not produce additional output.'\n);\n\nconst debugOption = new Option(\n '--debug',\n 'Debug output during command execution. If specified, may or may not produce additional output helpful for troubleshooting.'\n);\n\nconst curlirizeOption = new Option(\n '--curlirize',\n 'Output all network calls in curl format.'\n);\n\nconst defaultArgs = [\n hostArgument,\n realmArgument,\n usernameArgument,\n passwordArgument,\n];\n\nconst defaultOpts = [\n serviceAccountIdOption,\n serviceAccountJwkFileOption,\n deploymentOption,\n insecureOption,\n verboseOption,\n debugOption,\n curlirizeOption,\n];\n\nconst stateMap = {\n [hostArgument.name()]: state.setHost,\n [realmArgument.name()]: state.setRealm,\n [usernameArgument.name()]: state.setUsername,\n [passwordArgument.name()]: state.setPassword,\n [serviceAccountIdOption.attributeName()]: state.setServiceAccountId,\n [serviceAccountJwkFileOption.attributeName()]: (file) => {\n try {\n const data = fs.readFileSync(file);\n const jwk = JSON.parse(data.toString());\n state.setServiceAccountJwk(jwk);\n } catch (error) {\n printMessage(\n `Error parsing JWK from file ${file}: ${error.message}`,\n 'error'\n );\n }\n },\n [deploymentOption.attributeName()]: state.setDeploymentType,\n [insecureOption.attributeName()]: state.setAllowInsecureConnection,\n [verboseOption.attributeName()]: state.setVerbose,\n [debugOption.attributeName()]: state.setDebug,\n [curlirizeOption.attributeName()]: state.setCurlirize,\n};\n\n/**\n * Command with default options\n */\nexport class FrodoStubCommand extends Command {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string) {\n super(name);\n\n // other default settings\n this.helpOption('-h, --help', 'Help');\n this.showHelpAfterError();\n this.configureHelp({\n sortSubcommands: true,\n sortOptions: true,\n });\n\n // register default handlers\n state.setPrintHandler(printMessage);\n state.setVerboseHandler(verboseMessage);\n state.setDebugHandler(debugMessage);\n state.setCurlirizeHandler(curlirizeMessage);\n state.setCreateProgressHandler(createProgressIndicator);\n state.setUpdateProgressHandler(updateProgressIndicator);\n state.setStopProgressHandler(stopProgressIndicator);\n }\n}\n\n/**\n * Command with default options\n */\nexport class FrodoCommand extends FrodoStubCommand {\n /**\n * Creates a new FrodoCommand instance\n * @param name Name of the command\n * @param omits Array of default argument names and default option names that should not be added to this command\n */\n constructor(name: string, omits: string[] = []) {\n super(name);\n\n // register default arguments\n for (const arg of defaultArgs) {\n if (!omits.includes(arg.name())) this.addArgument(arg);\n }\n\n // register default options\n for (const opt of defaultOpts) {\n if (!omits.includes(opt.name())) this.addOption(opt);\n }\n }\n\n /**\n *\n * @param args\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handleDefaultArgsAndOpts(...args: any) {\n const command = args.pop();\n const options = args.pop();\n\n // handle arguments first\n for (const [i, v] of command.args.entries()) {\n const arg = command._args[i].name();\n // handle only default arguments\n if (Object.keys(stateMap).includes(arg)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default argument '${arg}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[arg];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default argument '${arg}'.`\n );\n }\n }\n\n // handle options\n for (const [k, v] of Object.entries(options)) {\n // handle only default options\n if (Object.keys(stateMap).includes(k)) {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Handling default option '${k}'.`\n );\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const handler: any = stateMap[k];\n handler(v);\n } else {\n debugMessage(\n `FrodoCommand.handleDefaultArgsAndOpts: Ignoring non-default option '${k}'.`\n );\n }\n }\n }\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,MAAM,QAAQ,WAAW;AACrD,OAAO,KAAKC,YAAY,MAAM,0BAA0B;AACxD,SAASC,KAAK,QAAQ,uBAAuB;AAC7C,OAAOC,EAAE,MAAM,IAAI;AACnB,SACEC,YAAY,EACZC,uBAAuB,EACvBC,uBAAuB,EACvBC,qBAAqB,EACrBC,cAAc,EACdC,YAAY,EACZC,gBAAgB,QACX,qBAAqB;AAE5B,MAAMC,YAAY,GAAG,IAAIb,QAAQ,CAC/B,QAAQ,EACR,iIAAiI,CAClI;AAED,MAAMc,aAAa,GAAG,IAAId,QAAQ,CAChC,SAAS,EACT,yFAAyF,CAC1F,CAACe,OAAO;AACP;AACAC,OAAO,CAACC,GAAG,CAACC,WAAW,IAAIf,YAAY,CAAC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C,MAAMZ,GAAG,GAAGO,OAAO,CAACM,KAAK,CAACH,CAAC,CAAC,CAAChD,IAAI,EAAE;MACnC;MACA,IAAIoD,MAAM,CAACC,IAAI,CAACtD,QAAQ,CAAC,CAACwC,QAAQ,CAACD,GAAG,CAAC,EAAE;QACvC7D,YAAY,CACT,qEAAoE6D,GAAI,IAAG,CAC7E;QACD;QACA,MAAMgB,OAAY,GAAGvD,QAAQ,CAACuC,GAAG,CAAC;QAClCgB,OAAO,CAACL,CAAC,CAAC;MACZ,CAAC,MAAM;QACLxE,YAAY,CACT,yEAAwE6D,GAAI,IAAG,CACjF;MACH;IACF;;IAEA;IACA,KAAK,MAAM,CAACiB,CAAC,EAAEN,CAAC,CAAC,IAAIG,MAAM,CAACF,OAAO,CAACH,OAAO,CAAC,EAAE;MAC5C;MACA,IAAIK,MAAM,CAACC,IAAI,CAACtD,QAAQ,CAAC,CAACwC,QAAQ,CAACgB,CAAC,CAAC,EAAE;QACrC9E,YAAY,CACT,mEAAkE8E,CAAE,IAAG,CACzE;QACD;QACA,MAAMD,OAAY,GAAGvD,QAAQ,CAACwD,CAAC,CAAC;QAChCD,OAAO,CAACL,CAAC,CAAC;MACZ,CAAC,MAAM;QACLxE,YAAY,CACT,uEAAsE8E,CAAE,IAAG,CAC7E;MACH;IACF;EACF;AACF"}
@@ -1,15 +1,11 @@
1
1
  import { FrodoCommand } from '../FrodoCommand';
2
2
  import { Option } from 'commander';
3
- import { Authenticate, Idp, state } from '@rockcarver/frodo-lib';
3
+ import { Authenticate, state } from '@rockcarver/frodo-lib';
4
4
  import { printMessage, verboseMessage } from '../../utils/Console';
5
+ import { exportSocialProvidersToFile, exportSocialProvidersToFiles, exportSocialProviderToFile } from '../../ops/IdpOps';
5
6
  const {
6
7
  getTokens
7
8
  } = Authenticate;
8
- const {
9
- exportSocialProviderToFile,
10
- exportSocialProvidersToFile,
11
- exportSocialProvidersToFiles
12
- } = Idp;
13
9
  const program = new FrodoCommand('frodo idp export');
14
10
  program.description('Export (social) identity providers.').addOption(new Option('-i, --idp-id <idp-id>', 'Id/name of a provider. If specified, -a and -A are ignored.')).addOption(new Option('-f, --file [file]', 'Name of the file to write the exported provider(s) to. Ignored with -A.')).addOption(new Option('-a, --all', 'Export all the providers in a realm to a single file. Ignored with -t and -i.')).addOption(new Option('-A, --all-separate', 'Export all the providers in a realm as separate files <provider name>.idp.json. Ignored with -t, -i, and -a.')).action(
15
11
  // implement command logic inside action handler
@@ -1 +1 @@
1
- {"version":3,"file":"idp-export.js","names":["FrodoCommand","Option","Authenticate","Idp","state","printMessage","verboseMessage","getTokens","exportSocialProviderToFile","exportSocialProvidersToFile","exportSocialProvidersToFiles","program","description","addOption","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","idpId","getRealm","file","all","allSeparate","help","process","exitCode","parse"],"sources":["cli/idp/idp-export.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport { Authenticate, Idp, state } from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\n\nconst { getTokens } = Authenticate;\nconst {\n exportSocialProviderToFile,\n exportSocialProvidersToFile,\n exportSocialProvidersToFiles,\n} = Idp;\n\nconst program = new FrodoCommand('frodo idp export');\n\nprogram\n .description('Export (social) identity providers.')\n .addOption(\n new Option(\n '-i, --idp-id <idp-id>',\n 'Id/name of a provider. If specified, -a and -A are ignored.'\n )\n )\n .addOption(\n new Option(\n '-f, --file [file]',\n 'Name of the file to write the exported provider(s) to. Ignored with -A.'\n )\n )\n .addOption(\n new Option(\n '-a, --all',\n 'Export all the providers in a realm to a single file. Ignored with -t and -i.'\n )\n )\n .addOption(\n new Option(\n '-A, --all-separate',\n 'Export all the providers in a realm as separate files <provider name>.idp.json. Ignored with -t, -i, and -a.'\n )\n )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n if (await getTokens()) {\n // export by id/name\n if (options.idpId) {\n verboseMessage(\n `Exporting provider \"${\n options.idpId\n }\" from realm \"${state.getRealm()}\"...`\n );\n exportSocialProviderToFile(options.idpId, options.file);\n }\n // --all -a\n else if (options.all) {\n verboseMessage('Exporting all providers to a single file...');\n exportSocialProvidersToFile(options.file);\n }\n // --all-separate -A\n else if (options.allSeparate) {\n verboseMessage('Exporting all providers to separate files...');\n exportSocialProvidersToFiles();\n }\n // unrecognized combination of options or no options\n else {\n printMessage(\n 'Unrecognized combination of options or no options...',\n 'error'\n );\n program.help();\n process.exitCode = 1;\n }\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,YAAY,EAAEC,GAAG,EAAEC,KAAK,QAAQ,uBAAuB;AAChE,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAElE,MAAM;EAAEC;AAAU,CAAC,GAAGL,YAAY;AAClC,MAAM;EACJM,0BAA0B;EAC1BC,2BAA2B;EAC3BC;AACF,CAAC,GAAGP,GAAG;AAEP,MAAMQ,OAAO,GAAG,IAAIX,YAAY,CAAC,kBAAkB,CAAC;AAEpDW,OAAO,CACJC,WAAW,CAAC,qCAAqC,CAAC,CAClDC,SAAS,CACR,IAAIZ,MAAM,CACR,uBAAuB,EACvB,6DAA6D,CAC9D,CACF,CACAY,SAAS,CACR,IAAIZ,MAAM,CACR,mBAAmB,EACnB,yEAAyE,CAC1E,CACF,CACAY,SAAS,CACR,IAAIZ,MAAM,CACR,WAAW,EACX,+EAA+E,CAChF,CACF,CACAY,SAAS,CACR,IAAIZ,MAAM,CACR,oBAAoB,EACpB,8GAA8G,CAC/G,CACF,CACAa,MAAM;AACL;AACA,OAAOC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,KAAK;EACvDA,OAAO,CAACC,wBAAwB,CAC9BN,IAAI,EACJC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,OAAO,CACR;EACD,IAAI,MAAMb,SAAS,EAAE,EAAE;IACrB;IACA,IAAIY,OAAO,CAACG,KAAK,EAAE;MACjBhB,cAAc,CACX,uBACCa,OAAO,CAACG,KACT,iBAAgBlB,KAAK,CAACmB,QAAQ,EAAG,MAAK,CACxC;MACDf,0BAA0B,CAACW,OAAO,CAACG,KAAK,EAAEH,OAAO,CAACK,IAAI,CAAC;IACzD;IACA;IAAA,KACK,IAAIL,OAAO,CAACM,GAAG,EAAE;MACpBnB,cAAc,CAAC,6CAA6C,CAAC;MAC7DG,2BAA2B,CAACU,OAAO,CAACK,IAAI,CAAC;IAC3C;IACA;IAAA,KACK,IAAIL,OAAO,CAACO,WAAW,EAAE;MAC5BpB,cAAc,CAAC,8CAA8C,CAAC;MAC9DI,4BAA4B,EAAE;IAChC;IACA;IAAA,KACK;MACHL,YAAY,CACV,sDAAsD,EACtD,OAAO,CACR;MACDM,OAAO,CAACgB,IAAI,EAAE;MACdC,OAAO,CAACC,QAAQ,GAAG,CAAC;IACtB;EACF;AACF;AACA;AAAA,CACD;;AAEHlB,OAAO,CAACmB,KAAK,EAAE"}
1
+ {"version":3,"file":"idp-export.js","names":["FrodoCommand","Option","Authenticate","state","printMessage","verboseMessage","exportSocialProvidersToFile","exportSocialProvidersToFiles","exportSocialProviderToFile","getTokens","program","description","addOption","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","idpId","getRealm","file","all","allSeparate","help","process","exitCode","parse"],"sources":["cli/idp/idp-export.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport { Authenticate, state } from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport {\n exportSocialProvidersToFile,\n exportSocialProvidersToFiles,\n exportSocialProviderToFile,\n} from '../../ops/IdpOps';\n\nconst { getTokens } = Authenticate;\n\nconst program = new FrodoCommand('frodo idp export');\n\nprogram\n .description('Export (social) identity providers.')\n .addOption(\n new Option(\n '-i, --idp-id <idp-id>',\n 'Id/name of a provider. If specified, -a and -A are ignored.'\n )\n )\n .addOption(\n new Option(\n '-f, --file [file]',\n 'Name of the file to write the exported provider(s) to. Ignored with -A.'\n )\n )\n .addOption(\n new Option(\n '-a, --all',\n 'Export all the providers in a realm to a single file. Ignored with -t and -i.'\n )\n )\n .addOption(\n new Option(\n '-A, --all-separate',\n 'Export all the providers in a realm as separate files <provider name>.idp.json. Ignored with -t, -i, and -a.'\n )\n )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n if (await getTokens()) {\n // export by id/name\n if (options.idpId) {\n verboseMessage(\n `Exporting provider \"${\n options.idpId\n }\" from realm \"${state.getRealm()}\"...`\n );\n exportSocialProviderToFile(options.idpId, options.file);\n }\n // --all -a\n else if (options.all) {\n verboseMessage('Exporting all providers to a single file...');\n exportSocialProvidersToFile(options.file);\n }\n // --all-separate -A\n else if (options.allSeparate) {\n verboseMessage('Exporting all providers to separate files...');\n exportSocialProvidersToFiles();\n }\n // unrecognized combination of options or no options\n else {\n printMessage(\n 'Unrecognized combination of options or no options...',\n 'error'\n );\n program.help();\n process.exitCode = 1;\n }\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,YAAY,EAAEC,KAAK,QAAQ,uBAAuB;AAC3D,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SACEC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,0BAA0B,QACrB,kBAAkB;AAEzB,MAAM;EAAEC;AAAU,CAAC,GAAGP,YAAY;AAElC,MAAMQ,OAAO,GAAG,IAAIV,YAAY,CAAC,kBAAkB,CAAC;AAEpDU,OAAO,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
1
1
  import { FrodoCommand } from '../FrodoCommand';
2
2
  import { Option } from 'commander';
3
- import { Authenticate, Idp, state } from '@rockcarver/frodo-lib';
3
+ import { Authenticate, state } from '@rockcarver/frodo-lib';
4
4
  import { printMessage, verboseMessage } from '../../utils/Console';
5
+ import { importFirstSocialProviderFromFile, importSocialProviderFromFile, importSocialProvidersFromFile, importSocialProvidersFromFiles } from '../../ops/IdpOps';
5
6
  const {
6
7
  getTokens
7
8
  } = Authenticate;
8
- const {
9
- importSocialProviderFromFile,
10
- importFirstSocialProviderFromFile,
11
- importSocialProvidersFromFile,
12
- importSocialProvidersFromFiles
13
- } = Idp;
14
9
  const program = new FrodoCommand('frodo idp import');
15
10
  program.description('Import (social) identity providers.').addOption(new Option('-i, --idp-id <id>', 'Provider id. If specified, -a and -A are ignored.')).addOption(new Option('-f, --file <file>', 'Name of the file to import the provider(s) from.')).addOption(new Option('-a, --all', 'Import all the providers from single file. Ignored with -t or -i.')).addOption(new Option('-A, --all-separate', 'Import all the providers from separate files (*.json) in the current directory. Ignored with -t or -i or -a.')).action(
16
11
  // implement command logic inside action handler
@@ -1 +1 @@
1
- {"version":3,"file":"idp-import.js","names":["FrodoCommand","Option","Authenticate","Idp","state","printMessage","verboseMessage","getTokens","importSocialProviderFromFile","importFirstSocialProviderFromFile","importSocialProvidersFromFile","importSocialProvidersFromFiles","program","description","addOption","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","file","idpId","getRealm","all","allSeparate","help","process","exitCode","parse"],"sources":["cli/idp/idp-import.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport { Authenticate, Idp, state } from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\n\nconst { getTokens } = Authenticate;\nconst {\n importSocialProviderFromFile,\n importFirstSocialProviderFromFile,\n importSocialProvidersFromFile,\n importSocialProvidersFromFiles,\n} = Idp;\n\nconst program = new FrodoCommand('frodo idp import');\n\nprogram\n .description('Import (social) identity providers.')\n .addOption(\n new Option(\n '-i, --idp-id <id>',\n 'Provider id. If specified, -a and -A are ignored.'\n )\n )\n .addOption(\n new Option(\n '-f, --file <file>',\n 'Name of the file to import the provider(s) from.'\n )\n )\n .addOption(\n new Option(\n '-a, --all',\n 'Import all the providers from single file. Ignored with -t or -i.'\n )\n )\n .addOption(\n new Option(\n '-A, --all-separate',\n 'Import all the providers from separate files (*.json) in the current directory. Ignored with -t or -i or -a.'\n )\n )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n // import by id\n if (options.file && options.idpId && (await getTokens())) {\n verboseMessage(\n `Importing provider \"${\n options.idpId\n }\" into realm \"${state.getRealm()}\"...`\n );\n importSocialProviderFromFile(options.idpId, options.file);\n }\n // --all -a\n else if (options.all && options.file && (await getTokens())) {\n verboseMessage(\n `Importing all providers from a single file (${options.file})...`\n );\n importSocialProvidersFromFile(options.file);\n }\n // --all-separate -A\n else if (options.allSeparate && !options.file && (await getTokens())) {\n verboseMessage(\n 'Importing all providers from separate files in current directory...'\n );\n importSocialProvidersFromFiles();\n }\n // import first provider from file\n else if (options.file && (await getTokens())) {\n verboseMessage(\n `Importing first provider from file \"${\n options.file\n }\" into realm \"${state.getRealm()}\"...`\n );\n importFirstSocialProviderFromFile(options.file);\n }\n // unrecognized combination of options or no options\n else {\n printMessage('Unrecognized combination of options or no options...');\n program.help();\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,YAAY,EAAEC,GAAG,EAAEC,KAAK,QAAQ,uBAAuB;AAChE,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAElE,MAAM;EAAEC;AAAU,CAAC,GAAGL,YAAY;AAClC,MAAM;EACJM,4BAA4B;EAC5BC,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AE,CAAC,EAAE;IACpED,cAAc,CACZ,qEAAqE,CACtE;IACDK,8BAA8B,EAAE;EAClC;EACA;EAAA,KACK,IAAIS,OAAO,CAACG,IAAI,KAAK,MAAMhB,SAAS,EAAE,CAAC,EAAE;IAC5CD,cAAc,CACX,uCACCc,OAAO,CAACG,IACT,iBAAgBnB,KAAK,CAACqB,QAAQ,EAAG,MAAK,CACxC;IACDhB,iCAAiC,CAACW,OAAO,CAACG,IAAI,CAAC;EACjD;EACA;EAAA,KACK;IACHlB,YAAY,CAAC,sDAAsD,CAAC;IACpEO,OAAO,CAACgB,IAAI,EAAE;IACdC,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AAAA,CACD;;AAEHlB,OAAO,CAACmB,KAAK,EAAE"}
1
+ {"version":3,"file":"idp-import.js","names":["FrodoCommand","Option","Authenticate","state","printMessage","verboseMessage","importFirstSocialProviderFromFile","importSocialProviderFromFile","importSocialProvidersFromFile","importSocialProvidersFromFiles","getTokens","program","description","addOption","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","file","idpId","getRealm","all","allSeparate","help","process","exitCode","parse"],"sources":["cli/idp/idp-import.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Option } from 'commander';\nimport { Authenticate, state } from '@rockcarver/frodo-lib';\nimport { printMessage, verboseMessage } from '../../utils/Console';\nimport {\n importFirstSocialProviderFromFile,\n importSocialProviderFromFile,\n importSocialProvidersFromFile,\n importSocialProvidersFromFiles,\n} from '../../ops/IdpOps';\n\nconst { getTokens } = Authenticate;\n\nconst program = new FrodoCommand('frodo idp import');\n\nprogram\n .description('Import (social) identity providers.')\n .addOption(\n new Option(\n '-i, --idp-id <id>',\n 'Provider id. If specified, -a and -A are ignored.'\n )\n )\n .addOption(\n new Option(\n '-f, --file <file>',\n 'Name of the file to import the provider(s) from.'\n )\n )\n .addOption(\n new Option(\n '-a, --all',\n 'Import all the providers from single file. Ignored with -t or -i.'\n )\n )\n .addOption(\n new Option(\n '-A, --all-separate',\n 'Import all the providers from separate files (*.json) in the current directory. Ignored with -t or -i or -a.'\n )\n )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n // import by id\n if (options.file && options.idpId && (await getTokens())) {\n verboseMessage(\n `Importing provider \"${\n options.idpId\n }\" into realm \"${state.getRealm()}\"...`\n );\n importSocialProviderFromFile(options.idpId, options.file);\n }\n // --all -a\n else if (options.all && options.file && (await getTokens())) {\n verboseMessage(\n `Importing all providers from a single file (${options.file})...`\n );\n importSocialProvidersFromFile(options.file);\n }\n // --all-separate -A\n else if (options.allSeparate && !options.file && (await getTokens())) {\n verboseMessage(\n 'Importing all providers from separate files in current directory...'\n );\n importSocialProvidersFromFiles();\n }\n // import first provider from file\n else if (options.file && (await getTokens())) {\n verboseMessage(\n `Importing first provider from file \"${\n options.file\n }\" into realm \"${state.getRealm()}\"...`\n );\n importFirstSocialProviderFromFile(options.file);\n }\n // unrecognized combination of options or no options\n else {\n printMessage('Unrecognized combination of options or no options...');\n program.help();\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,YAAY,EAAEC,KAAK,QAAQ,uBAAuB;AAC3D,SAASC,YAAY,EAAEC,cAAc,QAAQ,qBAAqB;AAClE,SACEC,iCAAiC,EACjCC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,8BAA8B,QACzB,kBAAkB;AAEzB,MAAM;EAAEC;AAAU,CAAC,GAAGR,YAAY;AAElC,MAAMS,OAAO,GAAG,IAAIX,YAAY,CAAC,kBAAkB,CAAC;AAEpDW,OAAO,CACJC,WAAW,CAAC,qCAAqC,CAAC,CAClDC,SAAS,CACR,IAAIZ,MAAM,CACR,mBAAmB,EACnB,mDAAmD,CACpD,CACF,CAC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G,MAAK,CACxC;IACDlB,iCAAiC,CAACa,OAAO,CAACG,IAAI,CAAC;EACjD;EACA;EAAA,KACK;IACHlB,YAAY,CAAC,sDAAsD,CAAC;IACpEO,OAAO,CAACgB,IAAI,EAAE;IACdC,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AAAA,CACD;;AAEHlB,OAAO,CAACmB,KAAK,EAAE"}
@@ -1,12 +1,10 @@
1
1
  import { FrodoCommand } from '../FrodoCommand';
2
- import { Authenticate, Idp, state } from '@rockcarver/frodo-lib';
2
+ import { Authenticate, state } from '@rockcarver/frodo-lib';
3
3
  import { verboseMessage } from '../../utils/Console';
4
+ import { listSocialProviders } from '../../ops/IdpOps';
4
5
  const {
5
6
  getTokens
6
7
  } = Authenticate;
7
- const {
8
- listSocialProviders
9
- } = Idp;
10
8
  const program = new FrodoCommand('frodo idp list');
11
9
  program.description('List (social) identity providers.')
12
10
  // .addOption(
@@ -1 +1 @@
1
- {"version":3,"file":"idp-list.js","names":["FrodoCommand","Authenticate","Idp","state","verboseMessage","getTokens","listSocialProviders","program","description","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","getRealm","process","exitCode","parse"],"sources":["cli/idp/idp-list.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Authenticate, Idp, state } from '@rockcarver/frodo-lib';\nimport { verboseMessage } from '../../utils/Console';\n\nconst { getTokens } = Authenticate;\nconst { listSocialProviders } = Idp;\n\nconst program = new FrodoCommand('frodo idp list');\n\nprogram\n .description('List (social) identity providers.')\n // .addOption(\n // new Option('-l, --long', 'Long with all fields.').default(false, 'false')\n // )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n if (await getTokens()) {\n verboseMessage(`Listing providers in realm \"${state.getRealm()}\"...`);\n listSocialProviders();\n } else {\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,YAAY,EAAEC,GAAG,EAAEC,KAAK,QAAQ,uBAAuB;AAChE,SAASC,cAAc,QAAQ,qBAAqB;AAEpD,MAAM;EAAEC;AAAU,CAAC,GAAGJ,YAAY;AAClC,MAAM;EAAEK;AAAoB,CAAC,GAAGJ,GAAG;AAEnC,MAAMK,OAAO,GAAG,IAAIP,YAAY,CAAC,gBAAgB,CAAC;AAElDO,OAAO,CACJC,WAAW,CAAC,mCAAmC;AAChD;AACA;AACA;AAAA,CACCC,MAAM;AACL;AACA,OAAOC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,KAAK;EACvDA,OAAO,CAACC,wBAAwB,CAC9BN,IAAI,EACJC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,OAAO,CACR;EACD,IAAI,MAAMV,SAAS,EAAE,EAAE;IACrBD,cAAc,CAAE,+BAA8BD,KAAK,CAACc,QAAQ,EAAG,MAAK,CAAC;IACrEX,mBAAmB,EAAE;EACvB,CAAC,MAAM;IACLY,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AAAA,CACD;;AAEHZ,OAAO,CAACa,KAAK,EAAE"}
1
+ {"version":3,"file":"idp-list.js","names":["FrodoCommand","Authenticate","state","verboseMessage","listSocialProviders","getTokens","program","description","action","host","realm","user","password","options","command","handleDefaultArgsAndOpts","getRealm","process","exitCode","parse"],"sources":["cli/idp/idp-list.ts"],"sourcesContent":["import { FrodoCommand } from '../FrodoCommand';\nimport { Authenticate, state } from '@rockcarver/frodo-lib';\nimport { verboseMessage } from '../../utils/Console';\nimport { listSocialProviders } from '../../ops/IdpOps';\n\nconst { getTokens } = Authenticate;\n\nconst program = new FrodoCommand('frodo idp list');\n\nprogram\n .description('List (social) identity providers.')\n // .addOption(\n // new Option('-l, --long', 'Long with all fields.').default(false, 'false')\n // )\n .action(\n // implement command logic inside action handler\n async (host, realm, user, password, options, command) => {\n command.handleDefaultArgsAndOpts(\n host,\n realm,\n user,\n password,\n options,\n command\n );\n if (await getTokens()) {\n verboseMessage(`Listing providers in realm \"${state.getRealm()}\"...`);\n listSocialProviders();\n } else {\n process.exitCode = 1;\n }\n }\n // end command logic inside action handler\n );\n\nprogram.parse();\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,YAAY,EAAEC,KAAK,QAAQ,uBAAuB;AAC3D,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,mBAAmB,QAAQ,kBAAkB;AAEtD,MAAM;EAAEC;AAAU,CAAC,GAAGJ,YAAY;AAElC,MAAMK,OAAO,GAAG,IAAIN,YAAY,CAAC,gBAAgB,CAAC;AAElDM,OAAO,CACJC,WAAW,CAAC,mCAAmC;AAChD;AACA;AACA;AAAA,CACCC,MAAM;AACL;AACA,OAAOC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,KAAK;EACvDA,OAAO,CAACC,wBAAwB,CAC9BN,IAAI,EACJC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,OAAO,CACR;EACD,IAAI,MAAMT,SAAS,EAAE,EAAE;IACrBF,cAAc,CAAE,+BAA8BD,KAAK,CAACc,QAAQ,EAAG,MAAK,CAAC;IACrEZ,mBAAmB,EAAE;EACvB,CAAC,MAAM;IACLa,OAAO,CAACC,QAAQ,GAAG,CAAC;EACtB;AACF;AACA;AAAA,CACD;;AAEHZ,OAAO,CAACa,KAAK,EAAE"}
package/esm/ops/IdpOps.js CHANGED
@@ -1,3 +1,16 @@
1
+ import fs from 'fs';
2
+ import { Idp } from '@rockcarver/frodo-lib';
3
+ import { createProgressBar, failSpinner, printMessage, showSpinner, stopProgressBar, succeedSpinner, updateProgressBar } from '../utils/Console';
4
+ import { getRealmString, getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
5
+ const {
6
+ getSocialIdentityProviders,
7
+ exportSocialProvider,
8
+ exportSocialProviders,
9
+ importSocialProvider,
10
+ importFirstSocialProvider,
11
+ importSocialProviders
12
+ } = Idp;
13
+
1
14
  /**
2
15
  * Get a one-line description of the social idp object
3
16
  * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe
@@ -28,4 +41,160 @@ export function getTableRowMd(socialIdpObj) {
28
41
  const row = `| ${socialIdpObj._id} | ${socialIdpObj.enabled === false ? ':o: `disabled`' : ':white_check_mark: `enabled`'} | ${socialIdpObj._type.name} |`;
29
42
  return row;
30
43
  }
44
+
45
+ /**
46
+ * List providers
47
+ */
48
+ export async function listSocialProviders() {
49
+ try {
50
+ const providers = await getSocialIdentityProviders();
51
+ providers.sort((a, b) => a._id.localeCompare(b._id));
52
+ providers.forEach(socialIdentityProvider => {
53
+ printMessage(`${socialIdentityProvider._id}`, 'data');
54
+ });
55
+ } catch (err) {
56
+ printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');
57
+ printMessage(err, 'error');
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Export provider by id
63
+ * @param {string} providerId provider id/name
64
+ * @param {string} file optional export file name
65
+ */
66
+ export async function exportSocialProviderToFile(providerId, file = '') {
67
+ let fileName = file;
68
+ if (!fileName) {
69
+ fileName = getTypedFilename(providerId, 'idp');
70
+ }
71
+ createProgressBar(1, `Exporting ${providerId}`);
72
+ try {
73
+ updateProgressBar(`Writing file ${fileName}`);
74
+ const fileData = await exportSocialProvider(providerId);
75
+ saveJsonToFile(fileData, fileName);
76
+ stopProgressBar(`Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`);
77
+ } catch (err) {
78
+ stopProgressBar(`${err}`);
79
+ printMessage(`${err}`, 'error');
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Export all providers
85
+ * @param {string} file optional export file name
86
+ */
87
+ export async function exportSocialProvidersToFile(file = '') {
88
+ let fileName = file;
89
+ if (!fileName) {
90
+ fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');
91
+ }
92
+ const fileData = await exportSocialProviders();
93
+ saveJsonToFile(fileData, fileName);
94
+ }
95
+
96
+ /**
97
+ * Export all providers to individual files
98
+ */
99
+ export async function exportSocialProvidersToFiles() {
100
+ const allIdpsData = await getSocialIdentityProviders();
101
+ // printMessage(allIdpsData, 'data');
102
+ createProgressBar(allIdpsData.length, 'Exporting providers');
103
+ for (const idpData of allIdpsData) {
104
+ updateProgressBar(`Writing provider ${idpData._id}`);
105
+ const fileName = getTypedFilename(idpData._id, 'idp');
106
+ const fileData = await exportSocialProvider(idpData._id);
107
+ saveJsonToFile(fileData, fileName);
108
+ }
109
+ stopProgressBar(`${allIdpsData.length} providers exported.`);
110
+ }
111
+
112
+ /**
113
+ * Import provider by id/name
114
+ * @param {string} providerId provider id/name
115
+ * @param {string} file import file name
116
+ * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise
117
+ */
118
+ export async function importSocialProviderFromFile(providerId, file) {
119
+ let outcome = false;
120
+ showSpinner(`Importing provider ${providerId} from ${file}...`);
121
+ fs.readFile(file, 'utf8', async (err, data) => {
122
+ if (err) throw err;
123
+ try {
124
+ const fileData = JSON.parse(data);
125
+ outcome = await importSocialProvider(providerId, fileData);
126
+ succeedSpinner(`Successfully imported provider ${providerId} from ${file}.`);
127
+ } catch (error) {
128
+ var _error$response;
129
+ failSpinner(`Error importing provider ${providerId} from ${file}.`);
130
+ printMessage(((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || error, 'error');
131
+ }
132
+ });
133
+ return outcome;
134
+ }
135
+
136
+ /**
137
+ * Import first provider from file
138
+ * @param {String} file import file name
139
+ * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise
140
+ */
141
+ export async function importFirstSocialProviderFromFile(file) {
142
+ let outcome = false;
143
+ showSpinner(`Importing first provider from ${file}...`);
144
+ fs.readFile(file, 'utf8', async (err, data) => {
145
+ if (err) throw err;
146
+ try {
147
+ const fileData = JSON.parse(data);
148
+ outcome = await importFirstSocialProvider(fileData);
149
+ succeedSpinner(`Successfully imported first provider from ${file}.`);
150
+ } catch (error) {
151
+ var _error$response2;
152
+ failSpinner(`Error importing first provider from ${file}.`);
153
+ printMessage(((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) || error, 'error');
154
+ }
155
+ });
156
+ return outcome;
157
+ }
158
+
159
+ /**
160
+ * Import all providers from file
161
+ * @param {string} file import file name
162
+ * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise
163
+ */
164
+ export async function importSocialProvidersFromFile(file) {
165
+ let outcome = false;
166
+ showSpinner(`Importing providers from ${file}...`);
167
+ fs.readFile(file, 'utf8', async (err, data) => {
168
+ if (err) throw err;
169
+ try {
170
+ const fileData = JSON.parse(data);
171
+ outcome = await importSocialProviders(fileData);
172
+ succeedSpinner(`Successfully imported providers from ${file}.`);
173
+ } catch (error) {
174
+ var _error$response3;
175
+ failSpinner(`Error importing providers from ${file}.`);
176
+ printMessage(((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data) || error, 'error');
177
+ }
178
+ });
179
+ return outcome;
180
+ }
181
+
182
+ /**
183
+ * Import providers from *.idp.json files in current working directory
184
+ */
185
+ export async function importSocialProvidersFromFiles() {
186
+ const names = fs.readdirSync('.');
187
+ const jsonFiles = names.filter(name => name.toLowerCase().endsWith('.idp.json'));
188
+ createProgressBar(jsonFiles.length, 'Importing providers...');
189
+ let total = 0;
190
+ for (const file of jsonFiles) {
191
+ const data = fs.readFileSync(file, 'utf8');
192
+ const fileData = JSON.parse(data);
193
+ const count = Object.keys(fileData.idp).length;
194
+ total += count;
195
+ await importSocialProviders(fileData);
196
+ updateProgressBar(`Imported ${count} provider(s) from ${file}`);
197
+ }
198
+ stopProgressBar(`Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`);
199
+ }
31
200
  //# sourceMappingURL=IdpOps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IdpOps.js","names":["getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name"],"sources":["ops/IdpOps.ts"],"sourcesContent":["import { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name/Id | Status | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,qBAAqB,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG,KAAK,CAACD,GAAI,EAAC;EACnF,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,gBAAgB,GAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,+BAA+B;EAC3CA,QAAQ,IAAI,6BAA6B;EACzC,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAa,CAACN,YAA+B,EAAU;EACrE,MAAMO,GAAG,GAAI,KAAIP,YAAY,CAACE,GAAI,MAChCF,YAAY,CAACQ,OAAO,KAAK,KAAK,GAC1B,gBAAgB,GAChB,8BACL,MAAKR,YAAY,CAACG,KAAK,CAACM,IAAK,IAAG;EACjC,OAAOF,GAAG;AACZ"}
1
+ {"version":3,"file":"IdpOps.js","names":["fs","Idp","createProgressBar","failSpinner","printMessage","showSpinner","stopProgressBar","succeedSpinner","updateProgressBar","getRealmString","getTypedFilename","saveJsonToFile","getSocialIdentityProviders","exportSocialProvider","exportSocialProviders","importSocialProvider","importFirstSocialProvider","importSocialProviders","getOneLineDescription","socialIdpObj","description","_id","_type","getTableHeaderMd","markdown","getTableRowMd","row","enabled","name","listSocialProviders","providers","sort","a","b","localeCompare","forEach","socialIdentityProvider","err","message","exportSocialProviderToFile","providerId","file","fileName","fileData","exportSocialProvidersToFile","exportSocialProvidersToFiles","allIdpsData","length","idpData","importSocialProviderFromFile","outcome","readFile","data","JSON","parse","error","response","importFirstSocialProviderFromFile","importSocialProvidersFromFile","importSocialProvidersFromFiles","names","readdirSync","jsonFiles","filter","toLowerCase","endsWith","total","readFileSync","count","Object","keys","idp"],"sources":["ops/IdpOps.ts"],"sourcesContent":["import fs from 'fs';\nimport { SocialIdpSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\nimport { Idp } from '@rockcarver/frodo-lib';\nimport {\n createProgressBar,\n failSpinner,\n printMessage,\n showSpinner,\n stopProgressBar,\n succeedSpinner,\n updateProgressBar,\n} from '../utils/Console';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n} from '../utils/ExportImportUtils';\n\nconst {\n getSocialIdentityProviders,\n exportSocialProvider,\n exportSocialProviders,\n importSocialProvider,\n importFirstSocialProvider,\n importSocialProviders,\n} = Idp;\n\n/**\n * Get a one-line description of the social idp object\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(socialIdpObj: SocialIdpSkeleton): string {\n const description = `[${socialIdpObj._id['brightCyan']}] ${socialIdpObj._type._id}`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Name/Id | Status | Type |\\n';\n markdown += '| ------- | ------ | ---- |';\n return markdown;\n}\n\n/**\n * Get a table-row of the social idp in markdown\n * @param {SocialIdpSkeleton} socialIdpObj social idp object to describe\n * @returns {string} a table-row of the social idp in markdown\n */\nexport function getTableRowMd(socialIdpObj: SocialIdpSkeleton): string {\n const row = `| ${socialIdpObj._id} | ${\n socialIdpObj.enabled === false\n ? ':o: `disabled`'\n : ':white_check_mark: `enabled`'\n } | ${socialIdpObj._type.name} |`;\n return row;\n}\n\n/**\n * List providers\n */\nexport async function listSocialProviders() {\n try {\n const providers = await getSocialIdentityProviders();\n providers.sort((a, b) => a._id.localeCompare(b._id));\n providers.forEach((socialIdentityProvider) => {\n printMessage(`${socialIdentityProvider._id}`, 'data');\n });\n } catch (err) {\n printMessage(`listSocialProviders ERROR: ${err.message}`, 'error');\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export provider by id\n * @param {string} providerId provider id/name\n * @param {string} file optional export file name\n */\nexport async function exportSocialProviderToFile(\n providerId: string,\n file = ''\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(providerId, 'idp');\n }\n createProgressBar(1, `Exporting ${providerId}`);\n try {\n updateProgressBar(`Writing file ${fileName}`);\n const fileData = await exportSocialProvider(providerId);\n saveJsonToFile(fileData, fileName);\n stopProgressBar(\n `Exported ${providerId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressBar(`${err}`);\n printMessage(`${err}`, 'error');\n }\n}\n\n/**\n * Export all providers\n * @param {string} file optional export file name\n */\nexport async function exportSocialProvidersToFile(file = '') {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`all${getRealmString()}Providers`, 'idp');\n }\n const fileData = await exportSocialProviders();\n saveJsonToFile(fileData, fileName);\n}\n\n/**\n * Export all providers to individual files\n */\nexport async function exportSocialProvidersToFiles() {\n const allIdpsData = await getSocialIdentityProviders();\n // printMessage(allIdpsData, 'data');\n createProgressBar(allIdpsData.length, 'Exporting providers');\n for (const idpData of allIdpsData) {\n updateProgressBar(`Writing provider ${idpData._id}`);\n const fileName = getTypedFilename(idpData._id, 'idp');\n const fileData = await exportSocialProvider(idpData._id);\n saveJsonToFile(fileData, fileName);\n }\n stopProgressBar(`${allIdpsData.length} providers exported.`);\n}\n\n/**\n * Import provider by id/name\n * @param {string} providerId provider id/name\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if provider was imported successfully, false otherwise\n */\nexport async function importSocialProviderFromFile(\n providerId: string,\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing provider ${providerId} from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await importSocialProvider(providerId, fileData);\n succeedSpinner(\n `Successfully imported provider ${providerId} from ${file}.`\n );\n } catch (error) {\n failSpinner(`Error importing provider ${providerId} from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import first provider from file\n * @param {String} file import file name\n * @returns {Promise<boolean>} true if first provider was imported successfully, false otherwise\n */\nexport async function importFirstSocialProviderFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing first provider from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await importFirstSocialProvider(fileData);\n succeedSpinner(`Successfully imported first provider from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing first provider from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import all providers from file\n * @param {string} file import file name\n * @returns {Promise<boolean>} true if all providers were imported successfully, false otherwise\n */\nexport async function importSocialProvidersFromFile(\n file: string\n): Promise<boolean> {\n let outcome = false;\n showSpinner(`Importing providers from ${file}...`);\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n try {\n const fileData = JSON.parse(data);\n outcome = await importSocialProviders(fileData);\n succeedSpinner(`Successfully imported providers from ${file}.`);\n } catch (error) {\n failSpinner(`Error importing providers from ${file}.`);\n printMessage(error.response?.data || error, 'error');\n }\n });\n return outcome;\n}\n\n/**\n * Import providers from *.idp.json files in current working directory\n */\nexport async function importSocialProvidersFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.idp.json')\n );\n\n createProgressBar(jsonFiles.length, 'Importing providers...');\n let total = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n const count = Object.keys(fileData.idp).length;\n total += count;\n await importSocialProviders(fileData);\n updateProgressBar(`Imported ${count} provider(s) from ${file}`);\n }\n stopProgressBar(\n `Finished importing ${total} provider(s) from ${jsonFiles.length} file(s).`\n );\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAEnB,SAASC,GAAG,QAAQ,uBAAuB;AAC3C,SACEC,iBAAiB,EACjBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,iBAAiB,QACZ,kBAAkB;AACzB,SACEC,cAAc,EACdC,gBAAgB,EAChBC,cAAc,QACT,4BAA4B;AAEnC,MAAM;EACJC,0BAA0B;EAC1BC,oBAAoB;EACpBC,qBAAqB;EACrBC,oBAAoB;EACpBC,yBAAyB;EACzBC;AACF,CAAC,GAAGhB,GAAG;;AAEP;AACA;AACA;AACA;AACA;AACA,OAAO,SAASiB,qBAAqB,CAACC,YAA+B,EAAU;EAC7E,MAAMC,WAAW,GAAI,IAAGD,YAAY,CAACE,GAAG,CAAC,YAAY,CAAE,KAAIF,YAAY,CAACG,KAAK,CAACD,GAAI,EAAC;EACnF,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,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AAI,CAACoC,WAAW,EAAE,CAACC,QAAQ,CAAC,WAAW,CAAC,CACzC;EAED/D,iBAAiB,CAAC4D,SAAS,CAACf,MAAM,EAAE,wBAAwB,CAAC;EAC7D,IAAImB,KAAK,GAAG,CAAC;EACb,KAAK,MAAMzB,IAAI,IAAIqB,SAAS,EAAE;IAC5B,MAAMV,IAAI,GAAGpD,EAAE,CAACmE,YAAY,CAAC1B,IAAI,EAAE,MAAM,CAAC;IAC1C,MAAME,QAAQ,GAAGU,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC;IACjC,MAAMgB,KAAK,GAAGC,MAAM,CAACC,IAAI,CAAC3B,QAAQ,CAAC4B,GAAG,CAAC,CAACxB,MAAM;IAC9CmB,KAAK,IAAIE,KAAK;IACd,MAAMnD,qBAAqB,CAAC0B,QAAQ,CAAC;IACrCnC,iBAAiB,CAAE,YAAW4D,KAAM,qBAAoB3B,IAAK,EAAC,CAAC;EACjE;EACAnC,eAAe,CACZ,sBAAqB4D,KAAM,qBAAoBJ,SAAS,CAACf,MAAO,WAAU,CAC5E;AACH"}
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import slugify from 'slugify';
3
- import { ExportImportUtils } from '@rockcarver/frodo-lib';
3
+ import { ExportImportUtils, state } from '@rockcarver/frodo-lib';
4
4
  import { printMessage } from './Console';
5
5
  const {
6
6
  getMetadata
@@ -17,7 +17,7 @@ export function getTypedFilename(name, type, suffix = 'json') {
17
17
  */
18
18
  export function saveJsonToFile(data, filename) {
19
19
  const exportData = data;
20
- exportData.meta = getMetadata();
20
+ if (!exportData.meta) exportData.meta = getMetadata();
21
21
  fs.writeFile(filename, JSON.stringify(exportData, null, 2), err => {
22
22
  if (err) {
23
23
  return printMessage(`ERROR - can't save ${filename}`, 'error');
@@ -43,4 +43,22 @@ export function saveToFile(type, data, identifier, filename) {
43
43
  return '';
44
44
  });
45
45
  }
46
+
47
+ /*
48
+ * Output str in title case
49
+ *
50
+ * e.g.: 'ALL UPPERCASE AND all lowercase' = 'All Uppercase And All Lowercase'
51
+ */
52
+ export function titleCase(input) {
53
+ const str = input.toString();
54
+ const splitStr = str.toLowerCase().split(' ');
55
+ for (let i = 0; i < splitStr.length; i += 1) {
56
+ splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].slice(1);
57
+ }
58
+ return splitStr.join(' ');
59
+ }
60
+ export function getRealmString() {
61
+ const realm = state.getRealm();
62
+ return realm.split('/').reduce((result, item) => `${result}${titleCase(item)}`, '');
63
+ }
46
64
  //# sourceMappingURL=ExportImportUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExportImportUtils.js","names":["fs","slugify","ExportImportUtils","printMessage","getMetadata","getTypedFilename","name","type","suffix","slug","replace","saveJsonToFile","data","filename","exportData","meta","writeFile","JSON","stringify","err","saveToFile","identifier","Array","isArray","forEach","element"],"sources":["utils/ExportImportUtils.ts"],"sourcesContent":["import fs from 'fs';\nimport slugify from 'slugify';\nimport { ExportImportUtils } from '@rockcarver/frodo-lib';\nimport { printMessage } from './Console';\n\nconst { getMetadata } = ExportImportUtils;\n\nexport function getTypedFilename(name: string, type: string, suffix = 'json') {\n const slug = slugify(name.replace(/^http(s?):\\/\\//, ''));\n return `${slug}.${type}.${suffix}`;\n}\n\n/**\n * Save JSON object to file\n * @param {Object} data data object\n * @param {String} filename file name\n */\nexport function saveJsonToFile(data, filename) {\n const exportData = data;\n exportData.meta = getMetadata();\n fs.writeFile(filename, JSON.stringify(exportData, null, 2), (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${filename}`, 'error');\n }\n return '';\n });\n}\n\nexport function saveToFile(type, data, identifier, filename) {\n const exportData = {};\n exportData['meta'] = getMetadata();\n exportData[type] = {};\n\n if (Array.isArray(data)) {\n data.forEach((element) => {\n exportData[type][element[identifier]] = element;\n });\n } else {\n exportData[type][data[identifier]] = data;\n }\n fs.writeFile(filename, JSON.stringify(exportData, null, 2), (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${type} to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AC,CAACkB,OAAO,CAACJ,UAAU,CAAC,CAAC,GAAGI,OAAO;IACjD,CAAC,CAAC;EACJ,CAAC,MAAM;IACLX,UAAU,CAACP,IAAI,CAAC,CAACK,IAAI,CAACS,UAAU,CAAC,CAAC,GAAGT,IAAI;EAC3C;EACAZ,EAAE,CAACgB,SAAS,CAACH,QAAQ,EAAEI,IAAI,CAACC,SAAS,CAACJ,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,EAAGK,GAAG,IAAK;IACnE,IAAIA,GAAG,EAAE;MACP,OAAOhB,YAAY,CAAE,sBAAqBI,IAAK,UAAS,EAAE,OAAO,CAAC;IACpE;IACA,OAAO,EAAE;EACX,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"ExportImportUtils.js","names":["fs","slugify","ExportImportUtils","state","printMessage","getMetadata","getTypedFilename","name","type","suffix","slug","replace","saveJsonToFile","data","filename","exportData","meta","writeFile","JSON","stringify","err","saveToFile","identifier","Array","isArray","forEach","element","titleCase","input","str","toString","splitStr","toLowerCase","split","i","length","charAt","toUpperCase","slice","join","getRealmString","realm","getRealm","reduce","result","item"],"sources":["utils/ExportImportUtils.ts"],"sourcesContent":["import fs from 'fs';\nimport slugify from 'slugify';\nimport { ExportImportUtils, state } from '@rockcarver/frodo-lib';\nimport { printMessage } from './Console';\n\nconst { getMetadata } = ExportImportUtils;\n\nexport function getTypedFilename(name: string, type: string, suffix = 'json') {\n const slug = slugify(name.replace(/^http(s?):\\/\\//, ''));\n return `${slug}.${type}.${suffix}`;\n}\n\n/**\n * Save JSON object to file\n * @param {Object} data data object\n * @param {String} filename file name\n */\nexport function saveJsonToFile(data, filename) {\n const exportData = data;\n if (!exportData.meta) exportData.meta = getMetadata();\n fs.writeFile(filename, JSON.stringify(exportData, null, 2), (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${filename}`, 'error');\n }\n return '';\n });\n}\n\nexport function saveToFile(type, data, identifier, filename) {\n const exportData = {};\n exportData['meta'] = getMetadata();\n exportData[type] = {};\n\n if (Array.isArray(data)) {\n data.forEach((element) => {\n exportData[type][element[identifier]] = element;\n });\n } else {\n exportData[type][data[identifier]] = data;\n }\n fs.writeFile(filename, JSON.stringify(exportData, null, 2), (err) => {\n if (err) {\n return printMessage(`ERROR - can't save ${type} to file`, 'error');\n }\n return '';\n });\n}\n\n/*\n * Output str in title case\n *\n * e.g.: 'ALL UPPERCASE AND all lowercase' = 'All Uppercase And All Lowercase'\n */\nexport function titleCase(input) {\n const str = input.toString();\n const splitStr = str.toLowerCase().split(' ');\n for (let i = 0; i < splitStr.length; i += 1) {\n splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].slice(1);\n }\n return splitStr.join(' ');\n}\n\nexport function getRealmString() {\n const realm = state.getRealm();\n return realm\n .split('/')\n .reduce((result, item) => `${result}${titleCase(item)}`, '');\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,OAAO,MAAM,SAAS;AAC7B,SAASC,iBAAiB,EAAEC,KAAK,QAAQ,uBAAuB;AAChE,SAASC,YAAY,QAAQ,WAAW;AAExC,MAAM;EAAEC;AAAY,CAAC,GAAGH,iBAAiB;AAEzC,OAAO,SAASI,gBAAgB,CAACC,IAAY,EAAEC,IAAY,EAAEC,MAAM,GAAG,MAAM,EAAE;EAC5E,MAAMC,IAAI,GAAGT,OAAO,CAACM,IAAI,CAACI,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;EACxD,OAAQ,GAAED,IAAK,IAAGF,IAAK,IAAGC,MAAO,EAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,cAAc,CAACC,IAAI,EAAEC,QAAQ,EAAE;EAC7C,MAAMC,UAAU,GAAGF,IAAI;EACvB,IAAI,CAACE,UAAU,CAACC,IAAI,EAAED,UAAU,CAACC,IAAI,GAAGX,WAAW,EAAE;EACrDL,EAAE,CAACiB,SAAS,CAACH,QAAQ,EAAEI,IAAI,CAACC,SAAS,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EA,CAAC,GAAGH,QAAQ,CAACI,MAAM,EAAED,CAAC,IAAI,CAAC,EAAE;IAC3CH,QAAQ,CAACG,CAAC,CAAC,GAAGH,QAAQ,CAACG,CAAC,CAAC,CAACE,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAE,GAAGN,QAAQ,CAACG,CAAC,CAAC,CAACI,KAAK,CAAC,CAAC,CAAC;EAC1E;EACA,OAAOP,QAAQ,CAACQ,IAAI,CAAC,GAAG,CAAC;AAC3B;AAEA,OAAO,SAASC,cAAc,GAAG;EAC/B,MAAMC,KAAK,GAAGtC,KAAK,CAACuC,QAAQ,EAAE;EAC9B,OAAOD,KAAK,CACTR,KAAK,CAAC,GAAG,CAAC,CACVU,MAAM,CAAC,CAACC,MAAM,EAAEC,IAAI,KAAM,GAAED,MAAO,GAAEjB,SAAS,CAACkB,IAAI,CAAE,EAAC,EAAE,EAAE,CAAC;AAChE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rockcarver/frodo-cli",
3
- "version": "0.19.0",
3
+ "version": "0.19.2",
4
4
  "type": "module",
5
5
  "description": "A command line interface to manage ForgeRock Identity Cloud tenants, ForgeOps deployments, and classic deployments.",
6
6
  "keywords": [
@@ -88,7 +88,7 @@
88
88
  ]
89
89
  },
90
90
  "dependencies": {
91
- "@rockcarver/frodo-lib": "0.17.1",
91
+ "@rockcarver/frodo-lib": "0.17.3",
92
92
  "cli-progress": "^3.11.2",
93
93
  "cli-table3": "^0.6.3",
94
94
  "colors": "^1.4.0",