auth0-deploy-cli 8.20.4-beta.0 → 8.21.0

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.
Files changed (318) hide show
  1. package/.circleci/config.yml +5 -46
  2. package/.eslintignore +5 -0
  3. package/.eslintrc +69 -0
  4. package/CHANGELOG.md +15 -6
  5. package/lib/args.js +1 -0
  6. package/lib/args.js.map +1 -0
  7. package/lib/commands/export.js +49 -41
  8. package/lib/commands/export.js.map +1 -0
  9. package/lib/commands/import.js +43 -36
  10. package/lib/commands/import.js.map +1 -0
  11. package/lib/commands/index.js +1 -0
  12. package/lib/commands/index.js.map +1 -0
  13. package/lib/configFactory.js +1 -0
  14. package/lib/configFactory.js.map +1 -0
  15. package/lib/context/defaults.js +10 -38
  16. package/lib/context/defaults.js.map +1 -0
  17. package/lib/context/directory/handlers/actions.js +39 -40
  18. package/lib/context/directory/handlers/actions.js.map +1 -0
  19. package/lib/context/directory/handlers/attackProtection.js +34 -22
  20. package/lib/context/directory/handlers/attackProtection.js.map +1 -0
  21. package/lib/context/directory/handlers/branding.js +21 -12
  22. package/lib/context/directory/handlers/branding.js.map +1 -0
  23. package/lib/context/directory/handlers/clientGrants.js +62 -52
  24. package/lib/context/directory/handlers/clientGrants.js.map +1 -0
  25. package/lib/context/directory/handlers/clients.js +60 -17
  26. package/lib/context/directory/handlers/clients.js.map +1 -0
  27. package/lib/context/directory/handlers/connectionProfiles.d.ts +11 -0
  28. package/lib/context/directory/handlers/connectionProfiles.js +59 -0
  29. package/lib/context/directory/handlers/connectionProfiles.js.map +1 -0
  30. package/lib/context/directory/handlers/connections.js +41 -32
  31. package/lib/context/directory/handlers/connections.js.map +1 -0
  32. package/lib/context/directory/handlers/customDomains.js +21 -9
  33. package/lib/context/directory/handlers/customDomains.js.map +1 -0
  34. package/lib/context/directory/handlers/databases.js +35 -37
  35. package/lib/context/directory/handlers/databases.js.map +1 -0
  36. package/lib/context/directory/handlers/emailProvider.js +36 -22
  37. package/lib/context/directory/handlers/emailProvider.js.map +1 -0
  38. package/lib/context/directory/handlers/emailTemplates.js +29 -20
  39. package/lib/context/directory/handlers/emailTemplates.js.map +1 -0
  40. package/lib/context/directory/handlers/flowVaultConnections.js +49 -39
  41. package/lib/context/directory/handlers/flowVaultConnections.js.map +1 -0
  42. package/lib/context/directory/handlers/flows.js +48 -38
  43. package/lib/context/directory/handlers/flows.js.map +1 -0
  44. package/lib/context/directory/handlers/forms.js +48 -38
  45. package/lib/context/directory/handlers/forms.js.map +1 -0
  46. package/lib/context/directory/handlers/guardianFactorProviders.js +21 -9
  47. package/lib/context/directory/handlers/guardianFactorProviders.js.map +1 -0
  48. package/lib/context/directory/handlers/guardianFactorTemplates.js +21 -9
  49. package/lib/context/directory/handlers/guardianFactorTemplates.js.map +1 -0
  50. package/lib/context/directory/handlers/guardianFactors.js +21 -9
  51. package/lib/context/directory/handlers/guardianFactors.js.map +1 -0
  52. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js +20 -8
  53. package/lib/context/directory/handlers/guardianPhoneFactorMessageTypes.js.map +1 -0
  54. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js +20 -8
  55. package/lib/context/directory/handlers/guardianPhoneFactorSelectedProvider.js.map +1 -0
  56. package/lib/context/directory/handlers/guardianPolicies.js +20 -8
  57. package/lib/context/directory/handlers/guardianPolicies.js.map +1 -0
  58. package/lib/context/directory/handlers/hooks.js +34 -24
  59. package/lib/context/directory/handlers/hooks.js.map +1 -0
  60. package/lib/context/directory/handlers/index.js +3 -0
  61. package/lib/context/directory/handlers/index.js.map +1 -0
  62. package/lib/context/directory/handlers/logStreams.js +24 -12
  63. package/lib/context/directory/handlers/logStreams.js.map +1 -0
  64. package/lib/context/directory/handlers/networkACLs.js +34 -22
  65. package/lib/context/directory/handlers/networkACLs.js.map +1 -0
  66. package/lib/context/directory/handlers/organizations.js +44 -39
  67. package/lib/context/directory/handlers/organizations.js.map +1 -0
  68. package/lib/context/directory/handlers/pages.js +37 -31
  69. package/lib/context/directory/handlers/pages.js.map +1 -0
  70. package/lib/context/directory/handlers/phoneProvider.js +24 -12
  71. package/lib/context/directory/handlers/phoneProvider.js.map +1 -0
  72. package/lib/context/directory/handlers/prompts.js +76 -58
  73. package/lib/context/directory/handlers/prompts.js.map +1 -0
  74. package/lib/context/directory/handlers/resourceServers.d.ts +1 -1
  75. package/lib/context/directory/handlers/resourceServers.js +30 -18
  76. package/lib/context/directory/handlers/resourceServers.js.map +1 -0
  77. package/lib/context/directory/handlers/roles.js +31 -21
  78. package/lib/context/directory/handlers/roles.js.map +1 -0
  79. package/lib/context/directory/handlers/rules.js +32 -22
  80. package/lib/context/directory/handlers/rules.js.map +1 -0
  81. package/lib/context/directory/handlers/rulesConfigs.js +15 -3
  82. package/lib/context/directory/handlers/rulesConfigs.js.map +1 -0
  83. package/lib/context/directory/handlers/selfServiceProfiles.js +40 -28
  84. package/lib/context/directory/handlers/selfServiceProfiles.js.map +1 -0
  85. package/lib/context/directory/handlers/tenant.js +34 -14
  86. package/lib/context/directory/handlers/tenant.js.map +1 -0
  87. package/lib/context/directory/handlers/themes.js +21 -9
  88. package/lib/context/directory/handlers/themes.js.map +1 -0
  89. package/lib/context/directory/handlers/triggers.d.ts +1 -1
  90. package/lib/context/directory/handlers/triggers.js +26 -16
  91. package/lib/context/directory/handlers/triggers.js.map +1 -0
  92. package/lib/context/directory/handlers/userAttributeProfiles.d.ts +1 -1
  93. package/lib/context/directory/handlers/userAttributeProfiles.js +26 -16
  94. package/lib/context/directory/handlers/userAttributeProfiles.js.map +1 -0
  95. package/lib/context/directory/index.js +80 -66
  96. package/lib/context/directory/index.js.map +1 -0
  97. package/lib/context/index.js +20 -9
  98. package/lib/context/index.js.map +1 -0
  99. package/lib/context/yaml/handlers/actions.js +41 -39
  100. package/lib/context/yaml/handlers/actions.js.map +1 -0
  101. package/lib/context/yaml/handlers/attackProtection.js +41 -27
  102. package/lib/context/yaml/handlers/attackProtection.js.map +1 -0
  103. package/lib/context/yaml/handlers/branding.js +69 -47
  104. package/lib/context/yaml/handlers/branding.js.map +1 -0
  105. package/lib/context/yaml/handlers/clientGrants.js +40 -26
  106. package/lib/context/yaml/handlers/clientGrants.js.map +1 -0
  107. package/lib/context/yaml/handlers/clients.js +85 -41
  108. package/lib/context/yaml/handlers/clients.js.map +1 -0
  109. package/lib/context/yaml/handlers/connectionProfiles.d.ts +11 -0
  110. package/lib/context/yaml/handlers/connectionProfiles.js +44 -0
  111. package/lib/context/yaml/handlers/connectionProfiles.js.map +1 -0
  112. package/lib/context/yaml/handlers/connections.js +67 -63
  113. package/lib/context/yaml/handlers/connections.js.map +1 -0
  114. package/lib/context/yaml/handlers/customDomains.js +19 -7
  115. package/lib/context/yaml/handlers/customDomains.js.map +1 -0
  116. package/lib/context/yaml/handlers/databases.js +65 -63
  117. package/lib/context/yaml/handlers/databases.js.map +1 -0
  118. package/lib/context/yaml/handlers/emailProvider.js +37 -22
  119. package/lib/context/yaml/handlers/emailProvider.js.map +1 -0
  120. package/lib/context/yaml/handlers/emailTemplates.js +39 -28
  121. package/lib/context/yaml/handlers/emailTemplates.js.map +1 -0
  122. package/lib/context/yaml/handlers/flowVaultConnections.js +50 -36
  123. package/lib/context/yaml/handlers/flowVaultConnections.js.map +1 -0
  124. package/lib/context/yaml/handlers/flows.js +66 -55
  125. package/lib/context/yaml/handlers/flows.js.map +1 -0
  126. package/lib/context/yaml/handlers/forms.js +66 -55
  127. package/lib/context/yaml/handlers/forms.js.map +1 -0
  128. package/lib/context/yaml/handlers/guardianFactorProviders.js +19 -7
  129. package/lib/context/yaml/handlers/guardianFactorProviders.js.map +1 -0
  130. package/lib/context/yaml/handlers/guardianFactorTemplates.js +19 -7
  131. package/lib/context/yaml/handlers/guardianFactorTemplates.js.map +1 -0
  132. package/lib/context/yaml/handlers/guardianFactors.js +19 -7
  133. package/lib/context/yaml/handlers/guardianFactors.js.map +1 -0
  134. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js +19 -7
  135. package/lib/context/yaml/handlers/guardianPhoneFactorMessageTypes.js.map +1 -0
  136. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js +19 -7
  137. package/lib/context/yaml/handlers/guardianPhoneFactorSelectedProvider.js.map +1 -0
  138. package/lib/context/yaml/handlers/guardianPolicies.js +19 -7
  139. package/lib/context/yaml/handlers/guardianPolicies.js.map +1 -0
  140. package/lib/context/yaml/handlers/hooks.js +48 -34
  141. package/lib/context/yaml/handlers/hooks.js.map +1 -0
  142. package/lib/context/yaml/handlers/index.js +3 -0
  143. package/lib/context/yaml/handlers/index.js.map +1 -0
  144. package/lib/context/yaml/handlers/logStreams.js +30 -16
  145. package/lib/context/yaml/handlers/logStreams.js.map +1 -0
  146. package/lib/context/yaml/handlers/networkACLs.js +39 -25
  147. package/lib/context/yaml/handlers/networkACLs.js.map +1 -0
  148. package/lib/context/yaml/handlers/organizations.js +46 -37
  149. package/lib/context/yaml/handlers/organizations.js.map +1 -0
  150. package/lib/context/yaml/handlers/pages.js +39 -31
  151. package/lib/context/yaml/handlers/pages.js.map +1 -0
  152. package/lib/context/yaml/handlers/phoneProvider.js +31 -17
  153. package/lib/context/yaml/handlers/phoneProvider.js.map +1 -0
  154. package/lib/context/yaml/handlers/prompts.js +47 -22
  155. package/lib/context/yaml/handlers/prompts.js.map +1 -0
  156. package/lib/context/yaml/handlers/resourceServers.d.ts +1 -1
  157. package/lib/context/yaml/handlers/resourceServers.js +33 -21
  158. package/lib/context/yaml/handlers/resourceServers.js.map +1 -0
  159. package/lib/context/yaml/handlers/roles.js +33 -19
  160. package/lib/context/yaml/handlers/roles.js.map +1 -0
  161. package/lib/context/yaml/handlers/rules.js +39 -28
  162. package/lib/context/yaml/handlers/rules.js.map +1 -0
  163. package/lib/context/yaml/handlers/rulesConfigs.js +28 -14
  164. package/lib/context/yaml/handlers/rulesConfigs.js.map +1 -0
  165. package/lib/context/yaml/handlers/selfServiceProfiles.js +43 -29
  166. package/lib/context/yaml/handlers/selfServiceProfiles.js.map +1 -0
  167. package/lib/context/yaml/handlers/tenant.js +41 -19
  168. package/lib/context/yaml/handlers/tenant.js.map +1 -0
  169. package/lib/context/yaml/handlers/themes.js +19 -7
  170. package/lib/context/yaml/handlers/themes.js.map +1 -0
  171. package/lib/context/yaml/handlers/triggers.d.ts +1 -1
  172. package/lib/context/yaml/handlers/triggers.js +29 -15
  173. package/lib/context/yaml/handlers/triggers.js.map +1 -0
  174. package/lib/context/yaml/handlers/userAttributeProfiles.d.ts +1 -1
  175. package/lib/context/yaml/handlers/userAttributeProfiles.js +19 -7
  176. package/lib/context/yaml/handlers/userAttributeProfiles.js.map +1 -0
  177. package/lib/context/yaml/index.js +128 -120
  178. package/lib/context/yaml/index.js.map +1 -0
  179. package/lib/index.d.ts +96 -4
  180. package/lib/index.js +34 -24
  181. package/lib/index.js.map +1 -0
  182. package/lib/keywordPreservation.d.ts +1 -1
  183. package/lib/keywordPreservation.js +6 -10
  184. package/lib/keywordPreservation.js.map +1 -0
  185. package/lib/logger.js +1 -0
  186. package/lib/logger.js.map +1 -0
  187. package/lib/readonly.js +4 -3
  188. package/lib/readonly.js.map +1 -0
  189. package/lib/sessionDurationsToMinutes.js +1 -0
  190. package/lib/sessionDurationsToMinutes.js.map +1 -0
  191. package/lib/tools/auth0/client.js +127 -108
  192. package/lib/tools/auth0/client.js.map +1 -0
  193. package/lib/tools/auth0/handlers/actions.d.ts +26 -8
  194. package/lib/tools/auth0/handlers/actions.js +149 -138
  195. package/lib/tools/auth0/handlers/actions.js.map +1 -0
  196. package/lib/tools/auth0/handlers/attackProtection.js +92 -80
  197. package/lib/tools/auth0/handlers/attackProtection.js.map +1 -0
  198. package/lib/tools/auth0/handlers/branding.js +99 -75
  199. package/lib/tools/auth0/handlers/branding.js.map +1 -0
  200. package/lib/tools/auth0/handlers/clientGrants.d.ts +9 -2
  201. package/lib/tools/auth0/handlers/clientGrants.js +72 -65
  202. package/lib/tools/auth0/handlers/clientGrants.js.map +1 -0
  203. package/lib/tools/auth0/handlers/clients.d.ts +85 -7
  204. package/lib/tools/auth0/handlers/clients.js +187 -66
  205. package/lib/tools/auth0/handlers/clients.js.map +1 -0
  206. package/lib/tools/auth0/handlers/connectionProfiles.d.ts +182 -0
  207. package/lib/tools/auth0/handlers/connectionProfiles.js +239 -0
  208. package/lib/tools/auth0/handlers/connectionProfiles.js.map +1 -0
  209. package/lib/tools/auth0/handlers/connections.d.ts +1 -3
  210. package/lib/tools/auth0/handlers/connections.js +135 -130
  211. package/lib/tools/auth0/handlers/connections.js.map +1 -0
  212. package/lib/tools/auth0/handlers/customDomains.d.ts +1 -4
  213. package/lib/tools/auth0/handlers/customDomains.js +53 -43
  214. package/lib/tools/auth0/handlers/customDomains.js.map +1 -0
  215. package/lib/tools/auth0/handlers/databases.js +114 -94
  216. package/lib/tools/auth0/handlers/databases.js.map +1 -0
  217. package/lib/tools/auth0/handlers/default.d.ts +2 -2
  218. package/lib/tools/auth0/handlers/default.js +171 -210
  219. package/lib/tools/auth0/handlers/default.js.map +1 -0
  220. package/lib/tools/auth0/handlers/emailProvider.js +52 -41
  221. package/lib/tools/auth0/handlers/emailProvider.js.map +1 -0
  222. package/lib/tools/auth0/handlers/emailTemplates.js +71 -49
  223. package/lib/tools/auth0/handlers/emailTemplates.js.map +1 -0
  224. package/lib/tools/auth0/handlers/flowVaultConnections.d.ts +12 -5
  225. package/lib/tools/auth0/handlers/flowVaultConnections.js +143 -108
  226. package/lib/tools/auth0/handlers/flowVaultConnections.js.map +1 -0
  227. package/lib/tools/auth0/handlers/flows.d.ts +3 -2
  228. package/lib/tools/auth0/handlers/flows.js +129 -92
  229. package/lib/tools/auth0/handlers/flows.js.map +1 -0
  230. package/lib/tools/auth0/handlers/forms.d.ts +3 -3
  231. package/lib/tools/auth0/handlers/forms.js +112 -98
  232. package/lib/tools/auth0/handlers/forms.js.map +1 -0
  233. package/lib/tools/auth0/handlers/guardianFactorProviders.js +84 -61
  234. package/lib/tools/auth0/handlers/guardianFactorProviders.js.map +1 -0
  235. package/lib/tools/auth0/handlers/guardianFactorTemplates.js +68 -46
  236. package/lib/tools/auth0/handlers/guardianFactorTemplates.js.map +1 -0
  237. package/lib/tools/auth0/handlers/guardianFactors.js +45 -35
  238. package/lib/tools/auth0/handlers/guardianFactors.js.map +1 -0
  239. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js +45 -29
  240. package/lib/tools/auth0/handlers/guardianPhoneFactorMessageTypes.js.map +1 -0
  241. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js +45 -29
  242. package/lib/tools/auth0/handlers/guardianPhoneFactorSelectedProvider.js.map +1 -0
  243. package/lib/tools/auth0/handlers/guardianPolicies.js +35 -20
  244. package/lib/tools/auth0/handlers/guardianPolicies.js.map +1 -0
  245. package/lib/tools/auth0/handlers/hooks.js +153 -123
  246. package/lib/tools/auth0/handlers/hooks.js.map +1 -0
  247. package/lib/tools/auth0/handlers/index.js +3 -0
  248. package/lib/tools/auth0/handlers/index.js.map +1 -0
  249. package/lib/tools/auth0/handlers/logStreams.js +47 -42
  250. package/lib/tools/auth0/handlers/logStreams.js.map +1 -0
  251. package/lib/tools/auth0/handlers/networkACLs.d.ts +4 -5
  252. package/lib/tools/auth0/handlers/networkACLs.js +133 -115
  253. package/lib/tools/auth0/handlers/networkACLs.js.map +1 -0
  254. package/lib/tools/auth0/handlers/organizations.d.ts +9 -10
  255. package/lib/tools/auth0/handlers/organizations.js +429 -360
  256. package/lib/tools/auth0/handlers/organizations.js.map +1 -0
  257. package/lib/tools/auth0/handlers/pages.js +83 -74
  258. package/lib/tools/auth0/handlers/pages.js.map +1 -0
  259. package/lib/tools/auth0/handlers/phoneProvider.d.ts +2 -2
  260. package/lib/tools/auth0/handlers/phoneProvider.js +82 -69
  261. package/lib/tools/auth0/handlers/phoneProvider.js.map +1 -0
  262. package/lib/tools/auth0/handlers/prompts.d.ts +5 -5
  263. package/lib/tools/auth0/handlers/prompts.js +235 -240
  264. package/lib/tools/auth0/handlers/prompts.js.map +1 -0
  265. package/lib/tools/auth0/handlers/resourceServers.d.ts +1 -3
  266. package/lib/tools/auth0/handlers/resourceServers.js +60 -59
  267. package/lib/tools/auth0/handlers/resourceServers.js.map +1 -0
  268. package/lib/tools/auth0/handlers/roles.js +178 -162
  269. package/lib/tools/auth0/handlers/roles.js.map +1 -0
  270. package/lib/tools/auth0/handlers/rules.js +162 -144
  271. package/lib/tools/auth0/handlers/rules.js.map +1 -0
  272. package/lib/tools/auth0/handlers/rulesConfigs.js +39 -30
  273. package/lib/tools/auth0/handlers/rulesConfigs.js.map +1 -0
  274. package/lib/tools/auth0/handlers/scimHandler.d.ts +3 -4
  275. package/lib/tools/auth0/handlers/scimHandler.js +132 -110
  276. package/lib/tools/auth0/handlers/scimHandler.js.map +1 -0
  277. package/lib/tools/auth0/handlers/selfServiceProfiles.d.ts +5 -13
  278. package/lib/tools/auth0/handlers/selfServiceProfiles.js +204 -170
  279. package/lib/tools/auth0/handlers/selfServiceProfiles.js.map +1 -0
  280. package/lib/tools/auth0/handlers/tenant.d.ts +3 -5
  281. package/lib/tools/auth0/handlers/tenant.js +52 -45
  282. package/lib/tools/auth0/handlers/tenant.js.map +1 -0
  283. package/lib/tools/auth0/handlers/themes.d.ts +12 -12
  284. package/lib/tools/auth0/handlers/themes.js +102 -86
  285. package/lib/tools/auth0/handlers/themes.js.map +1 -0
  286. package/lib/tools/auth0/handlers/triggers.js +75 -59
  287. package/lib/tools/auth0/handlers/triggers.js.map +1 -0
  288. package/lib/tools/auth0/handlers/userAttributeProfiles.d.ts +4 -4
  289. package/lib/tools/auth0/handlers/userAttributeProfiles.js +63 -56
  290. package/lib/tools/auth0/handlers/userAttributeProfiles.js.map +1 -0
  291. package/lib/tools/auth0/index.js +48 -35
  292. package/lib/tools/auth0/index.js.map +1 -0
  293. package/lib/tools/auth0/schema.js +4 -6
  294. package/lib/tools/auth0/schema.js.map +1 -0
  295. package/lib/tools/calculateChanges.js +15 -24
  296. package/lib/tools/calculateChanges.js.map +1 -0
  297. package/lib/tools/constants.d.ts +3 -2
  298. package/lib/tools/constants.js +2 -0
  299. package/lib/tools/constants.js.map +1 -0
  300. package/lib/tools/deploy.js +29 -17
  301. package/lib/tools/deploy.js.map +1 -0
  302. package/lib/tools/index.d.ts +89 -3
  303. package/lib/tools/index.js +2 -3
  304. package/lib/tools/index.js.map +1 -0
  305. package/lib/tools/utils.d.ts +1 -1
  306. package/lib/tools/utils.js +22 -12
  307. package/lib/tools/utils.js.map +1 -0
  308. package/lib/tools/validationError.js +1 -0
  309. package/lib/tools/validationError.js.map +1 -0
  310. package/lib/types.d.ts +6 -9
  311. package/lib/types.js +1 -0
  312. package/lib/types.js.map +1 -0
  313. package/lib/utils.d.ts +58 -3
  314. package/lib/utils.js +5 -8
  315. package/lib/utils.js.map +1 -0
  316. package/package.json +10 -11
  317. package/tsconfig.json +3 -4
  318. package/eslint.config.js +0 -130
@@ -38,12 +38,21 @@ var __importStar = (this && this.__importStar) || (function () {
38
38
  return result;
39
39
  };
40
40
  })();
41
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
42
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
+ return new (P || (P = Promise))(function (resolve, reject) {
44
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
47
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
48
+ });
49
+ };
41
50
  var __importDefault = (this && this.__importDefault) || function (mod) {
42
51
  return (mod && mod.__esModule) ? mod : { "default": mod };
43
52
  };
44
53
  Object.defineProperty(exports, "__esModule", { value: true });
45
54
  exports.schema = void 0;
46
- const lodash_1 = require("lodash");
55
+ const lodash_1 = __importStar(require("lodash"));
47
56
  const default_1 = __importStar(require("./default"));
48
57
  const calculateChanges_1 = require("../../calculateChanges");
49
58
  const logger_1 = __importDefault(require("../../../logger"));
@@ -122,408 +131,468 @@ exports.schema = {
122
131
  };
123
132
  class OrganizationsHandler extends default_1.default {
124
133
  constructor(config) {
125
- super({
126
- ...config,
127
- type: 'organizations',
128
- id: 'id',
129
- });
134
+ super(Object.assign(Object.assign({}, config), { type: 'organizations', id: 'id' }));
130
135
  }
131
- async deleteOrganization(org) {
132
- await this.client.organizations.delete(org.id);
136
+ deleteOrganization(org) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ yield this.client.organizations.delete({ id: org.id });
139
+ });
133
140
  }
134
- async deleteOrganizations(data) {
135
- if (this.config('AUTH0_ALLOW_DELETE') === 'true' ||
136
- this.config('AUTH0_ALLOW_DELETE') === true) {
137
- await this.client.pool
138
- .addEachTask({
139
- data: data || [],
140
- generator: (item) => this.deleteOrganization(item)
141
- .then(() => {
142
- this.didDelete(item);
143
- this.deleted += 1;
141
+ deleteOrganizations(data) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ if (this.config('AUTH0_ALLOW_DELETE') === 'true' ||
144
+ this.config('AUTH0_ALLOW_DELETE') === true) {
145
+ yield this.client.pool
146
+ .addEachTask({
147
+ data: data || [],
148
+ generator: (item) => this.deleteOrganization(item)
149
+ .then(() => {
150
+ this.didDelete(item);
151
+ this.deleted += 1;
152
+ })
153
+ .catch((err) => {
154
+ throw new Error(`Problem deleting ${this.type} ${this.objString(item)}\n${err}`);
155
+ }),
144
156
  })
145
- .catch((err) => {
146
- throw new Error(`Problem deleting ${this.type} ${this.objString(item)}\n${err}`);
147
- }),
148
- })
149
- .promise();
150
- }
151
- else {
152
- logger_1.default.warn(`Detected the following organizations should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
157
+ .promise();
158
+ }
159
+ else {
160
+ logger_1.default.warn(`Detected the following organizations should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
153
161
  \n${data.map((i) => this.objString(i)).join('\n')}`);
154
- }
162
+ }
163
+ });
164
+ }
165
+ createOrganization(org) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const organization = Object.assign({}, org);
168
+ delete organization.connections;
169
+ delete organization.client_grants;
170
+ if ('discovery_domains' in organization) {
171
+ delete organization.discovery_domains;
172
+ }
173
+ const { data: created } = yield this.client.organizations.create(organization);
174
+ if (typeof org.connections !== 'undefined' && org.connections.length > 0) {
175
+ yield Promise.all(org.connections.map((conn) => this.client.organizations.addEnabledConnection({ id: created.id }, conn)));
176
+ }
177
+ if (typeof org.client_grants !== 'undefined' && org.client_grants.length > 0) {
178
+ yield Promise.all(org.client_grants.map((organizationClientGrants) => this.createOrganizationClientGrants(created.id, this.getClientGrantIDByClientName(organizationClientGrants.client_id))));
179
+ }
180
+ if (typeof org.discovery_domains !== 'undefined' && org.discovery_domains.length > 0) {
181
+ yield this.client.pool
182
+ .addEachTask({
183
+ data: org.discovery_domains,
184
+ generator: (discoveryDomain) => this.createOrganizationDiscoveryDomain(created.id, {
185
+ domain: discoveryDomain === null || discoveryDomain === void 0 ? void 0 : discoveryDomain.domain,
186
+ status: discoveryDomain === null || discoveryDomain === void 0 ? void 0 : discoveryDomain.status,
187
+ }).catch((err) => {
188
+ throw new Error(`Problem creating discovery domain ${discoveryDomain === null || discoveryDomain === void 0 ? void 0 : discoveryDomain.domain} for organization ${created.id}\n${err}`);
189
+ }),
190
+ })
191
+ .promise();
192
+ }
193
+ return created;
194
+ });
155
195
  }
156
- async createOrganization(org) {
157
- const organization = { ...org };
158
- delete organization.connections;
159
- delete organization.client_grants;
160
- if ('discovery_domains' in organization) {
161
- delete organization.discovery_domains;
162
- }
163
- const { data: created } = await this.client.organizations.create(organization);
164
- if (typeof org.connections !== 'undefined' && org.connections.length > 0) {
165
- await Promise.all(org.connections.map((conn) => this.client.organizations.enabledConnections.add(created.id, conn)));
166
- }
167
- if (typeof org.client_grants !== 'undefined' && org.client_grants.length > 0) {
168
- await Promise.all(org.client_grants.map((organizationClientGrants) => this.createOrganizationClientGrants(created.id, this.getClientGrantIDByClientName(organizationClientGrants.client_id))));
169
- }
170
- if (typeof org.discovery_domains !== 'undefined' && org.discovery_domains.length > 0) {
171
- await this.client.pool
196
+ createOrganizations(creates) {
197
+ return __awaiter(this, void 0, void 0, function* () {
198
+ yield this.client.pool
172
199
  .addEachTask({
173
- data: org.discovery_domains,
174
- generator: (discoveryDomain) => this.createOrganizationDiscoveryDomain(created.id, {
175
- domain: discoveryDomain?.domain,
176
- status: discoveryDomain?.status,
177
- }).catch((err) => {
178
- throw new Error(`Problem creating discovery domain ${discoveryDomain?.domain} for organization ${created.id}\n${err}`);
200
+ data: creates || [],
201
+ generator: (item) => this.createOrganization(item)
202
+ .then((data) => {
203
+ this.didCreate(data);
204
+ this.created += 1;
205
+ })
206
+ .catch((err) => {
207
+ throw new Error(`Problem creating ${this.type} ${this.objString(item)}\n${err}`);
179
208
  }),
180
209
  })
181
210
  .promise();
182
- }
183
- return created;
211
+ });
184
212
  }
185
- async createOrganizations(creates) {
186
- await this.client.pool
187
- .addEachTask({
188
- data: creates || [],
189
- generator: (item) => this.createOrganization(item)
190
- .then((data) => {
191
- this.didCreate(data);
192
- this.created += 1;
213
+ updateOrganization(org, organizations) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ var _a, _b;
216
+ const { connections: existingConnections, client_grants: existingClientGrants, discovery_domains: existingDiscoveryDomains, } = yield organizations.find((orgToUpdate) => orgToUpdate.name === org.name);
217
+ const params = { id: org.id };
218
+ const { connections, client_grants: organizationClientGrants, discovery_domains: organizationDiscoveryDomains, } = org;
219
+ delete org.connections;
220
+ delete org.name;
221
+ delete org.id;
222
+ delete org.client_grants;
223
+ delete org.discovery_domains;
224
+ yield this.client.organizations.update(params, org);
225
+ // organization connections
226
+ const connectionsToRemove = existingConnections.filter((c) => !connections.find((x) => x.connection_id === c.connection_id));
227
+ const connectionsToAdd = connections.filter((c) => !existingConnections.find((x) => x.connection_id === c.connection_id));
228
+ const connectionsToUpdate = connections.filter((c) => existingConnections.find((x) => x.connection_id === c.connection_id &&
229
+ (x.assign_membership_on_login !== c.assign_membership_on_login ||
230
+ x.show_as_button !== c.show_as_button ||
231
+ x.is_signup_enabled !== c.is_signup_enabled)));
232
+ // Handle updates first
233
+ yield Promise.all(connectionsToUpdate.map((conn) => this.client.organizations
234
+ .updateEnabledConnection(Object.assign({ connectionId: conn.connection_id }, params), {
235
+ assign_membership_on_login: conn.assign_membership_on_login,
236
+ show_as_button: conn.show_as_button,
237
+ is_signup_enabled: conn.is_signup_enabled,
193
238
  })
194
- .catch((err) => {
195
- throw new Error(`Problem creating ${this.type} ${this.objString(item)}\n${err}`);
196
- }),
197
- })
198
- .promise();
199
- }
200
- async updateOrganization(org, organizations) {
201
- const { connections: existingConnections, client_grants: existingClientGrants, discovery_domains: existingDiscoveryDomains, } = await organizations.find((orgToUpdate) => orgToUpdate.name === org.name);
202
- const params = { id: org.id };
203
- const { connections, client_grants: organizationClientGrants, discovery_domains: organizationDiscoveryDomains, } = org;
204
- delete org.connections;
205
- delete org.name;
206
- delete org.id;
207
- delete org.client_grants;
208
- delete org.discovery_domains;
209
- await this.client.organizations.update(params.id, org);
210
- // organization connections
211
- const connectionsToRemove = existingConnections.filter((c) => !connections.find((x) => x.connection_id === c.connection_id));
212
- const connectionsToAdd = connections.filter((c) => !existingConnections.find((x) => x.connection_id === c.connection_id));
213
- const connectionsToUpdate = connections.filter((c) => existingConnections.find((x) => x.connection_id === c.connection_id &&
214
- (x.assign_membership_on_login !== c.assign_membership_on_login ||
215
- x.show_as_button !== c.show_as_button ||
216
- x.is_signup_enabled !== c.is_signup_enabled)));
217
- // Handle updates first
218
- await Promise.all(connectionsToUpdate.map((conn) => this.client.organizations.enabledConnections
219
- .update(params.id, conn.connection_id, {
220
- assign_membership_on_login: conn.assign_membership_on_login,
221
- show_as_button: conn.show_as_button,
222
- is_signup_enabled: conn.is_signup_enabled,
223
- })
224
- .catch(() => {
225
- throw new Error(`Problem updating Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
226
- })));
227
- await Promise.all(connectionsToAdd.map((conn) => this.client.organizations.enabledConnections
228
- .add(params.id, (0, lodash_1.omit)(conn, 'connection'))
229
- .catch(() => {
230
- throw new Error(`Problem adding Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
231
- })));
232
- await Promise.all(connectionsToRemove.map((conn) => this.client.organizations.enabledConnections
233
- .delete(params.id, conn.connection_id)
234
- .catch(() => {
235
- throw new Error(`Problem removing Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
236
- })));
237
- // organization client_grants
238
- const orgClientGrantsToRemove = existingClientGrants
239
- ?.filter((c) => !organizationClientGrants?.find((x) => x.client_id === c.client_id))
240
- ?.map((clientGrant) => ({
241
- grant_id: this.getClientGrantIDByClientName(clientGrant.client_id),
242
- })) || [];
243
- const orgClientGrantsToAdd = organizationClientGrants
244
- ?.filter((c) => !existingClientGrants?.find((x) => x.client_id === c.client_id))
245
- ?.map((clientGrant) => ({
246
- grant_id: this.getClientGrantIDByClientName(clientGrant.client_id),
247
- })) || [];
248
- // Handle updates first
249
- await Promise.all(orgClientGrantsToAdd.map((orgClientGrant) => this.createOrganizationClientGrants(params.id, orgClientGrant.grant_id).catch(() => {
250
- throw new Error(`Problem adding organization clientGrant ${orgClientGrant.grant_id} for organizations ${params.id}`);
251
- })));
252
- await Promise.all(orgClientGrantsToRemove.map((orgClientGrant) => this.deleteOrganizationClientGrants(params.id, orgClientGrant.grant_id).catch(() => {
253
- throw new Error(`Problem removing organization clientGrant ${orgClientGrant.grant_id} for organizations ${params.id}`);
254
- })));
255
- // organization discovery_domains
256
- const orgDiscoveryDomainsToRemove = existingDiscoveryDomains?.filter((existingDomain) => !organizationDiscoveryDomains?.find((d) => d.domain === existingDomain.domain)) || [];
257
- const orgDiscoveryDomainsToAdd = organizationDiscoveryDomains?.filter((domain) => !existingDiscoveryDomains?.find((d) => d.domain === domain.domain)) || [];
258
- const orgDiscoveryDomainsToUpdate = existingDiscoveryDomains
259
- ?.filter((existingDomain) => {
260
- const updatedDomain = organizationDiscoveryDomains?.find((d) => d.domain === existingDomain.domain);
261
- return updatedDomain && updatedDomain.status !== existingDomain.status;
262
- })
263
- .map((existingDomain) => ({
264
- id: existingDomain.id,
265
- domain: existingDomain.domain,
266
- status: organizationDiscoveryDomains.find((d) => d.domain === existingDomain.domain)
267
- .status,
268
- })) || [];
269
- // Handle updates first
270
- await Promise.all(orgDiscoveryDomainsToUpdate.map((domainUpdate) => this.updateOrganizationDiscoveryDomain(params.id, domainUpdate.id, domainUpdate.domain, domainUpdate.status).catch((err) => {
271
- throw new Error(`Problem updating discovery domain ${domainUpdate.domain} for organization ${params.id}\n${err.message}`);
272
- })));
273
- await Promise.all(orgDiscoveryDomainsToAdd.map((domain) => this.createOrganizationDiscoveryDomain(params.id, {
274
- domain: domain.domain,
275
- status: domain.status,
276
- }).catch((err) => {
277
- throw new Error(`Problem adding discovery domain ${domain.domain} for organization ${params.id}\n${err.message}`);
278
- })));
279
- if (orgDiscoveryDomainsToRemove.length > 0) {
280
- if (this.config('AUTH0_ALLOW_DELETE') === 'true' ||
281
- this.config('AUTH0_ALLOW_DELETE') === true) {
282
- await Promise.all(orgDiscoveryDomainsToRemove.map((domain) => this.deleteOrganizationDiscoveryDomain(params.id, domain.domain, domain.id).catch((err) => {
283
- throw new Error(`Problem removing discovery domain ${domain.domain} for organization ${params.id}\n${err.message}`);
284
- })));
285
- }
286
- else {
287
- logger_1.default.warn(`Detected the following organization discovery domains should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
239
+ .catch(() => {
240
+ throw new Error(`Problem updating Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
241
+ })));
242
+ yield Promise.all(connectionsToAdd.map((conn) => this.client.organizations
243
+ .addEnabledConnection(params, lodash_1.default.omit(conn, 'connection'))
244
+ .catch(() => {
245
+ throw new Error(`Problem adding Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
246
+ })));
247
+ yield Promise.all(connectionsToRemove.map((conn) => this.client.organizations
248
+ .deleteEnabledConnection(Object.assign({ connectionId: conn.connection_id }, params))
249
+ .catch(() => {
250
+ throw new Error(`Problem removing Enabled Connection ${conn.connection_id} for organizations ${params.id}`);
251
+ })));
252
+ // organization client_grants
253
+ const orgClientGrantsToRemove = ((_a = existingClientGrants === null || existingClientGrants === void 0 ? void 0 : existingClientGrants.filter((c) => !(organizationClientGrants === null || organizationClientGrants === void 0 ? void 0 : organizationClientGrants.find((x) => x.client_id === c.client_id)))) === null || _a === void 0 ? void 0 : _a.map((clientGrant) => ({
254
+ grant_id: this.getClientGrantIDByClientName(clientGrant.client_id),
255
+ }))) || [];
256
+ const orgClientGrantsToAdd = ((_b = organizationClientGrants === null || organizationClientGrants === void 0 ? void 0 : organizationClientGrants.filter((c) => !(existingClientGrants === null || existingClientGrants === void 0 ? void 0 : existingClientGrants.find((x) => x.client_id === c.client_id)))) === null || _b === void 0 ? void 0 : _b.map((clientGrant) => ({
257
+ grant_id: this.getClientGrantIDByClientName(clientGrant.client_id),
258
+ }))) || [];
259
+ // Handle updates first
260
+ yield Promise.all(orgClientGrantsToAdd.map((orgClientGrant) => this.createOrganizationClientGrants(params.id, orgClientGrant.grant_id).catch(() => {
261
+ throw new Error(`Problem adding organization clientGrant ${orgClientGrant.grant_id} for organizations ${params.id}`);
262
+ })));
263
+ yield Promise.all(orgClientGrantsToRemove.map((orgClientGrant) => this.deleteOrganizationClientGrants(params.id, orgClientGrant.grant_id).catch(() => {
264
+ throw new Error(`Problem removing organization clientGrant ${orgClientGrant.grant_id} for organizations ${params.id}`);
265
+ })));
266
+ // organization discovery_domains
267
+ const orgDiscoveryDomainsToRemove = (existingDiscoveryDomains === null || existingDiscoveryDomains === void 0 ? void 0 : existingDiscoveryDomains.filter((existingDomain) => !(organizationDiscoveryDomains === null || organizationDiscoveryDomains === void 0 ? void 0 : organizationDiscoveryDomains.find((d) => d.domain === existingDomain.domain)))) || [];
268
+ const orgDiscoveryDomainsToAdd = (organizationDiscoveryDomains === null || organizationDiscoveryDomains === void 0 ? void 0 : organizationDiscoveryDomains.filter((domain) => !(existingDiscoveryDomains === null || existingDiscoveryDomains === void 0 ? void 0 : existingDiscoveryDomains.find((d) => d.domain === domain.domain)))) || [];
269
+ const orgDiscoveryDomainsToUpdate = (existingDiscoveryDomains === null || existingDiscoveryDomains === void 0 ? void 0 : existingDiscoveryDomains.filter((existingDomain) => {
270
+ const updatedDomain = organizationDiscoveryDomains === null || organizationDiscoveryDomains === void 0 ? void 0 : organizationDiscoveryDomains.find((d) => d.domain === existingDomain.domain);
271
+ return updatedDomain && updatedDomain.status !== existingDomain.status;
272
+ }).map((existingDomain) => ({
273
+ id: existingDomain.id,
274
+ domain: existingDomain.domain,
275
+ status: organizationDiscoveryDomains.find((d) => d.domain === existingDomain.domain)
276
+ .status,
277
+ }))) || [];
278
+ // Handle updates first
279
+ yield Promise.all(orgDiscoveryDomainsToUpdate.map((domainUpdate) => this.updateOrganizationDiscoveryDomain(params.id, domainUpdate.id, domainUpdate.domain, domainUpdate.status).catch((err) => {
280
+ throw new Error(`Problem updating discovery domain ${domainUpdate.domain} for organization ${params.id}\n${err.message}`);
281
+ })));
282
+ yield Promise.all(orgDiscoveryDomainsToAdd.map((domain) => this.createOrganizationDiscoveryDomain(params.id, {
283
+ domain: domain.domain,
284
+ status: domain.status,
285
+ }).catch((err) => {
286
+ throw new Error(`Problem adding discovery domain ${domain.domain} for organization ${params.id}\n${err.message}`);
287
+ })));
288
+ if (orgDiscoveryDomainsToRemove.length > 0) {
289
+ if (this.config('AUTH0_ALLOW_DELETE') === 'true' ||
290
+ this.config('AUTH0_ALLOW_DELETE') === true) {
291
+ yield Promise.all(orgDiscoveryDomainsToRemove.map((domain) => this.deleteOrganizationDiscoveryDomain(params.id, domain.domain, domain.id).catch((err) => {
292
+ throw new Error(`Problem removing discovery domain ${domain.domain} for organization ${params.id}\n${err.message}`);
293
+ })));
294
+ }
295
+ else {
296
+ logger_1.default.warn(`Detected the following organization discovery domains should be deleted. Doing so may be destructive.\nYou can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config
288
297
  \n${orgDiscoveryDomainsToRemove.map((i) => this.objString(i)).join('\n')}`);
298
+ }
289
299
  }
290
- }
291
- return params;
300
+ return params;
301
+ });
292
302
  }
293
303
  getClientGrantIDByClientName(clientsName) {
294
304
  const found = this.formattedClientGrants.find((c) => c.client_id === clientsName);
295
- return found?.grant_id || '';
296
- }
297
- async getFormattedClientGrants() {
298
- const [clients, clientGrants] = await Promise.all([
299
- (0, client_1.paginate)(this.client.clients.list, {
300
- paginate: true,
301
- }),
302
- (0, client_1.paginate)(this.client.clientGrants.list, {
303
- paginate: true,
304
- }),
305
- ]);
306
- // Convert clients by name to the id and store it in the formattedClientGrants
307
- const formattedClientGrantsMapping = clientGrants?.map((clientGrant) => {
308
- const { id, client_id: clientName } = clientGrant;
309
- const grant = { grant_id: id, client_id: clientName };
310
- const found = clients.find((c) => c.client_id === grant.client_id);
311
- if (found)
312
- grant.client_id = found.name;
313
- return grant;
314
- });
315
- return formattedClientGrantsMapping;
316
- }
317
- async updateOrganizations(updates, orgs) {
318
- await this.client.pool
319
- .addEachTask({
320
- data: updates || [],
321
- generator: (item) => this.updateOrganization(item, orgs)
322
- .then((data) => {
323
- this.didUpdate(data);
324
- this.updated += 1;
325
- })
326
- .catch((err) => {
327
- throw new Error(`Problem updating ${this.type} ${this.objString(item)}\n${err}`);
328
- }),
329
- })
330
- .promise();
305
+ return (found === null || found === void 0 ? void 0 : found.grant_id) || '';
331
306
  }
332
- async getType() {
333
- if (this.existing) {
334
- return this.existing;
335
- }
336
- try {
337
- const [organizations, clients] = await Promise.all([
338
- (0, client_1.paginate)(this.client.organizations.list, {
339
- checkpoint: true,
307
+ getFormattedClientGrants() {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ const [clients, clientGrants] = yield Promise.all([
310
+ (0, client_1.paginate)(this.client.clients.getAll, {
311
+ paginate: true,
312
+ include_totals: true,
340
313
  }),
341
- (0, client_1.paginate)(this.client.clients.list, {
314
+ (0, client_1.paginate)(this.client.clientGrants.getAll, {
342
315
  paginate: true,
316
+ include_totals: true,
343
317
  }),
344
318
  ]);
345
- for (let index = 0; index < organizations.length; index++) {
346
- const org = organizations[index];
347
- if (!org?.id) {
348
- throw new Error(`Organization ${index} is missing an ID`);
349
- }
350
- const connections = await this.getOrganizationEnabledConnections(org.id);
351
- org.connections = connections;
352
- const organizationClientGrants = await this.getOrganizationClientGrants(org.id);
353
- org.client_grants = organizationClientGrants?.map((clientGrant) => ({
354
- client_id: (0, utils_1.convertClientIdToName)(clientGrant.client_id, clients),
355
- }));
356
- // Get discovery domains for each organization
357
- const organizationDiscoveryDomains = await this.getAllOrganizationDiscoveryDomains(org.id);
358
- if (organizationDiscoveryDomains) {
359
- org.discovery_domains = organizationDiscoveryDomains;
360
- }
319
+ // Convert clients by name to the id and store it in the formattedClientGrants
320
+ const formattedClientGrantsMapping = clientGrants === null || clientGrants === void 0 ? void 0 : clientGrants.map((clientGrant) => {
321
+ const { id, client_id: clientName } = clientGrant;
322
+ const grant = { grant_id: id, client_id: clientName };
323
+ const found = clients.find((c) => c.client_id === grant.client_id);
324
+ if (found)
325
+ grant.client_id = found.name;
326
+ return grant;
327
+ });
328
+ return formattedClientGrantsMapping;
329
+ });
330
+ }
331
+ updateOrganizations(updates, orgs) {
332
+ return __awaiter(this, void 0, void 0, function* () {
333
+ yield this.client.pool
334
+ .addEachTask({
335
+ data: updates || [],
336
+ generator: (item) => this.updateOrganization(item, orgs)
337
+ .then((data) => {
338
+ this.didUpdate(data);
339
+ this.updated += 1;
340
+ })
341
+ .catch((err) => {
342
+ throw new Error(`Problem updating ${this.type} ${this.objString(item)}\n${err}`);
343
+ }),
344
+ })
345
+ .promise();
346
+ });
347
+ }
348
+ getType() {
349
+ return __awaiter(this, void 0, void 0, function* () {
350
+ if (this.existing) {
351
+ return this.existing;
361
352
  }
362
- this.existing = organizations;
363
- return this.existing;
364
- }
365
- catch (err) {
366
- if (err.statusCode === 404 || err.statusCode === 501) {
353
+ if (!this.client.organizations || typeof this.client.organizations.getAll !== 'function') {
367
354
  return [];
368
355
  }
369
- throw err;
370
- }
356
+ try {
357
+ const [organizations, clients] = yield Promise.all([
358
+ (0, client_1.paginate)(this.client.organizations.getAll, {
359
+ checkpoint: true,
360
+ include_totals: true,
361
+ }),
362
+ (0, client_1.paginate)(this.client.clients.getAll, {
363
+ paginate: true,
364
+ include_totals: true,
365
+ }),
366
+ ]);
367
+ for (let index = 0; index < organizations.length; index++) {
368
+ // Get enabled connections for each organization
369
+ const { data: connections } = yield this.client.organizations.getEnabledConnections({
370
+ id: organizations[index].id,
371
+ });
372
+ organizations[index].connections = connections;
373
+ // Get client grants for each organization
374
+ const organizationClientGrants = yield this.getOrganizationClientGrants(organizations[index].id);
375
+ organizations[index].client_grants = organizationClientGrants === null || organizationClientGrants === void 0 ? void 0 : organizationClientGrants.map((clientGrant) => ({
376
+ client_id: (0, utils_1.convertClientIdToName)(clientGrant.client_id, clients),
377
+ }));
378
+ // Get discovery domains for each organization
379
+ const organizationDiscoveryDomains = yield this.getAllOrganizationDiscoveryDomains(organizations[index].id);
380
+ if (organizationDiscoveryDomains) {
381
+ organizations[index].discovery_domains = organizationDiscoveryDomains;
382
+ }
383
+ }
384
+ this.existing = organizations;
385
+ return this.existing;
386
+ }
387
+ catch (err) {
388
+ if (err.statusCode === 404 || err.statusCode === 501) {
389
+ return [];
390
+ }
391
+ throw err;
392
+ }
393
+ });
371
394
  }
372
395
  // Run after connections
373
- async processChanges(assets) {
374
- const { organizations } = assets;
375
- // Do nothing if not set
376
- if (!organizations)
377
- return;
378
- // Gets organizations from destination tenant
379
- const existing = await this.getType();
380
- const existingConnections = await (0, client_1.paginate)(this.client.connections.list, {
381
- checkpoint: true,
382
- });
383
- // We need to get the connection ids for the names configured so we can link them together
384
- organizations.forEach((org) => {
385
- org.connections = (org.connections || [])
386
- .map((connection) => {
387
- const { name } = connection;
388
- delete connection.name;
389
- return {
390
- ...connection,
391
- connection_id: (existingConnections.find((c) => c.name === name) || {}).id,
392
- };
393
- })
394
- .filter((connection) => !!connection.connection_id);
395
- });
396
- // store formated client_grants->client_id to client grant->grant_id mapping
397
- this.formattedClientGrants = await this.getFormattedClientGrants();
398
- const changes = (0, calculateChanges_1.calculateChanges)({
399
- handler: this,
400
- assets: organizations,
401
- existing,
402
- identifiers: this.identifiers,
403
- allowDelete: !!this.config('AUTH0_ALLOW_DELETE'),
396
+ processChanges(assets) {
397
+ return __awaiter(this, void 0, void 0, function* () {
398
+ const { organizations } = assets;
399
+ // Do nothing if not set
400
+ if (!organizations)
401
+ return;
402
+ // Gets organizations from destination tenant
403
+ const existing = yield this.getType();
404
+ const existingConnections = yield (0, client_1.paginate)(this.client.connections.getAll, {
405
+ checkpoint: true,
406
+ include_totals: true,
407
+ });
408
+ // We need to get the connection ids for the names configured so we can link them together
409
+ organizations.forEach((org) => {
410
+ org.connections = (org.connections || [])
411
+ .map((connection) => {
412
+ const { name } = connection;
413
+ delete connection.name;
414
+ return Object.assign(Object.assign({}, connection), { connection_id: (existingConnections.find((c) => c.name === name) || {}).id });
415
+ })
416
+ .filter((connection) => !!connection.connection_id);
417
+ });
418
+ // store formated client_grants->client_id to client grant->grant_id mapping
419
+ this.formattedClientGrants = yield this.getFormattedClientGrants();
420
+ const changes = (0, calculateChanges_1.calculateChanges)({
421
+ handler: this,
422
+ assets: organizations,
423
+ existing,
424
+ identifiers: this.identifiers,
425
+ allowDelete: !!this.config('AUTH0_ALLOW_DELETE'),
426
+ });
427
+ logger_1.default.debug(`Start processChanges for organizations [delete:${changes.del.length}] [update:${changes.update.length}], [create:${changes.create.length}]`);
428
+ const myChanges = [
429
+ { del: changes.del },
430
+ { create: changes.create },
431
+ { update: changes.update },
432
+ ];
433
+ yield Promise.all(myChanges.map((change) => __awaiter(this, void 0, void 0, function* () {
434
+ switch (true) {
435
+ case change.del && change.del.length > 0:
436
+ yield this.deleteOrganizations(change.del || []);
437
+ break;
438
+ case change.create && change.create.length > 0:
439
+ yield this.createOrganizations(changes.create);
440
+ break;
441
+ case change.update && change.update.length > 0:
442
+ if (change.update)
443
+ yield this.updateOrganizations(change.update, existing);
444
+ break;
445
+ default:
446
+ break;
447
+ }
448
+ })));
404
449
  });
405
- logger_1.default.debug(`Start processChanges for organizations [delete:${changes.del.length}] [update:${changes.update.length}], [create:${changes.create.length}]`);
406
- const myChanges = [
407
- { del: changes.del },
408
- { create: changes.create },
409
- { update: changes.update },
410
- ];
411
- await Promise.all(myChanges.map(async (change) => {
412
- switch (true) {
413
- case change.del && change.del.length > 0:
414
- await this.deleteOrganizations(change.del || []);
415
- break;
416
- case change.create && change.create.length > 0:
417
- await this.createOrganizations(changes.create);
418
- break;
419
- case change.update && change.update.length > 0:
420
- if (change.update)
421
- await this.updateOrganizations(change.update, existing);
450
+ }
451
+ getOrganizationClientGrants(organizationId) {
452
+ return __awaiter(this, void 0, void 0, function* () {
453
+ // paginate without paginate<T> helper as this is not getAll but getOrganizationClientGrants
454
+ // paginate through all oranizaion client grants for oranizaion id
455
+ const allOrganizationClientGrants = [];
456
+ let page = 0;
457
+ while (true) {
458
+ const { data: { client_grants: organizationClientGrants, total }, } = yield this.client.organizations.getOrganizationClientGrants({
459
+ id: organizationId,
460
+ page: page,
461
+ per_page: 100,
462
+ include_totals: true,
463
+ });
464
+ // if we get an unexpected response, break the loop to avoid infinite loop
465
+ if (!(0, lodash_1.isArray)(organizationClientGrants) || typeof total !== 'number') {
422
466
  break;
423
- default:
467
+ }
468
+ allOrganizationClientGrants.push(...organizationClientGrants);
469
+ page += 1;
470
+ if (allOrganizationClientGrants.length === total) {
424
471
  break;
472
+ }
425
473
  }
426
- }));
427
- }
428
- async getOrganizationEnabledConnections(organizationId) {
429
- const allOrganizationConnections = [];
430
- let organizationConnections = await this.client.organizations.enabledConnections.list(organizationId);
431
- do {
432
- allOrganizationConnections.push(...organizationConnections.data);
433
- organizationConnections = await organizationConnections.getNextPage();
434
- } while (organizationConnections.hasNextPage());
435
- return allOrganizationConnections;
436
- }
437
- async getOrganizationClientGrants(organizationId) {
438
- const allOrganizationClientGrants = [];
439
- let organizationClientGrants = await this.client.organizations.clientGrants.list(organizationId);
440
- do {
441
- allOrganizationClientGrants.push(...organizationClientGrants.data);
442
- organizationClientGrants = await organizationClientGrants.getNextPage();
443
- } while (organizationClientGrants.hasNextPage());
444
- return allOrganizationClientGrants;
474
+ return allOrganizationClientGrants;
475
+ });
445
476
  }
446
- async createOrganizationClientGrants(organizationId, grantId) {
447
- logger_1.default.debug(`Creating organization client grant ${grantId} for organization ${organizationId}`);
448
- const organizationClientGrants = await this.client.organizations.clientGrants.create(organizationId, {
449
- grant_id: grantId,
477
+ createOrganizationClientGrants(organizationId, grantId) {
478
+ return __awaiter(this, void 0, void 0, function* () {
479
+ logger_1.default.debug(`Creating organization client grant ${grantId} for organization ${organizationId}`);
480
+ const { data: organizationClientGrants } = yield this.client.organizations.postOrganizationClientGrants({
481
+ id: organizationId,
482
+ }, {
483
+ grant_id: grantId,
484
+ });
485
+ return organizationClientGrants;
450
486
  });
451
- return organizationClientGrants;
452
487
  }
453
- async deleteOrganizationClientGrants(organizationId, grantId) {
454
- logger_1.default.debug(`Deleting organization client grant ${grantId} for organization ${organizationId}`);
455
- await this.client.organizations.clientGrants.delete(organizationId, grantId);
488
+ deleteOrganizationClientGrants(organizationId, grantId) {
489
+ return __awaiter(this, void 0, void 0, function* () {
490
+ logger_1.default.debug(`Deleting organization client grant ${grantId} for organization ${organizationId}`);
491
+ yield this.client.organizations.deleteClientGrantsByGrantId({
492
+ id: organizationId,
493
+ grant_id: grantId,
494
+ });
495
+ });
456
496
  }
457
- async getAllOrganizationDiscoveryDomains(organizationId) {
458
- // paginate using checkpoint pagination for getAllDiscoveryDomains
459
- const allDiscoveryDomains = [];
460
- try {
461
- let orgDiscoveryDomain = await this.client.organizations.discoveryDomains.list(organizationId);
462
- do {
463
- allDiscoveryDomains.push(...orgDiscoveryDomain.data);
464
- orgDiscoveryDomain = await orgDiscoveryDomain.getNextPage();
465
- } while (orgDiscoveryDomain.hasNextPage());
466
- return allDiscoveryDomains;
467
- }
468
- catch (err) {
469
- if (err.statusCode === 404 || err.statusCode === 501) {
470
- return null;
497
+ getAllOrganizationDiscoveryDomains(organizationId) {
498
+ return __awaiter(this, void 0, void 0, function* () {
499
+ var _a, _b;
500
+ // paginate using checkpoint pagination for getAllDiscoveryDomains
501
+ const allDiscoveryDomains = [];
502
+ const requestArgs = { id: organizationId, take: 50 };
503
+ let next;
504
+ try {
505
+ do {
506
+ if (next) {
507
+ requestArgs.from = next;
508
+ }
509
+ else {
510
+ delete requestArgs.from;
511
+ }
512
+ const rsp = yield this.client.pool
513
+ .addSingleTask({
514
+ data: requestArgs,
515
+ generator: (args) => this.client.organizations.getAllDiscoveryDomains(args),
516
+ })
517
+ .promise();
518
+ const discoveryDomains = Array.isArray(rsp.data) ? rsp.data : ((_a = rsp.data) === null || _a === void 0 ? void 0 : _a.domains) || [];
519
+ allDiscoveryDomains.push(...discoveryDomains);
520
+ next = (_b = rsp.data) === null || _b === void 0 ? void 0 : _b.next;
521
+ } while (next);
522
+ return allDiscoveryDomains;
471
523
  }
472
- if (err.statusCode === 403 || err.errorCode === 'feature_not_enabled') {
473
- logger_1.default.debug('Organization Discovery domains are not enabled for this tenant. Please verify `scope` or contact Auth0 support to enable this feature.');
474
- return null;
524
+ catch (err) {
525
+ if (err.statusCode === 404 || err.statusCode === 501) {
526
+ return null;
527
+ }
528
+ if (err.statusCode === 403 || err.errorCode === 'feature_not_enabled') {
529
+ logger_1.default.debug('Organization Discovery domains are not enabled for this tenant. Please verify `scope` or contact Auth0 support to enable this feature.');
530
+ return null;
531
+ }
532
+ throw err;
475
533
  }
476
- throw err;
477
- }
478
- }
479
- async getOrganizationDiscoveryDomain(organizationId, discoveryDomainId) {
480
- const orgDiscoveryDomain = await this.client.organizations.discoveryDomains.get(organizationId, discoveryDomainId);
481
- return orgDiscoveryDomain;
534
+ });
482
535
  }
483
- async createOrganizationDiscoveryDomain(organizationId, discoveryDomain) {
484
- logger_1.default.debug(`Creating discovery domain ${discoveryDomain.domain} for organization ${organizationId}`);
485
- const orgDiscoveryDomain = await this.client.pool
486
- .addSingleTask({
487
- data: {
536
+ getOrganizationDiscoveryDomain(organizationId, discoveryDomainId) {
537
+ return __awaiter(this, void 0, void 0, function* () {
538
+ const { data } = yield this.client.organizations.getDiscoveryDomain({
488
539
  id: organizationId,
489
- },
490
- generator: (args) => this.client.organizations.discoveryDomains.create(args.id, discoveryDomain),
491
- })
492
- .promise();
493
- return orgDiscoveryDomain;
540
+ discovery_domain_id: discoveryDomainId,
541
+ });
542
+ return data;
543
+ });
494
544
  }
495
- async updateOrganizationDiscoveryDomain(organizationId, discoveryDomainId, discoveryDomain, status) {
496
- logger_1.default.debug(`Updating discovery domain ${discoveryDomain} for organization ${organizationId}`);
497
- // stripUpdateFields does not support in sub modules
498
- const stripUpdateFields = ['verification_host', 'verification_txt'];
499
- logger_1.default.debug(`Stripping ${this.type} discovery domain read-only fields ${JSON.stringify(stripUpdateFields)}`);
500
- const discoveryDomainUpdated = await this.client.pool
501
- .addSingleTask({
502
- data: {
503
- id: organizationId,
504
- discoveryDomainId: discoveryDomainId,
505
- },
506
- generator: (args) => this.client.organizations.discoveryDomains.update(args.id, args.discoveryDomainId, {
507
- status: status,
508
- }),
509
- })
510
- .promise();
511
- return discoveryDomainUpdated;
545
+ createOrganizationDiscoveryDomain(organizationId, discoveryDomain) {
546
+ return __awaiter(this, void 0, void 0, function* () {
547
+ logger_1.default.debug(`Creating discovery domain ${discoveryDomain.domain} for organization ${organizationId}`);
548
+ const { data } = yield this.client.pool
549
+ .addSingleTask({
550
+ data: {
551
+ id: organizationId,
552
+ },
553
+ generator: (args) => this.client.organizations.createDiscoveryDomain(args, discoveryDomain),
554
+ })
555
+ .promise();
556
+ return data;
557
+ });
512
558
  }
513
- async deleteOrganizationDiscoveryDomain(organizationId, discoveryDomain, discoveryDomainId) {
514
- logger_1.default.debug(`Deleting discovery domain ${discoveryDomain} for organization ${organizationId}`);
515
- await this.client.pool
516
- .addSingleTask({
517
- data: {
518
- id: organizationId,
519
- discoveryDomainId: discoveryDomainId,
520
- },
521
- generator: (args) => this.client.organizations.discoveryDomains.delete(args.id, args.discoveryDomainId),
522
- })
523
- .promise();
559
+ updateOrganizationDiscoveryDomain(organizationId, discoveryDomainId, discoveryDomain, status) {
560
+ return __awaiter(this, void 0, void 0, function* () {
561
+ logger_1.default.debug(`Updating discovery domain ${discoveryDomain} for organization ${organizationId}`);
562
+ // stripUpdateFields does not support in sub modules
563
+ const stripUpdateFields = ['verification_host', 'verification_txt'];
564
+ logger_1.default.debug(`Stripping ${this.type} discovery domain read-only fields ${JSON.stringify(stripUpdateFields)}`);
565
+ const { data } = yield this.client.pool
566
+ .addSingleTask({
567
+ data: {
568
+ id: organizationId,
569
+ discovery_domain_id: discoveryDomainId,
570
+ },
571
+ generator: (args) => this.client.organizations.updateDiscoveryDomain(args, {
572
+ status,
573
+ }),
574
+ })
575
+ .promise();
576
+ return data;
577
+ });
578
+ }
579
+ deleteOrganizationDiscoveryDomain(organizationId, discoveryDomain, discoveryDomainId) {
580
+ return __awaiter(this, void 0, void 0, function* () {
581
+ logger_1.default.debug(`Deleting discovery domain ${discoveryDomain} for organization ${organizationId}`);
582
+ yield this.client.pool
583
+ .addSingleTask({
584
+ data: {
585
+ id: organizationId,
586
+ discovery_domain_id: discoveryDomainId,
587
+ },
588
+ generator: (args) => this.client.organizations.deleteDiscoveryDomain(args),
589
+ })
590
+ .promise();
591
+ });
524
592
  }
525
593
  }
526
594
  exports.default = OrganizationsHandler;
527
595
  __decorate([
528
596
  (0, default_1.order)('70')
529
597
  ], OrganizationsHandler.prototype, "processChanges", null);
598
+ //# sourceMappingURL=organizations.js.map