@rockcarver/frodo-lib 0.12.5 → 0.12.6
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 +23 -8
- package/cjs/api/ApiTypes.js +42 -0
- package/cjs/api/ApiTypes.js.map +1 -0
- package/cjs/api/Saml2Api.js +1 -1
- package/cjs/api/Saml2Api.js.map +1 -1
- package/cjs/index.js +9 -1
- package/cjs/index.js.map +1 -1
- package/cjs/ops/CirclesOfTrustOps.js +12 -1
- package/cjs/ops/CirclesOfTrustOps.js.map +1 -1
- package/cjs/ops/EmailTemplateOps.js +12 -0
- package/cjs/ops/EmailTemplateOps.js.map +1 -1
- package/cjs/ops/IdpOps.js +12 -1
- package/cjs/ops/IdpOps.js.map +1 -1
- package/cjs/ops/JourneyOps.js +388 -140
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/NodeOps.js +13 -0
- package/cjs/ops/NodeOps.js.map +1 -1
- package/cjs/ops/OpsTypes.js +6 -0
- package/cjs/ops/OpsTypes.js.map +1 -0
- package/cjs/ops/Saml2Ops.js +24 -1
- package/cjs/ops/Saml2Ops.js.map +1 -1
- package/cjs/ops/ScriptOps.js +12 -0
- package/cjs/ops/ScriptOps.js.map +1 -1
- package/cjs/ops/ThemeOps.js +12 -0
- package/cjs/ops/ThemeOps.js.map +1 -1
- package/cjs/ops/utils/Console.js +18 -1
- package/cjs/ops/utils/Console.js.map +1 -1
- package/cjs/ops/utils/ExportImportUtils.js.map +1 -1
- package/cjs/storage/SessionStorage.js +4 -0
- package/cjs/storage/SessionStorage.js.map +1 -1
- package/esm/api/ApiTypes.mjs +33 -0
- package/esm/api/Saml2Api.mjs +1 -1
- package/esm/index.mjs +2 -0
- package/esm/ops/CirclesOfTrustOps.mjs +11 -1
- package/esm/ops/EmailTemplateOps.mjs +11 -1
- package/esm/ops/IdpOps.mjs +11 -1
- package/esm/ops/JourneyOps.mjs +269 -82
- package/esm/ops/NodeOps.mjs +11 -0
- package/esm/ops/OpsTypes.mjs +2 -0
- package/esm/ops/Saml2Ops.mjs +20 -2
- package/esm/ops/ScriptOps.mjs +10 -0
- package/esm/ops/ThemeOps.mjs +10 -0
- package/esm/ops/utils/Console.mjs +16 -1
- package/esm/storage/SessionStorage.mjs +4 -0
- package/package.json +1 -1
- package/types/api/ApiTypes.d.ts +102 -0
- package/types/api/ApiTypes.d.ts.map +1 -0
- package/types/api/Saml2Api.d.ts +1 -1
- package/types/api/Saml2Api.d.ts.map +1 -1
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -1
- package/types/ops/CirclesOfTrustOps.d.ts +7 -0
- package/types/ops/CirclesOfTrustOps.d.ts.map +1 -1
- package/types/ops/EmailTemplateOps.d.ts +7 -0
- package/types/ops/EmailTemplateOps.d.ts.map +1 -1
- package/types/ops/IdpOps.d.ts +7 -0
- package/types/ops/IdpOps.d.ts.map +1 -1
- package/types/ops/JourneyOps.d.ts +107 -89
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/NodeOps.d.ts +8 -0
- package/types/ops/NodeOps.d.ts.map +1 -1
- package/types/ops/OpsTypes.d.ts +66 -0
- package/types/ops/OpsTypes.d.ts.map +1 -0
- package/types/ops/Saml2Ops.d.ts +13 -0
- package/types/ops/Saml2Ops.d.ts.map +1 -1
- package/types/ops/ScriptOps.d.ts +7 -0
- package/types/ops/ScriptOps.d.ts.map +1 -1
- package/types/ops/ThemeOps.d.ts +7 -0
- package/types/ops/ThemeOps.d.ts.map +1 -1
- package/types/ops/utils/Console.d.ts +9 -1
- package/types/ops/utils/Console.d.ts.map +1 -1
- package/types/ops/utils/ExportImportUtils.d.ts.map +1 -1
- package/types/storage/SessionStorage.d.ts +4 -0
- package/types/storage/SessionStorage.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,8 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.12.6] - 2022-09-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- \#104: Enhanced `frodo journey describe` command to include more details
|
|
15
|
+
|
|
10
16
|
## [0.12.5] - 2022-09-29
|
|
11
17
|
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- \#98: Frodo now properly runs `frodo idm export -A -D ./idm <host>` command
|
|
21
|
+
- \#100: Frodo now properly handles nested realms when specified as `/parent/child`
|
|
22
|
+
- \#101: Frodo now properly sets the identity resource when the realm was specified with a leading slash
|
|
23
|
+
- \#102: Frodo now properly replaces existing themes on import when the realm was specified with a leading slash
|
|
24
|
+
|
|
12
25
|
## [0.12.5-0] - 2022-09-19
|
|
13
26
|
|
|
14
27
|
## [0.12.4] - 2022-09-17
|
|
@@ -17,9 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
30
|
|
|
18
31
|
- Frodo now allows two new parameters when adding a connection profile:
|
|
19
32
|
|
|
20
|
-
\--authentication-service [service]
|
|
33
|
+
\--authentication-service [service] Name of the authentication service/tree to use.
|
|
21
34
|
|
|
22
|
-
\--authentication-header-overrides [headers]
|
|
35
|
+
\--authentication-header-overrides [headers] Map of headers: {"host":"am.example.com:8081"}.
|
|
23
36
|
|
|
24
37
|
These parameters are currently only supported in the `frodo conn add` command and the configuration elements will be automatically applied to commands issued using that connection profile.
|
|
25
38
|
|
|
@@ -29,13 +42,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
29
42
|
Saving creds in /Users/vscheuber/.frodo/.frodorc...
|
|
30
43
|
Updating connection profile https://platform.example.com:9443/am
|
|
31
44
|
Advanced setting: Authentication Service: ldapService
|
|
32
|
-
Advanced setting: Authentication Header Overrides:
|
|
45
|
+
Advanced setting: Authentication Header Overrides:
|
|
33
46
|
{ host: 'am.example.com:8081' }
|
|
34
47
|
%
|
|
35
48
|
|
|
36
49
|
After the connection profile is created with the additional parameters, the environment can be accessed as usual. In this case it requires the `-k` parameter for every command, as the environment uses a self-signed certificate.
|
|
37
50
|
|
|
38
|
-
% frodo journey list platform alpha -k
|
|
51
|
+
% frodo journey list platform alpha -k
|
|
39
52
|
ForgeOps deployment detected.
|
|
40
53
|
Connected to ForgeRock Access Management 7.2.0 Build 64ef7ebc01ed3df1a1264d7b0400351bc101361f (2022-June-27 08:15)
|
|
41
54
|
Listing journeys in realm "alpha"...
|
|
@@ -127,7 +140,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
127
140
|
|
|
128
141
|
### Changed
|
|
129
142
|
|
|
130
|
-
- \#19: `frodo-lib` is now a typescript project.
|
|
143
|
+
- \#19: `frodo-lib` is now a typescript project.
|
|
131
144
|
|
|
132
145
|
## [0.11.1-7] - 2022-08-21
|
|
133
146
|
|
|
@@ -326,9 +339,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
326
339
|
|
|
327
340
|
- Changed `idm` sub-commands to align with other commands:
|
|
328
341
|
- The sub-commands `export`, `exportAll`, and `exportAllRaw` have been collapsed into one: `export`
|
|
329
|
-
- `idm export -A` (`--all-separate`) is now the way to export all idm configuration.
|
|
342
|
+
- `idm export -A` (`--all-separate`) is now the way to export all idm configuration.
|
|
330
343
|
- Options `-e` and `-E` select old `exportAll` functionality with variable replacement and filtering
|
|
331
|
-
- Omitting options `-e` and `-E`,
|
|
344
|
+
- Omitting options `-e` and `-E`, selects the old `exportAllRaw` functionality without variable replacement and without filtering
|
|
332
345
|
- Renamed sample resource files for `idm export` command:
|
|
333
346
|
- `<frodo home>/resources/sampleEntitiesFile.json`
|
|
334
347
|
- `<frodo home>/resources/sampleEnvFile.env`
|
|
@@ -553,7 +566,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
553
566
|
- Fixed problem with adding connection profiles
|
|
554
567
|
- Miscellaneous bug fixes
|
|
555
568
|
|
|
556
|
-
[Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.12.
|
|
569
|
+
[Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.12.6...HEAD
|
|
570
|
+
|
|
571
|
+
[0.12.6]: https://github.com/rockcarver/frodo-lib/compare/v0.12.5...v0.12.6
|
|
557
572
|
|
|
558
573
|
[0.12.5]: https://github.com/rockcarver/frodo-lib/compare/v0.12.5-0...v0.12.5
|
|
559
574
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScriptLanguage = exports.ScriptContext = exports.Saml2ProiderLocation = void 0;
|
|
7
|
+
var ScriptLanguage;
|
|
8
|
+
exports.ScriptLanguage = ScriptLanguage;
|
|
9
|
+
|
|
10
|
+
(function (ScriptLanguage) {
|
|
11
|
+
ScriptLanguage["GROOVY"] = "GROOVY";
|
|
12
|
+
ScriptLanguage["JAVASCRIPT"] = "JAVASCRIPT";
|
|
13
|
+
})(ScriptLanguage || (exports.ScriptLanguage = ScriptLanguage = {}));
|
|
14
|
+
|
|
15
|
+
var ScriptContext;
|
|
16
|
+
exports.ScriptContext = ScriptContext;
|
|
17
|
+
|
|
18
|
+
(function (ScriptContext) {
|
|
19
|
+
ScriptContext["OAUTH2_ACCESS_TOKEN_MODIFICATION"] = "OAUTH2_ACCESS_TOKEN_MODIFICATION";
|
|
20
|
+
ScriptContext["AUTHENTICATION_CLIENT_SIDE"] = "AUTHENTICATION_CLIENT_SIDE";
|
|
21
|
+
ScriptContext["AUTHENTICATION_TREE_DECISION_NODE"] = "AUTHENTICATION_TREE_DECISION_NODE";
|
|
22
|
+
ScriptContext["AUTHENTICATION_SERVER_SIDE"] = "AUTHENTICATION_SERVER_SIDE";
|
|
23
|
+
ScriptContext["SOCIAL_IDP_PROFILE_TRANSFORMATION"] = "SOCIAL_IDP_PROFILE_TRANSFORMATION";
|
|
24
|
+
ScriptContext["OAUTH2_VALIDATE_SCOPE"] = "OAUTH2_VALIDATE_SCOPE";
|
|
25
|
+
ScriptContext["CONFIG_PROVIDER_NODE"] = "CONFIG_PROVIDER_NODE";
|
|
26
|
+
ScriptContext["OAUTH2_AUTHORIZE_ENDPOINT_DATA_PROVIDER"] = "OAUTH2_AUTHORIZE_ENDPOINT_DATA_PROVIDER";
|
|
27
|
+
ScriptContext["OAUTH2_EVALUATE_SCOPE"] = "OAUTH2_EVALUATE_SCOPE";
|
|
28
|
+
ScriptContext["POLICY_CONDITION"] = "POLICY_CONDITION";
|
|
29
|
+
ScriptContext["OIDC_CLAIMS"] = "OIDC_CLAIMS";
|
|
30
|
+
ScriptContext["SAML2_IDP_ADAPTER"] = "SAML2_IDP_ADAPTER";
|
|
31
|
+
ScriptContext["SAML2_IDP_ATTRIBUTE_MAPPER"] = "SAML2_IDP_ATTRIBUTE_MAPPER";
|
|
32
|
+
ScriptContext["OAUTH2_MAY_ACT"] = "OAUTH2_MAY_ACT";
|
|
33
|
+
})(ScriptContext || (exports.ScriptContext = ScriptContext = {}));
|
|
34
|
+
|
|
35
|
+
var Saml2ProiderLocation;
|
|
36
|
+
exports.Saml2ProiderLocation = Saml2ProiderLocation;
|
|
37
|
+
|
|
38
|
+
(function (Saml2ProiderLocation) {
|
|
39
|
+
Saml2ProiderLocation["HOSTED"] = "hosted";
|
|
40
|
+
Saml2ProiderLocation["REMOTE"] = "remote";
|
|
41
|
+
})(Saml2ProiderLocation || (exports.Saml2ProiderLocation = Saml2ProiderLocation = {}));
|
|
42
|
+
//# sourceMappingURL=ApiTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiTypes.js","names":["ScriptLanguage","ScriptContext","Saml2ProiderLocation"],"sources":["api/ApiTypes.ts"],"sourcesContent":["interface ObjectSkeletonInterface {\n _id: string;\n _rev?: number;\n [k: string]: string | number | ObjectSkeletonInterface;\n}\n\nexport interface UiConfigInterface {\n categories: string[];\n}\n\nexport interface NodeRefSkeletonInterface {\n connections: Record<string, string>;\n displayName: string;\n nodeType: string;\n x: number;\n y: number;\n}\n\nexport interface InnerNodeRefSkeletonInterface {\n _id: string;\n displayName: string;\n nodeType: string;\n}\n\nexport type TreeSkeleton = ObjectSkeletonInterface & {\n entryNodeId: string;\n nodes: Record<string, NodeRefSkeletonInterface>;\n identityResource?: string;\n uiConfig?: UiConfigInterface;\n enabled?: boolean;\n};\n\nexport type AmServiceType = ObjectSkeletonInterface & {\n name: string;\n};\n\nexport type NodeSkeleton = ObjectSkeletonInterface & {\n _type: AmServiceType;\n nodes?: InnerNodeRefSkeletonInterface[];\n tree?: string;\n identityResource?: string;\n};\n\nexport type SocialIdpSkeleton = ObjectSkeletonInterface & {\n _type: AmServiceType;\n enabled: boolean;\n};\n\nexport type EmailTemplateSkeleton = ObjectSkeletonInterface & {\n defaultLocale?: string;\n displayName?: string;\n enabled?: boolean;\n from: string;\n subject: Record<string, string>;\n};\n\nexport type ThemeSkeleton = ObjectSkeletonInterface & {\n name: string;\n isDefault: boolean;\n linkedTrees: string[];\n};\n\nexport enum ScriptLanguage {\n GROOVY = 'GROOVY',\n JAVASCRIPT = 'JAVASCRIPT',\n}\n\nexport enum ScriptContext {\n OAUTH2_ACCESS_TOKEN_MODIFICATION = 'OAUTH2_ACCESS_TOKEN_MODIFICATION',\n AUTHENTICATION_CLIENT_SIDE = 'AUTHENTICATION_CLIENT_SIDE',\n AUTHENTICATION_TREE_DECISION_NODE = 'AUTHENTICATION_TREE_DECISION_NODE',\n AUTHENTICATION_SERVER_SIDE = 'AUTHENTICATION_SERVER_SIDE',\n SOCIAL_IDP_PROFILE_TRANSFORMATION = 'SOCIAL_IDP_PROFILE_TRANSFORMATION',\n OAUTH2_VALIDATE_SCOPE = 'OAUTH2_VALIDATE_SCOPE',\n CONFIG_PROVIDER_NODE = 'CONFIG_PROVIDER_NODE',\n OAUTH2_AUTHORIZE_ENDPOINT_DATA_PROVIDER = 'OAUTH2_AUTHORIZE_ENDPOINT_DATA_PROVIDER',\n OAUTH2_EVALUATE_SCOPE = 'OAUTH2_EVALUATE_SCOPE',\n POLICY_CONDITION = 'POLICY_CONDITION',\n OIDC_CLAIMS = 'OIDC_CLAIMS',\n SAML2_IDP_ADAPTER = 'SAML2_IDP_ADAPTER',\n SAML2_IDP_ATTRIBUTE_MAPPER = 'SAML2_IDP_ATTRIBUTE_MAPPER',\n OAUTH2_MAY_ACT = 'OAUTH2_MAY_ACT',\n}\n\nexport type ScriptSkeleton = ObjectSkeletonInterface & {\n name: string;\n description: string;\n isDefault: boolean;\n script: string;\n language: ScriptLanguage;\n context: ScriptContext;\n createdBy: string;\n creationDate: number;\n lastModifiedBy: string;\n lastModifiedDate: number;\n};\n\nexport enum Saml2ProiderLocation {\n HOSTED = 'hosted',\n REMOTE = 'remote',\n}\n\nexport type Saml2ProviderSkeleton = ObjectSkeletonInterface & {\n entityId: string;\n entityLocation: Saml2ProiderLocation;\n serviceProvider: unknown;\n identityProvider: unknown;\n attributeQueryProvider: unknown;\n xacmlPolicyEnforcementPoint: unknown;\n};\n\nexport type CircleOfTrustSkeleton = ObjectSkeletonInterface & {\n _type: AmServiceType;\n status: string;\n trustedProviders: string[];\n};\n"],"mappings":";;;;;;IA8DYA,c;;;WAAAA,c;EAAAA,c;EAAAA,c;GAAAA,c,8BAAAA,c;;IAKAC,a;;;WAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;EAAAA,a;GAAAA,a,6BAAAA,a;;IA8BAC,oB;;;WAAAA,oB;EAAAA,oB;EAAAA,oB;GAAAA,oB,oCAAAA,oB"}
|
package/cjs/api/Saml2Api.js
CHANGED
|
@@ -54,7 +54,7 @@ function getProviders() {
|
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Find all providers matching the filter and return the requested fields
|
|
57
|
-
* @param {string} filter CREST filter string, eg "entityId+eq+'${entityId}'"
|
|
57
|
+
* @param {string} filter CREST filter string, eg "entityId+eq+'${entityId}'" or "true" for all providers
|
|
58
58
|
* @param {string} fields Comma-delimited list of fields to include in the response
|
|
59
59
|
* @returns {Promise} a promise that resolves to an object containing an array of saml2 entities
|
|
60
60
|
*/
|
package/cjs/api/Saml2Api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Saml2Api.js","names":["providerByLocationAndIdURLTemplate","createHostedProviderURLTemplate","createRemoteProviderURLTemplate","queryAllProvidersURLTemplate","queryProvidersByEntityIdURLTemplate","metadataByEntityIdURLTemplate","apiVersion","getApiConfig","configPath","getCurrentRealmPath","path","getProviders","urlString","util","format","storage","session","getTenant","data","generateAmApi","get","withCredentials","findProviders","filter","fields","encodeURIComponent","getProviderByLocationAndId","location","entityId64","getProvider","entityId","response","resultCount","Error","result","id","_id","getProviderMetadataUrl","getRealm","getProviderMetadata","createProvider","providerData","metaData","postData","_","cloneDeep","standardMetadata","post","updateProvider","put"],"sources":["api/Saml2Api.ts"],"sourcesContent":["import util from 'util';\nimport _ from 'lodash';\nimport { generateAmApi } from './BaseApi';\nimport { getCurrentRealmPath } from './utils/ApiUtils';\nimport storage from '../storage/SessionStorage';\n\nconst providerByLocationAndIdURLTemplate = '%s/json%s/realm-config/saml2/%s/%s';\nconst createHostedProviderURLTemplate =\n '%s/json%s/realm-config/saml2/hosted/?_action=create';\nconst createRemoteProviderURLTemplate =\n '%s/json%s/realm-config/saml2/remote/?_action=importEntity';\nconst queryAllProvidersURLTemplate =\n '%s/json%s/realm-config/saml2?_queryFilter=true';\nconst queryProvidersByEntityIdURLTemplate =\n '%s/json%s/realm-config/saml2?_queryFilter=%s&_fields=%s';\nconst metadataByEntityIdURLTemplate =\n '%s/saml2/jsp/exportmetadata.jsp?entityid=%s&realm=%s';\nconst apiVersion = 'protocol=2.1,resource=1.0';\nconst getApiConfig = () => {\n const configPath = getCurrentRealmPath();\n return {\n path: `${configPath}/realm-config/saml2`,\n apiVersion,\n };\n};\n\n/**\n * Get all SAML2 entity providers\n * @returns {Promise} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getProviders() {\n const urlString = util.format(\n queryAllProvidersURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n const { data } = await generateAmApi(getApiConfig()).get(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Find all providers matching the filter and return the requested fields\n * @param {string} filter CREST filter string, eg \"entityId+eq+'${entityId}'\"\n * @param {string} fields Comma-delimited list of fields to include in the response\n * @returns {Promise} a promise that resolves to an object containing an array of saml2 entities\n */\nexport async function findProviders(filter = 'true', fields = '*') {\n const urlString = util.format(\n queryProvidersByEntityIdURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n encodeURIComponent(filter),\n fields\n );\n const { data } = await generateAmApi(getApiConfig()).get(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId(\n location: string,\n entityId64: string\n) {\n const urlString = util.format(\n providerByLocationAndIdURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n location,\n entityId64\n );\n const { data } = await generateAmApi(getApiConfig()).get(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Get SAML2 entity provider by entity id\n * @param {string} entityId Provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object or null\n */\nexport async function getProvider(entityId) {\n const response = await findProviders(`entityId eq '${entityId}'`, 'location');\n switch (response.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n const { location } = response.result[0];\n const id = response.result[0]._id;\n return getProviderByLocationAndId(location, id);\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl(entityId) {\n return util.format(\n metadataByEntityIdURLTemplate,\n storage.session.getTenant(),\n encodeURIComponent(entityId),\n storage.session.getRealm()\n );\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {String} entityId SAML2 entity id\n * @returns {Promise} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata(entityId) {\n const { data } = await generateAmApi(getApiConfig()).get(\n getProviderMetadataUrl(entityId),\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Create a SAML2 entity provider\n * @param {String} location 'hosted' or 'remote'\n * @param {Object} providerData Object representing a SAML entity provider\n * @param {String} metaData Base64-encoded metadata XML. Only required for remote providers\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function createProvider(location, providerData, metaData) {\n let postData = _.cloneDeep(providerData);\n let urlString = util.format(\n createHostedProviderURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n\n if (location === 'remote') {\n /**\n * Remote entity providers must be created using XML metadata\n */\n urlString = util.format(\n createRemoteProviderURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n postData = {\n standardMetadata: metaData,\n };\n }\n\n const { data } = await generateAmApi(getApiConfig()).post(\n urlString,\n postData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Update SAML2 entity provider\n * @param {String} location Entity provider location (hosted or remote)\n * @param {Object} providerData Object representing a SAML entity provider\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function updateProvider(location, providerData) {\n const urlString = util.format(\n providerByLocationAndIdURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n location,\n providerData._id\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n providerData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n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BrB,QAA9B,EAAwCc,YAAxC,EAAsD;IAC3D,IAAM7B,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBd,kCADgB,EAEhBe,uBAAA,CAAQC,OAAR,CAAgBC,SAAhB,EAFgB,EAGhB,IAAAR,6BAAA,GAHgB,EAIhBkB,QAJgB,EAKhBc,YAAY,CAACL,GALG,CAAlB;;IAOA,IAAM;MAAElB;IAAF,UAAiB,IAAAC,sBAAA,EAAcZ,YAAY,EAA1B,EAA8B0C,GAA9B,CACrBrC,SADqB,EAErB6B,YAFqB,EAGrB;MACEpB,eAAe,EAAE;IADnB,CAHqB,CAAvB;IAOA,OAAOH,IAAP;EACD,C"}
|
|
1
|
+
{"version":3,"file":"Saml2Api.js","names":["providerByLocationAndIdURLTemplate","createHostedProviderURLTemplate","createRemoteProviderURLTemplate","queryAllProvidersURLTemplate","queryProvidersByEntityIdURLTemplate","metadataByEntityIdURLTemplate","apiVersion","getApiConfig","configPath","getCurrentRealmPath","path","getProviders","urlString","util","format","storage","session","getTenant","data","generateAmApi","get","withCredentials","findProviders","filter","fields","encodeURIComponent","getProviderByLocationAndId","location","entityId64","getProvider","entityId","response","resultCount","Error","result","id","_id","getProviderMetadataUrl","getRealm","getProviderMetadata","createProvider","providerData","metaData","postData","_","cloneDeep","standardMetadata","post","updateProvider","put"],"sources":["api/Saml2Api.ts"],"sourcesContent":["import util from 'util';\nimport _ from 'lodash';\nimport { generateAmApi } from './BaseApi';\nimport { getCurrentRealmPath } from './utils/ApiUtils';\nimport storage from '../storage/SessionStorage';\n\nconst providerByLocationAndIdURLTemplate = '%s/json%s/realm-config/saml2/%s/%s';\nconst createHostedProviderURLTemplate =\n '%s/json%s/realm-config/saml2/hosted/?_action=create';\nconst createRemoteProviderURLTemplate =\n '%s/json%s/realm-config/saml2/remote/?_action=importEntity';\nconst queryAllProvidersURLTemplate =\n '%s/json%s/realm-config/saml2?_queryFilter=true';\nconst queryProvidersByEntityIdURLTemplate =\n '%s/json%s/realm-config/saml2?_queryFilter=%s&_fields=%s';\nconst metadataByEntityIdURLTemplate =\n '%s/saml2/jsp/exportmetadata.jsp?entityid=%s&realm=%s';\nconst apiVersion = 'protocol=2.1,resource=1.0';\nconst getApiConfig = () => {\n const configPath = getCurrentRealmPath();\n return {\n path: `${configPath}/realm-config/saml2`,\n apiVersion,\n };\n};\n\n/**\n * Get all SAML2 entity providers\n * @returns {Promise} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getProviders() {\n const urlString = util.format(\n queryAllProvidersURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n const { data } = await generateAmApi(getApiConfig()).get(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Find all providers matching the filter and return the requested fields\n * @param {string} filter CREST filter string, eg \"entityId+eq+'${entityId}'\" or \"true\" for all providers\n * @param {string} fields Comma-delimited list of fields to include in the response\n * @returns {Promise} a promise that resolves to an object containing an array of saml2 entities\n */\nexport async function findProviders(filter = 'true', fields = '*') {\n const urlString = util.format(\n queryProvidersByEntityIdURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n encodeURIComponent(filter),\n fields\n );\n const { data } = await generateAmApi(getApiConfig()).get(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId(\n location: string,\n entityId64: string\n) {\n const urlString = util.format(\n providerByLocationAndIdURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n location,\n entityId64\n );\n const { data } = await generateAmApi(getApiConfig()).get(urlString, {\n withCredentials: true,\n });\n return data;\n}\n\n/**\n * Get SAML2 entity provider by entity id\n * @param {string} entityId Provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object or null\n */\nexport async function getProvider(entityId) {\n const response = await findProviders(`entityId eq '${entityId}'`, 'location');\n switch (response.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n const { location } = response.result[0];\n const id = response.result[0]._id;\n return getProviderByLocationAndId(location, id);\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl(entityId) {\n return util.format(\n metadataByEntityIdURLTemplate,\n storage.session.getTenant(),\n encodeURIComponent(entityId),\n storage.session.getRealm()\n );\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {String} entityId SAML2 entity id\n * @returns {Promise} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata(entityId) {\n const { data } = await generateAmApi(getApiConfig()).get(\n getProviderMetadataUrl(entityId),\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Create a SAML2 entity provider\n * @param {String} location 'hosted' or 'remote'\n * @param {Object} providerData Object representing a SAML entity provider\n * @param {String} metaData Base64-encoded metadata XML. Only required for remote providers\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function createProvider(location, providerData, metaData) {\n let postData = _.cloneDeep(providerData);\n let urlString = util.format(\n createHostedProviderURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n\n if (location === 'remote') {\n /**\n * Remote entity providers must be created using XML metadata\n */\n urlString = util.format(\n createRemoteProviderURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath()\n );\n postData = {\n standardMetadata: metaData,\n };\n }\n\n const { data } = await generateAmApi(getApiConfig()).post(\n urlString,\n postData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n\n/**\n * Update SAML2 entity provider\n * @param {String} location Entity provider location (hosted or remote)\n * @param {Object} providerData Object representing a SAML entity provider\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function updateProvider(location, providerData) {\n const urlString = util.format(\n providerByLocationAndIdURLTemplate,\n storage.session.getTenant(),\n getCurrentRealmPath(),\n location,\n providerData._id\n );\n const { data } = await generateAmApi(getApiConfig()).put(\n urlString,\n providerData,\n {\n withCredentials: true,\n }\n );\n return data;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,kCAAkC,GAAG,oCAA3C;AACA,IAAMC,+BAA+B,GACnC,qDADF;AAEA,IAAMC,+BAA+B,GACnC,2DADF;AAEA,IAAMC,4BAA4B,GAChC,gDADF;AAEA,IAAMC,mCAAmC,GACvC,yDADF;AAEA,IAAMC,6BAA6B,GACjC,sDADF;AAEA,IAAMC,UAAU,GAAG,2BAAnB;;AACA,IAAMC,YAAY,GAAG,MAAM;EACzB,IAAMC,UAAU,GAAG,IAAAC,6BAAA,GAAnB;EACA,OAAO;IACLC,IAAI,YAAKF,UAAL,wBADC;IAELF;EAFK,CAAP;AAID,CAND;AAQA;AACA;AACA;AACA;;;SACsBK,Y;;;AAYtB;AACA;AACA;AACA;AACA;AACA;;;;oCAjBO,aAA8B;IACnC,IAAMC,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBX,4BADgB,EAEhBY,uBAAA,CAAQC,OAAR,CAAgBC,SAAhB,EAFgB,EAGhB,IAAAR,6BAAA,GAHgB,CAAlB;;IAKA,IAAM;MAAES;IAAF,UAAiB,IAAAC,sBAAA,EAAcZ,YAAY,EAA1B,EAA8Ba,GAA9B,CAAkCR,SAAlC,EAA6C;MAClES,eAAe,EAAE;IADiD,CAA7C,CAAvB;IAGA,OAAOH,IAAP;EACD,C;;;;SAQqBI,a;;;AActB;AACA;AACA;AACA;AACA;AACA;;;;qCAnBO,aAA4D;IAAA,IAA/BC,MAA+B,uEAAtB,MAAsB;IAAA,IAAdC,MAAc,uEAAL,GAAK;;IACjE,IAAMZ,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBV,mCADgB,EAEhBW,uBAAA,CAAQC,OAAR,CA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wC,IAA9B,CACrBnC,SADqB,EAErB+B,QAFqB,EAGrB;MACEtB,eAAe,EAAE;IADnB,CAHqB,CAAvB;IAOA,OAAOH,IAAP;EACD,C;;;;SAQqB8B,c;;;;;sCAAf,WAA8BrB,QAA9B,EAAwCc,YAAxC,EAAsD;IAC3D,IAAM7B,SAAS,GAAGC,aAAA,CAAKC,MAAL,CAChBd,kCADgB,EAEhBe,uBAAA,CAAQC,OAAR,CAAgBC,SAAhB,EAFgB,EAGhB,IAAAR,6BAAA,GAHgB,EAIhBkB,QAJgB,EAKhBc,YAAY,CAACL,GALG,CAAlB;;IAOA,IAAM;MAAElB;IAAF,UAAiB,IAAAC,sBAAA,EAAcZ,YAAY,EAA1B,EAA8B0C,GAA9B,CACrBrC,SADqB,EAErB6B,YAFqB,EAGrB;MACEpB,eAAe,EAAE;IADnB,CAHqB,CAAvB;IAOA,OAAOH,IAAP;EACD,C"}
|
package/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.VariablesRaw = exports.Variables = exports.Utils = exports.TreeRaw = exports.Theme = exports.StartupRaw = exports.Startup = exports.SecretsRaw = exports.Secrets = exports.Script = exports.Saml2 = exports.Realm = exports.Organization = exports.OAuth2OIDCApi = exports.OAuth2Client = exports.NodeRaw = exports.ManagedObject = exports.Log = exports.Journey = exports.Idp = exports.Idm = exports.EmailTemplate = exports.ConnectionProfile = exports.CirclesOfTrust = exports.Authenticate = exports.Admin = void 0;
|
|
6
|
+
exports.VariablesRaw = exports.Variables = exports.Utils = exports.TypesRaw = exports.Types = exports.TreeRaw = exports.Theme = exports.StartupRaw = exports.Startup = exports.SecretsRaw = exports.Secrets = exports.Script = exports.Saml2 = exports.Realm = exports.Organization = exports.OAuth2OIDCApi = exports.OAuth2Client = exports.NodeRaw = exports.ManagedObject = exports.Log = exports.Journey = exports.Idp = exports.Idm = exports.EmailTemplate = exports.ConnectionProfile = exports.CirclesOfTrust = exports.Authenticate = exports.Admin = void 0;
|
|
7
7
|
exports.getVersion = getVersion;
|
|
8
8
|
exports.state = void 0;
|
|
9
9
|
|
|
@@ -13,6 +13,10 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
13
13
|
|
|
14
14
|
var _url = require("url");
|
|
15
15
|
|
|
16
|
+
var _TypesRaw = _interopRequireWildcard(require("./api/ApiTypes"));
|
|
17
|
+
|
|
18
|
+
exports.TypesRaw = _TypesRaw;
|
|
19
|
+
|
|
16
20
|
var _NodeRaw = _interopRequireWildcard(require("./api/NodeApi"));
|
|
17
21
|
|
|
18
22
|
exports.NodeRaw = _NodeRaw;
|
|
@@ -33,6 +37,10 @@ var _VariablesRaw = _interopRequireWildcard(require("./api/VariablesApi"));
|
|
|
33
37
|
|
|
34
38
|
exports.VariablesRaw = _VariablesRaw;
|
|
35
39
|
|
|
40
|
+
var _Types = _interopRequireWildcard(require("./ops/OpsTypes"));
|
|
41
|
+
|
|
42
|
+
exports.Types = _Types;
|
|
43
|
+
|
|
36
44
|
var _Admin = _interopRequireWildcard(require("./ops/AdminOps"));
|
|
37
45
|
|
|
38
46
|
exports.Admin = _Admin;
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["__dirname","path","dirname","fileURLToPath","pkg","JSON","parse","fs","readFileSync","resolve","getVersion","version"],"sources":["index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst pkg = JSON.parse(\n fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')\n);\n\nexport function getVersion() {\n return `v${pkg.version}`;\n}\n\n// Api Layer\nexport * as NodeRaw from './api/NodeApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as StartupRaw from './api/StartupApi';\nexport * as SecretsRaw from './api/SecretsApi';\nexport * as VariablesRaw from './api/VariablesApi';\n\n// Ops Layer\nexport * as Admin from './ops/AdminOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Log from './ops/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Secrets from './ops/SecretsOps';\nexport * as Startup from './ops/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Variables from './ops/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './storage/SessionStorage';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA
|
|
1
|
+
{"version":3,"file":"index.js","names":["__dirname","path","dirname","fileURLToPath","pkg","JSON","parse","fs","readFileSync","resolve","getVersion","version"],"sources":["index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst pkg = JSON.parse(\n fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')\n);\n\nexport function getVersion() {\n return `v${pkg.version}`;\n}\n\n// Api Layer\nexport * as TypesRaw from './api/ApiTypes';\nexport * as NodeRaw from './api/NodeApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as StartupRaw from './api/StartupApi';\nexport * as SecretsRaw from './api/SecretsApi';\nexport * as VariablesRaw from './api/VariablesApi';\n\n// Ops Layer\nexport * as Types from './ops/OpsTypes';\nexport * as Admin from './ops/AdminOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Log from './ops/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Secrets from './ops/SecretsOps';\nexport * as Startup from './ops/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Variables from './ops/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './storage/SessionStorage';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,QAAS,GAAGC,aAAA,CAAKC,OAAL,CAAa,IAAAC,kBAAA,sDAAb,CAAlB;;AAEA,IAAMC,GAAG,GAAGC,IAAI,CAACC,KAAL,CACVC,WAAA,CAAGC,YAAH,CAAgBP,aAAA,CAAKQ,OAAL,CAAaT,QAAb,EAAwB,iBAAxB,CAAhB,EAA4D,MAA5D,CADU,CAAZ;;AAIO,SAASU,UAAT,GAAsB;EAC3B,kBAAWN,GAAG,CAACO,OAAf;AACD,C,CAED"}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.exportCircleOfTrust = exportCircleOfTrust;
|
|
7
7
|
exports.exportCirclesOfTrustToFile = exportCirclesOfTrustToFile;
|
|
8
8
|
exports.exportCirclesOfTrustToFiles = exportCirclesOfTrustToFiles;
|
|
9
|
+
exports.getOneLineDescription = getOneLineDescription;
|
|
9
10
|
exports.importCircleOfTrust = importCircleOfTrust;
|
|
10
11
|
exports.importCirclesOfTrustFromFile = importCirclesOfTrustFromFile;
|
|
11
12
|
exports.importCirclesOfTrustFromFiles = importCirclesOfTrustFromFiles;
|
|
@@ -28,7 +29,17 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
28
29
|
|
|
29
30
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Get a one-line description of the circle of trust object
|
|
34
|
+
* @param {CircleOfTrustSkeleton} cotObj circle of trust object to describe
|
|
35
|
+
* @returns {string} a one-line description
|
|
36
|
+
*/
|
|
37
|
+
function getOneLineDescription(cotObj) {
|
|
38
|
+
var description = "[".concat(cotObj._id['brightCyan'], "]");
|
|
39
|
+
return description;
|
|
40
|
+
} // use a function vs a template variable to avoid problems in loops
|
|
41
|
+
|
|
42
|
+
|
|
32
43
|
function getFileDataTemplate() {
|
|
33
44
|
return {
|
|
34
45
|
meta: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CirclesOfTrustOps.js","names":["getFileDataTemplate","meta","script","saml","hosted","remote","metadata","cot","listCirclesOfTrust","long","cotList","getCirclesOfTrust","result","error","printMessage","sort","a","b","_id","localeCompare","forEach","table","createTable","push","description","status","trustedProviders","map","provider","split","join","toString","exportDependencies","cotData","fileData","exportCircleOfTrust","cotId","file","fileName","getTypedFilename","createProgressIndicator","_","cloneDeep","getCircleOfTrust","updateProgressIndicator","saveJsonToFile","stopProgressIndicator","brightCyan","err","exportCirclesOfTrustToFile","getRealmString","allCotData","length","_rev","exportCirclesOfTrustToFiles","importDependencies","importCircleOfTrust","fs","readFile","data","JSON","parse","validateImport","get","createCircleOfTrust","createProviderErr","response","importFirstCircleOfTrust","hasOwnProperty","call","createCircleOfTrustErr","importCirclesOfTrustFromFile","Object","keys","importCirclesOfTrustFromFiles","names","readdirSync","jsonFiles","filter","name","toLowerCase","endsWith","total","totalErrors","readFileSync","errors"],"sources":["ops/CirclesOfTrustOps.ts"],"sourcesContent":["import fs from 'fs';\nimport _ from 'lodash';\nimport {\n createTable,\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\nimport {\n getCirclesOfTrust,\n getCircleOfTrust,\n createCircleOfTrust,\n} from '../api/CirclesOfTrustApi';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n };\n}\n\n/**\n * List entity providers\n * @param {String} long Long list format with details\n */\nexport async function listCirclesOfTrust(long = false) {\n let cotList = [];\n try {\n cotList = (await getCirclesOfTrust()).result;\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n cotList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n cotList.forEach((cot) => {\n printMessage(`${cot._id}`, 'data');\n });\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Description'['brightCyan'],\n 'Status'['brightCyan'],\n 'Trusted Providers'['brightCyan'],\n ]);\n cotList.forEach((cot) => {\n table.push([\n cot._id,\n cot.description,\n cot.status,\n cot.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('\\n'),\n ]);\n });\n printMessage(table.toString());\n }\n}\n\n/**\n * Include dependencies in the export file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(cotData, fileData) {\n // TODO: Export dependencies\n return [cotData, fileData];\n}\n\n/**\n * Export a single circle of trust to file\n * @param {String} cotId circle of trust id/name\n * @param {String} file Optional filename\n */\nexport async function exportCircleOfTrust(cotId, file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(cotId, 'cot.saml');\n }\n createProgressIndicator(1, `Exporting circle of trust ${cotId}`);\n try {\n const cotData = _.cloneDeep(getCircleOfTrust(cotId));\n delete cotData['_rev'];\n updateProgressIndicator(`Exporting ${cotId}`);\n const fileData = getFileDataTemplate();\n fileData.saml.cot[cotId] = cotData;\n await exportDependencies(cotData, fileData);\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${cotId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all circles of trust to one file\n * @param {String} file Optional filename\n */\nexport async function exportCirclesOfTrustToFile(file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(\n `all${getRealmString()}CirclesOfTrust`,\n 'cot.saml'\n );\n }\n const fileData = getFileDataTemplate();\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${allCotData.length} circle(s) of trust exported to ${fileName}.`\n );\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Export all circles of trust to individual files\n */\nexport async function exportCirclesOfTrustToFiles() {\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n const fileName = getTypedFilename(cotData._id, 'cot.saml');\n const fileData = getFileDataTemplate();\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${allCotData.length} providers exported.`);\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Include dependencies from the import file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to read dependencies from\n */\nasync function importDependencies(cotData, fileData) {\n // TODO: Import dependencies\n return [cotData, fileData];\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {String} file Import file name\n */\nexport async function importCircleOfTrust(cotId, file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n const cotData = _.get(fileData, ['saml', 'cot', cotId]);\n if (cotData) {\n updateProgressIndicator(`Importing ${cotId}`);\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createProviderErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createProviderErr.response.data, 'error');\n }\n } else {\n stopProgressIndicator(\n `Circle of trust ${cotId.brightCyan} not found in ${file.brightCyan}!`\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import first SAML circle of trust from file\n * @param {String} file Import file name\n */\nexport async function importFirstCircleOfTrust(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n updateProgressIndicator(`Importing ${cotId}`);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createCircleOfTrustErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from file\n * @param {String} file Import file name\n */\nexport async function importCirclesOfTrustFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.saml.cot).length,\n 'Importing circles of trust...'\n );\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Circles of trust imported.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from all *.cot.saml.json files in the current directory\n */\nexport async function importCirclesOfTrustFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.cot.saml.json')\n );\n createProgressIndicator(jsonFiles.length, 'Importing circles or trust...');\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n total += _.keys(fileData.saml.cot).length;\n let errors = 0;\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n // updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n errors += 1;\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(\n `Imported ${\n _.keys(fileData.saml.cot).length - errors\n } circle(s) of trust from ${file}`\n );\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} circle(s) of trust from ${\n jsonFiles.length\n } file(s).`\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAOA;;AAKA;;;;;;;;AAOA;AACA,SAASA,mBAAT,GAA+B;EAC7B,OAAO;IACLC,IAAI,EAAE,EADD;IAELC,MA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IAAT,CAAcI,GAArB,EAA0B6C,MAA1B,GAAmCiC,MAFvC,sCAG8BhD,IAH9B;MAKD,CAzBD,MAyBO;QACL,IAAAvB,qBAAA,0BAA8BuB,IAA9B,eAA8C,OAA9C;MACD;IACF;;IACD,IAAAS,8BAAA,qBACcoC,KAAK,GAAGC,WADtB,iBACwCD,KADxC,sCAEIL,SAAS,CAACzB,MAFd;EAKD,C"}
|
|
1
|
+
{"version":3,"file":"CirclesOfTrustOps.js","names":["getOneLineDescription","cotObj","description","_id","getFileDataTemplate","meta","script","saml","hosted","remote","metadata","cot","listCirclesOfTrust","long","cotList","getCirclesOfTrust","result","error","printMessage","sort","a","b","localeCompare","forEach","table","createTable","push","status","trustedProviders","map","provider","split","join","toString","exportDependencies","cotData","fileData","exportCircleOfTrust","cotId","file","fileName","getTypedFilename","createProgressIndicator","_","cloneDeep","getCircleOfTrust","updateProgressIndicator","saveJsonToFile","stopProgressIndicator","brightCyan","err","exportCirclesOfTrustToFile","getRealmString","allCotData","length","_rev","exportCirclesOfTrustToFiles","importDependencies","importCircleOfTrust","fs","readFile","data","JSON","parse","validateImport","get","createCircleOfTrust","createProviderErr","response","importFirstCircleOfTrust","hasOwnProperty","call","createCircleOfTrustErr","importCirclesOfTrustFromFile","Object","keys","importCirclesOfTrustFromFiles","names","readdirSync","jsonFiles","filter","name","toLowerCase","endsWith","total","totalErrors","readFileSync","errors"],"sources":["ops/CirclesOfTrustOps.ts"],"sourcesContent":["import fs from 'fs';\nimport _ from 'lodash';\nimport {\n createTable,\n printMessage,\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n} from './utils/Console';\nimport {\n getCirclesOfTrust,\n getCircleOfTrust,\n createCircleOfTrust,\n} from '../api/CirclesOfTrustApi';\nimport {\n getRealmString,\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport { CircleOfTrustSkeleton } from '../api/ApiTypes';\n\n/**\n * Get a one-line description of the circle of trust object\n * @param {CircleOfTrustSkeleton} cotObj circle of trust object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(cotObj: CircleOfTrustSkeleton): string {\n const description = `[${cotObj._id['brightCyan']}]`;\n return description;\n}\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n cot: {},\n },\n };\n}\n\n/**\n * List entity providers\n * @param {String} long Long list format with details\n */\nexport async function listCirclesOfTrust(long = false) {\n let cotList = [];\n try {\n cotList = (await getCirclesOfTrust()).result;\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n cotList.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n cotList.forEach((cot) => {\n printMessage(`${cot._id}`, 'data');\n });\n } else {\n const table = createTable([\n 'Name'['brightCyan'],\n 'Description'['brightCyan'],\n 'Status'['brightCyan'],\n 'Trusted Providers'['brightCyan'],\n ]);\n cotList.forEach((cot) => {\n table.push([\n cot._id,\n cot.description,\n cot.status,\n cot.trustedProviders\n .map((provider) => provider.split('|')[0])\n .join('\\n'),\n ]);\n });\n printMessage(table.toString());\n }\n}\n\n/**\n * Include dependencies in the export file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(cotData, fileData) {\n // TODO: Export dependencies\n return [cotData, fileData];\n}\n\n/**\n * Export a single circle of trust to file\n * @param {String} cotId circle of trust id/name\n * @param {String} file Optional filename\n */\nexport async function exportCircleOfTrust(cotId, file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(cotId, 'cot.saml');\n }\n createProgressIndicator(1, `Exporting circle of trust ${cotId}`);\n try {\n const cotData = _.cloneDeep(getCircleOfTrust(cotId));\n delete cotData['_rev'];\n updateProgressIndicator(`Exporting ${cotId}`);\n const fileData = getFileDataTemplate();\n fileData.saml.cot[cotId] = cotData;\n await exportDependencies(cotData, fileData);\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${cotId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all circles of trust to one file\n * @param {String} file Optional filename\n */\nexport async function exportCirclesOfTrustToFile(file = null) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(\n `all${getRealmString()}CirclesOfTrust`,\n 'cot.saml'\n );\n }\n const fileData = getFileDataTemplate();\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${allCotData.length} circle(s) of trust exported to ${fileName}.`\n );\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Export all circles of trust to individual files\n */\nexport async function exportCirclesOfTrustToFiles() {\n let allCotData = [];\n try {\n allCotData = _.cloneDeep((await getCirclesOfTrust()).result);\n createProgressIndicator(allCotData.length, 'Exporting circles of trust');\n for (const cotData of allCotData) {\n delete cotData._rev;\n updateProgressIndicator(`Exporting circle of trust ${cotData._id}`);\n const fileName = getTypedFilename(cotData._id, 'cot.saml');\n const fileData = getFileDataTemplate();\n // eslint-disable-next-line no-await-in-loop\n await exportDependencies(cotData, fileData);\n fileData.saml.cot[cotData._id] = cotData;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${allCotData.length} providers exported.`);\n } catch (error) {\n printMessage(`getCirclesOfTrust ERROR: ${error}`, 'error');\n printMessage(error, 'data');\n }\n}\n\n/**\n * Include dependencies from the import file\n * @param {Object} cotData Object representing a SAML circle of trust\n * @param {Object} fileData File data object to read dependencies from\n */\nasync function importDependencies(cotData, fileData) {\n // TODO: Import dependencies\n return [cotData, fileData];\n}\n\n/**\n * Import a SAML circle of trust by id/name from file\n * @param {String} cotId Circle of trust id/name\n * @param {String} file Import file name\n */\nexport async function importCircleOfTrust(cotId, file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n const cotData = _.get(fileData, ['saml', 'cot', cotId]);\n if (cotData) {\n updateProgressIndicator(`Importing ${cotId}`);\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createProviderErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createProviderErr.response.data, 'error');\n }\n } else {\n stopProgressIndicator(\n `Circle of trust ${cotId.brightCyan} not found in ${file.brightCyan}!`\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import first SAML circle of trust from file\n * @param {String} file Import file name\n */\nexport async function importFirstCircleOfTrust(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, 'Importing circle of trust...');\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n updateProgressIndicator(`Importing ${cotId}`);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n await createCircleOfTrust(cotData);\n stopProgressIndicator(`Successfully imported ${cotId}.`);\n } catch (createCircleOfTrustErr) {\n stopProgressIndicator(`Error importing ${cotId}.`);\n printMessage(`Error importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from file\n * @param {String} file Import file name\n */\nexport async function importCirclesOfTrustFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.saml.cot).length,\n 'Importing circles of trust...'\n );\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Circles of trust imported.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all SAML circles of trust from all *.cot.saml.json files in the current directory\n */\nexport async function importCirclesOfTrustFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith('.cot.saml.json')\n );\n createProgressIndicator(jsonFiles.length, 'Importing circles or trust...');\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n total += _.keys(fileData.saml.cot).length;\n let errors = 0;\n for (const cotId in fileData.saml.cot) {\n if ({}.hasOwnProperty.call(fileData.saml.cot, cotId)) {\n const cotData = _.cloneDeep(fileData.saml.cot[cotId]);\n // eslint-disable-next-line no-await-in-loop\n await importDependencies(cotData, fileData);\n try {\n // eslint-disable-next-line no-await-in-loop\n await createCircleOfTrust(cotData);\n // updateProgressIndicator(`Imported ${cotId}`);\n } catch (createCircleOfTrustErr) {\n errors += 1;\n printMessage(`\\nError importing ${cotId}`, 'error');\n printMessage(createCircleOfTrustErr.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(\n `Imported ${\n _.keys(fileData.saml.cot).length - errors\n } circle(s) of trust from ${file}`\n );\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} circle(s) of trust from ${\n jsonFiles.length\n } file(s).`\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAOA;;AAKA;;;;;;;;AAQA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAT,CAA+BC,MAA/B,EAAsE;EAC3E,IAAMC,WAAW,cAAOD,MAAM,CAACE,GAAP,CAAW,YAAX,CAAP,MAAjB;EACA,OAAOD,WAAP;AACD,C,CAED;;;AACA,SAASE,mBAAT,GAA+B;EAC7B,OAAO;IACLC,IAAI,EAAE,EADD;IAELC,MAAM,EAAE,EAFH;IAGLC,IAAI,EAAE;MACJC,MAAM,EAAE,EADJ;MAEJC,MAAM,EAAE,EAFJ;MAGJC,QAAQ,EAAE,EAHN;MAIJC,GAAG,EAAE;IAJD;EAHD,CAAP;AAUD;AAED;AACA;AACA;AACA;;;SACsBC,kB;;;AAkCtB;AACA;AACA;AACA;AACA;;;;0CAtCO,aAAgD;IAAA,IAAdC,IAAc,uEAAP,KAAO;IACrD,IAAIC,OAAO,GAAG,EAAd;;IACA,IAAI;MACFA,OAAO,GAAG,OAAO,IAAAC,oCAAA,GAAP,EAA4BC,MAAtC;IACD,CAFD,CAEE,OAAOC,KAAP,EAAc;MACd,IAAAC,qBAAA,qCAAyCD,KAAzC,GAAkD,OAAlD;MACA,IAAAC,qBAAA,EAAaD,KAAb,EAAoB,MAApB;IACD;;IACDH,OAAO,CAACK,IAAR,CAAa,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACjB,GAAF,CAAMmB,aAAN,CA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7B,IAAT,CAAcI,GAArC,EAA0C2B,KAA1C,CAAJ,EAAsD;YACpD,IAAMH,OAAO,GAAGQ,eAAA,CAAEC,SAAF,CAAYR,QAAQ,CAAC7B,IAAT,CAAcI,GAAd,CAAkB2B,KAAlB,CAAZ,CAAhB,CADoD,CAEpD;;;YACA,MAAMmB,kBAAkB,CAACtB,OAAD,EAAUC,QAAV,CAAxB;;YACA,IAAI;cACF;cACA,MAAM,IAAA8B,sCAAA,EAAoB/B,OAApB,CAAN,CAFE,CAGF;YACD,CAJD,CAIE,OAAOqC,sBAAP,EAA+B;cAC/Be,MAAM,IAAI,CAAV;cACA,IAAArE,qBAAA,8BAAkCoB,KAAlC,GAA2C,OAA3C;cACA,IAAApB,qBAAA,EAAasD,sBAAsB,CAACJ,QAAvB,CAAgCP,IAA7C,EAAmD,OAAnD;YACD;UACF;QACF;;QACDwB,WAAW,IAAIE,MAAf;QACA,IAAAzC,gCAAA,qBAEIH,eAAA,CAAEgC,IAAF,CAAOvC,QAAQ,CAAC7B,IAAT,CAAcI,GAArB,EAA0B2C,MAA1B,GAAmCiC,MAFvC,sCAG8BhD,IAH9B;MAKD,CAzBD,MAyBO;QACL,IAAArB,qBAAA,0BAA8BqB,IAA9B,eAA8C,OAA9C;MACD;IACF;;IACD,IAAAS,8BAAA,qBACcoC,KAAK,GAAGC,WADtB,iBACwCD,KADxC,sCAEIL,SAAS,CAACzB,MAFd;EAKD,C"}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.exportEmailTemplateToFile = exportEmailTemplateToFile;
|
|
7
7
|
exports.exportEmailTemplatesToFile = exportEmailTemplatesToFile;
|
|
8
8
|
exports.exportEmailTemplatesToFiles = exportEmailTemplatesToFiles;
|
|
9
|
+
exports.getOneLineDescription = getOneLineDescription;
|
|
9
10
|
exports.importEmailTemplateFromFile = importEmailTemplateFromFile;
|
|
10
11
|
exports.importEmailTemplatesFromFile = importEmailTemplatesFromFile;
|
|
11
12
|
exports.importEmailTemplatesFromFiles = importEmailTemplatesFromFiles;
|
|
@@ -44,6 +45,17 @@ function getFileDataTemplate() {
|
|
|
44
45
|
emailTemplate: {}
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Get a one-line description of the email template
|
|
50
|
+
* @param {EmailTemplateSkeleton} templateObj email template object to describe
|
|
51
|
+
* @returns {string} a one-line description
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function getOneLineDescription(templateObj) {
|
|
56
|
+
var description = "[".concat(templateObj._id.split('/')[1]['brightCyan'], "] ").concat(templateObj.displayName['brightYellow'], " - ").concat(templateObj.subject[templateObj.defaultLocale]['brightYellow']);
|
|
57
|
+
return description;
|
|
58
|
+
}
|
|
47
59
|
/**
|
|
48
60
|
* List email templates
|
|
49
61
|
* @param {boolean} long Long list format with details
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailTemplateOps.js","names":["regexEmailTemplateType","RegExp","EMAIL_TEMPLATE_TYPE","EMAIL_TEMPLATE_FILE_TYPE","getFileDataTemplate","meta","emailTemplate","listEmailTemplates","long","emailTemplates","getEmailTemplates","result","error","printMessage","message","sort","a","b","_id","localeCompare","entries","replace","table","createTable","push","displayName","enabled","defaultLocale","Object","keys","subject","length","filter","locale","join","from","wordwrap","toString","exportEmailTemplateToFile","templateId","file","fileName","getTypedFilename","createProgressIndicator","templateData","getEmailTemplate","updateProgressIndicator","fileData","saveJsonToFile","stopProgressIndicator","brightCyan","err","exportEmailTemplatesToFile","response","templates","resultCount","template","exportEmailTemplatesToFiles","importEmailTemplateFromFile","replaceAll","fs","readFile","data","JSON","parse","validateImport","putEmailTemplate","putEmailTemplateError","importEmailTemplatesFromFile","id","hasOwnProperty","call","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","name","toLowerCase","endsWith","total","totalErrors","readFileSync","errors","importFirstEmailTemplateFromFile"],"sources":["ops/EmailTemplateOps.ts"],"sourcesContent":["import fs from 'fs';\nimport {\n EMAIL_TEMPLATE_TYPE,\n getEmailTemplate,\n getEmailTemplates,\n putEmailTemplate,\n} from '../api/EmailTemplateApi';\nimport {\n createProgressIndicator,\n createTable,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport wordwrap from './utils/Wordwrap';\n\n/**\n * Regex to remove email template type from id\n */\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n/**\n * Maintain the file type centrally\n */\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = (await getEmailTemplates()).result;\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export a single email template to file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplateToFile(templateId, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n createProgressIndicator(1, `Exporting ${templateId}`);\n try {\n const templateData = await getEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${templateId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n try {\n const fileData = getFileDataTemplate();\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${response.resultCount} templates exported to ${fileName}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${response.resultCount} templates exported.`);\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function importEmailTemplateFromFile(templateId, file) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing ${templateId}`);\n if (fileData.emailTemplate[templateId]) {\n try {\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`${putEmailTemplateError}`);\n printMessage(putEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`\n );\n printMessage(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`,\n 'error'\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from file\n * @param {String} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from separate files\n */\nexport async function importEmailTemplatesFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n );\n createProgressIndicator(jsonFiles.length, 'Importing email templates...');\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n total += Object.keys(fileData.emailTemplate).length;\n let errors = 0;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (putEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(`Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing first email template`);\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await putEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n updateProgressIndicator(`Imported ${id}`);\n stopProgressIndicator(`Imported ${id}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`Error importing email template ${id}`);\n printMessage(`\\nError importing email template ${id}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AAMA;;AAOA;;AAKA;;;;;;;;AAEA;AACA;AACA;AACA,IAAMA,sBAAsB,GAAG,IAAIC,MAAJ,WAAcC,qCAAd,QAAsC,GAAtC,CAA/B;AAEA;AACA;AACA;;AACA,IAAMC,wBAAwB,GAAG,gBAAjC,C,CAEA;;AACA,SAASC,mBAAT,GAA+B;EAC7B,OAAO;IACLC,IAAI,EAAE,EADD;IAELC,aAAa,EAAE;EAFV,CAAP;AAID;AAED;AACA;AACA;AACA;AACA;;;SACsBC,kB;;;AAqDtB;AACA;AACA;AACA;AACA;;;;0CAzDO,aAAoE;IAAA,IAAlCC,IAAkC,uEAA3B,KAA2B;IACzE,IAAIC,cAAc,GAAG,EAArB;;IACA,IAAI;MACFA,cAAc,GAAG,OAAO,IAAAC,mCAAA,GAAP,EAA4BC,MAA7C;IACD,CAFD,CAEE,OAAOC,KAAP,EAAc;MACd,IAAAC,qBAAA,8CAAkDD,KAAK,CAACE,OAAxD,GAAmE,OAAnE;IACD;;IACDL,cAAc,CAACM,IAAf,CAAoB,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAACE,GAAF,CAAMC,aAAN,CAAoBF,CAAC,CAACC,GAAtB,CAA9B;;IACA,IAAI,CAACV,IAAL,EAA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AIA,IAAAvB,gCAAA,qBAAoCuB,EAApC;gBACA,IAAApB,8BAAA,qBAAkCoB,EAAlC;cACD,CAPD,CAOE,OAAOF,qBAAP,EAA8B;gBAC9B,IAAAlB,8BAAA,2CAAwDoB,EAAxD;gBACA,IAAAxD,qBAAA,6CAAiDwD,EAAjD,GAAuD,OAAvD;gBACA,IAAAxD,qBAAA,EAAasD,qBAAqB,CAACd,QAAtB,CAA+BS,IAA5C,EAAkD,OAAlD;cACD;;cACD;YACD;UACF;QACF,CAnBD,MAmBO;UACL,IAAAjD,qBAAA,EAAa,6BAAb,EAA4C,OAA5C;QACD;MACF,CAzBD;;MAAA;QAAA;MAAA;IAAA;EA0BD,C"}
|
|
1
|
+
{"version":3,"file":"EmailTemplateOps.js","names":["regexEmailTemplateType","RegExp","EMAIL_TEMPLATE_TYPE","EMAIL_TEMPLATE_FILE_TYPE","getFileDataTemplate","meta","emailTemplate","getOneLineDescription","templateObj","description","_id","split","displayName","subject","defaultLocale","listEmailTemplates","long","emailTemplates","getEmailTemplates","result","error","printMessage","message","sort","a","b","localeCompare","entries","replace","table","createTable","push","enabled","Object","keys","length","filter","locale","join","from","wordwrap","toString","exportEmailTemplateToFile","templateId","file","fileName","getTypedFilename","createProgressIndicator","templateData","getEmailTemplate","updateProgressIndicator","fileData","saveJsonToFile","stopProgressIndicator","brightCyan","err","exportEmailTemplatesToFile","response","templates","resultCount","template","exportEmailTemplatesToFiles","importEmailTemplateFromFile","replaceAll","fs","readFile","data","JSON","parse","validateImport","putEmailTemplate","putEmailTemplateError","importEmailTemplatesFromFile","id","hasOwnProperty","call","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","name","toLowerCase","endsWith","total","totalErrors","readFileSync","errors","importFirstEmailTemplateFromFile"],"sources":["ops/EmailTemplateOps.ts"],"sourcesContent":["import fs from 'fs';\nimport { EmailTemplateSkeleton } from '../api/ApiTypes';\nimport {\n EMAIL_TEMPLATE_TYPE,\n getEmailTemplate,\n getEmailTemplates,\n putEmailTemplate,\n} from '../api/EmailTemplateApi';\nimport {\n createProgressIndicator,\n createTable,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n getTypedFilename,\n saveJsonToFile,\n validateImport,\n} from './utils/ExportImportUtils';\nimport wordwrap from './utils/Wordwrap';\n\n/**\n * Regex to remove email template type from id\n */\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n/**\n * Maintain the file type centrally\n */\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName['brightYellow']\n } - ${templateObj.subject[templateObj.defaultLocale]['brightYellow']}`;\n return description;\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = (await getEmailTemplates()).result;\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export a single email template to file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplateToFile(templateId, file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n createProgressIndicator(1, `Exporting ${templateId}`);\n try {\n const templateData = await getEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${templateId.brightCyan} to ${fileName.brightCyan}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n try {\n const fileData = getFileDataTemplate();\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${response.resultCount} templates exported to ${fileName}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(response.resultCount, 'Exporting email templates');\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${response.resultCount} templates exported.`);\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function importEmailTemplateFromFile(templateId, file) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing ${templateId}`);\n if (fileData.emailTemplate[templateId]) {\n try {\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`${putEmailTemplateError}`);\n printMessage(putEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`\n );\n printMessage(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`,\n 'error'\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from file\n * @param {String} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from separate files\n */\nexport async function importEmailTemplatesFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n );\n createProgressIndicator(jsonFiles.length, 'Importing email templates...');\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n total += Object.keys(fileData.emailTemplate).length;\n let errors = 0;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (putEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(`Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(1, `Importing first email template`);\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await putEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n updateProgressIndicator(`Imported ${id}`);\n stopProgressIndicator(`Imported ${id}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`Error importing email template ${id}`);\n printMessage(`\\nError importing email template ${id}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAEA;;AAMA;;AAOA;;AAKA;;;;;;;;AAEA;AACA;AACA;AACA,IAAMA,sBAAsB,GAAG,IAAIC,MAAJ,WAAcC,qCAAd,QAAsC,GAAtC,CAA/B;AAEA;AACA;AACA;;AACA,IAAMC,wBAAwB,GAAG,gBAAjC,C,CAEA;;AACA,SAASC,mBAAT,GAA+B;EAC7B,OAAO;IACLC,IAAI,EAAE,EADD;IAELC,aAAa,EAAE;EAFV,CAAP;AAID;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASC,qBAAT,CACLC,WADK,EAEG;EACR,IAAMC,WAAW,cAAOD,WAAW,CAACE,GAAZ,CAAgBC,KAAhB,CAAsB,GAAtB,EAA2B,CAA3B,EAA8B,YAA9B,CAAP,eACfH,WAAW,CAACI,WAAZ,CAAwB,cAAxB,CADe,gBAEXJ,WAAW,CAACK,OAAZ,CAAoBL,WAAW,CAACM,aAAhC,EAA+C,cAA/C,CAFW,CAAjB;EAGA,OAAOL,WAAP;AACD;AAED;AACA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IAAMJ,QAAQ,GAAGgB,IAAI,CAACC,KAAL,CAAWF,IAAX,CAAjB;;QACA,IAAI,IAAAG,iCAAA,EAAelB,QAAQ,CAAC9C,IAAxB,CAAJ,EAAmC;UACjC,IAAA0C,gCAAA,EAAwB,CAAxB;;UACA,KAAK,IAAM0B,EAAX,IAAiBtB,QAAQ,CAAC7C,aAA1B,EAAyC;YACvC,IAAI,GAAGoE,cAAH,CAAkBC,IAAlB,CAAuBxB,QAAQ,CAAC7C,aAAhC,EAA+CmE,EAA/C,CAAJ,EAAwD;cACtD,IAAI;gBACF,MAAM,IAAAH,kCAAA,EACJG,EAAE,CAAC7C,OAAH,CAAW5B,sBAAX,EAAmC,EAAnC,CADI,EAEJmD,QAAQ,CAAC7C,aAAT,CAAuBmE,EAAvB,CAFI,CAAN;gBAIA,IAAAvB,gCAAA,qBAAoCuB,EAApC;gBACA,IAAApB,8BAAA,qBAAkCoB,EAAlC;cACD,CAPD,CAOE,OAAOF,qBAAP,EAA8B;gBAC9B,IAAAlB,8BAAA,2CAAwDoB,EAAxD;gBACA,IAAApD,qBAAA,6CAAiDoD,EAAjD,GAAuD,OAAvD;gBACA,IAAApD,qBAAA,EAAakD,qBAAqB,CAACd,QAAtB,CAA+BS,IAA5C,EAAkD,OAAlD;cACD;;cACD;YACD;UACF;QACF,CAnBD,MAmBO;UACL,IAAA7C,qBAAA,EAAa,6BAAb,EAA4C,OAA5C;QACD;MACF,CAzBD;;MAAA;QAAA;MAAA;IAAA;EA0BD,C"}
|
package/cjs/ops/IdpOps.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.exportSocialProviderToFile = exportSocialProviderToFile;
|
|
7
7
|
exports.exportSocialProvidersToFile = exportSocialProvidersToFile;
|
|
8
8
|
exports.exportSocialProvidersToFiles = exportSocialProvidersToFiles;
|
|
9
|
+
exports.getOneLineDescription = getOneLineDescription;
|
|
9
10
|
exports.getSocialProvider = getSocialProvider;
|
|
10
11
|
exports.importFirstSocialProviderFromFile = importFirstSocialProviderFromFile;
|
|
11
12
|
exports.importSocialProviderFromFile = importSocialProviderFromFile;
|
|
@@ -31,7 +32,17 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
31
32
|
|
|
32
33
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Get a one-line description of the social idp object
|
|
37
|
+
* @param {SocialIdpSkeleton} socialIdpObj social idp object to describe
|
|
38
|
+
* @returns {string} a one-line description
|
|
39
|
+
*/
|
|
40
|
+
function getOneLineDescription(socialIdpObj) {
|
|
41
|
+
var description = "[".concat(socialIdpObj._id['brightCyan'], "] ").concat(socialIdpObj._type._id);
|
|
42
|
+
return description;
|
|
43
|
+
} // use a function vs a template variable to avoid problems in loops
|
|
44
|
+
|
|
45
|
+
|
|
35
46
|
function getFileDataTemplate() {
|
|
36
47
|
return {
|
|
37
48
|
meta: {},
|